## Define the configuration variables.

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

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

## Define the text source files.

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

FIGURES = ${addsuffix .tex, \
AllocatorComponents \
AllocatedObject \
IntExtFragmentation \
MemoryFragmentation \
ContigFragmentation \
NonContigFragmentation \
ProgramFalseSharing \
AllocInducedActiveFalseSharing \
AllocInducedPassiveFalseSharing \
SingleHeap \
SharedHeaps \
PerThreadHeap \
MultipleHeapsStorage \
UserKernelHeaps \
MultipleHeapsOwnership \
MultipleHeapsNoOwnership \
ObjectHeaders \
Container \
ContainerNoOwnershipFreelist \
ContainerOwnershipFreelist \
ContainerFalseSharing1 \
ContainerFalseSharing2 \
ContainerNoOwnership \
ContainerOwnership \
SuperContainers \
FreeListAmongContainers \
FreeListWithinContainers \
PrivatePublicHeaps \
AllocDS1 \
AllocDS2 \
llheap \
Alignment1 \
Alignment2 \
Alignment2Impl \
FakeHeader \
Header \
decreasing \
increasing \
}

PICTURES = ${addsuffix .pstex, \
AddressSpace \
MultipleHeapsOwnershipStorage \
PrivatePublicHeaps \
RemoteFreeList \
}

PROGRAMS = ${addsuffix .tex, \
}

GRAPHS = ${addsuffix .tex, \
prolog \
swift \
java \
}

#prolog \

## 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} testgenfmt testgenfmt2 ${BASE}.ps WileyNJD-AMA.bst ${BASE}.out.ps ${Build}

# File Dependencies #

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

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

${BASE}.dvi : Makefile ${BASE}.out.ps WileyNJD-AMA.bst testgenfmt testgenfmt2 ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} \
		local.bib ../../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 .

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

testgenfmt : testgenfmt.cc
	g++ testgenfmt.cc -o $@

testgenfmt2 : testgenfmt2.cc
	g++ testgenfmt2.cc -o $@

#${addsuffix /testdata, ${basename ${GRAPHS}}} : ${addsuffix /testgen, ${basename ${GRAPHS}}}
#	echo ${addsuffix /testdata, ${basename ${GRAPHS}}}
#	echo ${addsuffix /testgen, ${basename ${GRAPHS}}}
#	testgenfmt < $< > $@

#swift/testdata.lexp : swift/testgen.ldata testgenfmt.cc
#	./testgenfmt < $<

swift/testdata.exp : swift/testgen.data testgenfmt2.cc
	./testgenfmt2 < $<

#prolog/testdata.lexp : prolog/testgen.ldata testgenfmt.cc
#	./testgenfmt < $<

prolog/testdata.exp : prolog/testgen.data testgenfmt2.cc
	./testgenfmt2 < $<

#java/testdata.lexp : java/testgen.ldata testgenfmt.cc
#	./testgenfmt < $<

java/testdata.exp : java/testgen.data testgenfmt2.cc
	./testgenfmt2 < $<

${GRAPHS} : Makefile plotexp.gp plotres.gp ${addsuffix /testdata.exp, ${basename ${GRAPHS}}}
	gnuplot -e GRAPH="'${basename $@}'" plotexp.gp
	gnuplot -e GRAPH="'${basename $@}'" plotres.gp

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