Http://blog.chinaunix.net/uid-20564848-id-217918.html
Makefile under $ (wildcard $^), $^,[email protected],$?,$<,$ (@D), $ (@F) stands for different meanings
$ (Filter-out $ (phony) $ (wildcard $^), $^)
Common usage is $ (wildcard *.c)
Indicates that all. c files in the current directory are enumerated
This $^ because it contains a dependent file name, and if it contains the file, it will return the filename with the path.
So $ (wildcard $^) is used to filter all the files contained in the $^ and the file does exist locally.
Automation variable $? Represents all files that have been changed in the dependent file list.
The automation variable $^ represents the full path name (directory + generic file name) List of all dependent files that are obtained by directory search.
The automation variable [email protected] represents the goal of the rule.
The automation variable $< represents the first dependent file of a list of dependent files in a rule that is obtained through a directory search.
Automation variable $ (@D)
The directory part of the file name of the target,
With the trailing slash removed. If the value of ' [email protected] ' is DIR/FOO.O
Then ' $ (@D) ' is dir. This value is. If ' [email protected] ' does not contain a slash.
Http://www.gnu.org/software/make/manual/make.html
Automation variable $ (@F)
The file-within-directory part of the file name of
The target. If the value of ' [email protected] ' is DIR/FOO.O then ' $ (@F) ' is foo.o.
' $ (@F) ' is equivalent to ' $ (notdir [email protected]) '.
4.12 Static Mode
A static mode rule is one such rule:
There are multiple targets for a rule,
and different goals can be based on the target
The name of the file to automatically construct the dependent file.
Static mode rules are more common than multi-objective rules,
It does not require multiple
The target has the same dependency.
However, dependent files in a static mode rule must be similar rather than identical
Of
4.12.1
Syntax for static mode rules
First, let's take a look at the basic syntax of a static mode rule:
TARGETS ...: target-pattern:prereq-patterns ...
COMMANDS
...
"Tagets"
Lists the series of target files for this rule.
As the goal of regular rules can contain
A wildcard. For the use of wildcards refer to the 4.4 file name using the wildcard character section
"Taget-pattern" and "Prereq-patterns" illustrate how each target file
Generate dependent files. Extracts a portion of a string from the target name of the target pattern (Taget-pattern) (called
To "stems". Use the corresponding part of the "stem" instead of the dependency mode (prereq-patterns) to produce a
)
The dependent file on which the target should be. Below is a detailed introduction to this alternative process.
First, in the target mode and dependency mode, it is generally necessary to include the pattern character "%"
。 In target mode
(taget-pattern) "%" can match any part of the target file, the pattern character "%" matches the
Part is "stem"
。 The remainder of the target file and the target pattern must match exactly. See an example: Target
"FOO.O" conforms to Mode "%.O"
, its "stem" is "foo"
。 and the target "foo.c" and "foo.out" are inconsistent.
This target pattern.
The dependent file for each target is the "stem" that uses this target instead of the dependency pattern
(prereq-patterns) The mode character "%" is obtained. Example: Dependency pattern in the example above
(prereq-patterns) for "%.c"
, then use the "stem"
"Foo" instead of "%" in dependency mode
The resulting dependency file is "foo.c".
。 It is important to be clear that the use of non-packet in the dependency list of a pattern rule
The "%" with the mode character is also legal. Represents this file as a dependent file for all targets.
The character '% ' in the pattern rule can be referenced with the preceding backslash "\" method. Backslash referring to "%"
You can also refer to them by more backslashes. The backslash in the reference "%" "\" is compared with the file name or by the "stem" generation
、
It will be removed from the schema before it is replaced. Backslashes do not get confused by referring to "%". For example, the mode
"The\%weird\\%pattern\\" is composed of "the%weird\" + "%" + "pattern\\". The last two
The backslash is unchanged because it does not have any escaped reference "%".
Let's look at an example that compiles "foo.o" and "bar.o" files according to the corresponding. C File:
objects = FOO.O BAR.O
All: $ (objects)
$ (objects):%.o:%.c
$ (CC)-C $ (CFLAGS) $<-o [email protected]
Example, the rules describe all of the. o File dependent files for the corresponding. c files, for the target "FOO.O"
Take
Its stem "foo" replaces the corresponding dependency pattern "%.c" in the pattern character "%" after which the target dependent text can be obtained
Piece "FOO.C"
。 This is the "foo.o" dependency of the target "FOO.O:FOO.C"
, the command line for the rule describes the
How to complete the build target "FOO.O" compiled by "FOO.C"
。 The command line "$<" and "[email protected]" are automation variables,
"$<"
Represents the first dependent file in a rule,
"[Email protected]"
Represents a target file in a rule
(Refer to 10.5.3 from
A section of the dynamic variable)
。 The above rule describes the following two specific rules:
Foo.o:foo.c
$ (CC)-C $ (CFLAGS) Foo.c-o foo.o
Bar.o:bar.c
$ (CC)-C $ (CFLAGS) Bar.c-o BAR.O
When using a static mode rule, the specified target must match the target pattern, otherwise
Will get an error prompt.
If there is a list of files,
One part fits one pattern and the other
In this case we can use the "filter" function (refer to chapter eighth make
nested functions) to classify this file list, after categorization, for a certain class of usage pattern rules.
For example:
Files = FOO.ELC bar.o lose.o
$ (Filter%.o,$ (Files)):%.O:%.c
$ (CC)-C $ (CFLAGS) $<-o [email protected]
$ (Filter%.elc,$ (Files)):%.ELC:%.el
Emacs-f Batch-byte-compile $<
The result of%.o,$ $ (files) is "bar.o lose.o" "Filter" function filtering does not conform to "%.O"
。
The file name of the schema and returns a list of all files that conform to this pattern.
The first static mode rule describes these goals
The files are rebuilt by compiling the corresponding. C source files. The second rule is also used in this way.
Let's look at another example of how the automatic loop variable "$*" is used in static mode rules:
Bigoutput Littleoutput:%OUTPUT:TEXT.G
Generate TEXT.G-$* > [email protected]
When you execute the command for this rule,
Automatic loop variable
"$*"
be expanded to
"Stem" here is the
。
"Big" "little"
And
。
Static mode rules are useful for managing a larger project.
It can be used for the entire project of the same type of file
The rebuild rule is defined once, and the implementation specifies the same rebuild rules for such files throughout the project. For example, you can
To describe the dependency rules and compilation commands for all the. o files throughout the project. The usual practice is to generate the same
The pattern of a class of targets is defined in a make.rules file. Included in the Makefile of each module of the project
This file.
- Static mode Makefile $ (COBJS): $ (obj)/%.O: $ (SRC)/%.c
- Http://www.gnu.org/software/make/manual/make.html
- 4.12.1 Syntax of Static Pattern Rules
- Here is the syntax of a static pattern rule:
- Targets ...: Target-pattern:prereq-patterns ...
- Recipe
- ...
- The targets list specifies the targets, the rule applies to. The targets can contain wildcard characters, just like the targets of ordinary rules (see Using wildcard characters in Fil e Names).
- The Target-pattern and prereq-patterns say how to compute the prerequisites of each target. Each target was matched against the Target-pattern to extract a part of the target name, called the stem. This stem was substituted into each of the prereq-patterns to make the prerequisite names (one from each prereq-pattern).
- Each pattern normally contains the character '% ' just once. When the Target-pattern matches a target, the '% ' can match any part of the target name; This is called the stem. The rest of the pattern must match exactly. For example, the target FOO.O matches the pattern '%.o ', with ' foo ' as the stem. The targets foo.c and foo.out do not match this pattern.
- The prerequisite names for each target is made by substituting, the stem for the ' percent ' in eachprerequisite pattern. For example, if one prerequisite pattern was%.c, then substitution of the stem ' foo ' gives the prerequisite name FOO.C. It is legitimate to write a prerequisite pattern that doesnot contain '% '; Then this prerequisite are the same for all targets.
- '% ' characters in pattern rules can is quoted with preceding backslashes (' \ '). Backslashes that would otherwise quote '% ' characters can is quoted with more backslashes. Backslashes that quote '% ' characters or other backslashes be removed from the pattern before it's compared tofile names Or have a stem substituted into it. Backslashes that is not in danger of quoting '% ' characters go unmolested. For example, the pattern the\%weird\\%pattern\\ have ' the%weird\ ' preceding the operative '% ' character, and ' pattern\\ ' fo Llowing it. The final of the backslashes areleft alone because they cannot affect any '% ' character.
- Here is a example, which compiles each of foo.o and BAR.O from the corresponding. c File:
- objects = FOO.O BAR.O
- All: $ (objects)
- $ (objects):%.o:%.c
- $ (CC)-C $ (CFLAGS) $<-o [email protected]
- Here ' $< ' are the automatic variable that holds the name of the prerequisite and ' [e-mail protected] ' is the automatic VA Riable that holds the name of the target; See Automatic Variables.
- Each target specified must match the target pattern; A warning is issued for each of the target that does not. If you had a list of files, only some of which would match the pattern, you can use the FilterFunction to remove Nonmatchi ng file names (see Functions for String Substitution and analysis):
- Files = FOO.ELC bar.o lose.o
- $ (Filter%.o,$ (Files)):%.O:%.c
- $ (CC)-C $ (CFLAGS) $<-o [email protected]
- $ (Filter%.elc,$ (Files)):%.ELC:%.el
- Emacs-f Batch-byte-compile $<
- In this example the result of ' $ ' (filter%.o,$ (Files)) ' was BAR.O LOSE.O, and the first static pattern rule causes each of T Hese object files to is updated by compiling the corresponding C source file. The result of ' $ (filter%.elc,$ (Files)) ' is FOO.ELC, so, file is made from Foo.el.
- Another example shows how to use the $* in static pattern rules:
- Bigoutput Littleoutput:%OUTPUT:TEXT.G
- Generate TEXT.G-$* > [email protected]
- When the Generate command is run, $* 'll expand to the stem, either ' big ' or ' little '.
Makefile Special Symbol Introduction