各种目录中的先决条件

Mat*_*eau 2 makefile rule gnu-make

我有一个变量,其中包含不同目录中的先决条件列表,每个目录由相对路径指定.例如:

HTML_FILES := ../foo1/bar1.html ../foo1/bar2.html ../foo2/bar3.html foo3/bar4.html
Run Code Online (Sandbox Code Playgroud)

(请注意,实际生成了此变量,因此事先不知道文件夹的完整列表.)

对于其中的每一个,我想在当前目录中生成目标文件,例如bar1.xml, bar2.xml, bar3.xml, bar4.xml.

如何编写符合此规则的规则?这就像我来的那样近.这似乎是魔术的地方?????? 可能会做的伎俩.

build: $(XML_FILES)
$(XML_FILES): %.xml : ??????/%.html
        perl $(HTML_TO_XML) $<
Run Code Online (Sandbox Code Playgroud)

Eld*_*mov 5

使用vpath.

vpath %.html $(dir $(HTML_FILES))
Run Code Online (Sandbox Code Playgroud)

现在可以使用简单的模式规则如下:

$(XML_FILES): %.xml : %.html
    perl $(HTML_TO_XML) $<
Run Code Online (Sandbox Code Playgroud)

这应该足以使事情有效,但我不确定如果在不同的目录中有一些同名的文件,例如../foo1/bar.html和,它会如何表现../foo2/bar.html.