How to detect if the makefile --silent / --quiet command line options was set?
Related questions:
How to detect if the makefile --silent / --quiet command line options was set?
Related questions:
I think you need:
$(findstring s,$(word 1, $(MAKEFLAGS)))
Because MAKEFLAGS has long options, too, eg:
MAKEFLAGS=s -j80 --jobserver-auth=4,6
So, IOW:
# Set SILENT to 's' if --quiet/-s set, otherwise ''.
SILENT := $(findstring s,$(word 1, $(MAKEFLAGS)))
If you call either make --quiet or --silent, the variable {MAKEFLAGS} is set only to s. And if you add other options like --ignore-errors and --keep-going, the variable {MAKEFLAGS} is set to iks. Then, you can capture it with this:
ECHOCMD:=/bin/echo -e
SHELL := /bin/bash
all:
printf 'Calling with "%s" %s\n' "${MAKECMDGOALS}" "${MAKEFLAGS}";
if [[ "ws" == "w$(findstring s,${MAKEFLAGS})" ]]; then \
printf '--silent option was set\n'; \
fi
References:
make gives MAKEFLAGS = ""
make -j8 gives MAKEFLAGS = " -j8 --jobserver-auth=3,4"
make -j8 -s gives MAKEFLAGS = "s -j8 --jobserver-auth=3,4"
make -j8 -s -B gives MAKEFLAGS = "Bs -j8 --jobserver-auth=3,4"
So this should do the trick:
$(findstring s,$(filter-out -%,$(MAKEFLAGS)))
It returns "s" or an empty string, which is suitable as the condition for an $(if ...).