2

In Debian when I want to compile my kernel module I need to install linux-header-* package and then I need to write some makefile like this:

obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

But now I have downloaded specific kenel from kernel.org and compile it. So how can I address the KDIR variable in my makefile?

I want to know, how Debian mainteners create linux-header-* packages?

5

You don't have to.

KDIR := /lib/modules/$(shell uname -r)/build

Presumes you are building a module for the currently running kernel, since it uses $(shell uname -r) to complete the path. When you build a kernel and run make modules_install, the modules are copied into a corresponding directory in /lib/modules -- this will match the output of uname -r for that kernel.

The build subdirectory is a link to the kernel source tree. So don't erase that, obviously.

If you are compiling for a different kernel than the running one, just set KDIR to the source directory where you built it.

  • Great, yes I created linux headers. but now, how can I create build subdirectory? In my debian, build doesn't link to all kernel source tree. – Milad Khajavi Dec 7 '13 at 17:45
  • 2
    build doesn't even have to be there at all for the system to work, in fact. But it does if you want to use that makefile with the running kernel. If there's a build directory in the distro /lib/modules/X.x-whatever, whatever it is is at least part of a source tree -- that probably gets installed when you install a "kernel sources" package. If it's empty or not there, that's because you haven't installed such a package. But you don't need it if you are building from a source you downloaded yourself. The distro stuff won't be involved anyway. – goldilocks Dec 7 '13 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.