2014-05-15 17:12:42 +02:00
|
|
|
ifeq (, $(__RIOTBUILD_FLAG))
|
|
|
|
$(error You cannot build a module on its own. Use "make" in your application's directory instead.)
|
|
|
|
endif
|
|
|
|
|
2014-06-18 11:21:05 +02:00
|
|
|
unexport DIRS
|
2014-11-11 09:20:37 +01:00
|
|
|
DIRS := $(sort $(abspath ${DIRS}))
|
2014-06-18 11:21:05 +02:00
|
|
|
|
2014-06-17 03:34:17 +02:00
|
|
|
MODULE ?= $(shell basename $(CURDIR))
|
|
|
|
|
2014-06-18 11:00:33 +02:00
|
|
|
.PHONY: all ${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:
|
|
|
|
@:
|
|
|
|
|
|
|
|
clean:: ${DIRS:%=CLEAN--%}
|
|
|
|
|
|
|
|
${DIRS:%=ALL--%}:
|
2016-12-22 12:18:38 +01:00
|
|
|
$(QQ)"$(MAKE)" -C ${@:ALL--%=%}
|
2014-06-18 11:00:33 +02:00
|
|
|
|
|
|
|
${DIRS:%=CLEAN--%}:
|
2016-12-22 12:18:38 +01:00
|
|
|
$(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))
|
|
|
|
# don't use *.c as SRC if SRC is empty (e.g., no module selected)
|
|
|
|
NO_AUTO_SRC := 1
|
|
|
|
|
|
|
|
# allow different submodule basename (e.g., MODULE=cpu_periph_common, but match just periph_%)
|
|
|
|
BASE_MODULE ?= $(MODULE)
|
|
|
|
|
|
|
|
# for each $(BASE_MODULE)_<name> in USEMODULE, add <name>.c to SRC
|
|
|
|
SRC += $(patsubst $(BASE_MODULE)_%,%.c,$(filter $(BASE_MODULE)_%,$(USEMODULE)))
|
|
|
|
|
|
|
|
# don't fail if a selected *.c file does not exist
|
|
|
|
ifeq (1, $(SUBMODULES_NOFORCE))
|
|
|
|
SRC := $(filter $(SRC), $(wildcard *.c))
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2017-03-22 11:04:41 +01:00
|
|
|
ifeq ($(strip $(SRC))$(NO_AUTO_SRC),)
|
2016-08-10 16:03:53 +02: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),)
|
2014-08-13 20:46:47 +02:00
|
|
|
SRCXX := $(wildcard *.cpp)
|
|
|
|
endif
|
2017-03-22 11:04:41 +01:00
|
|
|
ifeq ($(strip $(ASMSRC))$(NO_AUTO_SRC),)
|
2014-08-13 20:46:47 +02:00
|
|
|
ASMSRC := $(wildcard *.s)
|
|
|
|
endif
|
2017-03-22 11:04:41 +01:00
|
|
|
ifeq ($(strip $(ASSMSRC))$(NO_AUTO_SRC),)
|
2014-08-13 20:46:47 +02:00
|
|
|
ASSMSRC := $(wildcard *.S)
|
2014-06-25 03:17:20 +02:00
|
|
|
endif
|
|
|
|
|
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)
|
2016-10-18 23:27:59 +02:00
|
|
|
OBJCXX := $(SRCXX:%.cpp=$(BINDIR)/$(MODULE)/%.o)
|
|
|
|
ASMOBJ := $(ASMSRC:%.s=$(BINDIR)/$(MODULE)/%.o)
|
|
|
|
ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)/$(MODULE)/%.o)
|
2014-06-25 03:17:20 +02:00
|
|
|
|
2014-08-13 20:46:47 +02:00
|
|
|
OBJ := $(OBJC) $(OBJCXX) $(ASMOBJ) $(ASSMOBJ)
|
|
|
|
DEP := $(OBJC:.o=.d) $(OBJCXX:.o=.d) $(ASSMOBJ:.o=.d)
|
2013-02-06 13:20:21 +01:00
|
|
|
|
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
|
|
|
|
2016-10-18 23:27:59 +02:00
|
|
|
$(BINDIR)/$(MODULE).a: $(OBJ) | ${DIRS:%=ALL--%}
|
2016-12-17 01:16:59 +01:00
|
|
|
$(Q)$(AR) $(ARFLAGS) $@ $?
|
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)
|
|
|
|
|
2016-10-18 23:27:59 +02:00
|
|
|
$(OBJC): $(BINDIR)/$(MODULE)/%.o: %.c $(RIOTBUILD_CONFIG_HEADER_C)
|
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 $<)\" \
|
|
|
|
$(CFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
|
2013-02-06 13:20:21 +01:00
|
|
|
|
2016-10-18 23:27:59 +02:00
|
|
|
$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C)
|
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 $<)\" \
|
2016-12-21 13:05:15 +01:00
|
|
|
$(CXXFLAGS) $(CXXINCLUDES) $(INCLUDES) -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
|
|
|
|
2016-10-18 23:27:59 +02:00
|
|
|
$(ASSMOBJ): $(BINDIR)/$(MODULE)/%.o: %.S
|
2017-03-01 11:24:11 +01:00
|
|
|
$(Q)$(CCAS) $(CCASFLAGS) $(INCLUDES) -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)
|