-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
125 lines (85 loc) · 2.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
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
tests := $(patsubst test_%.cpp, %, $(wildcard test_*.cpp))
mode ?= debug
show_mode_and_goals := $(shell >&2 printf -- "\e[4m%s: [%s]\e[0m\n" "$$(echo $(mode) | tr [:lower:] [:upper:] )" "$(MAKECMDGOALS)")
# Compiler to use
CXX ?= g++
# Proxy which prettifies g++ output if prettifier is found, and deletes output file if compilation failed
define_cc_proxy = function cc_proxy {( set -euo pipefail; echo "$(CXX) $$*"; $(CXX) 2>&1 "$$@" | ( which c++-color &>/dev/null && c++-color || cat ) || { rm -f -- "$@"; false; }; )}
cc := cc_proxy
cc_base := -pipe -pedantic -std=c++14
ld_base := -pipe -lpthread
ifeq ($(mode),debug)
cc_opts := $(cc_base) -Wall -Wextra -Wno-unused-parameter -Og -g -DDEBUG
ld_opts := $(ld_base) -Wall
else
ifeq ($(mode),release)
cc_opts := $(cc_base) -Wall -Werror -flto -fPIC -O3
ld_opts := $(ld_base) -Wall -Werror -flto -s
else
$(error "Unknown mode: %(mode)")
endif
endif
ifneq ($(nowarn),)
cc_opts := $(filter-out -Wall, $(cc_opts)) -w
endif
test := test
dep := dep/$(mode)
out := out/$(mode)
obj := obj/$(mode)
outdirs := test/ dep/ out/ obj/
.PHONY: default syntax clean list-deps stats tests
.SECONDARY:
.ONESHELL:
.SHELLFLAGS: -euo pipefail -c
.DEFAULT: tests
syntax:
@$(define_cc_proxy)
$(cc) $(cc_base) -Wall -fsyntax-only $(filter-out test_%, $(wildcard *.cpp))
clean:
rm -rf -- $(outdirs)
# Run all tests
tests: $(tests:%=test/%)
@for test in $^; do
printf -- "Running test: '%s'\n" "$${test}"
"$${test}" --test-silent-if-perfect
done
tests-loud: $(tests:%=test/%)
@for test in $^; do
printf -- "Running test: '%s'\n" "$${test}"
"$${test}"
done
# Fun
list-deps:
@perl -ne 'print $$1."\n" if m/#include <([^>]+)>/' *.h *.cpp *.tcc | sort | uniq
stats:
@(
printf -- "Lines\tChars\tUnit name\n"
for root in $$(ls *.{cpp,tcc,h} | sed -e 's/\..*$$//g' | sort -u); do
printf -- "%s\t%s\t%s\n" $$(cat $${root}.* | wc -cl) "$${root}"
done | sort -rnt$$'\t';
) | column -t -o' | ' -s$$'\t'
# Directories
$(test) $(dep) $(out) $(obj):
mkdir -p $@
# Object files and autodependencies
$(obj)/%.o: %.cpp | $(obj) $(dep)
@$(define_cc_proxy)
$(cc) $(cc_opts) -x c++ $< -MMD -MF $(dep)/$*.d -MQ $@ -c -o $@
# Projects
$(out)/%: $(obj)/%.o | $(out)
@$(define_cc_proxy)
$(cc) $(ld_opts) $^ -o $@
# Test dependencies
$(test)/promise: $(obj)/promise.o
$(test)/event_loop: $(obj)/event_loop.o $(obj)/starter_pistol.o
$(test)/task: $(obj)/promise.o $(obj)/decimal.o $(obj)/event_loop.o $(obj)/starter_pistol.o
$(test)/functional: $(obj)/promise.o $(obj)/event_loop.o $(obj)/starter_pistol.o
$(test)/decimal: $(obj)/decimal.o
$(test)/promise_stream: $(obj)/promise_stream.o $(obj)/promise.o
$(test)/task_stream: $(obj)/promise.o $(obj)/promise_stream.o $(obj)/event_loop.o $(obj)/starter_pistol.o
# Test binaries
$(test)/%: $(obj)/test_%.o $(obj)/assertion.o | $(test)
@$(define_cc_proxy)
$(cc) $(ld_opts) $^ -o $@
# Autodependencies
-include $(wildcard $(dep)/*.d)