From 8709d116de129ebdfb54ac5feb7c0cc84309fece Mon Sep 17 00:00:00 2001 From: Roland Hieber Date: Mon, 10 Dec 2018 00:24:42 +0100 Subject: Toplevel: fix detection of -n / --dry-run option $(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 Fixes: a0b8075391cfeb324f60e42482b1c34f "ptxdist: add --progress option" Signed-off-by: Roland Hieber Signed-off-by: Michael Olbrich --- 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 -- cgit v1.2.3