Several of the built-in expansion functions relate specifically to taking apart file names or lists of file names.
Each of the following functions performs a specific transformation on a file name. The argument of the function is regarded as a series of file names, separated by whitespace. (Leading and trailing whitespace is ignored.) Each file name in the series is transformed in the same way and the results are concatenated with single spaces between them.
$(dir
names...)
$(dir src/foo.c hacks)
produces the result ‘src/ ./’.
$(notdir
names...)
A file name that ends with a slash becomes an empty string. This is unfortunate, because it means that the result does not always have the same number of whitespace-separated file names as the argument had; but we do not see any other valid alternative.
For example,
$(notdir src/foo.c hacks)
produces the result ‘foo.c hacks’.
$(suffix
names...)
For example,
$(suffix src/foo.c src-1.0/bar.c hacks)
produces the result ‘.c .c’.
$(basename
names...)
$(basename src/foo.c src-1.0/bar hacks)
produces the result ‘src/foo src-1.0/bar hacks’.
$(addsuffix
suffix,
names...)
$(addsuffix .c,foo bar)
produces the result ‘foo.c bar.c’.
$(addprefix
prefix,
names...)
$(addprefix src/,foo bar)
produces the result ‘src/foo src/bar’.
$(join
list1,
list2)
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.
$(wildcard
pattern)
wildcard
is a space-separated list of the names of existing files
that match the pattern.
See Using Wildcard Characters in File Names.
$(realpath
names...)
.
or ..
components,
nor any repeated path separators (/
) or symlinks. In case of a
failure the empty string is returned. Consult the realpath(3)
documentation for a list of possible failure causes.
$(abspath
names...)
.
or ..
components, nor any repeated path
separators (/
). Note that, in contrast to realpath
function, abspath
does not resolve symlinks and does not require
the file names to refer to an existing file or directory. Use the
wildcard
function to test for existence.