## 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 \
	eval_micro \
	eval_macro \
}}

FIGURES = ${addsuffix .tex, \
}

PICTURES = ${addsuffix .pstex, \
	base \
	base_avg \
	cache-share \
	cache-noshare \
	empty \
	emptybit \
	emptytls \
	emptytree \
	fairness \
	idle \
	idle1 \
	idle2 \
	idle_state \
	io_uring \
	pivot_ring \
	system \
	cycle \
	result.cycle.jax.ops \
	result.yield.jax.ops \
	result.churn.jax.ops \
	result.cycle.jax.ns \
	result.yield.jax.ns \
	result.churn.jax.ns \
	result.cycle.low.jax.ops \
	result.yield.low.jax.ops \
	result.churn.low.jax.ops \
	result.cycle.low.jax.ns \
	result.yield.low.jax.ns \
	result.churn.low.jax.ns \
	result.memcd.updt.qps \
	result.memcd.updt.lat \
	result.memcd.rate.qps \
	result.memcd.rate.99th \
}

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 ../../../LaTeXmacros/common.tex ../../../LaTeXmacros/common.sty

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 $< $@

cycle_jax_ops_FLAGS = --MaxY=120000000
cycle_low_jax_ops_FLAGS = --MaxY=120000000
cycle_jax_ns_FLAGS = --MaxY=2000
cycle_low_jax_ns_FLAGS = --MaxY=2000

yield_jax_ops_FLAGS = --MaxY=150000000
yield_low_jax_ops_FLAGS = --MaxY=150000000
yield_jax_ns_FLAGS = --MaxY=1500
yield_low_jax_ns_FLAGS = --MaxY=1500

build/result.%.ns.svg : data/% Makefile | ${Build}
	../../../../benchmark/plot.py -f $< -o $@ -y "ns per ops/procs" $($(subst .,_,$*)_ns_FLAGS)

build/result.%.ops.svg : data/% Makefile | ${Build}
	../../../../benchmark/plot.py -f $< -o $@ -y "Ops per second" $($(subst .,_,$*)_ops_FLAGS)

build/result.memcd.updt.qps.svg : data/memcd.updt Makefile | ${Build}
	../../../../benchmark/plot.py -f $< -o $@ -y "Actual QPS" -x "Update Ratio"

build/result.memcd.updt.lat.svg : data/memcd.updt Makefile | ${Build}
	../../../../benchmark/plot.py -f $< -o $@ -y "Average Read Latency" -x "Update Ratio"

build/result.memcd.rate.qps.svg : data/memcd.rate Makefile | ${Build}
	../../../../benchmark/plot.py -f $< -o $@ -y "Actual QPS" -x "Target QPS"

build/result.memcd.rate.99th.svg : data/memcd.rate Makefile | ${Build}
	../../../../benchmark/plot.py -f $< -o $@ -y "Tail Read Latency" -x "Target QPS"

## 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: #
