主程序:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk("<1> Hello, world/n");
return 0;
}
static void hello_exit(void)
{
printk("<1> Goodbye, cruel world/n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile:
#KERNELDIR = /home/blan/build/kernel
KERNELDIR = /usr/src/linux-headers-2.6.32-21-generic
# The current directory is passed to sub-makes as argument
PWD := $(shell pwd)
INSTALLDIR = /lib/modules
CC = gcc
obj-m := helloworld.o
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
cp helloworld.ko $(INSTALLDIR)
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY: modules modules_install clean