GNU Make silent by default

懵懂的女人 提交于 2019-11-30 06:21:45
Chris Dodd

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.

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

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

note that the manual saids that

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

but it seems to work as expected. the following code silents the all target.

.SILENT:

hoge:
    echo hoge

the following example silents only the hoge target

.SILENT: hoge

hoge:
    echo hoge

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