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 (<ARG1>;, <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