graphics_eps := $(patsubst %.jpg,%.eps,$(wildcard figs/*.jpg))
graphics_pdf := $(patsubst %.eps,%.pdf,$(filter-out Football_EnergyWork.pdf, $(filter-out $(graphics_eps), $(wildcard figs/*.eps)))) $(patsubst %.eps.gz,%.pdf,$(wildcard figs/*.eps.gz))
lectures_pdf := $(patsubst thumbdta.tex,"",$(wildcard *.tex))

$(lectures_pdf):

%.pdf: %.tex $(graphics_pdf) $(graphics_eps)
	pdflatex $< && thumbpdf $@ && pdflatex $<
	acroread $@

$(graphics_pdf):

$(graphics_eps):

%.pdf: %.eps
	epstopdf --outfile=$@ $< 

%.pdf: %.eps.gz
	gunzip $<
	epstopdf --outfile=$@ $(subst .gz,,$<)
	gzip --best $(subst .gz,,$<)

%.eps: %.jpg
	mogrify -format eps $< 


.PHONY: clean
clean: nearlyclean
	rm -f *.pdf *.ps

nearlyclean:
	rm -r -f *.aux *.dvi *.log *.out *.toc *.tof *.bbl *.blg *.brf *.fot thumb*.* *~ $(filter-out Football_EnergyWork.pdf, $(graphics_pdf))
