-
Notifications
You must be signed in to change notification settings - Fork 50
/
Makefile
136 lines (96 loc) · 3.84 KB
/
Makefile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Do not modify this file, as it is overwritten by the default file in the
# code grade testing environment
# If you need to include extra libraries for your gui or debugger,
# please provide list the extra compiler arguments (i.e. "lgtk-4") in
# debugger_libs or gui_libs.
.PHONY: clean testall run_test% zip tools
IDIR=include
CC = clang
USERFLAGS+=
override CFLAGS+=-I$(IDIR) -g -Wall -Wpedantic $(USERFLAGS) -std=c11 -Wformat-extra-args
PEDANTIC_CFLAGS=-std=c11 -Werror -Wpedantic -Wall -Wextra -Wformat=2 -O -Wuninitialized -Winit-self -Wswitch-enum -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wno-long-long -Wglobal-constructors -Wshorten-64-to-32
TESTS := test1 test2 test3 test4 test5 testadvanced1 testadvanced2 testadvanced3 testadvanced4 testadvanced5 testadvanced6 testadvanced7
GOJASM ?= tools/gojasm
ODIR=obj
LDIR =lib
SRCDIR=src
TSTDIR=tests
LIBS=-lm -ldl
DEBUGGER_LIBS=`cat debugger_libs.txt`
GUI_LIBS=`cat gui_libs.txt`
DEPS = $(wildcard $(IDIR)/*.h)
SRCS = $(wildcard $(SRCDIR)/*.c)
_OBJ = $(patsubst $(SRCDIR)/%,$(ODIR)/%,$(SRCS:.c=.o))
OBJ = $(filter-out $(ODIR)/main.o $(ODIR)/debugger.o $(ODIR)/gui.o,$(_OBJ))
DEPS2 := $(OBJ:.o=.d)
all: ijvm
$(OBJ) $(ODIR)/main.o $(ODIR)/debugger.o $(ODIR)/gui.o: $(DEPS)
-include $(DEPS2)
$(ODIR)/%.o: $(SRCDIR)/%.c
+@[ -d $(ODIR) ] || mkdir -p $(ODIR)
$(CC) -MMD $(CFLAGS) -c -o $@ $<
ijvm: $(OBJ) $(ODIR)/main.o
echo $(SRCS)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
debugger: $(OBJ) $(ODIR)/debugger.o
echo $(SRCS)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) $(DEBUGGER_LIBS)
gui: $(OBJ) $(ODIR)/gui.o
echo $(SRCS)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) $(GUI_LIBS)
# computes grade of basic and advanced tests, requires python
grade:
python3 tools/grade.py
clean:
-rm -f $(ODIR)/*.o *~ core.* $(INCDIR)/*~
-rm -f $(ODIR)/*.d
-rm -f ijvm gui debugger
-rm -f test1 test2 test3 test4 test5 testadvanced* testbonusheap testbonustail testbonusgarbage
-rm -f dist.zip
-rm -rf profdata/
-rm -rf obj/ *.dSYM
-rm -f valgrind-*.txt
tools:
make -C tools/
files/%.ijvm: files/%.jas
which $(GOJASM) # Check that GoJasm binary exists
echo $(GOJASM) -o $@ $<
JAS_FILES = $(wildcard files/task*/*.jas files/advanced/*.jas)
IJVM_FILES = $(JAS_FILES:.jas=.ijvm)
ijvm_binaries: tools $(IJVM_FILES)
UNAME_S := $(shell uname -s)
zip:
zip dist.zip bonus.md `find src include -iname "*.c" -o -iname "*.h"`
test%: $(OBJ) $(TSTDIR)/test%.c
$(CC) $(CFLAGS) $(LIBS) -o $@ $^
run_test%: test%
./$<
testbasic: run_test1 run_test2 run_test3 run_test4 run_test5
testadvanced: run_testadvanced1 run_testadvanced2 run_testadvanced3 run_testadvanced4 run_testadvanced5 run_testadvanced6 run_testadvanced7 run_testadvanced8
testall: testbasic testadvanced
build_tests: test1 test2 test3 test4 test5 testadvanced1 testadvanced2 testadvanced3 testadvanced4 testadvanced5 testadvanced6 testadvanced7 testadvanced8
# Uses LLVM sanitizers
testasan: CC=clang
testasan: CFLAGS += -fsanitize=undefined,address
testasan: clean testall
testmemsan: CC=clang
testmemsan: CFLAGS += -fsanitize=undefined,memory
testmemsan: clean testall
testsanitizers: testasan testmemsan
pedantic: CFLAGS+=$(PEDANTIC_CFLAGS)
pedantic: clean ijvm
testleaks: clean build_tests
for test in $(TESTS); do \
valgrind --leak-check=full ./$$test; \
done
# redirects valgrind output to file
saveleaks: clean build_tests
for test in $(TESTS); do \
valgrind --leak-check=full ./$$test 2> valgrind-$$test.txt; \
done
coverage: CFLAGS+=-fprofile-instr-generate -fcoverage-mapping
coverage: CC=clang
coverage: clean ijvm build_tests
LLVM_PROFILE_FILE="profdata/profile-%p.profraw" make testall
llvm-profdata merge -sparse profdata/*.profraw -o profdata/testcoverage.profdata
llvm-cov report ./ijvm -instr-profile=profdata/testcoverage.profdata