Gnu make: use wildcard twice depending on rule

I would like to have a couple of form make rules

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 markup files to PDF when I modify them. I think by specifying a rule like

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

      

does not work. Is there a way to generate a rule that matches a custom pattern I have? Are such cases better handled by cmake?

+3


source to share


1 answer


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)))

      

+2


source







All Articles