Consider the following:
%.foo: %.bar
echo $< > $@
Assuming we have one file 1.bar
, the command executed is simply echo 1.bar > 1.foo
. However, when %
contains a path, rather than just a file name, it start becoming finicky. My problem is that I want to prepend another path to %.bar
, the pattern becomes completely mangled. I.e., when %.bar
is nice/path/1.bar
, this becomes impossible:
%.foo: /project/something/%.bar
echo $< > $@
This will run, but it executes echo nice/path//project/something/1.bar > 1.foo
in stead of echo /project/something/nice/path1.bar > 1.foo
The reason for this is in how make does its pattern rules. From the docs:
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. [...] 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 prerequisites 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 prerequisite pattern ‘c%r’ gives the file name src/car
Is there any way I can turn this off for a specific rule?
You may like to read up on How Patterns Match:
The above explains why
nice/path/
is prepended to prerequisite/project/something/1.bar
.One fix would be to use full file names in rules, e.g.: