-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile
55 lines (42 loc) · 1.46 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
55
#!/bin/sh
### INITIAL
set -e # halt on first error
set -x # print out all commands
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/csc/411/include -I/usr/local/cii/include -I/usr/local/include"
LIBS="-lcii -lnetpbm -lm -lbitpack"
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 -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
### MIDDLE
# link together .o files + libraries to make executable binaries
# using one case statement per executable binary
case $link in
all|um) $CC $FLAGS $LFLAGS -o um um.o program_loader.o execute.o memory.o \
segment.o operators.o $LIBS
linked=yes ;;
esac
### FINAL
# 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