hello.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
static int hello_init(void)
{
printk("hello_init,this is a kernel module test!\n");
return 0;
}
static void hello_exit(void)
{
printk("hello_exit,this is a kernel module test!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPLv3");
Makefile
obj-m := hello.o
KERNEL_DIR := /usr/src/kernels/2.6.32-220.el6.x86_64
PWD := $(shell pwd)
default:
make -C $(KERNEL_DIR) M=$(PWD) modules
clean:
rm -fr *.ko.*
rm -fr *.mod.*
rm -fr *.o
rm -fr *.cmd
rm -fr *.order
rm -fr *.symvers
# -C $(KERNEL_DIR)进入内核源码主目录读取顶层Makefile
# M=$(PWD) 读取主Makefile后返回当前目录继续make