#include <linux/kernel.h>
#include <linux/module.h>
static int __init test_init(void)
{
printk("init module\n");
return 0;
}
static void __exit test_exit(void)
{
printk("exit modules\n");
}
module_init(test_init);
module_exit(test_exit);
KERNEL_SRC = /usr/src/linux-source-2.6.15/
obj-m := test.o
module-objs := test.o
all:
$(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules
clean:
rm *.ko
rm *.o
make[1]: Entering directory `/usr/src/linux-source-2.6.15'
CC [M] /home/vmeth/hello.o
Building modules, stage 2.
MODPOST
CC /home/vmeth/hello.mod.o
LD [M] /home/vmeth/hello.ko
make[1]: Leaving directory `/usr/src/linux-source-2.6.15'
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.
mymodule-objs := hello.o
obj-m := hello.o
else
PWD := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build #KDIR目录其实是链接到上面那个Makefile中的那个
/usr/src/linux-source-2.6.15/*中
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif