## Define the configuration variables.

Build = build
Figures = figures
Macros = ../../LaTeXmacros
TeXLIB = .:style:text:${Macros}:${Build}:../../bibliography:
LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex -halt-on-error -output-directory=${Build}
BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex -terse

MAKEFLAGS = --no-print-directory --silent #
VPATH = ${Build} ${Figures}

## Define the text source files.

SOURCES = ${addsuffix .tex, \
	text/intro \
	text/CFA_intro \
	text/actors \
	text/frontpgs \
	text/CFA_concurrency \
	thesis \
	text/mutex_stmt \
	text/channels \
	text/waituntil \
}

FIGURES = ${addsuffix .pgf, \
	figures/pykeExecutor \
	figures/pykeCFAExecutor \
	figures/nasusExecutor \
	figures/nasusCFAExecutor \
	figures/pykeMatrix \
	figures/pykeCFAMatrix \
	figures/nasusMatrix \
	figures/nasusCFAMatrix \
	figures/pykeRepeat \
	figures/pykeCFARepeat \
	figures/nasusRepeat \
	figures/nasusCFARepeat \
	figures/pykeCFABalance-One \
	figures/nasusCFABalance-One\
	figures/pykeCFABalance-Multi \
	figures/nasusCFABalance-Multi \
	figures/pyke_Aggregate_Lock_2 \
	figures/pyke_Aggregate_Lock_4 \
	figures/pyke_Aggregate_Lock_8 \
	figures/nasus_Aggregate_Lock_2 \
	figures/nasus_Aggregate_Lock_4 \
	figures/nasus_Aggregate_Lock_8 \
	figures/nasus_Channel_Contention \
	figures/pyke_Channel_Contention \
	figures/pyke_Future \
	figures/nasus_Future \
	figures/pyke_Contend_2 \
	figures/pyke_Contend_4 \
	figures/pyke_Contend_8 \
	figures/pyke_Spin_2 \
	figures/pyke_Spin_4 \
	figures/pyke_Spin_8 \
	figures/nasus_Contend_2 \
	figures/nasus_Contend_4 \
	figures/nasus_Contend_8 \
	figures/nasus_Spin_2 \
	figures/nasus_Spin_4 \
	figures/nasus_Spin_8 \
}

DATA = 	data/pykeSendStatic \
	data/pykeSendDynamic\
	data/pykeExecutorMem\
	data/nasusSendStatic\
	data/nasusSendDynamic\
	data/pykeExecutorMem\

PICTURES = ${addsuffix .tikz, \
	diagrams/standard_actor \
	diagrams/inverted_actor \
	diagrams/gulp \
	diagrams/chain_swap \
	diagrams/M_to_one_swap \
	diagrams/acyclic_swap \
	diagrams/cyclic_swap \
}

PROGRAMS = ${addsuffix .tex, \
}

GRAPHS = ${addsuffix .tex, \
}

## Define the documents that need to be made.

DOCUMENT = thesis.pdf
BASE = ${basename ${DOCUMENT}}

# Directives #

.PHONY : all clean					# not file names

all : ${DOCUMENT}

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

# File Dependencies #

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

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

${BASE}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${DATA} \
		glossary.tex style/style.tex ${Macros}/common.tex ${Macros}/indexstyle local.bib ../../bibliography/pl.bib | ${Build}
	# Must have *.aux file containing citations for bibtex
	if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi
	-${BibTeX} ${Build}/${basename $@}
	# Some citations reference others so run again to resolve these citations
#	${LaTeX} ${basename $@}.tex
#	-${BibTeX} ${Build}/${basename $@}
	# Make index from *.aux entries and input index at end of document
	makeglossaries -q -s ${Build}/${basename $@}.ist ${Build}/${basename $@}
	# Run again to finish citations
	${LaTeX} ${basename $@}.tex

## Define the default recipes.

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

# The following rules are currently unused but could be used later 
# if we want to swap figures to be .pngs
# %.tex : %.fig ${Build}
# 	fig2dev -L eepic $< > ${Build}/$@

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

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

# #-----------------------------------------------------------------------------------
# # Tools to generate png files
# # to create a png we create a pdf and convert it to png
# %.png : build/%.pstex figures/%.tex ${Build}
# 	echo ${basename $@}
# 	${LaTeX} figures/${basename $@}.tex
# 	dvips build/${basename $@}.dvi -o build/${basename $@}.ps
# 	ps2pdf build/${basename $@}.ps
# 	convert -negate ${basename $@}.pdf $@

# creating a pdf of a figure requires generating some latex that just includes the figure
# figures/%.tex: build/%.pstex ${Build}
# 	echo -n 	"\documentclass[preview]{standalone}\n" 	\
# 			"\usepackage[T1]{fontenc}\n" 			\
# 			"\usepackage[usenames]{color}\n" 		\
# 			"\usepackage{graphicx}\n" 			\
# 			"\usepackage{listings}\n" 			\
# 			"\usepackage{xspace}\n" 			\
# 			"\input{style}\n" 				\
# 			"\\\\begin{document}\n"				\
# 			"{\\\\resizebox{3\\\\textwidth}{!}{\input{${basename ${notdir $@}}.pstex_t}}}\n" \
# 			"\end{document}" > $@

data/%: ;
%.tikz: ;
%.pgf: ;

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