-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
192 lines (176 loc) · 6.2 KB
/
Makefile
File metadata and controls
192 lines (176 loc) · 6.2 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
NAME = libtpp
BUILD_DIR = build
MODULES = data_structures design_patterns tpp_iostream mathematics network threading
MODULE_LIBS = \
$(BUILD_DIR)/src/data_structures/libdata_structures.a \
$(BUILD_DIR)/src/design_patterns/libdesign_patterns.a \
$(BUILD_DIR)/src/iostream/libtpp_iostream.a \
$(BUILD_DIR)/src/mathematics/libmathematics.a \
$(BUILD_DIR)/src/network/libnetwork.a \
$(BUILD_DIR)/src/threading/libthreading.a
LIB_PATH = $(BUILD_DIR)/$(NAME).a
TEST_TARGETS = \
test_data_structures \
test_memento \
test_observer \
test_singleton \
test_state_machine \
test_threading \
test_network \
test_mathematics
EXAMPLE_TARGETS = \
perlin_noise_visualization
TEST_JOBS ?= $(shell nproc)
UBSAN_BUILD_DIR = $(BUILD_DIR)/ubsan
.PHONY: all
all: $(LIB_PATH)
@ln -sf $(BUILD_DIR)/compile_commands.json compile_commands.json
.PHONY: $(LIB_PATH)
$(LIB_PATH): cmake_configure
@echo "[cmake] build all module libraries"
@cmake --build $(BUILD_DIR) --target $(MODULES) -- -s
@echo "[ar] merge module archives -> $(LIB_PATH)"
@{ \
echo "create $(NAME).a"; \
echo "addlib src/data_structures/libdata_structures.a"; \
echo "addlib src/design_patterns/libdesign_patterns.a"; \
echo "addlib src/iostream/libtpp_iostream.a"; \
echo "addlib src/mathematics/libmathematics.a"; \
echo "addlib src/network/libnetwork.a"; \
echo "addlib src/threading/libthreading.a"; \
echo "save"; \
echo "end"; \
} | (cd $(BUILD_DIR) && ar -M)
@ranlib $(LIB_PATH)
@cp -f $(LIB_PATH) ./$(NAME).a
@echo "[ar] library $(NAME) created successfully"
.PHONY: $(MODULES)
$(MODULES): cmake_configure
@echo "[cmake] build module $@"
@cmake --build $(BUILD_DIR) --target $@ -- -s
.PHONY: re
re: fclean all
.PHONY: clean
clean:
@if [ -d "$(BUILD_DIR)" ]; then \
$(MAKE) -C $(BUILD_DIR) clean || true; \
fi
.PHONY: fclean
fclean:
@rm -f compile_commands.json
@cmake -E remove_directory $(BUILD_DIR) || true
.PHONY: tests
tests: cmake_configure
@echo "[cmake] build all test targets"
@cmake --build $(BUILD_DIR) --target libftpp_tests -- -s >/tmp/libtpp-build-tests.log 2>&1 || { \
echo "[cmake] build failed, details:"; \
cat /tmp/libtpp-build-tests.log; \
exit 1; \
}
@echo "[ctest] run test modules in parallel (module-jobs=$(TEST_JOBS))"
@python3 scripts/run_tests_pretty.py \
--build-dir $(BUILD_DIR) \
--jobs $(TEST_JOBS) \
$(TEST_TARGETS)
.PHONY: memcheck
memcheck: cmake_configure
@command -v valgrind >/dev/null 2>&1 || { \
echo "[error] valgrind not found. Install it first (e.g. sudo apt install valgrind)."; \
exit 1; \
}
@echo "[cmake] build all test targets"
@cmake --build $(BUILD_DIR) --target libftpp_tests -- -s >/tmp/libtpp-build-tests.log 2>&1 || { \
echo "[cmake] build failed, details:"; \
cat /tmp/libtpp-build-tests.log; \
exit 1; \
}
@echo "[ctest] valgrind memcheck (pretty output)"
@python3 scripts/run_tests_pretty.py \
--build-dir $(BUILD_DIR) \
--jobs $(TEST_JOBS) \
--full-detail \
--mode memcheck \
$(TEST_TARGETS)
.PHONY: ubsan_tests
ubsan_tests:
@echo "[cmake] configure UBSan build"
@cmake -B$(UBSAN_BUILD_DIR) -S . -DLIBFTPP_ENABLE_UBSAN=ON
@echo "[cmake] build all test targets (UBSan)"
@cmake --build $(UBSAN_BUILD_DIR) --target libftpp_tests -- -s
@echo "[ctest] run UBSan-enabled tests (pretty output)"
@python3 scripts/run_tests_pretty.py \
--build-dir $(UBSAN_BUILD_DIR) \
--jobs $(TEST_JOBS) \
$(TEST_TARGETS)
.PHONY: check_all
check_all:
@rc=0; \
echo "[check_all] ===== tests ====="; \
$(MAKE) tests TEST_JOBS=$(TEST_JOBS) || rc=1; \
echo "[check_all] ===== memcheck ====="; \
$(MAKE) memcheck TEST_JOBS=$(TEST_JOBS) || rc=1; \
echo "[check_all] ===== ubsan_tests ====="; \
$(MAKE) ubsan_tests TEST_JOBS=$(TEST_JOBS) || rc=1; \
if [ $$rc -ne 0 ]; then \
echo "[check_all] completed with failures"; \
exit $$rc; \
fi; \
echo "[check_all] all stages passed"
.PHONY: examples
examples: cmake_configure
@echo "[cmake] build example targets"
@cmake --build $(BUILD_DIR) --target $(EXAMPLE_TARGETS) -- -s
.PHONY: $(EXAMPLE_TARGETS)
$(EXAMPLE_TARGETS): cmake_configure
@echo "[cmake] build example target $@"
@cmake --build $(BUILD_DIR) --target $@ -- -s
# ---- test by module ----
.PHONY: $(TEST_TARGETS)
$(TEST_TARGETS): cmake_configure
@echo "[cmake] build test target $@"
@cmake --build $(BUILD_DIR) --target $@ -- -s
@echo "[ctest] run tests with prefix $@"
@cd $(BUILD_DIR) && ctest -R "^$@"
.PHONY: help
help:
@echo "Usage: make <target>"
@echo ""
@echo "Main targets:"
@echo " all - Configure (if needed), build modules, and pack $(NAME)"
@echo " tests - Build tests, run modules in parallel, show . / x progress"
@echo " memcheck - Build tests and run valgrind memcheck through ctest"
@echo " ubsan_tests - Configure UBSan build and run all tests"
@echo " check_all - Run tests, memcheck, and UBSan checks in sequence (continue on failure)"
@echo " examples - Build all example executables"
@echo " clean - Clean build artifacts inside $(BUILD_DIR)"
@echo " fclean - Remove $(BUILD_DIR) and compile_commands.json"
@echo " re - fclean + all"
@echo ""
@echo "Module build targets:"
@$(foreach m,$(MODULES),echo " $(m)$(shell printf '\n')";)
@echo ""
@echo "Test targets (per group):"
@$(foreach t,$(TEST_TARGETS),echo " $(t)$(shell printf '\n')";)
@echo ""
@echo "Example targets:"
@$(foreach e,$(EXAMPLE_TARGETS),echo " $(e)$(shell printf '\n')";)
@echo ""
@echo "Examples:"
@echo " make examples # build all examples"
@echo " make perlin_noise_visualization"
@echo " make tests TEST_JOBS=8 # run all tests with 8 parallel jobs"
@echo " make memcheck # valgrind memory leak checks"
@echo " make ubsan_tests # undefined behavior checks"
@echo " make check_all # tests + memcheck + UBSan"
@echo " make threading # build threading module"
@echo " make test_threading # build and run threading-related tests"
@echo " make test_data_structures"
@echo " make test_mathematics"
.PHONY: cmake_configure
cmake_configure:
@if [ ! -f "$(BUILD_DIR)/CMakeCache.txt" ]; then \
echo "[cmake] configure..."; \
else \
echo "[cmake] refresh configure..."; \
fi
@cmake -B$(BUILD_DIR) -S .