所以一般情况下,你只需要 git grep 'cmd.* = CODE'
找到CODE。
获取scripts/Makefile.build定义的所有代码 make | grep -E '^ ' | sort -uk1,1
CC和CC [M]
名单: quiet_cmd_cc_o_c = CC $(quiet_modtag) [email protected]
cmd_cc_o_c = $(CC) $(c_flags) -c -o [email protected] $< $(real-objs-m) : quiet_modtag := [M]
$(real-objs-m:.o=.i) : quiet_modtag := [M]
$(real-objs-m:.o=.s) : quiet_modtag := [M]
$(real-objs-m:.o=.lst): quiet_modtag := [M]
$(obj-m) : quiet_modtag := [M]
据当时称为通过: $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
[...]
$(call if_changed_rule,cc_o_c)
define rule_cc_o_c
[...]
$(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \
其中if_changed_rule在scripts/Kbuild.include定义为: if_changed_rule = $(if $(strip $(any-prereq) $(arg-check)), \
@set -e; \
$(rule_$(1)))
和Kbuild.include被包括在顶层的Makefile中。
LD
有几个版本,但最简单的似乎是: quiet_cmd_link_o_target = LD [email protected]
cmd_link_o_target = $(if $(strip $(obj-y)),\
$(LD) $(ld_flags) -r -o [email protected] $(filter $(obj-y), $^) \
$(cmd_secanalysis),\
rm -f [email protected]; $(AR) rcs$(KBUILD_ARFLAGS) [email protected])
$(builtin-target): $(obj-y) FORCE
$(call if_changed,link_o_target)
和scripts/Kbuild.include: # Execute command if command has changed or prerequisite(s) are updated.
#
if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
@set -e; \
$(echo-cmd) $(cmd_$(1)); \
printf '%s\n' '[email protected] := $(make-cmd)' > $(dot-target).cmd)