diff -Nur a/Makefile b/Makefile
--- a/Makefile	2022-10-19 22:19:09.000000000 +0100
+++ b/Makefile	2022-11-02 09:34:05.857715688 +0000
@@ -33,25 +33,25 @@
 # SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
 #
 
-ifneq ($(KERNELRELEASE),)
+ifneq ($(KBUILD_EXTMOD),)
 
-# Building from kBuild (make -C <kernel_directory> M=`pwd`),
-# or inside a kernel source tree.
+# Building from kBuild (make -C <kernel_directory> M=`pwd`).
+# KBUILD_EXTMOD is set to $(M) in this case.
 
 obj-m = vboxdrv/
- ifneq ($(wildcard $(CURDIR)/vboxnetflt/Makefile),)
+ ifneq ($(wildcard $(KBUILD_EXTMOD)/vboxnetflt/Makefile),)
 obj-m += vboxnetflt/
  endif
- ifneq ($(wildcard $(CURDIR)/vboxnetadp/Makefile),)
+ ifneq ($(wildcard $(KBUILD_EXTMOD)/vboxnetadp/Makefile),)
 obj-m += vboxnetadp/
  endif
- ifneq ($(wildcard $(CURDIR)/vboxpci/Makefile),)
+ ifneq ($(wildcard $(KBUILD_EXTMOD)/vboxpci/Makefile),)
 obj-m += vboxpci/
  endif
 
-else # ! KERNELRELEASE
+else # ! KBUILD_EXTMOD
 
-# convenience Makefile without KERNELRELEASE
+# convenience Makefile without KBUILD_EXTMOD
 
 ifndef SUDO
  ifneq ($(shell id -u),0)
@@ -244,5 +244,6 @@
 		fi; \
 	done
 
-endif # ! KERNELRELEASE
+endif # ! KBUILD_EXTMOD
+