makefile - Variable for '%' in multiple files matching -


i make complete text document several sources (since 1 of file source change, want doc change).

i have pass through translator develop. pass language argument, make cleaner.

yesterday, late @ night, dreamed of makefile this...

#makefile # ... my_complete_doc.%.html: my_trans_exe header.%.html $(wildcard source/*.%.html)         $< --language $(variable_for_%) > $@ 

(?) replace % languages have own header.language.html files. , file my_completed_doc.language.html changed 1 of source/*.language.html changed?

(?) how % replaced in several prerequisites, possibly wildcard , in recipe?

first, easy problem: wish use '%' variable in recipe. answer use '$*' automatic variable:

my_complete_doc.%.html: my_trans_exe ...     $< --language $* > $@ 

then easy question: yes, header.%.html prerequisite correct. when try build my_complete_doc.dutch.html make evaluate header.dutch.html, when try build my_complete_doc.french.html, make evaluate header.french.html.

now tricky problem: prerequisite $(wildcard source/*.%.html). ordinarily, make expands $(wildcard ...) statements before executing rule, or deciding targets build. searches files such source/foo.%.html or source/bar.%.html (that is, files names contain character '%'), finds none, , evaluates statement empty string. make defer evaluation until has chosen rule, if use secondexpansion:

.secondexpansion: my_complete_doc.%.html: my_trans_exe header.%.html $$(wildcard source/*.%.html)     $< --language $* > $@ 

(note '$$'. in first -- ordinary -- expansion, make reduces "$$(...)" "$(...)", , in second -- when '%' has value -- expands "$(...)".) if modify file such source/foo.german.html, make consider file my_complete_doc.german.html out of date , in need of rebuilding.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -