c60 How Patterns Match Contents|Index|Previous|Next

How Patterns Match

A target pattern is composed of a ‘%’ between a prefix and a suffix, either or both of which may be empty. The pattern matches a file name only if the file name starts with the prefix and ends with the suffix, without overlap. The text between the prefix and the suffix is called the stem. Thus, when the pattern ‘%.o’ matches the file name ‘test.o’, the stem is ‘test’. The pattern rule dependencies are turned into actual file names by substituting the stem for the character ‘%’. Thus, if in the same example one of the dependencies is written as ‘%.c’, it expands to ‘test.c’.

When the target pattern does not contain a slash (and it usually does not), directory names in the file names are removed from the file name before it is compared with the target prefix and suffix. After the comparison of the file name to the target pattern, the directory names, along with the slash that ends them, are added on to the dependency

file names generated from the pattern rule’s dependency patterns and the file name. The directories are ignored only for the purpose of finding an implicit rule to use, not in the application of that rule. Thus, ‘e%t’ matches the file name ‘src/eat’, with ‘src/a’ as the stem. When dependencies are turned into file names, the directories from the stem are added at the front, while the rest of the stem is substituted for the ‘%’. The stem ‘src/a’ with a dependency pattern ‘c%r’ gives the file name ‘src/car’.

0