From aa5fe87fe8057d3585c2e34374af070dbc609dac Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 8 Nov 2017 01:31:46 +0900 Subject: [PATCH] kbuild: create built-in.o automatically if parent directory wants it "obj-y += foo/" syntax requires Kbuild to visit the "foo" subdirectory and link built-in.o from that directory. This means foo/Makefile is responsible for creating built-in.o even if there is no object to link (in this case, built-in.o is an empty archive). We have had several fixups like commit 4b024242e8a4 ("kbuild: Fix linking error built-in.o no such file or directory"), then ended up with a complex condition as follows: ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(subdir-m) $(lib-target)),) builtin-target := $(obj)/built-in.o endif We still have more cases not covered by the above, so we need to add obj- := dummy.o in several places just for creating empty built-in.o. A key point is, the parent Makefile knows whether built-in.o is needed or not. If a subdirectory needs to create built-in.o, its parent can tell the fact when descending. If non-empty $(need-builtin) flag is passed from the parent, built-in.o should be created. $(obj-y) should be still checked to support the single target "%/". All of ugly tricks will go away. Change-Id: I438525660247ee9f30b4cdc7f7923d6068bd2b65 Signed-off-by: Masahiro Yamada Reviewed-by: Sam Ravnborg Git-commit: f7adc3124da019878186f1ebe98a13a1af041afd Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git Signed-off-by: Xiaowen Wu --- Makefile | 2 +- scripts/Makefile.build | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 00c0b80fec79..a66abded17ce 100644 --- a/Makefile +++ b/Makefile @@ -1185,7 +1185,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ; PHONY += $(vmlinux-dirs) $(vmlinux-dirs): prepare scripts - $(Q)$(MAKE) $(build)=$@ + $(Q)$(MAKE) $(build)=$@ need-builtin=1 define filechk_kernel.release echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 3195559f000f..74ce588c6951 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -90,7 +90,7 @@ lib-target := $(obj)/lib.a obj-y += $(obj)/lib-ksyms.o endif -ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(subdir-m) $(lib-target)),) +ifneq ($(strip $(obj-y) $(need-builtin)),) builtin-target := $(obj)/built-in.o endif @@ -673,7 +673,7 @@ targets += $(multi-used-y) $(multi-used-m) PHONY += $(subdir-ym) $(subdir-ym): - $(Q)$(MAKE) $(build)=$@ + $(Q)$(MAKE) $(build)=$@ need-builtin=$(if $(findstring $@,$(subdir-obj-y)),1) # Add FORCE to the prequisites of a target to force it to be always rebuilt. # ---------------------------------------------------------------------------