模板编写一个简单的Makefile,如下所示:
obj-m := hello.o
并使用如下命令编译Hello World模块,如下所示:
make -C /usr/src/linux-2.6.15.5/ M=/driver_study/ modules
如果当前处于模块所在的目录,则以下命令与上述命令同等:
make –C /usr/src/linux-2.6.15.5 M=$(pwd) modules
其中-C后指定的是Linux内核源代码的目录,而M=后指定的是hello.c和Makefile所在的目录,编译结果如下所示:
[root@localhost driver_study]# make -C /usr/src/linux-2.6.15.5/
M=/driver_study/ modules
make: Entering directory '/usr/src/linux-2.6.15.5'
CC [M] /driver_study/hello.o
/driver_study/hello.c:18:35: warning: no newline at end of file
Building modules, stage 2.
MODPOST
CC /driver_study/hello.mod.o
LD [M] /driver_study/hello.ko
make: Leaving directory '/usr/src/linux-2.6.15.5'