From 140824e69c763f3694d9cad64904909cf2a85853 Mon Sep 17 00:00:00 2001 From: NikLeberg Date: Sat, 22 Jan 2022 20:48:28 +0000 Subject: [PATCH] buildsystem/pkg: expand paths early --- Makefile.base | 4 ++-- Makefile.dep | 2 +- Makefile.include | 25 ++++++++++++++----------- makefiles/dependency_resolution.inc.mk | 4 ++++ makefiles/vars.inc.mk | 1 + 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Makefile.base b/Makefile.base index 0132e8c7e7db..cfc060c97348 100644 --- a/Makefile.base +++ b/Makefile.base @@ -97,8 +97,8 @@ compile-commands: | $(DIRS:%=COMPILE-COMMANDS--%) $(file >>$(BINDIR)/$(MODULE)/compile_cmds.txt,TARGET_ARCH: $(TARGET_ARCH)) $(file >>$(BINDIR)/$(MODULE)/compile_cmds.txt,TARGET_ARCH_LLVM: $(TARGET_ARCH_LLVM)) -# include makefile snippets for packages in $(USEPKG) that modify GENSRC: --include $(USEPKG:%=$(RIOTPKG)/%/Makefile.gensrc) +# include makefile snippets for packages in $(PKG_PATHS) that modify GENSRC: +-include $(PKG_PATHS:%=%Makefile.gensrc) GENOBJC := $(GENSRC:%.c=%.o) OBJC_LTO := $(SRC:%.c=$(BINDIR)/$(MODULE)/%.o) diff --git a/Makefile.dep b/Makefile.dep index 6e0f815619a3..4b3df3a74294 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -20,7 +20,7 @@ include $(RIOTBASE)/drivers/Makefile.dep -include $(sort $(USEMODULE:%=$(RIOTBASE)/drivers/%/Makefile.dep)) # pull dependencies from packages --include $(USEPKG:%=$(RIOTPKG)/%/Makefile.dep) +-include $(PKG_PATHS:%=%Makefile.dep) ifneq (,$(filter mpu_stack_guard,$(USEMODULE))) FEATURES_REQUIRED += cortexm_mpu diff --git a/Makefile.include b/Makefile.include index 97810cece760..e590eabef932 100644 --- a/Makefile.include +++ b/Makefile.include @@ -427,6 +427,10 @@ ifeq (1,$(TEST_KCONFIG)) USEMODULE := $(KCONFIG_MODULES) KCONFIG_PACKAGES := $(call lowercase,$(patsubst CONFIG_PACKAGE_%,%,$(filter CONFIG_PACKAGE_%,$(.VARIABLES)))) USEPKG := $(KCONFIG_PACKAGES) + + # Locate used packages in $(RIOTPKG). + PKG_PATHS := $(sort $(foreach dir,$(RIOTPKG),\ + $(foreach pkg,$(USEPKG),$(dir $(wildcard $(dir)/$(pkg)/Makefile))))) else # always select provided architecture features FEATURES_REQUIRED += $(filter arch_%,$(FEATURES_PROVIDED)) @@ -570,8 +574,8 @@ include $(RIOTBASE)/sys/Makefile.include # include Makefile.includes of each driver modules if they exist -include $(USEMODULE:%=$(RIOTBASE)/drivers/%/Makefile.include) -# include Makefile.includes for packages in $(USEPKG) --include $(USEPKG:%=$(RIOTPKG)/%/Makefile.include) +# include Makefile.includes for packages in $(PKG_PATHS) +-include $(PKG_PATHS:%=%Makefile.include) # include external modules configuration -include $(EXTERNAL_MODULE_PATHS:%=%/Makefile.include) @@ -771,31 +775,30 @@ endif # The `clean` needs to be serialized before everything else. all $(BASELIBS) $(ARCHIVES) $(BUILDDEPS) ..in-docker-container: | $(CLEAN) -.PHONY: pkg-prepare pkg-build pkg-build-% +.PHONY: pkg-prepare pkg-build pkg-prepare: - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i prepare ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) prepare $(NEWLINE)) -pkg-build: $(USEPKG:%=pkg-build-%) -pkg-build-%: $(BUILDDEPS) - $(QQ)"$(MAKE)" -C $(RIOTPKG)/$* +pkg-build: $(BUILDDEPS) + $(foreach dir,$(PKG_PATHS),$(QQ)"$(MAKE)" -C $(dir) $(NEWLINE)) clean: ifndef MAKE_RESTARTS - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i clean ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) clean $(NEWLINE)) -@rm -rf $(BINDIR) -@rm -rf $(SCANBUILD_OUTPUTDIR) endif # Remove intermediates, but keep the .elf, .hex and .map etc. clean-intermediates: - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) distclean $(NEWLINE)) -@rm -rf $(BINDIR)/*.a $(BINDIR)/*/ clean-pkg: - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) distclean $(NEWLINE)) distclean: - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) distclean $(NEWLINE)) -@rm -rf $(BINDIRBASE) # Include PROGRAMMER_FLASH/PROGRAMMER_RESET variables diff --git a/makefiles/dependency_resolution.inc.mk b/makefiles/dependency_resolution.inc.mk index a3a76223c223..55a142076c32 100644 --- a/makefiles/dependency_resolution.inc.mk +++ b/makefiles/dependency_resolution.inc.mk @@ -6,6 +6,10 @@ EXTERNAL_MODULE_PATHS := $(sort $(foreach dir,$(EXTERNAL_MODULE_DIRS),\ $(foreach mod,$(USEMODULE),$(dir $(wildcard $(dir)/$(mod)/Makefile))))) +# Locate used packages in $(RIOTPKG). +PKG_PATHS := $(sort $(foreach dir,$(RIOTPKG),\ + $(foreach pkg,$(USEPKG),$(dir $(wildcard $(dir)/$(pkg)/Makefile))))) + # Back up current state to detect changes OLD_STATE := $(USEMODULE) $(USEPKG) $(FEATURES_USED) diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index c8607d295bd1..70df740c537a 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -45,6 +45,7 @@ export BINDIR # This is the folder where the application should b export CARGO_TARGET_DIR # This is the folder where Rust parts of the application should be built in. export BUILD_DIR # This is the base folder to store common build files and artifacts, e.g. test results. export APPDIR # The base folder containing the application +export PKG_PATHS # List of absolute paths where packages of $(USEPKG) can be found export PKGDIRBASE # The base folder for building packages export PYTHONPATH # Python default search path for module filesi, with RIOT specific packages