Message ID | CAG+Z0CvOxWdvDi5qKa=ayPasVYxrourTDjEpXsg8T=mj3J4s6Q@mail.gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] kbuild: Port silent mode detection to future gnu make. | expand |
On Wed, Nov 30, 2022 at 2:10 AM Dmitry Goncharov <dgoncharov@users.sf.net> wrote: > > Port silent mode detection to the future (post make-4.4) versions of gnu make. > > Makefile contains the following piece of make code to detect if option -s is > specified on the command line. > > ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) > > > This code is executed by make at parse time and assumes that MAKEFLAGS > does not contain command line variable definitions. > Currently if the user defines a=s on the command line, then at build only > time MAKEFLAGS contains " -- a=s". > However, starting with commit dc2d963989b96161472b2cd38cef5d1f4851ea34 > MAKEFLAGS contains command line definitions at both parse time and > build time. > > This '-s' detection code then confuses a command line variable > definition which contains letter 's' with option -s. > > E.g. > $ # old make > $ make net/wireless/ocb.o a=s > CALL scripts/checksyscalls.sh > DESCEND objtool > $ # this a new make which defines makeflags at parse time > $ ~/src/gmake/make/l64/make net/wireless/ocb.o a=s > $ > > We can see here that the letter 's' from 'a=s' was confused with -s. > > This patch checks for presence of -s using a method recommended by the > make manual here > https://www.gnu.org/software/make/manual/make.html#Testing-Flags. The GNU Make manual is written with the latest Make version in mind. "Recall that MAKEFLAGS will put all single-letter options (such as â-tâ) into the first word, and that word will be empty if no single-letter options were given." This statement is not true for GNU Make 3.82, which the kbuild supports. $ git show 6f0fa58 commit 6f0fa58e459642b16901521cc58ac474b787ec5b Author: Masahiro Yamada <yamada.masahiro@socionext.com> Date: Fri May 19 20:42:30 2017 +0900 kbuild: simplify silent build (-s) detection [snip] 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 As this commit description says, Make 3.8x puts long options before the collection of single letter options. So, this patch does not work for Make 3.82.
On Thu, Dec 1, 2022 at 8:18 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Wed, Nov 30, 2022 at 2:10 AM Dmitry Goncharov > <dgoncharov@users.sf.net> wrote: > > > > Port silent mode detection to the future (post make-4.4) versions of gnu make. > > > > Makefile contains the following piece of make code to detect if option -s is > > specified on the command line. > > > > ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) > > > > > > This code is executed by make at parse time and assumes that MAKEFLAGS > > does not contain command line variable definitions. > > Currently if the user defines a=s on the command line, then at build only > > time MAKEFLAGS contains " -- a=s". > > However, starting with commit dc2d963989b96161472b2cd38cef5d1f4851ea34 > > MAKEFLAGS contains command line definitions at both parse time and > > build time. > > > > This '-s' detection code then confuses a command line variable > > definition which contains letter 's' with option -s. > > > > E.g. > > $ # old make > > $ make net/wireless/ocb.o a=s > > CALL scripts/checksyscalls.sh > > DESCEND objtool > > $ # this a new make which defines makeflags at parse time > > $ ~/src/gmake/make/l64/make net/wireless/ocb.o a=s > > $ > > > > We can see here that the letter 's' from 'a=s' was confused with -s. > > > > This patch checks for presence of -s using a method recommended by the > > make manual here > > https://www.gnu.org/software/make/manual/make.html#Testing-Flags. > > > > > The GNU Make manual is written with the latest Make version in mind. > > > "Recall that MAKEFLAGS will put all single-letter options (such as â-tâ) > into the first word, and that word will be empty if no single-letter > options were given." > > This statement is not true for GNU Make 3.82, which the kbuild supports. > > > > > $ git show 6f0fa58 > commit 6f0fa58e459642b16901521cc58ac474b787ec5b > Author: Masahiro Yamada <yamada.masahiro@socionext.com> > Date: Fri May 19 20:42:30 2017 +0900 > > kbuild: simplify silent build (-s) detection > > > [snip] > > 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 > > > > > > > > > As this commit description says, Make 3.8x puts long > options before the collection of single letter options. > > So, this patch does not work for Make 3.82. > I think the following code will work for 3.82, 4.x, and future releases. diff --git a/Makefile b/Makefile index 78525ebea876..58dfd7475448 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ endif # If the user is running make -s (silent mode), suppress echoing of # commands -ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) +ifneq ($(findstring s,$(filter-out --%,$(filter -%,-$(MAKEFLAGS)))),) quiet=silent_ KBUILD_VERBOSE = 0 endif
On Wed, Nov 30, 2022 at 6:23 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> So, this patch does not work for Make 3.82.
indeed.
regards, Dmitry
On Wed, Nov 30, 2022 at 6:41 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > I think the following code will work > for 3.82, 4.x, and future releases. > > diff --git a/Makefile b/Makefile > index 78525ebea876..58dfd7475448 100644 > --- a/Makefile > +++ b/Makefile > @@ -94,7 +94,7 @@ endif > # If the user is running make -s (silent mode), suppress echoing of > # commands > > -ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) > +ifneq ($(findstring s,$(filter-out --%,$(filter -%,-$(MAKEFLAGS)))),) > quiet=silent_ > KBUILD_VERBOSE = 0 > endif make-4.4 (and later) stores -I<path> in makeflags. $ cat makefile2 $(info $(MAKEFLAGS)) all: $ make-4.4 -rR -Isrc --warn-undefined-variables a=s -j2 -fmakefile2 rR -Isrc -j2 --warn-undefined-variables make-4.4: warning: undefined variable 'GNUMAKEFLAGS' make-4.4: Nothing to be done for 'all'. $ $(findstring s,$(filter-out --%,$(filter -%,-$(MAKEFLAGS)))),) confuses 's' in -Isrc with -s. What about the following? diff --git a/Makefile b/Makefile index 6f846b1f2618..3a97494a9989 100644 --- a/Makefile +++ b/Makefile @@ -94,9 +94,15 @@ endif # If the user is running make -s (silent mode), suppress echoing of # commands -ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) - quiet=silent_ - KBUILD_VERBOSE = 0 +ifeq ($(filter 3.%,$(MAKE_VERSION)),) +silence:=$(findstring s,$(firstword -$(MAKEFLAGS))) +else +silence:=$(findstring s,$(filter-out --%,$(filter -%,-$(MAKEFLAGS)))) +endif + +ifeq ($(silence),s) +quiet=silent_ +KBUILD_VERBOSE = 0 endif export quiet Q KBUILD_VERBOSE Tested 3.82, 4.3, 4.4, latest master. regards, Dmitry
On Fri, Dec 2, 2022 at 7:34 AM Dmitry Goncharov <dgoncharov@users.sf.net> wrote: > > On Wed, Nov 30, 2022 at 6:41 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > I think the following code will work > > for 3.82, 4.x, and future releases. > > > > diff --git a/Makefile b/Makefile > > index 78525ebea876..58dfd7475448 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -94,7 +94,7 @@ endif > > # If the user is running make -s (silent mode), suppress echoing of > > # commands > > > > -ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) > > +ifneq ($(findstring s,$(filter-out --%,$(filter -%,-$(MAKEFLAGS)))),) > > quiet=silent_ > > KBUILD_VERBOSE = 0 > > endif > > > make-4.4 (and later) stores -I<path> in makeflags. > $ cat makefile2 > $(info $(MAKEFLAGS)) > all: > $ make-4.4 -rR -Isrc --warn-undefined-variables a=s -j2 -fmakefile2 > rR -Isrc -j2 --warn-undefined-variables > make-4.4: warning: undefined variable 'GNUMAKEFLAGS' > make-4.4: Nothing to be done for 'all'. > $ > > $(findstring s,$(filter-out --%,$(filter -%,-$(MAKEFLAGS)))),) > confuses 's' in -Isrc with -s. > > What about the following? > > > diff --git a/Makefile b/Makefile > index 6f846b1f2618..3a97494a9989 100644 > --- a/Makefile > +++ b/Makefile > @@ -94,9 +94,15 @@ endif > # If the user is running make -s (silent mode), suppress echoing of > # commands > > -ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) > - quiet=silent_ > - KBUILD_VERBOSE = 0 > +ifeq ($(filter 3.%,$(MAKE_VERSION)),) > +silence:=$(findstring s,$(firstword -$(MAKEFLAGS))) > +else > +silence:=$(findstring s,$(filter-out --%,$(filter -%,-$(MAKEFLAGS)))) > +endif Yes. You do not need to change the logic in 'else' part, but this will work as well. > + > +ifeq ($(silence),s) > +quiet=silent_ > +KBUILD_VERBOSE = 0 > endif > > export quiet Q KBUILD_VERBOSE > > Tested 3.82, 4.3, 4.4, latest master. > regards, Dmitry
On Thu, Dec 1, 2022 at 6:39 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > You do not need to change the logic in 'else' part, > but this will work as well. Here is the version which keeps the 3.82 specific code intact. Tested with 3.82, 4.0, 4.3, 4.4, the latest master. regards, Dmitry diff --git a/Makefile b/Makefile index 6f846b1f2618..fbd9ff4a61e7 100644 --- a/Makefile +++ b/Makefile @@ -93,10 +93,17 @@ endif # If the user is running make -s (silent mode), suppress echoing of # commands +# make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. -ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) - quiet=silent_ - KBUILD_VERBOSE = 0 +ifeq ($(filter 3.%,$(MAKE_VERSION)),) +silence:=$(findstring s,$(firstword -$(MAKEFLAGS))) +else +silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS))) +endif + +ifeq ($(silence),s) +quiet=silent_ +KBUILD_VERBOSE = 0 endif export quiet Q KBUILD_VERBOSE
On Sat, Dec 3, 2022 at 12:26 PM Dmitry Goncharov <dgoncharov@users.sf.net> wrote: > > On Thu, Dec 1, 2022 at 6:39 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > You do not need to change the logic in 'else' part, > > but this will work as well. > > Here is the version which keeps the 3.82 specific code intact. > Tested with 3.82, 4.0, 4.3, 4.4, the latest master. Thanks. Could you please send v3 with a commit description? > > regards, Dmitry > > diff --git a/Makefile b/Makefile > index 6f846b1f2618..fbd9ff4a61e7 100644 > --- a/Makefile > +++ b/Makefile > @@ -93,10 +93,17 @@ endif > > # If the user is running make -s (silent mode), suppress echoing of > # commands > +# make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. > > -ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) > - quiet=silent_ > - KBUILD_VERBOSE = 0 > +ifeq ($(filter 3.%,$(MAKE_VERSION)),) > +silence:=$(findstring s,$(firstword -$(MAKEFLAGS))) > +else > +silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS))) > +endif > + > +ifeq ($(silence),s) > +quiet=silent_ > +KBUILD_VERBOSE = 0 > endif > > export quiet Q KBUILD_VERBOSE
diff --git a/Makefile b/Makefile index 6f846b1f2618..c5d5558e9806 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ endif # If the user is running make -s (silent mode), suppress echoing of # commands -ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) +ifneq ($(findstring s,$(firstword -$(MAKEFLAGS))),)
Port silent mode detection to the future (post make-4.4) versions of gnu make. Makefile contains the following piece of make code to detect if option -s is specified on the command line. ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) This code is executed by make at parse time and assumes that MAKEFLAGS does not contain command line variable definitions. Currently if the user defines a=s on the command line, then at build only time MAKEFLAGS contains " -- a=s". However, starting with commit dc2d963989b96161472b2cd38cef5d1f4851ea34 MAKEFLAGS contains command line definitions at both parse time and build time. This '-s' detection code then confuses a command line variable definition which contains letter 's' with option -s. E.g. $ # old make $ make net/wireless/ocb.o a=s CALL scripts/checksyscalls.sh DESCEND objtool $ # this a new make which defines makeflags at parse time $ ~/src/gmake/make/l64/make net/wireless/ocb.o a=s $ We can see here that the letter 's' from 'a=s' was confused with -s. This patch checks for presence of -s using a method recommended by the make manual here https://www.gnu.org/software/make/manual/make.html#Testing-Flags. This suggested method will work with the old and new make. Signed-off-by: Dmitry Goncharov <dgoncharov@users.sf.net> Reported-by: Jan Palus <jpalus+gnu@fastmail.com> Link: https://lists.gnu.org/archive/html/bug-make/2022-11/msg00190.html regards, Dmitry