History

kbuild: split out *.mod out of {single,multi}-used-m rules

Currently, *.mod is created as a side-effect of obj-m. Split out *.mod as a dedicated build rule, which allows to unify the %.c -> %.o rule, and remove the single-used-m rule. This also makes the incremental build of allmodconfig faster because it saves $(NM) invocation when there is no change in the module.

Masahiro Yamada committed 7 years ago

Commit 9f69a491 parent 30527ce1 file · +13 −9Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/Makefile.build+13−9
@@ -67,8 +67,10 @@ ifeq ($(CONFIG_MODULES)$(need-modorder),y1) · 66 unmodified lines
6767 modorder-target := $(obj)/modules.order
6868 endif
6969
70+mod-targets := $(patsubst %.o, %.mod, $(obj-m))
71+
7072 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
71− $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
73+ $(if $(KBUILD_MODULES),$(obj-m) $(mod-targets) $(modorder-target)) \
7274 $(subdir-ym) $(always)
7375 @:
7476
@@ -261,7 +263,7 @@ endef · 186 unmodified lines
261263
262264 # List module undefined symbols (or empty line if not enabled)
263265 ifdef CONFIG_TRIM_UNUSED_KSYMS
264−cmd_undef_syms = $(NM) $@ | sed -n 's/^ *U //p' | xargs echo
266+cmd_undef_syms = $(NM) $< | sed -n 's/^ *U //p' | xargs echo
265267 else
266268 cmd_undef_syms = echo
267269 endif
@@ -271,11 +273,15 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE · 3 unmodified lines
271273 $(call cmd,force_checksrc)
272274 $(call if_changed_rule,cc_o_c)
273275
274−$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
275− $(call cmd,force_checksrc)
276− $(call if_changed_rule,cc_o_c)
277− @{ echo $@; \
278− $(cmd_undef_syms); } > $(patsubst %.o,%.mod,$@)
276+cmd_mod = { \
277+ echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
278+ $(cmd_undef_syms); \
279+ } > $@
280+
281+$(obj)/%.mod: $(obj)/%.o FORCE
282+ $(call if_changed,mod)
283+
284+targets += $(mod-targets)
279285
280286 quiet_cmd_cc_lst_c = MKLST $@
281287 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
@@ -456,8 +462,6 @@ quiet_cmd_link_multi-m = LD [M] $@ · 174 unmodified lines
456462
457463 $(multi-used-m): FORCE
458464 $(call if_changed,link_multi-m)
459− @{ echo $(filter %.o,$^); \
460− $(cmd_undef_syms); } > $(patsubst %.o,%.mod,$@)
461465 $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
462466
463467 targets += $(multi-used-m)