kbuild: Abort build if SUBDIRS used
authorBen Hutchings <benh@debian.org>
Mon, 26 Apr 2021 16:27:16 +0000 (18:27 +0200)
committerSalvatore Bonaccorso <carnil@debian.org>
Mon, 18 Apr 2022 12:36:36 +0000 (13:36 +0100)
Forwarded: not-needed
Bug-Debian: https://bugs.debian.org/987575

DKMS and module-assistant both build OOT modules as root.  If they
build an old OOT module that still use SUBDIRS this causes Kbuild
to try building a full kernel, which obviously fails but not before
deleting files from the installed headers package.

To avoid such mishaps, detect this situation and abort the build.

The error message is based on that used in commit 0126be38d988
"kbuild: announce removal of SUBDIRS if used".

Gbp-Pq: Topic debian
Gbp-Pq: Name kbuild-abort-build-if-subdirs-used.patch

Makefile

index 458364e3cbaf97b7292d6f6b3035809e86ce42ae..7c34a9e039a2992c36a2d710d5bcf60ac574bdd7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -126,6 +126,18 @@ ifeq ("$(origin M)", "command line")
   KBUILD_EXTMOD := $(M)
 endif
 
+# Old syntax make ... SUBDIRS=$PWD should be rejected to avoid mishaps
+# (see Debian bugs #982334, #987575)
+ifndef KBUILD_EXTMOD
+  ifdef SUBDIRS
+    $(warning =============== ERROR ==============)
+    $(warning 'SUBDIRS' was removed in Linux 5.3)
+    $(warning Use 'M=' or 'KBUILD_EXTMOD=' instead)
+    $(warning ====================================)
+    $(error .)
+  endif
+endif
+
 $(if $(word 2, $(KBUILD_EXTMOD)), \
        $(error building multiple external modules is not supported))