Thread view

Hello!
It's not easy to compile ndiswrapper for a kernel that is not currently
used or installed (i.e. there is no link in /lib/modules). Both KVERS
and KBUILD should be set, which is inconvenient.
The logic that has been used in many other standalone drivers is
different. The version of the current kernel is only used to locate the
kernel tree. It's possible that the kernel sources have been updated,
so the actual kernel version should be taken from the configured kernel
tree.
Some older kernels were only installing the "source" link, so if the
"build" link is missing, "source" is the fallback. It's important if
ndiswrapper still aims to support 2.4 kernels.
If .config is missing, it should be an error. Otherwise, there is a
risk that the module will be miscompiled.
"readlink -f" is used so that the actual tree location is shown, as
opposed to the link.
Now it's sufficient to override KBUILD. It's still possible to override
KVERS if the kernel is installed.
Signed-off-by: Pavel Roskin <proski@...>
Index: driver/Makefile
===================================================================
--- driver/Makefile (revision 2426)
+++ driver/Makefile (working copy)
@@ -5,12 +5,41 @@
winnt_types.h workqueue.c wrapmem.h wrapmem.c wrapper.c \
wrapndis.h wrapndis.c lin2win.h win2lin_stubs.S
+# By default, we try to compile the modules for the currently running
+# kernel. But it's the first approximation, as we will re-read the
+# version from the kernel sources.
KVERS ?= $(shell uname -r)
+
+# KBUILD is the path to the Linux kernel build tree. It is usually the
+# same as the kernel source tree, except when the kernel was compiled in
+# a separate directory.
+KBUILD ?= $(shell readlink -f /lib/modules/$(KVERS)/build)
+
+# Some old kernels only install the "source" link
+ifeq (,$(KBUILD))
+KBUILD := $(shell readlink -f /lib/modules/$(KVERS)/source)
+endif
+
+ifeq (,$(KBUILD))
+$(error Kernel tree not found - please set KBUILD to configured kernel)
+endif
+
+# Kernel Makefile doesn't always know the exact kernel version, so we
+# get it from the kernel headers instead and pass it to make.
+
+VERSION_H := $(KBUILD)/include/linux/utsrelease.h
+ifeq (,$(wildcard $(VERSION_H)))
+VERSION_H := $(KBUILD)/include/linux/version.h
+endif
+ifeq (,$(wildcard $(VERSION_H)))
+$(error Cannot find kernel version in $(KBUILD), is it configured?)
+endif
+
+KVERS := $(shell sed -ne 's/"//g;s/^\#define UTS_RELEASE //p' $(VERSION_H))
KPSUB := $(shell echo $(KVERS) | sed -e 's/\([^\.]*\)\.\([^\.]*\)\..*/\1\2/')
# distros use different paths for kernel include files
-KBUILD ?= /lib/modules/$(KVERS)/build
KSRC ?= $(shell if \
[ -f /lib/modules/$(KVERS)/source/include/linux/kernel.h ]; then \
echo /lib/modules/$(KVERS)/source ; \
@@ -30,7 +59,11 @@
KREV := $(shell echo $(KVERS) | sed -e 's/[^\.]*\.[^\.]*\.\([0-9]*\).*/\1/')
--include $(KBUILD)/.config
+KCONFIG := $(KBUILD)/.config
+ifeq (,$(wildcard $(KCONFIG)))
+$(error No .config found in $(KBUILD), please set KBUILD to configured kernel)
+endif
+include $(KBUILD)/.config
CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
echo -DEXPORT_SYMTAB -DMODVERSIONS \
--
Regards,
Pavel Roskin