LP-399 Add groupbox for module Status
[librepilot.git] / Makefile
blobf2aac9ead2c84104fae271b686991fd296ba8e89
2 # Top level Makefile for the LibrePilot Project build system.
3 # Copyright (c) 2015-2017, 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 GCS_SYNTH_DIR := $(BUILD_DIR)/gcs-synthetics
55 DIRS := $(DL_DIR) $(TOOLS_DIR) $(BUILD_DIR) $(PACKAGE_DIR) $(DIST_DIR) $(GCS_SYNTH_DIR)
57 # Naming for binaries and packaging etc,.
58 export ORG_BIG_NAME := LibrePilot
59 GCS_LABEL := GCS
60 GCS_BIG_NAME := $(ORG_BIG_NAME) $(GCS_LABEL)
61 # These should be lowercase with no spaces
62 export ORG_SMALL_NAME := $(call smallify,$(ORG_BIG_NAME))
63 GCS_SMALL_NAME := $(call smallify,$(GCS_BIG_NAME))
65 WEBSITE_URL := http://librepilot.org
66 GIT_URL := https://bitbucket.org/librepilot/librepilot.git
67 GITWEB_URL := https://bitbucket.org/librepilot/librepilot
68 # Change this once the DNS is set to http://wiki.librepilot.org/
69 WIKI_URL_ROOT := https://librepilot.atlassian.net/wiki/display/LPDOC/
70 USAGETRACKER_URL := https://usagetracker.librepilot.org/
72 PACKAGING_EMAIL_ADDRESS := packaging@librepilot.org
74 define DESCRIPTION_SHORT :=
75 A ground control station and firmware for UAV flight controllers
76 endef
78 define DESCRIPTION_LONG :=
79 The LibrePilot open source project was founded in July 2015.
80 It focuses on research and development of software and hardware to be used in a variety of applications including vehicle control and stabilization, unmanned autonomous vehicles and robotics.
81 One of the project's primary goals is to provide an open and collaborative environment making it the ideal home for development of innovative ideas.
82 endef
85 # Clean out undesirable variables from the environment and command-line
86 # to remove the chance that they will cause problems with our build
87 define SANITIZE_VAR
88 $(if $(filter-out undefined,$(origin $(1))),
89 $(info $(EMPTY) NOTE Sanitized $(2) variable '$(1)' from $(origin $(1)))
90 MAKEOVERRIDES = $(filter-out $(1)=%,$(MAKEOVERRIDES))
91 override $(1) :=
92 unexport $(1)
94 endef
96 # These specific variables can influence compilation in unexpected (and undesirable) ways
97 # gcc flags
98 SANITIZE_GCC_VARS := TMPDIR GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH
99 # preprocessor flags
100 SANITIZE_GCC_VARS += CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH DEPENDENCIES_OUTPUT
101 # make flags
102 SANITIZE_GCC_VARS += CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LDLIBS
103 $(foreach var, $(SANITIZE_GCC_VARS), $(eval $(call SANITIZE_VAR,$(var),disallowed)))
105 # These specific variables used to be valid but now they make no sense
106 SANITIZE_DEPRECATED_VARS := USE_BOOTLOADER CLEAN_BUILD
107 $(foreach var, $(SANITIZE_DEPRECATED_VARS), $(eval $(call SANITIZE_VAR,$(var),deprecated)))
109 # Decide on a verbosity level based on the V= parameter
110 export AT := @
111 ifndef V
112 export V0 :=
113 export V1 := $(AT)
114 else ifeq ($(V), 0)
115 export V0 := $(AT)
116 export V1 := $(AT)
117 else ifeq ($(V), 1)
118 endif
120 ARCH := $(call get_arch)
122 # Include tools installers
123 include $(ROOT_DIR)/make/tools.mk
125 # Include third party builders if available
126 -include $(ROOT_DIR)/make/3rdparty/3rdparty.mk
128 # We almost need to consider autoconf/automake instead of this
129 ifeq ($(UNAME), Linux)
130 UAVOBJGENERATOR := $(BUILD_DIR)/uavobjgenerator/uavobjgenerator
131 GCS_WITH_OSG := 1
132 GCS_WITH_OSGEARTH := 1
133 GCS_COPY_OSG := 0
134 else ifeq ($(UNAME), Darwin)
135 UAVOBJGENERATOR := $(BUILD_DIR)/uavobjgenerator/uavobjgenerator
136 GCS_WITH_OSG := 1
137 GCS_WITH_OSGEARTH := 0
138 GCS_COPY_OSG := 1
139 else ifeq ($(UNAME), Windows)
140 UAVOBJGENERATOR := $(BUILD_DIR)/uavobjgenerator/uavobjgenerator.exe
141 GCS_WITH_OSG := 1
142 GCS_WITH_OSGEARTH := 1
143 GCS_COPY_OSG := 1
144 endif
146 export UAVOBJGENERATOR
148 # Set up default build configurations (debug | release)
149 GCS_BUILD_CONF := release
151 # Set extra configuration
152 ifeq ($(GCS_WITH_OSG), 1)
153 GCS_EXTRA_CONF += osg
154 ifeq ($(GCS_COPY_OSG), 1)
155 GCS_EXTRA_CONF += copy_osg
156 endif
157 ifeq ($(GCS_WITH_OSGEARTH), 1)
158 GCS_EXTRA_CONF += osgearth
159 endif
160 endif
162 ##############################
164 # All targets
166 ##############################
168 .PHONY: all
169 all: uavobjects all_ground all_flight
171 .PHONY: all_clean
172 all_clean:
173 @$(ECHO) " CLEAN $(call toprel, $(BUILD_DIR))"
174 $(V1) [ ! -d "$(BUILD_DIR)" ] || $(RM) -rf "$(BUILD_DIR)"
176 .PHONY: clean
177 clean: all_clean
180 ##############################
182 # UAVObjects
184 ##############################
186 UAVOBJGENERATOR_DIR := $(BUILD_DIR)/uavobjgenerator
187 DIRS += $(UAVOBJGENERATOR_DIR)
189 .PHONY: uavobjgenerator
190 uavobjgenerator: $(UAVOBJGENERATOR)
192 $(UAVOBJGENERATOR): | $(UAVOBJGENERATOR_DIR)
193 $(V1) cd $(UAVOBJGENERATOR_DIR) && \
194 ( [ -f Makefile ] || $(QMAKE) $(ROOT_DIR)/ground/uavobjgenerator/uavobjgenerator.pro \
195 CONFIG+='$(GCS_BUILD_CONF) $(GCS_EXTRA_CONF)' ) && \
196 $(MAKE) --no-print-directory -w
198 UAVOBJ_TARGETS := gcs flight arduino python matlab java wireshark
200 .PHONY: uavobjects
201 uavobjects: $(addprefix uavobjects_, $(UAVOBJ_TARGETS))
203 UAVOBJ_XML_DIR := $(ROOT_DIR)/shared/uavobjectdefinition
204 UAVOBJ_OUT_DIR := $(BUILD_DIR)/uavobject-synthetics
206 uavobjects_%: $(UAVOBJGENERATOR)
207 @$(MKDIR) -p $(UAVOBJ_OUT_DIR)/$*
208 $(V1) ( cd $(UAVOBJ_OUT_DIR)/$* && \
209 $(UAVOBJGENERATOR) -$* $(UAVOBJ_XML_DIR) $(ROOT_DIR) ; \
212 OBJECTCOUNT := $(shell find $(ROOT_DIR)/python/librepilot/uavobjects/ -name '*.py' | wc -l)
213 uavobjects_python_install:
214 $(V1) if [ $(OBJECTCOUNT) -gt 2 ]; then echo "UAVObjects already exist"; else make uavobjects_python; fi
215 $(V1) mkdir -p $(ROOT_DIR)/python/librepilot/uavobjects/
216 $(V1) ( touch $(ROOT_DIR)/python/librepilot/uavobjects/__init__.py )
217 $(V1) ( cp $(UAVOBJ_OUT_DIR)/python/* $(ROOT_DIR)/python/librepilot/uavobjects/ )
218 $(V1) ( cd $(ROOT_DIR)/python/ && sudo python setup.py build && sudo python setup.py install)
220 uavobjects_python_clean:
221 @$(ECHO) " CLEAN $(call toprel, $(ROOT_DIR)/python/librepilot/uavobjects/)"
222 $(V1) [ ! -d "$(ROOT_DIR)/python/librepilot/uavobjects/" ] || $(RM) -r "$(ROOT_DIR)/python/librepilot/uavobjects/"
223 @$(ECHO) " CLEAN $(call toprel, $(ROOT_DIR)/python/librepilot/build/)"
224 $(V1) [ ! -d "$(ROOT_DIR)/python/librepilot/build/" ] || sudo $(RM) -r "$(ROOT_DIR)/python/librepilot/build/"
225 @$(ECHO) " CLEAN $(call toprel, $(UAVOBJ_OUT_DIR)/python/)"
226 $(V1) [ ! -d "$(UAVOBJ_OUT_DIR)/python/" ] || $(RM) -r "$(UAVOBJ_OUT_DIR)/python/"
229 uavobjects_test: $(UAVOBJGENERATOR)
230 $(V1) $(UAVOBJGENERATOR) -v $(UAVOBJ_XML_DIR) $(ROOT_DIR)
232 uavobjects_clean:
233 @$(ECHO) " CLEAN $(call toprel, $(UAVOBJ_OUT_DIR))"
234 $(V1) [ ! -d "$(UAVOBJ_OUT_DIR)" ] || $(RM) -r "$(UAVOBJ_OUT_DIR)"
236 ##############################
238 # Flight related components
240 ##############################
243 # When building any of the "all_*" targets, tell all sub makefiles to display
244 # additional details on each line of output to describe which build and target
245 # that each line applies to. The same applies also to all, fw_resource,
246 # package targets
247 ifneq ($(strip $(filter all_% all fw_resource package,$(MAKECMDGOALS))),)
248 export ENABLE_MSG_EXTRA := yes
249 endif
251 # When building more than one goal in a single make invocation, also
252 # enable the extra context for each output line
253 ifneq ($(word 2,$(MAKECMDGOALS)),)
254 export ENABLE_MSG_EXTRA := yes
255 endif
257 FLIGHT_OUT_DIR := $(BUILD_DIR)/firmware
258 DIRS += $(FLIGHT_OUT_DIR)
260 # Might not be here in source package
261 -include $(ROOT_DIR)/flight/Makefile
263 ##############################
265 # GCS related components
267 ##############################
269 .PHONY: all_ground
270 all_ground: gcs uploader
272 ifneq ($(V), 1)
273 GCS_EXTRA_CONF += silent
274 endif
276 GCS_DIR := $(BUILD_DIR)/$(GCS_SMALL_NAME)_$(GCS_BUILD_CONF)
277 DIRS += $(GCS_DIR)
279 GCS_MAKEFILE := $(GCS_DIR)/Makefile
281 .PHONY: gcs_qmake
282 gcs_qmake $(GCS_MAKEFILE): | $(GCS_DIR)
283 $(V1) cd $(GCS_DIR) && \
284 $(QMAKE) $(ROOT_DIR)/ground/gcs/gcs.pro \
285 -r CONFIG+='$(GCS_BUILD_CONF) $(GCS_EXTRA_CONF)' \
286 'GCS_BIG_NAME="$(GCS_BIG_NAME)"' GCS_SMALL_NAME=$(GCS_SMALL_NAME) \
287 'ORG_BIG_NAME="$(ORG_BIG_NAME)"' ORG_SMALL_NAME=$(ORG_SMALL_NAME) \
288 'WIKI_URL_ROOT="$(WIKI_URL_ROOT)"' \
289 'USAGETRACKER_URL="$(USAGETRACKER_URL)"' \
290 'GCS_LIBRARY_BASENAME=$(libbasename)' \
291 $(GCS_QMAKE_OPTS)
293 .PHONY: gcs
294 gcs: $(UAVOBJGENERATOR) $(GCS_MAKEFILE)
295 $(V1) $(MAKE) -w -C $(GCS_DIR)/$(MAKE_DIR);
297 .PHONY: gcs_clean
298 gcs_clean:
299 @$(ECHO) " CLEAN $(call toprel, $(GCS_DIR))"
300 $(V1) [ ! -d "$(GCS_DIR)" ] || $(RM) -r "$(GCS_DIR)"
304 ################################
306 # Serial Uploader tool
308 ################################
310 UPLOADER_DIR := $(BUILD_DIR)/uploader_$(GCS_BUILD_CONF)
311 DIRS += $(UPLOADER_DIR)
313 UPLOADER_MAKEFILE := $(UPLOADER_DIR)/Makefile
315 .PHONY: uploader_qmake
316 uploader_qmake $(UPLOADER_MAKEFILE): | $(UPLOADER_DIR)
317 $(V1) cd $(UPLOADER_DIR) && \
318 $(QMAKE) $(ROOT_DIR)/ground/gcs/src/experimental/USB_UPLOAD_TOOL/upload.pro \
319 -r CONFIG+='$(GCS_BUILD_CONF) $(GCS_EXTRA_CONF)' $(GCS_QMAKE_OPTS)
321 .PHONY: uploader
322 uploader: $(UPLOADER_MAKEFILE)
323 $(V1) $(MAKE) -w -C $(UPLOADER_DIR)
325 .PHONY: uploader_clean
326 uploader_clean:
327 @$(ECHO) " CLEAN $(call toprel, $(UPLOADER_DIR))"
328 $(V1) [ ! -d "$(UPLOADER_DIR)" ] || $(RM) -r "$(UPLOADER_DIR)"
332 ##############################
334 # Packaging components
336 ##############################
337 # Firmware files to package
338 PACKAGE_FW_TARGETS := fw_coptercontrol fw_revolution fw_revonano fw_sparky2
339 PACKAGE_FW_TARGETS += fw_oplinkmini
340 PACKAGE_FW_TARGETS += fw_gpsplatinum
341 PACKAGE_FW_TARGETS += fw_osd
342 PACKAGE_FW_TARGETS += fw_revoproto
343 PACKAGE_FW_TARGETS += fw_spracingf3evo fw_spracingf3 fw_nucleof303re fw_pikoblx fw_tinyfish
345 # Rules to generate GCS resources used to embed firmware binaries into the GCS.
346 # They are used later by the vehicle setup wizard to update board firmware.
347 # To open a firmware image use ":/firmware/fw_coptercontrol.opfw"
348 FW_RESOURCE := $(GCS_SYNTH_DIR)/fw_resource.qrc
350 ifeq ($(WITH_PREBUILT_FW),)
351 FIRMWARE_DIR := $(FLIGHT_OUT_DIR)
352 # We need to build the FW targets
353 $(FW_RESOURCE): $(PACKAGE_FW_TARGETS)
354 else
355 FIRMWARE_DIR := $(WITH_PREBUILT_FW)
356 endif
358 FW_FILES := $(foreach fw_targ, $(PACKAGE_FW_TARGETS), $(FIRMWARE_DIR)/$(fw_targ)/$(fw_targ).opfw)
359 FW_CONTENTS := \
360 <!DOCTYPE RCC><RCC version="1.0"> \
361 <qresource prefix="/firmware"> \
362 $(foreach fw_file, $(FW_FILES), <file alias="$(notdir $(fw_file))">$(call system_path,$(fw_file))</file>) \
363 </qresource> \
364 </RCC>
366 .PHONY: fw_resource
367 fw_resource: $(FW_RESOURCE)
368 fw_resource: $(FW_RESOURCE)
370 $(FW_RESOURCE): | $(GCS_SYNTH_DIR)
371 @$(ECHO) Generating FW resource file $(call toprel, $@)
372 $(V1) $(ECHO) $(QUOTE)$(FW_CONTENTS)$(QUOTE) > $@
374 # If fw_resource or all firmware are requested, GCS should depend on the resource
375 ifneq ($(strip $(filter fw_resource all all_fw all_flight package,$(MAKECMDGOALS))),)
376 $(GCS_MAKEFILE): $(FW_RESOURCE)
377 endif
379 # Packaging targets: package
380 # - builds all firmware, fw_resource, gcs
381 # - copies firmware into a package directory
382 # - calls paltform-specific packaging script
384 # Define some variables
385 PACKAGE_LBL := $(shell $(VERSION_INFO) --format=\$${LABEL})
386 PACKAGE_NAME := $(subst $(SPACE),,$(ORG_BIG_NAME))
387 PACKAGE_SEP := -
388 PACKAGE_FULL_NAME := $(PACKAGE_NAME)$(PACKAGE_SEP)$(PACKAGE_LBL)
390 # Source distribution is never dirty because it uses git archive
391 DIST_LBL := $(subst -dirty,,$(PACKAGE_LBL))
392 DIST_NAME := $(PACKAGE_NAME)$(PACKAGE_SEP)$(DIST_LBL)
393 DIST_TAR := $(DIST_DIR)/$(DIST_NAME).tar
394 DIST_TAR_GZ := $(DIST_TAR).gz
395 FW_DIST_NAME := $(DIST_NAME)_firmware
396 FW_DIST_TAR := $(DIST_DIR)/$(FW_DIST_NAME).tar
397 FW_DIST_TAR_GZ := $(FW_DIST_TAR).gz
398 DIST_VER_INFO := $(DIST_DIR)/version-info.json
400 include $(ROOT_DIR)/package/$(UNAME).mk
402 ##############################
404 # Source for distribution
406 ##############################
407 FORCE:
409 $(DIST_VER_INFO): FORCE | $(DIST_DIR)
410 $(V1) $(VERSION_INFO) --jsonpath="$(DIST_DIR)"
412 $(DIST_TAR): $(DIST_VER_INFO) | $(DIST_DIR)
413 @$(ECHO) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR))"
414 $(V1) git archive --prefix="$(PACKAGE_NAME)/" -o "$(DIST_TAR)" HEAD
415 $(V1) tar --append --file="$(DIST_TAR)" \
416 --owner=root --group=root --mtime="`git show -s --format=%ci`" \
417 --transform='s,.*version-info.json,$(PACKAGE_NAME)/version-info.json,' \
418 $(call toprel, "$(DIST_VER_INFO)")
420 $(DIST_TAR_GZ): $(DIST_TAR)
421 @$(ECHO) " SOURCE FOR DISTRIBUTION $(call toprel, $(DIST_TAR_GZ))"
422 $(V1) gzip -knf "$(DIST_TAR)"
424 .PHONY: dist_tar_gz
425 dist_tar_gz: $(DIST_TAR_GZ)
427 .PHONY: dist
428 dist: dist_tar_gz
431 $(FW_DIST_TAR): $(PACKAGE_FW_TARGETS) | $(DIST_DIR)
432 @$(ECHO) " FIRMWARE FOR DISTRIBUTION $(call toprel, $(FW_DIST_TAR))"
433 $(V1) tar -c --file="$(FW_DIST_TAR)" --directory=$(FLIGHT_OUT_DIR) \
434 --owner=root --group=root --mtime="`git show -s --format=%ci`" \
435 --transform='s,^,firmware/,' \
436 --force-local \
437 $(foreach fw_targ,$(PACKAGE_FW_TARGETS),$(fw_targ)/$(fw_targ).opfw)
439 $(FW_DIST_TAR_GZ): $(FW_DIST_TAR)
440 @$(ECHO) " FIRMWARE FOR DISTRIBUTION $(call toprel, $(FW_DIST_TAR_GZ))"
441 $(V1) gzip -knf "$(FW_DIST_TAR)"
443 .PHONY: fw_dist_tar_gz
444 fw_dist_tar_gz: $(FW_DIST_TAR_GZ)
446 .PHONY: fw_dist
447 fw_dist: fw_dist_tar_gz
450 ##############################
452 # Source code formatting
454 ##############################
456 UNCRUSTIFY_TARGETS := flight ground
458 # $(1) = Uncrustify target (e.g flight or ground)
459 # $(2) = Target root directory
460 define UNCRUSTIFY_TEMPLATE
462 .PHONY: uncrustify_$(1)
463 uncrustify_$(1):
464 @$(ECHO) "Auto-formatting $(1) source code"
465 $(V1) UNCRUSTIFY_CONFIG="$(ROOT_DIR)/make/uncrustify/uncrustify.cfg" $(SHELL) make/scripts/uncrustify.sh $(call toprel, $(2))
467 .PHONY: pretty_$(1)
468 pretty_$(1): uncrustify_$(1)
469 endef
471 $(foreach uncrustify_targ, $(UNCRUSTIFY_TARGETS), $(eval $(call UNCRUSTIFY_TEMPLATE,$(uncrustify_targ),$(ROOT_DIR)/$(uncrustify_targ))))
473 .PHONY: uncrustify_all
474 uncrustify_all: $(addprefix uncrustify_,$(UNCRUSTIFY_TARGETS))
476 .PHONY: pretty
477 pretty: $(addprefix pretty_,$(UNCRUSTIFY_TARGETS))
479 ##############################
481 # Doxygen documentation
483 # Each target should have own Doxyfile.$(target) with build directory build/docs/$(target),
484 # proper source directory (e.g. $(target)) and appropriate other doxygen options.
486 ##############################
488 DOCS_TARGETS := flight ground uavobjects
490 # $(1) = Doxygen target (e.g flight or ground)
491 define DOXYGEN_TEMPLATE
493 .PHONY: docs_$(1)
494 docs_$(1): docs_$(1)_clean
495 @$(ECHO) "Generating $(1) documentation"
496 $(V1) $(MKDIR) -p $(BUILD_DIR)/docs/$(1)
497 $(V1) $(DOXYGEN) $(ROOT_DIR)/make/doxygen/Doxyfile.$(1)
499 .PHONY: docs_$(1)_clean
500 docs_$(1)_clean:
501 @$(ECHO) " CLEAN $(call toprel, $(BUILD_DIR)/docs/$(1))"
502 $(V1) [ ! -d "$(BUILD_DIR)/docs/$(1)" ] || $(RM) -r "$(BUILD_DIR)/docs/$(1)"
504 endef
506 $(foreach docs_targ, $(DOCS_TARGETS), $(eval $(call DOXYGEN_TEMPLATE,$(docs_targ))))
508 .PHONY: docs_all
509 docs_all: $(addprefix docs_,$(DOCS_TARGETS))
511 .PHONY: docs_all_clean
512 docs_all_clean:
513 @$(ECHO) " CLEAN $(call toprel, $(BUILD_DIR)/docs)"
514 $(V1) [ ! -d "$(BUILD_DIR)/docs" ] || $(RM) -rf "$(BUILD_DIR)/docs"
516 ##############################
518 # Build info
520 ##############################
522 .PHONY: build-info
523 build-info: | $(BUILD_DIR)
524 @$(ECHO) " BUILD-INFO $(call toprel, $(BUILD_DIR)/$@.txt)"
525 $(V1) $(VERSION_INFO) \
526 --uavodir=$(ROOT_DIR)/shared/uavobjectdefinition \
527 --template="make/templates/$@.txt" \
528 --outfile="$(BUILD_DIR)/$@.txt"
530 ##############################
532 # Config
534 ##############################
536 CONFIG_OPTS := $(subst \$(SPACE),%SPACE_PLACEHOLDER%,$(MAKEOVERRIDES))
537 CONFIG_OPTS := $(addprefix override%SPACE_PLACEHOLDER%,$(CONFIG_OPTS))
538 CONFIG_OPTS := $(subst $(SPACE),\n,$(CONFIG_OPTS))\n
539 CONFIG_OPTS := $(subst %SPACE_PLACEHOLDER%,$(SPACE),$(CONFIG_OPTS))
541 .PHONY: config_new
542 config_new:
543 @printf '$(CONFIG_OPTS)' > $(CONFIG_FILE)
545 .PHONY: config_append
546 config_append:
547 @printf '$(CONFIG_OPTS)' >> $(CONFIG_FILE)
549 .PHONY: config_show
550 config_show:
551 @cat $(CONFIG_FILE) | sed 's/override *//'
553 .PHONY: config_clean
554 config_clean:
555 rm -f $(CONFIG_FILE)
557 .PHONY: config_help
558 config_help:
559 @$(ECHO) " The build system has a simple system for persistent configuration"
560 @$(ECHO)
561 @$(ECHO) " To set persistent configuration variables you, for example, do:"
562 @$(ECHO) " $(MAKE) config_new CCACHE=ccache GCS_WITH_OSG=0"
563 @$(ECHO)
564 @$(ECHO) " To add to the existing configuration do:"
565 @$(ECHO) " $(MAKE) config_append GCS_BUILD_CONF=debug"
566 @$(ECHO)
567 @$(ECHO) " To reset the configuration to defaults do:"
568 @$(ECHO) " $(MAKE) config_clean"
569 @$(ECHO)
570 @$(ECHO) " To show the current configuration:"
571 @$(ECHO) " $(MAKE) config_show"
572 @$(ECHO)
573 @$(ECHO) " You can override any make variable this way, but these are the useful ones"
574 @$(ECHO) " shown with their current (or default values):"
575 @$(ECHO)
576 @$(ECHO) " GCS_BUILD_CONF=$(GCS_BUILD_CONF)"
577 @$(ECHO) " GCS build type"
578 @$(ECHO) " Options: debug or release"
579 @$(ECHO)
580 @$(ECHO) " GCS_WITH_OSG=$(GCS_WITH_OSG)"
581 @$(ECHO) " Build the GCS with OpenSceneGraph support, this enables the PFD Model View"
582 @$(ECHO) " Options: 0 or 1"
583 @$(ECHO)
584 @$(ECHO) " GCS_WITH_OSGEARTH=$(GCS_WITH_OSGEARTH)"
585 @$(ECHO) " Build the GCS with osgEarth support, this enables extra PFD terrain views"
586 @$(ECHO) " Options: 0 or 1"
587 @$(ECHO)
588 @$(ECHO) " GCS_COPY_OSG=$(GCS_COPY_OSG)"
589 @$(ECHO) " Copy OpenSceneGraph/osgEarth libraries into the build"
590 @$(ECHO) " (Needed unless using system versions)"
591 @$(ECHO) " Options: 0 or 1"
592 @$(ECHO)
593 @$(ECHO) " CCACHE=$(CCACHE)"
594 @$(ECHO) " A prefix to compiler invocations, usually 'ccache' or 'path/to/ccache'"
595 @$(ECHO)
596 @$(ECHO) " QMAKE=$(QMAKE)"
597 @$(ECHO) " How to invoke qmake, usually 'qmake', 'qmake-qt5' or 'path/to/qmake'"
598 @$(ECHO)
599 @$(ECHO) " WITH_PREBUILT_FIRMWARE=$(WITH_PREBUILT_FIRMWARE)"
600 @$(ECHO) " Set to path of prebuilt firmware or empty to build firmware when needed"
601 # TODO: add other things like downloads and tools directories, linux make install parameters
605 ##############################
607 # Directories
609 ##############################
611 $(DIRS):
612 $(V1) $(MKDIR) -p $@
615 ##############################
617 # Help message, the default Makefile goal
619 ##############################
621 .DEFAULT_GOAL := help
623 .PHONY: help
624 help:
625 @$(ECHO)
626 @$(ECHO) " This Makefile is known to work on Linux and Mac in a standard shell environment."
627 @$(ECHO) " It also works on Windows by following the instructions given on this wiki page:"
628 @$(ECHO) " $(WIKI_URL_ROOT)Windows+Building+and+Packaging"
629 @$(ECHO)
630 @$(ECHO) " Here is a summary of the available targets:"
631 @$(ECHO)
632 @$(ECHO) " [Source tree preparation]"
633 @$(ECHO) " prepare - Install GIT commit message template"
634 @$(ECHO) " [Tool Installers]"
635 @$(ECHO) " arm_sdk_install - Install the GNU ARM gcc toolchain"
636 @$(ECHO) " qt_sdk_install - Install the QT development tools"
637 @$(ECHO) " nsis_install - Install the NSIS Unicode (Windows only)"
638 @$(ECHO) " mesawin_install - Install the OpenGL32 DLL (Windows only)"
639 @$(ECHO) " uncrustify_install - Install the Uncrustify source code beautifier"
640 @$(ECHO) " doxygen_install - Install the Doxygen documentation generator"
641 @$(ECHO) " gtest_install - Install the GoogleTest framework"
642 @$(ECHO) " ccache_install - Install ccache"
643 @$(ECHO) " These targets are not updated yet and are probably broken:"
644 @$(ECHO) " openocd_install - Install the OpenOCD JTAG daemon"
645 @$(ECHO) " stm32flash_install - Install the stm32flash tool for unbricking F1-based boards"
646 @$(ECHO) " dfuutil_install - Install the dfu-util tool for unbricking F4-based boards"
647 @$(ECHO) " Install all available tools:"
648 @$(ECHO) " all_sdk_install - Install all of above (platform-dependent)"
649 @$(ECHO) " build_sdk_install - Install only essential for build tools (platform-dependent)"
650 @$(ECHO)
651 @$(ECHO) " Other tool options are:"
652 @$(ECHO) " <tool>_version - Display <tool> version"
653 @$(ECHO) " <tool>_clean - Remove installed <tool>"
654 @$(ECHO) " <tool>_distclean - Remove downloaded <tool> distribution file(s)"
655 @$(ECHO)
656 @$(ECHO) " [Big Hammer]"
657 @$(ECHO) " all - Generate UAVObjects, build $(ORG_BIG_NAME) firmware and gcs"
658 @$(ECHO) " all_flight - Build all firmware, bootloaders and bootloader updaters"
659 @$(ECHO) " all_fw - Build only firmware for all boards"
660 @$(ECHO) " all_bl - Build only bootloaders for all boards"
661 @$(ECHO) " all_bu - Build only bootloader updaters for all boards"
662 @$(ECHO)
663 @$(ECHO) " all_clean - Remove your build directory ($(BUILD_DIR))"
664 @$(ECHO) " all_flight_clean - Remove all firmware, bootloaders and bootloader updaters"
665 @$(ECHO) " all_fw_clean - Remove firmware for all boards"
666 @$(ECHO) " all_bl_clean - Remove bootloaders for all boards"
667 @$(ECHO) " all_bu_clean - Remove bootloader updaters for all boards"
668 @$(ECHO)
669 @$(ECHO) " all_<board> - Build all available images for <board>"
670 @$(ECHO) " all_<board>_clean - Remove all available images for <board>"
671 @$(ECHO)
672 @$(ECHO) " all_ut - Build all unit tests"
673 @$(ECHO) " all_ut_tap - Run all unit tests and capture all TAP output to files"
674 @$(ECHO) " all_ut_run - Run all unit tests and dump TAP output to console"
675 @$(ECHO)
676 @$(ECHO) " [Firmware]"
677 @$(ECHO) " <board> - Build firmware for <board>"
678 @$(ECHO) " Supported boards are ($(ALL_BOARDS))"
679 @$(ECHO) " fw_<board> - Build firmware for <board>"
680 @$(ECHO) " Supported boards are ($(FW_BOARDS))"
681 @$(ECHO) " fw_<board>_clean - Remove firmware for <board>"
682 @$(ECHO) " fw_<board>_program - Use OpenOCD + JTAG to write firmware to <board>"
683 @$(ECHO)
684 @$(ECHO) " [Bootloader]"
685 @$(ECHO) " bl_<board> - Build bootloader for <board>"
686 @$(ECHO) " Supported boards are ($(BL_BOARDS))"
687 @$(ECHO) " bl_<board>_clean - Remove bootloader for <board>"
688 @$(ECHO) " bl_<board>_program - Use OpenOCD + JTAG to write bootloader to <board>"
689 @$(ECHO)
690 @$(ECHO) " [Entire Flash]"
691 @$(ECHO) " ef_<board> - Build entire flash image for <board>"
692 @$(ECHO) " Supported boards are ($(EF_BOARDS))"
693 @$(ECHO) " ef_<board>_clean - Remove entire flash image for <board>"
694 @$(ECHO) " ef_<board>_program - Use OpenOCD + JTAG to write entire flash image to <board>"
695 @$(ECHO)
696 @$(ECHO) " [Bootloader Updater]"
697 @$(ECHO) " bu_<board> - Build bootloader updater for <board>"
698 @$(ECHO) " Supported boards are ($(BU_BOARDS))"
699 @$(ECHO) " bu_<board>_clean - Remove bootloader updater for <board>"
700 @$(ECHO)
701 @$(ECHO) " [Unbrick a board]"
702 @$(ECHO) " unbrick_<board> - Use the STM32's built in boot ROM to write a bootloader to <board>"
703 @$(ECHO) " Supported boards are ($(BL_BOARDS))"
704 @$(ECHO) " [Unittests]"
705 @$(ECHO) " ut_<test> - Build unit test <test>"
706 @$(ECHO) " ut_<test>_xml - Run test and capture XML output into a file"
707 @$(ECHO) " ut_<test>_run - Run test and dump output to console"
708 @$(ECHO)
709 @$(ECHO) " [Simulation]"
710 @$(ECHO) " sim_osx - Build $(ORG_BIG_NAME) simulation firmware for OSX"
711 @$(ECHO) " sim_osx_clean - Delete all build output for the osx simulation"
712 @$(ECHO) " sim_win32 - Build $(ORG_BIG_NAME) simulation firmware for Windows"
713 @$(ECHO) " using mingw and msys"
714 @$(ECHO) " sim_win32_clean - Delete all build output for the win32 simulation"
715 @$(ECHO)
716 @$(ECHO) " [GCS]"
717 @$(ECHO) " gcs - Build the Ground Control System (GCS) application (debug|release)"
718 @$(ECHO) " Compile specific directory: MAKE_DIR=<dir>"
719 @$(ECHO) " Example: make gcs MAKE_DIR=src/plugins/coreplugin"
720 @$(ECHO) " gcs_qmake - Run qmake for the Ground Control System (GCS) application (debug|release)"
721 @$(ECHO) " gcs_clean - Remove the Ground Control System (GCS) application (debug|release)"
722 @$(ECHO) " Supported build configurations: GCS_BUILD_CONF=debug|release (default is $(GCS_BUILD_CONF))"
723 @$(ECHO)
724 @$(ECHO) " [Uploader Tool]"
725 @$(ECHO) " uploader - Build the serial uploader tool (debug|release)"
726 @$(ECHO) " uploader_qmake - Run qmake for the serial uploader tool (debug|release)"
727 @$(ECHO) " uploader_clean - Remove the serial uploader tool (debug|release)"
728 @$(ECHO) " Supported build configurations: GCS_BUILD_CONF=debug|release (default is $(GCS_BUILD_CONF))"
729 @$(ECHO)
730 @$(ECHO)
731 @$(ECHO) " [UAVObjects]"
732 @$(ECHO) " uavobjects - Generate source files from the UAVObject definition XML files"
733 @$(ECHO) " uavobjects_test - Parse xml-files - check for valid, duplicate ObjId's, ..."
734 @$(ECHO) " uavobjects_<group> - Generate source files from a subset of the UAVObject definition XML files"
735 @$(ECHO) " Supported groups are ($(UAVOBJ_TARGETS))"
736 @$(ECHO) " uavobjects_python_install"
737 @$(ECHO) " - Install generated python files as eggs for use with example Python scripts"
738 @$(ECHO) " uavobjects_python_clean"
739 @$(ECHO) " - Remove generated python UAVOs from build directory & pyuavtalk folder"
740 @$(ECHO)
741 @$(ECHO) " [Packaging]"
742 @$(ECHO) " package - Build and package the platform-dependent package (no clean)"
743 @$(ECHO) " fw_resource - Generate resources to embed firmware binaries into the GCS"
744 @$(ECHO) " dist - Generate source archive for distribution"
745 @$(ECHO) " fw_dist - Generate archive of firmware"
746 @$(ECHO) " install - Install GCS to \"DESTDIR\" with prefix \"prefix\" (Linux only)"
747 @$(ECHO)
748 @$(ECHO) " [Code Formatting]"
749 @$(ECHO) " pretty_<source> - Reformat <source> code according to the project's standards"
750 @$(ECHO) " Supported sources are ($(UNCRUSTIFY_TARGETS))"
751 @$(ECHO) " pretty - Reformat all source code"
752 @$(ECHO)
753 @$(ECHO) " [Code Documentation]"
754 @$(ECHO) " docs_<source> - Generate HTML documentation for <source>"
755 @$(ECHO) " Supported sources are ($(DOCS_TARGETS))"
756 @$(ECHO) " docs_all - Generate HTML documentation for all"
757 @$(ECHO) " docs_<source>_clean - Delete generated documentation for <source>"
758 @$(ECHO) " docs_all_clean - Delete all generated documentation"
759 @$(ECHO)
760 @$(ECHO) " [Configuration]"
761 @$(ECHO) " config_help - Show information on how to configure the build"
762 @$(ECHO) " config_new - Place your make arguments in the config file"
763 @$(ECHO) " config_append - Place your make arguments in the config file but append"
764 @$(ECHO) " config_clean - Removes the config file"
765 @$(ECHO)
766 @$(ECHO) " Hint: Add V=1 to your command line to see verbose build output."
767 @$(ECHO)
768 @$(ECHO) " Notes: All tool distribution files will be downloaded into $(DL_DIR)"
769 @$(ECHO) " All tools will be installed into $(TOOLS_DIR)"
770 @$(ECHO) " All build output will be placed in $(BUILD_DIR)"
771 @$(ECHO)
772 @$(ECHO) " Tool download and install directories can be changed using environment variables:"
773 @$(ECHO) " DL_DIR full path to downloads directory [downloads if not set]"
774 @$(ECHO) " TOOLS_DIR full path to installed tools directory [tools if not set]"
775 @$(ECHO) " More info: $(WIKI_URL_ROOT)LibrePilot+Build+System+Overview"
776 @$(ECHO)