Makefile of the kernel module in Linux 2.6
Favorites
Makefile of the kernel module in Linux 2.6
# Makefile 2.6
OBJ-M + = Hello. o
Kdir: =/lib/modules/$ (shell uname-R)/build
# Pwd = $ (shell PWD)
ALL:
Make-C $ (kdir) M = $ (PWD) Modules
Clean:
Make-C $ (kdir) M = $ (PWD) clean
OBJ-M: = Hello. O indicates that the hello. O module is generated after compilation.
$ (Kdir) specifies the path of the kernel source code. "m =" indicates that this is an external module, and m = $ (PWD) specifies the path of the module File.
Note:Makefile
Predefined$ (PWD)
Variable.
If a module is compiled from multiple source files and the module name is test. Ko, the source file name cannot contain test. C.
OBJ-M: = test. o
Test-objs: = file1.o file2.o file3.o
Kdir: =/lib/modules/$ (shell uname-R)/build
# PWD: = $ (shell PWD)
ALL:
Make-C $ (kdir) M = $ (PWD) Modules
Clean:
Example of a simple kernel module: Hello. c
# Include <Linux/module. h>
# Include <Linux/init. h>
Module_license ("GPL ");
Static int _ iinit hello_init (void)
{
Printk ("Hello, world/N ");
Return 0;
}
Static void _ exit hello_exit (void)
{
Printk ("goodbe/N ");
}
Module_init (hello_init );
Module_exit (hello_exit );