2013-08-21 30 views
19

我有一個makefile是這樣的:如何才能不輸出打印的註釋在makefile

install: 
    @somecommand 

    #some explanation for next command 
    @lastcommand 

什麼情況是,當我執行make install評論#some explanation for next command正在打印。如何在未打印的生成文件中發表評論?也許我正在尋找windows的echo off的unix等價物?

(有效地,相反的this question。)

回答

35

不要縮進的評論 - 當行與選項卡啓動時,它是由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 
$ 
+3

與'@'前綴的縮進的評論也不會表現出來,如果你真的* *要縮進它:-) – cmbuckley

+3

@cbuckley:這是真的,但它是一個非常重的寫評論的方式,因爲'make'將fork和exec一個shell來掃描評論,推斷它是一個評論,然後成功退出...除非'make'優化,否則它可能不會。 –

+0

是啊......以前我的評論是以「......的效果」結尾的,但那可能是荒謬的。不知道爲什麼我刪除它! – cmbuckley