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.
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
来源:https://stackoverflow.com/questions/24005166/gnu-make-silent-by-default