Commit aa2ac864 authored by Kai Germaschewski's avatar Kai Germaschewski

Simplify linking/building objects in subdirectories

New-style Makefiles have a nice way of declaring objects
which need to be built either built-in or as modules:

        obj-$(CONFIG_EEPRO100) += eepro100.o

However, handling objects in subdirectories, which need to be
built and linked is not as nice:

        subdir-$(CONFIG_E100) += e100

        ifeq ($(CONFIG_E100),y)
          obj-y += e100/built-in.o
        endif

This means we descend into the subdirectory when building
vmlinux / modules, depending on CONFIG_XXX. When we are building
vmlinux we also need to link whatever has been built in the
subdirectory, so we add it to $(obj-y) at the appropriate place
(link order is important).

Now, the extension below allows to rewrite the second case into

         obj-$(CONFIG_E100) += e100/

which looks much nicer ;-) Existing behavior is not changed, and the
only prerequisite to using the extension above is that the O_TARGET in
the subdir is named "built-in.o".
parent e6d19c6a
......@@ -43,6 +43,27 @@ obj-m := $(filter-out $(obj-y),$(obj-m))
#
first_rule: all_targets
# Handle objects in subdirs
# ---------------------------------------------------------------------------
# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
# and add the directory to the list of dirs to descend into: $(subdir-y)
# o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
# and add the directory to the list of dirs to descend into: $(subdir-m)
__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y += $(__subdir-y)
__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
subdir-m += $(__subdir-m)
__subdir-n := $(patsubst %/,%,$(filter %/, $(obj-n)))
subdir-n += $(__subdir-n)
__subdir- := $(patsubst %/,%,$(filter %/, $(obj-)))
subdir- += $(__subdir-)
obj-y := $(patsubst %/, %/built-in.o, $(obj-y))
obj-m := $(filter-out %/, $(obj-m))
# If a dir is selected in $(subdir-y) and also mentioned in $(mod-subdirs),
# add it to $(subdir-m)
both-m := $(filter $(mod-subdirs), $(subdir-y))
SUB_DIRS := $(subdir-y)
MOD_SUB_DIRS := $(sort $(subdir-m) $(both-m))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment