* [PATCH v4 1/3] kbuild: set correct abs_srctree and abs_objtree for package builds
@ 2023-06-26 23:30 Masahiro Yamada
2023-06-26 23:30 ` [PATCH v4 2/3] kbuild: revive "Entering directory" for Make >= 4.4.1 Masahiro Yamada
2023-06-26 23:30 ` [PATCH v4 3/3] kbuild: respect GNU Make -w flag Masahiro Yamada
0 siblings, 2 replies; 5+ messages in thread
From: Masahiro Yamada @ 2023-06-26 23:30 UTC (permalink / raw)
To: linux-kbuild
Cc: linux-kernel, Masahiro Yamada, Nathan Chancellor,
Nick Desaulniers, Nicolas Schier
When you run 'make rpm-pkg', the rpmbuild tool builds the kernel in
rpmbuild/BUILD, but $(abs_srctree) and $(abs_objtree) point to the
directory path where make was started, not the kernel is actually
being built. The same applies to 'make snap-pkg'. Fix it.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
Changes in v4:
- Export abs_{src,obj}tree again
Changes in v3:
- New patch
Makefile | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index f18d59c81241..70b314059d8b 100644
--- a/Makefile
+++ b/Makefile
@@ -38,6 +38,10 @@ __all:
# descending is started. They are now explicitly listed as the
# prepare rule.
+this-makefile := $(lastword $(MAKEFILE_LIST))
+export abs_srctree := $(realpath $(dir $(this-makefile)))
+export abs_objtree := $(CURDIR)
+
ifneq ($(sub_make_done),1)
# Do not use make's built-in rules and variables
@@ -185,8 +189,6 @@ $(if $(abs_objtree),, \
# $(realpath ...) resolves symlinks
abs_objtree := $(realpath $(abs_objtree))
-else
-abs_objtree := $(CURDIR)
endif # ifneq ($(KBUILD_OUTPUT),)
ifeq ($(abs_objtree),$(CURDIR))
@@ -196,9 +198,6 @@ else
need-sub-make := 1
endif
-this-makefile := $(lastword $(MAKEFILE_LIST))
-abs_srctree := $(realpath $(dir $(this-makefile)))
-
ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
$(error source directory cannot contain spaces or colons)
endif
@@ -211,7 +210,6 @@ need-sub-make := 1
$(this-makefile): ;
endif
-export abs_srctree abs_objtree
export sub_make_done := 1
ifeq ($(need-sub-make),1)
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 2/3] kbuild: revive "Entering directory" for Make >= 4.4.1 2023-06-26 23:30 [PATCH v4 1/3] kbuild: set correct abs_srctree and abs_objtree for package builds Masahiro Yamada @ 2023-06-26 23:30 ` Masahiro Yamada 2023-06-26 23:30 ` [PATCH v4 3/3] kbuild: respect GNU Make -w flag Masahiro Yamada 1 sibling, 0 replies; 5+ messages in thread From: Masahiro Yamada @ 2023-06-26 23:30 UTC (permalink / raw) To: linux-kbuild Cc: linux-kernel, Masahiro Yamada, David Howells, Nicolas Schier, Nathan Chancellor, Nick Desaulniers, Nicolas Schier 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> Tested-by: Nicolas Schier <n.schier@avm.de> --- (no changes since v3) Changes in v3: - Fix build breakage of 'make rpm-pkg'. Changes in v2: - Fix the code. V1 did not work. - Remove the version check to simplify the code Makefile | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 70b314059d8b..7edb00603b7e 100644 --- a/Makefile +++ b/Makefile @@ -191,13 +191,6 @@ $(if $(abs_objtree),, \ abs_objtree := $(realpath $(abs_objtree)) 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 - ifneq ($(words $(subst :, ,$(abs_srctree))), 1) $(error source directory cannot contain spaces or colons) endif @@ -212,6 +205,23 @@ endif 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 recursing into __sub-make twice. This is needed due to the +# behavior change in GNU Make 4.4.1. +need-sub-make := 1 +endif + ifeq ($(need-sub-make),1) PHONY += $(MAKECMDGOALS) __sub-make @@ -221,18 +231,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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 3/3] kbuild: respect GNU Make -w flag 2023-06-26 23:30 [PATCH v4 1/3] kbuild: set correct abs_srctree and abs_objtree for package builds Masahiro Yamada 2023-06-26 23:30 ` [PATCH v4 2/3] kbuild: revive "Entering directory" for Make >= 4.4.1 Masahiro Yamada @ 2023-06-26 23:30 ` Masahiro Yamada 2023-06-28 7:09 ` Masahiro Yamada 1 sibling, 1 reply; 5+ messages in thread From: Masahiro Yamada @ 2023-06-26 23:30 UTC (permalink / raw) To: linux-kbuild Cc: linux-kernel, Masahiro Yamada, Nicolas Schier, Nathan Chancellor, Nick Desaulniers, Nicolas Schier Currently, -w (--print-directory) option is ignored, but it is better to respect the user's choice. This commit changes the behavior of "Entering directory ..." logging. If -w (or --print-directory) is given via the command line or the MAKEFLAGS environment variable, print "Entering directory ..." for every sub make. If --no-print-directory is given via the command line or the MAKEFLAGS environment variable, suppress "Entering directory ..." completely. If none of them is given, print "Entering directory ..." when Kbuild changes the working directory at the start of building. (default) Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Tested-by: Nicolas Schier <n.schier@avm.de> --- (no changes since v2) Changes in v2: - new patch Makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 7edb00603b7e..c9864f83a3d2 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,12 @@ __all: # descending is started. They are now explicitly listed as the # prepare rule. +ifeq ($(filter 3.%,$(MAKE_VERSION)),) +short-opts := $(firstword -$(MAKEFLAGS)) +else +short-opts := $(filter-out --%,$(MAKEFLAGS)) +endif + this-makefile := $(lastword $(MAKEFILE_LIST)) export abs_srctree := $(realpath $(dir $(this-makefile))) export abs_objtree := $(CURDIR) @@ -95,12 +101,6 @@ endif # commands # make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. -ifeq ($(filter 3.%,$(MAKE_VERSION)),) -short-opts := $(firstword -$(MAKEFLAGS)) -else -short-opts := $(filter-out --%,$(MAKEFLAGS)) -endif - ifneq ($(findstring s,$(short-opts)),) quiet=silent_ override KBUILD_VERBOSE := @@ -215,12 +215,16 @@ else need-sub-make := 1 endif +ifeq ($(findstring w, $(short-opts)),) ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),) # If --no-print-directory is unset, recurse once again to set it. # You may end up recursing into __sub-make twice. This is needed due to the # behavior change in GNU Make 4.4.1. need-sub-make := 1 endif +else +no-print-directory := +endif ifeq ($(need-sub-make),1) -- 2.39.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4 3/3] kbuild: respect GNU Make -w flag 2023-06-26 23:30 ` [PATCH v4 3/3] kbuild: respect GNU Make -w flag Masahiro Yamada @ 2023-06-28 7:09 ` Masahiro Yamada 2023-06-28 14:20 ` Nicolas Schier 0 siblings, 1 reply; 5+ messages in thread From: Masahiro Yamada @ 2023-06-28 7:09 UTC (permalink / raw) To: linux-kbuild Cc: linux-kernel, Nicolas Schier, Nathan Chancellor, Nick Desaulniers, Nicolas Schier On Tue, Jun 27, 2023 at 8:30 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > Currently, -w (--print-directory) option is ignored, but it is better > to respect the user's choice. > > This commit changes the behavior of "Entering directory ..." logging. > > If -w (or --print-directory) is given via the command line or the > MAKEFLAGS environment variable, print "Entering directory ..." for every > sub make. > > If --no-print-directory is given via the command line or the MAKEFLAGS > environment variable, suppress "Entering directory ..." completely. > > If none of them is given, print "Entering directory ..." when Kbuild > changes the working directory at the start of building. (default) > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > Tested-by: Nicolas Schier <n.schier@avm.de> > --- As it turns out, this patch does not work for GNU Make <= 4.3 I will drop (and give up) this patch. > > (no changes since v2) > > Changes in v2: > - new patch > > Makefile | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/Makefile b/Makefile > index 7edb00603b7e..c9864f83a3d2 100644 > --- a/Makefile > +++ b/Makefile > @@ -38,6 +38,12 @@ __all: > # descending is started. They are now explicitly listed as the > # prepare rule. > > +ifeq ($(filter 3.%,$(MAKE_VERSION)),) > +short-opts := $(firstword -$(MAKEFLAGS)) > +else > +short-opts := $(filter-out --%,$(MAKEFLAGS)) > +endif > + > this-makefile := $(lastword $(MAKEFILE_LIST)) > export abs_srctree := $(realpath $(dir $(this-makefile))) > export abs_objtree := $(CURDIR) > @@ -95,12 +101,6 @@ endif > # commands > # make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. > > -ifeq ($(filter 3.%,$(MAKE_VERSION)),) > -short-opts := $(firstword -$(MAKEFLAGS)) > -else > -short-opts := $(filter-out --%,$(MAKEFLAGS)) > -endif > - > ifneq ($(findstring s,$(short-opts)),) > quiet=silent_ > override KBUILD_VERBOSE := > @@ -215,12 +215,16 @@ else > need-sub-make := 1 > endif > > +ifeq ($(findstring w, $(short-opts)),) > ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),) > # If --no-print-directory is unset, recurse once again to set it. > # You may end up recursing into __sub-make twice. This is needed due to the > # behavior change in GNU Make 4.4.1. > need-sub-make := 1 > endif > +else > +no-print-directory := > +endif > > ifeq ($(need-sub-make),1) > > -- > 2.39.2 > -- Best Regards Masahiro Yamada ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 3/3] kbuild: respect GNU Make -w flag 2023-06-28 7:09 ` Masahiro Yamada @ 2023-06-28 14:20 ` Nicolas Schier 0 siblings, 0 replies; 5+ messages in thread From: Nicolas Schier @ 2023-06-28 14:20 UTC (permalink / raw) To: Masahiro Yamada Cc: linux-kbuild, linux-kernel, Nathan Chancellor, Nick Desaulniers On Wed, Jun 28, 2023 at 04:09:44PM +0900, Masahiro Yamada wrote: > On Tue, Jun 27, 2023 at 8:30 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > Currently, -w (--print-directory) option is ignored, but it is better > > to respect the user's choice. > > > > This commit changes the behavior of "Entering directory ..." logging. > > > > If -w (or --print-directory) is given via the command line or the > > MAKEFLAGS environment variable, print "Entering directory ..." for every > > sub make. > > > > If --no-print-directory is given via the command line or the MAKEFLAGS > > environment variable, suppress "Entering directory ..." completely. > > > > If none of them is given, print "Entering directory ..." when Kbuild > > changes the working directory at the start of building. (default) > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > Tested-by: Nicolas Schier <n.schier@avm.de> > > --- > > > As it turns out, this patch does not work for GNU Make <= 4.3 Ups, I'm sorry. I was pretty sure I tested it with make-4.3, but obviously not... Kind regards, Nicolas > I will drop (and give up) this patch. > > > > > > > > > > (no changes since v2) > > > > Changes in v2: > > - new patch > > > > Makefile | 16 ++++++++++------ > > 1 file changed, 10 insertions(+), 6 deletions(-) > > > > diff --git a/Makefile b/Makefile > > index 7edb00603b7e..c9864f83a3d2 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -38,6 +38,12 @@ __all: > > # descending is started. They are now explicitly listed as the > > # prepare rule. > > > > +ifeq ($(filter 3.%,$(MAKE_VERSION)),) > > +short-opts := $(firstword -$(MAKEFLAGS)) > > +else > > +short-opts := $(filter-out --%,$(MAKEFLAGS)) > > +endif > > + > > this-makefile := $(lastword $(MAKEFILE_LIST)) > > export abs_srctree := $(realpath $(dir $(this-makefile))) > > export abs_objtree := $(CURDIR) > > @@ -95,12 +101,6 @@ endif > > # commands > > # make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. > > > > -ifeq ($(filter 3.%,$(MAKE_VERSION)),) > > -short-opts := $(firstword -$(MAKEFLAGS)) > > -else > > -short-opts := $(filter-out --%,$(MAKEFLAGS)) > > -endif > > - > > ifneq ($(findstring s,$(short-opts)),) > > quiet=silent_ > > override KBUILD_VERBOSE := > > @@ -215,12 +215,16 @@ else > > need-sub-make := 1 > > endif > > > > +ifeq ($(findstring w, $(short-opts)),) > > ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),) > > # If --no-print-directory is unset, recurse once again to set it. > > # You may end up recursing into __sub-make twice. This is needed due to the > > # behavior change in GNU Make 4.4.1. > > need-sub-make := 1 > > endif > > +else > > +no-print-directory := > > +endif > > > > ifeq ($(need-sub-make),1) > > > > -- > > 2.39.2 > > > > > -- > Best Regards > Masahiro Yamada ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-28 14:21 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-06-26 23:30 [PATCH v4 1/3] kbuild: set correct abs_srctree and abs_objtree for package builds Masahiro Yamada 2023-06-26 23:30 ` [PATCH v4 2/3] kbuild: revive "Entering directory" for Make >= 4.4.1 Masahiro Yamada 2023-06-26 23:30 ` [PATCH v4 3/3] kbuild: respect GNU Make -w flag Masahiro Yamada 2023-06-28 7:09 ` Masahiro Yamada 2023-06-28 14:20 ` Nicolas Schier
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox