-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile
More file actions
50 lines (39 loc) · 1.42 KB
/
compile
File metadata and controls
50 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
set -e # halt on first error
link=all # link all binaries by default
linked=no # track whether we linked
case $1 in
-nolink) link=none ; shift ;; # don't link
-link) link="$2" ; shift ; shift ;; # link only one binary
esac
CC=gcc
# compile and link against course software and netpbm library
CFLAGS="-I. -I/usr/local/cii/include -I/usr/local/include -I/csc/411/include"
LIBS="-lc -lcii -llocality -lnetpbm -larith411 -lm"
LFLAGS="-L/usr/local/cii/lib -L/usr/local/lib -L/csc/411/lib"
# these flags max out warnings and debug info
FLAGS="-no-pie -g -O2 -Wall -Wextra -Werror -Wfatal-errors -std=c99 -pedantic"
rm -f *.o # make sure no object files are left hanging around
case $# in
0) set *.c ;; # if no args are given, compile all .c files
esac
# compile each argument to a .o file
for cfile
do
gcc $FLAGS $CFLAGS -c $cfile
done
########### the middle part is different for each assignment
# link together .o files + libraries to make executable binaries
# using one case statement per executable binary
case $link in
all|um) gcc $FLAGS $LFLAGS -o um um.o run_um.o seg.o bitpack.o \
-llocality -lnetpbm -larith411 $LIBS
linked=yes ;;
esac
# error if asked to link something we didn't recognize
if [ $linked = no ]; then
case $link in # if the -link option makes no sense, complain
none) ;; # OK, do nothing
*) echo "`basename $0`: don't know how to link $link" 1>&2 ; exit 1 ;;
esac
fi