diff --git a/Makefile.base b/Makefile.base index ab07fc5c94..00d7eb059d 100644 --- a/Makefile.base +++ b/Makefile.base @@ -104,20 +104,30 @@ ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)/$(MODULE)/%.o) OBJ := $(OBJC) $(OBJCXX) $(ASMOBJ) $(ASSMOBJ) $(GENOBJC) DEP := $(OBJC:.o=.d) $(OBJCXX:.o=.d) $(ASSMOBJ:.o=.d) +SRC_ALL := $(SRC) $(SRCXX) $(ASMSRC) $(ASSMSRC) +SUBDIRS_IN_DIRS := $(filter $(DIRS), $(abspath $(sort $(dir $(SRC_ALL))))) +ifneq (,$(SUBDIRS_IN_DIRS)) + $(warning Files of the following subdirectories are selected \ + both as RIOT modules (using DIRS) and directly as sourcefiles (using SRC): \ + $(patsubst $(CURDIR)/%,./%, $(SUBDIRS_IN_DIRS)). \ + Please select a single approach for each subfolder to prevent linking errors.) +endif +SUBDIRS := $(filter-out $(BINDIR)/$(MODULE)/, $(dir $(OBJ))) + include $(RIOTMAKE)/blob.inc.mk include $(RIOTMAKE)/tools/fixdep.inc.mk -$(BINDIR)/$(MODULE)/: +$(BINDIR)/$(MODULE)/ $(SUBDIRS): $(Q)mkdir -p $@ -OLD_OBJECTS = $(wildcard $(BINDIR)/$(MODULE)/*.o) +OLD_OBJECTS = $(wildcard $(BINDIR)/$(MODULE)/*.o $(BINDIR)/$(MODULE)/**/*.o) # do not clean objects from bindist modules ifeq (,$(filter $(MODULE),$(BIN_USEMODULE))) OBJECTS_TO_REMOVE = $(filter-out $(OBJ),$(OLD_OBJECTS)) endif -$(MODULE).module compile-commands $(OBJ): | $(BINDIR)/$(MODULE)/ +$(MODULE).module compile-commands $(OBJ): | $(BINDIR)/$(MODULE)/ $(SUBDIRS) $(MODULE).module: $(OBJ) $(if $(OBJECTS_TO_REMOVE),$(MODULE).cleanup) | $(DIRS:%=ALL--%) diff --git a/Makefile.include b/Makefile.include index 771f7cfd49..9a5f8292d4 100644 --- a/Makefile.include +++ b/Makefile.include @@ -720,6 +720,7 @@ COMPILE_COMMANDS_FLAGS ?= --clangd compile-commands: $(COMPILE_COMMANDS_PATH) %/compile_commands.json: $(BUILDDEPS) $(Q)DIRS="$(DIRS)" APPLICATION_BLOBS="$(BLOBS)" \ + APPLICATION_SRC="$(SRC)" APPLICATION_SRCXX="$(SRCXX)" APPLICATION_ASMSRC="$(ASMSRC)" APPLICATION_ASSMSRC="$(ASSMSRC)" \ "$(MAKE)" -C $(APPDIR) -f $(RIOTMAKE)/application.inc.mk compile-commands $(Q)$(RIOTTOOLS)/compile_commands/compile_commands.py $(COMPILE_COMMANDS_FLAGS) $(BINDIR) \ > $@ @@ -744,6 +745,7 @@ $(ELFFILE): $(BASELIBS) $(ARCHIVES) $(LD_SCRIPTS) $(APPLICATION_MODULE).module: pkg-build $(BUILDDEPS) $(Q)DIRS="$(DIRS)" APPLICATION_BLOBS="$(BLOBS)" \ + APPLICATION_SRC="$(SRC)" APPLICATION_SRCXX="$(SRCXX)" APPLICATION_ASMSRC="$(ASMSRC)" APPLICATION_ASSMSRC="$(ASSMSRC)" \ "$(MAKE)" -C $(APPDIR) -f $(RIOTMAKE)/application.inc.mk $(APPLICATION_MODULE).module: FORCE diff --git a/makefiles/application.inc.mk b/makefiles/application.inc.mk index 0460b057c1..274ec11445 100644 --- a/makefiles/application.inc.mk +++ b/makefiles/application.inc.mk @@ -3,17 +3,20 @@ MODULE = $(APPLICATION_MODULE) DIRS += $(RIOTCPU)/$(CPU) $(BOARDDIR) DIRS += $(RIOTBASE)/core $(RIOTBASE)/core/lib $(RIOTBASE)/drivers $(RIOTBASE)/sys -# For regular modules, adding files to BLOBS to their Makefile is sufficient to -# create the corresponding headers. +# For regular modules, adding files to BLOBS, SRC, SRCXX, ASMSRC or ASSMSRC +# in their Makefile is sufficient to explicitely set the variables. # # Application modules are different, as they use this makefile to build, thus # application level variables are not available unless exported. # -# But exporting e.g., BLOBS, would pre-set the variable for all -# submakefiles. +# But exporting would pre-set the variables for all submakefiles. # -# As workaround, $(RIOTBASE)/Makefile.include passes BLOBS to this -# Makefile as APPLICATION_BLOBS. -BLOBS = $(APPLICATION_BLOBS) +# As workaround, $(RIOTBASE)/Makefile.include passes the above-listed variables +# to this Makefile as APPLICATION_*. +BLOBS = $(APPLICATION_BLOBS) +SRC = $(APPLICATION_SRC) +SRCXX = $(APPLICATION_SRCXX) +ASMSRC = $(APPLICATION_ASMSRC) +ASSMSRC = $(APPLICATION_ASSMSRC) include $(RIOTBASE)/Makefile.base