Suppress messages in make clean (Makefile silent remove)

后端 未结 5 2000
感情败类
感情败类 2021-01-30 13:10

I\'m wondering how I can avoid some echo in a Makefile :

clean:
    rm -fr *.o

this rule will print:

$>make clean   
rm -fr          


        
5条回答
  •  伪装坚强ぢ
    2021-01-30 13:31

    From the manual: .SILENT is essentially obsolete since @ is more flexible.

    Much worse is that make prints far too much information. Warning/error/private messages are buried in the output. On the other hand -s (.SILENT) suppresses just anything. Especially the "nothing to be done" and "up to date" messages can be a pain. There is no option to suppress them. You have to filter them out actively or use something like colormake. Here is a solution for grep:

    make | egrep -hiv 'nothing to be done|up to date'
    

    But the output will have line numbers. The Perl solution is therefore better, because it suppresses line numbers and flushes stdout immediately:

    make | perl -ne '$|=1; print unless /nothing to be done|up to date/i'
    

    Make's a flawed tool. "What’s Wrong With GNU make?" explains this better than I can.

提交回复
热议问题