Re: [PATCH] kbuild: reduce output spam when building out of tree
From: Nathan Chancellor
Date: Mon Mar 09 2026 - 21:15:48 EST
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@xxxxxxxxxxxxx>
Reviewed-by: Nathan Chancellor <nathan@xxxxxxxxxx>
Tested-by: Nathan Chancellor <nathan@xxxxxxxxxx>
> ---
> 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@xxxxxxxxxxxxx>
>