update CREDITS.txt
[librepilot.git] / flight / Makefile
blob7540aa3647b0593891f784578ad20d3c23b79934
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 sparky2
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'
17 osd_short := 'osd '
18 revoproto_short := 'revp'
19 revonano_short := 'revn'
20 sparky2_short := 'spk2'
21 simposix_short := 'posx'
22 discoveryf4bare_short := 'df4b'
23 gpsplatinum_short := 'gps9'
25 # SimPosix only builds on Linux so drop it from the list for
26 # all other platforms.
27 ifneq ($(UNAME), Linux)
28 ALL_BOARDS := $(filter-out simposix, $(ALL_BOARDS))
29 endif
31 # Start out assuming that we'll build fw, bl and bu for all boards
32 FW_BOARDS := $(ALL_BOARDS)
33 BL_BOARDS := $(ALL_BOARDS)
34 BU_BOARDS := $(ALL_BOARDS)
35 EF_BOARDS := $(ALL_BOARDS)
37 # SimPosix doesn't have a BL, BU or EF target so we need to
38 # filter them out to prevent errors on the all_flight target.
39 BL_BOARDS := $(filter-out simposix, $(BL_BOARDS))
40 BU_BOARDS := $(filter-out simposix gpsplatinum, $(BU_BOARDS))
41 EF_BOARDS := $(filter-out simposix, $(EF_BOARDS))
43 # Generate the targets for whatever boards are left in each list
44 FW_TARGETS := $(addprefix fw_, $(FW_BOARDS))
45 BL_TARGETS := $(addprefix bl_, $(BL_BOARDS))
46 BU_TARGETS := $(addprefix bu_, $(BU_BOARDS))
47 EF_TARGETS := $(addprefix ef_, $(EF_BOARDS))
49 ALL_FLIGHT := all_fw all_bl all_bu all_ef
50 ALL_FLIGHT_CLEAN := $(addsuffix _clean,$(ALL_FLIGHT))
52 .PHONY: all_flight all_flight_clean
53 all_flight: $(ALL_FLIGHT)
54 all_flight_clean: $(ALL_FLIGHT_CLEAN)
57 # TEMPLATES (used to generate build rules)
59 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
60 # $(2) = Short name for board (e.g cc)
61 define FW_TEMPLATE
62 .PHONY: $(1) fw_$(1)
63 $(1): fw_$(1)_opfw
64 fw_$(1): fw_$(1)_opfw
66 fw_$(1)_%: flight_uavobjects
67 $(V1) $$(ARM_GCC_VERSION_CHECK_TEMPLATE)
68 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/fw_$(1)/dep
69 $(V1) cd $(FLIGHT_ROOT_DIR)/targets/boards/$(1)/firmware && \
70 $$(MAKE) -r --no-print-directory \
71 BUILD_TYPE=fw \
72 BOARD_NAME=$(1) \
73 BOARD_SHORT_NAME=$(2) \
74 TOPDIR=$(FLIGHT_ROOT_DIR)/targets/boards/$(1)/firmware \
75 OUTDIR=$(FLIGHT_OUT_DIR)/fw_$(1) \
76 TARGET=fw_$(1) \
77 $$*
79 .PHONY: $(1)_clean
80 $(1)_clean: fw_$(1)_clean
81 fw_$(1)_clean:
82 @echo " CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/fw_$(1))"
83 $(V1) rm -fr $(FLIGHT_OUT_DIR)/fw_$(1)
84 endef
86 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
87 # $(2) = Short name for board (e.g cc)
88 define BL_TEMPLATE
89 .PHONY: bl_$(1)
90 bl_$(1): bl_$(1)_bin
91 bl_$(1)_bino: bl_$(1)_bin
93 bl_$(1)_%:
94 $(V1) $$(ARM_GCC_VERSION_CHECK_TEMPLATE)
95 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/bl_$(1)/dep
96 $(V1) cd $(FLIGHT_ROOT_DIR)/targets/boards/$(1)/bootloader && \
97 $$(MAKE) -r --no-print-directory \
98 BUILD_TYPE=bl \
99 BOARD_NAME=$(1) \
100 BOARD_SHORT_NAME=$(2) \
101 TOPDIR=$(FLIGHT_ROOT_DIR)/targets/boards/$(1)/bootloader \
102 OUTDIR=$(FLIGHT_OUT_DIR)/bl_$(1) \
103 TARGET=bl_$(1) \
106 .PHONY: unbrick_$(1)
107 unbrick_$(1): bl_$(1)_hex
108 $(if $(filter-out undefined,$(origin UNBRICK_TTY)),
109 $(V0) @echo " UNBRICK $(1) via $$(UNBRICK_TTY)"
110 $(V1) $(STM32FLASH_DIR)/stm32flash \
111 -w $(FLIGHT_OUT_DIR)/bl_$(1)/bl_$(1).hex \
112 -g 0x0 \
113 $$(UNBRICK_TTY)
115 $(V0) @echo
116 $(V0) @echo "ERROR: You must specify UNBRICK_TTY=<serial-device> to use for unbricking."
117 $(V0) @echo " eg. $$(MAKE) $$@ UNBRICK_TTY=/dev/ttyUSB0"
120 .PHONY: bl_$(1)_clean
121 bl_$(1)_clean:
122 @echo " CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/bl_$(1))"
123 $(V1) rm -fr $(FLIGHT_OUT_DIR)/bl_$(1)
124 endef
126 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
127 # $(2) = Short name for board (e.g cc)
128 define BU_TEMPLATE
129 .PHONY: bu_$(1)
130 bu_$(1): bu_$(1)_opfw
132 bu_$(1)_%: bl_$(1)_bino
133 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/bu_$(1)/dep
134 $(V1) cd $(FLIGHT_ROOT_DIR)/targets/common/bootloader_updater && \
135 $$(MAKE) -r --no-print-directory \
136 BUILD_TYPE=bu \
137 BOARD_NAME=$(1) \
138 BOARD_SHORT_NAME=$(2) \
139 TOPDIR=$(FLIGHT_ROOT_DIR)/targets/common/bootloader_updater \
140 OUTDIR=$(FLIGHT_OUT_DIR)/bu_$(1) \
141 TARGET=bu_$(1) \
144 .PHONY: bu_$(1)_clean
145 bu_$(1)_clean:
146 @echo " CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/bu_$(1))"
147 $(V1) rm -fr $(FLIGHT_OUT_DIR)/bu_$(1)
148 endef
150 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
151 # $(2) = Short name for board (e.g cc)
152 define EF_TEMPLATE
153 .PHONY: ef_$(1)
154 ef_$(1): ef_$(1)_bin
156 ef_$(1)_%: bl_$(1)_bin fw_$(1)_opfw
157 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/ef_$(1)
158 $(V1) cd $(FLIGHT_ROOT_DIR)/targets/common/entire_flash && \
159 $$(MAKE) -r --no-print-directory \
160 BUILD_TYPE=ef \
161 BOARD_NAME=$(1) \
162 BOARD_SHORT_NAME=$(2) \
163 DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \
164 TOPDIR=$(FLIGHT_ROOT_DIR)/targets/common/entire_flash \
165 OUTDIR=$(FLIGHT_OUT_DIR)/ef_$(1) \
166 TARGET=ef_$(1) \
169 .PHONY: ef_$(1)_clean
170 ef_$(1)_clean:
171 @echo " CLEAN $(call toprel, $(FLIGHT_OUT_DIR)/ef_$(1))"
172 $(V1) rm -fr $(FLIGHT_OUT_DIR)/ef_$(1)
173 endef
175 # $(1) = Canonical board name all in lower case (e.g. coptercontrol)
176 define BOARD_PHONY_TEMPLATE
177 .PHONY: all_$(1)
178 all_$(1): $$(filter fw_$(1), $$(FW_TARGETS))
179 all_$(1): $$(filter bl_$(1), $$(BL_TARGETS))
180 all_$(1): $$(filter bu_$(1), $$(BU_TARGETS))
181 all_$(1): $$(filter ef_$(1), $$(EF_TARGETS))
183 .PHONY: all_$(1)_clean
184 all_$(1)_clean: $$(addsuffix _clean, $$(filter fw_$(1), $$(FW_TARGETS)))
185 all_$(1)_clean: $$(addsuffix _clean, $$(filter bl_$(1), $$(BL_TARGETS)))
186 all_$(1)_clean: $$(addsuffix _clean, $$(filter bu_$(1), $$(BU_TARGETS)))
187 all_$(1)_clean: $$(addsuffix _clean, $$(filter ef_$(1), $$(EF_TARGETS)))
188 endef
191 # Generate flight build rules
192 .PHONY: first
193 first: all_fw
195 .PHONY: all_fw all_fw_clean
196 all_fw: $(addsuffix _opfw, $(FW_TARGETS))
197 all_fw_clean: $(addsuffix _clean, $(FW_TARGETS))
199 .PHONY: all_bl all_bl_clean
200 all_bl: $(addsuffix _bin, $(BL_TARGETS))
201 all_bl_clean: $(addsuffix _clean, $(BL_TARGETS))
203 .PHONY: all_bu all_bu_clean
204 all_bu: $(addsuffix _opfw, $(BU_TARGETS))
205 all_bu_clean: $(addsuffix _clean, $(BU_TARGETS))
207 .PHONY: all_ef all_ef_clean
208 all_ef: $(EF_TARGETS)
209 all_ef_clean: $(addsuffix _clean, $(EF_TARGETS))
211 # Expand the groups of targets for each board
212 $(foreach board, $(ALL_BOARDS), $(eval $(call BOARD_PHONY_TEMPLATE,$(board))))
214 # Expand the firmware rules
215 $(foreach board, $(ALL_BOARDS), $(eval $(call FW_TEMPLATE,$(board),$($(board)_short))))
217 # Expand the bootloader rules
218 $(foreach board, $(ALL_BOARDS), $(eval $(call BL_TEMPLATE,$(board),$($(board)_short))))
220 # Expand the bootloader updater rules
221 $(foreach board, $(ALL_BOARDS), $(eval $(call BU_TEMPLATE,$(board),$($(board)_short))))
223 # Expand the entire-flash rules
224 $(foreach board, $(ALL_BOARDS), $(eval $(call EF_TEMPLATE,$(board),$($(board)_short))))
226 .PHONY: sim_win32
227 sim_win32: sim_win32_exe
229 sim_win32_%: flight_uavobjects
230 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/sitl_win32
231 $(V1) $(MAKE) --no-print-directory \
232 -C $(FLIGHT_ROOT_DIR)/targets/OpenPilot --file=$(FLIGHT_ROOT_DIR)/targets/OpenPilot/Makefile.win32 $*
234 .PHONY: sim_osx
235 sim_osx: sim_osx_elf
237 sim_osx_%: flight_uavobjects
238 $(V1) mkdir -p $(FLIGHT_OUT_DIR)/sim_osx
239 $(V1) $(MAKE) --no-print-directory \
240 -C $(FLIGHT_ROOT_DIR)/targets/SensorTest --file=$(FLIGHT_ROOT_DIR)/targets/SensorTest/Makefile.osx $*
242 ##############################
244 # UAV Objects
246 ##############################
247 UAVOBJGENERATOR ?= $(shell which uavobjgenerator)
249 UAVOBJ_XML_DIR := $(FLIGHT_ROOT_DIR)/../shared/uavobjectdefinition
250 export FLIGHT_UAVOBJ_DIR := $(FLIGHT_OUT_DIR)/uavobjects
252 .PHONY: flight_uavobjects
253 flight_uavobjects: $(UAVOBJGENERATOR)
254 @mkdir -p $(FLIGHT_UAVOBJ_DIR)
255 $(V1) cd $(FLIGHT_UAVOBJ_DIR) && \
256 $(UAVOBJGENERATOR) -flight $(UAVOBJ_XML_DIR) $(FLIGHT_ROOT_DIR)/..
259 ##############################
261 # Unit Tests
263 ##############################
265 ALL_UNITTESTS := logfs math lednotification
267 # Build the directory for the unit tests
268 UT_OUT_DIR := $(BUILD_DIR)/unit_tests
269 DIRS += $(UT_OUT_DIR)
271 .PHONY: all_ut
272 all_ut: $(addsuffix _elf, $(addprefix ut_, $(ALL_UNITTESTS)))
274 .PHONY: all_ut_xml
275 all_ut_xml: $(addsuffix _xml, $(addprefix ut_, $(ALL_UNITTESTS)))
277 .PHONY: all_ut_run
278 all_ut_run: $(addsuffix _run, $(addprefix ut_, $(ALL_UNITTESTS)))
280 .PHONY: all_ut_clean
281 all_ut_clean:
282 @$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR))"
283 $(V1) [ ! -d "$(UT_OUT_DIR)" ] || $(RM) -r "$(UT_OUT_DIR)"
285 # $(1) = Unit test name
286 define UT_TEMPLATE
287 .PHONY: ut_$(1)
288 ut_$(1): ut_$(1)_run
290 ut_$(1)_%: $$(UT_OUT_DIR)
291 $(V1) $(MKDIR) -p $(UT_OUT_DIR)/$(1)
292 $(V1) cd $(ROOT_DIR)/flight/tests/$(1) && \
293 $$(MAKE) -r --no-print-directory \
294 BUILD_TYPE=ut \
295 BOARD_SHORT_NAME=$(1) \
296 TOPDIR=$(ROOT_DIR)/flight/tests/$(1) \
297 OUTDIR="$(UT_OUT_DIR)/$(1)" \
298 TARGET=$(1) \
301 .PHONY: ut_$(1)_clean
302 ut_$(1)_clean:
303 @$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
304 $(V1) [ ! -d "$(UT_OUT_DIR)/$(1)" ] || $(RM) -r "$(UT_OUT_DIR)/$(1)"
305 endef
307 # Expand the unittest rules
308 $(foreach ut, $(ALL_UNITTESTS), $(eval $(call UT_TEMPLATE,$(ut))))
310 # Disable parallel make when the all_ut_run target is requested otherwise the TAP
311 # output is interleaved with the rest of the make output.
312 ifneq ($(strip $(filter all_ut_run,$(MAKECMDGOALS))),)
313 .NOTPARALLEL:
314 $(info $(EMPTY) NOTE Parallel make disabled by all_ut_run target so we have sane console output)
315 endif