Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·530 lines (435 loc) · 17.7 KB
/
Copy pathMakefile
File metadata and controls
executable file
·530 lines (435 loc) · 17.7 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
#! /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=
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) --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: wording ## Regenerate the wording if needed, then rebuild the paper(s)
$(MAKE) -C papers papers
# ---- Generated [expected] wording ------------------------------------------
#
# The three annotated headers are one specgen document each and one paper: a
# single invocation renders them together, so --validate sees the paper-wide
# union of documented names and a name specified by a sibling header is not
# foreign.
#
# specgen writes the fragments; this makefile assembles expected.tex from them,
# because the paper's clause order is not the headers' declaration order and
# cannot be. bad_expected_access<void> is the base class of
# bad_expected_access<E>, so the header has to define it first, while the draft
# states the primary template first. $(WORDING_CLAUSES) is where that one
# divergence is written down.
SPECGEN ?= specgen
WORDING_HEADERS := $(addprefix include/beman/expected/, \
unexpected.hpp bad_expected_access.hpp expected.hpp)
# In the draft's clause order, by stable name. These are the fragments that
# become expected.tex; specgen also writes one *.root.tex per document, holding
# the exposition-only helpers that sit outside every clause. The draft states
# those inline in the clause that uses them -- reinit-expected inside
# [expected.object.assign]'s own intro -- so they are deliberately not part of
# the assembled wording.
WORDING_CLAUSES := \
expected.general \
expected.syn \
expected.unexpected \
expected.bad \
expected.bad.void \
expected.expected \
expected.void \
expected.ref
WORDING_DIR := papers/wording
WORDING_FRAGMENTS := \
$(addprefix $(WORDING_DIR)/fragments/,$(addsuffix .tex,$(WORDING_CLAUSES)))
# The wording shows the standard's expansion of a configuration macro, not
# whichever one the standard library specgen's Clang finds happens to give:
# BEMAN_EXPECTED_CONSTEXPR_EXCEPTION is `constexpr` in the draft, which is
# what this feature-test macro selects. The value is libstdc++ 16's.
SPECGEN_CLANG_ARGS := -std=c++2c -Iinclude \
-D__cpp_lib_constexpr_exceptions=202502L
ifneq ($(SPECGEN_GCC_TOOLCHAIN),)
SPECGEN_CLANG_ARGS += --gcc-toolchain=$(SPECGEN_GCC_TOOLCHAIN)
endif
# One specgen run over the three headers, splitting into $(1). Any further
# options, $(2), follow the fixed ones; the grouped rule below passes the
# depfile through them, and wording-check passes none.
define specgen_wording
$(SPECGEN) generate $(WORDING_HEADERS) \
--backend latex --validate --warnings-as-errors \
--base-section-depth 2 \
--split $(1) \
--root expected.unexpected.root \
--root expected.bad.root \
--root expected.root \
$(2) \
--no-compile-commands -- $(SPECGEN_CLANG_ARGS)
endef
# The fragments of $(1)/fragments assembled, in clause order, into
# $(1)/expected.tex. Written to a temporary first: a half-written
# expected.tex that make believes is finished is worse than no expected.tex
# at all.
define assemble_wording
cat $(WORDING_DIR)/preamble.tex > $(1)/expected.tex.tmp
for clause in $(WORDING_CLAUSES); do \
printf '\n' >> $(1)/expected.tex.tmp; \
cat $(1)/fragments/$$clause.tex >> $(1)/expected.tex.tmp; \
done
mv $(1)/expected.tex.tmp $(1)/expected.tex
endef
# A grouped target (GNU Make 4.3+): one invocation writes all of these, and
# make must not run it once per fragment. Without specgen the checked-in
# fragments are used as they are, with a warning, so the paper still builds;
# they are not touched, so the warning repeats until specgen regenerates them.
$(WORDING_FRAGMENTS) &: $(WORDING_HEADERS)
@if command -v $(SPECGEN) > /dev/null 2>&1; then \
mkdir -p papers/.deps && \
$(call specgen_wording,$(WORDING_DIR)/fragments, \
--depfile papers/.deps/wording.d \
$(addprefix --dep-target ,$(WORDING_FRAGMENTS))); \
else \
echo "warning: '$(SPECGEN)' not found; using the checked-in wording" >&2; \
fi
$(WORDING_DIR)/expected.tex: $(WORDING_DIR)/preamble.tex $(WORDING_FRAGMENTS)
@$(call assemble_wording,$(WORDING_DIR))
@echo "Wrote $@"
.PHONY: wording
wording: $(WORDING_DIR)/expected.tex ## Regenerate papers/wording/ from the annotated headers via specgen
# Regenerates into a scratch directory and compares, so the checked-in
# wording is never touched. Only what is checked in is compared: specgen also
# writes the *.root.tex fragments, which are not.
.PHONY: wording-check
wording-check: ## Check the checked-in wording matches what the headers generate
rm -rf $(BUILD_DIR)/wording-check
mkdir -p $(BUILD_DIR)/wording-check/fragments
$(call specgen_wording,$(BUILD_DIR)/wording-check/fragments) > /dev/null
@$(call assemble_wording,$(BUILD_DIR)/wording-check)
diff $(WORDING_DIR)/expected.tex $(BUILD_DIR)/wording-check/expected.tex
for fragment in $(notdir $(WORDING_FRAGMENTS)); do \
diff $(WORDING_DIR)/fragments/$$fragment $(BUILD_DIR)/wording-check/fragments/$$fragment || exit 1; \
done
# Two measures of how far the generated wording is from where it is going.
# Neither fails the build; they are for judging a change to the docblocks.
#
# The first counts tokens against the paper's hand-written wording, with its
# change markup stripped. The second counts the change marks specgen makes
# when it diffs the generated wording against the working draft, beside the
# marks the paper makes by hand. It needs the draft: DRAFT_SOURCE names the
# `source` directory of a cplusplus/draft checkout, and is skipped when unset.
# specgen reads whatever revision that directory holds and records none, so
# say which it was when quoting the numbers.
#
# The draft diff is run without --validate. Reading the draft raises warnings
# no header can clear, and they must not stop a measurement.
DRAFT_SOURCE ?=
WORDING_GAP_DIR := $(BUILD_DIR)/wording-gap
.PHONY: wording-gap
wording-gap: $(WORDING_DIR)/expected.tex ## Print how far the generated wording is from the paper's and from the working draft's (DRAFT_SOURCE=<draft>/source)
@rm -rf $(WORDING_GAP_DIR)
@mkdir -p $(WORDING_GAP_DIR)/fragments
@sed -n '/\\rSec2\[expected\.unexpected\]/,$$p' papers/expected-new.tex \
| python3 papers/strip-wording.py > $(WORDING_GAP_DIR)/paper.tex
@python3 papers/wording-gap.py tokens \
$(WORDING_GAP_DIR)/paper.tex $(WORDING_DIR)/expected.tex
ifeq ($(DRAFT_SOURCE),)
@echo "Change marks against the working draft: skipped, DRAFT_SOURCE is not set"
else
@$(SPECGEN) generate $(WORDING_HEADERS) \
--backend latex --base-section-depth 2 \
--baseline-draft $(DRAFT_SOURCE) --diff-context all \
--split $(WORDING_GAP_DIR)/fragments \
--root expected.unexpected.root \
--root expected.bad.root \
--root expected.root \
--no-compile-commands -- $(SPECGEN_CLANG_ARGS) \
> /dev/null 2> $(WORDING_GAP_DIR)/specgen.log \
|| echo "specgen exited $$?; see $(WORDING_GAP_DIR)/specgen.log"
@python3 papers/wording-gap.py marks papers/expected-new.tex \
$(WORDING_GAP_DIR)/fragments $(WORDING_CLAUSES)
endif
# Deletes everything specgen and the assembly wrote, so that the next `make
# wording` writes all of it again. This is for a change in specgen itself: the
# rules above compare the wording with the headers, a new specgen changes the
# output without touching one, and so make sees nothing to do. `make -B
# wording` is no substitute, because .DEFAULT below then hands every
# prerequisite that has no rule of its own, the headers and this makefile among
# them, to cmake as a target.
#
# The fragments and expected.tex are checked in. So this refuses to run when
# there is no specgen to put them back, and neither clean nor realclean
# depends on it.
.PHONY: clean-wording
clean-wording: ## Delete the generated wording, so that 'make wording' regenerates all of it
@command -v $(SPECGEN) > /dev/null 2>&1 || { \
echo "error: '$(SPECGEN)' not found; nothing could regenerate the checked-in wording" >&2; \
exit 1; }
rm -f $(WORDING_DIR)/expected.tex $(WORDING_FRAGMENTS) \
$(WORDING_DIR)/fragments/*.root.tex papers/.deps/wording.d
# What specgen read to produce the fragments -- including headers reached only
# through an #include, which is the edge a hand-written prerequisite list
# forgets. Written by --depfile above; absent until the first run, hence
# $(wildcard): a bare glob that matches nothing stays a literal target name,
# and .DEFAULT below would hand it to cmake. Named, not globbed: papers/.deps/
# is also latexmk's -deps-out directory, and its paths are relative to papers/.
-include $(wildcard papers/.deps/wording.d)
.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)
# ------------------------------------------------------------------------------
# Blog: org-mode -> GFM markdown, with UUID-anchored source transclusion.
#
# docs/blog/*.org posts pull code out of the tree with org-transclusion,
# resolved by the elisp in .emacs.d/. orgit-file: links are pinned to a
# committed git rev, so a published post keeps showing the code its prose was
# written about. See docs/blog/pins.md for the post-to-rev mapping.
# ------------------------------------------------------------------------------
EMACS := $(shell command -v emacs 2> /dev/null)
ORGFILES := $(wildcard *.org)
%.html : %.org
$(EMACS) --init-directory=.emacs.d/ \
--batch --load .emacs.d/init.el \
-f package-initialize \
--eval "(setq enable-local-variables :all)" \
--visit $< \
--eval "(org-transclusion-mode t)" \
--eval "(org-export-to-file 'html \"$@\")"
echo $@ : \\ > $@.deps
echo " $<" \\ >> $@.deps
sed -n "s/^.*\[\[file:\(\S*\)::.*$$/\1/p" < $< | sort -u | xargs printf " %s \\\\\\n" >> $@.deps
-include $(wildcard $(ORGFILES:%.org=%.html.deps))
%-slides.html : %.org
$(EMACS) --init-directory=.emacs.d/ \
--batch --load .emacs.d/init.el \
-f package-initialize \
--eval "(setq enable-local-variables :all)" \
--visit $< \
--eval "(org-transclusion-mode t)" \
--eval "(org-export-to-file 're-reveal \"$@\")"
echo $@ : \\ > $@.deps
echo " $<" \\ >> $@.deps
sed -n "s/^.*\[\[file:\(\S*\)::.*$$/\1/p" < $< | sort -u | xargs printf " %s \\\\\\n" >> $@.deps
-include $(wildcard $(ORGFILES:%.org=%-slides.html.deps))
BLOG_ORGFILES := $(wildcard docs/blog/*.org)
docs/blog/%.md : docs/blog/%.org
$(EMACS) --init-directory=.emacs.d/ \
--batch --load .emacs.d/init.el \
-f package-initialize \
--eval "(setq enable-local-variables :all)" \
--visit $< \
--eval "(org-transclusion-mode t)" \
--eval "(require 'ox-gfm)" \
--eval "(org-export-to-file 'gfm \"$(abspath $@)\")"
echo $@ : \\ > $@.deps
echo " $<" \\ >> $@.deps
sed -n \
-e "s/^.*\[\[file:\(\S*\)::.*$$/\1/p" \
-e "s/^.*\[\[orgit:[^:]*::\([^:]*\)::.*$$/\1/p" \
< $< | sort -u | xargs printf " %s \\\\\\n" >> $@.deps
-include $(wildcard $(BLOG_ORGFILES:.org=.md.deps))
.PHONY: blog-md
blog-md: $(BLOG_ORGFILES:.org=.md) ## convert docs/blog/*.org to GFM markdown
.PHONY: clean-blog-md
clean-blog-md:
-rm -f $(BLOG_ORGFILES:.org=.md) $(BLOG_ORGFILES:.org=.md.deps)
clean: clean-blog-md
.PHONY: clean-emacs.d
clean-emacs.d:
-rm -rf .emacs.d/eln-cache
-rm -rf .emacs.d/elpa*
realclean: clean-emacs.d
.PHONY: clean-org-deps
clean-org-deps:
-rm $(ORGFILES:%.org=%.org.deps)
# 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