GNU Make silent by default

核能气质少年 提交于 2019-11-29 06:02:01

问题


Is it possible to suppress command echoing by default from within the Makefile?

I know that running make in --silent mode will do it, as will prefixing every command with @.

I'm looking for a command or stanza I can include inside the Makefile, saving the trouble of littering everything with @ or having the user silence everything manually.


回答1:


If you define the target .SILENT:, then make will not echo anything. It's usually best to guard the definition, so you can easily turn it off:

ifndef VERBOSE
.SILENT:
endif

Now by default, make will print nothing, but if you run make VERBOSE=1, it will print.

Note that despite the statement in the manual claiming that .SILENT is obsolete -- if properly guarded, it is generally much better (more useful and flexible) than @.

The .SILENT target should not be the first on your Makefile, otherwise make will use it by default.




回答2:


You can add --silent in the MAKEFLAGS variable at the beginning of your Makefile:

MAKEFLAGS += --silent

all:
    echo foobar

.PHONY: all

And you will have:

$ make
foobar



回答3:


According to GNU Make's manual, you can use special target .SILENT.

Note that the manual says that:

.SILENT is essentially obsolete since ‘@’ is more flexible.

But it seems to work as expected. The following code silences the all target:

.SILENT:

hoge:
    echo hoge

The following example silences only the hoge target:

.SILENT: hoge

hoge:
    echo hoge

fuga:
    echo fuga


来源:https://stackoverflow.com/questions/24005166/gnu-make-silent-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!