aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile36
-rw-r--r--makefiles/application.mk162
-rw-r--r--makefiles/config_px4fmu_default.mk4
-rw-r--r--makefiles/firmware.mk172
-rw-r--r--makefiles/module.mk165
-rw-r--r--makefiles/nuttx.mk20
-rw-r--r--makefiles/setup.mk24
-rw-r--r--makefiles/toolchain_gnu-arm-eabi.mk7
-rw-r--r--src/apps/test/app.mk4
-rw-r--r--src/modules/test/foo.c (renamed from src/apps/test/foo.c)0
-rw-r--r--src/modules/test/module.mk4
11 files changed, 305 insertions, 293 deletions
diff --git a/Makefile b/Makefile
index a86065b97..b113040d0 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,8 @@
#
# Get path and tool configuration
#
-export PX4_BASE := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
-include $(PX4_BASE)/makefiles/setup.mk
+export PX4_BASE := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/
+include $(PX4_BASE)makefiles/setup.mk
#
# Canned firmware configurations that we build.
@@ -41,15 +41,15 @@ endif
#
# Built products
#
-STAGED_FIRMWARES = $(foreach config,$(CONFIGS),$(IMAGE_DIR)/$(config).px4)
-FIRMWARES = $(foreach config,$(CONFIGS),$(BUILD_DIR)/$(config).build/firmware.px4)
+STAGED_FIRMWARES = $(foreach config,$(CONFIGS),$(IMAGE_DIR)$(config).px4)
+FIRMWARES = $(foreach config,$(CONFIGS),$(BUILD_DIR)$(config).build/firmware.px4)
all: $(STAGED_FIRMWARES)
#
# Copy FIRMWARES into the image directory.
#
-$(STAGED_FIRMWARES): $(IMAGE_DIR)/%.px4: $(BUILD_DIR)/%.build/firmware.px4
+$(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4
@echo %% Copying $@
$(Q) $(COPY) $< $@
@@ -57,15 +57,15 @@ $(STAGED_FIRMWARES): $(IMAGE_DIR)/%.px4: $(BUILD_DIR)/%.build/firmware.px4
# Generate FIRMWARES.
#
.PHONY: $(FIRMWARES)
-$(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:
+$(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:
@echo %%%%
@echo %%%% Building $(config) in $(work_dir)
@echo %%%%
$(Q) mkdir -p $(work_dir)
$(Q) make -C $(work_dir) \
- -f $(PX4_MK_DIR)/firmware.mk \
+ -f $(PX4_MK_DIR)firmware.mk \
CONFIG=$(config) \
WORK_DIR=$(work_dir) \
firmware
@@ -83,21 +83,21 @@ $(FIRMWARES): $(BUILD_DIR)/%.build/firmware.px4:
#
# XXX PX4IO configuration name is bad - NuttX configs should probably all be "px4"
#
-NUTTX_ARCHIVES = $(foreach board,$(BOARDS),$(ARCHIVE_DIR)/$(board).export)
+NUTTX_ARCHIVES = $(foreach board,$(BOARDS),$(ARCHIVE_DIR)$(board).export)
.PHONY: archives
archives: $(NUTTX_ARCHIVES)
-$(ARCHIVE_DIR)/%.export: board = $(notdir $(basename $@))
-$(ARCHIVE_DIR)/%.export: configuration = $(if $(filter $(board),px4io),io,nsh)
-$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)/%.export: $(NUTTX_SRC) $(NUTTX_APPS)
+$(ARCHIVE_DIR)%.export: board = $(notdir $(basename $@))
+$(ARCHIVE_DIR)%.export: configuration = $(if $(filter $(board),px4io),io,nsh)
+$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)%.export: $(NUTTX_SRC) $(NUTTX_APPS)
@echo %% Configuring NuttX for $(board)
$(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export)
$(Q) make -C $(NUTTX_SRC) -r $(MQUIET) distclean
- $(Q) (cd $(NUTTX_SRC)/tools && ./configure.sh $(board)/$(configuration))
+ $(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(board)/$(configuration))
@echo %% Exporting NuttX for $(board)
$(Q) make -C $(NUTTX_SRC) -r $(MQUIET) export
$(Q) mkdir -p $(dir $@)
- $(Q) $(COPY) $(NUTTX_SRC)/nuttx-export.zip $@
+ $(Q) $(COPY) $(NUTTX_SRC)nuttx-export.zip $@
#
# Cleanup targets. 'clean' should remove all built products and force
@@ -106,11 +106,11 @@ $(NUTTX_ARCHIVES): $(ARCHIVE_DIR)/%.export: $(NUTTX_SRC) $(NUTTX_APPS)
#
.PHONY: clean
clean:
- $(Q) $(RMDIR) $(BUILD_DIR)/*.build
- $(Q) $(REMOVE) -f $(IMAGE_DIR)/*.px4
+ $(Q) $(RMDIR) $(BUILD_DIR)*.build
+ $(Q) $(REMOVE) -f $(IMAGE_DIR)*.px4
.PHONY: distclean
distclean: clean
- $(Q) $(REMOVE) -f $(ARCHIVE_DIR)/*.export
+ $(Q) $(REMOVE) -f $(ARCHIVE_DIR)*.export
$(Q) make -C $(NUTTX_SRC) -r $(MQUIET) distclean
diff --git a/makefiles/application.mk b/makefiles/application.mk
deleted file mode 100644
index 24be729cc..000000000
--- a/makefiles/application.mk
+++ /dev/null
@@ -1,162 +0,0 @@
-#
-# 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)
diff --git a/makefiles/config_px4fmu_default.mk b/makefiles/config_px4fmu_default.mk
index 16b105277..6ab0d855d 100644
--- a/makefiles/config_px4fmu_default.mk
+++ b/makefiles/config_px4fmu_default.mk
@@ -15,6 +15,6 @@ ROMFS_ROOT = $(PX4_BASE)/ROMFS/$(CONFIG)
BUILTIN_COMMANDS = perf.SCHED_PRIORITY_DEFAULT.CONFIG_PTHREAD_STACK_DEFAULT.perf_main
#
-# Build the test app
+# Build the test module
#
-APPS = test
+MODULES = test
diff --git a/makefiles/firmware.mk b/makefiles/firmware.mk
index 9a98d2bc6..1b6a1cdef 100644
--- a/makefiles/firmware.mk
+++ b/makefiles/firmware.mk
@@ -9,37 +9,23 @@
#
# Optional:
#
-# APPS
-# Contains a list of application paths or path fragments used
-# to find applications. The names listed here are searched in
+# MODULES
+# Contains a list of module paths or path fragments used
+# to find modules. The names listed here are searched in
# the following directories:
# <absolute path>
-# $(APP_SEARCH_DIRS)
+# $(MODULE_SEARCH_DIRS)
# WORK_DIR
-# APP_SRC
-# PX4_APP_SRC
+# MODULE_SRC
+# PX4_MODULE_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.
+# Application directories are expected to contain a module.mk
+# file which provides build configuration for the module. See
+# makefiles/module.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
+# by modules / libraries. Each entry in this list is formatted
# as <command>.<priority>.<stacksize>.<entrypoint>
#
# PX4_BASE:
@@ -59,12 +45,8 @@
# containing the files under the directory and linked into the final
# 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
+# MODULE_SEARCH_DIRS:
+# Extra directories to search first for MODULES before looking in the
# usual places.
#
@@ -82,8 +64,8 @@
MK_DIR ?= $(dir $(lastword $(MAKEFILE_LIST)))
ifeq ($(PX4_BASE),)
export PX4_BASE := $(abspath $(MK_DIR)/..)
-$(info %% set PX4_BASE to $(PX4_BASE))
endif
+$(info PX4_BASE $(PX4_BASE))
#
# Set a default target so that included makefiles or errors here don't
@@ -111,7 +93,7 @@ $(error Can't find a config file called $(CONFIG) or $(PX4_MK_DIR)/config_$(CONF
endif
export CONFIG
include $(CONFIG_FILE)
-$(info %% CONFIG $(CONFIG))
+$(info CONFIG $(CONFIG))
#
# Sanity-check the BOARD variable and then get the board config.
@@ -128,7 +110,7 @@ $(error Config $(CONFIG) references board $(BOARD), but no board definition file
endif
export BOARD
include $(BOARD_FILE)
-$(info %% BOARD $(BOARD))
+$(info BOARD $(BOARD))
#
# If WORK_DIR is not set, create a 'build' directory next to the
@@ -136,9 +118,9 @@ $(info %% BOARD $(BOARD))
#
PARENT_MAKEFILE := $(lastword $(filter-out $(lastword $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
ifeq ($(WORK_DIR),)
-export WORK_DIR := $(dir $(PARENT_MAKEFILE))/build
+export WORK_DIR := $(dir $(PARENT_MAKEFILE))build/
endif
-$(info %% WORK_DIR $(WORK_DIR))
+$(info WORK_DIR $(WORK_DIR))
#
# Things that, if they change, might affect everything
@@ -146,53 +128,71 @@ $(info %% WORK_DIR $(WORK_DIR))
GLOBAL_DEPS += $(MAKEFILE_LIST)
################################################################################
-# Applications
+# Modules
################################################################################
-# where to look for applications
-APP_SEARCH_DIRS += $(WORK_DIR) $(APP_SRC) $(PX4_APP_SRC)
+#
+# We don't actually know what a moldule is called; all we have is a path fragment
+# that we can search for, and where we expect to find a module.mk file.
+#
+# As such, we replicate the successfully-found path inside WORK_DIR for the
+# module's build products in order to keep modules separated from each other.
+#
+# XXX If this becomes unwieldy or breaks for other reasons, we will need to
+# move to allocating directory names and keeping tabs on makefiles via
+# the directory name. That will involve arithmetic (it'd probably be time
+# for GMSL).
+
+# where to look for modules
+MODULE_SEARCH_DIRS += $(WORK_DIR) $(MODULE_SRC) $(PX4_MODULE_SRC)
-# sort and unique the apps list
-APPS := $(sort $(APPS))
+# sort and unique the modules list
+MODULES := $(sort $(MODULES))
-# 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)
+# locate the first instance of a module by full path or by looking on the
+# module search path
+define MODULE_SEARCH
+ $(abspath $(firstword $(wildcard $(1)/module.mk) \
+ $(foreach search_dir,$(MODULE_SEARCH_DIRS),$(wildcard $(search_dir)/$(1)/module.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))
+# make a list of module makefiles and check that we found them all
+MODULE_MKFILES := $(foreach module,$(MODULES),$(call MODULE_SEARCH,$(module)))
+MISSING_MODULES := $(subst MISSING_,,$(filter MISSING_%,$(MODULE_MKFILES)))
+ifneq ($(MISSING_MODULES),)
+$(error Can't find module(s): $(MISSING_MODULES))
endif
-APP_OBJS := $(foreach path,$(dir $(APP_MKFILES)),$(WORK_DIR)/$(path)/app.pre.o)
+# make a list of the object files we expect to build from modules
+MODULE_OBJS := $(foreach path,$(dir $(MODULE_MKFILES)),$(WORK_DIR)$(path)module.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)
+# rules to build module objects
+.PHONY: $(MODULE_OBJS)
+$(MODULE_OBJS): relpath = $(patsubst $(WORK_DIR)%,%,$@)
+$(MODULE_OBJS): mkfile = $(patsubst %module.pre.o,%module.mk,$(relpath))
+$(MODULE_OBJS): $(GLOBAL_DEPS) $(NUTTX_CONFIG_HEADER)
@echo %%
- @echo %% Building app in $(relpath) using $(mkfile)
+ @echo %% Building module 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):
+ $(Q) make -f $(PX4_MK_DIR)module.mk \
+ MODULE_WORK_DIR=$(dir $@) \
+ MODULE_OBJ=$@ \
+ MODULE_MK=$(mkfile) \
+ module
+
+# make a list of phony clean targets for modules
+MODULE_CLEANS := $(foreach path,$(dir $(MODULE_MKFILES)),$(WORK_DIR)$(path)/clean)
+
+# rules to clean modules
+.PHONY: $(MODULE_CLEANS)
+$(MODULE_CLEANS): relpath = $(patsubst $(WORK_DIR)%,%,$@)
+$(MODULE_CLEANS): mkfile = $(patsubst %clean,%module.mk,$(relpath))
+$(MODULE_CLEANS):
@echo %% cleaning using $(mkfile)
- $(Q) make -f $(PX4_MK_DIR)/application.mk \
- APP_WORK_DIR=$(dir $@) \
- APP_MK=$(mkfile) \
+ $(Q) make -f $(PX4_MK_DIR)module.mk \
+ MODULE_WORK_DIR=$(dir $@) \
+ MODULE_MK=$(mkfile) \
clean
################################################################################
@@ -217,7 +217,7 @@ ROMFS_DEPS += $(wildcard \
(ROMFS_ROOT)/*/*/*/* \
(ROMFS_ROOT)/*/*/*/*/* \
(ROMFS_ROOT)/*/*/*/*/*/*)
-ROMFS_IMG = $(WORK_DIR)/romfs.img
+ROMFS_IMG = $(WORK_DIR)romfs.img
ROMFS_CSRC = $(ROMFS_IMG:.img=.c)
ROMFS_OBJ = $(ROMFS_CSRC:.c=.o)
LIBS += $(ROMFS_OBJ)
@@ -245,7 +245,7 @@ endif
# NuttX export library. Instead, we have to treat it like a library.
#
# 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 modules
# when they are built.
#
# The configuration supplies builtin command information in the BUILTIN_COMMANDS
@@ -257,10 +257,10 @@ endif
# and the name of the function to call when starting the thread.
#
#
-BUILTIN_CSRC = $(WORK_DIR)/builtin_commands.c
+BUILTIN_CSRC = $(WORK_DIR)builtin_commands.c
-# add command definitions from apps
-BUILTIN_COMMANDS += $(subst COMMAND.,,$(notdir $(wildcard $(WORK_DIR)/builtin_commands/COMMAND.*)))
+# add command definitions from modules
+BUILTIN_COMMANDS += $(subst COMMAND.,,$(notdir $(wildcard $(WORK_DIR)builtin_commands/COMMAND.*)))
# (BUILTIN_PROTO,<cmdspec>,<outputfile>)
define BUILTIN_PROTO
@@ -300,7 +300,7 @@ $(BUILTIN_OBJ): $(BUILTIN_CSRC)
# source file.
#
ifeq ($(SRCS),)
-EMPTY_SRC = $(WORK_DIR)/empty.c
+EMPTY_SRC = $(WORK_DIR)empty.c
$(EMPTY_SRC):
$(Q) echo '/* this is an empty file */' > $@
@@ -314,9 +314,9 @@ endif
#
# What we're going to build.
#
-PRODUCT_BUNDLE = $(WORK_DIR)/firmware.px4
-PRODUCT_BIN = $(WORK_DIR)/firmware.bin
-PRODUCT_SYM = $(WORK_DIR)/firmware.sym
+PRODUCT_BUNDLE = $(WORK_DIR)firmware.px4
+PRODUCT_BIN = $(WORK_DIR)firmware.bin
+PRODUCT_SYM = $(WORK_DIR)firmware.sym
.PHONY: firmware
firmware: $(PRODUCT_BUNDLE)
@@ -324,7 +324,7 @@ firmware: $(PRODUCT_BUNDLE)
#
# Object files we will generate from sources
#
-OBJS := $(foreach src,$(SRCS),$(WORK_DIR)/$(src).o)
+OBJS := $(foreach src,$(SRCS),$(WORK_DIR)$(src).o)
#
# SRCS -> OBJS rules
@@ -332,13 +332,13 @@ OBJS := $(foreach src,$(SRCS),$(WORK_DIR)/$(src).o)
$(OBJS): $(GLOBAL_DEPS)
-$(filter %.c.o,$(OBJS)): $(WORK_DIR)/%.c.o: %.c
+$(filter %.c.o,$(OBJS)): $(WORK_DIR)%.c.o: %.c $(GLOBAL_DEPS)
$(call COMPILE,$<,$@)
-$(filter %.cpp.o,$(OBJS)): $(WORK_DIR)/%.cpp.o: %.cpp $(GLOBAL_DEPS)
+$(filter %.cpp.o,$(OBJS)): $(WORK_DIR)%.cpp.o: %.cpp $(GLOBAL_DEPS)
$(call COMPILEXX,$<,$@)
-$(filter %.S.o,$(OBJS)): $(WORK_DIR)/%.S.o: %.S $(GLOBAL_DEPS)
+$(filter %.S.o,$(OBJS)): $(WORK_DIR)%.S.o: %.S $(GLOBAL_DEPS)
$(call ASSEMBLE,$<,$@)
#
@@ -354,8 +354,8 @@ $(PRODUCT_BUNDLE): $(PRODUCT_BIN)
$(PRODUCT_BIN): $(PRODUCT_SYM)
$(call SYM_TO_BIN,$<,$@)
-$(PRODUCT_SYM): $(OBJS) $(APP_OBJS) $(GLOBAL_DEPS) $(LINK_DEPS) $(APP_MKFILES)
- $(call LINK,$@,$(OBJS) $(APP_OBJS))
+$(PRODUCT_SYM): $(OBJS) $(MODULE_OBJS) $(GLOBAL_DEPS) $(LINK_DEPS) $(MODULE_MKFILES)
+ $(call LINK,$@,$(OBJS) $(MODULE_OBJS))
#
# Utility rules
@@ -370,7 +370,7 @@ upload: $(PRODUCT_BUNDLE) $(PRODUCT_BIN)
BIN=$(PRODUCT_BIN)
.PHONY: clean
-clean: $(APP_CLEANS)
+clean: $(MODULE_CLEANS)
@echo %% cleaning
$(Q) $(REMOVE) $(PRODUCT_BUNDLE) $(PRODUCT_BIN) $(PRODUCT_SYM)
$(Q) $(REMOVE) $(OBJS) $(DEP_INCLUDES)
diff --git a/makefiles/module.mk b/makefiles/module.mk
new file mode 100644
index 000000000..306a9594f
--- /dev/null
+++ b/makefiles/module.mk
@@ -0,0 +1,165 @@
+#
+# Framework makefile for PX4 modules
+#
+# This makefile is invoked by firmware.mk to build each of the modules
+# 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 modules. Normally an
+# module will just export one or more <command>_main functions.
+#
+
+#
+# Variables that can be set by the module's module.mk:
+#
+#
+# SRCS (required)
+# Lists the .c, cpp and .S files that should be compiled/assembled to
+# produce the module.
+#
+# MODULE_NAME (optional)
+# MODULE_ENTRYPOINT (optional if MODULE_NAME is set)
+# MODULE_STACKSIZE (optional if MODULE_NAME is set)
+# MODULE_PRIORITY (optional if MODULE_NAME is set)
+# Defines a single builtin command exported by the module.
+# MODULE_NAME must be unique for any configuration, but need not be the
+# same as the module directory name.
+#
+# If MODULE_ENTRYPOINT is set, it names the function (which must be exported)
+# that will be the entrypoint for the builtin command. It defaults to
+# $(MODULE_NAME)_main.
+#
+# If MODULE_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 MODULE_PRIORITY is set, it is the thread priority for the builtin
+# command. If it is not set, it defaults to SCHED_PRIORITY_DEFAULT.
+#
+# MODULE_COMMANDS (optional)
+# Defines builtin commands exported by the module. Each word in
+# the list should be formatted as:
+# <command>.<priority>.<stacksize>.<entrypoint>
+#
+
+#
+# Variables visible to the module's module.mk:
+#
+# CONFIG
+# BOARD
+# MODULE_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 ($(MODULE_MK),)
+$(error No module makefile specified)
+endif
+$(info MODULE_MK $(MODULE_MK))
+
+#
+# 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 module's config
+#
+include $(MODULE_MK)
+MODULE_SRC := $(dir $(MODULE_MK))
+$(info MODULE_SRC $(MODULE_SRC))
+$(info MODULE_WORK_DIR $(MODULE_WORK_DIR))
+
+#
+# Things that, if they change, might affect everything
+#
+GLOBAL_DEPS += $(MAKEFILE_LIST)
+
+################################################################################
+# Builtin command definitions
+################################################################################
+
+ifneq ($(MODULE_NAME),)
+MODULE_ENTRYPOINT ?= $(MODULE_NAME)_main
+MODULE_STACKSIZE ?= CONFIG_PTHREAD_STACK_DEFAULT
+MODULE_PRIORITY ?= SCHED_PRIORITY_DEFAULT
+MODULE_COMMANDS += $(MODULE_NAME).$(MODULE_PRIORITY).$(MODULE_STACKSIZE).$(MODULE_ENTRYPOINT)
+endif
+
+ifneq ($(MODULE_COMMANDS),)
+MODULE_COMMAND_FILES := $(addprefix $(WORK_DIR)/builtin_commands/COMMAND.,$(MODULE_COMMANDS))
+
+.PHONY: $(MODULE_COMMAND_FILES)
+$(MODULE_COMMAND_FILES): $(GLOBAL_DEPS)
+ @echo COMMAND $(word 2,$(subst ., ,$(notdir $(@))))
+ @mkdir -p $@
+ $(Q) touch $@
+endif
+
+################################################################################
+# Build rules
+################################################################################
+
+#
+# What we're going to build
+#
+module: $(MODULE_OBJ) $(MODULE_COMMAND_FILES)
+
+#
+# Locate sources (allows relative source paths in module.mk)
+#
+define SRC_SEARCH
+ $(abspath $(firstword $(wildcard $(MODULE_SRC)/$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 $(MODULE_MK): missing in SRCS: $(MISSING_SRCS))
+endif
+ifeq ($(ABS_SRCS),)
+$(error $(MODULE_MK): nothing to compile in SRCS)
+endif
+
+#
+# Object files we will generate from sources
+#
+OBJS := $(foreach src,$(ABS_SRCS),$(MODULE_WORK_DIR)$(src).o)
+
+#
+# SRCS -> OBJS rules
+#
+
+$(OBJS): $(GLOBAL_DEPS)
+
+$(filter %.c.o,$(OBJS)): $(MODULE_WORK_DIR)%.c.o: %.c $(GLOBAL_DEPS)
+ $(call COMPILE,$<,$@)
+
+$(filter %.cpp.o,$(OBJS)): $(MODULE_WORK_DIR)%.cpp.o: %.cpp $(GLOBAL_DEPS)
+ $(call COMPILEXX,$<,$@)
+
+$(filter %.S.o,$(OBJS)): $(MODULE_WORK_DIR)%.S.o: %.S $(GLOBAL_DEPS)
+ $(call ASSEMBLE,$<,$@)
+
+#
+# Built product rules
+#
+
+$(MODULE_OBJ): $(OBJS) $(GLOBAL_DEPS)
+ $(call PRELINK,$@,$(OBJS))
+
+#
+# Utility rules
+#
+
+clean:
+ $(Q) $(REMOVE) $(MODULE_PRELINK) $(OBJS)
diff --git a/makefiles/nuttx.mk b/makefiles/nuttx.mk
index cdbd6e0af..bd2b98084 100644
--- a/makefiles/nuttx.mk
+++ b/makefiles/nuttx.mk
@@ -6,7 +6,7 @@
#
# Check that the NuttX archive for the selected board is available.
#
-NUTTX_ARCHIVE := $(wildcard $(ARCHIVE_DIR)/$(BOARD).export)
+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
@@ -16,23 +16,27 @@ endif
# 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
+NUTTX_EXPORT_DIR = $(WORK_DIR)nuttx-export/
+NUTTX_CONFIG_HEADER = $(NUTTX_EXPORT_DIR)include/nuttx/config.h
+$(info NUTTX_EXPORT_DIR $(NUTTX_EXPORT_DIR))
+$(info NUTTX_CONFIG_HEADER $(NUTTX_CONFIG_HEADER))
+
+
GLOBAL_DEPS += $(NUTTX_CONFIG_HEADER)
#
# Use the linker script from the NuttX export
#
-LDSCRIPT = $(NUTTX_EXPORT_DIR)/build/ld.script
+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
+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
+LINK_DEPS += $(NUTTX_EXPORT_DIR)libs/libapps.a \
+ $(NUTTX_EXPORT_DIR)libs/libnuttx.a
$(NUTTX_CONFIG_HEADER): $(NUTTX_ARCHIVE)
@echo %% Unpacking $(NUTTX_ARCHIVE)
diff --git a/makefiles/setup.mk b/makefiles/setup.mk
index 0c142cb1d..d4b279e7c 100644
--- a/makefiles/setup.mk
+++ b/makefiles/setup.mk
@@ -5,16 +5,20 @@
#
# Some useful paths.
#
-export PX4_APP_SRC = $(PX4_BASE)/src/apps
-export PX4_LIB_SRC = $(PX4_BASE)/src/libs
-export PX4_MK_DIR = $(PX4_BASE)/makefiles
-export NUTTX_SRC = $(PX4_BASE)/nuttx
-export NUTTX_APP_SRC = $(PX4_BASE)/apps
-export MAVLINK_SRC = $(PX4_BASE)/mavlink
-export ROMFS_SRC = $(PX4_BASE)/ROMFS
-export IMAGE_DIR = $(PX4_BASE)/Images
-export BUILD_DIR = $(PX4_BASE)/Build
-export ARCHIVE_DIR = $(PX4_BASE)/Archives
+# Note that in general we always keep directory paths with the separator
+# at the end, and join paths without explicit separators. This reduces
+# the number of duplicate slashes we have lying around in paths,
+# and is consistent with joining the results of $(dir) and $(notdir).
+#
+export PX4_MODULE_SRC = $(abspath $(PX4_BASE)/src/modules)/
+export PX4_MK_DIR = $(abspath $(PX4_BASE)/makefiles)/
+export NUTTX_SRC = $(abspath $(PX4_BASE)/nuttx)/
+export NUTTX_APP_SRC = $(abspath $(PX4_BASE)/apps)/
+export MAVLINK_SRC = $(abspath $(PX4_BASE)/mavlink)/
+export ROMFS_SRC = $(abspath $(PX4_BASE)/ROMFS)/
+export IMAGE_DIR = $(abspath $(PX4_BASE)/Images)/
+export BUILD_DIR = $(abspath $(PX4_BASE)/Build)/
+export ARCHIVE_DIR = $(abspath $(PX4_BASE)/Archives)/
#
# Tools
diff --git a/makefiles/toolchain_gnu-arm-eabi.mk b/makefiles/toolchain_gnu-arm-eabi.mk
index ba3b06c7f..0a1ee18e9 100644
--- a/makefiles/toolchain_gnu-arm-eabi.mk
+++ b/makefiles/toolchain_gnu-arm-eabi.mk
@@ -2,7 +2,7 @@
# Definitions for a generic GNU ARM-EABI toolchain
#
-$(info %% TOOLCHAIN gnu-arm-eabi)
+#$(info TOOLCHAIN gnu-arm-eabi)
CROSSDEV = arm-none-eabi-
@@ -134,7 +134,8 @@ DEP_INCLUDES = $(subst .o,.d,$(OBJS))
# compile C source $1 to object $2
# as a side-effect, generate a dependency file
define COMPILE
- @echo "CC: $1"
+ @echo "CC <- $1"
+ @echo "CC -> $2"
@mkdir -p $(dir $2)
$(Q) $(CC) -MD -c $(CFLAGS) $(abspath $1) -o $2
endef
@@ -172,7 +173,7 @@ endef
define LINK
@echo "LINK: $1"
@mkdir -p $(dir $1)
- $(Q) $(LD) $(LDFLAGS) -o $1 $2 --start-group $(LIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group
+ $(Q) $(LD) $(LDFLAGS) -o $1 --start-group $2 $(LIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group
endef
# convert $1 from a linked object to a raw binary
diff --git a/src/apps/test/app.mk b/src/apps/test/app.mk
deleted file mode 100644
index 283425c50..000000000
--- a/src/apps/test/app.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-
-APP_NAME = test
-SRCS = foo.c
-
diff --git a/src/apps/test/foo.c b/src/modules/test/foo.c
index e69de29bb..e69de29bb 100644
--- a/src/apps/test/foo.c
+++ b/src/modules/test/foo.c
diff --git a/src/modules/test/module.mk b/src/modules/test/module.mk
new file mode 100644
index 000000000..abf80eedf
--- /dev/null
+++ b/src/modules/test/module.mk
@@ -0,0 +1,4 @@
+
+MODULE_NAME = test
+SRCS = foo.c
+