# The file name is based on recommendations for submission at OU.
MAIN = Sean_McDonough_Thesis
# Also: ps2pdf -dEPSCrop file.eps
#       (or even ps2pdf14 -dPDFSETTINGS=/prepress -dEPSCrop ?)

all: paper

clean:
	rm -f *.aux *.bbl *.blg *.dvi *.lof *.log *.lot *.ps *.pdf *.ps.gz *~
#

# Usable separately from paper, if you don't want the added delay of prepress.
paper_temp:
	pdflatex $(MAIN)
	bibtex $(MAIN)
	pdflatex $(MAIN)
	pdflatex $(MAIN)
	mv $(MAIN).pdf $(MAIN)_temp.pdf
	rm $(MAIN).aux $(MAIN).bbl $(MAIN).blg $(MAIN).loa $(MAIN).lof $(MAIN).log \
		$(MAIN).lot $(MAIN).toc
#

# The proper final, production way to make the paper.
# TODO Rename this to paper.
# Use PDF version 1.4 (minimally, for Adobe Reader 5.0 compliance), embed fonts,
# etc.
paper_prod: paper_temp
	ps2pdf14 -dPDFSETTINGS=/prepress $(MAIN)_temp.pdf $(MAIN).pdf
	rm $(MAIN)_temp.pdf
#

# Hack time saver.
# TODO Rename this to paper_dev or something.
paper: paper_temp
	mv $(MAIN)_temp.pdf $(MAIN).pdf
#

# From: http://stackoverflow.com/questions/2483182
PDF_FIGURES = $(shell find -mindepth 2 -name '*.pdf' | sort)
PNG_FIGURES = $(patsubst %.pdf, raster_figures/%.png, $(PDF_FIGURES))
rasters: $(PNG_FIGURES)
raster_figures/%.png: %.pdf
	@mkdir -p "$(@D)"
	convert -density 600 +antialias "$<" "$@"
#
