## 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.
TEXTS = ${addprefix text/, ${addsuffix .tex, \
	front \
	intro \
	existing \
	runtime \
	core \
	practice \
	io \
}}

FIGURES = ${addsuffix .tex, \
}

PICTURES = ${addsuffix .pstex, \
	base \
	empty \
	emptybit \
	emptytls \
	emptytree \
	fairness \
	io_uring \
	pivot_ring \
	system \
}

PROGRAMS = ${addsuffix .tex, \
}

GRAPHS = ${addsuffix .tex, \
}

## Define the documents that need to be made.
all: thesis.pdf
thesis.pdf: ${TEXTS} ${FIGURES} ${PICTURES} thesis.tex glossary.tex local.bib

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

# Directives #

.NOTPARALLEL:						# cannot make in parallel

.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}
	# Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
	if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi
	# 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 $@}
	# Make index from *.aux entries and input index at end of document
	-makeindex ${basename $@}.idx
	# Run again to finish citations
	${LaTeX} $<

## Define the default recipes.

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

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

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

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

%.pstex : build/%.svg | ${Build}
	inkscape -z -D --file=$< --export-eps=${Build}/$@ --export-latex
	mv ${Build}/$@_tex ${Build}/$@_t
	echo "sed -i 's/$@/${Build}/$@/g' ${Build}/$@_t"
	sed -i 's/$@/${Build}\/$@/g' ${Build}/$@_t

build/fairness.svg : fig/fairness.py | ${Build}
	python3 $< $@

## pstex with inverted colors
%.dark.pstex : fig/%.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: #
