-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
77 lines (61 loc) · 1.85 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
# User-customizable variables:
CXX ?= c++
CXX_STD ?= c++11
CXXFLAGS ?= -I relacy/fakestd -O1 -std=$(CXX_STD)
DEPFLAGS ?= -MD -MF $(@).d -MP -MT $(@)
build_dir = build
.SECONDARY:
example_programs = cli_ws_deque
test_programs = \
ntest/ntest \
defaulted_debug_info \
atomic_init \
cxx11_thread \
new_delete \
debug_info
example_exe_files = $(foreach name,$(example_programs),$(build_dir)/example/$(name)/$(name))
test_exe_files = $(foreach name,$(test_programs),$(build_dir)/test/$(name))
main_test_exe_files = $(build_dir)/test/main
exe_files = $(example_exe_files) $(test_exe_files) $(main_test_exe_files)
o_files = $(exe_files:=.cpp.o)
ansi_term_csi = [
ansi_term_bold = $(ansi_term_csi)1m
ansi_term_green = $(ansi_term_csi)32m
ansi_term_red = $(ansi_term_csi)31m
ansi_term_reset = $(ansi_term_csi)m
COMPILE.cpp = $(CXX) $(DEPFLAGS) $(CXXFLAGS) -c
LINK.cpp = $(CXX) $(CXXFLAGS)
.PHONY: all
all: examples tests main_test
.PHONY: examples tests
examples: $(example_exe_files)
tests: $(test_exe_files)
main_test: $(main_test_exe_files)
.PHONY: check
check: check-examples check-tests
.PHONY: check-examples check-tests
check-examples: $(example_exe_files:=.check-result)
check-tests: $(test_exe_files:=.check-result)
$(build_dir)/%.check-result: $(build_dir)/% always-run
@ \
printf '%s%s ...%s\n' $(ansi_term_bold) $(*) $(ansi_term_reset) >&2; \
$(<); \
status="$${?}"; \
printf %d "$${status}" >$(@); \
if [ "$${status}" -eq 0 ]; then \
printf '%s%s %s%s\n' $(ansi_term_green) $(*) OK $(ansi_term_reset); \
else \
printf '%s%s %s%s\n' $(ansi_term_red) $(*) FAIL $(ansi_term_reset); \
fi >&2; \
exit "$${status}"
$(build_dir)/%: $(build_dir)/%.cpp.o
$(LINK.cpp) $(^) -o $(@)
$(build_dir)/%.cpp.o: %.cpp
@mkdir -p $(dir $(@))
$(COMPILE.cpp) -o $(@) $(<)
.PHONY: clean
clean:
rm -fr -- $(build_dir)/
.PHONY: always-run
always-run:
-include $(o_files:=.d)