如何不在输出中打印makefile中的注释

kno*_*cte 31 makefile build autotools

我有一个像这样的makefile:

install:
    @somecommand

    #some explanation for next command
    @lastcommand
Run Code Online (Sandbox Code Playgroud)

发生的是#some explanation for next command我执行时正在打印注释make install.如何在未打印的makefile中进行注释?也许我正在寻找windowsy的unix等价物echo off

(实际上,这个问题的反面.)

Jon*_*ler 50

不要缩进注释 - 当行以选项卡开头时,它是由shell执行的命令(并且shell将注释视为注释).

概念证明(ss.mk):

all:
    echo "This is the first command"
    # This comment is echoed

# This comment is not echoed
    echo "This is the second command"
Run Code Online (Sandbox Code Playgroud)

样本输出:

$ make -f ss.mk
echo "This is the first command"
This is the first command
# This comment is echoed
echo "This is the second command"
This is the second command
$
Run Code Online (Sandbox Code Playgroud)

  • 如果你*真的*想要缩进它,也不会显示带有"@"前缀的缩进注释:-) (9认同)
  • @cbuckley:这是真的,但是它是一种非常重量级的写评论方式,因为`make`会分叉并执行一个shell来扫描注释,推断它是注释,然后成功退出......除非` make`优化了它,它可能不会. (6认同)