You have to set up a kernel make enviroment. So a simple gcc would not suffice. You need to have both a makefile, and a kbuild file. I can't tell you for the latest kernel, I worked on an older kernel, and the build process may have changed a bit.
Let's say you have the following module:
Code:
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
MODULE_DESCRIPTION("My kernel module");
MODULE_AUTHOR("Me");
MODULE_LICENSE("GPL");
static int dummy_init(void)
{
printk( KERN_DEBUG "Hi\n" );
return 0;
}
static void dummy_exit(void)
{
printk( KERN_DEBUG "Bye\n" );
}
module_init(dummy_init);
module_exit(dummy_exit);
Let' say you call this module.c
You will also need a Makefile, and a kbuild file:
The makefile:
Code:
KDIR=/lib/modules/`uname -r`/build
kbuild:
make -C $(KDIR) M=`pwd`
clean:
make -C $(KDIR) M=`pwd` clean
The Kbuild file: (note that you may only need the kbuild file.. dunno the newer kernels - that should have worked on 2.6.12)
Code:
EXTRA_CFLAGS=-g
obj-m = module.o
and then make!. The output should be a .ko module. You may need to tune this a bit to work on the current kernel versions.
Links:
http://tldp.org/LDP/lkmpg/2.6/html/index.html - the linux kernel programming guide
http://lwn.net/images/pdf/LDD3/ch02.pdf // linux Device drivers third edition, 2nd chapter
There is also a cd Linux ddk, google it and you will get everything you need (including a kernel) on one big .iso file.
A small tip: never sleep while holding a lock!