mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH] Toplevel: fix detection of -n / --dry-run option
@ 2018-12-09 23:24 Roland Hieber
  0 siblings, 0 replies; only message in thread
From: Roland Hieber @ 2018-12-09 23:24 UTC (permalink / raw)
  To: ptxdist; +Cc: Roland Hieber

$(filter n,$(MAKEFLAGS)) will be empty if make is called with any
additional parameters. For example, with `make -s -n`, MAKEFLAGS will
contain "sn", which will not match the pattern "n".

The following way is inspired by kernel commit 6f0fa58e459642b169, which
tried to do the same for the -s / --silent option (although support for
make 3.x is probably not important to us):

    kbuild: simplify silent build (-s) detection

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

    As commit e36aaea28972 ("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 e6ac89fabd03 ("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>

Fixes: a0b8075391cfeb324f60e42482b1c34f "ptxdist: add --progress option"
Signed-off-by: Roland Hieber <rohieb@rohieb.name>
---
 rules/other/Toplevel.make | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rules/other/Toplevel.make b/rules/other/Toplevel.make
index 5d81c7504..7e850e233 100644
--- a/rules/other/Toplevel.make
+++ b/rules/other/Toplevel.make
@@ -3,7 +3,7 @@
 # Copyright (C) 2002-2009 by The PTXdist Team - See CREDITS for Details
 #
 
-ifneq ($(filter n,$(MAKEFLAGS)),)
+ifneq ($(findstring n,$(filter-out --%,$(MAKEFLAGS))),)
 # make sure recursive calls do nothing for --dry-run
 MAKE=true
 SHELL=true
-- 
2.19.2


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-12-09 23:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-09 23:24 [ptxdist] [PATCH] Toplevel: fix detection of -n / --dry-run option Roland Hieber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox