kbuild: remove trailing slashes from $(KBUILD_EXTMOD)
authorMasahiro Yamada <masahiroy@kernel.org>
Wed, 2 Jun 2021 14:02:13 +0000 (23:02 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Thu, 17 Jun 2021 00:50:59 +0000 (09:50 +0900)
commit74ee585b7eecd98be3650e677625a0ee588d08e0
treee62e213c8cbf35b48322f18149ffd2a902464da6
parentc7c90e121e992eefdf07945e5a6e9cf097b29463
kbuild: remove trailing slashes from $(KBUILD_EXTMOD)

M= (or KBUILD_EXTMOD) generally expects a directory path without any
trailing slashes, like M=a/b/c.

If you add a trailing slash, like M=a/b/c/, you will get ugly build
logs (two slashes in a series), but it still works fine as long as it
is consistent between 'make modules' and 'make modules_install'.

The following commands correctly build and install the modules.

  $ make M=a/b/c/ modules
  $ sudo make M=a/b/c/ modules_install

Since commit ccae4cfa7bfb ("kbuild: refactor scripts/Makefile.modinst"),
a problem happens if you add a trailing slash only for modules_install.

  $ make M=a/b/c modules
  $ sudo make M=a/b/c/ modules_install

No module is installed in this case, Johannes Berg reported. [1]

Trim any trailing slashes from $(KBUILD_EXTMOD).

I used the 'dirname' command to remove all the trailing slashes in
case someone adds more slashes like M=a/b/c/////. The Make's built-in
function, $(dir ...) cannot take care of such a case.

[1]: https://lore.kernel.org/lkml/10cc8522b27a051e6a9c3e158a4c4b6414fd04a0.camel@sipsolutions.net/

Fixes: ccae4cfa7bfb ("kbuild: refactor scripts/Makefile.modinst")
Reported-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Makefile