diff options
Diffstat (limited to 'makefiles')
-rw-r--r-- | makefiles/config_px4fmu_default.mk | 8 | ||||
-rw-r--r-- | makefiles/firmware.mk | 76 | ||||
-rw-r--r-- | makefiles/library.mk | 169 | ||||
-rw-r--r-- | makefiles/module.mk | 31 | ||||
-rw-r--r-- | makefiles/toolchain_gnu-arm-eabi.mk | 5 |
5 files changed, 249 insertions, 40 deletions
diff --git a/makefiles/config_px4fmu_default.mk b/makefiles/config_px4fmu_default.mk index 23700b0ac..b1737ee6b 100644 --- a/makefiles/config_px4fmu_default.mk +++ b/makefiles/config_px4fmu_default.mk @@ -81,16 +81,20 @@ MODULES += modules/multirotor_pos_control MODULES += modules/sdlog # -# Libraries +# Library modules # MODULES += modules/systemlib MODULES += modules/systemlib/mixer MODULES += modules/mathlib -MODULES += modules/mathlib/CMSIS MODULES += modules/controllib MODULES += modules/uORB # +# Libraries +# +LIBRARIES += modules/mathlib/CMSIS + +# # Demo apps # #MODULES += examples/math_demo diff --git a/makefiles/firmware.mk b/makefiles/firmware.mk index 497e79237..6b09e6ec3 100644 --- a/makefiles/firmware.mk +++ b/makefiles/firmware.mk @@ -180,18 +180,6 @@ EXTRA_CLEANS = # Modules ################################################################################ -# -# We don't actually know what a module 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) @@ -249,6 +237,66 @@ $(MODULE_CLEANS): clean ################################################################################ +# Libraries +################################################################################ + +# where to look for libraries +LIBRARY_SEARCH_DIRS += $(WORK_DIR) $(MODULE_SRC) $(PX4_MODULE_SRC) + +# sort and unique the library list +LIBRARIES := $(sort $(LIBRARIES)) + +# locate the first instance of a library by full path or by looking on the +# library search path +define LIBRARY_SEARCH + $(firstword $(abspath $(wildcard $(1)/library.mk)) \ + $(abspath $(foreach search_dir,$(LIBRARY_SEARCH_DIRS),$(wildcard $(search_dir)/$(1)/library.mk))) \ + MISSING_$1) +endef + +# make a list of library makefiles and check that we found them all +LIBRARY_MKFILES := $(foreach library,$(LIBRARIES),$(call LIBRARY_SEARCH,$(library))) +MISSING_LIBRARIES := $(subst MISSING_,,$(filter MISSING_%,$(LIBRARY_MKFILES))) +ifneq ($(MISSING_LIBRARIES),) +$(error Can't find library(s): $(MISSING_LIBRARIES)) +endif + +# Make a list of the archive files we expect to build from libraries +# Note that this path will typically contain a double-slash at the WORK_DIR boundary; this must be +# preserved as it is used below to get the absolute path for the library.mk file correct. +# +LIBRARY_LIBS := $(foreach path,$(dir $(LIBRARY_MKFILES)),$(WORK_DIR)$(path)library.a) + +# rules to build module objects +.PHONY: $(LIBRARY_LIBS) +$(LIBRARY_LIBS): relpath = $(patsubst $(WORK_DIR)%,%,$@) +$(LIBRARY_LIBS): mkfile = $(patsubst %library.a,%library.mk,$(relpath)) +$(LIBRARY_LIBS): workdir = $(@D) +$(LIBRARY_LIBS): $(GLOBAL_DEPS) $(NUTTX_CONFIG_HEADER) + $(Q) $(MKDIR) -p $(workdir) + $(Q) $(MAKE) -r -f $(PX4_MK_DIR)library.mk \ + -C $(workdir) \ + LIBRARY_WORK_DIR=$(workdir) \ + LIBRARY_LIB=$@ \ + LIBRARY_MK=$(mkfile) \ + LIBRARY_NAME=$(lastword $(subst /, ,$(workdir))) \ + library + +# make a list of phony clean targets for modules +LIBRARY_CLEANS := $(foreach path,$(dir $(LIBRARY_MKFILES)),$(WORK_DIR)$(path)/clean) + +# rules to clean modules +.PHONY: $(LIBRARY_CLEANS) +$(LIBRARY_CLEANS): relpath = $(patsubst $(WORK_DIR)%,%,$@) +$(LIBRARY_CLEANS): mkfile = $(patsubst %clean,%library.mk,$(relpath)) +$(LIBRARY_CLEANS): + @$(ECHO) %% cleaning using $(mkfile) + $(Q) $(MAKE) -r -f $(PX4_MK_DIR)library.mk \ + LIBRARY_WORK_DIR=$(dir $@) \ + LIBRARY_MK=$(mkfile) \ + clean + +################################################################################ # NuttX libraries and paths ################################################################################ @@ -420,8 +468,8 @@ $(PRODUCT_BUNDLE): $(PRODUCT_BIN) $(PRODUCT_BIN): $(PRODUCT_ELF) $(call SYM_TO_BIN,$<,$@) -$(PRODUCT_ELF): $(OBJS) $(MODULE_OBJS) $(GLOBAL_DEPS) $(LINK_DEPS) $(MODULE_MKFILES) - $(call LINK,$@,$(OBJS) $(MODULE_OBJS)) +$(PRODUCT_ELF): $(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS) $(GLOBAL_DEPS) $(LINK_DEPS) $(MODULE_MKFILES) + $(call LINK,$@,$(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS)) # # Utility rules diff --git a/makefiles/library.mk b/makefiles/library.mk new file mode 100644 index 000000000..28a421fe0 --- /dev/null +++ b/makefiles/library.mk @@ -0,0 +1,169 @@ +# +# Copyright (c) 2013 PX4 Development Team. All rights reserved. +# +# 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. +# + +# +# Framework makefile for PX4 libraries +# +# This makefile is invoked by firmware.mk to build each of the linraries +# that will subsequently be linked into the firmware image. +# +# Applications are built as standard ar archives. Unlike modules, +# all public symbols in library objects are visible across the entire +# firmware stack. +# +# In general, modules should be preferred to libraries when possible. +# Libraries may also be pre-built. +# +# IMPORTANT NOTE: +# +# This makefile assumes it is being invoked in the library's output directory. +# + +# +# Variables that can be set by the library's library.mk: +# +# +# SRCS (optional) +# +# Lists the .c, cpp and .S files that should be compiled/assembled to +# produce the library. +# +# PREBUILT_LIB (optional) +# +# Names the prebuilt library in the source directory that should be +# linked into the firmware. +# +# INCLUDE_DIRS (optional, must be appended, ignored if SRCS not set) +# +# The list of directories searched for include files. If non-standard +# includes (e.g. those from another module) are required, paths to search +# can be added here. +# +# + +# +# Variables visible to the library's library.mk: +# +# CONFIG +# BOARD +# LIBRARY_WORK_DIR +# LIBRARY_LIB +# LIBRARY_MK +# Anything set in setup.mk, board_$(BOARD).mk and the toolchain file. +# Anything exported from config_$(CONFIG).mk +# + +################################################################################ +# No user-serviceable parts below. +################################################################################ + +ifeq ($(LIBRARY_MK),) +$(error No library makefile specified) +endif +$(info %% LIBRARY_MK = $(LIBRARY_MK)) + +# +# Get the board/toolchain config +# +include $(PX4_MK_DIR)/board_$(BOARD).mk + +# +# Get the library's config +# +include $(LIBRARY_MK) +LIBRARY_SRC := $(dir $(LIBRARY_MK)) +$(info % LIBRARY_NAME = $(LIBRARY_NAME)) +$(info % LIBRARY_SRC = $(LIBRARY_SRC)) +$(info % LIBRARY_LIB = $(LIBRARY_LIB)) +$(info % LIBRARY_WORK_DIR = $(LIBRARY_WORK_DIR)) + +# +# Things that, if they change, might affect everything +# +GLOBAL_DEPS += $(MAKEFILE_LIST) + +################################################################################ +# Build rules +################################################################################ + +# +# What we're going to build +# +library: $(LIBRARY_LIB) + +ifneq ($(PREBUILT_LIB),) + +VPATH = $(LIBRARY_SRC) +$(LIBRARY_LIB): $(PREBUILT_LIB) $(GLOBAL_DEPS) + @$(ECHO) "PREBUILT: $(PREBUILT_LIB)" + $(Q) $(COPY) $< $@ + +else + +## +## Object files we will generate from sources +## + +OBJS = $(addsuffix .o,$(SRCS)) + +# +# SRCS -> OBJS rules +# + +$(OBJS): $(GLOBAL_DEPS) + +vpath %.c $(LIBRARY_SRC) +$(filter %.c.o,$(OBJS)): %.c.o: %.c $(GLOBAL_DEPS) + $(call COMPILE,$<,$@) + +vpath %.cpp $(LIBRARY_SRC) +$(filter %.cpp.o,$(OBJS)): %.cpp.o: %.cpp $(GLOBAL_DEPS) + $(call COMPILEXX,$<,$@) + +vpath %.S $(LIBRARY_SRC) +$(filter %.S.o,$(OBJS)): %.S.o: %.S $(GLOBAL_DEPS) + $(call ASSEMBLE,$<,$@) + +# +# Built product rules +# + +$(LIBRARY_LIB): $(OBJS) $(GLOBAL_DEPS) + $(call ARCHIVE,$@,$(OBJS)) + +endif + +# +# Utility rules +# + +clean: + $(Q) $(REMOVE) $(LIBRARY_LIB) $(OBJS) diff --git a/makefiles/module.mk b/makefiles/module.mk index db6f4e15e..9e4cbafc9 100644 --- a/makefiles/module.mk +++ b/makefiles/module.mk @@ -35,7 +35,7 @@ # 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 +# Modules 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. # @@ -183,30 +183,15 @@ 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 # -#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 # -## -## Object files we will generate from sources -## -#OBJS := $(foreach src,$(ABS_SRCS),$(MODULE_WORK_DIR)$(src).o) +OBJS = $(addsuffix .o,$(SRCS)) -OBJS = $(addsuffix .o,$(SRCS)) -$(info SRCS $(SRCS)) -$(info OBJS $(OBJS)) +# +# Dependency files that will be auto-generated +# +DEPS = $(addsuffix .d,$(SRCS)) # # SRCS -> OBJS rules @@ -239,3 +224,5 @@ $(MODULE_OBJ): $(OBJS) $(GLOBAL_DEPS) clean: $(Q) $(REMOVE) $(MODULE_PRELINK) $(OBJS) + +-include $(DEPS) diff --git a/makefiles/toolchain_gnu-arm-eabi.mk b/makefiles/toolchain_gnu-arm-eabi.mk index 874e7154c..eeba0ff2c 100644 --- a/makefiles/toolchain_gnu-arm-eabi.mk +++ b/makefiles/toolchain_gnu-arm-eabi.mk @@ -235,7 +235,7 @@ endef define LINK @$(ECHO) "LINK: $1" @$(MKDIR) -p $(dir $1) - $(Q) $(LD) $(LDFLAGS) -o $1 --start-group $2 $(LIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group + $(Q) $(LD) $(LDFLAGS) -Map $1.map -o $1 --start-group $2 $(LIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group endef # Convert $1 from a linked object to a raw binary in $2 @@ -280,6 +280,7 @@ define BIN_TO_OBJ $(Q) $(OBJCOPY) $2 \ --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 + --strip-symbol $(call BIN_SYM_PREFIX,$1)_end \ + --rename-section .data=.rodata $(Q) $(REMOVE) $2.c $2.c.o endef |