I need to create a special makefile rule, which is best explained by an example. Maybe we create files with the rules
%_test.pdf: %.tex
pdflatex -jobname=%_test %.tex
%_result.pdf: %.tex
pdflatex -jobname=%_result %.tex
and it is working fine. Just thinking there occur more templates like those above, one might think of one wildcard-rule like
%_WILDCARD.pdf: %.tex
pdflatex -jobname=%_$(WILDCARD) %.tex
where WILDCARD is determined by make. Is it possible to build such a rule?
Inspired by the answers of @eldar and @andres I think, I got the solution on myself
.SECONDEXPANSION:
%.pdf: $$(firstword $$(subst _, ,%))
pdflatex -jobname=$* $+
This does exactly, what I needed. Detailed information for this way may be found at GNU make manual.
Just merge your targets into a single rule as follows:
%_test.pdf %_result.pdf : %.tex
pdflatex -jobname=$(basename $@) $<
As Bastian said in comments this solution does not work for pattern rules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With