aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Makefile
blob: 608bb09584eb8d361241814e53a734bd281215e3 (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
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
126
127
128
129
130
131
include prelude.mk

COMPILER        ?= clang
CONFIGURATION   ?= debug
DEFAULT_HOST    ?= 127.0.0.1
DEFAULT_PORT    ?= 5556
COVERAGE        ?=
STATIC_ANALYZER ?=

$(eval $(call noexpand,COMPILER))
$(eval $(call noexpand,CONFIGURATION))
$(eval $(call noexpand,DEFAULT_HOST))
$(eval $(call noexpand,DEFAULT_PORT))
$(eval $(call noexpand,COVERAGE))
$(eval $(call noexpand,STATIC_ANALYZER))

src_dir   := $(abspath .)
build_dir := $(src_dir)/build

.PHONY: all
all: debug

.PHONY: DO
DO:

.PHONY: clean
clean:
	rm -rf -- '$(call escape,$(build_dir))'

.PHONY: build
build:
	@echo -----------------------------------------------------------------
	@echo 'Building: $(call escape,$(CONFIGURATION))'
	@echo -----------------------------------------------------------------
	@mkdir -p -- '$(call escape,$(build_dir)/cmake)'
	cmake \
		-G 'Unix Makefiles' \
		-D 'CMAKE_C_COMPILER=$(call escape,$(COMPILER))' \
		-D 'CMAKE_BUILD_TYPE=$(call escape,$(CONFIGURATION))' \
		-D 'CMAKE_INSTALL_PREFIX=$(call escape,$(build_dir)/install)' \
		-D 'DEFAULT_HOST=$(call escape,$(DEFAULT_HOST))' \
		-D 'DEFAULT_PORT=$(call escape,$(DEFAULT_PORT))' \
		-D 'TEST_REPORT_DIR=$(call escape,$(build_dir)/test_report)' \
		-D 'COVERAGE=$(call escape,$(COVERAGE))' \
		-D 'STATIC_ANALYZER=$(call escape,$(STATIC_ANALYZER))' \
		-D 'FLAME_GRAPHS_DIR=$(call escape,$(build_dir)/flame_graphs)' \
		-S '$(call escape,$(src_dir))' \
		-B '$(call escape,$(build_dir)/cmake)'
	cmake --build '$(call escape,$(build_dir)/cmake)' -- -j

.PHONY: debug
debug debug/%: CONFIGURATION := debug
debug debug/%: build_dir     := $(build_dir)/debug
debug: build

.PHONY: release
release release/%: CONFIGURATION := release
release release/%: build_dir     := $(build_dir)/release
release: build

# Coverage report depends on GCC debug data.
.PHONY: coverage
coverage coverage/%: CONFIGURATION := debug
coverage coverage/%: COMPILER      := gcc
coverage coverage/%: COVERAGE      := 1
coverage coverage/%: build_dir     := $(build_dir)/coverage
coverage: build coverage/test
	@echo -----------------------------------------------------------------
	@echo Generating code coverage report
	@echo -----------------------------------------------------------------
	@mkdir -p -- '$(call escape,$(build_dir))/html'
	gcovr --html-details '$(call escape,$(build_dir))/html/index.html' --print-summary
ifndef CI
	xdg-open '$(call escape,$(build_dir))/html/index.html' &> /dev/null
endif

# This a separate target, because CMake is kinda dumb; if you run `make debug`
# and then `make debug COMPILER=gcc STATIC_ANALYZER=1`, it'll run a rebuild,
# but won't include the -fanalyzer option for some reason.
.PHONY: analyzer
analyzer analyzer/%: CONFIGURATION   := debug
analyzer analyzer/%: COMPILER        := gcc
analyzer analyzer/%: STATIC_ANALYZER := 1
analyzer analyzer/%: build_dir       := $(build_dir)/analyzer
analyzer: build

%/install: % DO
	cmake --install '$(call escape,$(build_dir))/cmake'

%/test: DO
	@echo -----------------------------------------------------------------
	@echo Running tests
	@echo -----------------------------------------------------------------
	ctest --test-dir '$(call escape,$(build_dir))/cmake' \
		--verbose --tests-regex python_tests_default

%/report: DO
	@echo -----------------------------------------------------------------
	@echo Generating test report
	@echo -----------------------------------------------------------------
	ctest --test-dir '$(call escape,$(build_dir))/cmake' \
		--verbose --tests-regex python_tests_report
ifndef CI
	xdg-open '$(call escape,$(build_dir))/test_report/index.html' &> /dev/null
endif

# A subset of tests, excluding long-running stress tests.
%/sanity: DO
	@echo -----------------------------------------------------------------
	@echo Running sanity tests
	@echo -----------------------------------------------------------------
	ctest --test-dir '$(call escape,$(build_dir))/cmake' \
		--verbose --tests-regex python_tests_sanity

# Same, but run under Valgrind.
%/valgrind: DO
	@echo -----------------------------------------------------------------
	@echo Running sanity tests w/ Valgrind
	@echo -----------------------------------------------------------------
	ctest --test-dir '$(call escape,$(build_dir))/cmake' \
		--verbose --tests-regex python_tests_valgrind

# When building a Docker image for a different platform, exclude stress tests:
# they simply take way too long.

%/flame_graphs: DO
	@echo -----------------------------------------------------------------
	@echo Generating flame graphs
	@echo -----------------------------------------------------------------
	ctest --test-dir '$(call escape,$(build_dir))/cmake' \
		--verbose --tests-regex python_tests_flame_graphs