The makefile template is as follows:
#编译hello. o When combined with predefined debug_testcflags_hello.o + =-ddebug_test# Compile all time with predefined my_debugextra_cflags + =-dmy_debug# Specifies the final generated target # if only a single file can be written as "obj-m: = hello.o" Obj-m + = hello.o# Specify which modules are required to generate the hello.o file (if only a single file can delete the following line), # If the hello.o requires multiple file composition, it can be written like this: #isdn-objs: = isdn_net_lib.o isdn_v110.o isdn_common.o separate modules with spaces HELLO-OBJS: = src/ Hello.okid: =/lib/modules/$ (Shell uname-r)/buildpwd: = $ (shell pwd) All: make-c $ (KID) m=${pwd} Modulesclean: r m -rf *.o *.cmd *.ko *.mod.c .tmp_versions *.ko.unsigned *.order *.symvers rm -rf src/*.o src/*.cmd src/*.ko src/*.mod . C Src/.tmp_versions src/*.ko.unsigned Src/*.order src/*.symvers
The hello.c file is as follows:
#include <linux/module.h>//header files required for all modules #include <linux/init.h> //INIT&EXIT related macro module _license ("GPL"); static int __init hello_init (void) { printk (kern_err "# # # Hello world\n"); return 0; } static void __exit hello_exit (void) { printk (kern_err "# # # exit\n");} Module_init (hello_init); Module_exit (Hello_exit);
HELLO.C please put in makefile under the same directory under the SRC folder!!!
Kbuild's makefile Template