TARGET=$(subst .tex,.pdf,$(wildcard *.tex)) all: $(TARGET) %.dep: %.tex perl -lnwe 'print "$*.pdf: $$1" if /\\input{([\w-]+\.tex)}/' <$< >$@ include $(TARGET:.pdf=.dep) %.pdf : %.tex pdflatex $< pdflatex $< clean: latexmk -C rm -f *.dep .PHONY: clean