-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·65 lines (53 loc) · 3.15 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
TIME_COMMAND=/usr/bin/time --format "buildtime: real=%e user=%U sys=%S [ %C ]"
BUILD_DIR=build
RELEASE_BUILD_TYPE=RelWithDebInfo
DEBUG_BUILD_TYPE=Debug
RELEASE_DIR=$(shell echo "${RELEASE_BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')
DEBUG_DIR=$(shell echo "${DEBUG_BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')
NUM_JOBS := $(shell nproc --all)
BUILD_COMMAND := $(MAKE) --jobs $(NUM_JOBS) --no-print-directory
# The list of files which should trigger a re-cmake, find all CMakeLists.txt and .cmake files in the
# repro, excluding the build, install and .git folder
CMAKE_DEPS := $(shell find * \( -name CMakeLists.txt -or -name '*.cmake' \) -not \( -path "${BUILD_DIR}/*" -o -path "${INSTALL_DIR}/*" -o -path ".git/*" \) | sort)
# If the .ONESHELL special target appears anywhere in the makefile then all recipe lines for each
# target will be provided to a single invocation of the shell.
.ONESHELL:
SHELL=/bin/bash
# Default to release build
all: debug
#################### DEBUG
${BUILD_DIR}/${DEBUG_DIR}/Makefile: $(CMAKE_DEPS)
@ $(eval LOGFILE=$(shell echo cmake-`date +%Y%m%dT%H%M%S`.log))
@ $(info build: configuring ${DEBUG_BUILD_TYPE} build via cmake [log: ${BUILD_DIR}/${LOGFILE}]...)
@ mkdir -p ${BUILD_DIR}/${DEBUG_DIR}
@ cd ${BUILD_DIR}/${DEBUG_DIR}
@ $(TIME_COMMAND) cmake ../../ -DCMAKE_BUILD_TYPE="${DEBUG_BUILD_TYPE}" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON > ${LOGFILE} 2>&1 && (echo "release cmake SUCCEEDED") || (/usr/bin/tail -25 ${LOGFILE}; echo "release cmake FAILED"; exit 1)
.PHONY: debug
debug: ${BUILD_DIR}/${DEBUG_DIR}/Makefile
@ $(eval LOGFILE=$(shell echo build-`date +%Y%m%dT%H%M%S`.log))
@ $(info build: building ${RELEASE_BUILD_TYPE} [log: ${BUILD_DIR}/${LOGFILE}]...)
@ set -e -o pipefail
@ $(TIME_COMMAND) $(BUILD_COMMAND) -C "${BUILD_DIR}/${DEBUG_DIR}" 2>&1 && (echo "release build SUCCEEDED") || (echo "release build FAILED"; exit 1) | tee ${BUILD_DIR}/build-`date +%Y%m%dT%H%M%S`.log
@ cd ${BUILD_DIR}
@ rm -f latest
@ /bin/ln -s "${DEBUG_DIR}" latest
#################### RELEASE
${BUILD_DIR}/${RELEASE_DIR}/Makefile: $(CMAKE_DEPS)
@ $(eval LOGFILE=$(shell echo cmake-`date +%Y%m%dT%H%M%S`.log))
@ $(info build: configuring ${RELEASE_BUILD_TYPE} build via cmake [log: ${BUILD_DIR}/${LOGFILE}]...)
@ mkdir -p ${BUILD_DIR}/${RELEASE_DIR}
@ cd ${BUILD_DIR}/${RELEASE_DIR}
@ $(TIME_COMMAND) cmake ../../ -DCMAKE_BUILD_TYPE="${RELEASE_BUILD_TYPE}" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON > ${LOGFILE} 2>&1 && (echo "release cmake SUCCEEDED") || (/usr/bin/tail -25 ${LOGFILE}; echo "release cmake FAILED"; exit 1)
.PHONY: release
release: ${BUILD_DIR}/${RELEASE_DIR}/Makefile
@ $(eval LOGFILE=$(shell echo build-`date +%Y%m%dT%H%M%S`.log))
@ $(info build: building ${RELEASE_BUILD_TYPE} [log: ${BUILD_DIR}/${LOGFILE}]...)
@ set -e -o pipefail
@ $(TIME_COMMAND) $(BUILD_COMMAND) -C "${BUILD_DIR}/${RELEASE_DIR}" 2>&1 && (echo "release build SUCCEEDED") || (echo "release build FAILED"; exit 1) | tee ${BUILD_DIR}/build-`date +%Y%m%dT%H%M%S`.log
@ cd ${BUILD_DIR}
@ rm -f latest
@ /bin/ln -s "${RELEASE_DIR}" latest
.PHONY: clean
clean:
@ $(TIME_COMMAND) rm -rf "${BUILD_DIR}" && (echo "clean SUCCEEDED") || (echo "clean FAILED"; exit 1)
@ $(info build: outputs cleaned.)