public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Schier <nicolas@fjasle.eu>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	David Howells <dhowells@redhat.com>
Subject: Re: [PATCH v2 1/2] kbuild: revive "Entering directory" for Make >= 4.4.1
Date: Mon, 19 Jun 2023 14:50:17 +0200	[thread overview]
Message-ID: <ZJBPCb6DmHACwwq4@buildd.core.avm.de> (raw)
In-Reply-To: <20230616145751.945864-1-masahiroy@kernel.org>

On Fri, Jun 16, 2023 at 11:57:50PM +0900, Masahiro Yamada wrote:
> With commit 9da0763bdd82 ("kbuild: Use relative path when building in
> a subdir of the source tree"), compiler messages in out-of-tree builds
> include relative paths, which are relative to the build directory, not
> the directory where make was started.
> 
> To help IDEs/editors find the source files, Kbuild lets GNU Make print
> "Entering directory ..." when it changes the working directory. It has
> been working fine for a long time, but David reported it is broken with
> the latest GNU Make.
> 
> The behavior was changed by GNU Make commit 8f9e7722ff0f ("[SV 63537]
> Fix setting -w in makefiles"). Previously, setting --no-print-directory
> to MAKEFLAGS only affected child makes, but it is now interpreted in
> the current make as soon as it is set.
> 
> [test code]
> 
>   $ cat /tmp/Makefile
>   ifneq ($(SUBMAKE),1)
>   MAKEFLAGS += --no-print-directory
>   all: ; $(MAKE) SUBMAKE=1
>   else
>   all: ; :
>   endif
> 
> [before 8f9e7722ff0f]
> 
>   $ make -C /tmp
>   make: Entering directory '/tmp'
>   make SUBMAKE=1
>   :
>   make: Leaving directory '/tmp'
> 
> [after 8f9e7722ff0f]
> 
>   $ make -C /tmp
>   make SUBMAKE=1
>   :
> 
> Previously, the effect of --no-print-directory was delayed until Kbuild
> started the directory descending, but it is no longer true with GNU Make
> 4.4.1.
> 
> This commit adds one more recursion to cater to GNU Make >= 4.4.1.
> 
> When Kbuild needs to change the working directory, __submake will be
> executed twice.
> 
>   __submake without --no-print-directory  --> show "Entering directory ..."
>   __submake with    --no-print-directory  --> parse the rest of Makefile
> 
> We end up with one more recursion than needed for GNU Make < 4.4.1, but
> I do not want to complicate the version check.
> 
> Reported-by: David Howells <dhowells@redhat.com>
> Closes: https://lore.kernel.org/all/2427604.1686237298@warthog.procyon.org.uk/
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
> Changes in v2:
>   - Fix the code. V1 did not work.
>   - Remove the version check to simplify the code

Tested-by: Nicolas Schier <n.schier@avm.de>

> 
>  Makefile | 36 ++++++++++++++++++++----------------
>  1 file changed, 20 insertions(+), 16 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index cc3fe09c4dec..916c1a7984b0 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -189,13 +189,6 @@ else
>  abs_objtree := $(CURDIR)
>  endif # ifneq ($(KBUILD_OUTPUT),)
>  
> -ifeq ($(abs_objtree),$(CURDIR))
> -# Suppress "Entering directory ..." unless we are changing the work directory.
> -MAKEFLAGS += --no-print-directory
> -else
> -need-sub-make := 1
> -endif
> -
>  this-makefile := $(lastword $(MAKEFILE_LIST))
>  abs_srctree := $(realpath $(dir $(this-makefile)))
>  
> @@ -214,6 +207,23 @@ endif
>  export abs_srctree abs_objtree
>  export sub_make_done := 1
>  
> +endif # sub_make_done
> +
> +ifeq ($(abs_objtree),$(CURDIR))
> +# Suppress "Entering directory ..." if we are at the final work directory.
> +no-print-directory := --no-print-directory
> +else
> +# Recursion to show "Entering directory ..."
> +need-sub-make := 1
> +endif
> +
> +ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)
> +# If --no-print-directory is unset, recurse once again to set it.
> +# You may end up with recursing into __sub-make twice. This is due to the
> +# behavior change for GNU Make 4.4.1.
> +need-sub-make := 1
> +endif
> +
>  ifeq ($(need-sub-make),1)
>  
>  PHONY += $(MAKECMDGOALS) __sub-make
> @@ -223,18 +233,12 @@ $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
>  
>  # Invoke a second make in the output directory, passing relevant variables
>  __sub-make:
> -	$(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
> +	$(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \
> +	-f $(abs_srctree)/Makefile $(MAKECMDGOALS)
>  
> -endif # need-sub-make
> -endif # sub_make_done
> +else # need-sub-make
>  
>  # We process the rest of the Makefile if this is the final invocation of make
> -ifeq ($(need-sub-make),)
> -
> -# 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.
> -MAKEFLAGS += --no-print-directory
>  
>  ifeq ($(abs_srctree),$(abs_objtree))
>          # building in the source tree
> -- 
> 2.39.2
> 

  parent reply	other threads:[~2023-06-19 12:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 14:57 [PATCH v2 1/2] kbuild: revive "Entering directory" for Make >= 4.4.1 Masahiro Yamada
2023-06-16 14:57 ` [PATCH v2 2/2] kbuild: respect GNU Make -w flag Masahiro Yamada
2023-06-19 12:51   ` Nicolas Schier
2023-06-19 12:50 ` Nicolas Schier [this message]
2023-06-25  8:03 ` [PATCH v2 1/2] kbuild: revive "Entering directory" for Make >= 4.4.1 Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZJBPCb6DmHACwwq4@buildd.core.avm.de \
    --to=nicolas@fjasle.eu \
    --cc=dhowells@redhat.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox