Skip to content

Commit 5fc10e7

Browse files
committed
kbuild: revive "Entering directory" for Make >= 4.4.1
With commit 9da0763 ("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>
1 parent 5fa94ce commit 5fc10e7

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

Makefile

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ $(if $(abs_objtree),, \
191191
abs_objtree := $(realpath $(abs_objtree))
192192
endif # ifneq ($(KBUILD_OUTPUT),)
193193

194-
ifeq ($(abs_objtree),$(CURDIR))
195-
# Suppress "Entering directory ..." unless we are changing the work directory.
196-
MAKEFLAGS += --no-print-directory
197-
else
198-
need-sub-make := 1
199-
endif
200-
201194
ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
202195
$(error source directory cannot contain spaces or colons)
203196
endif
@@ -212,6 +205,23 @@ endif
212205

213206
export sub_make_done := 1
214207

208+
endif # sub_make_done
209+
210+
ifeq ($(abs_objtree),$(CURDIR))
211+
# Suppress "Entering directory ..." if we are at the final work directory.
212+
no-print-directory := --no-print-directory
213+
else
214+
# Recursion to show "Entering directory ..."
215+
need-sub-make := 1
216+
endif
217+
218+
ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)
219+
# If --no-print-directory is unset, recurse once again to set it.
220+
# You may end up recursing into __sub-make twice. This is needed due to the
221+
# behavior change in GNU Make 4.4.1.
222+
need-sub-make := 1
223+
endif
224+
215225
ifeq ($(need-sub-make),1)
216226

217227
PHONY += $(MAKECMDGOALS) __sub-make
@@ -221,18 +231,12 @@ $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
221231

222232
# Invoke a second make in the output directory, passing relevant variables
223233
__sub-make:
224-
$(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
234+
$(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \
235+
-f $(abs_srctree)/Makefile $(MAKECMDGOALS)
225236

226-
endif # need-sub-make
227-
endif # sub_make_done
237+
else # need-sub-make
228238

229239
# We process the rest of the Makefile if this is the final invocation of make
230-
ifeq ($(need-sub-make),)
231-
232-
# Do not print "Entering directory ...",
233-
# but we want to display it when entering to the output directory
234-
# so that IDEs/editors are able to understand relative filenames.
235-
MAKEFLAGS += --no-print-directory
236240

237241
ifeq ($(abs_srctree),$(abs_objtree))
238242
# building in the source tree

0 commit comments

Comments
 (0)