Moved question mark to code & added missing define
[librepilot.git] / Makefile
blob940e6a1de7f63f84491fd1315f5872e0bc494a83
2 # Top level Makefile for the LibrePilot Project build system.
3 # Copyright (c) 2015, The LibrePilot Project, http://www.librepilot.org
4 # Copyright (c) 2010-2013, The OpenPilot Team, http://www.openpilot.org
5 # Use 'make help' for instructions.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # This top level Makefile passes down some variables to sub-makes through
23 # the environment. They are explicitly exported using the export keyword.
24 # Lower level makefiles assume that these variables are defined. To ensure
25 # that a special magic variable is exported here. It must be checked for
26 # existance by each sub-make.
27 export TOP_LEVEL_MAKEFILE := TRUE
29 # The root directory that this makefile resides in
30 export ROOT_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
32 # Include some helper functions
33 include $(ROOT_DIR)/make/functions.mk
35 # This file can be used to override default options using the "override" keyword
36 CONFIG_FILE := config
37 -include $(CONFIG_FILE)
39 ##############################
40 # It is possible to set DL_DIR and/or TOOLS_DIR environment
41 # variables to override local tools download and installation directorys. So the
42 # same toolchains can be used for all working copies. Particularly useful for CI
43 # server build agents, but also for local installations.
44 override DL_DIR := $(if $(DL_DIR),$(call slashfix,$(DL_DIR)),$(ROOT_DIR)/downloads)
45 override TOOLS_DIR := $(if $(TOOLS_DIR),$(call slashfix,$(TOOLS_DIR)),$(ROOT_DIR)/tools)
46 export DL_DIR
47 export TOOLS_DIR
49 # Set up some macros for common directories within the tree
50 export BUILD_DIR := $(CURDIR)/build
51 export PACKAGE_DIR := $(BUILD_DIR)/package
52 export DIST_DIR := $(BUILD_DIR)/dist
53 export OPGCSSYNTHDIR := $(BUILD_DIR)/gcs-synthetics
55 DIRS := $(DL_DIR) $(TOOLS_DIR) $(BUILD_DIR) $(PACKAGE_DIR) $(DIST_DIR) $(OPGCSSYNTHDIR)
57 # Naming for binaries and packaging etc,.
58 export ORG_BIG_NAME := LibrePilot
59 GCS_BIG_NAME := ${ORG_BIG_NAME} GCS
60 # These should be lowercase with no spaces
61 export ORG_SMALL_NAME := $(call smallify,$(ORG_BIG_NAME))
62 GCS_SMALL_NAME := $(call smallify,$(GCS_BIG_NAME))
63 # Change this once the DNS is set to http://wiki.librepilot.org/
64 WIKI_URL_ROOT := https://librepilot.atlassian.net/wiki/display/LPDOC/
66 USAGETRACKER_URL := https://usagetracker.librepilot.org/
68 # Set up default build configurations (debug | release)
69 GCS_BUILD_CONF := release
70 GOOGLE_API_VERSION := 14
72 # Clean out undesirable variables from the environment and command-line
73 # to remove the chance that they will cause problems with our build
74 define SANITIZE_VAR
75 $(if $(filter-out undefined,$(origin $(1))),
76 $(info $(EMPTY) NOTE Sanitized $(2) variable '$(1)' from $(origin $(1)))
77 MAKEOVERRIDES = $(filter-out $(1)=%,$(MAKEOVERRIDES))
78 override $(1) :=
79 unexport $(1)
81 endef
83 # These specific variables can influence compilation in unexpected (and undesirable) ways
84 # gcc flags
85 SANITIZE_GCC_VARS := TMPDIR GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH
86 # preprocessor flags
87 SANITIZE_GCC_VARS += CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH DEPENDENCIES_OUTPUT
88 # make flags
89 SANITIZE_GCC_VARS += CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LDLIBS
90 $(foreach var, $(SANITIZE_GCC_VARS), $(eval $(call SANITIZE_VAR,$(var),disallowed)))
92 # These specific variables used to be valid but now they make no sense
93 SANITIZE_DEPRECATED_VARS := USE_BOOTLOADER CLEAN_BUILD
94 $(foreach var, $(SANITIZE_DEPRECATED_VARS), $(eval $(call SANITIZE_VAR,$(var),deprecated)))
96 # Make sure this isn't being run as root unless installing (no whoami on Windows, but that is ok here)
97 ifeq ($(shell whoami 2>/dev/null),root)
98 ifeq ($(filter install uninstall,$(MAKECMDGOALS)),)
99 ifndef FAKEROOTKEY
100 $(error You should not be running this as root)
101 endif
102 endif
103 endif
105 # Decide on a verbosity level based on the V= parameter
106 export AT := @
107 ifndef V
108 export V0 :=
109 export V1 := $(AT)
110 else ifeq ($(V), 0)
111 export V0 := $(AT)
112 export V1 := $(AT)
113 else ifeq ($(V), 1)
114 endif
116 # Make sure we know few things about the architecture before including
117 # the tools.mk to ensure that we download/install the right tools.
118 UNAME := $(shell uname)
119 ARCH := $(shell uname -m)
120 # Here and everywhere if not Linux or Mac then assume Windows
121 ifeq ($(filter Linux Darwin, $(UNAME)), )
122 UNAME := Windows
123 endif
125 # Include tools installers
126 include $(ROOT_DIR)/make/tools.mk
128 # Include third party builders if available
129 -include $(ROOT_DIR)/make/3rdparty/3rdparty.mk
131 # We almost need to consider autoconf/automake instead of this
132 ifeq ($(UNAME), Linux)
133 QT_SPEC := linux-g++
134 UAVOBJGENERATOR := $(BUILD_DIR)/uavobjgenerator/uavobjgenerator
135 else ifeq ($(UNAME), Darwin)
136 QT_SPEC := macx-g++
137 UAVOBJGENERATOR := $(BUILD_DIR)/uavobjgenerator/uavobjgenerator
138 else ifeq ($(UNAME), Windows)
139 QT_SPEC := win32-g++
140 UAVOBJGENERATOR := $(BUILD_DIR)/uavobjgenerator/uavobjgenerator.exe
141 endif
143 export UAVOBJGENERATOR
145 ##############################
147 # All targets
149 ##############################
151 .PHONY: all
152 all: uavobjects all_ground all_flight
154 .PHONY: all_clean
155 all_clean:
156 @$(ECHO) " CLEAN $(call toprel, $(BUILD_DIR))"
157 $(V1) [ ! -d "$(BUILD_DIR)" ] || $(RM) -rf "$(BUILD_DIR)"
159 .PHONY: clean
160 clean: all_clean
163 ##############################
165 # UAVObjects
167 ##############################
169 UAVOBJGENERATOR_DIR := $(BUILD_DIR)/uavobjgenerator
170 DIRS += $(UAVOBJGENERATOR_DIR)
172 .PHONY: uavobjgenerator
173 uavobjgenerator $(UAVOBJGENERATOR): | $(UAVOBJGENERATOR_DIR)
174 $(V1) cd $(UAVOBJGENERATOR_DIR) && \
175 ( [ -f Makefile ] || $(QMAKE) $(ROOT_DIR)/ground/uavobjgenerator/uavobjgenerator.pro \
176 -spec $(QT_SPEC) CONFIG+=$(GCS_BUILD_CONF) CONFIG+=$(GCS_SILENT) ) && \
177 $(MAKE) --no-print-directory -w
179 UAVOBJ_TARGETS := gcs flight python matlab java wireshark
181 .PHONY: uavobjects
182 uavobjects: $(addprefix uavobjects_, $(UAVOBJ_TARGETS))
184 UAVOBJ_XML_DIR := $(ROOT_DIR)/shared/uavobjectdefinition
185 UAVOBJ_OUT_DIR := $(BUILD_DIR)/uavobject-synthetics
187 uavobjects_%: uavobjgenerator
188 @$(MKDIR) -p $(UAVOBJ_OUT_DIR)/$*
189 $(V1) ( cd $(UAVOBJ_OUT_DIR)/$* && \
190 $(UAVOBJGENERATOR) -$* $(UAVOBJ_XML_DIR) $(ROOT_DIR) ; \
193 uavobjects_test: uavobjgenerator
194 $(V1) $(UAVOBJGENERATOR) -v $(UAVOBJ_XML_DIR) $(ROOT_DIR)
196 uavobjects_clean:
197 @$(ECHO) " CLEAN $(call toprel, $(UAVOBJ_OUT_DIR))"
198 $(V1) [ ! -d "$(UAVOBJ_OUT_DIR)" ] || $(RM) -r "$(UAVOBJ_OUT_DIR)"
200 ##############################
202 # Flight related components
204 ##############################
207 # When building any of the "all_*" targets, tell all sub makefiles to display
208 # additional details on each line of output to describe which build and target
209 # that each line applies to. The same applies also to all, opfw_resource,
210 # package targets
211 ifneq ($(strip $(filter all_% all opfw_resource package,$(MAKECMDGOALS))),)
212 export ENABLE_MSG_EXTRA := yes
213 endif
215 # When building more than one goal in a single make invocation, also
216 # enable the extra context for each output line
217 ifneq ($(word 2,$(MAKECMDGOALS)),)
218 export ENABLE_MSG_EXTRA := yes
219 endif
221 FLIGHT_OUT_DIR := $(BUILD_DIR)/firmware
222 DIRS += $(FLIGHT_OUT_DIR)
224 include $(ROOT_DIR)/flight/Makefile
226 ##############################
228 # GCS related components
230 ##############################
232 .PHONY: all_ground
233 all_ground: gcs uploader
235 ifeq ($(V), 1)
236 GCS_SILENT :=
237 else
238 GCS_SILENT := silent
239 endif
241 GCS_DIR := $(BUILD_DIR)/$(GCS_SMALL_NAME)_$(GCS_BUILD_CONF)
242 DIRS += $(GCS_DIR)
244 GCS_MAKEFILE := $(GCS_DIR)/Makefile
246 .PHONY: gcs_qmake
247 gcs_qmake $(GCS_MAKEFILE): | $(GCS_DIR)
248 $(V1) cd $(GCS_DIR) && \
249 $(QMAKE) $(ROOT_DIR)/ground/gcs/gcs.pro \
250 -spec $(QT_SPEC) -r CONFIG+=$(GCS_BUILD_CONF) CONFIG+=$(GCS_SILENT) \
251 'GCS_BIG_NAME="$(GCS_BIG_NAME)"' GCS_SMALL_NAME=$(GCS_SMALL_NAME) \
252 'ORG_BIG_NAME="$(ORG_BIG_NAME)"' ORG_SMALL_NAME=$(ORG_SMALL_NAME) \
253 'WIKI_URL_ROOT="$(WIKI_URL_ROOT)"' \
254 'USAGETRACKER_URL="$(USAGETRACKER_URL)"' \
255 'GCS_LIBRARY_BASENAME=$(libbasename)' \
256 $(GCS_QMAKE_OPTS)
258 .PHONY: gcs
259 gcs: uavobjgenerator $(GCS_MAKEFILE)
260 $(V1) $(MAKE) -w -C $(GCS_DIR)/$(MAKE_DIR);
262 .PHONY: gcs_clean
263 gcs_clean:
264 @$(ECHO) " CLEAN $(call toprel, $(GCS_DIR))"
265 $(V1) [ ! -d "$(GCS_DIR)" ] || $(RM) -r "$(GCS_DIR)"
269 ################################
271 # Serial Uploader tool
273 ################################
275 UPLOADER_DIR := $(BUILD_DIR)/uploader_$(GCS_BUILD_CONF)
276 DIRS += $(UPLOADER_DIR)
278 UPLOADER_MAKEFILE := $(UPLOADER_DIR)/Makefile
280 .PHONY: uploader_qmake
281 uploader_qmake $(UPLOADER_MAKEFILE): | $(UPLOADER_DIR)
282 $(V1) cd $(UPLOADER_DIR) && \
283 $(QMAKE) $(ROOT_DIR)/ground/gcs/src/experimental/USB_UPLOAD_TOOL/upload.pro \
284 -spec $(QT_SPEC) -r CONFIG+=$(GCS_BUILD_CONF) CONFIG+=$(GCS_SILENT) $(GCS_QMAKE_OPTS)
286 .PHONY: uploader
287 uploader: $(UPLOADER_MAKEFILE)
288 $(V1) $(MAKE) -w -C $(UPLOADER_DIR)
290 .PHONY: uploader_clean
291 uploader_clean:
292 @$(ECHO) " CLEAN $(call toprel, $(UPLOADER_DIR))"
293 $(V1) [ ! -d "$(UPLOADER_DIR)" ] || $(RM) -r "$(UPLOADER_DIR)"
296 # We want to take snapshots of the UAVOs at each point that they change
297 # to allow the GCS to be compatible with as many versions as possible.
298 # We always include a pseudo collection called "srctree" which represents
299 # the UAVOs in the source tree. So not necessary to add current tree UAVO
300 # hash here, it is always included.
302 # Find the git hashes of each commit that changes uavobjects with:
303 # git log --format=%h -- shared/uavobjectdefinition/ | head -n 2
304 # List only UAVO hashes of past releases, do not list current hash.
305 # Past compatible versions are so far: RELEASE-12.10.2
306 UAVO_GIT_VERSIONS := 5e14f53
308 # All versions includes also the current source tree UAVO hash
309 UAVO_ALL_VERSIONS := $(UAVO_GIT_VERSIONS) srctree
311 # This is where the UAVO collections are stored
312 UAVO_COLLECTION_DIR := $(BUILD_DIR)/uavo-collections
314 # $(1) git hash of a UAVO snapshot
315 define UAVO_COLLECTION_GIT_TEMPLATE
317 # Make the output directory that will contain all of the synthetics for the
318 # uavo collection referenced by the git hash $(1)
319 $$(UAVO_COLLECTION_DIR)/$(1):
320 $$(V1) $(MKDIR) -p $$(UAVO_COLLECTION_DIR)/$(1)
322 # Extract the snapshot of shared/uavobjectdefinition from git hash $(1)
323 $$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml.tar: | $$(UAVO_COLLECTION_DIR)/$(1)
324 $$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml.tar:
325 $$(V0) @$(ECHO) " UAVOTAR $(1)"
326 $$(V1) $(GIT) archive $(1) -o $$@ -- shared/uavobjectdefinition/
328 # Extract the uavo xml files from our snapshot
329 $$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml: $$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml.tar
330 $$(V0) @$(ECHO) " UAVOUNTAR $(1)"
331 $$(V1) $(RM) -rf $$@
332 $$(V1) $(MKDIR) -p $$@
333 $$(V1) $(TAR) -C $$(call toprel, $$@) -xf $$(call toprel, $$<) || $(RM) -rf $$@
334 endef
336 # Map the current working directory into the set of UAVO collections
337 $(UAVO_COLLECTION_DIR)/srctree:
338 $(V1) $(MKDIR) -p $@
340 $(UAVO_COLLECTION_DIR)/srctree/uavo-xml: | $(UAVO_COLLECTION_DIR)/srctree
341 $(UAVO_COLLECTION_DIR)/srctree/uavo-xml: $(UAVOBJ_XML_DIR)
342 $(V1) $(LN) -sf $(ROOT_DIR) $(UAVO_COLLECTION_DIR)/srctree/uavo-xml
344 # $(1) git hash (or symbolic name) of a UAVO snapshot
345 define UAVO_COLLECTION_BUILD_TEMPLATE
347 # This leaves us with a (broken) symlink that points to the full sha1sum of the collection
348 $$(UAVO_COLLECTION_DIR)/$(1)/uavohash: $$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml
349 # Compute the sha1 hash for this UAVO collection
350 # The sed bit truncates the UAVO hash to 16 hex digits
351 $$(V1) $$(VERSION_INFO) \
352 --uavodir=$$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml/shared/uavobjectdefinition \
353 --format='$$$${UAVO_HASH}' | \
354 $(SED) -e 's|\(................\).*|\1|' > $$@
356 $$(V0) @$(ECHO) " UAVOHASH $(1) ->" $$$$(cat $$(UAVO_COLLECTION_DIR)/$(1)/uavohash)
358 # Generate the java uavobjects for this UAVO collection
359 $$(UAVO_COLLECTION_DIR)/$(1)/java-build/java: $$(UAVO_COLLECTION_DIR)/$(1)/uavohash
360 $$(V0) @$(ECHO) " UAVOJAVA $(1) " $$$$(cat $$(UAVO_COLLECTION_DIR)/$(1)/uavohash)
361 $$(V1) $(MKDIR) -p $$@
362 $$(V1) ( \
363 cd $$(UAVO_COLLECTION_DIR)/$(1)/java-build && \
364 $$(UAVOBJGENERATOR) -java $$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml/shared/uavobjectdefinition $$(ROOT_DIR) ; \
367 # Build a jar file for this UAVO collection
368 $$(UAVO_COLLECTION_DIR)/$(1)/java-build/uavobjects.jar: | $$(ANDROIDGCS_ASSETS_DIR)/uavos
369 $$(UAVO_COLLECTION_DIR)/$(1)/java-build/uavobjects.jar: $$(UAVO_COLLECTION_DIR)/$(1)/java-build/java
370 $$(V0) @$(ECHO) " UAVOJAR $(1) " $$$$(cat $$(UAVO_COLLECTION_DIR)/$(1)/uavohash)
371 $$(V1) ( \
372 HASH=$$$$(cat $$(UAVO_COLLECTION_DIR)/$(1)/uavohash) && \
373 cd $$(UAVO_COLLECTION_DIR)/$(1)/java-build && \
374 $(JAVAC) java/*.java \
375 $$(ROOT_DIR)/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java \
376 $$(ROOT_DIR)/androidgcs/src/org/openpilot/uavtalk/UAVObject*.java \
377 $$(ROOT_DIR)/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java \
378 -d . && \
379 find ./org/openpilot/uavtalk/uavobjects -type f -name '*.class' > classlist.txt && \
380 $(JAR) cf tmp_uavobjects.jar @classlist.txt && \
381 $$(ANDROID_DX) \
382 --dex \
383 --output $$(ANDROIDGCS_ASSETS_DIR)/uavos/$$$${HASH}.jar \
384 tmp_uavobjects.jar && \
385 $(LN) -sf $$(ANDROIDGCS_ASSETS_DIR)/uavos/$$$${HASH}.jar uavobjects.jar \
388 endef
390 # One of these for each element of UAVO_GIT_VERSIONS so we can extract the UAVOs from git
391 $(foreach githash, $(UAVO_GIT_VERSIONS), $(eval $(call UAVO_COLLECTION_GIT_TEMPLATE,$(githash))))
393 # One of these for each UAVO_ALL_VERSIONS which includes the ones in the srctree
394 $(foreach githash, $(UAVO_ALL_VERSIONS), $(eval $(call UAVO_COLLECTION_BUILD_TEMPLATE,$(githash))))
396 .PHONY: uavo-collections_java
397 uavo-collections_java: $(foreach githash, $(UAVO_ALL_VERSIONS), $(UAVO_COLLECTION_DIR)/$(githash)/java-build/uavobjects.jar)
399 .PHONY: uavo-collections
400 uavo-collections: uavo-collections_java
402 .PHONY: uavo-collections_clean
403 uavo-collections_clean:
404 @$(ECHO) " CLEAN $(call toprel, $(UAVO_COLLECTION_DIR))"
405 $(V1) [ ! -d "$(UAVO_COLLECTION_DIR)" ] || $(RM) -r $(UAVO_COLLECTION_DIR)
407 ##############################
409 # Unit Tests
411 ##############################
413 ALL_UNITTESTS := logfs math lednotification
415 # Build the directory for the unit tests
416 UT_OUT_DIR := $(BUILD_DIR)/unit_tests
417 DIRS += $(UT_OUT_DIR)
419 .PHONY: all_ut
420 all_ut: $(addsuffix _elf, $(addprefix ut_, $(ALL_UNITTESTS)))
422 .PHONY: all_ut_xml
423 all_ut_xml: $(addsuffix _xml, $(addprefix ut_, $(ALL_UNITTESTS)))
425 .PHONY: all_ut_run
426 all_ut_run: $(addsuffix _run, $(addprefix ut_, $(ALL_UNITTESTS)))
428 .PHONY: all_ut_clean
429 all_ut_clean:
430 @$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR))"
431 $(V1) [ ! -d "$(UT_OUT_DIR)" ] || $(RM) -r "$(UT_OUT_DIR)"
433 # $(1) = Unit test name
434 define UT_TEMPLATE
435 .PHONY: ut_$(1)
436 ut_$(1): ut_$(1)_run
438 ut_$(1)_%: $$(UT_OUT_DIR)
439 $(V1) $(MKDIR) -p $(UT_OUT_DIR)/$(1)
440 $(V1) cd $(ROOT_DIR)/flight/tests/$(1) && \
441 $$(MAKE) -r --no-print-directory \
442 BUILD_TYPE=ut \
443 BOARD_SHORT_NAME=$(1) \
444 TOPDIR=$(ROOT_DIR)/flight/tests/$(1) \
445 OUTDIR="$(UT_OUT_DIR)/$(1)" \
446 TARGET=$(1) \
449 .PHONY: ut_$(1)_clean
450 ut_$(1)_clean:
451 @$(ECHO) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
452 $(V1) [ ! -d "$(UT_OUT_DIR)/$(1)" ] || $(RM) -r "$(UT_OUT_DIR)/$(1)"
453 endef
455 # Expand the unittest rules
456 $(foreach ut, $(ALL_UNITTESTS), $(eval $(call UT_TEMPLATE,$(ut))))
458 # Disable parallel make when the all_ut_run target is requested otherwise the TAP
459 # output is interleaved with the rest of the make output.
460 ifneq ($(strip $(filter all_ut_run,$(MAKECMDGOALS))),)
461 .NOTPARALLEL:
462 $(info $(EMPTY) NOTE Parallel make disabled by all_ut_run target so we have sane console output)
463 endif
465 ##############################
467 # Packaging components
469 ##############################
470 # Firmware files to package
471 PACKAGE_FW_TARGETS := fw_coptercontrol fw_oplinkmini fw_revolution fw_osd fw_revoproto fw_gpsplatinum fw_revonano
473 # Rules to generate GCS resources used to embed firmware binaries into the GCS.
474 # They are used later by the vehicle setup wizard to update board firmware.
475 # To open a firmware image use ":/firmware/fw_coptercontrol.opfw"
476 OPFW_RESOURCE := $(OPGCSSYNTHDIR)/opfw_resource.qrc
478 ifeq ($(WITH_PREBUILT_FW),)
479 FIRMWARE_DIR := $(FLIGHT_OUT_DIR)
480 # We need to build the FW targets
481 $(OPFW_RESOURCE): $(PACKAGE_FW_TARGETS)
482 else
483 FIRMWARE_DIR := $(WITH_PREBUILT_FW)
484 endif
486 OPFW_FILES := $(foreach fw_targ, $(PACKAGE_FW_TARGETS), $(FIRMWARE_DIR)/$(fw_targ)/$(fw_targ).opfw)
487 OPFW_CONTENTS := \
488 <!DOCTYPE RCC><RCC version="1.0"> \
489 <qresource prefix="/firmware"> \
490 $(foreach fw_file, $(OPFW_FILES), <file alias="$(notdir $(fw_file))">$(fw_file)</file>) \
491 </qresource> \
492 </RCC>
494 .PHONY: opfw_resource
495 opfw_resource: $(OPFW_RESOURCE)
497 $(OPFW_RESOURCE): | $(OPGCSSYNTHDIR)
498 @$(ECHO) Generating OPFW resource file $(call toprel, $@)
499 $(V1) $(ECHO) $(QUOTE)$(OPFW_CONTENTS)$(QUOTE) > $@
501 # If opfw_resource or all firmware are requested, GCS should depend on the resource
502 ifneq ($(strip $(filter opfw_resource all all_fw all_flight package,$(MAKECMDGOALS))),)
503 $(GCS_MAKEFILE): $(OPFW_RESOURCE)
504 endif
506 # Packaging targets: package
507 # - builds all firmware, opfw_resource, gcs
508 # - copies firmware into a package directory
509 # - calls paltform-specific packaging script
511 # Define some variables
512 PACKAGE_LBL := $(shell $(VERSION_INFO) --format=\$${LABEL})
513 PACKAGE_NAME := $(subst $(SPACE),,$(ORG_BIG_NAME))
514 PACKAGE_SEP := -
515 PACKAGE_FULL_NAME := $(PACKAGE_NAME)$(PACKAGE_SEP)$(PACKAGE_LBL)
517 # Source distribution is never dirty because it uses git archive
518 DIST_LBL := $(subst -dirty,,$(PACKAGE_LBL))
519 DIST_NAME := $(PACKAGE_NAME)$(PACKAGE_SEP)$(DIST_LBL)
520 DIST_TAR := $(DIST_DIR)/$(DIST_NAME).tar
521 DIST_TAR_GZ := $(DIST_TAR).gz
522 FW_DIST_NAME := $(DIST_NAME)_firmware
523 FW_DIST_TAR := $(DIST_DIR)/$(FW_DIST_NAME).tar
524 FW_DIST_TAR_GZ := $(FW_DIST_TAR).gz
525 DIST_VER_INFO := $(DIST_DIR)/version-info.json
527 include $(ROOT_DIR)/package/$(UNAME).mk
529 ##############################
531 # Source for distribution
533 ##############################
534 $(DIST_VER_INFO): .git/index | $(DIST_DIR)
535 $(V1) $(VERSION_INFO) --jsonpath="$(DIST_DIR)"
537 $(DIST_TAR): $(DIST_VER_INFO) .git/index | $(DIST_DIR)
538 @$(ECHO) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR))"
539 $(V1) git archive --prefix="$(PACKAGE_NAME)/" -o "$(DIST_TAR)" HEAD
540 $(V1) tar --append --file="$(DIST_TAR)" \
541 --transform='s,.*version-info.json,$(PACKAGE_NAME)/version-info.json,' \
542 $(call toprel, "$(DIST_VER_INFO)")
544 $(DIST_TAR_GZ): $(DIST_TAR)
545 @$(ECHO) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR_GZ))"
546 $(V1) gzip -kf "$(DIST_TAR)"
548 .PHONY: dist_tar_gz
549 dist_tar_gz: $(DIST_TAR_GZ)
551 .PHONY: dist
552 dist: dist_tar_gz
555 $(FW_DIST_TAR): $(PACKAGE_FW_TARGETS) | $(DIST_DIR)
556 @$(ECHO) " FIRMWARE FOR DISTRIBUTION $(call toprel, $(FW_DIST_TAR))"
557 $(V1) tar -c --file="$(FW_DIST_TAR)" --directory=$(FLIGHT_OUT_DIR) \
558 --transform='s,^,firmware/,' \
559 $(foreach fw_targ,$(PACKAGE_FW_TARGETS),$(fw_targ)/$(fw_targ).opfw)
561 $(FW_DIST_TAR_GZ): $(FW_DIST_TAR)
562 @$(ECHO) " FIRMWARE FOR DISTRIBUTION $(call toprel, $(FW_DIST_TAR_GZ))"
563 $(V1) gzip -kf "$(FW_DIST_TAR)"
565 .PHONY: fw_dist_tar_gz
566 fw_dist_tar_gz: $(FW_DIST_TAR_GZ)
568 .PHONY: fw_dist
569 fw_dist: fw_dist_tar_gz
572 ##############################
574 # Source code formatting
576 ##############################
578 UNCRUSTIFY_TARGETS := flight ground
580 # $(1) = Uncrustify target (e.g flight or ground)
581 # $(2) = Target root directory
582 define UNCRUSTIFY_TEMPLATE
584 .PHONY: uncrustify_$(1)
585 uncrustify_$(1):
586 @$(ECHO) "Auto-formatting $(1) source code"
587 $(V1) UNCRUSTIFY_CONFIG="$(ROOT_DIR)/make/uncrustify/uncrustify.cfg" $(SHELL) make/scripts/uncrustify.sh $(call toprel, $(2))
588 endef
590 $(foreach uncrustify_targ, $(UNCRUSTIFY_TARGETS), $(eval $(call UNCRUSTIFY_TEMPLATE,$(uncrustify_targ),$(ROOT_DIR)/$(uncrustify_targ))))
592 .PHONY: uncrustify_all
593 uncrustify_all: $(addprefix uncrustify_,$(UNCRUSTIFY_TARGETS))
595 ##############################
597 # Doxygen documentation
599 # Each target should have own Doxyfile.$(target) with build directory build/docs/$(target),
600 # proper source directory (e.g. $(target)) and appropriate other doxygen options.
602 ##############################
604 DOCS_TARGETS := flight ground uavobjects
606 # $(1) = Doxygen target (e.g flight or ground)
607 define DOXYGEN_TEMPLATE
609 .PHONY: docs_$(1)
610 docs_$(1): docs_$(1)_clean
611 @$(ECHO) "Generating $(1) documentation"
612 $(V1) $(MKDIR) -p $(BUILD_DIR)/docs/$(1)
613 $(V1) $(DOXYGEN) $(ROOT_DIR)/make/doxygen/Doxyfile.$(1)
615 .PHONY: docs_$(1)_clean
616 docs_$(1)_clean:
617 @$(ECHO) " CLEAN $(call toprel, $(BUILD_DIR)/docs/$(1))"
618 $(V1) [ ! -d "$(BUILD_DIR)/docs/$(1)" ] || $(RM) -r "$(BUILD_DIR)/docs/$(1)"
620 endef
622 $(foreach docs_targ, $(DOCS_TARGETS), $(eval $(call DOXYGEN_TEMPLATE,$(docs_targ))))
624 .PHONY: docs_all
625 docs_all: $(addprefix docs_,$(DOCS_TARGETS))
627 .PHONY: docs_all_clean
628 docs_all_clean:
629 @$(ECHO) " CLEAN $(call toprel, $(BUILD_DIR)/docs)"
630 $(V1) [ ! -d "$(BUILD_DIR)/docs" ] || $(RM) -rf "$(BUILD_DIR)/docs"
632 ##############################
634 # Build info
636 ##############################
638 .PHONY: build-info
639 build-info: | $(BUILD_DIR)
640 @$(ECHO) " BUILD-INFO $(call toprel, $(BUILD_DIR)/$@.txt)"
641 $(V1) $(VERSION_INFO) \
642 --uavodir=$(ROOT_DIR)/shared/uavobjectdefinition \
643 --template="make/templates/$@.txt" \
644 --outfile="$(BUILD_DIR)/$@.txt"
646 ##############################
648 # Config
650 ##############################
652 CONFIG_OPTS := $(addsuffix \n,$(MAKEOVERRIDES))
653 CONFIG_OPTS := $(addprefix override$(SPACE),$(CONFIG_OPTS))
655 .PHONY: config_new
656 config_new:
657 @printf '$(CONFIG_OPTS)' > $(CONFIG_FILE)
659 .PHONY: config_append
660 config_append:
661 @printf '$(CONFIG_OPTS)' >> $(CONFIG_FILE)
663 .PHONY: config_show
664 config_show:
665 @cat $(CONFIG_FILE)
667 .PHONY: config_clean
668 config_clean:
669 rm -f $(CONFIG_FILE)
672 ##############################
674 # Directories
676 ##############################
678 $(DIRS):
679 $(V1) $(MKDIR) -p $@
682 ##############################
684 # Help message, the default Makefile goal
686 ##############################
688 .DEFAULT_GOAL := help
690 .PHONY: help
691 help:
692 @$(ECHO)
693 @$(ECHO) " This Makefile is known to work on Linux and Mac in a standard shell environment."
694 @$(ECHO) " It also works on Windows by following the instructions given on this wiki page:"
695 @$(ECHO) " http://wiki.openpilot.org/display/Doc/Windows%3A+Building+and+Packaging"
696 @$(ECHO)
697 @$(ECHO) " Here is a summary of the available targets:"
698 @$(ECHO)
699 @$(ECHO) " [Source tree preparation]"
700 @$(ECHO) " prepare - Install GIT commit message template"
701 @$(ECHO) " [Tool Installers]"
702 @$(ECHO) " arm_sdk_install - Install the GNU ARM gcc toolchain"
703 @$(ECHO) " qt_sdk_install - Install the QT development tools"
704 @$(ECHO) " nsis_install - Install the NSIS Unicode (Windows only)"
705 @$(ECHO) " sdl_install - Install the SDL library (Windows only)"
706 @$(ECHO) " mesawin_install - Install the OpenGL32 DLL (Windows only)"
707 @$(ECHO) " openssl_install - Install the OpenSSL libraries (Windows only)"
708 @$(ECHO) " uncrustify_install - Install the Uncrustify source code beautifier"
709 @$(ECHO) " doxygen_install - Install the Doxygen documentation generator"
710 @$(ECHO) " gtest_install - Install the GoogleTest framework"
711 @$(ECHO) " ccache_install - Install ccache"
712 @$(ECHO) " These targets are not updated yet and are probably broken:"
713 @$(ECHO) " openocd_install - Install the OpenOCD JTAG daemon"
714 @$(ECHO) " stm32flash_install - Install the stm32flash tool for unbricking F1-based boards"
715 @$(ECHO) " dfuutil_install - Install the dfu-util tool for unbricking F4-based boards"
716 @$(ECHO) " Install all available tools:"
717 @$(ECHO) " all_sdk_install - Install all of above (platform-dependent)"
718 @$(ECHO) " build_sdk_install - Install only essential for build tools (platform-dependent)"
719 @$(ECHO)
720 @$(ECHO) " Other tool options are:"
721 @$(ECHO) " <tool>_version - Display <tool> version"
722 @$(ECHO) " <tool>_clean - Remove installed <tool>"
723 @$(ECHO) " <tool>_distclean - Remove downloaded <tool> distribution file(s)"
724 @$(ECHO)
725 @$(ECHO) " [Big Hammer]"
726 @$(ECHO) " all - Generate UAVObjects, build openpilot firmware and gcs"
727 @$(ECHO) " all_flight - Build all firmware, bootloaders and bootloader updaters"
728 @$(ECHO) " all_fw - Build only firmware for all boards"
729 @$(ECHO) " all_bl - Build only bootloaders for all boards"
730 @$(ECHO) " all_bu - Build only bootloader updaters for all boards"
731 @$(ECHO)
732 @$(ECHO) " all_clean - Remove your build directory ($(BUILD_DIR))"
733 @$(ECHO) " all_flight_clean - Remove all firmware, bootloaders and bootloader updaters"
734 @$(ECHO) " all_fw_clean - Remove firmware for all boards"
735 @$(ECHO) " all_bl_clean - Remove bootloaders for all boards"
736 @$(ECHO) " all_bu_clean - Remove bootloader updaters for all boards"
737 @$(ECHO)
738 @$(ECHO) " all_<board> - Build all available images for <board>"
739 @$(ECHO) " all_<board>_clean - Remove all available images for <board>"
740 @$(ECHO)
741 @$(ECHO) " all_ut - Build all unit tests"
742 @$(ECHO) " all_ut_tap - Run all unit tests and capture all TAP output to files"
743 @$(ECHO) " all_ut_run - Run all unit tests and dump TAP output to console"
744 @$(ECHO)
745 @$(ECHO) " [Firmware]"
746 @$(ECHO) " <board> - Build firmware for <board>"
747 @$(ECHO) " Supported boards are ($(ALL_BOARDS))"
748 @$(ECHO) " fw_<board> - Build firmware for <board>"
749 @$(ECHO) " Supported boards are ($(FW_BOARDS))"
750 @$(ECHO) " fw_<board>_clean - Remove firmware for <board>"
751 @$(ECHO) " fw_<board>_program - Use OpenOCD + JTAG to write firmware to <board>"
752 @$(ECHO)
753 @$(ECHO) " [Bootloader]"
754 @$(ECHO) " bl_<board> - Build bootloader for <board>"
755 @$(ECHO) " Supported boards are ($(BL_BOARDS))"
756 @$(ECHO) " bl_<board>_clean - Remove bootloader for <board>"
757 @$(ECHO) " bl_<board>_program - Use OpenOCD + JTAG to write bootloader to <board>"
758 @$(ECHO)
759 @$(ECHO) " [Entire Flash]"
760 @$(ECHO) " ef_<board> - Build entire flash image for <board>"
761 @$(ECHO) " Supported boards are ($(EF_BOARDS))"
762 @$(ECHO) " ef_<board>_clean - Remove entire flash image for <board>"
763 @$(ECHO) " ef_<board>_program - Use OpenOCD + JTAG to write entire flash image to <board>"
764 @$(ECHO)
765 @$(ECHO) " [Bootloader Updater]"
766 @$(ECHO) " bu_<board> - Build bootloader updater for <board>"
767 @$(ECHO) " Supported boards are ($(BU_BOARDS))"
768 @$(ECHO) " bu_<board>_clean - Remove bootloader updater for <board>"
769 @$(ECHO)
770 @$(ECHO) " [Unbrick a board]"
771 @$(ECHO) " unbrick_<board> - Use the STM32's built in boot ROM to write a bootloader to <board>"
772 @$(ECHO) " Supported boards are ($(BL_BOARDS))"
773 @$(ECHO) " [Unittests]"
774 @$(ECHO) " ut_<test> - Build unit test <test>"
775 @$(ECHO) " ut_<test>_xml - Run test and capture XML output into a file"
776 @$(ECHO) " ut_<test>_run - Run test and dump output to console"
777 @$(ECHO)
778 @$(ECHO) " [Simulation]"
779 @$(ECHO) " sim_osx - Build OpenPilot simulation firmware for OSX"
780 @$(ECHO) " sim_osx_clean - Delete all build output for the osx simulation"
781 @$(ECHO) " sim_win32 - Build OpenPilot simulation firmware for Windows"
782 @$(ECHO) " using mingw and msys"
783 @$(ECHO) " sim_win32_clean - Delete all build output for the win32 simulation"
784 @$(ECHO)
785 @$(ECHO) " [GCS]"
786 @$(ECHO) " gcs - Build the Ground Control System (GCS) application (debug|release)"
787 @$(ECHO) " Compile specific directory: MAKE_DIR=<dir>"
788 @$(ECHO) " Example: make gcs MAKE_DIR=src/plugins/coreplugin"
789 @$(ECHO) " gcs_qmake - Run qmake for the Ground Control System (GCS) application (debug|release)"
790 @$(ECHO) " gcs_clean - Remove the Ground Control System (GCS) application (debug|release)"
791 @$(ECHO) " Supported build configurations: GCS_BUILD_CONF=debug|release (default is $(GCS_BUILD_CONF))"
792 @$(ECHO)
793 @$(ECHO) " [Uploader Tool]"
794 @$(ECHO) " uploader - Build the serial uploader tool (debug|release)"
795 @$(ECHO) " uploader_qmake - Run qmake for the serial uploader tool (debug|release)"
796 @$(ECHO) " uploader_clean - Remove the serial uploader tool (debug|release)"
797 @$(ECHO) " Supported build configurations: GCS_BUILD_CONF=debug|release (default is $(GCS_BUILD_CONF))"
798 @$(ECHO)
799 @$(ECHO)
800 @$(ECHO) " [UAVObjects]"
801 @$(ECHO) " uavobjects - Generate source files from the UAVObject definition XML files"
802 @$(ECHO) " uavobjects_test - Parse xml-files - check for valid, duplicate ObjId's, ..."
803 @$(ECHO) " uavobjects_<group> - Generate source files from a subset of the UAVObject definition XML files"
804 @$(ECHO) " Supported groups are ($(UAVOBJ_TARGETS))"
805 @$(ECHO)
806 @$(ECHO) " [Packaging]"
807 @$(ECHO) " package - Build and package the OpenPilot platform-dependent package (no clean)"
808 @$(ECHO) " opfw_resource - Generate resources to embed firmware binaries into the GCS"
809 @$(ECHO) " dist - Generate source archive for distribution"
810 @$(ECHO) " fw_dist - Generate archive of firmware"
811 @$(ECHO) " install - Install GCS to \"DESTDIR\" with prefix \"prefix\" (Linux only)"
812 @$(ECHO)
813 @$(ECHO) " [Code Formatting]"
814 @$(ECHO) " uncrustify_<source> - Reformat <source> code according to the project's standards"
815 @$(ECHO) " Supported sources are ($(UNCRUSTIFY_TARGETS))"
816 @$(ECHO) " uncrustify_all - Reformat all source code"
817 @$(ECHO)
818 @$(ECHO) " [Code Documentation]"
819 @$(ECHO) " docs_<source> - Generate HTML documentation for <source>"
820 @$(ECHO) " Supported sources are ($(DOCS_TARGETS))"
821 @$(ECHO) " docs_all - Generate HTML documentation for all"
822 @$(ECHO) " docs_<source>_clean - Delete generated documentation for <source>"
823 @$(ECHO) " docs_all_clean - Delete all generated documentation"
824 @$(ECHO)
825 @$(ECHO) " [Configuration]"
826 @$(ECHO) " config_new - Place your make arguments in the config file"
827 @$(ECHO) " config_append - Place your make arguments in the config file but append"
828 @$(ECHO) " config_clean - Removes the config file"
829 @$(ECHO)
830 @$(ECHO) " Hint: Add V=1 to your command line to see verbose build output."
831 @$(ECHO)
832 @$(ECHO) " Notes: All tool distribution files will be downloaded into $(DL_DIR)"
833 @$(ECHO) " All tools will be installed into $(TOOLS_DIR)"
834 @$(ECHO) " All build output will be placed in $(BUILD_DIR)"
835 @$(ECHO)
836 @$(ECHO) " Tool download and install directories can be changed using environment variables:"
837 @$(ECHO) " DL_DIR full path to downloads directory [downloads if not set]"
838 @$(ECHO) " TOOLS_DIR full path to installed tools directory [tools if not set]"
839 @$(ECHO) " More info: http://wiki.openpilot.org/display/Doc/OpenPilot+Build+System+Overview"
840 @$(ECHO)