-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
168 lines (139 loc) · 4.18 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
################################################################################
#
# Generic Makefile to simplify the use of CMake projects
# ------------------------------------------------------
#
# This simple Makefile is meant to provide a simplified entry point for the
# configuration and build of CMake-based projects that use a default toolchain
# (as it is the case for Elements-based projects).
#
# Only a few targets are actually provided: all the main targets are directly
# delegated to the CMake Makefile.
#
# Main targets:
#
# all
# (default) build everything
#
# test
# run the declared tests
#
# install
# populate the InstallArea with the products of the build
#
# clean
# remove build products from the build directory
#
# purge [*]_
# deep clean of the build, including InstallArea
# (requires re-configuration)
#
# help
# print the list of available targets
#
# configure [*]_
# alias to CMake 'rebuild_cache' target
#
# tests [*]_
# backward-compatibility target for the CMT generic Makefile. Tt
# ensures that the "all" target has been called before.
#
# :Author: Marco Clemencic
# :Author: Hubert Degaudenzi
#
# .. [*] Targets defined by this Makefile.
#
################################################################################
# settings
CMAKE := cmake
CTEST := ctest
NINJA := $(shell which ninja-build 2> /dev/null)
ifeq ($(NINJA),)
NINJA := $(shell which ninja 2> /dev/null)
endif
# Looking for the ToolChain
TOOLCHAIN_NAME := ElementsToolChain.cmake
ifneq ($(wildcard $(CURDIR)/cmake/$(TOOLCHAIN_NAME)),)
TOOLCHAIN_FILE := $(CURDIR)/cmake/$(TOOLCHAIN_NAME)
else
ifneq ($(CMAKE_PREFIX_PATH),)
PREFIX_LIST := $(subst :, ,$(CMAKE_PREFIX_PATH))
TOOLCHAIN_LIST := $(foreach dir,$(PREFIX_LIST),$(wildcard $(dir)/$(TOOLCHAIN_NAME)))
TOOLCHAIN_FILE := $(firstword $(TOOLCHAIN_LIST))
endif
endif
ifneq ($(TOOLCHAIN_FILE),)
# A toolchain has been found. Lets use it.
override CMAKEFLAGS += -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE)
endif
BUILD_PREFIX_NAME := build
override CMAKEFLAGS += -DUSE_LOCAL_INSTALLAREA=ON -DBUILD_PREFIX_NAME:STRING=$(BUILD_PREFIX_NAME)
ifndef BINARY_TAG
ifdef CMAKECONFIG
BINARY_TAG := ${CMAKECONFIG}
else
ifdef CMTCONFIG
BINARY_TAG := ${CMTCONFIG}
endif
endif
endif
ifdef BINARY_TAG
BUILD_SUBDIR := $(BUILD_PREFIX_NAME).$(BINARY_TAG)
else
BUILD_SUBDIR := $(BUILD_PREFIX_NAME)
endif
BUILDDIR := $(CURDIR)/$(BUILD_SUBDIR)
# build tool
ifneq ($(USE_NINJA),)
# enable Ninja
override CMAKEFLAGS += -GNinja
ifneq ($(VERBOSE),)
NINJAFLAGS := -v $(NINJAFLAGS)
endif
BUILD_CONF_FILE := build.ninja
BUILD_CMD := $(NINJA) -C $(BUILD_SUBDIR) $(NINJAFLAGS)
# BUILD_CMD := cd $(BUILD_SUBDIR) && $(NINJA) $(NINJAFLAGS)
else
BUILD_CONF_FILE := Makefile
BUILD_CMD := $(MAKE) -C $(BUILD_SUBDIR)
endif
# default target
all:
# deep clean
purge:
$(RM) -r $(BUILDDIR) $(CURDIR)/InstallArea/$(BINARY_TAG)
find $(CURDIR) -type f -name "*.pyc" -exec $(RM) -v \{} \;
find $(CURDIR) -depth -type d -name "__pycache__" -exec $(RM) -rv \{} \;
# delegate any target to the build directory (except 'purge')
ifneq ($(MAKECMDGOALS),purge)
%: $(BUILDDIR)/$(BUILD_CONF_FILE) FORCE
+$(BUILD_CMD) $*
endif
# aliases
.PHONY: configure tests FORCE
ifneq ($(wildcard $(BUILDDIR)/$(BUILD_CONF_FILE)),)
configure: rebuild_cache
else
configure: $(BUILDDIR)/$(BUILD_CONF_FILE)
endif
@ # do not delegate further
# This wrapping around the test target is used to ensure the generation of
# the XML output from ctest.
test: $(BUILDDIR)/$(BUILD_CONF_FILE)
cd $(BUILDDIR) && $(CTEST) -T Test $(ARGS)
# This target ensures that the "all" target is called before
# running the tests (unlike the "test" default target of CMake)
tests: all
$(BUILD_CMD) test
# ensure that the target are always passed to the CMake Makefile
FORCE:
@ # dummy target
# Makefiles are used as implicit targets in make, but we should not consider
# them for delegation.
$(MAKEFILE_LIST):
@ # do not delegate further
# trigger CMake configuration
$(BUILDDIR)/$(BUILD_CONF_FILE): | $(BUILDDIR)
cd $(BUILDDIR) && $(CMAKE) $(CMAKEFLAGS) $(CURDIR)
$(BUILDDIR):
mkdir -p $(BUILDDIR)