summerdog
summerdog

Reputation: 91

How to build kernel module without full kernel source tree?

I would like to build a kernel module without the kernel source tree. For that, I specified the kernel header directory only.

This reference link tell me it should be workable :
build kernel module w/o source tree

But some other reference links tell me I should build my kernel module with full kernel source tree!

My questions are :

  1. Shall I build kernel module link with full kernel source tree ?
  2. Is it necessary to do a full build under kernel source tree before build my single module ?

Upvotes: 4

Views: 8790

Answers (2)

KikiYu
KikiYu

Reputation: 3267

No to both questions. You're talking about out-of-tree (or "external") modules.

Here is a tutorial of Building External Modules.

And here is a simple sample of a Makefile.

obj-m += your-module.o
KDIR=/lib/modules/`uname -r`/build
default:
    $(MAKE) -C $(KDIR) M=$(PWD) modules

Upvotes: -1

Alexander Dzyoba
Alexander Dzyoba

Reputation: 4189

  1. Not it's not necessary. You need a header files that contains function and types declarations. You also kernel tree with Makefiles and Kconfig but without sources. This kernel tree is needed by kbuild - kernel building system.

  2. Absolutely not. You can build a single module without building whole kernel regardless of it's out-of-tree or in-tree module.

Upvotes: 3

Related Questions