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 # Set up default build configurations (debug | release)
67 GCS_BUILD_CONF
:= release
68 GOOGLE_API_VERSION
:= 14
70 # Clean out undesirable variables from the environment and command-line
71 # to remove the chance that they will cause problems with our build
73 $(if
$(filter-out undefined
,$(origin $(1))),
74 $(info $(EMPTY
) NOTE Sanitized
$(2) variable
'$(1)' from
$(origin $(1)))
75 MAKEOVERRIDES
= $(filter-out $(1)=%,$(MAKEOVERRIDES
))
81 # These specific variables can influence compilation in unexpected (and undesirable) ways
83 SANITIZE_GCC_VARS
:= TMPDIR GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH
85 SANITIZE_GCC_VARS
+= CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH DEPENDENCIES_OUTPUT
87 SANITIZE_GCC_VARS
+= CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LDLIBS
88 $(foreach var
, $(SANITIZE_GCC_VARS
), $(eval
$(call SANITIZE_VAR
,$(var
),disallowed
)))
90 # These specific variables used to be valid but now they make no sense
91 SANITIZE_DEPRECATED_VARS
:= USE_BOOTLOADER CLEAN_BUILD
92 $(foreach var
, $(SANITIZE_DEPRECATED_VARS
), $(eval
$(call SANITIZE_VAR
,$(var
),deprecated
)))
94 # Make sure this isn't being run as root unless installing (no whoami on Windows, but that is ok here)
95 ifeq ($(shell whoami
2>/dev
/null
),root
)
96 ifeq ($(filter install uninstall,$(MAKECMDGOALS
)),)
98 $(error You should not be running this
as root
)
103 # Decide on a verbosity level based on the V= parameter
114 # Make sure we know few things about the architecture before including
115 # the tools.mk to ensure that we download/install the right tools.
116 UNAME
:= $(shell uname
)
117 ARCH
:= $(shell uname
-m
)
118 # Here and everywhere if not Linux or Mac then assume Windows
119 ifeq ($(filter Linux Darwin
, $(UNAME
)), )
123 # Include tools installers
124 include $(ROOT_DIR
)/make
/tools.mk
126 # Include third party builders if available
127 -include $(ROOT_DIR
)/make
/3rdparty
/3rdparty.mk
129 # We almost need to consider autoconf/automake instead of this
130 ifeq ($(UNAME
), Linux
)
132 UAVOBJGENERATOR
:= $(BUILD_DIR
)/uavobjgenerator
/uavobjgenerator
133 else ifeq ($(UNAME
), Darwin
)
135 UAVOBJGENERATOR
:= $(BUILD_DIR
)/uavobjgenerator
/uavobjgenerator
136 else ifeq ($(UNAME
), Windows
)
138 UAVOBJGENERATOR
:= $(BUILD_DIR
)/uavobjgenerator
/uavobjgenerator.exe
141 export UAVOBJGENERATOR
143 ##############################
147 ##############################
150 all: uavobjects all_ground all_flight
154 @
$(ECHO
) " CLEAN $(call toprel, $(BUILD_DIR))"
155 $(V1
) [ ! -d
"$(BUILD_DIR)" ] ||
$(RM
) -rf
"$(BUILD_DIR)"
161 ##############################
165 ##############################
167 UAVOBJGENERATOR_DIR
:= $(BUILD_DIR
)/uavobjgenerator
168 DIRS
+= $(UAVOBJGENERATOR_DIR
)
170 .PHONY
: uavobjgenerator
171 uavobjgenerator
$(UAVOBJGENERATOR
): |
$(UAVOBJGENERATOR_DIR
)
172 $(V1
) cd
$(UAVOBJGENERATOR_DIR
) && \
173 ( [ -f Makefile
] ||
$(QMAKE
) $(ROOT_DIR
)/ground
/uavobjgenerator
/uavobjgenerator.pro \
174 -spec
$(QT_SPEC
) CONFIG
+=$(GCS_BUILD_CONF
) CONFIG
+=$(GCS_SILENT
) ) && \
175 $(MAKE
) --no-print-directory
-w
177 UAVOBJ_TARGETS
:= gcs flight python matlab java wireshark
180 uavobjects
: $(addprefix uavobjects_
, $(UAVOBJ_TARGETS
))
182 UAVOBJ_XML_DIR
:= $(ROOT_DIR
)/shared
/uavobjectdefinition
183 UAVOBJ_OUT_DIR
:= $(BUILD_DIR
)/uavobject-synthetics
185 uavobjects_
%: uavobjgenerator
186 @
$(MKDIR
) -p
$(UAVOBJ_OUT_DIR
)/$*
187 $(V1
) ( cd
$(UAVOBJ_OUT_DIR
)/$* && \
188 $(UAVOBJGENERATOR
) -$* $(UAVOBJ_XML_DIR
) $(ROOT_DIR
) ; \
191 uavobjects_test
: uavobjgenerator
192 $(V1
) $(UAVOBJGENERATOR
) -v
$(UAVOBJ_XML_DIR
) $(ROOT_DIR
)
195 @
$(ECHO
) " CLEAN $(call toprel, $(UAVOBJ_OUT_DIR))"
196 $(V1
) [ ! -d
"$(UAVOBJ_OUT_DIR)" ] ||
$(RM
) -r
"$(UAVOBJ_OUT_DIR)"
198 ##############################
200 # Flight related components
202 ##############################
205 # When building any of the "all_*" targets, tell all sub makefiles to display
206 # additional details on each line of output to describe which build and target
207 # that each line applies to. The same applies also to all, opfw_resource,
209 ifneq ($(strip $(filter all_
% all opfw_resource package
,$(MAKECMDGOALS
))),)
210 export ENABLE_MSG_EXTRA
:= yes
213 # When building more than one goal in a single make invocation, also
214 # enable the extra context for each output line
215 ifneq ($(word 2,$(MAKECMDGOALS
)),)
216 export ENABLE_MSG_EXTRA
:= yes
219 FLIGHT_OUT_DIR
:= $(BUILD_DIR
)/firmware
220 DIRS
+= $(FLIGHT_OUT_DIR
)
222 include $(ROOT_DIR
)/flight
/Makefile
224 ##############################
226 # GCS related components
228 ##############################
231 all_ground
: gcs uploader
239 GCS_DIR
:= $(BUILD_DIR
)/$(GCS_SMALL_NAME
)_
$(GCS_BUILD_CONF
)
242 GCS_MAKEFILE
:= $(GCS_DIR
)/Makefile
245 gcs_qmake
$(GCS_MAKEFILE
): |
$(GCS_DIR
)
246 $(V1
) cd
$(GCS_DIR
) && \
247 $(QMAKE
) $(ROOT_DIR
)/ground
/gcs
/gcs.pro \
248 -spec
$(QT_SPEC
) -r CONFIG
+=$(GCS_BUILD_CONF
) CONFIG
+=$(GCS_SILENT
) \
249 'GCS_BIG_NAME="$(GCS_BIG_NAME)"' GCS_SMALL_NAME
=$(GCS_SMALL_NAME
) \
250 'ORG_BIG_NAME="$(ORG_BIG_NAME)"' ORG_SMALL_NAME
=$(ORG_SMALL_NAME
) \
251 'WIKI_URL_ROOT="$(WIKI_URL_ROOT)"' \
252 'GCS_LIBRARY_BASENAME=$(libbasename)' \
256 gcs
: uavobjgenerator
$(GCS_MAKEFILE
)
257 $(V1
) $(MAKE
) -w
-C
$(GCS_DIR
)/$(MAKE_DIR
);
261 @
$(ECHO
) " CLEAN $(call toprel, $(GCS_DIR))"
262 $(V1
) [ ! -d
"$(GCS_DIR)" ] ||
$(RM
) -r
"$(GCS_DIR)"
266 ################################
268 # Serial Uploader tool
270 ################################
272 UPLOADER_DIR
:= $(BUILD_DIR
)/uploader_
$(GCS_BUILD_CONF
)
273 DIRS
+= $(UPLOADER_DIR
)
275 UPLOADER_MAKEFILE
:= $(UPLOADER_DIR
)/Makefile
277 .PHONY
: uploader_qmake
278 uploader_qmake
$(UPLOADER_MAKEFILE
): |
$(UPLOADER_DIR
)
279 $(V1
) cd
$(UPLOADER_DIR
) && \
280 $(QMAKE
) $(ROOT_DIR
)/ground
/gcs
/src
/experimental
/USB_UPLOAD_TOOL
/upload.pro \
281 -spec
$(QT_SPEC
) -r CONFIG
+=$(GCS_BUILD_CONF
) CONFIG
+=$(GCS_SILENT
) $(GCS_QMAKE_OPTS
)
284 uploader
: $(UPLOADER_MAKEFILE
)
285 $(V1
) $(MAKE
) -w
-C
$(UPLOADER_DIR
)
287 .PHONY
: uploader_clean
289 @
$(ECHO
) " CLEAN $(call toprel, $(UPLOADER_DIR))"
290 $(V1
) [ ! -d
"$(UPLOADER_DIR)" ] ||
$(RM
) -r
"$(UPLOADER_DIR)"
293 # We want to take snapshots of the UAVOs at each point that they change
294 # to allow the GCS to be compatible with as many versions as possible.
295 # We always include a pseudo collection called "srctree" which represents
296 # the UAVOs in the source tree. So not necessary to add current tree UAVO
297 # hash here, it is always included.
299 # Find the git hashes of each commit that changes uavobjects with:
300 # git log --format=%h -- shared/uavobjectdefinition/ | head -n 2
301 # List only UAVO hashes of past releases, do not list current hash.
302 # Past compatible versions are so far: RELEASE-12.10.2
303 UAVO_GIT_VERSIONS
:= 5e14f53
305 # All versions includes also the current source tree UAVO hash
306 UAVO_ALL_VERSIONS
:= $(UAVO_GIT_VERSIONS
) srctree
308 # This is where the UAVO collections are stored
309 UAVO_COLLECTION_DIR
:= $(BUILD_DIR
)/uavo-collections
311 # $(1) git hash of a UAVO snapshot
312 define UAVO_COLLECTION_GIT_TEMPLATE
314 # Make the output directory that will contain all of the synthetics for the
315 # uavo collection referenced by the git hash $(1)
316 $$(UAVO_COLLECTION_DIR
)/$(1):
317 $$(V1
) $(MKDIR
) -p
$$(UAVO_COLLECTION_DIR
)/$(1)
319 # Extract the snapshot of shared/uavobjectdefinition from git hash $(1)
320 $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml.
tar: |
$$(UAVO_COLLECTION_DIR
)/$(1)
321 $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml.
tar:
322 $$(V0
) @
$(ECHO
) " UAVOTAR $(1)"
323 $$(V1
) $(GIT
) archive
$(1) -o
$$@
-- shared
/uavobjectdefinition
/
325 # Extract the uavo xml files from our snapshot
326 $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml
: $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml.
tar
327 $$(V0
) @
$(ECHO
) " UAVOUNTAR $(1)"
329 $$(V1
) $(MKDIR
) -p
$$@
330 $$(V1
) $(TAR
) -C
$$(call toprel
, $$@
) -xf
$$(call toprel
, $$<) ||
$(RM
) -rf
$$@
333 # Map the current working directory into the set of UAVO collections
334 $(UAVO_COLLECTION_DIR
)/srctree
:
337 $(UAVO_COLLECTION_DIR
)/srctree
/uavo-xml
: |
$(UAVO_COLLECTION_DIR
)/srctree
338 $(UAVO_COLLECTION_DIR
)/srctree
/uavo-xml
: $(UAVOBJ_XML_DIR
)
339 $(V1
) $(LN
) -sf
$(ROOT_DIR
) $(UAVO_COLLECTION_DIR
)/srctree
/uavo-xml
341 # $(1) git hash (or symbolic name) of a UAVO snapshot
342 define UAVO_COLLECTION_BUILD_TEMPLATE
344 # This leaves us with a (broken) symlink that points to the full sha1sum of the collection
345 $$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
: $$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml
346 # Compute the sha1 hash for this UAVO collection
347 # The sed bit truncates the UAVO hash to 16 hex digits
348 $$(V1
) $$(VERSION_INFO
) \
349 --uavodir
=$$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml
/shared
/uavobjectdefinition \
350 --format
='$$$${UAVO_HASH}' | \
351 $(SED
) -e
's|\(................\).*|\1|' > $$@
353 $$(V0
) @
$(ECHO
) " UAVOHASH $(1) ->" $$$$(cat
$$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
)
355 # Generate the java uavobjects for this UAVO collection
356 $$(UAVO_COLLECTION_DIR
)/$(1)/java-build
/java
: $$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
357 $$(V0
) @
$(ECHO
) " UAVOJAVA $(1) " $$$$(cat
$$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
)
358 $$(V1
) $(MKDIR
) -p
$$@
360 cd
$$(UAVO_COLLECTION_DIR
)/$(1)/java-build
&& \
361 $$(UAVOBJGENERATOR
) -java
$$(UAVO_COLLECTION_DIR
)/$(1)/uavo-xml
/shared
/uavobjectdefinition
$$(ROOT_DIR
) ; \
364 # Build a jar file for this UAVO collection
365 $$(UAVO_COLLECTION_DIR
)/$(1)/java-build
/uavobjects.jar
: |
$$(ANDROIDGCS_ASSETS_DIR
)/uavos
366 $$(UAVO_COLLECTION_DIR
)/$(1)/java-build
/uavobjects.jar
: $$(UAVO_COLLECTION_DIR
)/$(1)/java-build
/java
367 $$(V0
) @
$(ECHO
) " UAVOJAR $(1) " $$$$(cat
$$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
)
369 HASH
=$$$$(cat
$$(UAVO_COLLECTION_DIR
)/$(1)/uavohash
) && \
370 cd
$$(UAVO_COLLECTION_DIR
)/$(1)/java-build
&& \
371 $(JAVAC
) java
/*.java \
372 $$(ROOT_DIR
)/androidgcs
/src
/org
/openpilot
/uavtalk
/UAVDataObject.java \
373 $$(ROOT_DIR
)/androidgcs
/src
/org
/openpilot
/uavtalk
/UAVObject
*.java \
374 $$(ROOT_DIR
)/androidgcs
/src
/org
/openpilot
/uavtalk
/UAVMetaObject.java \
376 find .
/org
/openpilot
/uavtalk
/uavobjects
-type f
-name
'*.class' > classlist.txt
&& \
377 $(JAR
) cf tmp_uavobjects.jar @classlist.txt
&& \
380 --output
$$(ANDROIDGCS_ASSETS_DIR
)/uavos
/$$$${HASH}.jar \
381 tmp_uavobjects.jar
&& \
382 $(LN
) -sf
$$(ANDROIDGCS_ASSETS_DIR
)/uavos
/$$$${HASH}.jar uavobjects.jar \
387 # One of these for each element of UAVO_GIT_VERSIONS so we can extract the UAVOs from git
388 $(foreach githash
, $(UAVO_GIT_VERSIONS
), $(eval
$(call UAVO_COLLECTION_GIT_TEMPLATE
,$(githash
))))
390 # One of these for each UAVO_ALL_VERSIONS which includes the ones in the srctree
391 $(foreach githash
, $(UAVO_ALL_VERSIONS
), $(eval
$(call UAVO_COLLECTION_BUILD_TEMPLATE
,$(githash
))))
393 .PHONY
: uavo-collections_java
394 uavo-collections_java
: $(foreach githash
, $(UAVO_ALL_VERSIONS
), $(UAVO_COLLECTION_DIR
)/$(githash
)/java-build
/uavobjects.jar
)
396 .PHONY
: uavo-collections
397 uavo-collections
: uavo-collections_java
399 .PHONY
: uavo-collections_clean
400 uavo-collections_clean
:
401 @
$(ECHO
) " CLEAN $(call toprel, $(UAVO_COLLECTION_DIR))"
402 $(V1
) [ ! -d
"$(UAVO_COLLECTION_DIR)" ] ||
$(RM
) -r
$(UAVO_COLLECTION_DIR
)
404 ##############################
408 ##############################
410 ALL_UNITTESTS
:= logfs math lednotification
412 # Build the directory for the unit tests
413 UT_OUT_DIR
:= $(BUILD_DIR
)/unit_tests
414 DIRS
+= $(UT_OUT_DIR
)
417 all_ut
: $(addsuffix _elf
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
420 all_ut_xml
: $(addsuffix _xml
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
423 all_ut_run
: $(addsuffix _run
, $(addprefix ut_
, $(ALL_UNITTESTS
)))
427 @
$(ECHO
) " CLEAN $(call toprel, $(UT_OUT_DIR))"
428 $(V1
) [ ! -d
"$(UT_OUT_DIR)" ] ||
$(RM
) -r
"$(UT_OUT_DIR)"
430 # $(1) = Unit test name
435 ut_
$(1)_
%: $$(UT_OUT_DIR
)
436 $(V1
) $(MKDIR
) -p
$(UT_OUT_DIR
)/$(1)
437 $(V1
) cd
$(ROOT_DIR
)/flight
/tests
/$(1) && \
438 $$(MAKE
) -r
--no-print-directory \
440 BOARD_SHORT_NAME
=$(1) \
441 TOPDIR
=$(ROOT_DIR
)/flight
/tests
/$(1) \
442 OUTDIR
="$(UT_OUT_DIR)/$(1)" \
446 .PHONY
: ut_
$(1)_clean
448 @
$(ECHO
) " CLEAN $(call toprel, $(UT_OUT_DIR)/$(1))"
449 $(V1
) [ ! -d
"$(UT_OUT_DIR)/$(1)" ] ||
$(RM
) -r
"$(UT_OUT_DIR)/$(1)"
452 # Expand the unittest rules
453 $(foreach ut
, $(ALL_UNITTESTS
), $(eval
$(call UT_TEMPLATE
,$(ut
))))
455 # Disable parallel make when the all_ut_run target is requested otherwise the TAP
456 # output is interleaved with the rest of the make output.
457 ifneq ($(strip $(filter all_ut_run
,$(MAKECMDGOALS
))),)
459 $(info $(EMPTY
) NOTE Parallel make disabled by all_ut_run target so we have sane console output
)
462 ##############################
464 # Packaging components
466 ##############################
467 # Firmware files to package
468 PACKAGE_FW_TARGETS
:= fw_coptercontrol fw_oplinkmini fw_revolution fw_osd fw_revoproto fw_gpsplatinum fw_revonano
470 # Rules to generate GCS resources used to embed firmware binaries into the GCS.
471 # They are used later by the vehicle setup wizard to update board firmware.
472 # To open a firmware image use ":/firmware/fw_coptercontrol.opfw"
473 OPFW_RESOURCE
:= $(OPGCSSYNTHDIR
)/opfw_resource.qrc
475 ifeq ($(WITH_PREBUILT_FW
),)
476 FIRMWARE_DIR
:= $(FLIGHT_OUT_DIR
)
477 # We need to build the FW targets
478 $(OPFW_RESOURCE
): $(PACKAGE_FW_TARGETS
)
480 FIRMWARE_DIR
:= $(WITH_PREBUILT_FW
)
483 OPFW_FILES
:= $(foreach fw_targ
, $(PACKAGE_FW_TARGETS
), $(FIRMWARE_DIR
)/$(fw_targ
)/$(fw_targ
).opfw
)
485 <!DOCTYPE RCC
><RCC version
="1.0"> \
486 <qresource
prefix="/firmware"> \
487 $(foreach fw_file
, $(OPFW_FILES
), <file alias
="$(notdir $(fw_file))">$(fw_file
)</file
>) \
491 .PHONY
: opfw_resource
492 opfw_resource
: $(OPFW_RESOURCE
)
494 $(OPFW_RESOURCE
): |
$(OPGCSSYNTHDIR
)
495 @
$(ECHO
) Generating OPFW resource file
$(call toprel
, $@
)
496 $(V1
) $(ECHO
) $(QUOTE
)$(OPFW_CONTENTS
)$(QUOTE
) > $@
498 # If opfw_resource or all firmware are requested, GCS should depend on the resource
499 ifneq ($(strip $(filter opfw_resource
all all_fw all_flight package
,$(MAKECMDGOALS
))),)
500 $(GCS_MAKEFILE
): $(OPFW_RESOURCE
)
503 # Packaging targets: package
504 # - builds all firmware, opfw_resource, gcs
505 # - copies firmware into a package directory
506 # - calls paltform-specific packaging script
508 # Define some variables
509 PACKAGE_LBL
:= $(shell $(VERSION_INFO
) --format
=\
$${LABEL})
510 PACKAGE_NAME
:= $(subst $(SPACE
),,$(ORG_BIG_NAME
))
512 PACKAGE_FULL_NAME
:= $(PACKAGE_NAME
)$(PACKAGE_SEP
)$(PACKAGE_LBL
)
514 # Source distribution is never dirty because it uses git archive
515 DIST_LBL
:= $(subst -dirty
,,$(PACKAGE_LBL
))
516 DIST_NAME
:= $(PACKAGE_NAME
)$(PACKAGE_SEP
)$(DIST_LBL
)
517 DIST_TAR
:= $(DIST_DIR
)/$(DIST_NAME
).
tar
518 DIST_TAR_GZ
:= $(DIST_TAR
).gz
519 FW_DIST_NAME
:= $(DIST_NAME
)_firmware
520 FW_DIST_TAR
:= $(DIST_DIR
)/$(FW_DIST_NAME
).
tar
521 FW_DIST_TAR_GZ
:= $(FW_DIST_TAR
).gz
522 DIST_VER_INFO
:= $(DIST_DIR
)/version-info.json
524 include $(ROOT_DIR
)/package
/$(UNAME
).mk
526 ##############################
528 # Source for distribution
530 ##############################
531 $(DIST_VER_INFO
): .git
/index |
$(DIST_DIR
)
532 $(V1
) $(VERSION_INFO
) --jsonpath
="$(DIST_DIR)"
534 $(DIST_TAR
): $(DIST_VER_INFO
) .git
/index |
$(DIST_DIR
)
535 @
$(ECHO
) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR))"
536 $(V1
) git archive
--prefix="$(PACKAGE_NAME)/" -o
"$(DIST_TAR)" HEAD
537 $(V1
) tar --append
--file
="$(DIST_TAR)" \
538 --transform
='s,.*version-info.json,$(PACKAGE_NAME)/version-info.json,' \
539 $(call toprel
, "$(DIST_VER_INFO)")
541 $(DIST_TAR_GZ
): $(DIST_TAR
)
542 @
$(ECHO
) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR_GZ))"
543 $(V1
) gzip
-kf
"$(DIST_TAR)"
546 dist_tar_gz
: $(DIST_TAR_GZ
)
552 $(FW_DIST_TAR
): $(PACKAGE_FW_TARGETS
) |
$(DIST_DIR
)
553 @
$(ECHO
) " FIRMWARE FOR DISTRIBUTION $(call toprel, $(FW_DIST_TAR))"
554 $(V1
) tar -c
--file
="$(FW_DIST_TAR)" --directory
=$(FLIGHT_OUT_DIR
) \
555 --transform
='s,^,firmware/,' \
556 $(foreach fw_targ
,$(PACKAGE_FW_TARGETS
),$(fw_targ
)/$(fw_targ
).opfw
)
558 $(FW_DIST_TAR_GZ
): $(FW_DIST_TAR
)
559 @
$(ECHO
) " FIRMWARE FOR DISTRIBUTION $(call toprel, $(FW_DIST_TAR_GZ))"
560 $(V1
) gzip
-kf
"$(FW_DIST_TAR)"
562 .PHONY
: fw_dist_tar_gz
563 fw_dist_tar_gz
: $(FW_DIST_TAR_GZ
)
566 fw_dist
: fw_dist_tar_gz
569 ##############################
571 # Source code formatting
573 ##############################
575 UNCRUSTIFY_TARGETS
:= flight ground
577 # $(1) = Uncrustify target (e.g flight or ground)
578 # $(2) = Target root directory
579 define UNCRUSTIFY_TEMPLATE
581 .PHONY
: uncrustify_
$(1)
583 @
$(ECHO
) "Auto-formatting $(1) source code"
584 $(V1
) UNCRUSTIFY_CONFIG
="$(ROOT_DIR)/make/uncrustify/uncrustify.cfg" $(SHELL
) make
/scripts
/uncrustify.sh
$(call toprel
, $(2))
587 $(foreach uncrustify_targ
, $(UNCRUSTIFY_TARGETS
), $(eval
$(call UNCRUSTIFY_TEMPLATE
,$(uncrustify_targ
),$(ROOT_DIR
)/$(uncrustify_targ
))))
589 .PHONY
: uncrustify_all
590 uncrustify_all
: $(addprefix uncrustify_
,$(UNCRUSTIFY_TARGETS
))
592 ##############################
594 # Doxygen documentation
596 # Each target should have own Doxyfile.$(target) with build directory build/docs/$(target),
597 # proper source directory (e.g. $(target)) and appropriate other doxygen options.
599 ##############################
601 DOCS_TARGETS
:= flight ground uavobjects
603 # $(1) = Doxygen target (e.g flight or ground)
604 define DOXYGEN_TEMPLATE
607 docs_
$(1): docs_
$(1)_clean
608 @
$(ECHO
) "Generating $(1) documentation"
609 $(V1
) $(MKDIR
) -p
$(BUILD_DIR
)/docs
/$(1)
610 $(V1
) $(DOXYGEN
) $(ROOT_DIR
)/make
/doxygen
/Doxyfile.
$(1)
612 .PHONY
: docs_
$(1)_clean
614 @
$(ECHO
) " CLEAN $(call toprel, $(BUILD_DIR)/docs/$(1))"
615 $(V1
) [ ! -d
"$(BUILD_DIR)/docs/$(1)" ] ||
$(RM
) -r
"$(BUILD_DIR)/docs/$(1)"
619 $(foreach docs_targ
, $(DOCS_TARGETS
), $(eval
$(call DOXYGEN_TEMPLATE
,$(docs_targ
))))
622 docs_all
: $(addprefix docs_
,$(DOCS_TARGETS
))
624 .PHONY
: docs_all_clean
626 @
$(ECHO
) " CLEAN $(call toprel, $(BUILD_DIR)/docs)"
627 $(V1
) [ ! -d
"$(BUILD_DIR)/docs" ] ||
$(RM
) -rf
"$(BUILD_DIR)/docs"
629 ##############################
633 ##############################
636 build-info
: |
$(BUILD_DIR
)
637 @
$(ECHO
) " BUILD-INFO $(call toprel, $(BUILD_DIR)/$@.txt)"
638 $(V1
) $(VERSION_INFO
) \
639 --uavodir
=$(ROOT_DIR
)/shared
/uavobjectdefinition \
640 --template
="make/templates/$@.txt" \
641 --outfile
="$(BUILD_DIR)/$@.txt"
643 ##############################
647 ##############################
649 CONFIG_OPTS
:= $(addsuffix \n,$(MAKEOVERRIDES
))
650 CONFIG_OPTS
:= $(addprefix override$(SPACE
),$(CONFIG_OPTS
))
654 @printf
'$(CONFIG_OPTS)' > $(CONFIG_FILE
)
656 .PHONY
: config_append
658 @printf
'$(CONFIG_OPTS)' >> $(CONFIG_FILE
)
669 ##############################
673 ##############################
679 ##############################
681 # Help message, the default Makefile goal
683 ##############################
685 .DEFAULT_GOAL
:= help
690 @
$(ECHO
) " This Makefile is known to work on Linux and Mac in a standard shell environment."
691 @
$(ECHO
) " It also works on Windows by following the instructions given on this wiki page:"
692 @
$(ECHO
) " http://wiki.openpilot.org/display/Doc/Windows%3A+Building+and+Packaging"
694 @
$(ECHO
) " Here is a summary of the available targets:"
696 @
$(ECHO
) " [Source tree preparation]"
697 @
$(ECHO
) " prepare - Install GIT commit message template"
698 @
$(ECHO
) " [Tool Installers]"
699 @
$(ECHO
) " arm_sdk_install - Install the GNU ARM gcc toolchain"
700 @
$(ECHO
) " qt_sdk_install - Install the QT development tools"
701 @
$(ECHO
) " nsis_install - Install the NSIS Unicode (Windows only)"
702 @
$(ECHO
) " sdl_install - Install the SDL library (Windows only)"
703 @
$(ECHO
) " mesawin_install - Install the OpenGL32 DLL (Windows only)"
704 @
$(ECHO
) " openssl_install - Install the OpenSSL libraries (Windows only)"
705 @
$(ECHO
) " uncrustify_install - Install the Uncrustify source code beautifier"
706 @
$(ECHO
) " doxygen_install - Install the Doxygen documentation generator"
707 @
$(ECHO
) " gtest_install - Install the GoogleTest framework"
708 @
$(ECHO
) " ccache_install - Install ccache"
709 @
$(ECHO
) " These targets are not updated yet and are probably broken:"
710 @
$(ECHO
) " openocd_install - Install the OpenOCD JTAG daemon"
711 @
$(ECHO
) " stm32flash_install - Install the stm32flash tool for unbricking F1-based boards"
712 @
$(ECHO
) " dfuutil_install - Install the dfu-util tool for unbricking F4-based boards"
713 @
$(ECHO
) " Install all available tools:"
714 @
$(ECHO
) " all_sdk_install - Install all of above (platform-dependent)"
715 @
$(ECHO
) " build_sdk_install - Install only essential for build tools (platform-dependent)"
717 @
$(ECHO
) " Other tool options are:"
718 @
$(ECHO
) " <tool>_version - Display <tool> version"
719 @
$(ECHO
) " <tool>_clean - Remove installed <tool>"
720 @
$(ECHO
) " <tool>_distclean - Remove downloaded <tool> distribution file(s)"
722 @
$(ECHO
) " [Big Hammer]"
723 @
$(ECHO
) " all - Generate UAVObjects, build openpilot firmware and gcs"
724 @
$(ECHO
) " all_flight - Build all firmware, bootloaders and bootloader updaters"
725 @
$(ECHO
) " all_fw - Build only firmware for all boards"
726 @
$(ECHO
) " all_bl - Build only bootloaders for all boards"
727 @
$(ECHO
) " all_bu - Build only bootloader updaters for all boards"
729 @
$(ECHO
) " all_clean - Remove your build directory ($(BUILD_DIR))"
730 @
$(ECHO
) " all_flight_clean - Remove all firmware, bootloaders and bootloader updaters"
731 @
$(ECHO
) " all_fw_clean - Remove firmware for all boards"
732 @
$(ECHO
) " all_bl_clean - Remove bootloaders for all boards"
733 @
$(ECHO
) " all_bu_clean - Remove bootloader updaters for all boards"
735 @
$(ECHO
) " all_<board> - Build all available images for <board>"
736 @
$(ECHO
) " all_<board>_clean - Remove all available images for <board>"
738 @
$(ECHO
) " all_ut - Build all unit tests"
739 @
$(ECHO
) " all_ut_tap - Run all unit tests and capture all TAP output to files"
740 @
$(ECHO
) " all_ut_run - Run all unit tests and dump TAP output to console"
742 @
$(ECHO
) " [Firmware]"
743 @
$(ECHO
) " <board> - Build firmware for <board>"
744 @
$(ECHO
) " Supported boards are ($(ALL_BOARDS))"
745 @
$(ECHO
) " fw_<board> - Build firmware for <board>"
746 @
$(ECHO
) " Supported boards are ($(FW_BOARDS))"
747 @
$(ECHO
) " fw_<board>_clean - Remove firmware for <board>"
748 @
$(ECHO
) " fw_<board>_program - Use OpenOCD + JTAG to write firmware to <board>"
750 @
$(ECHO
) " [Bootloader]"
751 @
$(ECHO
) " bl_<board> - Build bootloader for <board>"
752 @
$(ECHO
) " Supported boards are ($(BL_BOARDS))"
753 @
$(ECHO
) " bl_<board>_clean - Remove bootloader for <board>"
754 @
$(ECHO
) " bl_<board>_program - Use OpenOCD + JTAG to write bootloader to <board>"
756 @
$(ECHO
) " [Entire Flash]"
757 @
$(ECHO
) " ef_<board> - Build entire flash image for <board>"
758 @
$(ECHO
) " Supported boards are ($(EF_BOARDS))"
759 @
$(ECHO
) " ef_<board>_clean - Remove entire flash image for <board>"
760 @
$(ECHO
) " ef_<board>_program - Use OpenOCD + JTAG to write entire flash image to <board>"
762 @
$(ECHO
) " [Bootloader Updater]"
763 @
$(ECHO
) " bu_<board> - Build bootloader updater for <board>"
764 @
$(ECHO
) " Supported boards are ($(BU_BOARDS))"
765 @
$(ECHO
) " bu_<board>_clean - Remove bootloader updater for <board>"
767 @
$(ECHO
) " [Unbrick a board]"
768 @
$(ECHO
) " unbrick_<board> - Use the STM32's built in boot ROM to write a bootloader to <board>"
769 @
$(ECHO
) " Supported boards are ($(BL_BOARDS))"
770 @
$(ECHO
) " [Unittests]"
771 @
$(ECHO
) " ut_<test> - Build unit test <test>"
772 @
$(ECHO
) " ut_<test>_xml - Run test and capture XML output into a file"
773 @
$(ECHO
) " ut_<test>_run - Run test and dump output to console"
775 @
$(ECHO
) " [Simulation]"
776 @
$(ECHO
) " sim_osx - Build OpenPilot simulation firmware for OSX"
777 @
$(ECHO
) " sim_osx_clean - Delete all build output for the osx simulation"
778 @
$(ECHO
) " sim_win32 - Build OpenPilot simulation firmware for Windows"
779 @
$(ECHO
) " using mingw and msys"
780 @
$(ECHO
) " sim_win32_clean - Delete all build output for the win32 simulation"
783 @
$(ECHO
) " gcs - Build the Ground Control System (GCS) application (debug|release)"
784 @
$(ECHO
) " Compile specific directory: MAKE_DIR=<dir>"
785 @
$(ECHO
) " Example: make gcs MAKE_DIR=src/plugins/coreplugin"
786 @
$(ECHO
) " gcs_qmake - Run qmake for the Ground Control System (GCS) application (debug|release)"
787 @
$(ECHO
) " gcs_clean - Remove the Ground Control System (GCS) application (debug|release)"
788 @
$(ECHO
) " Supported build configurations: GCS_BUILD_CONF=debug|release (default is $(GCS_BUILD_CONF))"
790 @
$(ECHO
) " [Uploader Tool]"
791 @
$(ECHO
) " uploader - Build the serial uploader tool (debug|release)"
792 @
$(ECHO
) " uploader_qmake - Run qmake for the serial uploader tool (debug|release)"
793 @
$(ECHO
) " uploader_clean - Remove the serial uploader tool (debug|release)"
794 @
$(ECHO
) " Supported build configurations: GCS_BUILD_CONF=debug|release (default is $(GCS_BUILD_CONF))"
797 @
$(ECHO
) " [UAVObjects]"
798 @
$(ECHO
) " uavobjects - Generate source files from the UAVObject definition XML files"
799 @
$(ECHO
) " uavobjects_test - Parse xml-files - check for valid, duplicate ObjId's, ..."
800 @
$(ECHO
) " uavobjects_<group> - Generate source files from a subset of the UAVObject definition XML files"
801 @
$(ECHO
) " Supported groups are ($(UAVOBJ_TARGETS))"
803 @
$(ECHO
) " [Packaging]"
804 @
$(ECHO
) " package - Build and package the OpenPilot platform-dependent package (no clean)"
805 @
$(ECHO
) " opfw_resource - Generate resources to embed firmware binaries into the GCS"
806 @
$(ECHO
) " dist - Generate source archive for distribution"
807 @
$(ECHO
) " fw_dist - Generate archive of firmware"
808 @
$(ECHO
) " install - Install GCS to \"DESTDIR\" with prefix \"prefix\" (Linux only)"
810 @
$(ECHO
) " [Code Formatting]"
811 @
$(ECHO
) " uncrustify_<source> - Reformat <source> code according to the project's standards"
812 @
$(ECHO
) " Supported sources are ($(UNCRUSTIFY_TARGETS))"
813 @
$(ECHO
) " uncrustify_all - Reformat all source code"
815 @
$(ECHO
) " [Code Documentation]"
816 @
$(ECHO
) " docs_<source> - Generate HTML documentation for <source>"
817 @
$(ECHO
) " Supported sources are ($(DOCS_TARGETS))"
818 @
$(ECHO
) " docs_all - Generate HTML documentation for all"
819 @
$(ECHO
) " docs_<source>_clean - Delete generated documentation for <source>"
820 @
$(ECHO
) " docs_all_clean - Delete all generated documentation"
822 @
$(ECHO
) " [Configuration]"
823 @
$(ECHO
) " config_new - Place your make arguments in the config file"
824 @
$(ECHO
) " config_append - Place your make arguments in the config file but append"
825 @
$(ECHO
) " config_clean - Removes the config file"
827 @
$(ECHO
) " Hint: Add V=1 to your command line to see verbose build output."
829 @
$(ECHO
) " Notes: All tool distribution files will be downloaded into $(DL_DIR)"
830 @
$(ECHO
) " All tools will be installed into $(TOOLS_DIR)"
831 @
$(ECHO
) " All build output will be placed in $(BUILD_DIR)"
833 @
$(ECHO
) " Tool download and install directories can be changed using environment variables:"
834 @
$(ECHO
) " DL_DIR full path to downloads directory [downloads if not set]"
835 @
$(ECHO
) " TOOLS_DIR full path to installed tools directory [tools if not set]"
836 @
$(ECHO
) " More info: http://wiki.openpilot.org/display/Doc/OpenPilot+Build+System+Overview"