$ tree .
|-- Makefile
|-- a.c
|-- m
| |-- b.h
| `-- b.c
//a.c
#include <linux/init.h>
#include <linux/module.h>
#include "b.h"
MODULE_LICENSE("GPL");
static __init int a(void)
{
led_on();
return 0;
}
static __exit void b(void)
{
led_off();
}
module_init(a);
module_exit(b);
//b.h
#ifndef _B_H_
#define _B_H_
void led_on(void);
void led_off(void);
#endif // _B_H_
//b.c
#include <linux/module.h>
#include "b.h"
void led_on(void)
{
printk("%s %d LED ON\n", __func__, __LINE__);
}
void led_off(void)
{
printk("%s %d LED OFF\n", __func__, __LINE__);
}
#Makefile
PWD=$(shell pwd)
TARGET := test
obj-m = $(TARGET).o
$(TARGET)-objs = a.o ./m/b.o
#KERN = /share/arm/linux-3.2
KERN = /lib/modules/`uname -r`/build/
EXTRA_CFLAGS += -I$(INCDIR) #关键
all:
make -C $(KERN) M=`pwd` $(CFLAGS) INCDIR=$(PWD)/m modules
clean:
make -C $(KERN) M=`pwd` INCDIR=$(PWD)/m modules clean
# rm -rf modules.order
#no more