make Automatic variables |
$@ |
The file name of the target of the rule. If the target is an archive member, then $@ is the name of the archive file. In a pattern rule that has multiple targets, $@ is the name of whichever target caused the rule's commands to be run. |
$< |
The name of the first dependency. If the target got its commands from an implicit rule, this will be the first dependency added by the implicit rule. |
$? |
The names of all the dependencies that are newer than the target, with spaces between them. |
$^ |
The names of all the dependencies, with spaces between them. A target has only one dependency on each other file it depends on, no matter how many times each file is listed as a dependency. So if you list a dependency more than once for a target, the value of $^ contains just one copy of the name. |
$+ |
This is like $^, but dependencies listed more than once are duplicated in the order they were listed in the makefile. This is primarily useful for use in linking commands where it is meaningful to repeat library file names in a particular order. |
$* |
The stem with which an implicit rule matches. If the target is dir/a.foo.b and the target pattern is a.%.b then the stem is dir/foo. The stem is useful for constructing names of related files.
In a static pattern rule, the stem is part of the file name that matched the % in the target pattern.
$? is useful even in explicit rules when you wish to operate on only the dependencies that have changed. For example, suppose that an archive named lib is supposed to contain copies of several object files. This rule copies just the changed object files into the archive:
lib: foo.o bar.o lose.o win.o
ar r lib $?
|
Of the variables listed above, four have values that are single file names, and two have values that are lists of file names. These six have variants that get just the file's directory name or just the file name within the directory. The variant variables' names are formed by appending D or F, respectively. These variants are semi-obsolete in GNU make since the functions dir and notdir can be used to get a similar effect. Note, however, that the F variants all omit the trailing slash which always appears in the output of the dir function. Here is a table of the variants:
make Derived Automatic variables |
$(@D) |
The directory part of the file name of the target, with the trailing slash removed. If the value of $@ is dir/foo.o then $(@D) is dir. This value is . if $@ does not contain a slash. |
$(@F) |
The file-within-directory part of the file name of the target. If the value of $@ is dir/foo.o then $(@F) is foo.o. $(@F) is equivalent to $(notdir $@). |
$(*D)
$(*F) |
The directory part and the file-within-directory part of the stem; dir and foo in this example. |
$(%D)
$(%F) |
The directory part and the file-within-directory part of the target archive member name. This makes sense only for archive member targets of the form ARCHIVE(MEMBER) and is useful only when MEMBER may contain a directory name. |
$(<D)
$(<F) |
The directory part and the file-within-directory part of the first dependency. |
$(^D)
$(^F) |
Lists of the directory parts and the file-within-directory parts of all dependencies. |
$(?D)
$(?F) |
Lists of the directory parts and the file-within-directory parts of all dependencies that are newer than the target. |
make filename functions |
$(suffix NAMES...) |
Extracts the suffix of each file name in NAMES. If the file name contains a period, the suffix is everything starting with the last period. Otherwise, the suffix is the empty string. This frequently means that the result will be empty when NAMES is not, and if NAMES contains multiple file names, the result may contain fewer file names. For example,
$(suffix src/foo.c src-1.0/bar.c hacks)
produces the result .c .c.
|
$(basename NAMES...) |
Extracts all but the suffix of each file name in NAMES. If the file name contains a period, the basename is everything starting up to (and not including) the last period. Periods in the directory part are ignored. If there is no period, the basename is the entire file name. For example,
$(basename src/foo.c src-1.0/bar hacks)
produces the result src/foo src-1.0/bar hacks.
|
$(addsuffix SUFFIX,NAMES...) |
The argument NAMES is regarded as a series of names, separated by whitespace; SUFFIX is used as a unit. The value of SUFFIX is appended to the end of each individual name and the resulting larger names are concatenated with single spaces between them. For example,
$(addsuffix .c,foo bar)
produces the result foo.c bar.c.
|
$(addprefix PREFIX,NAMES...) |
The argument NAMES is regarded as a series of names, separated by whitespace; PREFIX is used as a unit. The value of PREFIX is prepended to the front of each individual name and the resulting larger names are concatenated with single spaces between them. For example,
$(addprefix src/,foo bar)
produces the result src/foo src/bar.
|
$(join LIST1,LIST2) |
Concatenates the two arguments word by word: the two first words (one from each argument) concatenated form the first word of the result, the two second words form the second word of the result, and so on. So the Nth word of the result comes from the Nth word of each argument. If one argument has more words that the other, the extra words are copied unchanged into the result. For example,
$(join a b,.c .o)
produces
a.c b.o
Whitespace between the words in the lists is not preserved; it is replaced with a single space.
This function can merge the results of the dir and notdir functions, to produce the original list of files which was given to those two functions.
|
$(word N,TEXT) |
Returns the Nth word of TEXT. The legitimate values of N start from 1. If N is bigger than the number of words in TEXT, the value is empty. For example,
$(word 2, foo bar baz)
returns bar.
|
$(wordlist S,E,TEXT) |
Returns the list of words in TEXT starting with word S and ending with word E (inclusive). The legitimate values of S and E start from 1. If S is bigger than the number of words in TEXT, the value is empty. If E is bigger than the number of words in TEXT, words up to the end of TEXT are returned. If S is greater than E, make swaps them for you. For example,
$(wordlist 2, 3, foo bar baz)
returns bar baz.
|
$(words TEXT) |
Returns the number of words in TEXT. Thus, the last word of TEXT is $(word $(words TEXT),TEXT). |
$(firstword NAMES...) |
The argument NAMES is regarded as a series of names, separated by whitespace. The value is the first name in the series. The rest of the names are ignored. For example,
$(firstword foo bar)
produces the result foo. Although $(firstword TEXT) is the same as $(word 1,TEXT), the firstword function is retained for its simplicity.
|
$(wildcard PATTERN) |
The argument PATTERN is a file name pattern, typically containing wildcard characters (as in shell file name patterns). The result of wildcard is a space-separated list of the names of existing files that match the pattern. |