From 196ee8b16fcd42fca04d1fb7e11ec46dd45c8421 Mon Sep 17 00:00:00 2001 From: px4dev Date: Sat, 11 May 2013 11:32:05 -0700 Subject: Change the way modules are built so that object paths are relative and use vpath for locating sources (so source paths are also shorter). Add some basic documentation for the build system files while we're at it. --- makefiles/README.txt | 71 +++++++++++++++++++++++++++++++++++++ makefiles/firmware.mk | 7 ++-- makefiles/module.mk | 51 +++++++++++++++----------- src/modules/mathlib/CMSIS/module.mk | 5 +-- 4 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 makefiles/README.txt diff --git a/makefiles/README.txt b/makefiles/README.txt new file mode 100644 index 000000000..8b84e4c40 --- /dev/null +++ b/makefiles/README.txt @@ -0,0 +1,71 @@ +PX4 Build System +================ + +The files in this directory implement the PX4 runtime firmware build system +and configuration for the standard PX4 boards and software, in conjunction +with Makefile in the parent directory. + +../Makefile + + Top-level makefile for the PX4 build system. This makefile supports + building NuttX archives, as well as supervising the building of all + of the defined PX4 firmware configurations. + + Try 'make help' in the parent directory for documentation. + +firmware.mk + + Manages the build for one specific firmware configuration. + See the comments at the top of this file for detailed documentation. + + Builds modules, builtin command lists and the ROMFS (if configured). + + This is the makefile directly used by external build systems; it can + be configured to compile modules both inside and outside the PX4 + source tree. When used in this mode, at least BOARD, MODULES and + CONFIG_FILE must be set. + +module.mk + + Called by firmware.mk to build individual modules. + See the comments at the top of this file for detailed documentation. + + Not normally used other than by firmware.mk. + +nuttx.mk + + Called by ../Makefile to build or download the NuttX archives. + +upload.mk + + Called by ../Makefile to upload files to a target board. Can be used + by external build systems as well. + +setup.mk + + Provides common path and tool definitions. Implements host system-specific + compatibility hacks. + +board_.mk + + Board-specific configuration for . Typically sets CONFIG_ARCH + and then includes the toolchain definition for the board. + +config__.mk + + Parameters for a specific configuration on a specific board. + The board name is derived from the filename. Sets MODULES to select + source modules to be included in the configuration, may also set + ROMFS_ROOT to build a ROMFS and BUILTIN_COMMANDS to include non-module + commands (e.g. from NuttX) + +toolchain_.mk + + Provides macros used to compile and link source files. + Accepts EXTRADEFINES to add additional pre-processor symbol definitions, + EXTRACFLAGS, EXTRACXXFLAGS, EXTRAAFLAGS and EXTRALDFLAGS to pass + additional flags to the C compiler, C++ compiler, assembler and linker + respectively. + + Defines the COMPILE, COMPILEXX, ASSEMBLE, PRELINK, ARCHIVE and LINK + macros that are used elsewhere in the build system. diff --git a/makefiles/firmware.mk b/makefiles/firmware.mk index b63aa28d7..e6a45a4e8 100644 --- a/makefiles/firmware.mk +++ b/makefiles/firmware.mk @@ -223,12 +223,15 @@ MODULE_OBJS := $(foreach path,$(dir $(MODULE_MKFILES)),$(WORK_DIR)$(path)module .PHONY: $(MODULE_OBJS) $(MODULE_OBJS): relpath = $(patsubst $(WORK_DIR)%,%,$@) $(MODULE_OBJS): mkfile = $(patsubst %module.pre.o,%module.mk,$(relpath)) +$(MODULE_OBJS): workdir = $(@D) $(MODULE_OBJS): $(GLOBAL_DEPS) $(NUTTX_CONFIG_HEADER) + $(Q) $(MKDIR) -p $(workdir) $(Q) $(MAKE) -r -f $(PX4_MK_DIR)module.mk \ - MODULE_WORK_DIR=$(dir $@) \ + -C $(workdir) \ + MODULE_WORK_DIR=$(workdir) \ MODULE_OBJ=$@ \ MODULE_MK=$(mkfile) \ - MODULE_NAME=$(lastword $(subst /, ,$(@D))) \ + MODULE_NAME=$(lastword $(subst /, ,$(workdir))) \ module # make a list of phony clean targets for modules diff --git a/makefiles/module.mk b/makefiles/module.mk index 0fe6f0ffe..db6f4e15e 100644 --- a/makefiles/module.mk +++ b/makefiles/module.mk @@ -39,6 +39,10 @@ # symbols, as the global namespace is shared between all modules. Normally an # module will just export one or more _main functions. # +# IMPORTANT NOTE: +# +# This makefile assumes it is being invoked in the module's output directory. +# # # Variables that can be set by the module's module.mk: @@ -179,26 +183,30 @@ CXXFLAGS += -fvisibility=$(DEFAULT_VISIBILITY) -include $(PX4_INCLUDE_DIR)visibi # module: $(MODULE_OBJ) $(MODULE_COMMAND_FILES) +## +## Locate sources (allows relative source paths in module.mk) +## +#define SRC_SEARCH +# $(abspath $(firstword $(wildcard $1) $(wildcard $(MODULE_SRC)/$1) MISSING_$1)) +#endef # -# Locate sources (allows relative source paths in module.mk) +#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 # -define SRC_SEARCH - $(abspath $(firstword $(wildcard $1) $(wildcard $(MODULE_SRC)/$1) MISSING_$1)) -endef +## +## Object files we will generate from sources +## +#OBJS := $(foreach src,$(ABS_SRCS),$(MODULE_WORK_DIR)$(src).o) -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) +OBJS = $(addsuffix .o,$(SRCS)) +$(info SRCS $(SRCS)) +$(info OBJS $(OBJS)) # # SRCS -> OBJS rules @@ -206,13 +214,16 @@ OBJS := $(foreach src,$(ABS_SRCS),$(MODULE_WORK_DIR)$(src).o) $(OBJS): $(GLOBAL_DEPS) -$(filter %.c.o,$(OBJS)): $(MODULE_WORK_DIR)%.c.o: %.c $(GLOBAL_DEPS) +vpath %.c $(MODULE_SRC) +$(filter %.c.o,$(OBJS)): %.c.o: %.c $(GLOBAL_DEPS) $(call COMPILE,$<,$@) -$(filter %.cpp.o,$(OBJS)): $(MODULE_WORK_DIR)%.cpp.o: %.cpp $(GLOBAL_DEPS) +vpath %.cpp $(MODULE_SRC) +$(filter %.cpp.o,$(OBJS)): %.cpp.o: %.cpp $(GLOBAL_DEPS) $(call COMPILEXX,$<,$@) -$(filter %.S.o,$(OBJS)): $(MODULE_WORK_DIR)%.S.o: %.S $(GLOBAL_DEPS) +vpath %.S $(MODULE_SRC) +$(filter %.S.o,$(OBJS)): %.S.o: %.S $(GLOBAL_DEPS) $(call ASSEMBLE,$<,$@) # diff --git a/src/modules/mathlib/CMSIS/module.mk b/src/modules/mathlib/CMSIS/module.mk index c676f3261..ba45b159e 100644 --- a/src/modules/mathlib/CMSIS/module.mk +++ b/src/modules/mathlib/CMSIS/module.mk @@ -38,8 +38,9 @@ # # Find sources # -DSPLIB_SRCDIR := $(PX4_MODULE_SRC)/modules/mathlib/CMSIS -ABS_SRCS := $(wildcard $(DSPLIB_SRCDIR)/DSP_Lib/Source/*/*.c) +DSPLIB_SRCDIR := $(dir $(lastword $(MAKEFILE_LIST))) +SRCLIST := $(wildcard $(DSPLIB_SRCDIR)DSP_Lib/Source/*/*.c) +SRCS := $(patsubst $(DSPLIB_SRCDIR)%,%,$(SRCLIST)) zork.c INCLUDE_DIRS += $(DSPLIB_SRCDIR)/Include \ $(DSPLIB_SRCDIR)/Device/ARM/ARMCM4/Include \ -- cgit v1.2.3 From 555d42e0cd2724225391bede58629d3bcea175db Mon Sep 17 00:00:00 2001 From: px4dev Date: Sat, 11 May 2013 16:46:52 -0700 Subject: Oops, left in some test code. --- src/modules/mathlib/CMSIS/module.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/mathlib/CMSIS/module.mk b/src/modules/mathlib/CMSIS/module.mk index ba45b159e..5e1abe642 100644 --- a/src/modules/mathlib/CMSIS/module.mk +++ b/src/modules/mathlib/CMSIS/module.mk @@ -40,7 +40,7 @@ # DSPLIB_SRCDIR := $(dir $(lastword $(MAKEFILE_LIST))) SRCLIST := $(wildcard $(DSPLIB_SRCDIR)DSP_Lib/Source/*/*.c) -SRCS := $(patsubst $(DSPLIB_SRCDIR)%,%,$(SRCLIST)) zork.c +SRCS := $(patsubst $(DSPLIB_SRCDIR)%,%,$(SRCLIST)) INCLUDE_DIRS += $(DSPLIB_SRCDIR)/Include \ $(DSPLIB_SRCDIR)/Device/ARM/ARMCM4/Include \ -- cgit v1.2.3 From 0ee738e9c91c49739798ac5ff8dd4a12c06bb82f Mon Sep 17 00:00:00 2001 From: px4dev Date: Sun, 12 May 2013 10:51:25 -0700 Subject: Fix ROMFS dependency scan, add a warning if ROMFS_ROOT appears to be empty. --- makefiles/firmware.mk | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/makefiles/firmware.mk b/makefiles/firmware.mk index e6a45a4e8..6fa0ae3eb 100644 --- a/makefiles/firmware.mk +++ b/makefiles/firmware.mk @@ -269,13 +269,17 @@ endif # # Add dependencies on anything in the ROMFS root -ROMFS_DEPS += $(wildcard \ - (ROMFS_ROOT)/* \ - (ROMFS_ROOT)/*/* \ - (ROMFS_ROOT)/*/*/* \ - (ROMFS_ROOT)/*/*/*/* \ - (ROMFS_ROOT)/*/*/*/*/* \ - (ROMFS_ROOT)/*/*/*/*/*/*) +ROMFS_FILES += $(wildcard \ + $(ROMFS_ROOT)/* \ + $(ROMFS_ROOT)/*/* \ + $(ROMFS_ROOT)/*/*/* \ + $(ROMFS_ROOT)/*/*/*/* \ + $(ROMFS_ROOT)/*/*/*/*/* \ + $(ROMFS_ROOT)/*/*/*/*/*/*) +ifeq ($(ROMFS_FILES),) +$(error ROMFS_ROOT $(ROMFS_ROOT) specifies a directory containing no files) +endif +ROMFS_DEPS += $(ROMFS_FILES) ROMFS_IMG = $(WORK_DIR)romfs.img ROMFS_CSRC = $(ROMFS_IMG:.img=.c) ROMFS_OBJ = $(ROMFS_CSRC:.c=.o) -- cgit v1.2.3 From edb0e01dfd9c38b826ec038ff7b8387e8ce0bd21 Mon Sep 17 00:00:00 2001 From: px4dev Date: Sun, 12 May 2013 14:04:57 -0700 Subject: HOTFIX: simplify symbol names going into the ROMFS object, hopefully this avoids inconsistent symbol naming on Windows. --- Makefile | 9 +++++++-- makefiles/firmware.mk | 2 +- makefiles/toolchain_gnu-arm-eabi.mk | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 224910e0f..1d1287b7f 100644 --- a/Makefile +++ b/Makefile @@ -159,11 +159,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) $(REMOVE) $(IMAGE_DIR)*.px4 .PHONY: distclean distclean: clean - $(Q) $(REMOVE) -f $(ARCHIVE_DIR)*.export + $(Q) $(REMOVE) $(ARCHIVE_DIR)*.export $(Q) make -C $(NUTTX_SRC) -r $(MQUIET) distclean # @@ -196,6 +196,11 @@ help: @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 "" @echo " Common options:" @echo " ---------------" @echo "" diff --git a/makefiles/firmware.mk b/makefiles/firmware.mk index 6fa0ae3eb..7afa3e787 100644 --- a/makefiles/firmware.mk +++ b/makefiles/firmware.mk @@ -280,7 +280,7 @@ ifeq ($(ROMFS_FILES),) $(error ROMFS_ROOT $(ROMFS_ROOT) specifies a directory containing no files) endif ROMFS_DEPS += $(ROMFS_FILES) -ROMFS_IMG = $(WORK_DIR)romfs.img +ROMFS_IMG = romfs.img ROMFS_CSRC = $(ROMFS_IMG:.img=.c) ROMFS_OBJ = $(ROMFS_CSRC:.c=.o) LIBS += $(ROMFS_OBJ) diff --git a/makefiles/toolchain_gnu-arm-eabi.mk b/makefiles/toolchain_gnu-arm-eabi.mk index 0e651e53c..874e7154c 100644 --- a/makefiles/toolchain_gnu-arm-eabi.mk +++ b/makefiles/toolchain_gnu-arm-eabi.mk @@ -254,6 +254,20 @@ endef # - relink the object and insert the binary file # - edit symbol names to suit # +# NOTE: exercise caution using this with absolute pathnames; it looks +# like the MinGW tools insert an extra _ in the binary symbol name; e.g. +# the path: +# +# /d/px4/firmware/Build/px4fmu_default.build/romfs.img +# +# is assigned symbols like: +# +# _binary_d__px4_firmware_Build_px4fmu_default_build_romfs_img_size +# +# when we would expect +# +# _binary__d_px4_firmware_Build_px4fmu_default_build_romfs_img_size +# define BIN_SYM_PREFIX _binary_$(subst /,_,$(subst .,_,$1)) endef @@ -267,4 +281,5 @@ define BIN_TO_OBJ --redefine-sym $(call BIN_SYM_PREFIX,$1)_start=$3 \ --redefine-sym $(call BIN_SYM_PREFIX,$1)_size=$3_len \ --strip-symbol $(call BIN_SYM_PREFIX,$1)_end + $(Q) $(REMOVE) $2.c $2.c.o endef -- cgit v1.2.3