Output to multiple files with Makefile

make

I have a makefile that I use to convert files in markdown into .pdf through a latex template. At the moment, this only works with one file at a time. However, I'd like the makefile to run on any markdown file in the active directory and output to a .pdf with the same name with a single make command. For example, I might have the following:

Foo.md —> Foo.pdf

Bar.md —> Bar.pdf

My current makefile is here:

TEX = pandoc
MEXT = md
src = template.tex $(wildcard *.$(MEXT))
FLAGS = --latex-engine=xelatex

letter.pdf : $(src)
$(TEX) $(filter-out $<,$^ ) -o $@ --template=$< $(FLAGS)

.PHONY: clean
clean :
rm output.pdf

Thank you for any pointers…

Best Answer

Try this:

TEX = pandoc
MEXT = md
SRC = $(wildcard *.$(MEXT))
PDFS = $(SRC:.md=.pdf)
TMP = template.tex
FLAGS = --latex-engine=xelatex

all:    ${PDFS}

%.pdf:  %.md ${TMP}
        ${TEX} $(filter-out $<,$^ ) -o $@ --template=${TMP} $(FLAGS) $<


.PHONY: clean
clean:
        rm *.pdf
Related Question