From d8a264312c5a4efab31d670ae55b120fa62c13ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Mon, 18 Jun 2018 17:52:48 +0200 Subject: [PATCH 1/3] Makefile.include: process 'modules.inc.mk' before using BASELIBS Build targets were using the immediate value of '$(BASELIBS)' before it was actually set. bindist.inc.mk should also be processed before as it is adding `BIN_USEMODULE` to `USEMODULE`. This fixes use before define problems for: * `make -C examples/hello-world` * `make -C examples/bindist` --- Makefile.include | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile.include b/Makefile.include index 4d7da693b516..45f1ff95ab2a 100644 --- a/Makefile.include +++ b/Makefile.include @@ -310,6 +310,14 @@ APPLICATION_MODULE ?= application_$(APPLICATION) BASELIBS += $(BINDIR)/$(APPLICATION_MODULE).a BASELIBS += $(APPDEPS) + +# include bindist target +include $(RIOTMAKE)/bindist.inc.mk + +# Add all USEMODULE modules to CFLAGS and populate BASELIBS +include $(RIOTMAKE)/modules.inc.mk + + .PHONY: all link clean flash flash-only term doc debug debug-server reset objdump help info-modules .PHONY: print-size elffile binfile hexfile .PHONY: ..in-docker-container @@ -603,12 +611,6 @@ endif # Include desvirt Makefile include $(RIOTTOOLS)/desvirt/Makefile.desvirt -# include bindist target -include $(RIOTMAKE)/bindist.inc.mk - -# Add all USEMODULE modules to CFLAGS -include $(RIOTMAKE)/modules.inc.mk - # Build a header file with all common macro definitions and undefinitions # make it phony to force re-run of the script every time even if the file exists # The script will only touch the file if anything has changed since last time. From fb27a801afe1a9d8a2222c060f146b6d04e7f9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 20 Jun 2018 19:08:19 +0200 Subject: [PATCH 2/3] Makefile.include: process pkg/*/Makefile.include before using BASELIBS They can define PSEUDOMODULES which is used to populate BASELIBS. It means they must be processed before using BASELIBS immediate value. This moved the processing of all `Makefile.include` before using `BASELIBS`. It is also moved before setting `BASELIBS` in `modules.inc.mk to keep the order logical (it would work anyway thanks to deferred variables evaluation). This fixes the problems for `make -C tests/unittests` --- Makefile.include | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Makefile.include b/Makefile.include index 45f1ff95ab2a..49eb367a2c15 100644 --- a/Makefile.include +++ b/Makefile.include @@ -311,6 +311,25 @@ BASELIBS += $(BINDIR)/$(APPLICATION_MODULE).a BASELIBS += $(APPDEPS) +# add extra include paths for packages in $(USEMODULE) +export USEMODULE_INCLUDES = + +include $(RIOTBASE)/sys/Makefile.include +include $(RIOTBASE)/drivers/Makefile.include + +# include Makefile.includes for packages in $(USEPKG) +$(RIOTPKG)/%/Makefile.include:: + $(Q)"$(MAKE)" -C $(RIOTPKG)/$* Makefile.include + +$(info $(USEPKG:%=$(RIOTPKG)/%/Makefile.include)) +.PHONY: $(USEPKG:%=$(RIOTPKG)/%/Makefile.include) +-include $(USEPKG:%=$(RIOTPKG)/%/Makefile.include) + +USEMODULE_INCLUDES_ = $(shell echo $(USEMODULE_INCLUDES) | tr ' ' '\n' | awk '!a[$$0]++' | tr '\n' ' ') + +INCLUDES += $(USEMODULE_INCLUDES_:%=-I%) + + # include bindist target include $(RIOTMAKE)/bindist.inc.mk @@ -399,28 +418,11 @@ endef @$(COLOR_ECHO) '$(COLOR_GREEN)Building application "$(APPLICATION)" for "$(BOARD)" with MCU "$(MCU)".$(COLOR_RESET)' @$(COLOR_ECHO) -# add extra include paths for packages in $(USEMODULE) -export USEMODULE_INCLUDES = - -include $(RIOTBASE)/sys/Makefile.include -include $(RIOTBASE)/drivers/Makefile.include - # The `clean` needs to be serialized before everything else. ifneq (, $(filter clean, $(MAKECMDGOALS))) all $(BASELIBS) $(USEPKG:%=$(RIOTPKG)/%/Makefile.include) $(RIOTBUILD_CONFIG_HEADER_C) pkg-prepare: clean endif -# include Makefile.includes for packages in $(USEPKG) -$(RIOTPKG)/%/Makefile.include:: - $(Q)"$(MAKE)" -C $(RIOTPKG)/$* Makefile.include - -.PHONY: $(USEPKG:%=$(RIOTPKG)/%/Makefile.include) --include $(USEPKG:%=$(RIOTPKG)/%/Makefile.include) - -USEMODULE_INCLUDES_ = $(shell echo $(USEMODULE_INCLUDES) | tr ' ' '\n' | awk '!a[$$0]++' | tr '\n' ' ') - -INCLUDES += $(USEMODULE_INCLUDES_:%=-I%) - .PHONY: pkg-prepare $(USEPKG:%=$(BINDIR)/%.a) pkg-prepare: -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i prepare ; done From 90fdd091767ed8674846dd99ba505d58977b2b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 20 Jun 2018 18:59:21 +0200 Subject: [PATCH 3/3] Makefile.include: detect if BASELIBS changed after its first use --- Makefile.include | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Makefile.include b/Makefile.include index 49eb367a2c15..6ee815bd9333 100644 --- a/Makefile.include +++ b/Makefile.include @@ -362,6 +362,9 @@ LINKFLAGPREFIX ?= -Wl, DIRS += $(EXTERNAL_MODULE_DIRS) +# Save value to verify it is not modified later +_BASELIBS_VALUE_BEFORE_USAGE := $(BASELIBS) + # Linker rule $(ELFFILE): FORCE ifeq ($(BUILDOSXNATIVE),1) @@ -644,4 +647,12 @@ ifneq (all, $(.DEFAULT_GOAL)) $(error .DEFAULT_GOAL := $(.DEFAULT_GOAL)) endif + +# Detect if BASELIBS changed since its first use +ifneq ($(_BASELIBS_VALUE_BEFORE_USAGE),$(BASELIBS)) + $(warning $(sort $(filter-out $(_BASELIBS_VALUE_BEFORE_USAGE), $(BASELIBS)) \ + $(filter-out $(BASELIBS), $(_BASELIBS_VALUE_BEFORE_USAGE)))) + $(error BASELIBS value changed) +endif + endif # BOARD=none