-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile
executable file
·54 lines (42 loc) · 1.38 KB
/
compile
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
51
52
53
54
#!/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
# compile and link against CII40
CIIFLAGS=`pkg-config --cflags cii40`
CIILIBS=`pkg-config --libs cii40`
# compile and link against course software and netpbm library
CFLAGS="-I. -I/comp/40/include $CIIFLAGS"
LIBS="$CIILIBS -lm"
LFLAGS="-L/comp/40/lib64"
# these flags max out warnings and debug info
FLAGS="-g -O0 -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 -o um main.o segment.o bitpack.o\
processor.o\
$LIBS $LFLAGS
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