### Makefile for Andrew Beach's Masters Thesis

DOC=uw-ethesis.pdf
BUILD=out
TEXSRC=$(wildcard *.tex)
FIGSRC=$(wildcard *.fig)
BIBSRC=$(wildcard *.bib)
STYSRC=$(wildcard *.sty)
CLSSRC=$(wildcard *.cls)
TEXLIB= .:../../LaTeXmacros:${BUILD}:
BIBLIB= .:../../bibliography

# Since tex programs like to add their own file extensions:
BASE= ${DOC:%.pdf=%}

RAWSRC=${TEXSRC} ${BIBSRC} ${STYSRC} ${CLSSRC}
FIGTEX=${FIGSRC:%.fig=${BUILD}/%.tex}

### Special Rules:

.PHONY: all clean deepclean

### Commands:
LATEX=TEXINPUTS=${TEXLIB} latex -halt-on-error -output-directory=${BUILD}
BIBTEX=BIBINPUTS=${BIBLIB} bibtex
GLOSSARY=INDEXSTYLE=${BUILD} makeglossaries-lite

### Rules and Recipies:

all: ${DOC}

# The main rule, it does all the tex/latex processing.
${BUILD}/${BASE}.dvi: ${RAWSRC} ${FIGTEX} termhandle.pstex resumhandle.pstex Makefile | ${BUILD}
	${LATEX} ${BASE}
	${BIBTEX} ${BUILD}/${BASE}
	${GLOSSARY} ${BUILD}/${BASE}
	${LATEX} ${BASE}

# Convert xfig output to tex. (Generates \special declarations.)
${FIGTEX}: ${BUILD}/%.tex: %.fig | ${BUILD}
	fig2dev -L eepic $< > $@

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

# Step through dvi & postscript to handle xfig specials.
%.pdf : ${BUILD}/%.dvi
	dvipdf $^ $@

${BUILD}:
	mkdir $@

clean:
	-@rm -rv ${BUILD}

deepclean: clean
	-@rm -v ${DOC}
