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 oplinkmini revolution osd revoproto simposix discoveryf4bare gpsplatinum revonano
13 # Short names of each board (used to display board name in parallel builds)
14 coptercontrol_short
:= 'cc '
15 oplinkmini_short
:= 'oplm'
16 revolution_short
:= 'revo'
18 revoproto_short
:= 'revp'
19 revonano_short
:= 'revn'
20 simposix_short
:= 'posx'
21 discoveryf4bare_short
:= 'df4b'
22 gpsplatinum_short
:= 'gps9'
24 # SimPosix only builds on Linux so drop it from the list for
25 # all other platforms.
26 ifneq ($(UNAME
), Linux
)
27 ALL_BOARDS
:= $(filter-out simposix
, $(ALL_BOARDS
))
30 # Start out assuming that we'll build fw, bl and bu for all boards
31 FW_BOARDS
:= $(ALL_BOARDS
)
32 BL_BOARDS
:= $(ALL_BOARDS
)
33 BU_BOARDS
:= $(ALL_BOARDS
)
34 EF_BOARDS
:= $(ALL_BOARDS
)
36 # SimPosix doesn't have a BL, BU or EF target so we need to
37 # filter them out to prevent errors on the all_flight target.
38 BL_BOARDS
:= $(filter-out simposix
, $(BL_BOARDS
))
39 BU_BOARDS
:= $(filter-out simposix gpsplatinum
, $(BU_BOARDS
))
40 EF_BOARDS
:= $(filter-out simposix
, $(EF_BOARDS
))
42 # Generate the targets for whatever boards are left in each list
43 FW_TARGETS
:= $(addprefix fw_
, $(FW_BOARDS
))
44 BL_TARGETS
:= $(addprefix bl_
, $(BL_BOARDS
))
45 BU_TARGETS
:= $(addprefix bu_
, $(BU_BOARDS
))
46 EF_TARGETS
:= $(addprefix ef_
, $(EF_BOARDS
))
48 ALL_FLIGHT
:= all_fw all_bl all_bu all_ef
49 ALL_FLIGHT_CLEAN
:= $(addsuffix _clean
,$(ALL_FLIGHT
))
51 .PHONY
: all_flight all_flight_clean
52 all_flight
: $(ALL_FLIGHT
)
53 all_flight_clean
: $(ALL_FLIGHT_CLEAN
)
56 # TEMPLATES (used to generate build rules)
58 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
59 # $(2) = Short name for board (e.g cc)
65 fw_
$(1)_
%: flight_uavobjects
66 $(V1
) $$(ARM_GCC_VERSION_CHECK_TEMPLATE
)
67 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/fw_
$(1)/dep
68 $(V1
) cd
$(FLIGHT_ROOT_DIR
)/targets
/boards
/$(1)/firmware
&& \
69 $$(MAKE
) -r
--no-print-directory \
72 BOARD_SHORT_NAME
=$(2) \
73 TOPDIR
=$(FLIGHT_ROOT_DIR
)/targets
/boards
/$(1)/firmware \
74 OUTDIR
=$(FLIGHT_OUT_DIR
)/fw_
$(1) \
79 $(1)_clean
: fw_
$(1)_clean
81 @echo
" CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/fw_$(1))"
82 $(V1
) rm -fr
$(FLIGHT_OUT_DIR
)/fw_
$(1)
85 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
86 # $(2) = Short name for board (e.g cc)
90 bl_
$(1)_bino
: bl_
$(1)_bin
93 $(V1
) $$(ARM_GCC_VERSION_CHECK_TEMPLATE
)
94 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/bl_
$(1)/dep
95 $(V1
) cd
$(FLIGHT_ROOT_DIR
)/targets
/boards
/$(1)/bootloader
&& \
96 $$(MAKE
) -r
--no-print-directory \
99 BOARD_SHORT_NAME
=$(2) \
100 TOPDIR
=$(FLIGHT_ROOT_DIR
)/targets
/boards
/$(1)/bootloader \
101 OUTDIR
=$(FLIGHT_OUT_DIR
)/bl_
$(1) \
106 unbrick_
$(1): bl_
$(1)_hex
107 $(if
$(filter-out undefined
,$(origin UNBRICK_TTY
)),
108 $(V0
) @echo
" UNBRICK $(1) via $$(UNBRICK_TTY)"
109 $(V1
) $(STM32FLASH_DIR
)/stm32flash \
110 -w
$(FLIGHT_OUT_DIR
)/bl_
$(1)/bl_
$(1).hex \
115 $(V0
) @echo
"ERROR: You must specify UNBRICK_TTY=<serial-device> to use for unbricking."
116 $(V0
) @echo
" eg. $$(MAKE) $$@ UNBRICK_TTY=/dev/ttyUSB0"
119 .PHONY
: bl_
$(1)_clean
121 @echo
" CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/bl_$(1))"
122 $(V1
) rm -fr
$(FLIGHT_OUT_DIR
)/bl_
$(1)
125 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
126 # $(2) = Short name for board (e.g cc)
129 bu_
$(1): bu_
$(1)_opfw
131 bu_
$(1)_
%: bl_
$(1)_bino
132 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/bu_
$(1)/dep
133 $(V1
) cd
$(FLIGHT_ROOT_DIR
)/targets
/common
/bootloader_updater
&& \
134 $$(MAKE
) -r
--no-print-directory \
137 BOARD_SHORT_NAME
=$(2) \
138 TOPDIR
=$(FLIGHT_ROOT_DIR
)/targets
/common
/bootloader_updater \
139 OUTDIR
=$(FLIGHT_OUT_DIR
)/bu_
$(1) \
143 .PHONY
: bu_
$(1)_clean
145 @echo
" CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/bu_$(1))"
146 $(V1
) rm -fr
$(FLIGHT_OUT_DIR
)/bu_
$(1)
149 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
150 # $(2) = Short name for board (e.g cc)
155 ef_
$(1)_
%: bl_
$(1)_bin fw_
$(1)_opfw
156 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/ef_
$(1)
157 $(V1
) cd
$(FLIGHT_ROOT_DIR
)/targets
/common
/entire_flash
&& \
158 $$(MAKE
) -r
--no-print-directory \
161 BOARD_SHORT_NAME
=$(2) \
162 DFU_CMD
="$(DFUUTIL_DIR)/bin/dfu-util" \
163 TOPDIR
=$(FLIGHT_ROOT_DIR
)/targets
/common
/entire_flash \
164 OUTDIR
=$(FLIGHT_OUT_DIR
)/ef_
$(1) \
168 .PHONY
: ef_
$(1)_clean
170 @echo
" CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/ef_$(1))"
171 $(V1
) rm -fr
$(FLIGHT_OUT_DIR
)/ef_
$(1)
174 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
175 define BOARD_PHONY_TEMPLATE
177 all_
$(1): $$(filter fw_
$(1), $$(FW_TARGETS
))
178 all_
$(1): $$(filter bl_
$(1), $$(BL_TARGETS
))
179 all_
$(1): $$(filter bu_
$(1), $$(BU_TARGETS
))
180 all_
$(1): $$(filter ef_
$(1), $$(EF_TARGETS
))
182 .PHONY
: all_
$(1)_clean
183 all_
$(1)_clean
: $$(addsuffix _clean
, $$(filter fw_
$(1), $$(FW_TARGETS
)))
184 all_
$(1)_clean
: $$(addsuffix _clean
, $$(filter bl_
$(1), $$(BL_TARGETS
)))
185 all_
$(1)_clean
: $$(addsuffix _clean
, $$(filter bu_
$(1), $$(BU_TARGETS
)))
186 all_
$(1)_clean
: $$(addsuffix _clean
, $$(filter ef_
$(1), $$(EF_TARGETS
)))
190 # Generate flight build rules
194 .PHONY
: all_fw all_fw_clean
195 all_fw
: $(addsuffix _opfw
, $(FW_TARGETS
))
196 all_fw_clean
: $(addsuffix _clean
, $(FW_TARGETS
))
198 .PHONY
: all_bl all_bl_clean
199 all_bl
: $(addsuffix _bin
, $(BL_TARGETS
))
200 all_bl_clean
: $(addsuffix _clean
, $(BL_TARGETS
))
202 .PHONY
: all_bu all_bu_clean
203 all_bu
: $(addsuffix _opfw
, $(BU_TARGETS
))
204 all_bu_clean
: $(addsuffix _clean
, $(BU_TARGETS
))
206 .PHONY
: all_ef all_ef_clean
207 all_ef
: $(EF_TARGETS
)
208 all_ef_clean
: $(addsuffix _clean
, $(EF_TARGETS
))
210 # Expand the groups of targets for each board
211 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call BOARD_PHONY_TEMPLATE
,$(board
))))
213 # Expand the firmware rules
214 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call FW_TEMPLATE
,$(board
),$($(board
)_short
))))
216 # Expand the bootloader rules
217 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call BL_TEMPLATE
,$(board
),$($(board
)_short
))))
219 # Expand the bootloader updater rules
220 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call BU_TEMPLATE
,$(board
),$($(board
)_short
))))
222 # Expand the entire-flash rules
223 $(foreach board
, $(ALL_BOARDS
), $(eval
$(call EF_TEMPLATE
,$(board
),$($(board
)_short
))))
226 sim_win32
: sim_win32_exe
228 sim_win32_
%: flight_uavobjects
229 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/sitl_win32
230 $(V1
) $(MAKE
) --no-print-directory \
231 -C
$(FLIGHT_ROOT_DIR
)/targets
/OpenPilot
--file
=$(FLIGHT_ROOT_DIR
)/targets
/OpenPilot
/Makefile.win32
$*
236 sim_osx_
%: flight_uavobjects
237 $(V1
) mkdir
-p
$(FLIGHT_OUT_DIR
)/sim_osx
238 $(V1
) $(MAKE
) --no-print-directory \
239 -C
$(FLIGHT_ROOT_DIR
)/targets
/SensorTest
--file
=$(FLIGHT_ROOT_DIR
)/targets
/SensorTest
/Makefile.osx
$*
241 ##############################
245 ##############################
246 UAVOBJGENERATOR ?
= $(shell which uavobjgenerator
)
248 UAVOBJ_XML_DIR
:= $(FLIGHT_ROOT_DIR
)/..
/shared
/uavobjectdefinition
249 export FLIGHT_UAVOBJ_DIR
:= $(FLIGHT_OUT_DIR
)/uavobjects
251 .PHONY
: flight_uavobjects
252 flight_uavobjects
: $(UAVOBJGENERATOR
)
253 @mkdir
-p
$(FLIGHT_UAVOBJ_DIR
)
254 $(V1
) cd
$(FLIGHT_UAVOBJ_DIR
) && \
255 $(UAVOBJGENERATOR
) -flight
$(UAVOBJ_XML_DIR
) $(FLIGHT_ROOT_DIR
)/..
258 ##############################
262 ##############################
264 ALL_UNITTESTS
:= logfs math lednotification
266 # Build the directory for the unit tests
267 UT_OUT_DIR
:= $(BUILD_DIR
)/unit_tests
268 DIRS
+= $(UT_OUT_DIR
)
271 all_ut
: $(addsuffix _elf
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
274 all_ut_xml
: $(addsuffix _xml
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
277 all_ut_run
: $(addsuffix _run
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
281 @
$(ECHO
) " CLEAN $(call toprel, $(UT_OUT_DIR))"
282 $(V1
) [ ! -d
"$(UT_OUT_DIR)" ] ||
$(RM
) -r
"$(UT_OUT_DIR)"
284 # $(1) = Unit test name
289 ut_
$(1)_
%: $$(UT_OUT_DIR
)
290 $(V1
) $(MKDIR
) -p
$(UT_OUT_DIR
)/$(1)
291 $(V1
) cd
$(ROOT_DIR
)/flight
/tests
/$(1) && \
292 $$(MAKE
) -r
--no-print-directory \
294 BOARD_SHORT_NAME
=$(1) \
295 TOPDIR
=$(ROOT_DIR
)/flight
/tests
/$(1) \
296 OUTDIR
="$(UT_OUT_DIR)/$(1)" \
300 .PHONY
: ut_
$(1)_clean
302 @
$(ECHO
) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
303 $(V1
) [ ! -d
"$(UT_OUT_DIR)/$(1)" ] ||
$(RM
) -r
"$(UT_OUT_DIR)/$(1)"
306 # Expand the unittest rules
307 $(foreach ut
, $(ALL_UNITTESTS
), $(eval
$(call UT_TEMPLATE
,$(ut
))))
309 # Disable parallel make when the all_ut_run target is requested otherwise the TAP
310 # output is interleaved with the rest of the make output.
311 ifneq ($(strip $(filter all_ut_run
,$(MAKECMDGOALS
))),)
313 $(info $(EMPTY
) NOTE Parallel make disabled by all_ut_run target so we have sane console output
)