## Define the configuration variables.

Build = build
Figures = img
Macros = ../../../LaTeXmacros
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}

## Define the text source files.
FIGURES = ${addsuffix .tex, \
	emptybit \
	emptytree \
	emptytls \
	resize \
}

PICTURES = ${addsuffix .pstex, \
	base \
	empty \
	system \
}

PROGRAMS = ${addsuffix .tex, \
}

GRAPHS = ${addsuffix .tex, \
}

## Define the documents that need to be made.
all: comp_II.pdf presentation.pdf
comp_II.pdf: ${FIGURES} ${PICTURES}
presentation.pdf: presentationstyle.sty base.dark.pstex empty.dark.pstex system.dark.pstex

DOCUMENT = comp_II.pdf presentation.pdf
BASE = ${basename ${DOCUMENT}}

# Directives #

.PHONY : all clean					# not file names

all : ${DOCUMENT}

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

# File Dependencies #

%.pdf : build/%.ps | ${Build}
	ps2pdf $<

build/%.ps : build/%.dvi | ${Build}
	dvips $< -o $@

build/%.dvi : %.tex Makefile | ${Build}
	# Must have *.aux file containing citations for bibtex
	if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} $< ; fi
	-${BibTeX} ${basename $@}
	# Some citations reference others so run again to resolve these citations
	${LaTeX} $<
	-${BibTeX} ${basename $@}
	# Make index from *.aux entries and input index at end of document
	-makeglossaries -q -s ${basename $@}.ist ${basename $@}
	# Run again to finish citations
	${LaTeX} $<

## Define the default recipes.

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

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

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

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

## pstex with inverted colors
%.dark.pstex : img/%.fig Makefile | ${Build}
	fig2dev -L pstex $< > ${Build}/$@
	sed -i 's/\/col-1 {0 setgray} bind def/\/col-1 {1 setgray} bind def/g' ${Build}/$@
	sed -i 's/\/col0 {0.000 0.000 0.000 srgb} bind def/\/col0 {1.000 1.000 1.000 srgb} bind def/g' ${Build}/$@
	sed -i 's/\/col7 {1.000 1.000 1.000 srgb} bind def/\/col7 {0.000 0.000 0.000 srgb} bind def/g' ${Build}/$@
	fig2dev -L pstex_t -p ${Build}/$@ $< > ${Build}/$@_t

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