Learning makefile loaded by Linux Device Drivers

Source: Internet
Author: User

Because of work needs, now we need to learn the Linux Device Driver. Starting from the simplest character device driver, we need to record our learning experience and stick to our own ideas and conclusions.

The makefile I wrote for the first hello World character driver is as follows:

# Kvers = $ (shell uname-R)

Ifneq ($ (kernelrelease ),)

OBJ-M + = hello_world.o

 

Else

Kerdir =/usr/src/linux-headers-3.2.0-33-generic

#/Lib/modules/3.2.0-33-generic/build

#/Usr/src/linux-headers-3.2.0-33-generic

Curdir =/home/wangyihong/My-Drivers/first-Driver/

Default:

$ (Make)-C $ (kerdir) M = $ (curdir) Modules

 

Clean:

$ (Make)-C $ (kerdir) M = $ (curdir) clean

Endif

The first ifneq ($ (kernelrelease) indicates that if kernelrelease has been defined, the following statement is executed. If not, the else branch is executed. Obviously, the end of the comma is blank. Obviously, the kernelrelease is empty when make starts, and the two execute the else branch statement equally.

Kerdir =/usr/src/linux-headers-3.2.0-33-generic specifies the directory where the kernel source code is stored, in fact

Kerdir =/lib/modules/$ (shelluname-R)/build can also be found, their internal structure is the same, $ (shelluname-R) indicates the execution of Shell Command uname
-R: Output kernel version

Curdir =/home/wangyihong/My-Drivers/first-driver is the path where the driver source program is stored.

When making, first run the default: $ (make)-C $ (kerdir) m =$ (curdir) modules of the else branch, $ (make) indicates make, -C $ (kerdir) indicates to execute the makefile in the directory where the kernel is stored. During the execution, the kernelrelease is defined, and then M = $ (curdir) indicates to return to the current directory, execute makefile again. Modules indicates the meaning of compiling to a module.

If kernelrelease is defined, obj-M + = hello_world.o is executed, which indicates that the hello_world.o target will be compiled into the. Ko module. If multiple source files exist, use the following method:

OBJ-M: = hello_world.o
Hello_world-objs: = file1.o file2.o file3.o

At the end of the make clean object, all files generated by make will be deleted.

The above is an analysis summary of a makefile that I learned to load for the hello World Driver Module. If there are any errors, please correct me. cainiao will start the linxu Device Driver journey!

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.