2014-04-17 32 views
3

在我的makefile,我有一個目標叫indent-fast -爲什麼在執行過程中出現腳本和註釋?

indent-fast: 
    # astyle --style=allman --indent=tab `find . -name "*.java"` 
    files=`find . -name "*.java"` ; \ 
    for file in $$files ; do \ 
     echo formatting $$file ; \ 
    done ;\ 
    # to do a whitesmith at 4 spaces, uncomment this line -- 
    # astyle --style=whitesmith --indent=spaces=4 `find . -name "*.java"` 

但是當我執行它,我得到這個輸出 -

[email protected]:~$ make indent-fast 

# astyle --style=allman --indent=tab `find . -name "*.java"` 
files=`find . -name "*.java"` ; \ 
    for file in $files ; do \ 
     echo formatting $file ; \ 
    done ;\ 
formatting ./File1.java 
formatting ./File2.java 
formatting ./File3.java 
. 
. 
. 
formatting ./FileN.java 
# to do a whitesmith at 4 spaces, uncomment this line -- 
# astyle --style=whitesmith --indent=spaces=4 `find . -name "*.java"` 

爲什麼它顯示與評論​​沿着腳本在標準輸出?另請注意,indent-fast是該文件中的最後一個目標。

回答

2

因爲您的評論是在配方中縮進的,所以它們不是make評論,而是作爲配方的一部分執行。他們在這方面是殼牌評論。如果這是您的目標,您可以添加一個@以防止它們被輸出。

GNU make manual

配方中的註釋傳遞到外殼,就像任何其他配方文本。 shell決定如何解釋它:這是否是註釋取決於shell。

簡單的例子生成文件:

# make comment 
target: 
    # shell comment 
    : 
    @# output-suppressed shell comment 
    @: 

執行:

$ make 
# shell comment 
: 

編輯:既然一個例子是不夠好,這裏是爲您的具體問題的解決方案:

indent-fast: 
    @# astyle --style=allman --indent=tab `find . -name "*.java"` 
    @files=`find . -name "*.java"` ; \ 
    for file in $$files ; do \ 
     echo formatting $$file ; \ 
    done 
    @# to do a whitesmith at 4 spaces, uncomment this line -- 
    @# astyle --style=whitesmith --indent=spaces=4 `find . -name "*.java"` 
+0

好吧,謝謝我可以用'@'來壓制註釋,但它仍然顯示'for'循環體a nd也會拋出這個錯誤'/ bin/sh:5:@#:找不到make:*** [indent-fast] Error 127' – ramgorur

+0

如果你不想'for'循環體,可以放一個'@'在它包含的命令前面。你得到錯誤的原因是你在錯誤的地方放了一個'@',而shell正在試圖解釋它。 –

+0

只需添加:如果您不希望打印它們,請不要用TAB縮進它們。如果它沒有用TAB縮進,那麼它不是配方的一部分,它是'make'註釋,make不會將它傳遞給shell。 – MadScientist

相關問題