OSDN Git Service

kbuild: create built-in.o automatically if parent directory wants it
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Tue, 7 Nov 2017 16:31:46 +0000 (01:31 +0900)
committer0ranko0P <ranko0p@outlook.com>
Sat, 7 Dec 2019 08:34:45 +0000 (16:34 +0800)
commit73fbae6d8d85b6056d5e259eed2773c33a278ccd
treec75d62c229abcfd5511a7de90543f24e33c666d4
parent038b8134db6f7cbaf73035e678a7c0be6b5f7b33
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.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Makefile
scripts/Makefile.build