mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 03:49:12 +08:00
Checkpoint: application framework makefile done
This commit is contained in:
@@ -60,10 +60,13 @@ $(STAGED_FIRMWARES): $(IMAGE_DIR)/%.px4: $(BUILD_DIR)/%.build/firmware.px4
|
|||||||
$(BUILD_DIR)/%.build/firmware.px4: config = $(patsubst $(BUILD_DIR)/%.build/firmware.px4,%,$@)
|
$(BUILD_DIR)/%.build/firmware.px4: config = $(patsubst $(BUILD_DIR)/%.build/firmware.px4,%,$@)
|
||||||
$(BUILD_DIR)/%.build/firmware.px4: work_dir = $(BUILD_DIR)/$(config).build
|
$(BUILD_DIR)/%.build/firmware.px4: work_dir = $(BUILD_DIR)/$(config).build
|
||||||
$(FIRMWARES): $(BUILD_DIR)/%.build/firmware.px4:
|
$(FIRMWARES): $(BUILD_DIR)/%.build/firmware.px4:
|
||||||
|
@echo %%%%
|
||||||
@echo %%%% Building $(config) in $(work_dir)
|
@echo %%%% Building $(config) in $(work_dir)
|
||||||
|
@echo %%%%
|
||||||
$(Q) mkdir -p $(work_dir)
|
$(Q) mkdir -p $(work_dir)
|
||||||
$(Q) make -C $(work_dir) \
|
$(Q) make -C $(work_dir) \
|
||||||
-f $(PX4_BASE)/makefiles/config_$(config).mk \
|
-f $(PX4_MK_DIR)/firmware.mk \
|
||||||
|
CONFIG=$(config) \
|
||||||
WORK_DIR=$(work_dir) \
|
WORK_DIR=$(work_dir) \
|
||||||
firmware
|
firmware
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,162 @@
|
|||||||
|
#
|
||||||
|
# Framework makefile for PX4 applications
|
||||||
|
#
|
||||||
|
# This makefile is invoked by firmware.mk to build each of the applications
|
||||||
|
# that will subsequently be linked into the firmware image.
|
||||||
|
#
|
||||||
|
# Applications are built as prelinked objects with a limited set of exported
|
||||||
|
# symbols, as the global namespace is shared between all apps. Normally an
|
||||||
|
# application will just export one or more <command>_main functions.
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Variables that can be set by the application's app.mk:
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# SRCS (required)
|
||||||
|
# Lists the .c, cpp and .S files that should be compiled/assembled to
|
||||||
|
# produce the application.
|
||||||
|
#
|
||||||
|
# APP_NAME (optional)
|
||||||
|
# APP_ENTRYPOINT (optional if APP_NAME is set)
|
||||||
|
# APP_STACKSIZE (optional if APP_NAME is set)
|
||||||
|
# APP_PRIORITY (optional if APP_NAME is set)
|
||||||
|
# Defines a single builtin command exported by the application.
|
||||||
|
# APP_NAME must be unique for any configuration, but need not be the
|
||||||
|
# same as the app directory name.
|
||||||
|
#
|
||||||
|
# If APP_ENTRYPOINT is set, it names the function (which must be exported)
|
||||||
|
# that will be the entrypoint for the builtin command. It defaults to
|
||||||
|
# $(APP_NAME)_main.
|
||||||
|
#
|
||||||
|
# If APP_STACKSIZE is set, it is the size in bytes of the stack to be
|
||||||
|
# allocated for the builtin command. If it is not set, it defaults
|
||||||
|
# to CONFIG_PTHREAD_STACK_DEFAULT.
|
||||||
|
#
|
||||||
|
# If APP_PRIORITY is set, it is the thread priority for the builtin
|
||||||
|
# command. If it is not set, it defaults to SCHED_PRIORITY_DEFAULT.
|
||||||
|
#
|
||||||
|
# APP_COMMANDS (optional)
|
||||||
|
# Defines builtin commands exported by the application. Each word in
|
||||||
|
# the list should be formatted as:
|
||||||
|
# <command>.<priority>.<stacksize>.<entrypoint>
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Variables visible to the application's app.mk:
|
||||||
|
#
|
||||||
|
# CONFIG
|
||||||
|
# BOARD
|
||||||
|
# APP_WORK_DIR
|
||||||
|
# Anything set in setup.mk, board_$(BOARD).mk and the toolchain file.
|
||||||
|
# Anything exported from config_$(CONFIG).mk
|
||||||
|
#
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# No user-serviceable parts below.
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ifeq ($(APP_MK),)
|
||||||
|
$(error No application makefile specified)
|
||||||
|
endif
|
||||||
|
|
||||||
|
#
|
||||||
|
# Get path and tool config
|
||||||
|
#
|
||||||
|
include $(PX4_BASE)/makefiles/setup.mk
|
||||||
|
|
||||||
|
#
|
||||||
|
# Get the board/toolchain config
|
||||||
|
#
|
||||||
|
include $(PX4_MK_DIR)/board_$(BOARD).mk
|
||||||
|
|
||||||
|
#
|
||||||
|
# Get the application's config
|
||||||
|
#
|
||||||
|
include $(APP_MK)
|
||||||
|
APP_SRC_DIR := $(dir $(APP_MK))
|
||||||
|
|
||||||
|
#
|
||||||
|
# Things that, if they change, might affect everything
|
||||||
|
#
|
||||||
|
GLOBAL_DEPS += $(MAKEFILE_LIST)
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Builtin command definitions
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ifneq ($(APP_NAME),)
|
||||||
|
APP_ENTRYPOINT ?= $(APP_NAME)_main
|
||||||
|
APP_STACKSIZE ?= CONFIG_PTHREAD_STACK_DEFAULT
|
||||||
|
APP_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||||
|
APP_COMMANDS += $(APP_NAME).$(APP_PRIORITY).$(APP_STACKSIZE).$(APP_ENTRYPOINT)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(APP_COMMANDS),)
|
||||||
|
APP_COMMAND_FILES := $(addprefix $(WORK_DIR)/builtin_commands/COMMAND.,$(APP_COMMANDS))
|
||||||
|
|
||||||
|
.PHONY: $(APP_COMMAND_FILES)
|
||||||
|
$(APP_COMMAND_FILES): $(GLOBAL_DEPS)
|
||||||
|
@echo %% registering: $(word 2,$(subst ., ,$(notdir $(@))))
|
||||||
|
@mkdir -p $@
|
||||||
|
$(Q) touch $@
|
||||||
|
endif
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Build rules
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
#
|
||||||
|
# What we're going to build
|
||||||
|
#
|
||||||
|
app: $(APP_OBJ) $(APP_COMMAND_FILES)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Locate sources (allows relative source paths in app.mk)
|
||||||
|
#
|
||||||
|
define SRC_SEARCH
|
||||||
|
$(firstword $(wildcard $(APP_SRC_DIR)/$1) MISSING_$1)
|
||||||
|
endef
|
||||||
|
|
||||||
|
ABS_SRCS := $(foreach src,$(SRCS),$(call SRC_SEARCH,$(src)))
|
||||||
|
MISSING_SRCS := $(subst MISSING_,,$(filter MISSING_%,$(ABS_SRCS)))
|
||||||
|
ifneq ($(MISSING_SRCS),)
|
||||||
|
$(error $(APP_MK): missing in SRCS: $(MISSING_SRCS))
|
||||||
|
endif
|
||||||
|
ifeq ($(ABS_SRCS),)
|
||||||
|
$(error $(APP_MK): nothing to compile in SRCS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
#
|
||||||
|
# Object files we will generate from sources
|
||||||
|
#
|
||||||
|
OBJS := $(foreach src,$(ABS_SRCS),$(APP_WORK_DIR)/$(src).o)
|
||||||
|
|
||||||
|
#
|
||||||
|
# SRCS -> OBJS rules
|
||||||
|
#
|
||||||
|
|
||||||
|
$(OBJS): $(GLOBAL_DEPS)
|
||||||
|
|
||||||
|
$(filter %.c.o,$(OBJS)): $(APP_WORK_DIR)/%.c.o: %.c
|
||||||
|
$(call COMPILE,$<,$@)
|
||||||
|
|
||||||
|
$(filter %.cpp.o,$(OBJS)): $(APP_WORK_DIR)/%.cpp.o: %.cpp $(GLOBAL_DEPS)
|
||||||
|
$(call COMPILEXX,$<,$@)
|
||||||
|
|
||||||
|
$(filter %.S.o,$(OBJS)): $(APP_WORK_DIR)/%.S.o: %.S $(GLOBAL_DEPS)
|
||||||
|
$(call ASSEMBLE,$<,$@)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Built product rules
|
||||||
|
#
|
||||||
|
|
||||||
|
$(APP_OBJ): $(OBJS) $(GLOBAL_DEPS)
|
||||||
|
$(call PRELINK,$@,$(OBJS))
|
||||||
|
|
||||||
|
#
|
||||||
|
# Utility rules
|
||||||
|
#
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(Q) $(REMOVE) $(APP_PRELINK) $(OBJS)
|
||||||
@@ -2,13 +2,19 @@
|
|||||||
# Makefile for the px4fmu_default configuration
|
# Makefile for the px4fmu_default configuration
|
||||||
#
|
#
|
||||||
|
|
||||||
CONFIG = px4fmu_default
|
#
|
||||||
SRCS = $(PX4_BASE)/platforms/empty.c
|
# Use the configuration's ROMFS.
|
||||||
|
#
|
||||||
ROMFS_ROOT = $(PX4_BASE)/ROMFS/$(CONFIG)
|
ROMFS_ROOT = $(PX4_BASE)/ROMFS/$(CONFIG)
|
||||||
|
|
||||||
# Commands from the NuttX export archive
|
#
|
||||||
|
# Add commands from the NuttX export archive.
|
||||||
#
|
#
|
||||||
# Each entry here is <command>.<priority>.<stacksize>.<entrypoint>
|
# Each entry here is <command>.<priority>.<stacksize>.<entrypoint>
|
||||||
|
#
|
||||||
BUILTIN_COMMANDS = perf.SCHED_PRIORITY_DEFAULT.CONFIG_PTHREAD_STACK_DEFAULT.perf_main
|
BUILTIN_COMMANDS = perf.SCHED_PRIORITY_DEFAULT.CONFIG_PTHREAD_STACK_DEFAULT.perf_main
|
||||||
|
|
||||||
include $(PX4_MK_DIR)/firmware.mk
|
#
|
||||||
|
# Build the test app
|
||||||
|
#
|
||||||
|
APPS = test
|
||||||
|
|||||||
@@ -2,7 +2,4 @@
|
|||||||
# Makefile for the px4io_default configuration
|
# Makefile for the px4io_default configuration
|
||||||
#
|
#
|
||||||
|
|
||||||
CONFIG = px4io_default
|
# ... nothing here yet
|
||||||
SRCS = $(PX4_BASE)/platforms/empty.c
|
|
||||||
|
|
||||||
include $(PX4_MK_DIR)/firmware.mk
|
|
||||||
|
|||||||
+145
-67
@@ -1,8 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Generic Makefile for PX4 firmware.
|
# Generic Makefile for PX4 firmware images.
|
||||||
#
|
|
||||||
# Currently this assumes that we're just compiling SRCS
|
|
||||||
# and then linking the whole thing together.
|
|
||||||
#
|
#
|
||||||
# Requires:
|
# Requires:
|
||||||
#
|
#
|
||||||
@@ -12,6 +9,39 @@
|
|||||||
#
|
#
|
||||||
# Optional:
|
# Optional:
|
||||||
#
|
#
|
||||||
|
# APPS
|
||||||
|
# Contains a list of application paths or path fragments used
|
||||||
|
# to find applications. The names listed here are searched in
|
||||||
|
# the following directories:
|
||||||
|
# <absolute path>
|
||||||
|
# $(APP_SEARCH_DIRS)
|
||||||
|
# WORK_DIR
|
||||||
|
# APP_SRC
|
||||||
|
# PX4_APP_SRC
|
||||||
|
#
|
||||||
|
# Application directories are expected to contain an 'app.mk'
|
||||||
|
# file which provides build configuration for the app. See
|
||||||
|
# application.mk for more details.
|
||||||
|
#
|
||||||
|
# LIBS
|
||||||
|
# Contains a list of library paths or path fragments used
|
||||||
|
# to find libraries. The names listed here are searched in the
|
||||||
|
# following directories:
|
||||||
|
# <absolute path>
|
||||||
|
# $(LIB_SEARCH_DIRS)
|
||||||
|
# WORK_DIR
|
||||||
|
# LIB_SRC
|
||||||
|
# PX4_LIB_SRC
|
||||||
|
#
|
||||||
|
# Library directories are expected to contain a 'lib.mk'
|
||||||
|
# file which provides build configuration for the library. See
|
||||||
|
# library.mk for more details.
|
||||||
|
#
|
||||||
|
# BUILTIN_COMMANDS
|
||||||
|
# Contains a list of built-in commands not explicitly provided
|
||||||
|
# by applications / libraries. Each entry in this list is formatted
|
||||||
|
# as <command>.<priority>.<stacksize>.<entrypoint>
|
||||||
|
#
|
||||||
# PX4_BASE:
|
# PX4_BASE:
|
||||||
# Points to a PX4 distribution. Normally determined based on the
|
# Points to a PX4 distribution. Normally determined based on the
|
||||||
# path to this file.
|
# path to this file.
|
||||||
@@ -29,6 +59,14 @@
|
|||||||
# containing the files under the directory and linked into the final
|
# containing the files under the directory and linked into the final
|
||||||
# image.
|
# image.
|
||||||
#
|
#
|
||||||
|
# APP_SEARCH_DIRS:
|
||||||
|
# Extra directories to search first for APPS before looking in the
|
||||||
|
# usual places.
|
||||||
|
#
|
||||||
|
# LIB_SEARCH_DIRS:
|
||||||
|
# Extra directories to search first for LIBS before looking in the
|
||||||
|
# usual places.
|
||||||
|
#
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Paths and configuration
|
# Paths and configuration
|
||||||
@@ -41,17 +79,57 @@
|
|||||||
# If PX4_BASE wasn't set previously, work out what it should be
|
# If PX4_BASE wasn't set previously, work out what it should be
|
||||||
# and set it here now.
|
# and set it here now.
|
||||||
#
|
#
|
||||||
export MK_DIR ?= $(dir $(lastword $(MAKEFILE_LIST)))
|
MK_DIR ?= $(dir $(lastword $(MAKEFILE_LIST)))
|
||||||
ifeq ($(PX4_BASE),)
|
ifeq ($(PX4_BASE),)
|
||||||
export PX4_BASE := $(abspath $(MK_DIR)/..)
|
export PX4_BASE := $(abspath $(MK_DIR)/..)
|
||||||
$(info %% set PX4_BASE to $(PX4_BASE))
|
$(info %% set PX4_BASE to $(PX4_BASE))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set a default target so that included makefiles or errors here don't
|
||||||
|
# cause confusion.
|
||||||
|
#
|
||||||
|
# XXX We could do something cute here with $(DEFAULT_GOAL) if it's not one
|
||||||
|
# of the maintenance targets and set CONFIG based on it.
|
||||||
|
#
|
||||||
|
all: firmware
|
||||||
|
|
||||||
#
|
#
|
||||||
# Get path and tool config
|
# Get path and tool config
|
||||||
#
|
#
|
||||||
include $(MK_DIR)/setup.mk
|
include $(MK_DIR)/setup.mk
|
||||||
|
|
||||||
|
#
|
||||||
|
# Locate the configuration file
|
||||||
|
#
|
||||||
|
ifeq ($(CONFIG),)
|
||||||
|
$(error Missing configuration name or file (specify with CONFIG=<config>))
|
||||||
|
endif
|
||||||
|
CONFIG_FILE := $(firstword $(wildcard $(CONFIG)) $(wildcard $(PX4_MK_DIR)/config_$(CONFIG).mk))
|
||||||
|
ifeq ($(CONFIG_FILE),)
|
||||||
|
$(error Can't find a config file called $(CONFIG) or $(PX4_MK_DIR)/config_$(CONFIG).mk)
|
||||||
|
endif
|
||||||
|
export CONFIG
|
||||||
|
include $(CONFIG_FILE)
|
||||||
|
$(info %% CONFIG $(CONFIG))
|
||||||
|
|
||||||
|
#
|
||||||
|
# Sanity-check the BOARD variable and then get the board config.
|
||||||
|
# If BOARD was not set by the configuration, extract it automatically.
|
||||||
|
#
|
||||||
|
# The board config in turn will fetch the toolchain configuration.
|
||||||
|
#
|
||||||
|
ifeq ($(BOARD),)
|
||||||
|
BOARD := $(firstword $(subst _, ,$(CONFIG)))
|
||||||
|
endif
|
||||||
|
BOARD_FILE := $(wildcard $(PX4_MK_DIR)/board_$(BOARD).mk)
|
||||||
|
ifeq ($(BOARD_FILE),)
|
||||||
|
$(error Config $(CONFIG) references board $(BOARD), but no board definition file found)
|
||||||
|
endif
|
||||||
|
export BOARD
|
||||||
|
include $(BOARD_FILE)
|
||||||
|
$(info %% BOARD $(BOARD))
|
||||||
|
|
||||||
#
|
#
|
||||||
# If WORK_DIR is not set, create a 'build' directory next to the
|
# If WORK_DIR is not set, create a 'build' directory next to the
|
||||||
# parent Makefile.
|
# parent Makefile.
|
||||||
@@ -62,63 +140,66 @@ export WORK_DIR := $(dir $(PARENT_MAKEFILE))/build
|
|||||||
endif
|
endif
|
||||||
$(info %% WORK_DIR $(WORK_DIR))
|
$(info %% WORK_DIR $(WORK_DIR))
|
||||||
|
|
||||||
#
|
|
||||||
# Sanity-check the BOARD variable and then get the board config.
|
|
||||||
# If BOARD is not set, but CONFIG is, use that.
|
|
||||||
#
|
|
||||||
# The board config in turn will fetch the toolchain configuration.
|
|
||||||
#
|
|
||||||
ifeq ($(BOARD),)
|
|
||||||
ifeq ($(CONFIG),)
|
|
||||||
$(error At least one of the BOARD or CONFIG variables must be set before including firmware.mk)
|
|
||||||
endif
|
|
||||||
BOARD := $(firstword $(subst _, ,$(CONFIG)))
|
|
||||||
endif
|
|
||||||
include $(PX4_MK_DIR)/board_$(BOARD).mk
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Things that, if they change, might affect everything
|
# Things that, if they change, might affect everything
|
||||||
#
|
#
|
||||||
GLOBAL_DEPS += $(MAKEFILE_LIST)
|
GLOBAL_DEPS += $(MAKEFILE_LIST)
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Applications
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# where to look for applications
|
||||||
|
APP_SEARCH_DIRS += $(WORK_DIR) $(APP_SRC) $(PX4_APP_SRC)
|
||||||
|
|
||||||
|
# sort and unique the apps list
|
||||||
|
APPS := $(sort $(APPS))
|
||||||
|
|
||||||
|
# locate the first instance of an app by full path or by looking on the
|
||||||
|
# application search path
|
||||||
|
define APP_SEARCH
|
||||||
|
$(firstword $(wildcard $(1)/app.mk) \
|
||||||
|
$(foreach search_dir,$(APP_SEARCH_DIRS),$(wildcard $(search_dir)/$(1)/app.mk)) \
|
||||||
|
MISSING_$1)
|
||||||
|
endef
|
||||||
|
|
||||||
|
APP_MKFILES := $(foreach app,$(APPS),$(call APP_SEARCH,$(app)))
|
||||||
|
MISSING_APPS := $(subst MISSING_,,$(filter MISSING_%,$(APP_MKFILES)))
|
||||||
|
ifneq ($(MISSING_APPS),)
|
||||||
|
$(error Can't find application(s): $(MISSING_APPS))
|
||||||
|
endif
|
||||||
|
|
||||||
|
APP_OBJS := $(foreach path,$(dir $(APP_MKFILES)),$(WORK_DIR)/$(path)/app.pre.o)
|
||||||
|
|
||||||
|
$(APP_OBJS): relpath = $(patsubst $(WORK_DIR)/%,%,$@)
|
||||||
|
$(APP_OBJS): mkfile = $(patsubst %/app.pre.o,%/app.mk,$(relpath))
|
||||||
|
$(APP_OBJS): $(GLOBAL_DEPS) $(NUTTX_CONFIG_HEADER)
|
||||||
|
@echo %%
|
||||||
|
@echo %% Building app in $(relpath) using $(mkfile)
|
||||||
|
@echo %%
|
||||||
|
$(Q) make -f $(PX4_MK_DIR)/application.mk \
|
||||||
|
APP_WORK_DIR=$(dir $@) \
|
||||||
|
APP_OBJ=$@ \
|
||||||
|
APP_MK=$(mkfile) \
|
||||||
|
app
|
||||||
|
|
||||||
|
APP_CLEANS := $(foreach path,$(dir $(APP_MKFILES)),$(WORK_DIR)/$(path)/clean)
|
||||||
|
|
||||||
|
.PHONY: $(APP_CLEANS)
|
||||||
|
$(APP_CLEANS): relpath = $(patsubst $(WORK_DIR)/%,%,$@)
|
||||||
|
$(APP_CLEANS): mkfile = $(patsubst %/clean,%/app.mk,$(relpath))
|
||||||
|
$(APP_CLEANS):
|
||||||
|
@echo %% cleaning using $(mkfile)
|
||||||
|
$(Q) make -f $(PX4_MK_DIR)/application.mk \
|
||||||
|
APP_WORK_DIR=$(dir $@) \
|
||||||
|
APP_MK=$(mkfile) \
|
||||||
|
clean
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# NuttX libraries and paths
|
# NuttX libraries and paths
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
#
|
include $(PX4_MK_DIR)/nuttx.mk
|
||||||
# Check that the NuttX archive for the selected board is available.
|
|
||||||
#
|
|
||||||
NUTTX_ARCHIVE := $(wildcard $(ARCHIVE_DIR)/$(BOARD).export)
|
|
||||||
ifeq ($(NUTTX_ARCHIVE),)
|
|
||||||
$(error The NuttX export archive for $(BOARD) is missing from $(ARCHIVE_DIR) - try 'make archives' in $(PX4_BASE))
|
|
||||||
endif
|
|
||||||
|
|
||||||
#
|
|
||||||
# The NuttX config header should always be present in the NuttX archive, and
|
|
||||||
# if it changes, everything should be rebuilt. So, use it as the trigger to
|
|
||||||
# unpack the NuttX archive.
|
|
||||||
#
|
|
||||||
NUTTX_EXPORT_DIR = $(WORK_DIR)/nuttx-export
|
|
||||||
NUTTX_CONFIG_HEADER = $(NUTTX_EXPORT_DIR)/include/nuttx/config.h
|
|
||||||
GLOBAL_DEPS += $(NUTTX_CONFIG_HEADER)
|
|
||||||
|
|
||||||
#
|
|
||||||
# Use the linker script from the NuttX export
|
|
||||||
#
|
|
||||||
LDSCRIPT = $(NUTTX_EXPORT_DIR)/build/ld.script
|
|
||||||
|
|
||||||
#
|
|
||||||
# Add directories from the NuttX export to the relevant search paths
|
|
||||||
#
|
|
||||||
INCLUDE_DIRS += $(NUTTX_EXPORT_DIR)/include
|
|
||||||
LIB_DIRS += $(NUTTX_EXPORT_DIR)/libs
|
|
||||||
LIBS += -lapps -lnuttx
|
|
||||||
LINK_DEPS += $(wildcard $(addsuffix /*.a,$(LIB_DIRS)))
|
|
||||||
|
|
||||||
$(NUTTX_CONFIG_HEADER): $(NUTTX_ARCHIVE)
|
|
||||||
@echo %% Unpacking $(NUTTX_ARCHIVE)
|
|
||||||
$(Q) unzip -q -o -d $(WORK_DIR) $(NUTTX_ARCHIVE)
|
|
||||||
$(Q) touch $@
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# ROMFS generation
|
# ROMFS generation
|
||||||
@@ -149,7 +230,7 @@ $(ROMFS_CSRC): $(ROMFS_IMG)
|
|||||||
@echo %% generating $@
|
@echo %% generating $@
|
||||||
$(Q) (cd $(dir $<) && xxd -i $(notdir $<)) > $@
|
$(Q) (cd $(dir $<) && xxd -i $(notdir $<)) > $@
|
||||||
|
|
||||||
$(ROMFS_IMG): $(ROMFS_DEPS)
|
$(ROMFS_IMG): $(ROMFS_DEPS) $(GLOBAL_DEPS)
|
||||||
@echo %% generating $@
|
@echo %% generating $@
|
||||||
$(Q) $(GENROMFS) -f $@ -d $(ROMFS_ROOT) -V "NSHInitVol"
|
$(Q) $(GENROMFS) -f $@ -d $(ROMFS_ROOT) -V "NSHInitVol"
|
||||||
|
|
||||||
@@ -163,8 +244,6 @@ endif
|
|||||||
# Note that we can't just put builtin_commands.c in SRCS, as it's depended on by the
|
# Note that we can't just put builtin_commands.c in SRCS, as it's depended on by the
|
||||||
# NuttX export library. Instead, we have to treat it like a library.
|
# NuttX export library. Instead, we have to treat it like a library.
|
||||||
#
|
#
|
||||||
# XXX need to fix stack size numbers here so that apps can set them.
|
|
||||||
#
|
|
||||||
# Builtin commands can be generated by the configuration, in which case they
|
# Builtin commands can be generated by the configuration, in which case they
|
||||||
# must refer to commands that already exist, or indirectly generated by applications
|
# must refer to commands that already exist, or indirectly generated by applications
|
||||||
# when they are built.
|
# when they are built.
|
||||||
@@ -181,7 +260,7 @@ endif
|
|||||||
BUILTIN_CSRC = $(WORK_DIR)/builtin_commands.c
|
BUILTIN_CSRC = $(WORK_DIR)/builtin_commands.c
|
||||||
|
|
||||||
# add command definitions from apps
|
# add command definitions from apps
|
||||||
BUILTIN_COMMANDS += $(subst COMMAND.,,$(notdir $(wildcard $(WORK_DIR)/builtin_commands/APP.*)))
|
BUILTIN_COMMANDS += $(subst COMMAND.,,$(notdir $(wildcard $(WORK_DIR)/builtin_commands/COMMAND.*)))
|
||||||
|
|
||||||
# (BUILTIN_PROTO,<cmdspec>,<outputfile>)
|
# (BUILTIN_PROTO,<cmdspec>,<outputfile>)
|
||||||
define BUILTIN_PROTO
|
define BUILTIN_PROTO
|
||||||
@@ -193,7 +272,7 @@ define BUILTIN_DEF
|
|||||||
echo ' {"$(word 1,$1)", $(word 2,$1), $(word 3,$1), $(word 4,$1)},' >> $2;
|
echo ' {"$(word 1,$1)", $(word 2,$1), $(word 3,$1), $(word 4,$1)},' >> $2;
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(BUILTIN_CSRC): $(MAKEFILE_LIST)
|
$(BUILTIN_CSRC): $(GLOBAL_DEPS)
|
||||||
@echo %% generating $@
|
@echo %% generating $@
|
||||||
$(Q) echo '/* builtin command list - automatically generated, do not edit */' > $@
|
$(Q) echo '/* builtin command list - automatically generated, do not edit */' > $@
|
||||||
$(Q) echo '#include <nuttx/config.h>' >> $@
|
$(Q) echo '#include <nuttx/config.h>' >> $@
|
||||||
@@ -209,7 +288,7 @@ BUILTIN_OBJ = $(BUILTIN_CSRC:.c=.o)
|
|||||||
LIBS += $(BUILTIN_OBJ)
|
LIBS += $(BUILTIN_OBJ)
|
||||||
LINK_DEPS += $(BUILTIN_OBJ)
|
LINK_DEPS += $(BUILTIN_OBJ)
|
||||||
|
|
||||||
$(BUILTIN_OBJ): $(BUILTIN_CSRC) $(GLOBAL_DEPS)
|
$(BUILTIN_OBJ): $(BUILTIN_CSRC)
|
||||||
$(Q) $(call COMPILE,$<,$@)
|
$(Q) $(call COMPILE,$<,$@)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -239,7 +318,7 @@ PRODUCT_BUNDLE = $(WORK_DIR)/firmware.px4
|
|||||||
PRODUCT_BIN = $(WORK_DIR)/firmware.bin
|
PRODUCT_BIN = $(WORK_DIR)/firmware.bin
|
||||||
PRODUCT_SYM = $(WORK_DIR)/firmware.sym
|
PRODUCT_SYM = $(WORK_DIR)/firmware.sym
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: firmware
|
||||||
firmware: $(PRODUCT_BUNDLE)
|
firmware: $(PRODUCT_BUNDLE)
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -254,15 +333,12 @@ OBJS := $(foreach src,$(SRCS),$(WORK_DIR)/$(src).o)
|
|||||||
$(OBJS): $(GLOBAL_DEPS)
|
$(OBJS): $(GLOBAL_DEPS)
|
||||||
|
|
||||||
$(filter %.c.o,$(OBJS)): $(WORK_DIR)/%.c.o: %.c
|
$(filter %.c.o,$(OBJS)): $(WORK_DIR)/%.c.o: %.c
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
$(call COMPILE,$<,$@)
|
$(call COMPILE,$<,$@)
|
||||||
|
|
||||||
$(filter %.cpp.o,$(OBJS)): $(WORK_DIR)/%.cpp.o: %.cpp $(GLOBAL_DEPS)
|
$(filter %.cpp.o,$(OBJS)): $(WORK_DIR)/%.cpp.o: %.cpp $(GLOBAL_DEPS)
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
$(call COMPILEXX,$<,$@)
|
$(call COMPILEXX,$<,$@)
|
||||||
|
|
||||||
$(filter %.S.o,$(OBJS)): $(WORK_DIR)/%.S.o: %.S $(GLOBAL_DEPS)
|
$(filter %.S.o,$(OBJS)): $(WORK_DIR)/%.S.o: %.S $(GLOBAL_DEPS)
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
$(call ASSEMBLE,$<,$@)
|
$(call ASSEMBLE,$<,$@)
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -278,21 +354,23 @@ $(PRODUCT_BUNDLE): $(PRODUCT_BIN)
|
|||||||
$(PRODUCT_BIN): $(PRODUCT_SYM)
|
$(PRODUCT_BIN): $(PRODUCT_SYM)
|
||||||
$(call SYM_TO_BIN,$<,$@)
|
$(call SYM_TO_BIN,$<,$@)
|
||||||
|
|
||||||
$(PRODUCT_SYM): $(OBJS) $(GLOBAL_DEPS) $(LINK_DEPS)
|
$(PRODUCT_SYM): $(OBJS) $(APP_OBJS) $(GLOBAL_DEPS) $(LINK_DEPS) $(APP_MKFILES)
|
||||||
$(call LINK,$@,$(OBJS))
|
$(call LINK,$@,$(OBJS) $(APP_OBJS))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Utility rules
|
# Utility rules
|
||||||
#
|
#
|
||||||
|
|
||||||
|
.PHONY: upload
|
||||||
upload: $(PRODUCT_BUNDLE) $(PRODUCT_BIN)
|
upload: $(PRODUCT_BUNDLE) $(PRODUCT_BIN)
|
||||||
$(Q) make -f $(PX4_MK_INCLUDE)/upload.mk \
|
$(Q) make -f $(PX4_MK_DIR)/upload.mk \
|
||||||
METHOD=serial \
|
METHOD=serial \
|
||||||
PRODUCT=$(PRODUCT) \
|
PRODUCT=$(PRODUCT) \
|
||||||
BUNDLE=$(PRODUCT_BUNDLE) \
|
BUNDLE=$(PRODUCT_BUNDLE) \
|
||||||
BIN=$(PRODUCT_BIN)
|
BIN=$(PRODUCT_BIN)
|
||||||
|
|
||||||
clean:
|
.PHONY: clean
|
||||||
|
clean: $(APP_CLEANS)
|
||||||
@echo %% cleaning
|
@echo %% cleaning
|
||||||
$(Q) $(REMOVE) $(PRODUCT_BUNDLE) $(PRODUCT_BIN) $(PRODUCT_SYM)
|
$(Q) $(REMOVE) $(PRODUCT_BUNDLE) $(PRODUCT_BIN) $(PRODUCT_SYM)
|
||||||
$(Q) $(REMOVE) $(OBJS) $(DEP_INCLUDES)
|
$(Q) $(REMOVE) $(OBJS) $(DEP_INCLUDES)
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#
|
||||||
|
# Rules and definitions related to handling the NuttX export archives when
|
||||||
|
# building firmware.
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check that the NuttX archive for the selected board is available.
|
||||||
|
#
|
||||||
|
NUTTX_ARCHIVE := $(wildcard $(ARCHIVE_DIR)/$(BOARD).export)
|
||||||
|
ifeq ($(NUTTX_ARCHIVE),)
|
||||||
|
$(error The NuttX export archive for $(BOARD) is missing from $(ARCHIVE_DIR) - try 'make archives' in $(PX4_BASE))
|
||||||
|
endif
|
||||||
|
|
||||||
|
#
|
||||||
|
# The NuttX config header should always be present in the NuttX archive, and
|
||||||
|
# if it changes, everything should be rebuilt. So, use it as the trigger to
|
||||||
|
# unpack the NuttX archive.
|
||||||
|
#
|
||||||
|
NUTTX_EXPORT_DIR = $(WORK_DIR)/nuttx-export
|
||||||
|
NUTTX_CONFIG_HEADER = $(NUTTX_EXPORT_DIR)/include/nuttx/config.h
|
||||||
|
GLOBAL_DEPS += $(NUTTX_CONFIG_HEADER)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Use the linker script from the NuttX export
|
||||||
|
#
|
||||||
|
LDSCRIPT = $(NUTTX_EXPORT_DIR)/build/ld.script
|
||||||
|
|
||||||
|
#
|
||||||
|
# Add directories from the NuttX export to the relevant search paths
|
||||||
|
#
|
||||||
|
INCLUDE_DIRS += $(NUTTX_EXPORT_DIR)/include
|
||||||
|
LIB_DIRS += $(NUTTX_EXPORT_DIR)/libs
|
||||||
|
LIBS += -lapps -lnuttx
|
||||||
|
LINK_DEPS += $(NUTTX_EXPORT_DIR)/libs/libapps.a \
|
||||||
|
$(NUTTX_EXPORT_DIR)/libs/libnuttx.a
|
||||||
|
|
||||||
|
$(NUTTX_CONFIG_HEADER): $(NUTTX_ARCHIVE)
|
||||||
|
@echo %% Unpacking $(NUTTX_ARCHIVE)
|
||||||
|
$(Q) unzip -q -o -d $(WORK_DIR) $(NUTTX_ARCHIVE)
|
||||||
|
$(Q) touch $@
|
||||||
+1
-1
@@ -39,5 +39,5 @@ endif
|
|||||||
#
|
#
|
||||||
# Makefile debugging.
|
# Makefile debugging.
|
||||||
#
|
#
|
||||||
Q := $(if $(V),,@)
|
export Q := $(if $(V),,@)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# Definitions for a generic GNU ARM-EABI toolchain
|
# Definitions for a generic GNU ARM-EABI toolchain
|
||||||
#
|
#
|
||||||
|
|
||||||
$(info %% Toolchain: gnu-arm-eabi)
|
$(info %% TOOLCHAIN gnu-arm-eabi)
|
||||||
|
|
||||||
CROSSDEV = arm-none-eabi-
|
CROSSDEV = arm-none-eabi-
|
||||||
|
|
||||||
@@ -131,16 +131,11 @@ LINK_DEPS += $(LDSCRIPT)
|
|||||||
# files to include to get automated dependencies
|
# files to include to get automated dependencies
|
||||||
DEP_INCLUDES = $(subst .o,.d,$(OBJS))
|
DEP_INCLUDES = $(subst .o,.d,$(OBJS))
|
||||||
|
|
||||||
ifeq ($(V),)
|
|
||||||
Q = @
|
|
||||||
else
|
|
||||||
Q =
|
|
||||||
endif
|
|
||||||
|
|
||||||
# compile C source $1 to object $2
|
# compile C source $1 to object $2
|
||||||
# as a side-effect, generate a dependency file
|
# as a side-effect, generate a dependency file
|
||||||
define COMPILE
|
define COMPILE
|
||||||
@echo "CC: $1"
|
@echo "CC: $1"
|
||||||
|
@mkdir -p $(dir $2)
|
||||||
$(Q) $(CC) -MD -c $(CFLAGS) $(abspath $1) -o $2
|
$(Q) $(CC) -MD -c $(CFLAGS) $(abspath $1) -o $2
|
||||||
endef
|
endef
|
||||||
|
|
||||||
@@ -148,35 +143,41 @@ endef
|
|||||||
# as a side-effect, generate a dependency file
|
# as a side-effect, generate a dependency file
|
||||||
define COMPILEXX
|
define COMPILEXX
|
||||||
@echo "CXX: $1"
|
@echo "CXX: $1"
|
||||||
|
@mkdir -p $(dir $2)
|
||||||
$(Q) $(CXX) -MD -c $(CXXFLAGS) $(abspath $1) -o $2
|
$(Q) $(CXX) -MD -c $(CXXFLAGS) $(abspath $1) -o $2
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# assemble $1 into $2
|
# assemble $1 into $2
|
||||||
define ASSEMBLE
|
define ASSEMBLE
|
||||||
@echo "AS: $1"
|
@echo "AS: $1"
|
||||||
|
@mkdir -p $(dir $2)
|
||||||
$(Q) $(CC) -c $(AFLAGS) $(abspath $1) -o $2
|
$(Q) $(CC) -c $(AFLAGS) $(abspath $1) -o $2
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# produce partially-linked $1 from files in $2
|
# produce partially-linked $1 from files in $2
|
||||||
define PRELINK
|
define PRELINK
|
||||||
@echo "PRELINK: $1"
|
@echo "PRELINK: $1"
|
||||||
|
@mkdir -p $(dir $1)
|
||||||
$(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
|
$(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# update the archive $1 with the files in $2
|
# update the archive $1 with the files in $2
|
||||||
define ARCHIVE
|
define ARCHIVE
|
||||||
@echo "AR: $2"
|
@echo "AR: $2"
|
||||||
|
@mkdir -p $(dir $1)
|
||||||
$(Q) $(AR) $1 $2
|
$(Q) $(AR) $1 $2
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Link the objects in $2 into the binary $1
|
# Link the objects in $2 into the binary $1
|
||||||
define LINK
|
define LINK
|
||||||
@echo "LINK: $1"
|
@echo "LINK: $1"
|
||||||
$(Q) $(LD) $(LDFLAGS) -o $1 --start-group $(LIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group
|
@mkdir -p $(dir $1)
|
||||||
|
$(Q) $(LD) $(LDFLAGS) -o $1 $2 --start-group $(LIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# convert $1 from a linked object to a raw binary
|
# convert $1 from a linked object to a raw binary
|
||||||
define SYM_TO_BIN
|
define SYM_TO_BIN
|
||||||
@echo "BIN: $2"
|
@echo "BIN: $2"
|
||||||
|
@mkdir -p $(dir $2)
|
||||||
$(Q) $(OBJCOPY) -O binary $1 $2
|
$(Q) $(OBJCOPY) -O binary $1 $2
|
||||||
endef
|
endef
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
APP_NAME = test
|
||||||
|
SRCS = foo.c
|
||||||
|
|
||||||
Reference in New Issue
Block a user