-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuilding.mk
39 lines (32 loc) · 1.32 KB
/
building.mk
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
### Uncomment this to run Clang's static analyzer while building; this makes the build slower.
ANALYZER:=scan-build --status-bugs
### Compiler settings
CC:=clang
CFLAGS :=-std=gnu11 -g -lm
WARNINGS :=-Weverything -Werror
INCLUDES :=-I common/include
LIBS := common/src/*.c
EXTRA_FLAGS:=-D TEST_OUTPUT
COMPILE:=$(ANALYZER) $(CC) $(CFLAGS) $(WARNINGS) $(EXTRA_FLAGS) $(INCLUDES) $(LIBS)
### Uncomment this if you want to run the tests; this makes the build slower.
RUN_TESTS:=true
### Uncomment this to do memory leak analysis while running; this makes tests run (slightly) slower
VALGRIND := valgrind -q --leak-check=full --show-leak-kinds=all --track-origins=yes --error-exitcode=42
# Each individual make target runs a build target
# matching to this to produce the compiled binary.
%-build: clean
$(eval CHAPTER := ch-$(shell echo $@ | sed -E 's/\.([0-9]*|[0-9]*-[0-9]*)-build//g'))
$(eval EXERCISE := $(shell echo $@ | sed 's/-build//'))
$(COMPILE) -I $(CHAPTER)/include $(CHAPTER)/src/$(EXERCISE).c -o bin/$(EXERCISE)
### Exercises that do not need any input for testing can use this target for testing;
### otherwise, they will run tests their own way.
%-basic-test:
ifdef RUN_TESTS
$(eval EXERCISE := $(shell echo $@ | sed 's/-basic-test//'))
$(VALGRIND) ./bin/$(EXERCISE)
endif
### Binary cleanup
setup:
-mkdir bin
clean:
-rm -r bin/*