manpagez: man pages & more
info make
Home | html | info | man

File: make.info,  Node: File Name Functions,  Next: Functions.php">Conditional Functions,  Prev: Functions.php">Text Functions,  Up: Functions

8.3 Functions for File Names
============================

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...)'
     Extracts the directory-part of each file name in NAMES.  The
     directory-part of the file name is everything up through (and
     including) the last slash in it.  If the file name contains no
     slash, the directory part is the string './'.  For example,

          $(dir src/foo.c hacks)

     produces the result 'src/ ./'.

'$(notdir NAMES...)'
     Extracts all but the directory-part of each file name in NAMES.  If
     the file name contains no slash, it is left unchanged.  Otherwise,
     everything through the last slash is removed from it.

     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...)'
     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.

'$(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.  *Note Using Wildcard Characters in
     File Names: Wildcards.

'$(realpath NAMES...)'
     For each file name in NAMES return the canonical absolute name.  A
     canonical name does not contain any '.' 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...)'
     For each file name in NAMES return an absolute name that does not
     contain any '.' 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.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.