-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
109 lines (81 loc) · 2.65 KB
/
Makefile
File metadata and controls
109 lines (81 loc) · 2.65 KB
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
# this make file is a wrapper around CMake and provided for convience only.
# actual rules for building software and components should be in cmake scripts.
.PHONY: all help config build clean distclean install test check smoke
.DEFAULT_GOAL := all
USER = $(shell id -u -n)
SUDO = $(shell which sudo)
DESTDIR ?=
BUILDDIR = build
Q = $(if ${V},,@)
all: build
help:
@echo "make build"
@echo "make build TYPE=[Debug|Release]"
@echo "make clean"
@echo "make distclean"
@echo "make install"
@echo "make test"
@echo "make smoke"
# ---------------------------------------------------------------------------
BUILDNINJA = ${BUILDDIR}/build.ninja
CMAKEFLAGS = -G Ninja
DEFAULT_TYPE = Release
CURRENT_TYPE = $(shell sed -r -n -e 's/CMAKE_BUILD_TYPE:STRING=//p' ${BUILDDIR}/CMakeCache.txt 2>/dev/null)
TYPE ?= $(if ${CURRENT_TYPE},${CURRENT_TYPE},${DEFAULT_TYPE})
CMAKEFLAGS += -DCMAKE_BUILD_TYPE=${TYPE}
# prefer clang over gcc
ifneq ($(shell which clang),)
CMAKEFLAGS += -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
else
ifneq ($(shell which gcc),)
CMAKEFLAGS += -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
else
# otherwise use default
endif
endif
ifneq (${TYPE},${CURRENT_TYPE})
ifneq (${CURRENT_TYPE},)
$(info ### switching from ${CURRENT_TYPE} to ${TYPE})
endif
.PHONY: ${BUILDNINJA}
endif
config: ${BUILDNINJA}
${BUILDNINJA}: Makefile CMakeLists.txt
@echo "### setting up cmake in ${BUILDDIR} for ${TYPE}"
${Q}mkdir -p ${BUILDDIR}
${Q}cmake -B${BUILDDIR} -S. ${CMAKEFLAGS}
build/compile_commands.json: config
COMPILE_COMMANDS = compile_commands.json
${COMPILE_COMMANDS}: build/compile_commands.json
@echo "### linking compile_commands.json"
${Q}ln -fs $< $@
build: ${BUILDNINJA} ${COMPILE_COMMANDS}
@echo "### building in ${BUILDDIR}"
${Q}ninja -C ${BUILDDIR}
clean:
@echo "### cleaning in ${BUILDDIR}"
${Q}ninja -C ${BUILDDIR} clean
distclean:
@echo "### removing ${BUILDDIR}"
${Q}rm -rf build
install: build
@echo "### installing from ${BUILDDIR}"
${Q}DESTDIR=$(abspath ${DESTDIR}) ninja -C ${BUILDDIR} install
test check: build
@echo "### unit-testing from ${BUILDDIR}"
${Q}cd ${BUILDDIR} && ctest --output-on-failure --output-junit test_report.xml
smoke: build
@echo "### smoke-testing from ${BUILDDIR}"
@echo there are no smoke tests yet
# ---------------------------------------------------------------------------
.PHONY: tags cscope cscope.files
TAG_DIRS = lib include cli test
tags: cscope ctags
cscope: cscope.out
cscope.out: cscope.files
${Q}cscope -P`pwd` -b
cscope.files:
${Q}find ${TAG_DIRS} -type f -name '*.[ch]' -o -name '*.[ch]pp' \
| grep -v -e /rpm/ -e CVS -e SCCS > $@
ctags: cscope.files
${Q}ctags --sort=yes -L $<