kbuild: link $(real-obj-y) instead of $(obj-y) into built-in.a
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Mon, 19 Mar 2018 11:26:08 +0000 (20:26 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Sun, 25 Mar 2018 17:01:27 +0000 (02:01 +0900)
commitf98fe47ce51dee6d97dd91bbeccdde23f043c754
tree9baebcbde886c154d22f51a01a1ca69bd2442660
parentf5f336812c233976ad84995110c2266cd94c5cd0
kbuild: link $(real-obj-y) instead of $(obj-y) into built-in.a

In Kbuild, Makefiles can add the same object to obj-y multiple
times.  So,

   obj-y += foo.o
   obj-y += foo.o

is fine.

However, this is not true when the same object is added multiple
times via composite objects.  For example,

   obj-y    += foo.o bar.o
   foo-objs := foo-bar-common.o foo-only.o
   bar-objs := foo-bar-common.o bar-only.o

causes build error because two instances of foo-bar-common.o are
linked into the vmlinux.

Makefiles tend to invent ugly work-around, for example
  - lib/zstd/Makefile
  - drivers/net/ethernet/cavium/liquidio/Makefile

The technique used in Kbuild to avoid the multiple definition error
is to use $(filter $(obj-y), $^).  Here, $^ lists the names of all
the prerequisites with duplicated names removed.

By replacing it with $(filter $(real-obj-y), $^) we can do likewise
for composite objects.  For built-in objects, we do not need to keep
the composite object structure.  We can simply expand them, and link
$(real-obj-y) to built-in.a.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
scripts/Makefile.build
scripts/Makefile.lib