Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kbuild: skip parsing pre sub-make code for recursion

When Make recurses to the top Makefile with sub-make-done unset,
the code block surrounded by 'ifneq ($(sub-make-done),1) ... endif'
is parsed multiple times. This happens for in-tree building of
include/config/auto.conf, *-pkg, etc. with GNU Make 4.x.

This is a slight regression by commit 688931a5ad4e ("kbuild: skip
sub-make for in-tree build with GNU Make 4.x") in terms of performance
since that code block contains one $(shell ...) invocation.

Fix it by exporting the variable irrespective of sub-make being run.
I renamed it because GNU Make cannot properly export variables
containing hyphens. This is probably a bug of GNU Make, and the issue
in Kbuild had already been reported by commit 2bfbe7881ee0 ("kbuild:
Do not use hyphen in exported variable name").

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

+5 -3
+5 -3
Makefile
··· 31 31 # descending is started. They are now explicitly listed as the 32 32 # prepare rule. 33 33 34 - ifneq ($(sub-make-done),1) 34 + ifneq ($(sub_make_done),1) 35 35 36 36 # Do not use make's built-in rules and variables 37 37 # (this increases performance and avoids hard-to-debug behaviour) ··· 155 155 $(lastword $(MAKEFILE_LIST)): ; 156 156 endif 157 157 158 + export sub_make_done := 1 159 + 158 160 ifeq ($(need-sub-make),1) 159 161 160 162 PHONY += $(MAKECMDGOALS) sub-make ··· 166 164 167 165 # Invoke a second make in the output directory, passing relevant variables 168 166 sub-make: 169 - $(Q)$(MAKE) sub-make-done=1 \ 167 + $(Q)$(MAKE) \ 170 168 $(if $(KBUILD_OUTPUT),-C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR)) \ 171 169 -f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS)) 172 170 173 171 endif # need-sub-make 174 - endif # sub-make-done 172 + endif # sub_make_done 175 173 176 174 # We process the rest of the Makefile if this is the final invocation of make 177 175 ifeq ($(need-sub-make),)