BUILD = build
BIBDIR = ../../../bibliography
EVALDIR = evaluation
FIGDIR = figures
TEXLIB = .:${BUILD}:${BIBDIR}:

# LATEX = TEXINPUTS=${TEXLIB} && export TEXINPUTS && pdflatex -interaction=nonstopmode -halt-on-error -output-directory=${BUILD}
LATEX = TEXINPUTS=${TEXLIB} && export TEXINPUTS && latex -halt-on-error -output-directory=${BUILD}
BIBTEX = BIBINPUTS=${TEXLIB} && export BIBINPUTS && bibtex

VPATH = ${EVALDIR} ${FIGDIR}

BASE = thesis
DOCUMENT = ${BASE}.pdf
BIBFILE = ${BIBDIR}/pl.bib

SOURCES = ${addsuffix .tex, \
thesis \
macros \
cfa-macros \
frontpgs \
introduction \
background \
generic-types \
resolution-heuristics \
type-environment \
experiments \
conclusion \
}

FIGURES = ${addsuffix .eps, \
safe-conv-graph \
resolution-dag \
union-find-with-classes \
persistent-union-find \
}

GRAPHS = ${addsuffix .tex, \
generic-timing \
tests-completed \
per-prob-histo \
per-prob-depth \
cfa-time \
}

.PHONY : all rebuild-refs clean wc

all : ${DOCUMENT}

clean : 
	@rm -fv ${BUILD}/*

wc :
	wc ${SOURCES}

${DOCUMENT} : ${BASE}.ps
	ps2pdf ${BUILD}/$<

${BASE}.ps : ${BASE}.dvi
	dvips ${BUILD}/$< -o ${BUILD}/$@

${BASE}.dvi : Makefile ${SOURCES} ${GRAPHS} ${FIGURES} ${BIBFILE} ${BUILD}
	${LATEX} ${BASE}
	${BIBTEX} ${BUILD}/${BASE}
	${LATEX} ${BASE}
	${LATEX} ${BASE}

generic-timing.tex : generic-timing.gp generic-timing.dat ${BUILD}
	gnuplot -e BUILD="'${BUILD}/'" ${EVALDIR}/generic-timing.gp
	
tests-completed.tex : algo-summary.gp algo-summary.dat bu-summary.dat ${BUILD}
	gnuplot -e BUILD="'${BUILD}/'" ${EVALDIR}/algo-summary.gp

per-prob-histo.tex : per-prob.gp per-prob.tsv ${BUILD}
	gnuplot -e BUILD="'${BUILD}/'" ${EVALDIR}/per-prob.gp

per-prob-depth.tex : per-prob-scatter.gp ${BUILD}
	gnuplot -e BUILD="'${BUILD}/'" ${EVALDIR}/per-prob-scatter.gp

cfa-time.tex : cfa-plots.gp cfa-time.tsv cfa-mem.tsv ${BUILD}
	gnuplot -e BUILD="'${BUILD}/'" ${EVALDIR}/cfa-plots.gp

${BUILD}: 
	mkdir -p ${BUILD}