EMACS=emacs
BATCH_EMACS=$(EMACS) --batch -Q -l init.el proposal.org

all: proposal.pdf

proposal.html: proposal.org
	$(BATCH_EMACS) -f org-export-as-html

proposal.tex: proposal.org proposal.bib init.el
	$(BATCH_EMACS) -f org-export-as-latex

proposal.bib: tasks.org bib-export.el
	$(BATCH_EMACS) -l bib-export.el

proposal.pdf: proposal.tex gantt.pdf
	rm -f proposal.aux
	if pdflatex proposal.tex </dev/null; then \
		true; \
	else \
		stat=$$?; touch proposal.pdf; exit $$stat; \
	fi
	bibtex proposal
	while grep "Rerun to get" proposal.log; do \
		if pdflatex proposal.tex </dev/null; then \
			true; \
		else \
			stat=$$?; touch proposal.pdf; exit $$stat; \
		fi; \
	done

gantt.pdf: gantt.tex
	./single-fig gantt.tex

clean:
	rm -f *.aux *.log *.dvi *.blg *.bbl *.toc proposal.tex *~ *.out *.html proposal.pdf proposal.bib gantt.pdf
