-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
288 lines (240 loc) · 7.77 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
########################################################################################################################
.PHONY: default
default:
@echo "Make what? Try 'make help'!"
@exit 1
# Defaults (keep in sync with help screen below)
BUILD_TYPE = Debug
INSTALL_PREFIX = fpsdk
BUILD_TESTING =
VERBOSE = 0
# User vars
-include config.mk
# Check if we have ROS
FP_USE_ROS1=
FP_USE_ROS2=
ifneq ($(ROS_PACKAGE_PATH),)
FP_USE_ROS1=yes
else ifeq ($(ROS_VERSION),2)
FP_USE_ROS2=yes
# else
# $(info No ROS_PACKAGE_PATH (ROS1) and no ROS_VERSION (ROS2) found)
endif
# A unique ID for this exact config we're using
configuid=$(shell echo "$(BUILD_TYPE) $(INSTALL_PREFIX) $(BUILD_TESTING)" | md5sum | cut -d " " -f1)
.PHONY: help
help:
@echo "Usage:"
@echo
@echo " make <target> [INSTALL_PREFIX=...] [BUILD_TYPE=Debug|Release] [BUILD_TESTING=|ON|OFF] [VERBOSE=1]"
@echo
@echo "Where possible <target>s are:"
@echo
@echo " clean Clean build directory"
@echo " cmake Configure packages"
@echo " build Build packages"
@echo " test Run tests"
@echo " install Install packages (into INSTALL_PREFIX path)"
@echo " doc Generate documentation (into build directory)"
@echo
@echo "Typically you want to do something like this:"
@echo
@echo " source /opt/ros/noetic/setup.bash # if you have ROS..."
@echo " make install INSTALL_PREFIX=~/fpsdk"
@echo
@echo "Notes:"
@echo
@echo "- ROS_PACKAGE_PATH can be provided through catkin/ros env (recommended) or on the command line"
@echo "- Command line variables can be stored into a config.mk file, which is automatically loaded"
@echo "- 'make ci' runs the CI (more or less) like on Github. INSTALL_PREFIX and BUILD_TYPE have no effect here."
@echo
########################################################################################################################
TOUCH := touch
MKDIR := mkdir
ECHO := echo
RM := rm
CMAKE := cmake
DOXYGEN := doxygen
NICE := nice
CAT := cat
ifeq ($(VERBOSE),1)
V =
V1 =
V2 =
V12 =
RM += -v
MV += -v
CP += -v
MKDIR += -v
else
ZIP += -q
UNZIP += -q
V = @
V1 = > /dev/null
V2 = 2> /dev/null
V12 = 2>&1 > /dev/null
endif
fancyterm := true
ifeq ($(TERM),dumb)
fancyterm := false
endif
ifeq ($(TERM),)
fancyterm := false
endif
ifneq ($(MSYSTEM),)
fancyterm := false
endif
ifeq ($(fancyterm),true)
HLW="\\e[1m"
HLO="\\e[m"
else
HLW=
HLO=
endif
# Disable all built-in rules
.SUFFIXES:
########################################################################################################################
CMAKE_ARGS_BUILD :=
CTEST_ARGS := --output-on-failure
CMAKE_ARGS := -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)
CMAKE_ARGS += -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
ifneq ($(ROS_PACKAGE_PATH),)
CMAKE_ARGS += -DROS_PACKAGE_PATH=$(ROS_PACKAGE_PATH)
endif
ifneq ($(BUILD_TESTING),)
CMAKE_ARGS += -DBUILD_TESTING=$(BUILD_TESTING)
endif
MAKEFLAGS = --no-print-directory
ifneq ($(VERBOSE),0)
CMAKE_ARGS_BUILD += --verbose
CTEST_ARGS += --verbose
endif
ifeq ($(GITHUB_WORKSPACE),)
CMAKE_ARGS_BUILD = --parallel $(shell nproc --ignore=4)
NICE_BUILD=$(NICE) -19
else
CMAKE_ARGS_BUILD = --parallel 1
NICE_BUILD=
endif
BUILD_DIR = build/$(BUILD_TYPE)
# "All-in-one" targets
.PHONY: clean
clean:
$(V)$(RM) -rf $(BUILD_DIR)
.PHONY: distclean
distclean:
$(V)$(RM) -rf install build fpsdk
$(BUILD_DIR):
$(V)$(MKDIR) -p $@
# Detect changed build config
ifneq ($(MAKECMDGOALS),)
ifneq ($(MAKECMDGOALS),help)
ifneq ($(MAKECMDGOALS),pre-commit)
ifneq ($(MAKECMDGOALS),ci)
ifneq ($(MAKECMDGOALS),distclean)
ifneq ($(MAKECMDGOALS),doc)
builddiruid=$(shell $(CAT) $(BUILD_DIR)/.make-uid 2>/dev/null || echo "none")
ifneq ($(builddiruid),$(configuid))
$(shell $(RM) -f $(BUILD_DIR)/.make-uid)
endif
endif
endif
endif
endif
endif
endif
$(BUILD_DIR)/.make-uid: | $(BUILD_DIR)
$(V)$(ECHO) $(configuid) > $@
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: cmake
cmake: $(BUILD_DIR)/.make-cmake
deps = $(sort $(wildcard CMakeList.txt Makefile fpsdk_doc/* Doxyfile \
fpsdk_common/* fpsdk_common/*/* fpsdk_common/*/*/* fpsdk_common/*/*/*/* \
fpsdk_ros1/* fpsdk_ros1/*/* fpsdk_ros1/*/*/* fpsdk_ros1/*/*/*/* \
fpsdk_ros2/* fpsdk_ros2/*/* fpsdk_ros2/*/*/* fpsdk_ros2/*/*/*/* \
fpsdk_apps/* fpsdk_apps/*/* fpsdk_apps/*/*/* fpsdk_apps/*/*/*/*))
$(BUILD_DIR)/.make-cmake: $(deps) $(BUILD_DIR)/.make-uid
@echo "$(HLW)***** Configure ($(BUILD_TYPE)) *****$(HLO)"
$(V)$(CMAKE) -B $(BUILD_DIR) $(CMAKE_ARGS)
$(V)$(TOUCH) $@
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build
build: $(BUILD_DIR)/.make-build
$(BUILD_DIR)/.make-build: $(BUILD_DIR)/.make-cmake $(BUILD_DIR)/.make-uid
@echo "$(HLW)***** Build ($(BUILD_TYPE)) *****$(HLO)"
$(V)$(NICE_BUILD) $(CMAKE) --build $(BUILD_DIR) $(CMAKE_ARGS_BUILD)
$(V)$(TOUCH) $@
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: install
install: $(BUILD_DIR)/.make-install
$(BUILD_DIR)/.make-install: $(BUILD_DIR)/.make-build
@echo "$(HLW)***** Install ($(BUILD_TYPE)) *****$(HLO)"
$(V)$(CMAKE) --install $(BUILD_DIR)
$(V)$(TOUCH) $@
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: test
test: $(BUILD_DIR)/.make-build
@echo "$(HLW)***** Test ($(BUILD_TYPE)) *****$(HLO)"
$(V)(cd $(BUILD_DIR)/fpsdk_common && ctest $(CTEST_ARGS))
ifneq ($(FP_USE_ROS1),)
$(V)(cd $(BUILD_DIR)/fpsdk_ros1 && ctest $(CTEST_ARGS))
endif
ifneq ($(FP_USE_ROS2),)
$(V)(cd $(BUILD_DIR)/fpsdk_ros2 && ctest $(CTEST_ARGS))
endif
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: doc
doc: $(BUILD_DIR)/.make-doc
$(BUILD_DIR)/.make-doc: $(BUILD_DIR)/.make-cmake
@echo "$(HLW)***** Doc ($(BUILD_TYPE)) *****$(HLO)"
$(V)( \
cat Doxyfile; \
echo "PROJECT_NUMBER = $$(cat $(BUILD_DIR)/FP_VERSION_STRING || echo 'unknown revision')"; \
echo "OUTPUT_DIRECTORY = $(BUILD_DIR)"; \
) | $(DOXYGEN) -
$(V)$(TOUCH) $@
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: ci
ci: $(BUILD_DIR)/.ci-bookworm $(BUILD_DIR)/.ci-noetic $(BUILD_DIR)/.ci-humble $(BUILD_DIR)/.ci-jazzy
$(BUILD_DIR)/.ci-bookworm: $(deps)
@echo "$(HLW)***** CI (bookworm) *****$(HLO)"
ifeq ($(FPSDK_IMAGE),)
$(V)docker/docker.sh run bookworm-ci ./docker/ci.sh
$(V)$(TOUCH) $@
else
@echo "This ($@) should not run inside Docker!"
@false
endif
$(BUILD_DIR)/.ci-noetic: $(deps)
@echo "$(HLW)***** CI (noetic) *****$(HLO)"
ifeq ($(FPSDK_IMAGE),)
$(V)docker/docker.sh run noetic-ci ./docker/ci.sh
$(V)$(TOUCH) $@
else
@echo "This ($@) should not run inside Docker!"
@false
endif
$(BUILD_DIR)/.ci-humble: $(deps)
@echo "$(HLW)***** CI (humble) *****$(HLO)"
ifeq ($(FPSDK_IMAGE),)
$(V)docker/docker.sh run humble-ci ./docker/ci.sh
$(V)$(TOUCH) $@
else
@echo "This ($@) should not run inside Docker!"
@false
endif
$(BUILD_DIR)/.ci-jazzy: $(deps)
@echo "$(HLW)***** CI (jazzy) *****$(HLO)"
ifeq ($(FPSDK_IMAGE),)
$(V)docker/docker.sh run jazzy-ci ./docker/ci.sh
$(V)$(TOUCH) $@
else
@echo "This ($@) should not run inside Docker!"
@false
endif
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: pre-commit
pre-commit:
@echo "$(HLW)***** pre-commit checks *****$(HLO)"
$(V)pre-commit run --all-files --hook-stage manual || return 1
########################################################################################################################