Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

makefile patternrule with further wildcards in target file name

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?

like image 480
Bastian Ebeling Avatar asked Jan 17 '12 14:01

Bastian Ebeling


2 Answers

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.

like image 51
Bastian Ebeling Avatar answered Oct 13 '22 09:10

Bastian Ebeling


Just merge your targets into a single rule as follows:

%_test.pdf %_result.pdf : %.tex
    pdflatex -jobname=$(basename $@) $<

UPD.

As Bastian said in comments this solution does not work for pattern rules.

like image 38
Eldar Abusalimov Avatar answered Oct 13 '22 09:10

Eldar Abusalimov