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
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
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
)
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
75 $(if
$(filter-out undefined
,$(origin $(1))),
76 $(info $(EMPTY
) NOTE Sanitized
$(2) variable
'$(1)' from
$(origin $(1)))
77 MAKEOVERRIDES
= $(filter-out $(1)=%,$(MAKEOVERRIDES
))
83 # These specific variables can influence compilation in unexpected (and undesirable) ways
85 SANITIZE_GCC_VARS
:= TMPDIR GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH
87 SANITIZE_GCC_VARS
+= CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH DEPENDENCIES_OUTPUT
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
)),)
100 $(error You should not be running this
as root
)
105 # Decide on a verbosity level based on the V= parameter
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
)), )
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
)
134 UAVOBJGENERATOR
:= $(BUILD_DIR
)/uavobjgenerator
/uavobjgenerator
135 else ifeq ($(UNAME
), Darwin
)
137 UAVOBJGENERATOR
:= $(BUILD_DIR
)/uavobjgenerator
/uavobjgenerator
138 else ifeq ($(UNAME
), Windows
)
140 UAVOBJGENERATOR
:= $(BUILD_DIR
)/uavobjgenerator
/uavobjgenerator.exe
143 export UAVOBJGENERATOR
145 ##############################
149 ##############################
152 all: uavobjects all_ground all_flight
156 @
$(ECHO
) " CLEAN $(call toprel, $(BUILD_DIR))"
157 $(V1
) [ ! -d
"$(BUILD_DIR)" ] ||
$(RM
) -rf
"$(BUILD_DIR)"
163 ##############################
167 ##############################
169 UAVOBJGENERATOR_DIR
:= $(BUILD_DIR
)/uavobjgenerator
170 DIRS
+= $(UAVOBJGENERATOR_DIR
)
172 .PHONY
: uavobjgenerator
173 uavobjgenerator
: $(UAVOBJGENERATOR
)
175 $(UAVOBJGENERATOR
): |
$(UAVOBJGENERATOR_DIR
)
176 $(V1
) cd
$(UAVOBJGENERATOR_DIR
) && \
177 ( [ -f Makefile
] ||
$(QMAKE
) $(ROOT_DIR
)/ground
/uavobjgenerator
/uavobjgenerator.pro \
178 -spec
$(QT_SPEC
) CONFIG
+=$(GCS_BUILD_CONF
) CONFIG
+=$(GCS_SILENT
) ) && \
179 $(MAKE
) --no-print-directory
-w
181 UAVOBJ_TARGETS
:= gcs flight python matlab java wireshark
184 uavobjects
: $(addprefix uavobjects_
, $(UAVOBJ_TARGETS
))
186 UAVOBJ_XML_DIR
:= $(ROOT_DIR
)/shared
/uavobjectdefinition
187 UAVOBJ_OUT_DIR
:= $(BUILD_DIR
)/uavobject-synthetics
189 uavobjects_
%: $(UAVOBJGENERATOR
)
190 @
$(MKDIR
) -p
$(UAVOBJ_OUT_DIR
)/$*
191 $(V1
) ( cd
$(UAVOBJ_OUT_DIR
)/$* && \
192 $(UAVOBJGENERATOR
) -$* $(UAVOBJ_XML_DIR
) $(ROOT_DIR
) ; \
195 uavobjects_test
: $(UAVOBJGENERATOR
)
196 $(V1
) $(UAVOBJGENERATOR
) -v
$(UAVOBJ_XML_DIR
) $(ROOT_DIR
)
199 @
$(ECHO
) " CLEAN $(call toprel, $(UAVOBJ_OUT_DIR))"
200 $(V1
) [ ! -d
"$(UAVOBJ_OUT_DIR)" ] ||
$(RM
) -r
"$(UAVOBJ_OUT_DIR)"
202 ##############################
204 # Flight related components
206 ##############################
209 # When building any of the "all_*" targets, tell all sub makefiles to display
210 # additional details on each line of output to describe which build and target
211 # that each line applies to. The same applies also to all, opfw_resource,
213 ifneq ($(strip $(filter all_
% all opfw_resource package
,$(MAKECMDGOALS
))),)
214 export ENABLE_MSG_EXTRA
:= yes
217 # When building more than one goal in a single make invocation, also
218 # enable the extra context for each output line
219 ifneq ($(word 2,$(MAKECMDGOALS
)),)
220 export ENABLE_MSG_EXTRA
:= yes
223 FLIGHT_OUT_DIR
:= $(BUILD_DIR
)/firmware
224 DIRS
+= $(FLIGHT_OUT_DIR
)
226 include $(ROOT_DIR
)/flight
/Makefile
228 ##############################
230 # GCS related components
232 ##############################
235 all_ground
: gcs uploader
243 GCS_DIR
:= $(BUILD_DIR
)/$(GCS_SMALL_NAME
)_
$(GCS_BUILD_CONF
)
246 GCS_MAKEFILE
:= $(GCS_DIR
)/Makefile
249 gcs_qmake
$(GCS_MAKEFILE
): |
$(GCS_DIR
)
250 $(V1
) cd
$(GCS_DIR
) && \
251 $(QMAKE
) $(ROOT_DIR
)/ground
/gcs
/gcs.pro \
252 -spec
$(QT_SPEC
) -r CONFIG
+=$(GCS_BUILD_CONF
) CONFIG
+=$(GCS_SILENT
) \
253 'GCS_BIG_NAME="$(GCS_BIG_NAME)"' GCS_SMALL_NAME
=$(GCS_SMALL_NAME
) \
254 'ORG_BIG_NAME="$(ORG_BIG_NAME)"' ORG_SMALL_NAME
=$(ORG_SMALL_NAME
) \
255 'WIKI_URL_ROOT="$(WIKI_URL_ROOT)"' \
256 'USAGETRACKER_URL="$(USAGETRACKER_URL)"' \
257 'GCS_LIBRARY_BASENAME=$(libbasename)' \
261 gcs
: $(UAVOBJGENERATOR
) $(GCS_MAKEFILE
)
262 $(V1
) $(MAKE
) -w
-C
$(GCS_DIR
)/$(MAKE_DIR
);
266 @
$(ECHO
) " CLEAN $(call toprel, $(GCS_DIR))"
267 $(V1
) [ ! -d
"$(GCS_DIR)" ] ||
$(RM
) -r
"$(GCS_DIR)"
271 ################################
273 # Serial Uploader tool
275 ################################
277 UPLOADER_DIR
:= $(BUILD_DIR
)/uploader_
$(GCS_BUILD_CONF
)
278 DIRS
+= $(UPLOADER_DIR
)
280 UPLOADER_MAKEFILE
:= $(UPLOADER_DIR
)/Makefile
282 .PHONY
: uploader_qmake
283 uploader_qmake
$(UPLOADER_MAKEFILE
): |
$(UPLOADER_DIR
)
284 $(V1
) cd
$(UPLOADER_DIR
) && \
285 $(QMAKE
) $(ROOT_DIR
)/ground
/gcs
/src
/experimental
/USB_UPLOAD_TOOL
/upload.pro \
286 -spec
$(QT_SPEC
) -r CONFIG
+=$(GCS_BUILD_CONF
) CONFIG
+=$(GCS_SILENT
) $(GCS_QMAKE_OPTS
)
289 uploader
: $(UPLOADER_MAKEFILE
)
290 $(V1
) $(MAKE
) -w
-C
$(UPLOADER_DIR
)
292 .PHONY
: uploader_clean
294 @
$(ECHO
) " CLEAN $(call toprel, $(UPLOADER_DIR))"
295 $(V1
) [ ! -d
"$(UPLOADER_DIR)" ] ||
$(RM
) -r
"$(UPLOADER_DIR)"
298 # We want to take snapshots of the UAVOs at each point that they change
299 # to allow the GCS to be compatible with as many versions as possible.
300 # We always include a pseudo collection called "srctree" which represents
301 # the UAVOs in the source tree. So not necessary to add current tree UAVO
302 # hash here, it is always included.
304 # Find the git hashes of each commit that changes uavobjects with:
305 # git log --format=%h -- shared/uavobjectdefinition/ | head -n 2
306 # List only UAVO hashes of past releases, do not list current hash.
307 # Past compatible versions are so far: RELEASE-12.10.2
308 UAVO_GIT_VERSIONS
:= 5e14f53
310 # All versions includes also the current source tree UAVO hash
311 UAVO_ALL_VERSIONS
:= $(UAVO_GIT_VERSIONS
) srctree
313 # This is where the UAVO collections are stored
314 UAVO_COLLECTION_DIR
:= $(BUILD_DIR
)/uavo-collections
316 # $(1) git hash of a UAVO snapshot
317 define UAVO_COLLECTION_GIT_TEMPLATE
319 # Make the output directory that will contain all of the synthetics for the
320 # uavo collection referenced by the git hash $(1)
321 $$(UAVO_COLLECTION_DIR
)/$(1):
322 $$(V1
) $(MKDIR
) -p
$$(UAVO_COLLECTION_DIR
)/$(1)
324 # Extract the snapshot of shared/uavobjectdefinition from git hash $(1)
325 $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml.
tar: |
$$(UAVO_COLLECTION_DIR
)/$(1)
326 $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml.
tar:
327 $$(V0
) @
$(ECHO
) " UAVOTAR $(1)"
328 $$(V1
) $(GIT
) archive
$(1) -o
$$@
-- shared
/uavobjectdefinition
/
330 # Extract the uavo xml files from our snapshot
331 $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml
: $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml.
tar
332 $$(V0
) @
$(ECHO
) " UAVOUNTAR $(1)"
334 $$(V1
) $(MKDIR
) -p
$$@
335 $$(V1
) $(TAR
) -C
$$(call toprel
, $$@
) -xf
$$(call toprel
, $$<) ||
$(RM
) -rf
$$@
338 # Map the current working directory into the set of UAVO collections
339 $(UAVO_COLLECTION_DIR
)/srctree
:
342 $(UAVO_COLLECTION_DIR
)/srctree
/uavo-xml
: |
$(UAVO_COLLECTION_DIR
)/srctree
343 $(UAVO_COLLECTION_DIR
)/srctree
/uavo-xml
: $(UAVOBJ_XML_DIR
)
344 $(V1
) $(LN
) -sf
$(ROOT_DIR
) $(UAVO_COLLECTION_DIR
)/srctree
/uavo-xml
346 # $(1) git hash (or symbolic name) of a UAVO snapshot
347 define UAVO_COLLECTION_BUILD_TEMPLATE
349 # This leaves us with a (broken) symlink that points to the full sha1sum of the collection
350 $$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
: $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml
351 # Compute the sha1 hash for this UAVO collection
352 # The sed bit truncates the UAVO hash to 16 hex digits
353 $$(V1
) $$(VERSION_INFO
) \
354 --uavodir
=$$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml
/shared
/uavobjectdefinition \
355 --format
='$$$${UAVO_HASH}' | \
356 $(SED
) -e
's|\(................\).*|\1|' > $$@
358 $$(V0
) @
$(ECHO
) " UAVOHASH $(1) ->" $$$$(cat
$$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
)
360 # Generate the java uavobjects for this UAVO collection
361 $$(UAVO_COLLECTION_DIR
)/$(1)/java-build
/java
: $$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
362 $$(V0
) @
$(ECHO
) " UAVOJAVA $(1) " $$$$(cat
$$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
)
363 $$(V1
) $(MKDIR
) -p
$$@
365 cd
$$(UAVO_COLLECTION_DIR
)/$(1)/java-build
&& \
366 $$(UAVOBJGENERATOR
) -java
$$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml
/shared
/uavobjectdefinition
$$(ROOT_DIR
) ; \
369 # Build a jar file for this UAVO collection
370 $$(UAVO_COLLECTION_DIR
)/$(1)/java-build
/uavobjects.jar
: |
$$(ANDROIDGCS_ASSETS_DIR
)/uavos
371 $$(UAVO_COLLECTION_DIR
)/$(1)/java-build
/uavobjects.jar
: $$(UAVO_COLLECTION_DIR
)/$(1)/java-build
/java
372 $$(V0
) @
$(ECHO
) " UAVOJAR $(1) " $$$$(cat
$$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
)
374 HASH
=$$$$(cat
$$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
) && \
375 cd
$$(UAVO_COLLECTION_DIR
)/$(1)/java-build
&& \
376 $(JAVAC
) java
/*.java \
377 $$(ROOT_DIR
)/androidgcs
/src
/org
/openpilot
/uavtalk
/UAVDataObject.java \
378 $$(ROOT_DIR
)/androidgcs
/src
/org
/openpilot
/uavtalk
/UAVObject
*.java \
379 $$(ROOT_DIR
)/androidgcs
/src
/org
/openpilot
/uavtalk
/UAVMetaObject.java \
381 find .
/org
/openpilot
/uavtalk
/uavobjects
-type f
-name
'*.class' > classlist.txt
&& \
382 $(JAR
) cf tmp_uavobjects.jar @classlist.txt
&& \
385 --output
$$(ANDROIDGCS_ASSETS_DIR
)/uavos
/$$$${HASH}.jar \
386 tmp_uavobjects.jar
&& \
387 $(LN
) -sf
$$(ANDROIDGCS_ASSETS_DIR
)/uavos
/$$$${HASH}.jar uavobjects.jar \
392 # One of these for each element of UAVO_GIT_VERSIONS so we can extract the UAVOs from git
393 $(foreach githash
, $(UAVO_GIT_VERSIONS
), $(eval
$(call UAVO_COLLECTION_GIT_TEMPLATE
,$(githash
))))
395 # One of these for each UAVO_ALL_VERSIONS which includes the ones in the srctree
396 $(foreach githash
, $(UAVO_ALL_VERSIONS
), $(eval
$(call UAVO_COLLECTION_BUILD_TEMPLATE
,$(githash
))))
398 .PHONY
: uavo-collections_java
399 uavo-collections_java
: $(foreach githash
, $(UAVO_ALL_VERSIONS
), $(UAVO_COLLECTION_DIR
)/$(githash
)/java-build
/uavobjects.jar
)
401 .PHONY
: uavo-collections
402 uavo-collections
: uavo-collections_java
404 .PHONY
: uavo-collections_clean
405 uavo-collections_clean
:
406 @
$(ECHO
) " CLEAN $(call toprel, $(UAVO_COLLECTION_DIR))"
407 $(V1
) [ ! -d
"$(UAVO_COLLECTION_DIR)" ] ||
$(RM
) -r
$(UAVO_COLLECTION_DIR
)
409 ##############################
413 ##############################
415 ALL_UNITTESTS
:= logfs math lednotification
417 # Build the directory for the unit tests
418 UT_OUT_DIR
:= $(BUILD_DIR
)/unit_tests
419 DIRS
+= $(UT_OUT_DIR
)
422 all_ut
: $(addsuffix _elf
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
425 all_ut_xml
: $(addsuffix _xml
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
428 all_ut_run
: $(addsuffix _run
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
432 @
$(ECHO
) " CLEAN $(call toprel, $(UT_OUT_DIR))"
433 $(V1
) [ ! -d
"$(UT_OUT_DIR)" ] ||
$(RM
) -r
"$(UT_OUT_DIR)"
435 # $(1) = Unit test name
440 ut_
$(1)_
%: $$(UT_OUT_DIR
)
441 $(V1
) $(MKDIR
) -p
$(UT_OUT_DIR
)/$(1)
442 $(V1
) cd
$(ROOT_DIR
)/flight
/tests
/$(1) && \
443 $$(MAKE
) -r
--no-print-directory \
445 BOARD_SHORT_NAME
=$(1) \
446 TOPDIR
=$(ROOT_DIR
)/flight
/tests
/$(1) \
447 OUTDIR
="$(UT_OUT_DIR)/$(1)" \
451 .PHONY
: ut_
$(1)_clean
453 @
$(ECHO
) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
454 $(V1
) [ ! -d
"$(UT_OUT_DIR)/$(1)" ] ||
$(RM
) -r
"$(UT_OUT_DIR)/$(1)"
457 # Expand the unittest rules
458 $(foreach ut
, $(ALL_UNITTESTS
), $(eval
$(call UT_TEMPLATE
,$(ut
))))
460 # Disable parallel make when the all_ut_run target is requested otherwise the TAP
461 # output is interleaved with the rest of the make output.
462 ifneq ($(strip $(filter all_ut_run
,$(MAKECMDGOALS
))),)
464 $(info $(EMPTY
) NOTE Parallel make disabled by all_ut_run target so we have sane console output
)
467 ##############################
469 # Packaging components
471 ##############################
472 # Firmware files to package
473 PACKAGE_FW_TARGETS
:= fw_coptercontrol fw_oplinkmini fw_revolution fw_osd fw_revoproto fw_gpsplatinum fw_revonano
475 # Rules to generate GCS resources used to embed firmware binaries into the GCS.
476 # They are used later by the vehicle setup wizard to update board firmware.
477 # To open a firmware image use ":/firmware/fw_coptercontrol.opfw"
478 OPFW_RESOURCE
:= $(OPGCSSYNTHDIR
)/opfw_resource.qrc
480 ifeq ($(WITH_PREBUILT_FW
),)
481 FIRMWARE_DIR
:= $(FLIGHT_OUT_DIR
)
482 # We need to build the FW targets
483 $(OPFW_RESOURCE
): $(PACKAGE_FW_TARGETS
)
485 FIRMWARE_DIR
:= $(WITH_PREBUILT_FW
)
488 OPFW_FILES
:= $(foreach fw_targ
, $(PACKAGE_FW_TARGETS
), $(FIRMWARE_DIR
)/$(fw_targ
)/$(fw_targ
).opfw
)
490 <!DOCTYPE RCC
><RCC version
="1.0"> \
491 <qresource
prefix="/firmware"> \
492 $(foreach fw_file
, $(OPFW_FILES
), <file alias
="$(notdir $(fw_file))">$(fw_file
)</file
>) \
496 .PHONY
: opfw_resource
497 opfw_resource
: $(OPFW_RESOURCE
)
499 $(OPFW_RESOURCE
): |
$(OPGCSSYNTHDIR
)
500 @
$(ECHO
) Generating OPFW resource file
$(call toprel
, $@
)
501 $(V1
) $(ECHO
) $(QUOTE
)$(OPFW_CONTENTS
)$(QUOTE
) > $@
503 # If opfw_resource or all firmware are requested, GCS should depend on the resource
504 ifneq ($(strip $(filter opfw_resource
all all_fw all_flight package
,$(MAKECMDGOALS
))),)
505 $(GCS_MAKEFILE
): $(OPFW_RESOURCE
)
508 # Packaging targets: package
509 # - builds all firmware, opfw_resource, gcs
510 # - copies firmware into a package directory
511 # - calls paltform-specific packaging script
513 # Define some variables
514 PACKAGE_LBL
:= $(shell $(VERSION_INFO
) --format
=\
$${LABEL})
515 PACKAGE_NAME
:= $(subst $(SPACE
),,$(ORG_BIG_NAME
))
517 PACKAGE_FULL_NAME
:= $(PACKAGE_NAME
)$(PACKAGE_SEP
)$(PACKAGE_LBL
)
519 # Source distribution is never dirty because it uses git archive
520 DIST_LBL
:= $(subst -dirty
,,$(PACKAGE_LBL
))
521 DIST_NAME
:= $(PACKAGE_NAME
)$(PACKAGE_SEP
)$(DIST_LBL
)
522 DIST_TAR
:= $(DIST_DIR
)/$(DIST_NAME
).
tar
523 DIST_TAR_GZ
:= $(DIST_TAR
).gz
524 FW_DIST_NAME
:= $(DIST_NAME
)_firmware
525 FW_DIST_TAR
:= $(DIST_DIR
)/$(FW_DIST_NAME
).
tar
526 FW_DIST_TAR_GZ
:= $(FW_DIST_TAR
).gz
527 DIST_VER_INFO
:= $(DIST_DIR
)/version-info.json
529 include $(ROOT_DIR
)/package
/$(UNAME
).mk
531 ##############################
533 # Source for distribution
535 ##############################
536 $(DIST_VER_INFO
): .git
/index |
$(DIST_DIR
)
537 $(V1
) $(VERSION_INFO
) --jsonpath
="$(DIST_DIR)"
539 $(DIST_TAR
): $(DIST_VER_INFO
) .git
/index |
$(DIST_DIR
)
540 @
$(ECHO
) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR))"
541 $(V1
) git archive
--prefix="$(PACKAGE_NAME)/" -o
"$(DIST_TAR)" HEAD
542 $(V1
) tar --append
--file
="$(DIST_TAR)" \
543 --transform
='s,.*version-info.json,$(PACKAGE_NAME)/version-info.json,' \
544 $(call toprel
, "$(DIST_VER_INFO)")
546 $(DIST_TAR_GZ
): $(DIST_TAR
)
547 @
$(ECHO
) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR_GZ))"
548 $(V1
) gzip
-kf
"$(DIST_TAR)"
551 dist_tar_gz
: $(DIST_TAR_GZ
)
557 $(FW_DIST_TAR
): $(PACKAGE_FW_TARGETS
) |
$(DIST_DIR
)
558 @
$(ECHO
) " FIRMWARE FOR DISTRIBUTION $(call toprel, $(FW_DIST_TAR))"
559 $(V1
) tar -c
--file
="$(FW_DIST_TAR)" --directory
=$(FLIGHT_OUT_DIR
) \
560 --transform
='s,^,firmware/,' \
561 $(foreach fw_targ
,$(PACKAGE_FW_TARGETS
),$(fw_targ
)/$(fw_targ
).opfw
)
563 $(FW_DIST_TAR_GZ
): $(FW_DIST_TAR
)
564 @
$(ECHO
) " FIRMWARE FOR DISTRIBUTION $(call toprel, $(FW_DIST_TAR_GZ))"
565 $(V1
) gzip
-kf
"$(FW_DIST_TAR)"
567 .PHONY
: fw_dist_tar_gz
568 fw_dist_tar_gz
: $(FW_DIST_TAR_GZ
)
571 fw_dist
: fw_dist_tar_gz
574 ##############################
576 # Source code formatting
578 ##############################
580 UNCRUSTIFY_TARGETS
:= flight ground
582 # $(1) = Uncrustify target (e.g flight or ground)
583 # $(2) = Target root directory
584 define UNCRUSTIFY_TEMPLATE
586 .PHONY
: uncrustify_
$(1)
588 @
$(ECHO
) "Auto-formatting $(1) source code"
589 $(V1
) UNCRUSTIFY_CONFIG
="$(ROOT_DIR)/make/uncrustify/uncrustify.cfg" $(SHELL
) make
/scripts
/uncrustify.sh
$(call toprel
, $(2))
592 $(foreach uncrustify_targ
, $(UNCRUSTIFY_TARGETS
), $(eval
$(call UNCRUSTIFY_TEMPLATE
,$(uncrustify_targ
),$(ROOT_DIR
)/$(uncrustify_targ
))))
594 .PHONY
: uncrustify_all
595 uncrustify_all
: $(addprefix uncrustify_
,$(UNCRUSTIFY_TARGETS
))
597 ##############################
599 # Doxygen documentation
601 # Each target should have own Doxyfile.$(target) with build directory build/docs/$(target),
602 # proper source directory (e.g. $(target)) and appropriate other doxygen options.
604 ##############################
606 DOCS_TARGETS
:= flight ground uavobjects
608 # $(1) = Doxygen target (e.g flight or ground)
609 define DOXYGEN_TEMPLATE
612 docs_
$(1): docs_
$(1)_clean
613 @
$(ECHO
) "Generating $(1) documentation"
614 $(V1
) $(MKDIR
) -p
$(BUILD_DIR
)/docs
/$(1)
615 $(V1
) $(DOXYGEN
) $(ROOT_DIR
)/make
/doxygen
/Doxyfile.
$(1)
617 .PHONY
: docs_
$(1)_clean
619 @
$(ECHO
) " CLEAN $(call toprel, $(BUILD_DIR)/docs/$(1))"
620 $(V1
) [ ! -d
"$(BUILD_DIR)/docs/$(1)" ] ||
$(RM
) -r
"$(BUILD_DIR)/docs/$(1)"
624 $(foreach docs_targ
, $(DOCS_TARGETS
), $(eval
$(call DOXYGEN_TEMPLATE
,$(docs_targ
))))
627 docs_all
: $(addprefix docs_
,$(DOCS_TARGETS
))
629 .PHONY
: docs_all_clean
631 @
$(ECHO
) " CLEAN $(call toprel, $(BUILD_DIR)/docs)"
632 $(V1
) [ ! -d
"$(BUILD_DIR)/docs" ] ||
$(RM
) -rf
"$(BUILD_DIR)/docs"
634 ##############################
638 ##############################
641 build-info
: |
$(BUILD_DIR
)
642 @
$(ECHO
) " BUILD-INFO $(call toprel, $(BUILD_DIR)/$@.txt)"
643 $(V1
) $(VERSION_INFO
) \
644 --uavodir
=$(ROOT_DIR
)/shared
/uavobjectdefinition \
645 --template
="make/templates/$@.txt" \
646 --outfile
="$(BUILD_DIR)/$@.txt"
648 ##############################
652 ##############################
654 CONFIG_OPTS
:= $(addsuffix \n,$(MAKEOVERRIDES
))
655 CONFIG_OPTS
:= $(addprefix override$(SPACE
),$(CONFIG_OPTS
))
659 @printf
'$(CONFIG_OPTS)' > $(CONFIG_FILE
)
661 .PHONY
: config_append
663 @printf
'$(CONFIG_OPTS)' >> $(CONFIG_FILE
)
674 ##############################
678 ##############################
684 ##############################
686 # Help message, the default Makefile goal
688 ##############################
690 .DEFAULT_GOAL
:= help
695 @
$(ECHO
) " This Makefile is known to work on Linux and Mac in a standard shell environment."
696 @
$(ECHO
) " It also works on Windows by following the instructions given on this wiki page:"
697 @
$(ECHO
) " http://wiki.openpilot.org/display/Doc/Windows%3A+Building+and+Packaging"
699 @
$(ECHO
) " Here is a summary of the available targets:"
701 @
$(ECHO
) " [Source tree preparation]"
702 @
$(ECHO
) " prepare - Install GIT commit message template"
703 @
$(ECHO
) " [Tool Installers]"
704 @
$(ECHO
) " arm_sdk_install - Install the GNU ARM gcc toolchain"
705 @
$(ECHO
) " qt_sdk_install - Install the QT development tools"
706 @
$(ECHO
) " nsis_install - Install the NSIS Unicode (Windows only)"
707 @
$(ECHO
) " sdl_install - Install the SDL library (Windows only)"
708 @
$(ECHO
) " mesawin_install - Install the OpenGL32 DLL (Windows only)"
709 @
$(ECHO
) " openssl_install - Install the OpenSSL libraries (Windows only)"
710 @
$(ECHO
) " uncrustify_install - Install the Uncrustify source code beautifier"
711 @
$(ECHO
) " doxygen_install - Install the Doxygen documentation generator"
712 @
$(ECHO
) " gtest_install - Install the GoogleTest framework"
713 @
$(ECHO
) " ccache_install - Install ccache"
714 @
$(ECHO
) " These targets are not updated yet and are probably broken:"
715 @
$(ECHO
) " openocd_install - Install the OpenOCD JTAG daemon"
716 @
$(ECHO
) " stm32flash_install - Install the stm32flash tool for unbricking F1-based boards"
717 @
$(ECHO
) " dfuutil_install - Install the dfu-util tool for unbricking F4-based boards"
718 @
$(ECHO
) " Install all available tools:"
719 @
$(ECHO
) " all_sdk_install - Install all of above (platform-dependent)"
720 @
$(ECHO
) " build_sdk_install - Install only essential for build tools (platform-dependent)"
722 @
$(ECHO
) " Other tool options are:"
723 @
$(ECHO
) " <tool>_version - Display <tool> version"
724 @
$(ECHO
) " <tool>_clean - Remove installed <tool>"
725 @
$(ECHO
) " <tool>_distclean - Remove downloaded <tool> distribution file(s)"
727 @
$(ECHO
) " [Big Hammer]"
728 @
$(ECHO
) " all - Generate UAVObjects, build openpilot firmware and gcs"
729 @
$(ECHO
) " all_flight - Build all firmware, bootloaders and bootloader updaters"
730 @
$(ECHO
) " all_fw - Build only firmware for all boards"
731 @
$(ECHO
) " all_bl - Build only bootloaders for all boards"
732 @
$(ECHO
) " all_bu - Build only bootloader updaters for all boards"
734 @
$(ECHO
) " all_clean - Remove your build directory ($(BUILD_DIR))"
735 @
$(ECHO
) " all_flight_clean - Remove all firmware, bootloaders and bootloader updaters"
736 @
$(ECHO
) " all_fw_clean - Remove firmware for all boards"
737 @
$(ECHO
) " all_bl_clean - Remove bootloaders for all boards"
738 @
$(ECHO
) " all_bu_clean - Remove bootloader updaters for all boards"
740 @
$(ECHO
) " all_<board> - Build all available images for <board>"
741 @
$(ECHO
) " all_<board>_clean - Remove all available images for <board>"
743 @
$(ECHO
) " all_ut - Build all unit tests"
744 @
$(ECHO
) " all_ut_tap - Run all unit tests and capture all TAP output to files"
745 @
$(ECHO
) " all_ut_run - Run all unit tests and dump TAP output to console"
747 @
$(ECHO
) " [Firmware]"
748 @
$(ECHO
) " <board> - Build firmware for <board>"
749 @
$(ECHO
) " Supported boards are ($(ALL_BOARDS))"
750 @
$(ECHO
) " fw_<board> - Build firmware for <board>"
751 @
$(ECHO
) " Supported boards are ($(FW_BOARDS))"
752 @
$(ECHO
) " fw_<board>_clean - Remove firmware for <board>"
753 @
$(ECHO
) " fw_<board>_program - Use OpenOCD + JTAG to write firmware to <board>"
755 @
$(ECHO
) " [Bootloader]"
756 @
$(ECHO
) " bl_<board> - Build bootloader for <board>"
757 @
$(ECHO
) " Supported boards are ($(BL_BOARDS))"
758 @
$(ECHO
) " bl_<board>_clean - Remove bootloader for <board>"
759 @
$(ECHO
) " bl_<board>_program - Use OpenOCD + JTAG to write bootloader to <board>"
761 @
$(ECHO
) " [Entire Flash]"
762 @
$(ECHO
) " ef_<board> - Build entire flash image for <board>"
763 @
$(ECHO
) " Supported boards are ($(EF_BOARDS))"
764 @
$(ECHO
) " ef_<board>_clean - Remove entire flash image for <board>"
765 @
$(ECHO
) " ef_<board>_program - Use OpenOCD + JTAG to write entire flash image to <board>"
767 @
$(ECHO
) " [Bootloader Updater]"
768 @
$(ECHO
) " bu_<board> - Build bootloader updater for <board>"
769 @
$(ECHO
) " Supported boards are ($(BU_BOARDS))"
770 @
$(ECHO
) " bu_<board>_clean - Remove bootloader updater for <board>"
772 @
$(ECHO
) " [Unbrick a board]"
773 @
$(ECHO
) " unbrick_<board> - Use the STM32's built in boot ROM to write a bootloader to <board>"
774 @
$(ECHO
) " Supported boards are ($(BL_BOARDS))"
775 @
$(ECHO
) " [Unittests]"
776 @
$(ECHO
) " ut_<test> - Build unit test <test>"
777 @
$(ECHO
) " ut_<test>_xml - Run test and capture XML output into a file"
778 @
$(ECHO
) " ut_<test>_run - Run test and dump output to console"
780 @
$(ECHO
) " [Simulation]"
781 @
$(ECHO
) " sim_osx - Build OpenPilot simulation firmware for OSX"
782 @
$(ECHO
) " sim_osx_clean - Delete all build output for the osx simulation"
783 @
$(ECHO
) " sim_win32 - Build OpenPilot simulation firmware for Windows"
784 @
$(ECHO
) " using mingw and msys"
785 @
$(ECHO
) " sim_win32_clean - Delete all build output for the win32 simulation"
788 @
$(ECHO
) " gcs - Build the Ground Control System (GCS) application (debug|release)"
789 @
$(ECHO
) " Compile specific directory: MAKE_DIR=<dir>"
790 @
$(ECHO
) " Example: make gcs MAKE_DIR=src/plugins/coreplugin"
791 @
$(ECHO
) " gcs_qmake - Run qmake for the Ground Control System (GCS) application (debug|release)"
792 @
$(ECHO
) " gcs_clean - Remove the Ground Control System (GCS) application (debug|release)"
793 @
$(ECHO
) " Supported build configurations: GCS_BUILD_CONF=debug|release (default is $(GCS_BUILD_CONF))"
795 @
$(ECHO
) " [Uploader Tool]"
796 @
$(ECHO
) " uploader - Build the serial uploader tool (debug|release)"
797 @
$(ECHO
) " uploader_qmake - Run qmake for the serial uploader tool (debug|release)"
798 @
$(ECHO
) " uploader_clean - Remove the serial uploader tool (debug|release)"
799 @
$(ECHO
) " Supported build configurations: GCS_BUILD_CONF=debug|release (default is $(GCS_BUILD_CONF))"
802 @
$(ECHO
) " [UAVObjects]"
803 @
$(ECHO
) " uavobjects - Generate source files from the UAVObject definition XML files"
804 @
$(ECHO
) " uavobjects_test - Parse xml-files - check for valid, duplicate ObjId's, ..."
805 @
$(ECHO
) " uavobjects_<group> - Generate source files from a subset of the UAVObject definition XML files"
806 @
$(ECHO
) " Supported groups are ($(UAVOBJ_TARGETS))"
808 @
$(ECHO
) " [Packaging]"
809 @
$(ECHO
) " package - Build and package the OpenPilot platform-dependent package (no clean)"
810 @
$(ECHO
) " opfw_resource - Generate resources to embed firmware binaries into the GCS"
811 @
$(ECHO
) " dist - Generate source archive for distribution"
812 @
$(ECHO
) " fw_dist - Generate archive of firmware"
813 @
$(ECHO
) " install - Install GCS to \"DESTDIR\" with prefix \"prefix\" (Linux only)"
815 @
$(ECHO
) " [Code Formatting]"
816 @
$(ECHO
) " uncrustify_<source> - Reformat <source> code according to the project's standards"
817 @
$(ECHO
) " Supported sources are ($(UNCRUSTIFY_TARGETS))"
818 @
$(ECHO
) " uncrustify_all - Reformat all source code"
820 @
$(ECHO
) " [Code Documentation]"
821 @
$(ECHO
) " docs_<source> - Generate HTML documentation for <source>"
822 @
$(ECHO
) " Supported sources are ($(DOCS_TARGETS))"
823 @
$(ECHO
) " docs_all - Generate HTML documentation for all"
824 @
$(ECHO
) " docs_<source>_clean - Delete generated documentation for <source>"
825 @
$(ECHO
) " docs_all_clean - Delete all generated documentation"
827 @
$(ECHO
) " [Configuration]"
828 @
$(ECHO
) " config_new - Place your make arguments in the config file"
829 @
$(ECHO
) " config_append - Place your make arguments in the config file but append"
830 @
$(ECHO
) " config_clean - Removes the config file"
832 @
$(ECHO
) " Hint: Add V=1 to your command line to see verbose build output."
834 @
$(ECHO
) " Notes: All tool distribution files will be downloaded into $(DL_DIR)"
835 @
$(ECHO
) " All tools will be installed into $(TOOLS_DIR)"
836 @
$(ECHO
) " All build output will be placed in $(BUILD_DIR)"
838 @
$(ECHO
) " Tool download and install directories can be changed using environment variables:"
839 @
$(ECHO
) " DL_DIR full path to downloads directory [downloads if not set]"
840 @
$(ECHO
) " TOOLS_DIR full path to installed tools directory [tools if not set]"
841 @
$(ECHO
) " More info: http://wiki.openpilot.org/display/Doc/OpenPilot+Build+System+Overview"