在内核 v4.1 上使用 MadScientist 的方法:
make -p | grep -B1 -E '^cmd '
we find:
# makefile (from `scripts/Kbuild.include', line 211)
cmd = @$(echo-cmd) $(cmd_$(1))
scripts/Kbuild.include
包含在顶层Makefile
。它还包含:
echo-cmd = $(if $($(quiet)cmd_$(1)),\
echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
-
quiet
:在顶层 makefile 中设置,具体取决于 的值V
.
将是:
-
quiet_
打印CC file.c
- 空以打印命令
V=
-
silent_
不打印任何东西make -s
-
escsq
定义为:
squote := '
escsq = $(subst $(squote),'\$(squote)',$1)
它转义单引号,以便echo '$(call escsq,Letter 'a'.'
将正确打印在sh
.
-
echo-why
:进一步定义为Kbuild.include
.
它用于make V=2
,并说明为什么要重新制定目标。
的设置make tags
是在Makefile
:
quiet_cmd_tags = GEN $@
cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
tags TAGS cscope gtags: FORCE
$(call cmd,tags)
其中显示了在 kbuild 上调用命令的典型使用模式:
quiet_cmd_XXX = NAME $@
cmd_XXX = actual-command $@
target: prerequisites
$(call cmd,tags)
对以下内容的评论Makefile
解释了所有这一切是如何完成的make
输出更漂亮:
# Beautify output
# ---------------------------------------------------------------------------
#
# Normally, we echo the whole command before executing it. By making
# that echo $($(quiet)$(cmd)), we now have the possibility to set
# $(quiet) to choose other forms of output instead, e.g.
#
# quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<