build: add support for PKG_SUBDIRS variable
authorMichael Pratt <mcpratt@pm.me>
Thu, 20 Jun 2024 04:23:39 +0000 (00:23 -0400)
committerRobert Marko <robimarko@gmail.com>
Mon, 8 Jul 2024 06:49:42 +0000 (08:49 +0200)
Add support for overriding the SUBDIRS variable while invoking Make
by defining it after Make in the command line.

This is useful for builds that have previously patched out
the building of certain subdirectories in projects
that use recursive and independent Makefiles,
for example, to block the building of docs or test suites.

The wildcard function is used in the case of there being
subdirectories within any of the subdirectories,
for example, in the building of gengetopt,
in order to avoid the problem where Make will attempt
to execute a Makefile in a subdirectory that does not exist
within the subdirectory it is currently running from
because it really exists at the top-level, or one that exists
within one of the subdirectories when ran from top-level.
There are also cases where the Makefiles in the subdirectories
have the recursive building rules even though there are no more
subdirectories beyond that point, for example, with gnulib.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
Link: https://github.com/openwrt/openwrt/pull/15853
Signed-off-by: Robert Marko <robimarko@gmail.com>
include/host-build.mk
include/package-defaults.mk
include/package.mk

index 246f248e26eecf344bb0e86725fa00ec327f20fe..7e64fc16fe30bfda567cb9ee8bc3041c9ed80f4a 100644 (file)
@@ -110,11 +110,11 @@ define Host/Compile/Default
 endef
 
 define Host/Compile
-  $(call Host/Compile/Default)
+  $(call Host/Compile/Default,$(if $(PKG_SUBDIRS),SUBDIRS='$$$$(wildcard $(PKG_SUBDIRS))'))
 endef
 
 define Host/Install/Default
-       $(call Host/Compile/Default,install)
+  $(call Host/Compile/Default,$(if $(PKG_SUBDIRS),SUBDIRS='$$$$(wildcard $(PKG_SUBDIRS))') install)
 endef
 
 define Host/Install
index 37de9f0ccbacd73d19d98ca0fe0aaf00aa4b35df..6a401dde2c9ea543158c3ce0ab7d3fc1b6acf898 100644 (file)
@@ -151,6 +151,7 @@ define Build/Install/Default
        $(MAKE_VARS) \
        $(MAKE) -C $(PKG_BUILD_DIR)/$(MAKE_PATH) \
                $(MAKE_INSTALL_FLAGS) \
+               $(if $(PKG_SUBDIRS),SUBDIRS='$$$$(wildcard $(PKG_SUBDIRS))') \
                $(if $(1), $(1), install);
 endef
 
index 8ee78415df24c1bc568e9d6364ef1a422360bf9a..7fbecf98dc7c9a5b11ce1958e254578f7e4d9c73 100644 (file)
@@ -343,7 +343,7 @@ endef
 
 Build/Prepare=$(call Build/Prepare/Default,)
 Build/Configure=$(call Build/Configure/Default,)
-Build/Compile=$(call Build/Compile/Default,)
+Build/Compile=$(call Build/Compile/Default,$(if $(PKG_SUBDIRS),SUBDIRS='$$$$(wildcard $(PKG_SUBDIRS))'))
 Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
 Build/Dist=$(call Build/Dist/Default,)
 Build/DistCheck=$(call Build/DistCheck/Default,)