A step-by-step study of Linux driver driver module makefile analysis

Source: Internet
Author: User

When the make command executes, a Makefile file is required to tell the make command what to do to compile and link the program.

First, the use of conditions to judge

The following example determines whether the $ (CC) variable is "gcc" and, if so, compiles the target using the GNU function.

LIBS_FOR_GCC =-lgnu normal_libs = foo: $ (objects) ifeq ($ (cc), GCC)      $ (cc)-o foo $ (objects) $ (LIBS_FOR_GCC) Else      

It can be seen that in this rule of the example above, the target "foo" could choose a different library of functions to compile the program based on the variable "$ (CC)" value.

We can see three keywords from the above example: ifeq, else and endif

LIBS_FOR_GCC =-lgnu Normal_libs = ifeq ($ (CC), GCC)     libs=$ (LIBS_FOR_GCC) Else     libs=$ (normal_libs) endif foo: $ ( Objects      
Here is an analysis of an arm driver

Ifneq ($ (kernelrelease),) obj-m: =hello.oelsekerneldir: =/home/zp1015/desktop/linux-2.6.32.2all:make-c $ (KERNELDIR) m=$ (PWD) modules Arch=arm cross_compile=arm-linux-clean:rm-f *.o *.ko *.mod.o *.mod.c *.symvers modul*endif

1, ifeq "syntax is ifeq (&LT;ARG1&GT;;, <arg2>;), the function is to compare the values of the parameter" Arg1 "and" arg2 "are the same. Ifneq just the opposite, comparing the values of the two is differentSome of them are common or we have seen, the first oneIfneq ($ (kernelrelease),)at present, it is useful to refer to the origin ofLinuxunder the source root directoryMakefilewhen compiling the kernel,Kernelreleasemacros are defined, so if you start from the source root directory Makeit will behello.oThe module is compiled into the kernel.

< Span style= "font-size:14px" >KERNELDIR: =/ home/zp1015/desktop/linux-2.6.32.2   kerneldir Assignment, This variable is used to refer to the kernel source directory that we used later.

2, Make-c $ (kerneldir) m=$ (PWD) modules Arch=arm cross_compile=arm-linux-

This sentence isMakefilethe rules: here's the$ (make)is equivalent to Make,- C The purpose of the option is to transfer the current working directory to the location you specify . "m=" The purpose of the option is that when a user needs to compile an external module based on a kernel, it needs to beMake modulescommand to add the"M=dir", the program automatically takes you to the specifieddirdirectory to find the module source code, compile it, generateKO file. m is not an option for makefile, it is a variable used in Makefile in the kernel root directory



A step-by-step study of Linux driver driver module makefile analysis

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.