我想在我的 makefile 的行尾添加注释。
rule:
echo 1 # Print 1
Run Code Online (Sandbox Code Playgroud)
但是,当运行此 makefile 时,注释也会打印在命令行中。
$ make rule
echo 1 # Print 1
1
Run Code Online (Sandbox Code Playgroud)
但我希望隐藏注释(而不是命令)。有没有办法在 makefile 中不打印的行尾添加注释?(我知道您可以通过在注释前添加 a 来隐藏注释@,但只有当整行都是注释而不是在行尾时才有效。)
这# print 1不是 的注释make,整行echo 1 # print 1(不带前导 TAB)被传递到 shell(通过使用$(SHELL)和-c作为that-line额外参数执行),并且 shell 将其解释为该上下文中的注释。在其他上下文中,例如在 aecho "foo # bar"或 with $(SHELL)s 中,不将其视为#注释引导者,则不会。在任何情况下,除非使用@或禁用.SILENT,make否则都会打印传递到 shell 的代码。
Makefile 配方中的make注释必须将作为#该行的第一个字符:
rule:
# print 1:
echo 1
Run Code Online (Sandbox Code Playgroud)
或者注释行也可以用反斜杠继续:
rule:
#\
# print 1:
echo 1
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
rule:
@# print 1:
echo 1
Run Code Online (Sandbox Code Playgroud)
这确实为该配方的每一行调用一个 shell。对于只有一个shell注释的内联 shell 脚本的第一行,它@会跳过该 shell 代码的回显make,并且不是传递给 shell 的代码的一部分。
有关详细信息,请参阅info make 'comments, in recipe'GNU 系统(有关 的 GNU 实现make)
食谱中的评论不是发表评论;而是评论。它将按原样传递给 shell。shell 是否将其视为注释取决于您的 shell。
更一般地说info make comments是关于 Makefile 中的注释。
现在,您可以做的是make使用规则完全禁用 的回显.SILENT,并让 shell 使用其xtrace选项自行执行回显:
SHELL = sh -o xtrace
export PS4 =
.SILENT: rule
rule:
echo 1 # print 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
769 次 |
| 最近记录: |