Makefile of Linux 2.6 kernel module

Source: Internet
Author: User


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 );

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.