Kernel modules out of tree build (was: Setting up NFS client)

Michael Abbott michael at araneidae.co.uk
Sun Apr 19 10:50:38 UTC 2009


On Sun, 19 Apr 2009, Gilles Espinasse wrote:
> From: "Michael Abbott" <michael at araneidae.co.uk>
> > P.S.  Anybody here know how to build out of tree kernel modules so that
> > the built files are in their own "out of tree" directory?  Two quite
> > different uses of the term "out of tree" here, and necessarily four
> > separate directories: 1. kernel sources; 2. kernel build directory; 3.
> > module sources; 4. module build directory.  Unfortunately I haven't found
> > any way to avoid (3)==(4).
> 
> It depend of the module Makefile you build against
> You usually need to indicate where the kernel sources, especially when the
> kernel version running is not the same as the kernel version you build. If
> it's the same version, usually Makefile find it at
> /usr/src/linux-$(uname -r)
> 
> For openswan for example, when running kernel is not the same as kernel
> build, you have to, inside openswan package directory run
> make KERNELSRC=/usr/src/linux-$(KVER) module
> 
> Usually out of tree modules are installed in /lib/modules/<KVER>/extra

Let me be a bit clearer and more explicit.  Some symbols (from my 
makefile, none of these are exported):

KERNEL_SOURCE_DIR = /path/to/kernel/source/tree
MODULE_SOURCE_DIR = /path/to/module/source/tree

KBUILD_OUTPUT = /path/to/kernel/build
MODULE_OUTPUT = /path/to/module/build

I'm actually cross-compiling, so there are also exports of CROSS_COMPILE 
and ARCH which we don't need to see here.


The kernel was built with the command

	make -C $(KERNEL_SOURCE_DIR) O=$(KBUILD_OUTPUT) uImage


The problem comes when I try to build the module.  In $(MODULE_SOURCE_DIR) 
I have a Kbuild with just two lines:

	obj-m := my-module.o
	my-module-objs := my-module-source.c

Currently I build with

	make -C $(KBUILD_OUTPUT) M=$(MODULE_SOURCE_DIR)

and of course my build output appears in $(MODULE_SOURCE_DIR) -- and of 
course MODULE_OUTPUT never got communicated to the kernel makefile.  
Unfortunately I can't see any way to do that...

I've tried a variety of combinations on this make command, but I'm running 
a bit blind here.  I can't see any way to specify all four directories to 
the make system!  I guess the next step is going to have to be to trace 
all the way through the kernel build ... ouch.


More information about the busybox mailing list