[PATCH] kbuild: unexport sub_make_done to fix child make invocations

Simon Glass sjg at chromium.org
Sat Feb 14 03:47:34 CET 2026


The exported sub_make_done variable leaks into the environment of all
child processes. When make targets like tcheck spawn independent make
invocations with O=, those child makes inherit sub_make_done=1, skip
the KBUILD_OUTPUT setup and try to build in the source tree.

There is a workaround that resets sub_make_done to 0 for specific test
targets, but this isn't great since it has tolist every target that
spawns independent make invocations.

Instead, unexport sub_make_done once we are in the final make
invocation. The direct sub-make already has the value in its
environment from the export, and no further propagation is needed.
This also allows the per-target workaround to be removed.

Fixes: 27529f1cb02d ("kbuild: skip parsing pre sub-make code for recursion")
Signed-off-by: Simon Glass <simon.glass at canonical.com>
---

 Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index d38fa5d6aca..f539c6f82f3 100644
--- a/Makefile
+++ b/Makefile
@@ -194,6 +194,10 @@ endif # sub_make_done
 # We process the rest of the Makefile if this is the final invocation of make
 ifeq ($(need-sub-make),)
 
+# Do not propagate sub_make_done to non-submake children (e.g. test scripts
+# that invoke make separately with O= need to process the KBUILD_OUTPUT block)
+unexport sub_make_done
+
 # Do not print "Entering directory ...",
 # but we want to display it when entering to the output directory
 # so that IDEs/editors are able to understand relative filenames.
@@ -2738,10 +2742,6 @@ help:
 	@echo  'Execute "make" or "make all" to build all targets marked with [*] '
 	@echo  'For further info see the ./README file'
 
-ifneq ($(filter tests pcheck qcheck tcheck,$(MAKECMDGOALS)),)
-export sub_make_done := 0
-endif
-
 tests check:
 	$(srctree)/test/run
 
-- 
2.43.0

base-commit: eae0ca2125933c3d1742deba723d2cc4b4955ef0
branch: fix-kbuild


More information about the U-Boot mailing list