gnu make: use wildcard twice in rule dependency

379 Views Asked by At

I would like to have a couple of make rules of the form

build/file_a.pdf: text/file_a/file_a.md
    pandoc -o build/file_a.pdf text/file_a/file_a.md

build/file_b.pdf: text/file_b/file_b.md
    pandoc -o build/file_b.pdf text/file_a/file_b.md

...

to convert a couple of markdown files to PDF whenever I change them. I think specifying a rule like

build/%.pdf: text/%/%.md
    ....

is not working. Is there a way of generating a rule matching the special pattern I have? Are such cases better handled by cmake?

1

There are 1 best solutions below

3
On

You can generate your rules dynamically with define, eval, and call.

define build_rule
    build/$1.pdf: text/$1/$1.md
        ....
endef

$(foreach f,file_a file_b,$(eval $(call build_rule,$f)))