update credits
[librepilot.git] / flight / Makefile
blobe7603b6c5f2a25b8c22f29536e234cde2e093907
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
15 ALL_BOARDS += osd
16 ALL_BOARDS += discoveryf4bare
17 ALL_BOARDS += ccf3d spracingf3 spracingf3evo nucleof303re pikoblx tinyfish
18 # SimPosix only builds on Linux
19 ifeq ($(UNAME), Linux)
20 ALL_BOARDS += simposix
21 endif
23 # Short names of each board (used to display board name in parallel builds)
24 spracingf3_short := 'srf3'
25 spracingf3evo_short := 'spev'
26 ccf3d_short := 'cf3d'
27 coptercontrol_short := 'cc '
28 oplinkmini_short := 'oplm'
29 revolution_short := 'revo'
30 osd_short := 'osd '
31 revoproto_short := 'revp'
32 revonano_short := 'revn'
33 sparky2_short := 'spk2'
34 simposix_short := 'posx'
35 discoveryf4bare_short := 'df4b'
36 gpsplatinum_short := 'gps9'
37 nucleof303re_short := 'nf3r'
38 pikoblx_short := 'piko'
39 tinyfish_short := 'tfsh'
41 # Start out assuming that we'll build fw, bl and bu for all boards
42 FW_BOARDS := $(ALL_BOARDS)
43 BL_BOARDS := $(ALL_BOARDS)
44 BU_BOARDS := $(ALL_BOARDS)
45 EF_BOARDS := $(ALL_BOARDS)
47 # SimPosix doesn't have a BL, BU or EF target so we need to
48 # filter them out to prevent errors on the all_flight target.
49 BL_BOARDS := $(filter-out simposix, $(BL_BOARDS))
50 BU_BOARDS := $(filter-out simposix gpsplatinum, $(BU_BOARDS))
51 EF_BOARDS := $(filter-out simposix, $(EF_BOARDS))
53 # Generate the targets for whatever boards are left in each list
54 FW_TARGETS := $(addprefix fw_, $(FW_BOARDS))
55 BL_TARGETS := $(addprefix bl_, $(BL_BOARDS))
56 BU_TARGETS := $(addprefix bu_, $(BU_BOARDS))
57 EF_TARGETS := $(addprefix ef_, $(EF_BOARDS))
59 ALL_FLIGHT := all_fw all_bl all_bu all_ef
60 ALL_FLIGHT_CLEAN := $(addsuffix _clean,$(ALL_FLIGHT))
62 .PHONY: all_flight all_flight_clean
63 all_flight: $(ALL_FLIGHT)
64 all_flight_clean: $(ALL_FLIGHT_CLEAN)
67 # TEMPLATES (used to generate build rules)
69 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
70 # $(2) = Short name for board (e.g cc)
71 define FW_TEMPLATE
72 .PHONY: $(1) fw_$(1)
73 $(1): fw_$(1)_opfw
74 fw_$(1): fw_$(1)_opfw
76 fw_$(1)_%: flight_uavobjects
77 $(V1) $$(ARM_GCC_VERSION_CHECK_TEMPLATE)
78 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/fw_$(1)/dep
79 $(V1) cd $(FLIGHT_ROOT_DIR)/targets/boards/$(1)/firmware && \
80 $$(MAKE) -r --no-print-directory \
81 BUILD_TYPE=fw \
82 BOARD_NAME=$(1) \
83 BOARD_SHORT_NAME=$(2) \
84 TOPDIR=$(FLIGHT_ROOT_DIR)/targets/boards/$(1)/firmware \
85 OUTDIR=$(FLIGHT_OUT_DIR)/fw_$(1) \
86 TARGET=fw_$(1) \
87 $$*
89 .PHONY: $(1)_clean
90 $(1)_clean: fw_$(1)_clean
91 fw_$(1)_clean:
92 @echo " CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/fw_$(1))"
93 $(V1) rm -fr $(FLIGHT_OUT_DIR)/fw_$(1)
94 endef
96 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
97 # $(2) = Short name for board (e.g cc)
98 define BL_TEMPLATE
99 .PHONY: bl_$(1)
100 bl_$(1): bl_$(1)_bin
101 bl_$(1)_bino: bl_$(1)_bin
103 bl_$(1)_%:
104 $(V1) $$(ARM_GCC_VERSION_CHECK_TEMPLATE)
105 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/bl_$(1)/dep
106 $(V1) cd $(FLIGHT_ROOT_DIR)/targets/boards/$(1)/bootloader && \
107 $$(MAKE) -r --no-print-directory \
108 BUILD_TYPE=bl \
109 BOARD_NAME=$(1) \
110 BOARD_SHORT_NAME=$(2) \
111 TOPDIR=$(FLIGHT_ROOT_DIR)/targets/boards/$(1)/bootloader \
112 OUTDIR=$(FLIGHT_OUT_DIR)/bl_$(1) \
113 TARGET=bl_$(1) \
116 .PHONY: unbrick_$(1)
117 unbrick_$(1): bl_$(1)_hex
118 $(if $(filter-out undefined,$(origin UNBRICK_TTY)),
119 $(V0) @echo " UNBRICK $(1) via $$(UNBRICK_TTY)"
120 $(V1) $(STM32FLASH_DIR)/stm32flash \
121 -w $(FLIGHT_OUT_DIR)/bl_$(1)/bl_$(1).hex \
122 -g 0x0 \
123 $$(UNBRICK_TTY)
125 $(V0) @echo
126 $(V0) @echo "ERROR: You must specify UNBRICK_TTY=<serial-device> to use for unbricking."
127 $(V0) @echo " eg. $$(MAKE) $$@ UNBRICK_TTY=/dev/ttyUSB0"
130 .PHONY: bl_$(1)_clean
131 bl_$(1)_clean:
132 @echo " CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/bl_$(1))"
133 $(V1) rm -fr $(FLIGHT_OUT_DIR)/bl_$(1)
134 endef
136 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
137 # $(2) = Short name for board (e.g cc)
138 define BU_TEMPLATE
139 .PHONY: bu_$(1)
140 bu_$(1): bu_$(1)_opfw
142 bu_$(1)_%: bl_$(1)_bino
143 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/bu_$(1)/dep
144 $(V1) cd $(FLIGHT_ROOT_DIR)/targets/common/bootloader_updater && \
145 $$(MAKE) -r --no-print-directory \
146 BUILD_TYPE=bu \
147 BOARD_NAME=$(1) \
148 BOARD_SHORT_NAME=$(2) \
149 TOPDIR=$(FLIGHT_ROOT_DIR)/targets/common/bootloader_updater \
150 OUTDIR=$(FLIGHT_OUT_DIR)/bu_$(1) \
151 TARGET=bu_$(1) \
154 .PHONY: bu_$(1)_clean
155 bu_$(1)_clean:
156 @echo " CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/bu_$(1))"
157 $(V1) rm -fr $(FLIGHT_OUT_DIR)/bu_$(1)
158 endef
160 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
161 # $(2) = Short name for board (e.g cc)
162 define EF_TEMPLATE
163 .PHONY: ef_$(1)
164 ef_$(1): ef_$(1)_bin
166 ef_$(1)_%: bl_$(1)_bin fw_$(1)_opfw
167 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/ef_$(1)
168 $(V1) cd $(FLIGHT_ROOT_DIR)/targets/common/entire_flash && \
169 $$(MAKE) -r --no-print-directory \
170 BUILD_TYPE=ef \
171 BOARD_NAME=$(1) \
172 BOARD_SHORT_NAME=$(2) \
173 DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \
174 TOPDIR=$(FLIGHT_ROOT_DIR)/targets/common/entire_flash \
175 OUTDIR=$(FLIGHT_OUT_DIR)/ef_$(1) \
176 TARGET=ef_$(1) \
179 .PHONY: ef_$(1)_clean
180 ef_$(1)_clean:
181 @echo " CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/ef_$(1))"
182 $(V1) rm -fr $(FLIGHT_OUT_DIR)/ef_$(1)
183 endef
185 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
186 define BOARD_PHONY_TEMPLATE
187 .PHONY: all_$(1)
188 all_$(1): $$(filter fw_$(1), $$(FW_TARGETS))
189 all_$(1): $$(filter bl_$(1), $$(BL_TARGETS))
190 all_$(1): $$(filter bu_$(1), $$(BU_TARGETS))
191 all_$(1): $$(filter ef_$(1), $$(EF_TARGETS))
193 .PHONY: all_$(1)_clean
194 all_$(1)_clean: $$(addsuffix _clean, $$(filter fw_$(1), $$(FW_TARGETS)))
195 all_$(1)_clean: $$(addsuffix _clean, $$(filter bl_$(1), $$(BL_TARGETS)))
196 all_$(1)_clean: $$(addsuffix _clean, $$(filter bu_$(1), $$(BU_TARGETS)))
197 all_$(1)_clean: $$(addsuffix _clean, $$(filter ef_$(1), $$(EF_TARGETS)))
198 endef
201 # Generate flight build rules
202 .PHONY: first
203 first: all_fw
205 .PHONY: all_fw all_fw_clean
206 all_fw: $(addsuffix _opfw, $(FW_TARGETS))
207 all_fw_clean: $(addsuffix _clean, $(FW_TARGETS))
209 .PHONY: all_bl all_bl_clean
210 all_bl: $(addsuffix _bin, $(BL_TARGETS))
211 all_bl_clean: $(addsuffix _clean, $(BL_TARGETS))
213 .PHONY: all_bu all_bu_clean
214 all_bu: $(addsuffix _opfw, $(BU_TARGETS))
215 all_bu_clean: $(addsuffix _clean, $(BU_TARGETS))
217 .PHONY: all_ef all_ef_clean
218 all_ef: $(EF_TARGETS)
219 all_ef_clean: $(addsuffix _clean, $(EF_TARGETS))
221 # Expand the groups of targets for each board
222 $(foreach board, $(ALL_BOARDS), $(eval $(call BOARD_PHONY_TEMPLATE,$(board))))
224 # Expand the firmware rules
225 $(foreach board, $(ALL_BOARDS), $(eval $(call FW_TEMPLATE,$(board),$($(board)_short))))
227 # Expand the bootloader rules
228 $(foreach board, $(ALL_BOARDS), $(eval $(call BL_TEMPLATE,$(board),$($(board)_short))))
230 # Expand the bootloader updater rules
231 $(foreach board, $(ALL_BOARDS), $(eval $(call BU_TEMPLATE,$(board),$($(board)_short))))
233 # Expand the entire-flash rules
234 $(foreach board, $(ALL_BOARDS), $(eval $(call EF_TEMPLATE,$(board),$($(board)_short))))
236 .PHONY: sim_win32
237 sim_win32: sim_win32_exe
239 sim_win32_%: flight_uavobjects
240 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/sitl_win32
241 $(V1) $(MAKE) --no-print-directory \
242 -C $(FLIGHT_ROOT_DIR)/targets/OpenPilot --file=$(FLIGHT_ROOT_DIR)/targets/OpenPilot/Makefile.win32 $*
244 .PHONY: sim_osx
245 sim_osx: sim_osx_elf
247 sim_osx_%: flight_uavobjects
248 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/sim_osx
249 $(V1) $(MAKE) --no-print-directory \
250 -C $(FLIGHT_ROOT_DIR)/targets/SensorTest --file=$(FLIGHT_ROOT_DIR)/targets/SensorTest/Makefile.osx $*
252 ##############################
254 # UAV Objects
256 ##############################
257 UAVOBJGENERATOR ?= $(shell which uavobjgenerator)
259 UAVOBJ_XML_DIR := $(FLIGHT_ROOT_DIR)/../shared/uavobjectdefinition
260 export FLIGHT_UAVOBJ_DIR := $(FLIGHT_OUT_DIR)/uavobjects
262 .PHONY: flight_uavobjects
263 flight_uavobjects: $(UAVOBJGENERATOR)
264 @mkdir -p $(FLIGHT_UAVOBJ_DIR)
265 $(V1) cd $(FLIGHT_UAVOBJ_DIR) && \
266 $(UAVOBJGENERATOR) -flight $(UAVOBJ_XML_DIR) $(FLIGHT_ROOT_DIR)/..
269 ##############################
271 # Unit Tests
273 ##############################
275 ALL_UNITTESTS := logfs math lednotification
277 # Build the directory for the unit tests
278 UT_OUT_DIR := $(BUILD_DIR)/unit_tests
279 DIRS += $(UT_OUT_DIR)
281 .PHONY: all_ut
282 all_ut: $(addsuffix _elf, $(addprefix ut_, $(ALL_UNITTESTS)))
284 .PHONY: all_ut_xml
285 all_ut_xml: $(addsuffix _xml, $(addprefix ut_, $(ALL_UNITTESTS)))
287 .PHONY: all_ut_run
288 all_ut_run: $(addsuffix _run, $(addprefix ut_, $(ALL_UNITTESTS)))
290 .PHONY: all_ut_clean
291 all_ut_clean:
292 @$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR))"
293 $(V1) [ ! -d "$(UT_OUT_DIR)" ] || $(RM) -r "$(UT_OUT_DIR)"
295 # $(1) = Unit test name
296 define UT_TEMPLATE
297 .PHONY: ut_$(1)
298 ut_$(1): ut_$(1)_run
300 ut_$(1)_%: $$(UT_OUT_DIR)
301 $(V1) $(MKDIR) -p $(UT_OUT_DIR)/$(1)
302 $(V1) cd $(ROOT_DIR)/flight/tests/$(1) && \
303 $$(MAKE) -r --no-print-directory \
304 BUILD_TYPE=ut \
305 BOARD_SHORT_NAME=$(1) \
306 TOPDIR=$(ROOT_DIR)/flight/tests/$(1) \
307 OUTDIR="$(UT_OUT_DIR)/$(1)" \
308 TARGET=$(1) \
311 .PHONY: ut_$(1)_clean
312 ut_$(1)_clean:
313 @$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
314 $(V1) [ ! -d "$(UT_OUT_DIR)/$(1)" ] || $(RM) -r "$(UT_OUT_DIR)/$(1)"
315 endef
317 # Expand the unittest rules
318 $(foreach ut, $(ALL_UNITTESTS), $(eval $(call UT_TEMPLATE,$(ut))))
320 # Disable parallel make when the all_ut_run target is requested otherwise the TAP
321 # output is interleaved with the rest of the make output.
322 ifneq ($(strip $(filter all_ut_run,$(MAKECMDGOALS))),)
323 .NOTPARALLEL:
324 $(info $(EMPTY) NOTE Parallel make disabled by all_ut_run target so we have sane console output)
325 endif