## Define the configuration variables.

Build = build
Macros = ../../LaTeXmacros
TeXLIB = .:${Macros}:${Build}:../../bibliography:
LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex -halt-on-error -output-directory=${Build} -interaction=nonstopmode
BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex

MAKEFLAGS = --no-print-directory --silent #

## Define the text source files.

SOURCES = ${addsuffix .tex, \
Paper \
}

FIGURES = ${addsuffix .tex, \
}

PICTURES = ${addsuffix .pstex, \
}

PROGRAMS = ${addsuffix .tex, \
}

GRAPHS = ${addsuffix .tex, \
timing \
}

## Define the documents that need to be made.

DOCUMENT = Paper.pdf

# Directives #

.PHONY : all clean										# not file names

all : ${DOCUMENT}

clean :
	@rm -frv ${DOCUMENT} ${basename ${DOCUMENT}}.ps ${Build}

# File Dependencies #

${DOCUMENT} : ${basename ${DOCUMENT}}.ps
	ps2pdf $<

${basename ${DOCUMENT}}.ps : ${basename ${DOCUMENT}}.dvi
	dvips ${Build}/$< -o $@

${basename ${DOCUMENT}}.dvi : Makefile ${Build} ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \
			${Macros}/common.tex ${Macros}/indexstyle ../../bibliography/cfa.bib
	if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi # Must have *.aux file containing citations for bibtex
	-${BibTeX} ${Build}/${basename $@}					# Some citations reference others so run again to resolve these citations
	${LaTeX} ${basename $@}.tex
	-${BibTeX} ${Build}/${basename $@}
	${LaTeX} ${basename $@}.tex							# Finish citations

## Define the default recipes.

vpath %.tex ${subst .zzz,,${subst .zzz ,:,${SOURCES}}}	# add prefix for source
vpath %.fig ${subst .zzz,,${subst .zzz ,:,${SOURCES}}}	# add prefix for source

${Build}:
	mkdir -p ${Build}

${GRAPHS} : evaluation/timing.gp evaluation/timing.dat
	gnuplot evaluation/timing.gp

%.tex : figures/%.fig
	fig2dev -L eepic $< > ${Build}/$@

%.ps : figures/%.fig
	fig2dev -L ps $< > ${Build}/$@

%.pstex : figures/%.fig
	fig2dev -L pstex $< > ${Build}/$@
	fig2dev -L pstex_t -p ${Build}/$@ $< > ${Build}/$@_t

# Local Variables: #
# tab-width : 4 #
# compile-command: "make" #
# End: #
