aboutsummaryrefslogtreecommitdiff
path: root/makefiles/module.mk
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2013-05-11 11:32:05 -0700
committerpx4dev <px4@purgatory.org>2013-05-11 11:32:05 -0700
commit196ee8b16fcd42fca04d1fb7e11ec46dd45c8421 (patch)
treee6e4b9c4f601cc7fa4981f4ad83bd4ec7cefce02 /makefiles/module.mk
parent15aae728e5bba7ac255e2f0266d39c5e9d95fc6a (diff)
downloadpx4-firmware-196ee8b16fcd42fca04d1fb7e11ec46dd45c8421.tar.gz
px4-firmware-196ee8b16fcd42fca04d1fb7e11ec46dd45c8421.tar.bz2
px4-firmware-196ee8b16fcd42fca04d1fb7e11ec46dd45c8421.zip
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.
Diffstat (limited to 'makefiles/module.mk')
-rw-r--r--makefiles/module.mk51
1 files changed, 31 insertions, 20 deletions
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 <command>_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,$<,$@)
#