Makefile automatic Variables

Source: Internet
Author: User

From: http://blog.163.com/seven_7_one/blog/static/162606412201010211829474/

$ @
Indicates the target file set in the rule. In a pattern rule, if there are multiple targets, "$ @" is the set that matches the schema definition in the target.

$ %
Only when the target is in the function library file, it indicates the target member name in the rule. For example, if a target is "foo. A (Bar. o) ", then," $ % "is" bar. O "," $ @ "is" foo. A ". If the target file is not a function library file ([. A] in UNIX and [. Lib] in Windows), the value is null.

$ <
The first target name in the dependency target. If the dependency target is defined in the mode ("%"), "$ <" is a series of file sets that conform to the mode. Note that it is obtained one by one.

$?
A set of new dependent targets. Separated by spaces.

$ ^
A set of all dependent targets. Separated by spaces. If there are multiple duplicate dependency targets, the variable will remove the duplicate dependency targets and retain only one copy.

$ +
This variable is similar to "$ ^" and is also a set of all dependent targets. It does not remove repeated dependency targets.

$ *
This variable indicates "%" and its previous parts in the target mode. If the target is "DIR/. foo. B ", and the target mode is". %. B ", then, the value of" $ * "is" DIR/. foo ". This variable is relatively useful for constructing associated file names. If there is no schema definition in the target, "$ *" cannot be pushed or exported. However, if the suffix of the target file is what make recognizes, then "$ *" is the part except the suffix. For example, if the target is "foo. c", because ". c" is the suffix that can be identified by make, the value of "$ *" is "foo ". This feature is GNU
Make may not be compatible with other versions of make. Therefore, you should avoid using "$ *" unless it is in implicit rules or static mode. If the Suffix in the target is not recognized by make, "$ *" indicates a null value.

When you want to operate only the updated dependent files, "$? "It is useful in explicit rules. For example, assume that there is a function library file named" lib ", which is updated by several other object files. The more efficient makefile rule for packaging object files is:

Lib: Foo. O Bar. O lose. o win. o
Ar R Lib $?

In the automatic variable listed above. Four variables ($ @, $ <, $ %, and $ *) only have one file during expansion, and the other three values are a file list. These seven automation variables can also get the directory name of the file or the pattern-compliant file name under the current directory. You only need to match the words "D" or "F. This is GNU
The features of earlier versions of make can be achieved by using the "dir" or "notdir" functions in the new version. "D" means directory, that is, directory, and "F" means file, that is, file.

The following are the meanings of adding "D" or "F" to the above seven variables:

$ (@ D)
Indicates the directory section of "$ @" (not ending with a slash). If the "$ @" value is "DIR/Foo. O ", then" $ (@ D) "is" dir ", and if" $ @ "does not contain a slash, its value is ". "(current directory ).

$ (@ F)
Indicates the file part of "$ @". If the value of "$ @" is "DIR/Foo. O ", then" $ (@ f) "is" foo. O "," $ (@ f) "is equivalent to the function" $ (notdir $ @)".

"$ (* D )"
"$ (* F )"
As mentioned above, it is also the directory part and file part of the file. For the above example, "$ (* D)" returns "dir", while "$ (* f)" returns "foo"

"$ (% D )"
"$ (% F )"
Indicates the Directory and file of the function package file members. This is useful when "member" in the form of "archive (member)" contains different directories.

"$ (" $ (Indicating the directory part and file part of the dependent file respectively.

"$ (^ D )"
"$ (^ F )"
Indicates the Directory and file of all dependent files. (None)

"$ (+ D )"
"$ (+ F )"
Indicates the Directory and file of all dependent files. (Can have the same)

"$ (? D )"
"$ (? F )"
Indicates the Directory and file of the updated dependent files.

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.