diff mbox series

[1/1] Makefile: identify silent make via firstword findstring

Message ID 20221014230905.3091021-1-james.hilliard1@gmail.com
State Rejected
Headers show
Series [1/1] Makefile: identify silent make via firstword findstring | expand

Commit Message

James Hilliard Oct. 14, 2022, 11:09 p.m. UTC
Make recommends using this technique for identifying short options.

From make NEWS for upcoming version 4.4:

Previously only simple (one-letter) options were added to the MAKEFLAGS
variable that was visible while parsing makefiles.  Now, all options are
available in MAKEFLAGS.  If you want to check MAKEFLAGS for a one-letter
option, expanding "$(firstword -$(MAKEFLAGS))" is a reliable way to return
the set of one-letter options which can be examined via findstring, etc.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Thomas Petazzoni Oct. 30, 2022, 8:26 p.m. UTC | #1
Hello James,

On Fri, 14 Oct 2022 17:09:05 -0600
James Hilliard <james.hilliard1@gmail.com> wrote:

> +QUIET := $(if $(findstring s,$(firstword -$(MAKEFLAGS))),-q)

I must be missing something, but why is -$(MAKEFLAGS) used and not just
$(MAKEFLAGS) ?

Indeed, with "make -s --debug -k", $(MAKEFLAGS) is "ks --debug=all",
and therefore $(firstword $(MAKEFLAGS)) is ks, which is good enough for
the findstring s, no? Why is adding a - in front needed?

Thanks!

Thomas
James Hilliard Oct. 30, 2022, 8:35 p.m. UTC | #2
On Sun, Oct 30, 2022 at 4:26 PM Thomas Petazzoni
<thomas.petazzoni@bootlin.com> wrote:
>
> Hello James,
>
> On Fri, 14 Oct 2022 17:09:05 -0600
> James Hilliard <james.hilliard1@gmail.com> wrote:
>
> > +QUIET := $(if $(findstring s,$(firstword -$(MAKEFLAGS))),-q)
>
> I must be missing something, but why is -$(MAKEFLAGS) used and not just
> $(MAKEFLAGS) ?
>
> Indeed, with "make -s --debug -k", $(MAKEFLAGS) is "ks --debug=all",
> and therefore $(firstword $(MAKEFLAGS)) is ks, which is good enough for
> the findstring s, no? Why is adding a - in front needed?

I think so that if $(MAKEFLAGS) doesn't have any short options that it won't
accidentally match on a long option.

For example if $(MAKEFLAGS) is " --shuffle=none" the - in front ensures that
we don't match the s in a long option like shuffle.

>
> Thanks!
>
> Thomas
> --
> Thomas Petazzoni, co-owner and CEO, Bootlin
> Embedded Linux and Kernel engineering and training
> https://bootlin.com
Arnout Vandecappelle April 10, 2023, 7:44 p.m. UTC | #3
On 30/10/2022 21:35, James Hilliard wrote:
> On Sun, Oct 30, 2022 at 4:26 PM Thomas Petazzoni
> <thomas.petazzoni@bootlin.com> wrote:
>>
>> Hello James,
>>
>> On Fri, 14 Oct 2022 17:09:05 -0600
>> James Hilliard <james.hilliard1@gmail.com> wrote:
>>
>>> +QUIET := $(if $(findstring s,$(firstword -$(MAKEFLAGS))),-q)
>>
>> I must be missing something, but why is -$(MAKEFLAGS) used and not just
>> $(MAKEFLAGS) ?
>>
>> Indeed, with "make -s --debug -k", $(MAKEFLAGS) is "ks --debug=all",
>> and therefore $(firstword $(MAKEFLAGS)) is ks, which is good enough for
>> the findstring s, no? Why is adding a - in front needed?
> 
> I think so that if $(MAKEFLAGS) doesn't have any short options that it won't
> accidentally match on a long option.
> 
> For example if $(MAKEFLAGS) is " --shuffle=none" the - in front ensures that
> we don't match the s in a long option like shuffle.

  Exactly right.

  However, the firstword approach doesn't work with GNU make 3.81. For example, 
the following invocation:

make --no-print-directory -s

will set MAKEFLAGS to " --no-print-directory -s", so the firstword approach 
*doesn't* find the -s, but the filter-out approach does.

  Therefore, I marked this patch as Rejected.

  Regards,
  Arnout

> 
>>
>> Thanks!
>>
>> Thomas
>> --
>> Thomas Petazzoni, co-owner and CEO, Bootlin
>> Embedded Linux and Kernel engineering and training
>> https://bootlin.com
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index ec7c034ac1..2d31fd45fa 100644
--- a/Makefile
+++ b/Makefile
@@ -434,7 +434,7 @@  PACKAGES :=
 PACKAGES_ALL :=
 
 # silent mode requested?
-QUIET := $(if $(findstring s,$(filter-out --%,$(MAKEFLAGS))),-q)
+QUIET := $(if $(findstring s,$(firstword -$(MAKEFLAGS))),-q)
 
 # Strip off the annoying quoting
 ARCH := $(call qstrip,$(BR2_ARCH))