forked from beman-project/optional26
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·170 lines (128 loc) · 4.37 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
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
#! /usr/bin/make -f
# cmake-format: off
# /Makefile -*-makefile-*-
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# cmake-format: on
INSTALL_PREFIX?=.install/
PROJECT?=$(shell basename $(CURDIR))
BUILD_DIR?=.build
DEST?=$(INSTALL_PREFIX)
CMAKE_FLAGS?=
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/
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan;Gcov"
_cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/toolchain.cmake
else
_build_name?=build-$(TOOLCHAIN)
_build_dir?=.build/
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan;Gcov"
_cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/$(TOOLCHAIN)-toolchain.cmake
endif
_build_path?=$(_build_dir)/$(_build_name)
define run_cmake =
cmake \
-G "Ninja Multi-Config" \
-DCMAKE_CONFIGURATION_TYPES=$(_configuration_types) \
-DCMAKE_INSTALL_PREFIX=$(abspath $(INSTALL_PREFIX)) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
$(_cmake_args) \
$(CURDIR)
endef
default: test
$(_build_path):
mkdir -p $(_build_path)
$(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules
cd $(_build_path) && $(run_cmake)
-rm compile_commands.json
ln -s $(_build_path)/compile_commands.json
compile: $(_build_path)/CMakeCache.txt ## Compile the project
cmake --build $(_build_path) --config $(CONFIG) --target all -- -k 0
install: $(_build_path)/CMakeCache.txt ## Install the project
DESTDIR=$(abspath $(DEST)) ninja -C $(_build_path) -k 0 install
ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build
cd $(_build_path) && ctest --output-on-failure -C $(CONFIG)
ctest_ : compile
cd $(_build_path) && ctest --output-on-failure -C $(CONFIG)
test: ctest_ ## Rebuild and run tests
cmake: | $(_build_path)
cd $(_build_path) && ${run_cmake}
clean: $(_build_path)/CMakeCache.txt ## Clean the build artifacts
cmake --build $(_build_path) --config $(CONFIG) --target clean
realclean: ## Delete the build directory
rm -rf $(_build_path)
env:
$(foreach v, $(.VARIABLES), $(info $(v) = $($(v))))
.PHONY : compile install ctest ctest_ test cmake clean realclean env
.PHONY: papers
papers:
$(MAKE) -C papers/P2988 papers
PYEXECPATH ?= $(shell which python3.12 || which python3.11 || which python3.10 || which python3.9 || which python3.8 || which python3.7 || which python3)
PYTHON ?= $(shell basename $(PYEXECPATH))
VENV := .venv
ACTIVATE := . $(VENV)/bin/activate &&
PYEXEC := $(ACTIVATE) $(PYTHON)
MARKER=.initialized.venv.stamp
PIP := $(PYEXEC) -m pip
PIP_SYNC := $(PYEXEC) -m piptools sync
PIPTOOLS_COMPILE := $(PYEXEC) -m piptools compile --no-header --strip-extras
PRE_COMMIT := $(ACTIVATE) pre-commit
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',''))"
$(PIP) --version
@echo venv: $(VENV)
requirements.txt: requirements.in
$(PIPTOOLS_COMPILE) --output-file=$@ $<
requirements-dev.txt: requirements-dev.in
$(PIPTOOLS_COMPILE) --output-file=$@ $<
$(VENV):
$(PYEXECPATH) -m venv $(VENV)
$(PIP) install --upgrade pip setuptools wheel
$(PIP) install pip-tools
$(VENV)/$(MARKER): requirements.txt requirements-dev.txt | $(VENV)
$(PIP_SYNC) requirements.txt
$(PIP_SYNC) requirements-dev.txt
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) exec $@
.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
$(MAKE) CONFIG=Gcov test
$(ACTIVATE) cmake --build $(_build_path) --config Gcov --target process_coverage
# 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