-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
145 lines (115 loc) · 3.33 KB
/
Makefile
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
# Makefile
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules.
MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced.
SANITIZERS := run
# SANITIZERS = usan # TODO: lsan
# OS := $(shell /usr/bin/uname)
# ifeq ($(OS),Darwin)
# SANITIZERS += tsan # TODO: asan
# endif
# ifeq ($(OS),Linux)
# SANITIZERS += asan # TODO: tsan msan
# endif
.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test install all format unstage $(SANITIZERS)
SYSROOT ?=
TOOLCHAIN ?=
COMPILER=c++
CXX_BASE=$(CXX:$(dir $(CXX))%=%)
ifeq ($(CXX_BASE),g++)
COMPILER=g++
endif
ifeq ($(CXX_BASE),clang++)
COMPILER=clang++
endif
LDFLAGS ?=
SAN_FLAGS ?=
CXX_FLAGS ?= -g
SANITIZER ?= default
SOURCEDIR = $(CURDIR)
BUILDROOT = build
BUILD = $(BUILDROOT)/$(SANITIZER)
EXAMPLE = beman.execution.examples.stop_token
CMAKE_CXX_COMPILER=$(COMPILER)
ifeq ($(SANITIZER),release)
CXX_FLAGS = -O3 -Wpedantic -Wall -Wextra -Wno-shadow -Werror
endif
ifeq ($(SANITIZER),debug)
CXX_FLAGS = -g
endif
ifeq ($(SANITIZER),msan)
SAN_FLAGS = -fsanitize=memory
LDFLAGS = $(SAN_FLAGS)
endif
ifeq ($(SANITIZER),asan)
SAN_FLAGS = -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize-address-use-after-scope
endif
ifeq ($(SANITIZER),usan)
SAN_FLAGS = -fsanitize=undefined
LDFLAGS = $(SAN_FLAGS)
endif
ifeq ($(SANITIZER),tsan)
SAN_FLAGS = -fsanitize=thread
LDFLAGS = $(SAN_FLAGS)
endif
ifeq ($(SANITIZER),lsan)
SAN_FLAGS = -fsanitize=leak
LDFLAGS = $(SAN_FLAGS)
endif
default: test
all: $(SANITIZERS)
run: test
./$(BUILD)/examples/$(EXAMPLE)
doc:
doxygen docs/Doxyfile
# $(SANITIZERS):
# $(MAKE) SANITIZER=$@
build:
CC=$(CXX) cmake --fresh -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
-D CMAKE_EXPORT_COMPILE_COMMANDS=1 \
-D CMAKE_SKIP_INSTALL_RULES=1 \
-D CMAKE_CXX_COMPILER=$(CXX) # XXX -D CMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
cmake --build $(BUILD)
# NOTE: without install! CK
test: build
ctest --test-dir $(BUILD) --rerun-failed --output-on-failure
install: test
cmake --install $(BUILD) --prefix /opt/local
release:
cmake --workflow --preset $@ --fresh
debug:
cmake --workflow --preset $@ --fresh
ce:
@mkdir -p $(BUILD)
bin/mk-compiler-explorer.py $(BUILD)
SOURCE_CMAKELISTS = src/beman/execution/CMakeLists.txt
update:
bin/update-cmake-headers.py $(SOURCE_CMAKELISTS)
check:
@for h in `find include -name \*.hpp`; \
do \
from=`echo -n $$h | sed -n 's@.*Beman/\(.*\).hpp.*@\1@p'`; \
< $$h sed -n "/^ *# *include <Beman\//s@.*[</]Beman/\(.*\).hpp>.*@$$from \1@p"; \
done | tsort > /dev/null
build/$(SANITIZER)/compile_commands.json: $(SANITIZER)
clang-tidy: $(BUILD)/compile_commands.json
run-clang-tidy -p $(BUILD) tests examples
codespell:
codespell -L statics,snd,copyable,cancelled
format: cmake-format clang-format
cmake-format:
cmake-format -i `git diff --name-only main | egrep '(CMakeLists.txt|\.cmake)'`
clang-format:
git clang-format main
todo:
bin/mk-todo.py
unstage:
git restore --staged tests/beman/execution/CMakeLists.txt
.PHONY: clean-doc
clean-doc:
$(RM) -r docs/html docs/latex
clean: clean-doc
$(RM) -r $(BUILD)
$(RM) mkerr olderr *~
distclean: clean
$(RM) -r $(BUILDROOT) stagedir