3

Given a package that uses autoconf (a configure script) to provide both a user-mode application and a kernel driver, with a directory structure like this:

configure.ac
configure
Makefile.am
user
    Makefile.am
    user.c
driver
    Makefile.am
    Kbuild.in
    driver.c

This successfully configures and builds both user and driver when configured locally (run ./configure --options).

However a useful feature of configure scripts is that you can have a separate source and build directory, simply by running the script from the build directory, eg:

mkdir build && cd build && ../configure --options

This works fine for the user app, but I'm having trouble getting the kernel driver to build in this context. In the driver's Makefile.am I have the following, as suggested in this answer:

modules:
    $(MAKE) -C "$(LINUX_SOURCE_DIR)" M="@abs_builddir@" src="@abs_srcdir@" modules

But this fails to compile, as it's expecting the Kbuild or Makefile to be in src, but they're actually in M. Omitting src does let it find the Kbuild but it then fails to find the actual source files (no rule to make target //path/in/build//driver.o).

Using O= as some other answers suggest is not correct, as this specifies the path to find the kernel's output files (.config etc) and these are still in the LINUX_SOURCE_DIR. (So trying to use it results in various other missing-file errors.)

I'm hoping for a solution that doesn't require modifying any actual Kbuild scripts, since those are outside my package's control.

Thus far the best option I've come up with is to copy/link all the module source files into the build directory before calling Kbuild, which is not ideal. I'm hoping there's a hidden setting that can be used for this.

Community
  • 1
  • 1
Miral
  • 12,637
  • 4
  • 53
  • 93
  • 2
    `Thus far the best option I've come up with is to copy/link all the module source files into the build directory before calling Kbuild` - I know no other way for out-of-source build of the kernel modules. – Tsyvarev Apr 27 '17 at 08:07
  • @Tsyvarev, oh, really? The above excerpt shows how to get it `make -C "$KERNEL_BUILD_DIR" M=$PWD modules`, if you want to compile module in $PWD for kernel which build files are located in $KERNEL_BUILD_DIR. – 0andriy Apr 27 '17 at 12:37
  • Did you try to remove `src="@abs_srcdir@"` from your *Makefile*? – 0andriy Apr 27 '17 at 12:40
  • 1
    @0andriy: In command line `make -C "$KERNEL_BUILD_DIR" M=$PWD modules` variable `KERNEL_BUILD_DIR` actually refers to kernel core build directory, which is actually a kernel source directory too. Option `M` refers to module's source dir, but **resulted files will be placed in this directory too**. So, there is no separation "module source dir" and "module build dir" here. – Tsyvarev Apr 27 '17 at 13:41

0 Answers0