[PATCH] kbuild: reduce output spam when building out of tree

Thomas Weißschuh posted 1 patch 1 month ago
Makefile | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
[PATCH] kbuild: reduce output spam when building out of tree
Posted by Thomas Weißschuh 1 month ago
The execution of $(call cmd,makefile) will print 'GEN Makefile' on each
build, even if the Makefile is not effectively changed.

Use a filechk command instead, so a message is only printed on changes.

The Makefile is now created even if the build is aborted due to an
unclean working tree. That should not make a difference in practice.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 Makefile | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index e944c6e71e81..fae52ab03525 100644
--- a/Makefile
+++ b/Makefile
@@ -676,14 +676,19 @@ print_env_for_makefile = \
 	echo "export KBUILD_OUTPUT = $(CURDIR)"
 endif
 
-quiet_cmd_makefile = GEN     Makefile
-      cmd_makefile = { \
+filechk_makefile = { \
 	echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \
 	$(print_env_for_makefile); \
 	echo "include $(abs_srctree)/Makefile"; \
-	} > Makefile
+	}
 
-outputmakefile:
+$(objtree)/Makefile: FORCE
+	$(call filechk,makefile)
+
+# Prevent $(srcroot)/Makefile from inhibiting the rule to run.
+PHONY += $(objtree)/Makefile
+
+outputmakefile: $(objtree)/Makefile
 ifeq ($(KBUILD_EXTMOD),)
 	@if [ -f $(srctree)/.config -o \
 		 -d $(srctree)/include/config -o \
@@ -704,7 +709,6 @@ else
 	fi
 endif
 	$(Q)ln -fsn $(srcroot) source
-	$(call cmd,makefile)
 	$(Q)test -e .gitignore || \
 	{ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
 endif

---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260213-kbuild-makefile-spam-4e72f6792dfa

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh@linutronix.de>

Re: [PATCH] kbuild: reduce output spam when building out of tree
Posted by Nicolas Schier 3 weeks, 1 day ago
On Thu, 05 Mar 2026 13:04:07 +0100, Thomas Weißschuh wrote:
> The execution of $(call cmd,makefile) will print 'GEN Makefile' on each
> build, even if the Makefile is not effectively changed.
> 
> Use a filechk command instead, so a message is only printed on changes.
> 
> The Makefile is now created even if the build is aborted due to an
> unclean working tree. That should not make a difference in practice.
> 
> [...]

Sorry for the delay, this thread slipped into my spam folder ...

but finally: Applied to kbuild/kbuild-next.git (kbuild-next-unstable), thanks!

[1/1] kbuild: reduce output spam when building out of tree
      https://git.kernel.org/kbuild/c/c9bb03ac

Please look out for regression or issue reports or other follow up
comments, as they may result in the patch/series getting dropped,
reverted or modified (e.g. trailers). Patches applied to the
kbuild-next-unstable branch are accepted pending wider testing in
linux-next and any post-commit review; they will generally be moved
to the kbuild-next branch in about a week if no issues are found.

Best regards,
-- 
Nicolas

Re: [PATCH] kbuild: reduce output spam when building out of tree
Posted by Nathan Chancellor 1 month ago
On Thu, Mar 05, 2026 at 01:04:07PM +0100, Thomas Weißschuh wrote:
> The execution of $(call cmd,makefile) will print 'GEN Makefile' on each
> build, even if the Makefile is not effectively changed.
> 
> Use a filechk command instead, so a message is only printed on changes.
> 
> The Makefile is now created even if the build is aborted due to an
> unclean working tree. That should not make a difference in practice.
> 
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  Makefile | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index e944c6e71e81..fae52ab03525 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -676,14 +676,19 @@ print_env_for_makefile = \
>  	echo "export KBUILD_OUTPUT = $(CURDIR)"
>  endif
>  
> -quiet_cmd_makefile = GEN     Makefile
> -      cmd_makefile = { \
> +filechk_makefile = { \
>  	echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \
>  	$(print_env_for_makefile); \
>  	echo "include $(abs_srctree)/Makefile"; \
> -	} > Makefile
> +	}
>  
> -outputmakefile:
> +$(objtree)/Makefile: FORCE
> +	$(call filechk,makefile)
> +
> +# Prevent $(srcroot)/Makefile from inhibiting the rule to run.
> +PHONY += $(objtree)/Makefile
> +
> +outputmakefile: $(objtree)/Makefile
>  ifeq ($(KBUILD_EXTMOD),)
>  	@if [ -f $(srctree)/.config -o \
>  		 -d $(srctree)/include/config -o \
> @@ -704,7 +709,6 @@ else
>  	fi
>  endif
>  	$(Q)ln -fsn $(srcroot) source
> -	$(call cmd,makefile)
>  	$(Q)test -e .gitignore || \
>  	{ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
>  endif
> 
> ---
> base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
> change-id: 20260213-kbuild-makefile-spam-4e72f6792dfa
> 
> Best regards,
> -- 
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
>