Skip to content

Commit f7f4cf6

Browse files
committed
Resurrect Makefile
1 parent bfeb908 commit f7f4cf6

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

Makefile

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#! /usr/bin/make -f
2+
# cmake-format: off
3+
# /Makefile -*-makefile-*-
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
# cmake-format: on
6+
7+
INSTALL_PREFIX?=.install/
8+
PROJECT?=$(shell basename $(CURDIR))
9+
BUILD_DIR?=.build
10+
DEST?=$(INSTALL_PREFIX)
11+
CMAKE_FLAGS?=
12+
13+
TARGETS := test clean all ctest
14+
15+
export
16+
17+
.update-submodules:
18+
git submodule update --init --recursive
19+
touch .update-submodules
20+
21+
.gitmodules: .update-submodules
22+
23+
CONFIG?=Asan
24+
25+
export
26+
27+
ifeq ($(strip $(TOOLCHAIN)),)
28+
_build_name?=build-system/
29+
_build_dir?=.build/
30+
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan"
31+
_cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/toolchain.cmake
32+
else
33+
_build_name?=build-$(TOOLCHAIN)
34+
_build_dir?=.build/
35+
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan"
36+
_cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/$(TOOLCHAIN)-toolchain.cmake
37+
endif
38+
39+
40+
_build_path?=$(_build_dir)/$(_build_name)
41+
42+
define run_cmake =
43+
cmake \
44+
-G "Ninja Multi-Config" \
45+
-DCMAKE_CONFIGURATION_TYPES=$(_configuration_types) \
46+
-DCMAKE_INSTALL_PREFIX=$(abspath $(INSTALL_PREFIX)) \
47+
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
48+
$(_cmake_args) \
49+
$(CURDIR)
50+
endef
51+
52+
default: test
53+
54+
$(_build_path):
55+
mkdir -p $(_build_path)
56+
57+
$(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules
58+
cd $(_build_path) && $(run_cmake)
59+
-rm compile_commands.json
60+
ln -s $(_build_path)/compile_commands.json
61+
62+
compile: $(_build_path)/CMakeCache.txt ## Compile the project
63+
cmake --build $(_build_path) --config $(CONFIG) --target all -- -k 0
64+
65+
install: $(_build_path)/CMakeCache.txt ## Install the project
66+
DESTDIR=$(abspath $(DEST)) ninja -C $(_build_path) -k 0 install
67+
68+
ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build
69+
cd $(_build_path) && ctest --output-on-failure
70+
71+
ctest_ : compile
72+
cd $(_build_path) && ctest --output-on-failure
73+
74+
test: ctest_ ## Rebuild and run tests
75+
76+
cmake: | $(_build_path)
77+
cd $(_build_path) && ${run_cmake}
78+
79+
clean: $(_build_path)/CMakeCache.txt ## Clean the build artifacts
80+
cmake --build $(_build_path) --config $(CONFIG) --target clean
81+
82+
realclean: ## Delete the build directory
83+
rm -rf $(_build_path)
84+
85+
env:
86+
$(foreach v, $(.VARIABLES), $(info $(v) = $($(v))))
87+
88+
.PHONY : compile install ctest ctest_ test cmake clean realclean env
89+
90+
.PHONY: papers
91+
papers:
92+
$(MAKE) -C papers papers
93+
94+
# Help target
95+
.PHONY: help
96+
help: ## Show this help.
97+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) targets.mk | sort

0 commit comments

Comments
 (0)