## Define the appropriate configuration variables.

TeXLIB = .:./style:./text:./annex:./build:../../LaTeXmacros:../../LaTeXmacros/listings:../../LaTeXmacros/enumitem:~/bibliographies:
LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex -halt-on-error -output-directory=build -interaction=nonstopmode
BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex -terse

## Define the text source files.

SOURCES = ${addsuffix .tex, \
thesis \
style/style \
style/cfa-format \
annex/glossary \
text/intro \
text/basics \
text/cforall \
text/concurrency \
text/internals \
text/parallelism \
text/results \
text/together \
text/conclusion \
text/future \
text/acknowledge \
}

FIGURES = ${addprefix build/, ${addsuffix .tex, \
	monitor \
	ext_monitor \
	int_monitor \
	dependency \
}}

PICTURES = ${addprefix build/, ${addsuffix .pstex, \
	system \
	monitor_structs \
}}

PROGRAMS = ${addsuffix .tex, \
}

GRAPHS = ${addsuffix .tex, \
}

## Define the documents that need to be made.

DOCUMENT = thesis.pdf

# Directives #

all : ${DOCUMENT}

clean :
	@rm -fv ${DOCUMENT} \
	build/*.acn     \
	build/*.acr     \
	build/*.alg     \
	build/*.aux     \
	build/*.bbl     \
	build/*.blg     \
	build/*.brf     \
	build/*.cf      \
	build/*.dvi     \
	build/*.glg     \
	build/*.glo     \
	build/*.gls     \
	build/*.ist     \
	build/*.idx     \
	build/*.ilg     \
	build/*.ind     \
	build/*.log     \
	build/*.out     \
	build/*.ps      \
	build/*.pstex   \
	build/*.pstex_t \
	build/*.tex     \
	build/*.toc     \


# File Dependencies #

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

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

build/${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex ../../LaTeXmacros/common.tex ../../LaTeXmacros/indexstyle annex/local.bib

	@ if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi 				# Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
	@ echo "Citation lookup"											# Must have *.aux file containing citations for bibtex
	@ if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename ${notdir $@}}.tex ; fi
	@ echo "Citation Pass 1"
	@ -${BibTeX} ${basename $@}											# Some citations reference others so run steps again to resolve these citations
	@ echo "Citation Pass 2"
	@ ${LaTeX} ${basename ${notdir $@}}.tex
	@ -${BibTeX} ${basename $@}
	@ echo "Glossary"
	@ makeglossaries -q -s ${basename $@}.ist ${basename $@}						# Make index from *.aux entries and input index at end of document
	@ echo ".dvi generation"
	@ -build/bump_ver.sh
	@ ${LaTeX} ${basename ${notdir $@}}.tex									# Run again to get index title into table of contents


predefined :
	sed -f predefined.sed ${basename ${DOCUMENT}}.tex > ${basename $@}.cf

## Define the default recipes.

build/%.tex : figures/%.fig
	fig2dev -L eepic $< > $@

build/%.ps : figures/%.fig
	fig2dev -L ps $< > $@

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


# Local Variables: #
# compile-command: "make" #
# End: #
