vpath
A vpath pattern is a string containing a % character. The string must match the file name of a dependency that is being searched for, the % character matching any sequence of zero or more characters (as in pattern rules; see Defining and redefining pattern rules). For example, %.h matches files that end in .h. (If there is no %, the pattern must match the dependency exactly, which is not useful very often.)
% characters in a vpath directives pattern can be quoted with preceding backslashes (\). Backslashes that would otherwise quote % characters can be quoted with more backslashes. Backslashes that quote % characters or other backslashes are removed from the pattern before it is compared to file names. Backslashes that are not in danger of quoting % characters go unmolested.
When a dependency fails to exist in the current directory, if the pattern in a vpath directive matches the name of the dependency file, then the directories in that directive are searched just like (and before) the directories in the VPATH variable.
For example, vpath %.h ../headers tells make to look for any dependency whose name ends in .h in the directory ../headers if the file is not found in the current directory.
If several vpath
patterns match the dependency files name, then make
processes each matching vpath
directive one by one, searching all the directories mentioned in each directive.
make
handles multiple vpath
directives in the order in which they appear in the makefile; multiple
directives with the same pattern are independent of each other. Thus, the
following directive will look for a file ending in .c
in foo,
then blish,
then bar.
The next example, on the
other hand, will look for a file ending in .c
in foo,
then bar,
then blish.