aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 808c71f17b8f7fcd0697b796b1e5364d9565e9be (plain) (blame)
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
TEST += bitfield
TEST += option
TEST += timer
TEST += log
TEST += owning_mutex
TEST += latch

# -- INTERNALS -----------------------------------------------------------------

BINS = $(TEST:%=build/%)
DEPS = $(TEST:%=build/%.d)
RUNS = $(TEST:%=run/%)

# -- FLAGS ---------------------------------------------------------------------

DEPS_GEN  = -MMD
SANITIZER = -fsanitize=address -fsanitize=undefined -fsanitize=leak -fno-omit-frame-pointer

STD      ?= 14
CXXFLAGS  = -Og -g -Wall -Wextra -Werror -I. -std=c++$(STD) $(DEPS_GEN) $(SANITIZER)
LDFLAGS   = $(SANITIZER)

# -- RULES ---------------------------------------------------------------------

default: lint build $(BINS)

run: $(RUNS)

run/%: build build/%
	@echo "==> run $*"
	build/$*

build/%: build/%.o
	$(CXX) -o $@ $< $(LDFLAGS)

build/%.o: test/%.cc
	$(CXX) -c -o $@ $< $(CXXFLAGS)

build:
	mkdir -p build

lint:
	clang-format --dry-run -Werror $(shell find -name '*.cc' -o -name '*.h')
	clang-tidy test/*.cc -- $(CXXFLAGS)

clean:
	$(RM) -r build
	$(RM) compile_commands.json events.json

# Since DEPS files contain rules, include at the end.
-include $(DEPS)

# -- SPECIAL RULES -------------------------------------------------------------

# Generate compile database using bear(1).
bear:
	bear intercept -- $(MAKE) build $(BINS)
	bear citnames

define VARTEST
var-$(1)-$(2):
	@echo "==> VARTEST CXX=$(1) STD=$(2)"
	$(MAKE) clean build CXX=$(1) STD=$(2) $(BINS)
endef

STD_LIST := 14 17 20
CXX_LIST := g++ clang++

# Generate targets for {compiler,std} variant build tests.
$(foreach C,$(CXX_LIST),$(foreach S,$(STD_LIST),$(eval $(call VARTEST,$(C),$(S)))))
# Generate umbrella target to run all variant tests.
vartest: $(foreach C,$(CXX_LIST),$(foreach S,$(STD_LIST),var-$(C)-$(S)))