[hirasawa@cent5-64b-40 ~]$ cat Makefile
obj-m := hello.o
ROOTDIR := ~/rpmbuild/BUILD/kernel-2.6.18/linux/
PWD := $(shell pwd)
default:
$(MAKE) -C $(ROOTDIR) M=$(PWD) modules
clean:
rm -f *.o *.ko
[hirasawa@cent5-64b-40 ~]$
#include <linux/module.h> // required by all modules
#include <linux/kernel.h> // required by printk()
#include <linux/init.h>
MODULE_LICENSE("GPL2");
MODULE_DESCRIPTION("hello");
MODULE_AUTHOR("toshi");
// Start/Init function
static int hello_init(void) {
printk(KERN_ALERT "Hello world!\n");
return 0;
}
// End/Cleanup function
static void hello_exit(void) {
printk(KERN_ALERT "Goodbye world!\n");
}
module_init(hello_init);
module_exit(hello_exit);