Matthew Simoneau
Matthew Simoneau

Reputation: 6279

Prerequisites in assorted directories

I have a variable with a list of prerequisites in varying directories, each specified by a relative path. For example:

HTML_FILES := ../foo1/bar1.html ../foo1/bar2.html ../foo2/bar3.html foo3/bar4.html

(Note that this variable is actually generated, so the full list of folders isn't known in advance.)

For each of these, I want to generate a target file in the current directory, e.g. bar1.xml, bar2.xml, bar3.xml, bar4.xml.

How can I write a rule which will match for this? This is as close as I've come. It seems like something magic in the place of ?????? might do the trick.

build: $(XML_FILES)
$(XML_FILES): %.xml : ??????/%.html
        perl $(HTML_TO_XML) $<

Upvotes: 2

Views: 110

Answers (1)

Eldar Abusalimov
Eldar Abusalimov

Reputation: 25543

Use vpath.

vpath %.html $(dir $(HTML_FILES))

Now one can use simple pattern rule as follows:

$(XML_FILES): %.xml : %.html
    perl $(HTML_TO_XML) $<

This should be enough to get things work, but I'm not sure how it would behave if there are some files with the same name in different directories, like ../foo1/bar.html and ../foo2/bar.html.

Upvotes: 5

Related Questions