# This should point to your current (revised) version.
PAPER=main
# This should point to your original submission. It's OK if these files import
# other tex files, latexdiff should inline them.
ORIG_PAPER=original_submission
# Name for the version of the paper with highlighting.
DIFF_PAPER=diff

default: paper-$(PAPER) paper-$(DIFF_PAPER)

paper-%: %.tex
	pdflatex $< </dev/null
	bibtex $*
	pdflatex $< </dev/null >/dev/null
	pdflatex $< </dev/null >/dev/null
	pdflatex $< </dev/null

# Always run latexdiff before building the highlighted version
$(DIFF_PAPER).tex: FORCE
	latexdiff -p latexdiff_preamble.tex --flatten --exclude-textcmd="section,subsection" $(ORIG_PAPER).tex $(PAPER).tex > $(DIFF_PAPER).tex
FORCE:


tidy-%:
	rm -f $*.aux $*.bbl $*.blg $*.brf $*.btx $*.log $*.out

clean-%: tidy-%
	rm -f $*.pdf

# Removes $(DIFF_PAPER).tex, which latexdiff generates
tidy: tidy-$(PAPER) tidy-$(DIFF_PAPER)
	rm -f $(DIFF_PAPER).tex

clean: clean-$(PAPER) clean-$(DIFF_PAPER)
	rm -f $(DIFF_PAPER).tex
