-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
63 lines (49 loc) · 1.88 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
CC = gcc
CFLAGS = -std=c99 -O2 -flto -pedantic -Wall
LDLIBS = -lm
ifeq ($(debug), 1)
# -Wno-unknown-warning-option is given so that a user can specify both
# CC=clang and debug=1 as command-line arguments at the same time.
# -Wunreachable-code has no effect in gcc, but in clang it does.
CFLAGS += \
-g -save-temps=obj \
-fsanitize=address,float-cast-overflow,float-divide-by-zero,undefined \
-Wno-unknown-warning-option -Wno-type-limits -Werror -Wextra \
-Wbad-function-cast -Wcast-align=strict -Wcast-qual -Wconversion \
-Wdouble-promotion -Wduplicated-branches -Wduplicated-cond -Wformat=2 \
-Winit-self -Winline -Winvalid-pch -Wjump-misses-init \
-Wlogical-not-parentheses -Wlogical-op -Wmissing-declarations \
-Wmissing-format-attribute -Wmissing-include-dirs \
-Wmissing-prototypes -Wnested-externs -Wnull-dereference \
-Wold-style-definition -Wredundant-decls -Wshadow -Wstrict-overflow=2 \
-Wstrict-prototypes -Wundef -Wunreachable-code -Wwrite-strings
endif
programs := $(sort $(wildcard d[0-9][0-9]*.c))
stems := $(programs:%.c=%)
bins := $(stems:%=bin/%)
objs := $(programs:%.c=obj/%.o)
module_headers := $(sort $(wildcard *.h))
module_objs := $(module_headers:%.h=obj/%.o)
labels := $(foreach stem,$(stems),$(firstword $(subst _, ,$(stem))))
days := $(subst d,,$(labels))
days += $(patsubst 0%,%,$(filter 0%,$(days)))
.PHONY: all run $(days) test time clean
all: $(bins)
# The mv command is for compatibility with Windows.
$(bins): bin/%: obj/%.o $(module_objs) | bin
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)
@[ ! -e [email protected] ] || mv [email protected] $@
$(objs) $(module_objs): obj/%.o: %.c $(module_headers) | obj
$(CC) $(CFLAGS) -c -o $@ $<
run: $(bins)
@sh run.sh
$(days): $(bins)
@sh run.sh $@
test: $(bins)
@sh test/run_all.sh
time: $(bins)
@sh run.sh --time
bin obj:
mkdir $@
clean:
rm -f bin/* obj/*