1 export FLIGHT_MAKEFILE
:= TRUE
2 export FLIGHT_ROOT_DIR
:= $(realpath
$(dir $(lastword
$(MAKEFILE_LIST
))))
3 export PIOS
:= $(FLIGHT_ROOT_DIR
)/pios
4 export FLIGHTLIB
:= $(FLIGHT_ROOT_DIR
)/libraries
5 export OPMODULEDIR
:= $(FLIGHT_ROOT_DIR
)/modules
6 export OPUAVOBJ
:= $(FLIGHT_ROOT_DIR
)/uavobjects
7 export OPUAVTALK
:= $(FLIGHT_ROOT_DIR
)/uavtalk
8 export FLIGHT_OUT_DIR ?
= $(CURDIR
)
10 # Define supported board lists
11 ALL_BOARDS
:= coptercontrol revolution revonano sparky2
12 ALL_BOARDS
+= revoproto
13 ALL_BOARDS
+= oplinkmini
14 ALL_BOARDS
+= gpsplatinum
16 ALL_BOARDS
+= discoveryf4bare
17 # SimPosix only builds on Linux
18 ifeq ($(UNAME
), Linux
)
19 ALL_BOARDS
+= simposix
22 # Short names of each board (used to display board name in parallel builds)
23 coptercontrol_short
:= 'cc '
24 oplinkmini_short
:= 'oplm'
25 revolution_short
:= 'revo'
27 revoproto_short
:= 'revp'
28 revonano_short
:= 'revn'
29 sparky2_short
:= 'spk2'
30 simposix_short
:= 'posx'
31 discoveryf4bare_short
:= 'df4b'
32 gpsplatinum_short
:= 'gps9'
34 # Start out assuming that we'll build fw, bl and bu for all boards
35 FW_BOARDS
:= $(ALL_BOARDS
)
36 BL_BOARDS
:= $(ALL_BOARDS
)
37 BU_BOARDS
:= $(ALL_BOARDS
)
38 EF_BOARDS
:= $(ALL_BOARDS
)
40 # SimPosix doesn't have a BL, BU or EF target so we need to
41 # filter them out to prevent errors on the all_flight target.
42 BL_BOARDS
:= $(filter-out simposix gpsplatinum
, $(BL_BOARDS
))
43 BU_BOARDS
:= $(filter-out simposix gpsplatinum
, $(BU_BOARDS
))
44 EF_BOARDS
:= $(filter-out simposix gpsplatinum
, $(EF_BOARDS
))
46 # Generate the targets for whatever boards are left in each list
47 FW_TARGETS
:= $(addprefix fw_
, $(FW_BOARDS
))
48 BL_TARGETS
:= $(addprefix bl_
, $(BL_BOARDS
))
49 BU_TARGETS
:= $(addprefix bu_
, $(BU_BOARDS
))
50 EF_TARGETS
:= $(addprefix ef_
, $(EF_BOARDS
))
52 ALL_FLIGHT
:= all_fw all_bl all_bu all_ef
53 ALL_FLIGHT_CLEAN
:= $(addsuffix _clean
,$(ALL_FLIGHT
))
55 .PHONY
: all_flight all_flight_clean
56 all_flight
: $(ALL_FLIGHT
)
57 all_flight_clean
: $(ALL_FLIGHT_CLEAN
)
60 # TEMPLATES (used to generate build rules)
62 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
63 # $(2) = Short name for board (e.g cc)
69 fw_
$(1)_
%: flight_uavobjects
70 $(V1
) $$(ARM_GCC_VERSION_CHECK_TEMPLATE
)
71 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/fw_
$(1)/dep
72 $(V1
) cd
$(FLIGHT_ROOT_DIR
)/targets
/boards
/$(1)/firmware
&& \
73 $$(MAKE
) -r
--no-print-directory \
76 BOARD_SHORT_NAME
=$(2) \
77 TOPDIR
=$(FLIGHT_ROOT_DIR
)/targets
/boards
/$(1)/firmware \
78 OUTDIR
=$(FLIGHT_OUT_DIR
)/fw_
$(1) \
83 $(1)_clean
: fw_
$(1)_clean
85 @echo
" CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/fw_$(1))"
86 $(V1
) rm -fr
$(FLIGHT_OUT_DIR
)/fw_
$(1)
89 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
90 # $(2) = Short name for board (e.g cc)
94 bl_
$(1)_bino
: bl_
$(1)_bin
97 $(V1
) $$(ARM_GCC_VERSION_CHECK_TEMPLATE
)
98 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/bl_
$(1)/dep
99 $(V1
) cd
$(FLIGHT_ROOT_DIR
)/targets
/boards
/$(1)/bootloader
&& \
100 $$(MAKE
) -r
--no-print-directory \
103 BOARD_SHORT_NAME
=$(2) \
104 TOPDIR
=$(FLIGHT_ROOT_DIR
)/targets
/boards
/$(1)/bootloader \
105 OUTDIR
=$(FLIGHT_OUT_DIR
)/bl_
$(1) \
110 unbrick_
$(1): bl_
$(1)_hex
111 $(if
$(filter-out undefined
,$(origin UNBRICK_TTY
)),
112 $(V0
) @echo
" UNBRICK $(1) via $$(UNBRICK_TTY)"
113 $(V1
) $(STM32FLASH_DIR
)/stm32flash \
114 -w
$(FLIGHT_OUT_DIR
)/bl_
$(1)/bl_
$(1).hex \
119 $(V0
) @echo
"ERROR: You must specify UNBRICK_TTY=<serial-device> to use for unbricking."
120 $(V0
) @echo
" eg. $$(MAKE) $$@ UNBRICK_TTY=/dev/ttyUSB0"
123 .PHONY
: bl_
$(1)_clean
125 @echo
" CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/bl_$(1))"
126 $(V1
) rm -fr
$(FLIGHT_OUT_DIR
)/bl_
$(1)
129 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
130 # $(2) = Short name for board (e.g cc)
133 bu_
$(1): bu_
$(1)_opfw
135 bu_
$(1)_
%: bl_
$(1)_bino
136 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/bu_
$(1)/dep
137 $(V1
) cd
$(FLIGHT_ROOT_DIR
)/targets
/common
/bootloader_updater
&& \
138 $$(MAKE
) -r
--no-print-directory \
141 BOARD_SHORT_NAME
=$(2) \
142 TOPDIR
=$(FLIGHT_ROOT_DIR
)/targets
/common
/bootloader_updater \
143 OUTDIR
=$(FLIGHT_OUT_DIR
)/bu_
$(1) \
147 .PHONY
: bu_
$(1)_clean
149 @echo
" CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/bu_$(1))"
150 $(V1
) rm -fr
$(FLIGHT_OUT_DIR
)/bu_
$(1)
153 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
154 # $(2) = Short name for board (e.g cc)
159 ef_
$(1)_
%: bl_
$(1)_bin fw_
$(1)_opfw
160 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/ef_
$(1)
161 $(V1
) cd
$(FLIGHT_ROOT_DIR
)/targets
/common
/entire_flash
&& \
162 $$(MAKE
) -r
--no-print-directory \
165 BOARD_SHORT_NAME
=$(2) \
166 DFU_CMD
="$(DFUUTIL_DIR)/bin/dfu-util" \
167 TOPDIR
=$(FLIGHT_ROOT_DIR
)/targets
/common
/entire_flash \
168 OUTDIR
=$(FLIGHT_OUT_DIR
)/ef_
$(1) \
172 .PHONY
: ef_
$(1)_clean
174 @echo
" CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/ef_$(1))"
175 $(V1
) rm -fr
$(FLIGHT_OUT_DIR
)/ef_
$(1)
178 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
179 define BOARD_PHONY_TEMPLATE
181 all_
$(1): $$(filter fw_
$(1), $$(FW_TARGETS
))
182 all_
$(1): $$(filter bl_
$(1), $$(BL_TARGETS
))
183 all_
$(1): $$(filter bu_
$(1), $$(BU_TARGETS
))
184 all_
$(1): $$(filter ef_
$(1), $$(EF_TARGETS
))
186 .PHONY
: all_
$(1)_clean
187 all_
$(1)_clean
: $$(addsuffix _clean
, $$(filter fw_
$(1), $$(FW_TARGETS
)))
188 all_
$(1)_clean
: $$(addsuffix _clean
, $$(filter bl_
$(1), $$(BL_TARGETS
)))
189 all_
$(1)_clean
: $$(addsuffix _clean
, $$(filter bu_
$(1), $$(BU_TARGETS
)))
190 all_
$(1)_clean
: $$(addsuffix _clean
, $$(filter ef_
$(1), $$(EF_TARGETS
)))
194 # Generate flight build rules
198 .PHONY
: all_fw all_fw_clean
199 all_fw
: $(addsuffix _opfw
, $(FW_TARGETS
))
200 all_fw_clean
: $(addsuffix _clean
, $(FW_TARGETS
))
202 .PHONY
: all_bl all_bl_clean
203 all_bl
: $(addsuffix _bin
, $(BL_TARGETS
))
204 all_bl_clean
: $(addsuffix _clean
, $(BL_TARGETS
))
206 .PHONY
: all_bu all_bu_clean
207 all_bu
: $(addsuffix _opfw
, $(BU_TARGETS
))
208 all_bu_clean
: $(addsuffix _clean
, $(BU_TARGETS
))
210 .PHONY
: all_ef all_ef_clean
211 all_ef
: $(EF_TARGETS
)
212 all_ef_clean
: $(addsuffix _clean
, $(EF_TARGETS
))
214 # Expand the groups of targets for each board
215 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call BOARD_PHONY_TEMPLATE
,$(board
))))
217 # Expand the firmware rules
218 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call FW_TEMPLATE
,$(board
),$($(board
)_short
))))
220 # Expand the bootloader rules
221 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call BL_TEMPLATE
,$(board
),$($(board
)_short
))))
223 # Expand the bootloader updater rules
224 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call BU_TEMPLATE
,$(board
),$($(board
)_short
))))
226 # Expand the entire-flash rules
227 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call EF_TEMPLATE
,$(board
),$($(board
)_short
))))
230 sim_win32
: sim_win32_exe
232 sim_win32_
%: flight_uavobjects
233 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/sitl_win32
234 $(V1
) $(MAKE
) --no-print-directory \
235 -C
$(FLIGHT_ROOT_DIR
)/targets
/OpenPilot
--file
=$(FLIGHT_ROOT_DIR
)/targets
/OpenPilot
/Makefile.win32
$*
240 sim_osx_
%: flight_uavobjects
241 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/sim_osx
242 $(V1
) $(MAKE
) --no-print-directory \
243 -C
$(FLIGHT_ROOT_DIR
)/targets
/SensorTest
--file
=$(FLIGHT_ROOT_DIR
)/targets
/SensorTest
/Makefile.osx
$*
245 ##############################
249 ##############################
250 UAVOBJGENERATOR ?
= $(shell which uavobjgenerator
)
252 UAVOBJ_XML_DIR
:= $(FLIGHT_ROOT_DIR
)/..
/shared
/uavobjectdefinition
253 export FLIGHT_UAVOBJ_DIR
:= $(FLIGHT_OUT_DIR
)/uavobjects
255 .PHONY
: flight_uavobjects
256 flight_uavobjects
: $(UAVOBJGENERATOR
)
257 @mkdir
-p
$(FLIGHT_UAVOBJ_DIR
)
258 $(V1
) cd
$(FLIGHT_UAVOBJ_DIR
) && \
259 $(UAVOBJGENERATOR
) -flight
$(UAVOBJ_XML_DIR
) $(FLIGHT_ROOT_DIR
)/..
262 ##############################
266 ##############################
268 ALL_UNITTESTS
:= logfs math lednotification
270 # Build the directory for the unit tests
271 UT_OUT_DIR
:= $(BUILD_DIR
)/unit_tests
272 DIRS
+= $(UT_OUT_DIR
)
275 all_ut
: $(addsuffix _elf
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
278 all_ut_xml
: $(addsuffix _xml
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
281 all_ut_run
: $(addsuffix _run
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
285 @
$(ECHO
) " CLEAN $(call toprel, $(UT_OUT_DIR))"
286 $(V1
) [ ! -d
"$(UT_OUT_DIR)" ] ||
$(RM
) -r
"$(UT_OUT_DIR)"
288 # $(1) = Unit test name
293 ut_
$(1)_
%: $$(UT_OUT_DIR
)
294 $(V1
) $(MKDIR
) -p
$(UT_OUT_DIR
)/$(1)
295 $(V1
) cd
$(ROOT_DIR
)/flight
/tests
/$(1) && \
296 $$(MAKE
) -r
--no-print-directory \
298 BOARD_SHORT_NAME
=$(1) \
299 TOPDIR
=$(ROOT_DIR
)/flight
/tests
/$(1) \
300 OUTDIR
="$(UT_OUT_DIR)/$(1)" \
304 .PHONY
: ut_
$(1)_clean
306 @
$(ECHO
) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
307 $(V1
) [ ! -d
"$(UT_OUT_DIR)/$(1)" ] ||
$(RM
) -r
"$(UT_OUT_DIR)/$(1)"
310 # Expand the unittest rules
311 $(foreach ut
, $(ALL_UNITTESTS
), $(eval
$(call UT_TEMPLATE
,$(ut
))))
313 # Disable parallel make when the all_ut_run target is requested otherwise the TAP
314 # output is interleaved with the rest of the make output.
315 ifneq ($(strip $(filter all_ut_run
,$(MAKECMDGOALS
))),)
317 $(info $(EMPTY
) NOTE Parallel make disabled by all_ut_run target so we have sane console output
)