[PATCH v2] tools: Restore built-in rules for subdirectory tool compilation

Riwen Lu <[email protected]> Wed, 2 Apr 2025 15:52:53 +0800
Newsgroups gmane.linux.acpi.devel,gmane.linux.kernel.firewire.devel,gmane.linux.kernel
Message-ID <[email protected]>
Prior to commit d1d096312176 ("tools: fix annoying "mkdir -p ..." logs
when building tools in parallel"), the top-level MAKEFLAGS=-rR
(disabling built-in rules/variables) was overridden by
subdirectory-specific MAKEFLAGS during tools compilation. This allowed
tools like pfrut and firewire to implicitly rely on Make's built-in rules.

After the aforementioned commit, the -rR flags from the top-level
Makefile began propagating to subdirectory builds. This broke tools
depending on implicit rules because:
1. -r (--no-builtin-rules) disabled implicit .c -> .o rules
2. -R (--no-builtin-variables) hid critical implicit variables like CC

Fix this by filtering out -rR from MAKEFLAGS.

Fixes: d1d096312176 ("tools: fix annoying "mkdir -p ..." logs when building tools in parallel")
Reported-by: k2ci <[email protected]>
Signed-off-by: Riwen Lu <[email protected]>
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index d138b17b8840..abf9cfebaf4f 100644
--- a/Makefile
+++ b/Makefile
@@ -1431,11 +1431,11 @@ endif
 
 tools/: FORCE
 	$(Q)mkdir -p $(objtree)/tools
-	$(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
+	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter-out rR,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
 
 tools/%: FORCE
 	$(Q)mkdir -p $(objtree)/tools
-	$(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
+	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter-out rR,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
 
 # ---------------------------------------------------------------------------
 # Kernel selftest
-- 
2.25.1