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?
$(notdir $<)or$(<F)instead. - Etan Reisner/project/something/nice/path1.bar. It makesnice/path//project/something/1.bar. That is, it splits%in a prefix (nice/path) and a stem (1.bar), then prepends/project/something/to the stem, and THEN prepends the prefix to that. I want it to stop splitting%in a prefix and stem. - Gx1sptDTDa1.foowith no path? Is itnice/path/1.foo? I don't understand where thenice/pathcame from. Make starts with the target and from that determines the stem and from that determines the prerequisites. So if your target is1.fooas you say, then how can the stem of the prerequisite benice/path/1? - MadScientist