Skip to contentSkip to conversation

kbuild: strip the last slash in KBUILD_EXTMOD

PATCH In review Wei Yang 2 participants 3 messages Feb 22, 2017 – Mar 12, 2017 Kbuild

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 kbuild: strip the last slash in KBUILD_EXTMOD

Current kbuild will build the target again if we run "make M=dir" and "make M=dir/" by turns, since if_changed will see the prerequisite is changed. The behavior may confuse the user a little, since actually we are building the same target and no difference.

According to current implementation in scripts/Makefile.build, the obj passed to next level is a directory name with last slash stripped. This patch strips the last slash in KBUILD_EXTMOD which is assigned from "M=".

---
 Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Makefile +4 -2
index b1037774e8e8..db6ed60928ab 100644
@@ -184,13 +184,15 @@ endif
 # Old syntax make ... SUBDIRS=$PWD is still supported
 # Setting the environment variable KBUILD_EXTMOD take precedence
 ifdef SUBDIRS
-  KBUILD_EXTMOD ?= $(SUBDIRS)
+  __KBUILD_EXTMOD ?= $(SUBDIRS)
 endif
 
 ifeq ("$(origin M)", "command line")
-  KBUILD_EXTMOD := $(M)
+  __KBUILD_EXTMOD := $(M)
 endif
 
+KBUILD_EXTMOD = $(patsubst %/,%,$(__KBUILD_EXTMOD))
+
 # If building an external module we do not care about the all: rule
 # but instead _all depend on modules
 PHONY += all
Signature · 1 line
2.11.0
#1 lore raw

Hi Wei,

2017-02-23 0:08 GMT+09:00 Wei Yang <[email protected]>:

Quoted 26 lines

Current kbuild will build the target again if we run "make M=dir" and "make M=dir/" by turns, since if_changed will see the prerequisite is changed. The behavior may confuse the user a little, since actually we are building the same target and no difference.

According to current implementation in scripts/Makefile.build, the obj passed to next level is a directory name with last slash stripped. This patch strips the last slash in KBUILD_EXTMOD which is assigned from "M=".

---
 Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Makefile +1 -1
index b1037774e8e8..db6ed60928ab 100644
@@ -184,13 +184,15 @@ endif
 # Old syntax make ... SUBDIRS=$PWD is still supported
 # Setting the environment variable KBUILD_EXTMOD take precedence
 ifdef SUBDIRS
-  KBUILD_EXTMOD ?= $(SUBDIRS)
+  __KBUILD_EXTMOD ?= $(SUBDIRS)
 endif
 

Makefile endif · line 198

Quoted 10 lines
Makefile +3 -1
 ifeq ("$(origin M)", "command line")
-  KBUILD_EXTMOD := $(M)
+  __KBUILD_EXTMOD := $(M)
 endif
 
+KBUILD_EXTMOD = $(patsubst %/,%,$(__KBUILD_EXTMOD))
+
 # If building an external module we do not care about the all: rule
 # but instead _all depend on modules
 PHONY += all

This patch would break a use-case
where KBUILD_EXTMOD is given as an environment.

Maybe adding the following should be enough?

KBUILD_EXTMOD := $(patsubst %/,%,$(KBUILD_EXTMOD))

Signature · 2 lines
Best Regards
Masahiro Yamada
author
#2 lore raw
Quoted 35 lines · Masahiro Yamada

Hi Wei,

2017-02-23 0:08 GMT+09:00 Wei Yang <[email protected]>:

Quoted 31 lines

Current kbuild will build the target again if we run "make M=dir" and "make M=dir/" by turns, since if_changed will see the prerequisite is changed. The behavior may confuse the user a little, since actually we are building the same target and no difference.

According to current implementation in scripts/Makefile.build, the obj passed to next level is a directory name with last slash stripped. This patch strips the last slash in KBUILD_EXTMOD which is assigned from "M=".

---
 Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Makefile +2 -2
index b1037774e8e8..db6ed60928ab 100644
@@ -184,13 +184,15 @@ endif
 # Old syntax make ... SUBDIRS=$PWD is still supported
 # Setting the environment variable KBUILD_EXTMOD take precedence
 ifdef SUBDIRS
-  KBUILD_EXTMOD ?= $(SUBDIRS)
+  __KBUILD_EXTMOD ?= $(SUBDIRS)
 endif
 
 ifeq ("$(origin M)", "command line")
-  KBUILD_EXTMOD := $(M)
+  __KBUILD_EXTMOD := $(M)
 endif
 
Quoted 9 lines

Makefile endif · line 198

Quoted 5 lines
Makefile +2 -0
+KBUILD_EXTMOD = $(patsubst %/,%,$(__KBUILD_EXTMOD))
+
 # If building an external module we do not care about the all: rule
 # but instead _all depend on modules
 PHONY += all

This patch would break a use-case
where KBUILD_EXTMOD is given as an environment.

Hi, Masahiro

Thanks for your comment.

Got your point, you are right.

Quoted 6 lines

Maybe adding the following should be enough?

KBUILD_EXTMOD := $(patsubst %/,%,$(KBUILD_EXTMOD))

Yep, it looks good.

BTW, I found another interesting thing.

     make M=dir//// 

is also a valid target in kbuild.

Even this is a very rare case, I plan to use this to handle it.

KBUILD_EXTMOD := $(subst $(CURDIR)/,,$(KBUILD_EXTMOD))

This also works for an out tree build.

I would send out v2 soon, hope you like this.

Quoted 4 lines
Signature · 3 lines
-- 
Best Regards
Masahiro Yamada
Signature · 2 lines
Wei Yang
Help you, Help me