2013-02-23 20:05:59 -04:00
|
|
|
#
|
2013-05-05 06:35:56 -03:00
|
|
|
# Copyright (c) 2012, 2013 PX4 Development Team. All rights reserved.
|
2013-02-23 20:05:59 -04:00
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in
|
|
|
|
# the documentation and/or other materials provided with the
|
|
|
|
# distribution.
|
|
|
|
# 3. Neither the name PX4 nor the names of its contributors may be
|
|
|
|
# used to endorse or promote products derived from this software
|
|
|
|
# without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
|
|
|
# Top-level Makefile for building PX4 firmware images.
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-02-21 01:12:59 -04:00
|
|
|
# Get path and tool configuration
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-02-23 16:23:34 -04:00
|
|
|
export PX4_BASE := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/
|
|
|
|
include $(PX4_BASE)makefiles/setup.mk
|
2013-01-16 22:23:49 -04:00
|
|
|
|
2013-09-06 14:18:08 -03:00
|
|
|
#
|
|
|
|
# Get a version string provided by git
|
|
|
|
# This assumes that git command is available and that
|
|
|
|
# the directory holding this file also contains .git directory
|
|
|
|
#
|
|
|
|
GIT_DESC := $(shell git log -1 --pretty=format:%H)
|
|
|
|
ifneq ($(words $(GIT_DESC)),1)
|
|
|
|
GIT_DESC := "unknown_git_version"
|
|
|
|
endif
|
|
|
|
export GIT_DESC
|
|
|
|
|
2013-01-16 22:23:49 -04:00
|
|
|
#
|
2013-08-26 02:26:47 -03:00
|
|
|
# Canned firmware configurations that we (know how to) build.
|
2013-01-16 22:23:49 -04:00
|
|
|
#
|
2013-08-26 02:26:47 -03:00
|
|
|
KNOWN_CONFIGS := $(subst config_,,$(basename $(notdir $(wildcard $(PX4_MK_DIR)config_*.mk))))
|
|
|
|
CONFIGS ?= $(KNOWN_CONFIGS)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-01-17 02:38:47 -04:00
|
|
|
#
|
2013-08-26 02:26:47 -03:00
|
|
|
# Boards that we (know how to) build NuttX export kits for.
|
2013-01-17 02:38:47 -04:00
|
|
|
#
|
2013-08-26 02:26:47 -03:00
|
|
|
KNOWN_BOARDS := $(subst board_,,$(basename $(notdir $(wildcard $(PX4_MK_DIR)board_*.mk))))
|
|
|
|
BOARDS ?= $(KNOWN_BOARDS)
|
2013-01-17 02:38:47 -04:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-02-21 01:25:04 -04:00
|
|
|
# Debugging
|
|
|
|
#
|
|
|
|
MQUIET = --no-print-directory
|
|
|
|
#MQUIET = --print-directory
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# No user-serviceable parts below
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
#
|
|
|
|
# If the user has listed a config as a target, strip it out and override CONFIGS.
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-04-26 20:14:32 -03:00
|
|
|
FIRMWARE_GOAL = firmware
|
2013-01-16 22:23:49 -04:00
|
|
|
EXPLICIT_CONFIGS := $(filter $(CONFIGS),$(MAKECMDGOALS))
|
|
|
|
ifneq ($(EXPLICIT_CONFIGS),)
|
|
|
|
CONFIGS := $(EXPLICIT_CONFIGS)
|
|
|
|
.PHONY: $(EXPLICIT_CONFIGS)
|
|
|
|
$(EXPLICIT_CONFIGS): all
|
2013-04-26 20:14:32 -03:00
|
|
|
|
|
|
|
#
|
|
|
|
# If the user has asked to upload, they must have also specified exactly one
|
|
|
|
# config.
|
|
|
|
#
|
|
|
|
ifneq ($(filter upload,$(MAKECMDGOALS)),)
|
|
|
|
ifneq ($(words $(EXPLICIT_CONFIGS)),1)
|
|
|
|
$(error In order to upload, exactly one board config must be specified)
|
|
|
|
endif
|
|
|
|
FIRMWARE_GOAL = upload
|
|
|
|
.PHONY: upload
|
|
|
|
upload:
|
|
|
|
@:
|
|
|
|
endif
|
2013-01-11 06:14:43 -04:00
|
|
|
endif
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-01-16 22:23:49 -04:00
|
|
|
#
|
|
|
|
# Built products
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-08-26 02:26:47 -03:00
|
|
|
DESIRED_FIRMWARES = $(foreach config,$(CONFIGS),$(IMAGE_DIR)$(config).px4)
|
|
|
|
STAGED_FIRMWARES = $(foreach config,$(KNOWN_CONFIGS),$(IMAGE_DIR)$(config).px4)
|
|
|
|
FIRMWARES = $(foreach config,$(KNOWN_CONFIGS),$(BUILD_DIR)$(config).build/firmware.px4)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2014-07-07 12:18:54 -03:00
|
|
|
all: checksubmodules $(DESIRED_FIRMWARES)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
#
|
2013-01-17 01:03:27 -04:00
|
|
|
# Copy FIRMWARES into the image directory.
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-05-17 05:55:02 -03:00
|
|
|
# XXX copying the .bin files is a hack to work around the PX4IO uploader
|
|
|
|
# not supporting .px4 files, and it should be deprecated onced that
|
|
|
|
# is taken care of.
|
|
|
|
#
|
2013-02-23 16:23:34 -04:00
|
|
|
$(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4
|
2013-07-07 21:53:55 -03:00
|
|
|
@$(ECHO) %% Copying $@
|
2013-01-17 01:03:27 -04:00
|
|
|
$(Q) $(COPY) $< $@
|
2013-05-17 05:55:02 -03:00
|
|
|
$(Q) $(COPY) $(patsubst %.px4,%.bin,$<) $(patsubst %.px4,%.bin,$@)
|
2013-01-03 02:13:30 -04:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-17 02:38:47 -04:00
|
|
|
# Generate FIRMWARES.
|
2013-01-16 22:23:49 -04:00
|
|
|
#
|
2013-01-17 02:44:27 -04:00
|
|
|
.PHONY: $(FIRMWARES)
|
2013-02-23 16:23:34 -04:00
|
|
|
$(BUILD_DIR)%.build/firmware.px4: config = $(patsubst $(BUILD_DIR)%.build/firmware.px4,%,$@)
|
|
|
|
$(BUILD_DIR)%.build/firmware.px4: work_dir = $(BUILD_DIR)$(config).build/
|
|
|
|
$(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4:
|
2013-07-07 21:53:55 -03:00
|
|
|
@$(ECHO) %%%%
|
|
|
|
@$(ECHO) %%%% Building $(config) in $(work_dir)
|
|
|
|
@$(ECHO) %%%%
|
2013-08-23 03:47:55 -03:00
|
|
|
$(Q) $(MKDIR) -p $(work_dir)
|
|
|
|
$(Q) $(MAKE) -r -C $(work_dir) \
|
2013-02-23 16:23:34 -04:00
|
|
|
-f $(PX4_MK_DIR)firmware.mk \
|
2013-02-23 03:27:24 -04:00
|
|
|
CONFIG=$(config) \
|
2013-02-21 01:12:59 -04:00
|
|
|
WORK_DIR=$(work_dir) \
|
2013-04-26 20:14:32 -03:00
|
|
|
$(FIRMWARE_GOAL)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-08-23 04:23:32 -03:00
|
|
|
#
|
2013-08-26 02:26:47 -03:00
|
|
|
# Make FMU firmwares depend on the corresponding IO firmware.
|
2013-08-23 04:23:32 -03:00
|
|
|
#
|
|
|
|
# This is a pretty vile hack, since it hard-codes knowledge of the FMU->IO dependency
|
|
|
|
# and forces the _default config in all cases. There has to be a better way to do this...
|
|
|
|
#
|
|
|
|
FMU_VERSION = $(patsubst px4fmu-%,%,$(word 1, $(subst _, ,$(1))))
|
|
|
|
define FMU_DEP
|
|
|
|
$(BUILD_DIR)$(1).build/firmware.px4: $(IMAGE_DIR)px4io-$(call FMU_VERSION,$(1))_default.px4
|
|
|
|
endef
|
|
|
|
FMU_CONFIGS := $(filter px4fmu%,$(CONFIGS))
|
|
|
|
$(foreach config,$(FMU_CONFIGS),$(eval $(call FMU_DEP,$(config))))
|
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
# Build the NuttX export archives.
|
|
|
|
#
|
|
|
|
# Note that there are no explicit dependencies extended from these
|
|
|
|
# archives. If NuttX is updated, the user is expected to rebuild the
|
2013-01-17 01:03:27 -04:00
|
|
|
# archives/build area manually. Likewise, when the 'archives' target is
|
|
|
|
# invoked, all archives are always rebuilt.
|
2013-01-16 22:23:49 -04:00
|
|
|
#
|
|
|
|
# XXX Should support fetching/unpacking from a separate directory to permit
|
|
|
|
# downloads of the prebuilt archives as well...
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
2013-02-23 16:23:34 -04:00
|
|
|
NUTTX_ARCHIVES = $(foreach board,$(BOARDS),$(ARCHIVE_DIR)$(board).export)
|
2013-01-16 22:23:49 -04:00
|
|
|
.PHONY: archives
|
|
|
|
archives: $(NUTTX_ARCHIVES)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-04-26 20:14:32 -03:00
|
|
|
# We cannot build these parallel; note that we also force -j1 for the
|
|
|
|
# sub-make invocations.
|
|
|
|
ifneq ($(filter archives,$(MAKECMDGOALS)),)
|
|
|
|
.NOTPARALLEL:
|
|
|
|
endif
|
|
|
|
|
2013-02-23 16:23:34 -04:00
|
|
|
$(ARCHIVE_DIR)%.export: board = $(notdir $(basename $@))
|
2013-06-13 03:46:22 -03:00
|
|
|
$(ARCHIVE_DIR)%.export: configuration = nsh
|
2013-07-07 21:53:55 -03:00
|
|
|
$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)%.export: $(NUTTX_SRC)
|
|
|
|
@$(ECHO) %% Configuring NuttX for $(board)
|
2013-01-16 22:23:49 -04:00
|
|
|
$(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export)
|
2013-08-23 03:47:55 -03:00
|
|
|
$(Q) $(MAKE) -r -j1 -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
2013-08-10 16:39:58 -03:00
|
|
|
$(Q) (cd $(NUTTX_SRC)/configs && $(COPYDIR) $(PX4_BASE)nuttx-configs/$(board) .)
|
2013-02-23 16:23:34 -04:00
|
|
|
$(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(board)/$(configuration))
|
2013-07-07 21:53:55 -03:00
|
|
|
@$(ECHO) %% Exporting NuttX for $(board)
|
2013-08-23 03:47:55 -03:00
|
|
|
$(Q) $(MAKE) -r -j1 -C $(NUTTX_SRC) -r $(MQUIET) CONFIG_ARCH_BOARD=$(board) export
|
|
|
|
$(Q) $(MKDIR) -p $(dir $@)
|
2013-02-23 16:23:34 -04:00
|
|
|
$(Q) $(COPY) $(NUTTX_SRC)nuttx-export.zip $@
|
2013-08-03 03:11:04 -03:00
|
|
|
$(Q) (cd $(NUTTX_SRC)/configs && $(RMDIR) $(board))
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-08-10 16:39:58 -03:00
|
|
|
#
|
|
|
|
# The user can run the NuttX 'menuconfig' tool for a single board configuration with
|
|
|
|
# make BOARDS=<boardname> menuconfig
|
|
|
|
#
|
|
|
|
ifeq ($(MAKECMDGOALS),menuconfig)
|
|
|
|
ifneq ($(words $(BOARDS)),1)
|
|
|
|
$(error BOARDS must specify exactly one board for the menuconfig goal)
|
|
|
|
endif
|
|
|
|
BOARD = $(BOARDS)
|
|
|
|
menuconfig: $(NUTTX_SRC)
|
|
|
|
@$(ECHO) %% Configuring NuttX for $(BOARD)
|
|
|
|
$(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export)
|
2013-08-23 03:47:55 -03:00
|
|
|
$(Q) $(MAKE) -r -j1 -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
2013-08-10 16:39:58 -03:00
|
|
|
$(Q) (cd $(NUTTX_SRC)/configs && $(COPYDIR) $(PX4_BASE)nuttx-configs/$(BOARD) .)
|
|
|
|
$(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(BOARD)/nsh)
|
|
|
|
@$(ECHO) %% Running menuconfig for $(BOARD)
|
2013-08-23 03:47:55 -03:00
|
|
|
$(Q) $(MAKE) -r -j1 -C $(NUTTX_SRC) -r $(MQUIET) menuconfig
|
2013-08-10 16:39:58 -03:00
|
|
|
@$(ECHO) %% Saving configuration file
|
|
|
|
$(Q)$(COPY) $(NUTTX_SRC).config $(PX4_BASE)nuttx-configs/$(BOARD)/nsh/defconfig
|
|
|
|
else
|
|
|
|
menuconfig:
|
|
|
|
@$(ECHO) ""
|
|
|
|
@$(ECHO) "The menuconfig goal must be invoked without any other goal being specified"
|
|
|
|
@$(ECHO) ""
|
|
|
|
endif
|
|
|
|
|
2013-07-07 21:53:55 -03:00
|
|
|
$(NUTTX_SRC):
|
2014-07-07 12:35:47 -03:00
|
|
|
$(Q) (./Tools/check_submodules.sh)
|
2014-07-07 12:18:54 -03:00
|
|
|
|
|
|
|
.PHONY: checksubmodules
|
|
|
|
checksubmodules:
|
2014-07-07 12:35:47 -03:00
|
|
|
$(Q) (./Tools/check_submodules.sh)
|
2013-07-07 21:53:55 -03:00
|
|
|
|
2014-07-07 12:51:30 -03:00
|
|
|
.PHONY: updatesubmodules
|
|
|
|
updatesubmodules:
|
2014-07-07 17:20:55 -03:00
|
|
|
$(Q) (git submodule init)
|
2014-07-07 12:51:30 -03:00
|
|
|
$(Q) (git submodule update)
|
|
|
|
|
2013-08-04 19:01:11 -03:00
|
|
|
#
|
|
|
|
# Testing targets
|
|
|
|
#
|
|
|
|
testbuild:
|
2013-08-23 03:47:55 -03:00
|
|
|
$(Q) (cd $(PX4_BASE) && $(MAKE) distclean && $(MAKE) archives && $(MAKE) -j8)
|
2013-08-04 19:01:11 -03:00
|
|
|
|
2012-08-04 19:12:36 -03:00
|
|
|
#
|
|
|
|
# Cleanup targets. 'clean' should remove all built products and force
|
|
|
|
# a complete re-compilation, 'distclean' should remove everything
|
|
|
|
# that's generated leaving only files that are in source control.
|
|
|
|
#
|
2013-01-16 22:23:49 -04:00
|
|
|
.PHONY: clean
|
2012-08-04 19:12:36 -03:00
|
|
|
clean:
|
2013-02-23 16:23:34 -04:00
|
|
|
$(Q) $(RMDIR) $(BUILD_DIR)*.build
|
2013-05-12 18:04:57 -03:00
|
|
|
$(Q) $(REMOVE) $(IMAGE_DIR)*.px4
|
2012-08-04 19:12:36 -03:00
|
|
|
|
|
|
|
.PHONY: distclean
|
2013-01-16 22:23:49 -04:00
|
|
|
distclean: clean
|
2013-05-12 18:04:57 -03:00
|
|
|
$(Q) $(REMOVE) $(ARCHIVE_DIR)*.export
|
2013-08-23 03:47:55 -03:00
|
|
|
$(Q) $(MAKE) -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
|
|
|
$(Q) (cd $(NUTTX_SRC)/configs && $(FIND) . -maxdepth 1 -type l -delete)
|
2012-08-04 19:12:36 -03:00
|
|
|
|
2013-03-31 19:46:07 -03:00
|
|
|
#
|
|
|
|
# Print some help text
|
|
|
|
#
|
|
|
|
.PHONY: help
|
|
|
|
help:
|
2013-07-07 21:53:55 -03:00
|
|
|
@$(ECHO) ""
|
|
|
|
@$(ECHO) " PX4 firmware builder"
|
|
|
|
@$(ECHO) " ===================="
|
|
|
|
@$(ECHO) ""
|
|
|
|
@$(ECHO) " Available targets:"
|
|
|
|
@$(ECHO) " ------------------"
|
|
|
|
@$(ECHO) ""
|
|
|
|
@$(ECHO) " archives"
|
|
|
|
@$(ECHO) " Build the NuttX RTOS archives that are used by the firmware build."
|
|
|
|
@$(ECHO) ""
|
|
|
|
@$(ECHO) " all"
|
|
|
|
@$(ECHO) " Build all firmware configs: $(CONFIGS)"
|
|
|
|
@$(ECHO) " A limited set of configs can be built with CONFIGS=<list-of-configs>"
|
|
|
|
@$(ECHO) ""
|
2013-03-31 19:46:07 -03:00
|
|
|
@for config in $(CONFIGS); do \
|
2013-08-23 03:47:55 -03:00
|
|
|
$(ECHO) " $$config"; \
|
|
|
|
$(ECHO) " Build just the $$config firmware configuration."; \
|
|
|
|
$(ECHO) ""; \
|
2013-03-31 19:46:07 -03:00
|
|
|
done
|
2013-07-07 21:53:55 -03:00
|
|
|
@$(ECHO) " clean"
|
|
|
|
@$(ECHO) " Remove all firmware build pieces."
|
|
|
|
@$(ECHO) ""
|
|
|
|
@$(ECHO) " distclean"
|
|
|
|
@$(ECHO) " Remove all compilation products, including NuttX RTOS archives."
|
|
|
|
@$(ECHO) ""
|
|
|
|
@$(ECHO) " upload"
|
|
|
|
@$(ECHO) " When exactly one config is being built, add this target to upload the"
|
|
|
|
@$(ECHO) " firmware to the board when the build is complete. Not supported for"
|
|
|
|
@$(ECHO) " all configurations."
|
|
|
|
@$(ECHO) ""
|
2013-08-04 19:01:11 -03:00
|
|
|
@$(ECHO) " testbuild"
|
|
|
|
@$(ECHO) " Perform a complete clean build of the entire tree."
|
|
|
|
@$(ECHO) ""
|
2013-07-07 21:53:55 -03:00
|
|
|
@$(ECHO) " Common options:"
|
|
|
|
@$(ECHO) " ---------------"
|
|
|
|
@$(ECHO) ""
|
|
|
|
@$(ECHO) " V=1"
|
|
|
|
@$(ECHO) " If V is set, more verbose output is printed during the build. This can"
|
|
|
|
@$(ECHO) " help when diagnosing issues with the build or toolchain."
|
|
|
|
@$(ECHO) ""
|