Skip to content

Commit 729e2b4

Browse files
committed
Tweaks in root Makefile for generic build and run
1 parent 1b45f87 commit 729e2b4

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

Makefile

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55
# cmake-format: on
66

7-
INSTALL_PREFIX?=.install/
7+
# This Makefile is a thin wrapper around CMake. It is intended to be used.
8+
9+
# Default target.
810
PROJECT?=$(shell basename $(CURDIR))
11+
12+
# Default install prefix.
13+
INSTALL_PREFIX?=.install/
14+
# Default build directory.
915
BUILD_DIR?=.build
16+
# Default destination directory.
1017
DEST?=$(INSTALL_PREFIX)
18+
# Default toolchain: missing => c++ sytem tool.
19+
TOOLCHAIN?=
20+
# Default configuration: missing => Asan.
21+
BUILD_CONFIG?=Asan
22+
# Default CMake flags.
1123
CMAKE_FLAGS?=
1224

25+
# Default targets.
1326
TARGETS := test clean all ctest
1427

1528
export
@@ -20,36 +33,40 @@ export
2033

2134
.gitmodules: .update-submodules
2235

23-
CONFIG?=Asan
2436

2537
export
2638

2739
ifeq ($(strip $(TOOLCHAIN)),)
28-
_build_name?=build-system/
29-
_build_dir?=.build/
40+
# Default build configuration.
41+
_build_name?=toolchain/c++-system
42+
_build_dir?=$(BUILD_DIR)
3043
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan"
3144
_cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/toolchain.cmake
3245
else
33-
_build_name?=build-$(TOOLCHAIN)
34-
_build_dir?=.build/
46+
# Custom toolchain.
47+
_build_name?=toolchain/$(TOOLCHAIN)
48+
_build_dir?=$(BUILD_DIR)
3549
_configuration_types?="RelWithDebInfo;Debug;Tsan;Asan"
3650
_cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/$(TOOLCHAIN)-toolchain.cmake
3751
endif
3852

39-
53+
# Build path.
4054
_build_path?=$(_build_dir)/$(_build_name)
4155

56+
# CMake command wrapper.
4257
define run_cmake =
4358
cmake \
4459
-G "Ninja Multi-Config" \
4560
-DCMAKE_CONFIGURATION_TYPES=$(_configuration_types) \
4661
-DCMAKE_INSTALL_PREFIX=$(abspath $(INSTALL_PREFIX)) \
4762
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
4863
$(_cmake_args) \
64+
$(CMAKE_FLAGS) \
4965
$(CURDIR)
5066
endef
5167

52-
default: test
68+
# Default target.
69+
default: build test
5370

5471
$(_build_path):
5572
mkdir -p $(_build_path)
@@ -59,34 +76,34 @@ $(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules
5976
-rm compile_commands.json
6077
ln -s $(_build_path)/compile_commands.json
6178

62-
compile: $(_build_path)/CMakeCache.txt ## Compile the project
63-
cmake $(CMAKE_FLAGS) -DCMAKE_TOOLCHAIN_FILE=etc/$(TOOLCHAIN)-toolchain.cmake -B $(_build_path) -S .
64-
cmake --build $(_build_path) --config $(CONFIG) --target all -- -k 0
79+
build: $(_build_path)/CMakeCache.txt ## Compile the project.
80+
cmake $(CMAKE_FLAGS) -DCMAKE_TOOLCHAIN_FILE=etc/$(TOOLCHAIN)-toolchain.cmake -B $(_build_path) -S .
81+
cmake --build $(_build_path) --config $(BUILD_CONFIG) --target all -- -k 0
6582

66-
install: $(_build_path)/CMakeCache.txt ## Install the project
83+
install: $(_build_path)/CMakeCache.txt ## Install the project.
6784
DESTDIR=$(abspath $(DEST)) ninja -C $(_build_path) -k 0 install
6885

69-
ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build
70-
ctest --build-config $(CONFIG) --output-on-failure --test-dir $(_build_path)
86+
ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build.
87+
ctest --build-config $(BUILD_CONFIG) --output-on-failure --test-dir $(_build_path)
7188

72-
ctest_ : compile
73-
ctest --build-config $(CONFIG) --output-on-failure --test-dir $(_build_path)
89+
ctest_ : build
90+
ctest --build-config $(BUILD_CONFIG) --output-on-failure --test-dir $(_build_path)
7491

75-
test: ctest_ ## Rebuild and run tests
92+
test: ctest_ ## Rebuild and run tests.
7693

7794
cmake: | $(_build_path)
7895
cd $(_build_path) && ${run_cmake}
7996

80-
clean: $(_build_path)/CMakeCache.txt ## Clean the build artifacts
81-
cmake --build $(_build_path) --config $(CONFIG) --target clean
97+
clean: $(_build_path)/CMakeCache.txt ## Clean the build artifacts, but don't delete the build directory.
98+
cmake --build $(_build_path) --config $(BUILD_CONFIG) --target clean
8299

83-
realclean: ## Delete the build directory
100+
realclean: ## Delete the entire build directory.
84101
rm -rf $(_build_path)
85102

86103
env:
87104
$(foreach v, $(.VARIABLES), $(info $(v) = $($(v))))
88105

89-
.PHONY : compile install ctest ctest_ test cmake clean realclean env
106+
.PHONY : build install ctest ctest_ test cmake clean realclean env
90107

91108
.PHONY: papers
92109
papers:
@@ -95,4 +112,4 @@ papers:
95112
# Help target
96113
.PHONY: help
97114
help: ## Show this help.
98-
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) targets.mk | sort
115+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort

0 commit comments

Comments
 (0)