## Define the configuration variables.

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

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

## Define the text source files.

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

FIGURES = ${addsuffix .tex, \
Cdecl \
}

PICTURES = ${addsuffix .pstex, \
}

PROGRAMS = ${addsuffix .tex, \
}

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

## Define the documents that need to be made.

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

# Directives #

.PHONY : all clean					# not file names

all : ${DOCUMENT}

clean :
	@rm -frv ${DOCUMENT} ${BASE}.ps WileyNJD-AMA.bst ${BASE}.out.ps ${Build}

Paper.zip :
	zip -x general/.gitignore -x general/Paper.out.ps -x general/Paper.tex.plain -x -x general/WileyNJD-AMA.bst general/"*evaluation*" -x general/evaluation.zip \
		-x general/mail -x general/response -x general/test.c -x general/Paper.ps -x general/"*build*" -r Paper.zip general pl.bib

evaluation.zip :
	zip -x evaluation/.gitignore -x evaluation/timing.xlsx -x evaluation/timing.dat -r evaluation.zip evaluation

# File Dependencies #

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

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

${BASE}.dvi : Makefile ${BASE}.out.ps WileyNJD-AMA.bst ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} \
		../../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 $@}
	# Run again to finish citations
	${LaTeX} ${basename $@}.tex

## Define the default recipes.

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

${BASE}.out.ps : | ${Build}
	ln -fs ${Build}/Paper.out.ps .

WileyNJD-AMA.bst :
	ln -fs ../AMA/AMA-stix/ama/WileyNJD-AMA.bst .

${GRAPHS} : ${Build} timing.gp timing.dat
	gnuplot -e Build="'${Build}/'" evaluation/timing.gp

%.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

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