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

问题描述 投票:0回答:2

我有一个像这样的makefile:

install:
    @somecommand

    #some explanation for next command
    @lastcommand

发生的情况是,当我执行

#some explanation for next command
时,会打印注释
make install
。如何在 makefile 中做出不被打印的注释?也许我正在寻找 windowsy 的 unix 等效项
echo off

(实际上,与这个问题相反。)

build makefile autotools
2个回答
89
投票

不要缩进注释 - 当该行以制表符开头时,它是由 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"

输出示例:

$ 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
$

4
投票

只需在行首使用

@

all:
    @echo "test 1"
    @# echo "test 2"
    echo "test 3"
  • 输出:
$ make

test 1
echo "test 3"
test 3
© www.soinside.com 2019 - 2024. All rights reserved.