-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
94 lines (68 loc) · 2.44 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
TARGET = bin/tinylisp
SRC = $(subst src/,,$(shell ls src/*.c | grep -v 'tinylisp.c'))
TESTS = $(subst tests/,bin/,$(subst .c,,$(shell ls tests/*.c)))
TOOLS = $(subst tools/,bin/,$(subst .c,,$(shell ls tools/*.c)))
SNIPPETS = $(shell ls snippets/*.lisp)
OBJS = $(addprefix build/,$(subst .c,.o,${SRC}))
OBJSPROFILE = $(subst build/,build/profile-,${OBJS})
OBJSTESTS = $(subst tests/,build/,$(subst .c,.o,${TESTS}))
OBJSTOOLS = $(subst tools/,build/,$(subst .c,.o,${TOOLS}))
CPPFLAGS =
CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -Wno-gnu-union-cast -Werror
LDFLAGS = -lm
VALGRINDFLAGS = --error-exitcode=1 --leak-check=full --show-leak-kinds=all
GPROFFLAGS = -b
ifeq (${BUILD},release)
CFLAGS += -march=native -O2
CPPFLAGS += -DNDEBUG
else
CFLAGS += -g
endif
all: ${TARGET} ${TOOLS}
release:
make "BUILD=release"
# Compile
build/%.o: src/%.c
${CC} -c -o $@ ${CPPFLAGS} ${CFLAGS} $<
build/%.o: tests/%.c
${CC} -c -o $@ -I./lighttest2/ -I./src/ ${CPPFLAGS} ${CFLAGS} $<
build/%.o: tools/%.c
${CC} -c -o $@ -I./src/ ${CPPFLAGS} ${CFLAGS} $<
build/profile-%.o: src/%.c
${CC} -c -o $@ -pg ${CPPFLAGS} ${CFLAGS} $<
build/profile-%.o: tests/%.c
${CC} -c -o $@ -pg -I./lighttest2/ -I./src/ ${CPPFLAGS} ${CFLAGS} $<
build/profile-%.o: tools/%.c
${CC} -c -o $@ -pg -I./src/ ${CPPFLAGS} ${CFLAGS} $<
# Link
bin/profile-%: build/profile-%.o ${OBJSPROFILE}
${CC} -o $@ $^ -pg ${LDFLAGS}
bin/%: build/%.o ${OBJS}
${CC} -o $@ $^ ${LDFLAGS}
# Profile
profile: $(addsuffix .report,$(subst bin/,,${TESTS})) PROFILE $(subst .lisp,.report,${SNIPPETS})
PROFILE: bin/profile-tinylisp $(subst .lisp,.profile,${SNIPPETS})
gprof ${GPROFFLAGS} $^ > $@
snippets/%.profile: snippets/%.lisp bin/profile-tinylisp
./bin/profile-tinylisp < $< && mv gmon.out $@
snippets/%.report: bin/profile-tinylisp snippets/%.profile
gprof ${GPROFFLAGS} $^ > $@
%.profile: bin/profile-%
./$< && mv gmon.out $@
%.report: bin/profile-% %.profile
gprof ${GPROFFLAGS} $^ > $@
.PHONY: all clean mrproper test memtest vtest profile
.PRECIOUS: build/%.o build/profile-%.o bin/profile-% %.profile snippets/%.profile
# Run tests
test: ${TESTS}
for f in $^; do ./$$f || exit 1; done
# Run tests in valgrind
memtest: ${TESTS}
for f in $^; do valgrind ${VALGRINDFLAGS} ./$$f -v && echo || exit 1; done
# Run tests in verbose mode
vtest: ${TESTS}
for f in $^; do ./$$f -v || exit 1; done
clean:
rm -f build/*.o *.profile *.report snippets/*.profile snippets/*.report PROFILE
mrproper: clean
rm -f bin/*