Skip to content

Commit f7adc31

Browse files
committed
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 4b02424 ("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. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Sam Ravnborg <[email protected]>
1 parent 16f8259 commit f7adc31

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
10091009

10101010
PHONY += $(vmlinux-dirs)
10111011
$(vmlinux-dirs): prepare scripts
1012-
$(Q)$(MAKE) $(build)=$@
1012+
$(Q)$(MAKE) $(build)=$@ need-builtin=1
10131013

10141014
define filechk_kernel.release
10151015
echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"

scripts/Makefile.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ lib-target := $(obj)/lib.a
7676
obj-y += $(obj)/lib-ksyms.o
7777
endif
7878

79-
ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(subdir-m) $(lib-target)),)
79+
ifneq ($(strip $(obj-y) $(need-builtin)),)
8080
builtin-target := $(obj)/built-in.o
8181
endif
8282

@@ -561,7 +561,7 @@ targets := $(filter-out $(PHONY), $(targets))
561561

562562
PHONY += $(subdir-ym)
563563
$(subdir-ym):
564-
$(Q)$(MAKE) $(build)=$@
564+
$(Q)$(MAKE) $(build)=$@ need-builtin=$(if $(findstring $@,$(subdir-obj-y)),1)
565565

566566
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
567567
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)