Linux-powered Modular drive Makefile

Source: Internet
Author: User

This digest from http://blog.csdn.net/lufeiop02/article/details/6446343

Linux drivers are generally loaded in the form of module modules, which first need to compile the driver into the form of a module. A simple example,

#include <linux/init.h>#include<linux/kernel.h>#include<linux/module.h>Static int__init Test_init (void) {PRINTK ("Init module/n"); return 0;}Static void__exit Test_exit (void) {PRINTK ("Exit modules/n");} Module_init (Test_init); Module_exit (test_exit);

Makefile is:

PWD ==/usr/src/linux-source-2.6. / obj-M: = test.omodule-objs: = test.o All:       -C $ (KERNEL_SRC) m=$ (PWD) Modules Clean       :       *. Ko       *.o

Run make in the same directory as test.c and makefile, if you see similar output

Make-c/usr/src/linux-source-2.6. m=/home/vmeth modulesmake[1]: Entering directory '/usr/src/linux-source-2.6 .  the '  CC [M]  /home/vmeth/hello.o  2.  Modpost  CC      /home/vmeth/hello.mod.o  LD [M]  /home/vmeth/hello.komake[  1]: Leaving directory '/usr/src/linux-source-2.6.  the '

# Makefile2. 6 Ifneq ($ (kernelrelease),) #kbuild syntax. Dependency Relationshsip of files and target modules are listed Here.mymodule -OBJS: = hello.oobj-M: =   hello.oelsePWD  :=? = $ (shell Uname-R) Kdir:=/lib/modules/$ (kver)/build #KDIR目录其实是链接到上面那个Makefile中的那个                                          /usr/src/ linux-source-2.6.  the /* All in:       $ (make)-C $ (Kdir) m=$ (PWD) Clean:       rm-rf. *.cmd *.o *.mod.c *.ko. Tmp_versionsendif

Kernelrelease is a variable defined in the top-level makefile of the kernel source, and kernelrelease is not defined when the first read executes this makefile, so make reads the content after the else is executed. When the target of make is all, the-C $ (kdir) indicates that jumping to the kernel source directory reads the makefile;m=$ (PWD) there and then returns to the current directory to continue to read in and execute the current makefile. When returned from the kernel source directory, Kernelrelease has been defined and Kbuild is also initiated to parse the Kbuild syntax, and make will continue to read the content before else. Else before is a Kbuild syntax statement that indicates the dependencies of the files in the module's source code and the name of the target module to be generated. The name of each kernel contains its version number, which is also the value displayed by the Uname-r command. Resolution for the following error: makefile:1: * * * missing delimiter This has a number of situations: 1, the command before the TAB key 2, may be the punctuation into a Chinese-shaped 3, such as the above file: Ifneq to add a space after

Linux-powered Modular drive Makefile

Related Article

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.