kbuild: simplify silent build (-s) detection

This allows to detect -s (--silent) option without checking GNU Make
version.

As commit e36aaea289 ("kbuild: Fix silent builds with make-4")
pointed out, GNU Make 4.x changed the way/order it presents the
command line options into MAKEFLAGS.

In Make 3.8x, 's' is always the first in a group of short options.
The group may be prefixed with '-' in some cases.

In Make 4.x, 's' is always the last in a group of short options.

As commit e6ac89fabd ("kbuild: Correctly deal with make options
which contain an 's'") addressed, we also need to deal with long
options that contain 's', like --warn-undefined-variables.

Test cases:

[1] command line input:    make --silent
     -> MAKEFLAGS for Make 3.8x:    s
     -> MAKEFLAGS for Make 4.x :    s

[2] command line input:    make -srR
     -> MAKEFLAGS for Make 3.8x:    sRr
     -> MAKEFLAGS for Make 4.x :    rRs

[3] command line input:    make -s -rR --warn-undefined-variables
     -> MAKEFLAGS for Make 3.8x:    --warn-undefined-variables -sRr
     -> MAKEFLAGS for Make 4.x :    rRs --warn-undefined-variables

My idea to cater to all the cases more easily is to filter out long
options (--%), then search 's' with $(findstring ...).  This way will
be more future-proof even if future versions of Make put 's' in the
middle of the group.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
Masahiro Yamada 2017-05-19 20:42:30 +09:00
parent 08332893e3
commit 6f0fa58e45
3 changed files with 3 additions and 22 deletions

View File

@ -84,17 +84,10 @@ endif
# If the user is running make -s (silent mode), suppress echoing of # If the user is running make -s (silent mode), suppress echoing of
# commands # commands
ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4 ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
quiet=silent_ quiet=silent_
tools_silent=s tools_silent=s
endif endif
else # make-3.8x
ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
quiet=silent_
tools_silent=-s
endif
endif
export quiet Q KBUILD_VERBOSE export quiet Q KBUILD_VERBOSE

View File

@ -19,15 +19,9 @@ else
Q=@ Q=@
endif endif
ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4 ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
quiet=silent_ quiet=silent_
endif endif
else # make-3.8x
ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
quiet=silent_
endif
endif
build-dir := $(srctree)/tools/build build-dir := $(srctree)/tools/build

View File

@ -58,15 +58,9 @@ else
NO_SUBDIR = : NO_SUBDIR = :
endif endif
ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4 ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
silent=1 silent=1
endif endif
else # make-3.8x
ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
silent=1
endif
endif
# #
# Define a callable command for descending to a new directory # Define a callable command for descending to a new directory