Skip to content

Commit c8589d1

Browse files
masahir0ymichal42
authored andcommitted
kbuild: handle multi-objs dependency appropriately
The comment in scripts/Makefile.build says as follows: We would rather have a list of rules like foo.o: $(foo-objs) but that's not so easy, so we rather make all composite objects depend on the set of all their parts This commit makes it possible! For example, assume a Makefile like this obj-m = foo.o bar.o foo-objs := foo1.o foo2.o bar-objs := bar1.o bar2.o Without this patch, foo.o depends on all of foo1.o foo2.o bar1.o bar2.o. It looks funny that foo.o is regenerated when bar1.c is updated. Now we can handle the dependency of foo.o and bar.o separately. Signed-off-by: Masahiro Yamada <[email protected]> Signed-off-by: Michal Marek <[email protected]>
1 parent 7d1311b commit c8589d1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

scripts/Makefile.build

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,14 @@ cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalys
382382
quiet_cmd_link_multi-m = LD [M] $@
383383
cmd_link_multi-m = $(cmd_link_multi-y)
384384

385-
# We would rather have a list of rules like
386-
# foo.o: $(foo-objs)
387-
# but that's not so easy, so we rather make all composite objects depend
388-
# on the set of all their parts
389-
$(multi-used-y) : %.o: $(multi-objs-y) FORCE
385+
$(multi-used-y): FORCE
390386
$(call if_changed,link_multi-y)
387+
$(call multi_depend, $(multi-used-y), .o, -objs -y)
391388

392-
$(multi-used-m) : %.o: $(multi-objs-m) FORCE
389+
$(multi-used-m): FORCE
393390
$(call if_changed,link_multi-m)
394391
@{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod)
392+
$(call multi_depend, $(multi-used-m), .o, -objs -y)
395393

396394
targets += $(multi-used-y) $(multi-used-m)
397395

scripts/Makefile.lib

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
159159
modname-multi = $(sort $(foreach m,$(multi-used),\
160160
$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
161161

162+
# Useful for describing the dependency of composite objects
163+
# Usage:
164+
# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
165+
define multi_depend
166+
$(foreach m, $(notdir $1), \
167+
$(eval $(obj)/$m: \
168+
$(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
169+
endef
170+
162171
ifdef REGENERATE_PARSERS
163172

164173
# GPERF

0 commit comments

Comments
 (0)