1239 |
|
|
1240 |
@example |
@example |
1241 |
@group |
@group |
1242 |
name1 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) |
name1 := $(lastword $(MAKEFILE_LIST)) |
1243 |
|
|
1244 |
include inc.mk |
include inc.mk |
1245 |
|
|
1246 |
name2 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) |
name2 := $(lastword $(MAKEFILE_LIST)) |
1247 |
|
|
1248 |
all: |
all: |
1249 |
@@echo name1 = $(name1) |
@@echo name1 = $(name1) |
5963 |
produces the result @samp{foo}. Although @code{$(firstword |
produces the result @samp{foo}. Although @code{$(firstword |
5964 |
@var{text})} is the same as @code{$(word 1,@var{text})}, the |
@var{text})} is the same as @code{$(word 1,@var{text})}, the |
5965 |
@code{firstword} function is retained for its simplicity.@refill |
@code{firstword} function is retained for its simplicity.@refill |
5966 |
|
|
5967 |
|
|
5968 |
|
@item $(lastword @var{names}@dots{}) |
5969 |
|
@findex lastword |
5970 |
|
@cindex words, extracting last |
5971 |
|
The argument @var{names} is regarded as a series of names, separated |
5972 |
|
by whitespace. The value is the last name in the series. |
5973 |
|
|
5974 |
|
For example, |
5975 |
|
|
5976 |
|
@example |
5977 |
|
$(lastword foo bar) |
5978 |
|
@end example |
5979 |
|
|
5980 |
|
@noindent |
5981 |
|
produces the result @samp{bar}. Although @code{$(lastword |
5982 |
|
@var{text})} is the same as @code{$(word $(words @var{text}),@var{text})}, |
5983 |
|
the @code{lastword} function was added for its simplicity and better |
5984 |
|
performance.@refill |
5985 |
@end table |
@end table |
5986 |
|
|
5987 |
|
|
5988 |
Here is a realistic example of the use of @code{subst} and |
Here is a realistic example of the use of @code{subst} and |
5989 |
@code{patsubst}. Suppose that a makefile uses the @code{VPATH} variable |
@code{patsubst}. Suppose that a makefile uses the @code{VPATH} variable |
5990 |
to specify a list of directories that @code{make} should search for |
to specify a list of directories that @code{make} should search for |
9656 |
directive. |
directive. |
9657 |
@end table |
@end table |
9658 |
|
|
9659 |
Here is a summary of the text manipulation functions (@pxref{Functions}): |
Here is a summary of the built-in functions (@pxref{Functions}): |
9660 |
|
|
9661 |
@table @code |
@table @code |
9662 |
@item $(subst @var{from},@var{to},@var{text}) |
@item $(subst @var{from},@var{to},@var{text}) |
9687 |
Sort the words in @var{list} lexicographically, removing duplicates.@* |
Sort the words in @var{list} lexicographically, removing duplicates.@* |
9688 |
@xref{Text Functions, , Functions for String Substitution and Analysis}. |
@xref{Text Functions, , Functions for String Substitution and Analysis}. |
9689 |
|
|
9690 |
|
@item $(word @var{n},@var{text}) |
9691 |
|
Extract the @var{n}th word (one-origin) of @var{text}.@* |
9692 |
|
@xref{Text Functions, , Functions for String Substitution and Analysis}. |
9693 |
|
|
9694 |
|
@item $(words @var{text}) |
9695 |
|
Count the number of words in @var{text}.@* |
9696 |
|
@xref{Text Functions, , Functions for String Substitution and Analysis}. |
9697 |
|
|
9698 |
|
@item $(wordlist @var{s},@var{e},@var{text}) |
9699 |
|
Returns the list of words in @var{text} from @var{s} to @var{e}.@* |
9700 |
|
@xref{Text Functions, , Functions for String Substitution and Analysis}. |
9701 |
|
|
9702 |
|
@item $(firstword @var{names}@dots{}) |
9703 |
|
Extract the first word of @var{names}.@* |
9704 |
|
@xref{Text Functions, , Functions for String Substitution and Analysis}. |
9705 |
|
|
9706 |
|
@item $(lastword @var{names}@dots{}) |
9707 |
|
Extract the last word of @var{names}.@* |
9708 |
|
@xref{Text Functions, , Functions for String Substitution and Analysis}. |
9709 |
|
|
9710 |
@item $(dir @var{names}@dots{}) |
@item $(dir @var{names}@dots{}) |
9711 |
Extract the directory part of each file name.@* |
Extract the directory part of each file name.@* |
9712 |
@xref{File Name Functions, ,Functions for File Names}. |
@xref{File Name Functions, ,Functions for File Names}. |
9735 |
Join two parallel lists of words.@* |
Join two parallel lists of words.@* |
9736 |
@xref{File Name Functions, ,Functions for File Names}. |
@xref{File Name Functions, ,Functions for File Names}. |
9737 |
|
|
|
@item $(word @var{n},@var{text}) |
|
|
Extract the @var{n}th word (one-origin) of @var{text}.@* |
|
|
@xref{File Name Functions, ,Functions for File Names}. |
|
|
|
|
|
@item $(words @var{text}) |
|
|
Count the number of words in @var{text}.@* |
|
|
@xref{File Name Functions, ,Functions for File Names}. |
|
|
|
|
|
@item $(wordlist @var{s},@var{e},@var{text}) |
|
|
Returns the list of words in @var{text} from @var{s} to @var{e}.@* |
|
|
@xref{File Name Functions, ,Functions for File Names}. |
|
|
|
|
|
@item $(firstword @var{names}@dots{}) |
|
|
Extract the first word of @var{names}.@* |
|
|
@xref{File Name Functions, ,Functions for File Names}. |
|
|
|
|
9738 |
@item $(wildcard @var{pattern}@dots{}) |
@item $(wildcard @var{pattern}@dots{}) |
9739 |
Find file names matching a shell file name pattern (@emph{not} a |
Find file names matching a shell file name pattern (@emph{not} a |
9740 |
@samp{%} pattern).@* |
@samp{%} pattern).@* |