The execution order GNU Makefile

Gnu make the implementation process is divided into two stages

The first stage: to read all of the makefile (including "MAKEFILES" specified variable, the indicator "include" specified, as well as command-line option "-f (- file)" specified in the makefile), built-in variables , clear rules and implicit rules and establishes the structure of the list of dependencies between all targets and rely on.

The second stage: to decide which targets need to be updated, and use the corresponding rules to reconstruct the structure of the target list first stage of dependency has been established.

Make the implementation process is as follows:
1. List the makefile read sequentially variable "MAKEFILES" definition
2. Read the makefile in the working directory (the default is named according to the search order "GNUmakefile", "makefile", "Makefile", first find that you read that)
3. sequentially reads the makefile in the working directory using the indicator "include" files included
4. Find the makefile rules to rebuild all that has been read (if there is one goal of a current read a makefile, then rebuild this rule is enforced makefile file, re-start after the completion of the first step execution)
The variable values ​​and initializes the variables and functions that need to expand immediately launched and execution branches determined in accordance with a preset condition
6. Establish dependency list based on dependencies "ultimate goal" and other goals
7. implementation of the rules all the goals except the "ultimate goal" (rule if the timestamp of any dependent file a new file than the target file, use the command defined by the rules rebuilding target file)
8. Implementation Rules "ultimate goal" is located

(1) list in order to read the makefile variable "MAKEFILES" definition 
Look there is no definition in the current environment "MAKEFILES" environment variable, if MAKEFILES environment variable is defined, it will make before reading the other makefile, first read the list MAKEFILE defined names (separated by spaces). We do not recommend to define the environment variable, because we did not know much about the use of this variable, it often leads to some strange errors.
(2) Makefile files in the working directory read
         Specify the makefile method is to use the file name ' -f ' or ' --file ' option ( ' --makefile ' will also work). For example, ' -f altmake ' instructions called ' altmake file' as makefile file. If you do not use ' -f ' or ' --file ' option, the default look is in order, 'GNUmakefile' , 'Makefile' , and 'Makefile' , using the presence of these three files can be found in the first or files can be created.
(3) sequentially reads the makefile in the working directory using the file indicator "include" contained 
For example, the following can be found in the main Makefile u-boot file which "include", it is to config.mk files under the top-level Makefile to the directory that contains the file.
The order of execution of the makefile linux

(4) Find makefile rules to rebuild all files have been read 

(5) initializes the variable value and expand the functions and variables that require immediate deployment and execution branches is determined in accordance with a preset condition
    Variable function are more familiar with, and that preconditions mean? It is a conditional statement! For example: ifeq ... the else .... endif statements such conditions, according to the conditions determined execution branches.
(6) establish dependency list based on dependencies "ultimate goal" and other goals

(7)   Rules perform all the goals except the "ultimate goal" of (the rule if any of the timestamp dependency file a new file than the target file, use the command defined by the rules rebuilding target file)
(8) the rules of implementation of the "ultimate goal" is located. 

 

Note: the difference between make and execute a shell script. Implementation shell script is from top to bottom, left to right.

Guess you like

Origin blog.csdn.net/wujiafei_njgcxy/article/details/78024013