2014-05-15 17:12:42 +02:00
|
|
|
ifeq (, $(__RIOTBUILD_FLAG))
|
2017-11-03 13:51:51 +01:00
|
|
|
$(error You cannot build a module on its own. Use "make" in your application's directory instead.)
|
2014-05-15 17:12:42 +02:00
|
|
|
endif
|
|
|
|
|
2019-11-14 12:12:18 +01:00
|
|
|
#
|
|
|
|
# enable second expansion of prerequisites.
|
|
|
|
#
|
|
|
|
# Doing that here enables it globally for all modules and the application.
|
|
|
|
#
|
|
|
|
# See https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
|
|
|
|
# for what it can be used for.
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
|
2014-06-18 11:21:05 +02:00
|
|
|
unexport DIRS
|
2018-03-22 16:20:19 +01:00
|
|
|
DIRS := $(sort $(abspath $(DIRS)))
|
2014-06-18 11:21:05 +02:00
|
|
|
|
2020-02-04 13:13:22 +01:00
|
|
|
_MOD := $(shell basename $(CURDIR))
|
|
|
|
MODULE ?= $(_MOD)
|
2014-06-17 03:34:17 +02:00
|
|
|
|
2018-08-22 15:57:59 +02:00
|
|
|
.PHONY: all clean $(DIRS:%=ALL--%) $(DIRS:%=CLEAN--%)
|
2014-06-17 04:01:10 +02:00
|
|
|
|
2016-10-18 23:27:59 +02:00
|
|
|
all: $(BINDIR)/$(MODULE).a ..nothing
|
2014-06-18 11:00:33 +02:00
|
|
|
|
|
|
|
..nothing:
|
|
|
|
@:
|
|
|
|
|
2018-03-22 16:20:19 +01:00
|
|
|
clean:: $(DIRS:%=CLEAN--%)
|
2014-06-18 11:00:33 +02:00
|
|
|
|
2018-03-22 16:20:19 +01:00
|
|
|
$(DIRS:%=ALL--%):
|
|
|
|
$(QQ)"$(MAKE)" -C $(@:ALL--%=%)
|
2014-06-18 11:00:33 +02:00
|
|
|
|
2018-03-22 16:20:19 +01:00
|
|
|
$(DIRS:%=CLEAN--%):
|
|
|
|
$(QQ)"$(MAKE)" -C $(@:CLEAN--%=%) clean
|
2014-06-17 04:01:10 +02:00
|
|
|
|
2017-03-22 15:51:36 +01:00
|
|
|
## submodules
|
|
|
|
ifeq (1, $(SUBMODULES))
|
2017-11-03 13:51:51 +01:00
|
|
|
# don't use *.c as SRC if SRC is empty (e.g., no module selected)
|
|
|
|
NO_AUTO_SRC := 1
|
2017-03-22 15:51:36 +01:00
|
|
|
|
2017-11-03 13:51:51 +01:00
|
|
|
# allow different submodule basename (e.g., MODULE=cpu_periph_common, but match just periph_%)
|
|
|
|
BASE_MODULE ?= $(MODULE)
|
2017-03-22 15:51:36 +01:00
|
|
|
|
2017-11-03 13:51:51 +01:00
|
|
|
# for each $(BASE_MODULE)_<name> in USEMODULE, add <name>.c to SRC
|
2019-02-08 12:08:38 +01:00
|
|
|
SRC += $(wildcard $(patsubst $(BASE_MODULE)_%,%.c,$(filter $(BASE_MODULE)_%,$(USEMODULE))))
|
2017-03-22 15:51:36 +01:00
|
|
|
|
2017-11-03 13:51:51 +01:00
|
|
|
# don't fail if a selected *.c file does not exist
|
|
|
|
ifeq (1, $(SUBMODULES_NOFORCE))
|
|
|
|
SRC := $(filter $(SRC), $(wildcard *.c))
|
|
|
|
endif
|
2017-03-22 15:51:36 +01:00
|
|
|
endif
|
|
|
|
|
2019-11-29 14:02:00 +01:00
|
|
|
# By default consider C++ files has a .cpp extension
|
|
|
|
SRCXXEXT ?= cpp
|
|
|
|
|
2017-03-22 11:04:41 +01:00
|
|
|
ifeq ($(strip $(SRC))$(NO_AUTO_SRC),)
|
2017-11-03 13:51:51 +01:00
|
|
|
SRC := $(filter-out $(SRC_NOLTO), $(wildcard *.c))
|
2013-10-29 16:26:42 +01:00
|
|
|
endif
|
2017-03-22 11:04:41 +01:00
|
|
|
ifeq ($(strip $(SRCXX))$(NO_AUTO_SRC),)
|
2019-11-29 14:03:02 +01:00
|
|
|
SRCXX := $(filter-out $(SRCXXEXCLUDE),$(wildcard *.$(SRCXXEXT)))
|
2014-08-13 20:46:47 +02:00
|
|
|
endif
|
2017-03-22 11:04:41 +01:00
|
|
|
ifeq ($(strip $(ASMSRC))$(NO_AUTO_SRC),)
|
2017-11-03 13:51:51 +01:00
|
|
|
ASMSRC := $(wildcard *.s)
|
2014-08-13 20:46:47 +02:00
|
|
|
endif
|
2017-03-22 11:04:41 +01:00
|
|
|
ifeq ($(strip $(ASSMSRC))$(NO_AUTO_SRC),)
|
2017-11-03 13:51:51 +01:00
|
|
|
ASSMSRC := $(wildcard *.S)
|
2014-06-25 03:17:20 +02:00
|
|
|
endif
|
|
|
|
|
2018-09-16 14:48:35 +02:00
|
|
|
# include makefile snippets for packages in $(USEPKG) that modify GENSRC:
|
|
|
|
-include $(USEPKG:%=$(RIOTPKG)/%/Makefile.gensrc)
|
2018-09-14 13:53:24 +02:00
|
|
|
|
|
|
|
GENOBJC := $(GENSRC:%.c=%.o)
|
2016-10-18 23:27:59 +02:00
|
|
|
OBJC_LTO := $(SRC:%.c=$(BINDIR)/$(MODULE)/%.o)
|
|
|
|
OBJC_NOLTO := $(SRC_NOLTO:%.c=$(BINDIR)/$(MODULE)/%.o)
|
2016-08-10 16:03:53 +02:00
|
|
|
OBJC := $(OBJC_NOLTO) $(OBJC_LTO)
|
2019-11-29 14:02:00 +01:00
|
|
|
OBJCXX := $(SRCXX:%.$(SRCXXEXT)=$(BINDIR)/$(MODULE)/%.o)
|
2016-10-18 23:27:59 +02:00
|
|
|
ASMOBJ := $(ASMSRC:%.s=$(BINDIR)/$(MODULE)/%.o)
|
|
|
|
ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)/$(MODULE)/%.o)
|
2014-06-25 03:17:20 +02:00
|
|
|
|
2018-09-14 13:53:24 +02:00
|
|
|
OBJ := $(OBJC) $(OBJCXX) $(ASMOBJ) $(ASSMOBJ) $(GENOBJC)
|
2014-08-13 20:46:47 +02:00
|
|
|
DEP := $(OBJC:.o=.d) $(OBJCXX:.o=.d) $(ASSMOBJ:.o=.d)
|
2013-02-06 13:20:21 +01:00
|
|
|
|
2019-07-19 12:19:53 +02:00
|
|
|
include $(RIOTMAKE)/blob.inc.mk
|
|
|
|
|
2016-10-18 23:27:59 +02:00
|
|
|
$(BINDIR)/$(MODULE)/:
|
2016-12-17 01:16:59 +01:00
|
|
|
$(Q)mkdir -p $@
|
2014-08-13 20:23:08 +02:00
|
|
|
|
2016-10-18 23:27:59 +02:00
|
|
|
$(BINDIR)/$(MODULE).a $(OBJ): | $(BINDIR)/$(MODULE)/
|
2014-09-27 11:29:11 +02:00
|
|
|
|
2019-09-16 13:14:42 +02:00
|
|
|
# Build the archive from the output directory to create relative thin archives
|
|
|
|
# This allows having them valid in and outside of docker
|
2018-03-22 16:20:19 +01:00
|
|
|
$(BINDIR)/$(MODULE).a: $(OBJ) | $(DIRS:%=ALL--%)
|
2017-11-03 17:53:00 +01:00
|
|
|
@# Recreate archive to cleanup deleted/non selected source files objects
|
|
|
|
$(Q)$(RM) $@
|
2019-09-16 13:14:42 +02:00
|
|
|
$(Q)cd $(@D) && $(AR) $(ARFLAGS) $(@F) $(subst $(@D)/,,$^)
|
2014-09-27 11:29:11 +02:00
|
|
|
|
2014-08-13 20:41:48 +02:00
|
|
|
CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS)
|
2017-03-01 11:24:11 +01:00
|
|
|
CCASFLAGS = $(filter-out $(CCASUWFLAGS), $(CFLAGS)) $(CCASEXFLAGS)
|
2013-02-06 13:20:21 +01:00
|
|
|
|
2014-06-18 23:25:07 +02:00
|
|
|
# compile and generate dependency info
|
2014-08-13 20:41:48 +02:00
|
|
|
|
2016-08-10 16:03:53 +02:00
|
|
|
$(OBJC_LTO): CFLAGS+=$(LTOFLAGS)
|
|
|
|
|
2019-12-18 09:39:34 +01:00
|
|
|
# Define dependencies for object files
|
|
|
|
OBJ_DEPS += $(RIOTBUILD_CONFIG_HEADER_C)
|
|
|
|
ifneq (,$(SHOULD_RUN_KCONFIG))
|
|
|
|
OBJ_DEPS += $(KCONFIG_GENERATED_AUTOCONF_HEADER_C)
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(OBJC): $(BINDIR)/$(MODULE)/%.o: %.c $(OBJ_DEPS)
|
2016-12-17 01:16:59 +01:00
|
|
|
$(Q)$(CCACHE) $(CC) \
|
2015-05-11 15:42:59 +02:00
|
|
|
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \
|
|
|
|
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
|
2019-11-28 15:34:20 +01:00
|
|
|
$(CFLAGS) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $(abspath $<)
|
2013-02-06 13:20:21 +01:00
|
|
|
|
2019-12-18 09:39:34 +01:00
|
|
|
$(GENOBJC): %.o: %.c $(OBJ_DEPS)
|
2018-09-14 13:53:24 +02:00
|
|
|
$(Q) $(CCACHE) $(CC) \
|
|
|
|
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$<)\" \
|
|
|
|
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
|
2019-11-28 15:34:20 +01:00
|
|
|
$(CFLAGS) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $<
|
2018-09-14 13:53:24 +02:00
|
|
|
|
2019-12-18 09:39:34 +01:00
|
|
|
$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.$(SRCXXEXT) $(OBJ_DEPS)
|
2016-12-17 01:16:59 +01:00
|
|
|
$(Q)$(CCACHE) $(CXX) \
|
2015-05-11 15:42:59 +02:00
|
|
|
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \
|
|
|
|
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
|
2019-11-28 15:34:20 +01:00
|
|
|
$(CXXFLAGS) $(CXXINCLUDES) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $(abspath $<)
|
2014-06-25 03:17:20 +02:00
|
|
|
|
2016-10-18 23:27:59 +02:00
|
|
|
$(ASMOBJ): $(BINDIR)/$(MODULE)/%.o: %.s
|
2016-12-17 01:16:59 +01:00
|
|
|
$(Q)$(AS) $(ASFLAGS) -o $@ $(abspath $<)
|
2013-02-06 13:20:21 +01:00
|
|
|
|
2019-12-18 09:39:34 +01:00
|
|
|
$(ASSMOBJ): $(BINDIR)/$(MODULE)/%.o: %.S $(OBJ_DEPS)
|
2019-11-28 15:34:20 +01:00
|
|
|
$(Q)$(CCAS) $(CCASFLAGS) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $(abspath $<)
|
2014-08-13 20:41:48 +02:00
|
|
|
|
|
|
|
# pull in dependency info for *existing* .o files
|
|
|
|
# deleted header files will be silently ignored
|
2014-08-13 20:46:47 +02:00
|
|
|
-include $(DEP)
|