3

How to detect if the makefile --silent / --quiet command line options was set?

Related questions:

  1. how to detect if --quiet option is specified with rake
user
  • 7,316
  • 9
  • 70
  • 122

2 Answers2

5

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)))
Rusty Russell
  • 66
  • 1
  • 4
1

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:

  1. Recursive make: correct way to insert `$(MAKEFLAGS)`
  2. How to set MAKEFLAGS from Makefile, in order to remove default implicit-rules
  3. Remove target from MAKECMDGOALS?
  4. https://www.gnu.org/software/autoconf/manual/autoconf-2.61/html_node/The-Make-Macro-MAKEFLAGS.html
user
  • 7,316
  • 9
  • 70
  • 122