Skip to contentSkip to conversation

Makefile: ignore long options

PATCH In review Alexey Neyman 2 participants 3 messages Jul 22, 2021 – Jul 24, 2021 1 message not in the archive Kbuild

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 Makefile: ignore long options

When searching for options like -n in MAKEFLAGS, current code may result in a false positive match when make is invoked with long options like --no-print-directory. This has been observed with certain versions of host make (e.g. 3.82) while building the Qemu package in buildroot.

Filter out such long options before searching for one-character options.

---
 Makefile | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Makefile +5 -3
index 6c36330eef..401c623a65 100644
@@ -129,9 +129,11 @@ endif
 # 4. Rules to bridge to other makefiles
 
 ifneq ($(NINJA),)
-MAKE.n = $(findstring n,$(firstword $(MAKEFLAGS)))
-MAKE.k = $(findstring k,$(firstword $(MAKEFLAGS)))
-MAKE.q = $(findstring q,$(firstword $(MAKEFLAGS)))
+# Filter out long options to avoid flags like --no-print-directory which
+# may result in false positive match for MAKE.n
+MAKE.n = $(findstring n,$(firstword $(filter-out --%,$(MAKEFLAGS))))
+MAKE.k = $(findstring k,$(firstword $(filter-out --%,$(MAKEFLAGS))))
+MAKE.q = $(findstring q,$(firstword $(filter-out --%,$(MAKEFLAGS))))
 MAKE.nq = $(if $(word 2, $(MAKE.n) $(MAKE.q)),nq)
 NINJAFLAGS = $(if $V,-v) $(if $(MAKE.n), -n) $(if $(MAKE.k), -k0) \
         $(filter-out -j, $(lastword -j1 $(filter -l% -j%, $(MAKEFLAGS)))) \
Signature · 1 line
2.27.0
#2 lore raw

Patch ping...

Quoted 31 lines · Alexey Neyman

When searching for options like -n in MAKEFLAGS, current code may result in a false positive match when make is invoked with long options like --no-print-directory. This has been observed with certain versions of host make (e.g. 3.82) while building the Qemu package in buildroot.

Filter out such long options before searching for one-character options.

---
  Makefile | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
Makefile +5 -3
index 6c36330eef..401c623a65 100644
@@ -129,9 +129,11 @@ endif
  # 4. Rules to bridge to other makefiles
 
  ifneq ($(NINJA),)
-MAKE.n = $(findstring n,$(firstword $(MAKEFLAGS)))
-MAKE.k = $(findstring k,$(firstword $(MAKEFLAGS)))
-MAKE.q = $(findstring q,$(firstword $(MAKEFLAGS)))
+# Filter out long options to avoid flags like --no-print-directory which
+# may result in false positive match for MAKE.n
+MAKE.n = $(findstring n,$(firstword $(filter-out --%,$(MAKEFLAGS))))
+MAKE.k = $(findstring k,$(firstword $(filter-out --%,$(MAKEFLAGS))))
+MAKE.q = $(findstring q,$(firstword $(filter-out --%,$(MAKEFLAGS))))
  MAKE.nq = $(if $(word 2, $(MAKE.n) $(MAKE.q)),nq)
  NINJAFLAGS = $(if $V,-v) $(if $(MAKE.n), -n) $(if $(MAKE.k), -k0) \
          $(filter-out -j, $(lastword -j1 $(filter -l% -j%, $(MAKEFLAGS)))) \
#3 lore raw
Quoted 2 lines · Alexey Neyman

Patch ping...

Ccing Paolo as author of this bit of code...

Quoted 20 lines · Alexey Neyman
Quoted 19 lines

When searching for options like -n in MAKEFLAGS, current code may result in a false positive match when make is invoked with long options like --no-print-directory. This has been observed with certain versions of host make (e.g. 3.82) while building the Qemu package in buildroot.

Filter out such long options before searching for one-character options.

---
  Makefile | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
Makefile +0 -0
index 6c36330eef..401c623a65 100644
@@ -129,9 +129,11 @@ endif
  # 4. Rules to bridge to other makefiles
 
Quoted 13 lines

Makefile endif · line 139

Quoted 12 lines
Makefile +5 -3
  ifneq ($(NINJA),)
-MAKE.n = $(findstring n,$(firstword $(MAKEFLAGS)))
-MAKE.k = $(findstring k,$(firstword $(MAKEFLAGS)))
-MAKE.q = $(findstring q,$(firstword $(MAKEFLAGS)))
+# Filter out long options to avoid flags like --no-print-directory which
+# may result in false positive match for MAKE.n
+MAKE.n = $(findstring n,$(firstword $(filter-out --%,$(MAKEFLAGS))))
+MAKE.k = $(findstring k,$(firstword $(filter-out --%,$(MAKEFLAGS))))
+MAKE.q = $(findstring q,$(firstword $(filter-out --%,$(MAKEFLAGS))))
  MAKE.nq = $(if $(word 2, $(MAKE.n) $(MAKE.q)),nq)
  NINJAFLAGS = $(if $V,-v) $(if $(MAKE.n), -n) $(if $(MAKE.k), -k0) \
          $(filter-out -j, $(lastword -j1 $(filter -l% -j%, $(MAKEFLAGS)))) \

-- PMM