diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 13ec3e96650c..69d74661d3d5 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -83,7 +83,17 @@ MODPOST += -e input-symdump := Module.symvers $(KBUILD_EXTRA_SYMBOLS) output-symdump := $(KBUILD_EXTMOD)/Module.symvers -module_srcpath := $(KBUILD_EXTMOD) + +# Get the external module's source path. KBUILD_EXTMOD could either be an +# absolute path or relative path from $(srctree). This makes sure that we +# aren't using a relative path from a separate working directory (O= or +# KBUILD_OUTPUT) since that may not be the actual module's SCM project path. So +# check the path relative to $(srctree) first. +ifneq ($(realpath $(srctree)/$(KBUILD_EXTMOD) 2>/dev/null),) + module_srcpath := $(srctree)/$(KBUILD_EXTMOD) +else + module_srcpath := $(KBUILD_EXTMOD) +endif endif