Skip to contentSkip to conversation

kbuild: Add $(strip ...) before compare make variable with string

PATCH In review Wang Nan 2 participants 2 messages Apr 25, 2020 Kbuild

lore
Share & tools
lore

Wang Nan

author
#0 lore raw

PATCH 1/1 kbuild: Add $(strip ...) before compare make variable with string

Some of ifneq in Makefile.build works improperly:

ifneq ($(a)$(b)$(c),)
...
endif

Because some make vairable contains unintended spaces introduced by:

a := $(x) $(y)

This commit adds $(strip ...) to some potentially buggy ifneq.

Cc Masahiro Yamada <[email protected]>
Cc Michal Marek <[email protected]>
---
 scripts/Makefile.build | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/Makefile.build +3 -3
index 9fcbfac..b2bc0db 100644
@@ -46,7 +46,7 @@ include $(kbuild-file)
 include scripts/Makefile.lib
 
 # Do not include host rules unless needed
-ifneq ($(hostprogs)$(hostcxxlibs-y)$(hostcxxlibs-m),)
+ifneq ($(strip $(hostprogs) $(hostcxxlibs-y) $(hostcxxlibs-m)),)
 include scripts/Makefile.host
 endif
 
@@ -55,7 +55,7 @@ $(warning kbuild: Makefile.build is included improperly)
 endif
 
 ifeq ($(need-modorder),)
-ifneq ($(obj-m),)
+ifneq ($(strip $(obj-m)),)
 $(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
 $(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
 endif
@@ -512,7 +512,7 @@ obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
 # If targets exist, their directories apparently exist. Skip mkdir.
 existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
 obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
-ifneq ($(obj-dirs),)
+ifneq ($(strip $(obj-dirs)),)
 $(shell mkdir -p $(obj-dirs))
 endif
 endif
Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · Wang Nan

Some of ifneq in Makefile.build works improperly:

ifneq ($(a)$(b)$(c),)
...
endif

Because some make vairable contains unintended spaces introduced by:

a := $(x) $(y)

Right.
I made a mistake in commit 5f2fb52fac15a

$(hostprogs) always contains a space due to this line:

hostprogs += $(hostprogs-y) $(hostprogs-m)

This line will go away soon, though.

Quoted 15 lines

This commit adds $(strip ...) to some potentially buggy ifneq.

Cc Masahiro Yamada <[email protected]>
Cc Michal Marek <[email protected]>
---
 scripts/Makefile.build | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/Makefile.build +0 -0
index 9fcbfac..b2bc0db 100644

scripts/Makefile.build include $(kbuild-file) · line 49

Quoted 5 lines
scripts/Makefile.build +1 -1
@@ -46,7 +46,7 @@ include $(kbuild-file)
 include scripts/Makefile.lib
 
 # Do not include host rules unless needed
-ifneq ($(hostprogs)$(hostcxxlibs-y)$(hostcxxlibs-m),)
+ifneq ($(strip $(hostprogs) $(hostcxxlibs-y) $(hostcxxlibs-m)),)

Only this one is correct.

scripts/Makefile.build $(warning kbuild: Makefile.build is included improperly) · line 58

Quoted 9 lines
scripts/Makefile.build +1 -1
 include scripts/Makefile.host
 endif
 
@@ -55,7 +55,7 @@ $(warning kbuild: Makefile.build is included improperly)
 endif
 
 ifeq ($(need-modorder),)
-ifneq ($(obj-m),)
+ifneq ($(strip $(obj-m)),)

obj-m := $(addprefix $(obj)/,$(obj-m))

has always stripped away spaces.

scripts/Makefile.build obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets)))) · line 515

Quoted 8 lines
scripts/Makefile.build +0 -1
 $(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
 $(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
 endif
@@ -512,7 +512,7 @@ obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
 # If targets exist, their directories apparently exist. Skip mkdir.
 existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
 obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
-ifneq ($(obj-dirs),)

The previous line has $(strip )

Quoted 8 lines
scripts/Makefile.build +1 -1
+ifneq ($(strip $(obj-dirs)),)
 $(shell mkdir -p $(obj-dirs))
 endif
 endif
--

2.7.4

Signature · 2 lines
Best Regards
Masahiro Yamada