-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
331 lines (277 loc) · 9.81 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# Set up a default goal
.DEFAULT_GOAL := help
# Set bash shell
SHELL := /bin/bash
# Set up some macros for common directories within the tree
export ROOT_DIR := $(CURDIR)
export TARGETS_DIR := $(ROOT_DIR)/src/targets
export TESTS_DIR := $(ROOT_DIR)/src/tests
export TOOLS_DIR := $(ROOT_DIR)/tools
export BUILD_DIR := $(ROOT_DIR)/build
export DL_DIR := $(ROOT_DIR)/downloads
$(TOOLS_DIR):
$(V1) mkdir -p $@
$(BUILD_DIR):
$(V1) mkdir -p $@
$(DL_DIR):
$(V1) mkdir -p $@
# Decide on a verbosity level based on the V= parameter
export AT := @
ifndef V
export V0 :=
export V1 := $(AT)
else ifeq ($(V), 0)
export V0 := $(AT)
export V1 := $(AT)
else ifeq ($(V), 1)
endif
# Set build variant defaults
export BUILD_TYPE ?= DEBUG_BUILD
ifeq ($(BUILD_TYPE),DEBUG_BUILD)
else ifeq ($(BUILD_TYPE),RELEASE_BUILD)
export NDEBUG := 1
else
$(error BUILD_TYPE is not set properly)
endif
# When building any of the "all_*" targets, tell all sub makefiles to display
# additional details on each line of output to describe which build and target
# that each line applies to.
ifneq ($(strip $(filter all_%,$(MAKECMDGOALS))),)
export ENABLE_MSG_EXTRA := yes
endif
# When building more than one goal in a single make invocation, also
# enable the extra context for each output line
ifneq ($(word 2,$(MAKECMDGOALS)),)
export ENABLE_MSG_EXTRA := yes
endif
include $(ROOT_DIR)/make/tools.mk
.PHONY: help
help:
@echo
@echo " Here is a summary of the available targets:"
@echo
@echo " [Tools]"
@echo " arm_sdk_install - Install the GNU ARM gcc toolchain"
@echo " openocd_install - Install the OpenOCD JTAG daemon"
@echo " gtest_install - Install the google test framework"
@echo " deps_install - Install required os dependencies"
@echo
@echo " [Big Hammer]"
@echo " all - Build all firmware, bootloaders, entire flash and flashtool"
@echo " all_fw - Build only firmware for all boards"
@echo " all_bl - Build only bootloaders for all boards"
@echo " all_ef - Build only entire flash imanges for all boards"
@echo " all_ft - Build only flashtool packages for all boards"
@echo
@echo " all_clean - Remove your build directory ($(BUILD_DIR))"
@echo " all_fw_clean - Remove firmware for all boards"
@echo " all_bl_clean - Remove bootloaders for all boards"
@echo " all_ef_clean - Remove entire flash images for all boards"
@echo " all_ft_clean - Remove flashtool packages for all boards"
@echo
@echo " all_<board> - Build all available images for <board>"
@echo " all_<board>_clean - Remove all available images for <board>"
@echo
@echo " [Firmware]"
@echo " fw_<board> - Build firmware for <board>"
@echo " supported boards are ($(FW_BOARDS))"
@echo " fw_<board>_clean - Remove firmware for <board>"
@echo
@echo " [Bootloader]"
@echo " bl_<board> - Build bootloader for <board>"
@echo " supported boards are ($(BL_BOARDS))"
@echo " bl_<board>_clean - Remove bootloader for <board>"
@echo
@echo " [Entire Flash]"
@echo " ef_<board> - Build entire flash image for <board>"
@echo " supported boards are ($(EF_BOARDS))"
@echo " ef_<board>_clean - Remove entire flash image for <board>"
@echo
@echo " [Flashtool]"
@echo " ft_<board> - Build flashtool package for <board>"
@echo " supported boards are ($(FT_BOARDS))"
@echo " ft_<board>_clean - Remove flashtool package for <board>"
@echo
@echo " [Unittests]"
@echo " ut_<test> - Build unit test <test>"
@echo " supported tests are ($(ALL_UNITTESTS))"
@echo " ut_<test>_xml - Run test and capture XML output into a file"
@echo " ut_<test>_run - Run test and dump output to console"
@echo
@echo " Hint: Add V=1 to your command line to see verbose build output."
@echo
@echo " Note: All tools will be installed into $(TOOLS_DIR)"
@echo " All build output will be placed in $(BUILD_DIR)"
@echo
.PHONY: all_clean
all_clean:
$(V0) @echo " CLEAN $(BUILD_DIR)"
$(V1) [ ! -d "$(BUILD_DIR)" ] || $(RM) -r "$(BUILD_DIR)"
##############################
#
# embedded related components
#
##############################
# $(1) = Canonical board name all in lower case (e.g. discoveryf4)
define FW_TEMPLATE
.PHONY: $(1) fw_$(1)
fw_$(1): fw_$(1)_all
fw_$(1)_%:
$(V1) cd $(TARGETS_DIR)/$(1)/fw && \
$$(MAKE) -r --no-print-directory \
BOARD_NAME=$(1) \
BUILD_PREFIX=fw \
OUTDIR=$(BUILD_DIR)/fw_$(1) \
$$*
.PHONY: $(1)_clean
$(1)_clean: fw_$(1)_clean
fw_$(1)_clean:
$(V0) @echo " CLEAN $$@"
$(V1) $(RM) -r $(BUILD_DIR)/fw_$(1)
endef
# $(1) = Canonical board name all in lower case (e.g. discoveryf4)
define BL_TEMPLATE
.PHONY: bl_$(1)
bl_$(1): bl_$(1)_all
bl_$(1)_%:
$(V1) cd $(TARGETS_DIR)/$(1)/bl && \
$$(MAKE) -r --no-print-directory \
BOARD_NAME=$(1) \
BUILD_PREFIX=bl \
OUTDIR=$(BUILD_DIR)/bl_$(1) \
$$*
.PHONY: bl_$(1)_clean
bl_$(1)_clean:
$(V0) @echo " CLEAN $$@"
$(V1) $(RM) -r $(BUILD_DIR)/bl_$(1)
endef
# $(1) = Canonical board name all in lower case (e.g. discoveryf4)
define EF_TEMPLATE
.PHONY: ef_$(1)
ef_$(1): ef_$(1)_all
ef_$(1)_%:
$(V1) cd $(TARGETS_DIR)/$(1)/ef && \
$$(MAKE) -r --no-print-directory \
BOARD_NAME=$(1) \
BUILD_PREFIX=ef \
OUTDIR=$(BUILD_DIR)/ef_$(1) \
$$*
.PHONY: ef_$(1)_clean
ef_$(1)_clean:
$(V0) @echo " CLEAN $$@"
$(V1) $(RM) -r $(BUILD_DIR)/ef_$(1)
endef
# $(1) = Canonical board name all in lower case (e.g. discoveryf4)
define FT_TEMPLATE
.PHONY: ft_$(1)
ft_$(1): ft_$(1)_all
ft_$(1)_%:
$(V1) cd $(TARGETS_DIR)/$(1)/ft && \
$$(MAKE) -r --no-print-directory \
BOARD_NAME=$(1) \
BUILD_PREFIX=ft \
OUTDIR=$(BUILD_DIR)/ft_$(1) \
$$*
.PHONY: ft_$(1)_clean
ft_$(1)_clean:
$(V0) @echo " CLEAN $$@"
$(V1) $(RM) -r $(BUILD_DIR)/ft_$(1)
endef
# When building any of the "all_*" targets, tell all sub makefiles to display
# additional details on each line of output to describe which build and target
# that each line applies to.
ifneq ($(strip $(filter all%,$(MAKECMDGOALS))),)
export ENABLE_MSG_EXTRA := yes
endif
# When building more than one goal in a single make invocation, also
# enable the extra context for each output line
ifneq ($(word 2,$(MAKECMDGOALS)),)
export ENABLE_MSG_EXTRA := yes
endif
# $(1) = Canonical board name all in lower case (e.g. discoveryf4)
define BOARD_PHONY_TEMPLATE
.PHONY: all_$(1)
all_$(1): $$(filter fw_$(1), $$(FW_TARGETS))
all_$(1): $$(filter bl_$(1), $$(BL_TARGETS))
all_$(1): $$(filter ef_$(1), $$(EF_TARGETS))
all_$(1): $$(filter ft_$(1), $$(FT_TARGETS))
.PHONY: all_$(1)_clean
all_$(1)_clean: $$(addsuffix _clean, $$(filter fw_$(1), $$(FW_TARGETS)))
all_$(1)_clean: $$(addsuffix _clean, $$(filter bl_$(1), $$(BL_TARGETS)))
all_$(1)_clean: $$(addsuffix _clean, $$(filter ef_$(1), $$(EF_TARGETS)))
all_$(1)_clean: $$(addsuffix _clean, $$(filter ft_$(1), $$(FT_TARGETS)))
endef
# Include all board definitions from targets dir
-include $(ROOT_DIR)/src/targets/*/target-defs.mk
# Generate the targets
FW_TARGETS := $(addprefix fw_, $(FW_BOARDS))
BL_TARGETS := $(addprefix bl_, $(BL_BOARDS))
EF_TARGETS := $(addprefix ef_, $(EF_BOARDS))
FT_TARGETS := $(addprefix ft_, $(FT_BOARDS))
.PHONY: all_fw all_fw_clean
all_fw: $(FW_TARGETS)
all_fw_clean: $(addsuffix _clean, $(FW_TARGETS))
.PHONY: all_bl all_bl_clean
all_bl: $(BL_TARGETS)
all_bl_clean: $(addsuffix _clean, $(BL_TARGETS))
.PHONY: all_ef all_ef_clean
all_ef: $(EF_TARGETS)
all_ef_clean: $(addsuffix _clean, $(EF_TARGETS))
.PHONY: all_ft all_ft_clean
all_ft: $(FT_TARGETS)
all_ft_clean: $(addsuffix _clean, $(FT_TARGETS))
.PHONY: all
all: all_fw all_bl all_ef all_ft
# Expand the firmware rules
$(foreach board, $(FW_BOARDS), $(eval $(call BOARD_PHONY_TEMPLATE,$(board))))
$(foreach board, $(FW_BOARDS), $(eval $(call FW_TEMPLATE,$(board))))
# Expand the bootloader rules
$(foreach board, $(BL_BOARDS), $(eval $(call BOARD_PHONY_TEMPLATE,$(board))))
$(foreach board, $(BL_BOARDS), $(eval $(call BL_TEMPLATE,$(board))))
# Expand the entire-flash rules
$(foreach board, $(EF_BOARDS), $(eval $(call BOARD_PHONY_TEMPLATE,$(board))))
$(foreach board, $(EF_BOARDS), $(eval $(call EF_TEMPLATE,$(board))))
# Expand the flashtool rules
$(foreach board, $(FT_BOARDS), $(eval $(call BOARD_PHONY_TEMPLATE,$(board))))
$(foreach board, $(FT_BOARDS), $(eval $(call FT_TEMPLATE,$(board))))
##############################
#
# Unit Tests
#
##############################
ALL_UNITTESTS := $(notdir $(wildcard $(TESTS_DIR)/*))
.PHONY: all_ut
all_ut: $(addsuffix _elf, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_xml
all_ut_xml: $(addsuffix _xml, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_run
all_ut_run: $(addsuffix _run, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_clean
all_ut_clean: $(addsuffix _clean, $(addprefix ut_, $(ALL_UNITTESTS)))
# $(1) = Unit test name
define UT_TEMPLATE
.PHONY: ut_$(1)
ut_$(1): ut_$(1)_all
ut_$(1)_%:
$(V1) cd $(TESTS_DIR)/$(1) && \
$$(MAKE) -r --no-print-directory \
BOARD_NAME=$(1) \
BUILD_PREFIX=ut \
TCHAIN_PREFIX="" \
TARGET=ut_$(1) \
OUTDIR=$(BUILD_DIR)/ut_$(1) \
GTEST_DIR=$(GTEST_DIR) \
$$*
.PHONY: ut_$(1)_clean
ut_$(1)_clean:
$(V0) @echo " CLEAN $$@"
$(V1) $(RM) -r $(BUILD_DIR)/ut_$(1)
endef
# Expand the unittest rules
$(foreach ut, $(ALL_UNITTESTS), $(eval $(call UT_TEMPLATE,$(ut))))
# Disable parallel make when the all_ut_run target is requested otherwise the XML
# output is interleaved with the rest of the make output.
ifneq ($(strip $(filter all_ut_run,$(MAKECMDGOALS))),)
.NOTPARALLEL:
$(info *NOTE* Parallel make disabled by all_ut_run target so we have sane console output)
endif