-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·270 lines (206 loc) · 6.95 KB
/
Copy pathMakefile
File metadata and controls
executable file
·270 lines (206 loc) · 6.95 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#! /usr/bin/make -f
# Makefile -*-makefile-*-
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
NO_COLOR=1
INSTALL_PREFIX?=.install/
BUILD_DIR?=.build
DEST?=$(INSTALL_PREFIX)
CMAKE_FLAGS?=
PYEXECPATH ?= $(shell which python3.13 || which python3.12 || which python3.11 || which python3.10 || which python3.9 || which python3.8 || which python3)
PYTHON ?= $(notdir $(PYEXECPATH))
VENV := .venv
UV := $(shell command -v uv 2> /dev/null)
ACTIVATE := $(UV) run
PYEXEC := $(UV) run python
MARKER=.initialized.venv.stamp
PRE_COMMIT := $(UV) run pre-commit
TARGETS := test clean all ctest
export
.update-submodules:
git submodule update --init --recursive
touch .update-submodules
.gitmodules: .update-submodules
CONFIG?=Asan
export
ifeq ($(strip $(TOOLCHAIN)),)
_build_name?=build-system/
_build_dir?=.build/
_local_toolchain?=$(CURDIR)/cmake/toolchain.cmake
else
_build_name?=build-$(TOOLCHAIN)
_build_dir?=.build/
_local_toolchain?=$(CURDIR)/cmake/$(TOOLCHAIN)-toolchain.cmake
endif
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan;Gcov"
_build_path?=$(_build_dir)/$(_build_name)
_build_path:=$(subst //,/,$(_build_path))
_build_path:=$(patsubst %/,%,$(_build_path))
VCPKG ?= $(shell command -v vcpkg 2> /dev/null)
ifeq ($(VCPKG),)
_cmake_top_level?="./cmake/use-fetch-content.cmake"
_toolchain:=$(_local_toolchain)
_args=-DBEMANINFRA_googletest_REPO=file:///home/sdowney/bld/googletest/googletest.git
else
_vcpkg_toolchain:=$(VCPKG_ROOT)/scripts/buildsystems/vcpkg.cmake
_cmake_top_level?=$(_vcpkg_toolchain)
export PROJECT_VCPKG_TOOLCHAIN=$(_local_toolchain)
_toolchain:=$(_local_toolchain)
_args=-DVCPKG_OVERLAY_TRIPLETS=$(CURDIR)/cmake -DVCPKG_TARGET_TRIPLET=x64-linux-custom
# for debugging add -DVCPKG_INSTALL_OPTIONS="--debug"
endif
CMAKE ?= $(UV) run cmake
CTEST ?= $(UV) run ctest
define run_cmake =
$(CMAKE) \
-G "Ninja Multi-Config" \
-DCMAKE_CONFIGURATION_TYPES=$(_configuration_types) \
-DCMAKE_INSTALL_PREFIX=$(abspath $(INSTALL_PREFIX)) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-DCMAKE_PREFIX_PATH=$(CURDIR)/infra/cmake \
-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=$(_cmake_top_level) \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_TOOLCHAIN_FILE=$(_toolchain) \
$(_args) \
$(_cmake_args) \
$(CURDIR)
endef
default: test
.PHONY: default
$(_build_path):
mkdir -p $(_build_path)
$(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules $(VENV)
cd $(_build_path) && $(run_cmake)
$(_build_path)/compile_commands.json : $(_build_path)/CMakeCache.txt
.PHONY: compile_commands.json
compile_commands.json: $(_build_path)/compile_commands.json
compile_commands.json: ## symlink the current compile commands db
if [ "$(shell readlink compile_commands.json)" != "$(_build_path)/compile_commands.json" ] ; then \
ln -sf $(_build_path)/compile_commands.json ; \
fi
TARGET:=all
.PHONY: TARGET
.PHONY: compile
compile: $(_build_path)/CMakeCache.txt
compile: compile_commands.json
compile: ## Compile the project
$(CMAKE) --build $(_build_path) --config $(CONFIG) --target all -- -k 0
.PHONY: compile-headers
compile-headers: $(_build_path)/CMakeCache.txt ## Compile the headers
$(CMAKE) --build $(_build_path) --config $(CONFIG) --target all_verify_interface_header_sets -- -k 0
.PHONY: install
install: $(_build_path)/CMakeCache.txt compile ## Install the project
$(CMAKE) --install $(_build_path) --config $(CONFIG) --component beman.expected --verbose
.PHONY: clean-install
clean-install:
-rm -rf .install
.PHONY: realclean
realclean: clean-install
.PHONY: ctest
ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build
$(CTEST) --test-dir $(_build_path) --output-on-failure -C $(CONFIG)
.PHONY: ctest_
ctest_ : compile
$(CTEST) --test-dir $(_build_path) --output-on-failure -C $(CONFIG)
.PHONY: test
test: ctest_ ## Rebuild and run tests
.PHONY: cmake
cmake: | $(_build_path)
cd $(_build_path) && ${run_cmake}
.PHONY: clean
clean: $(_build_path)/CMakeCache.txt ## Clean the build artifacts
$(CMAKE) --build $(_build_path) --config $(CONFIG) --target clean
.PHONY: realclean
realclean: ## Delete the build directory
rm -rf $(_build_path)
.PHONY: env
env:
$(foreach v, $(.VARIABLES), $(info $(v) = $($(v))))
.PHONY: papers
papers:
$(MAKE) -C papers/P2988 papers
.DEFAULT: $(_build_path)/CMakeCache.txt ## Other targets passed through to cmake
$(CMAKE) --build $(_build_path) --config $(CONFIG) --target $@ -- -k 0
.PHONY: all
all: compile
.PHONY: venv
venv: ## Create python virtual env
venv: $(VENV)/$(MARKER)
.PHONY: clean-venv
clean-venv:
clean-venv: ## Delete python virtual env
-rm -rf $(VENV)
realclean: clean-venv
.PHONY: show-venv
show-venv: venv
show-venv: ## Debugging target - show venv details
$(PYEXEC) -c "import sys; print('Python ' + sys.version.replace('\n',''))"
@echo venv: $(VENV)
uv.lock: pyproject.toml
$(UV) lock
$(VENV):
$(UV) venv --python $(PYTHON)
$(VENV)/$(MARKER): uv.lock | $(VENV)
$(UV) sync
touch $(VENV)/$(MARKER)
.PHONY: dev-shell
dev-shell: venv
dev-shell: ## Shell with the venv activated
$(ACTIVATE) $(notdir $(SHELL))
.PHONY: bash zsh
bash zsh: venv
bash zsh: ## Run bash or zsh with the venv activated
$(ACTIVATE) $@
.PHONY: lint
lint: venv
lint: ## Run all configured tools in pre-commit
$(PRE_COMMIT) run -a
.PHONY: lint-manual
lint-manual: venv
lint-manual: ## Run all manual tools in pre-commit
$(PRE_COMMIT) run --hook-stage manual -a
.PHONY: coverage
coverage: ## Build and run the tests with the GCOV profile and process the results
coverage: venv $(_build_path)/CMakeCache.txt
$(CMAKE) --build $(_build_path) --config Gcov
$(ACTIVATE) ctest --build-config Gcov --output-on-failure --test-dir $(_build_path)
$(CMAKE) --build $(_build_path) --config Gcov --target process_coverage
.PHONY: view-coverage
view-coverage: ## View the coverage report
sensible-browser $(_build_path)/coverage/coverage.html
.PHONY: docs
docs: ## Build the docs with Doxygen
doxygen docs/Doxyfile
.PHONY: mrdocs
mrdocs: ## Build the docs with Doxygen
-rm -rf docs/adoc
cd docs && NO_COLOR=1 mrdocs mrdocs.yml 2>&1 | sed 's/\x1b\[[0-9;]*m//g'
find docs/adoc -name '*.adoc' | xargs asciidoctor
.PHONY: testinstall
testinstall: install
testinstall: ## Test the installed package
mkdir -p installtest
$(CMAKE) -S installtest -B installtest/.build
$(CMAKE) --build installtest/.build --target test
.PHONY: clean-testinstall
clean-testinstall:
-rm -rf installtest/.build
realclean: clean-testinstall
ifeq ($(UV),)
define install_uv_cmd
pipx install uv
endef
define uv_error_message
'uv' command not found.
Please install uv or set the UV variable to the path of the uv binary.
The makefile target "install-uv" will run ``$(install_uv_cmd)''
endef
$(error "$(uv_error_message)")
endif
.PHONY: install-uv
install-uv: ## install uv via `pipx install uv`
$(install_uv_cmd)
# Help target
.PHONY: help
help: ## Show this help.
@awk 'BEGIN {FS = ":.*?## "} /^[.a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort