all : parallel-gc.pdf

figures=
epsfigures=$(figures:.pdf=.eps)

tables=overhead.tex

$(epsfigures): %.eps: %.pdf
	pdf2ps $< $(@:.eps=.ps)
	ps2eps $(@:.eps=.ps)

parallel-gc.dvi :: $(tables)
	latex parallel-gc.tex
	bibtex parallel-gc
	latex parallel-gc.tex
	echo hello
	latex parallel-gc.tex
	echo hello
	dvips -t letter -f parallel-gc.dvi > parallel-gc.ps
	ps2pdf parallel-gc.ps

parallel-gc.pdf :: $(tables)
parallel-gc.pdf ::
	rm -f parallel-gc.pdf
	pdflatex parallel-gc.tex
	bibtex parallel-gc
	pdflatex parallel-gc.tex
	pdflatex parallel-gc.tex


NOFIB_ANALYSE = nofib-analyse/nofib-analyse
NOFIB_ANALYSE_SRCS = $(wildcard nofib-analyse/*.hs nofib-analyse/*.lhs)
EXTS = -cpp -XRankNTypes -XExistentialQuantification 

$(NOFIB_ANALYSE): $(NOFIB_ANALYSE_SRCS)
	ghc --make $(EXTS) $(NOFIB_ANALYSE_SRCS) -o $@

# Don't depend on $(NOFIB_ANALYSE): otherwise you'd be forced to install GHC
# just to build the paper.  I'll put the generated .tex tables in the repo
# instead; these rules are just to help me build the tables.
overhead.tex:
	$(NOFIB_ANALYSE) >$@ --latex --columns=GCETime results/overhead/log* 

eager.tex:
	$(NOFIB_ANALYSE) >$@ --latex --columns=GCETime \
		results/eager/log-*-LARGE-no-eager-promotion-baseline \
		results/eager/log-*-LARGE-baseline

# To generate speedup.pdf from speedup.csv:
#   - load up speedup.csv into Excel
#   - create a line graph
#   - label the axes
#   - cut & paste it into a new sheet
#   - save as PDF
#   - fix the viewport in the paper
#   - sigh, there must be an easier way to do this
speedup.csv:
	echo "linear speedup,1,2,3,4,5,6,7,8" >$@.tmp
	$(NOFIB_ANALYSE) >>$@.tmp --csv=GCETime results/speedup/log*threaded*
	sed 's/^\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)$$/\1 (\9),1,\3,\4,\5,\6,\7,\8,\9/' <$@.tmp >$@.tmp2
	sort --numeric --field-separator=, --key=9 --reverse <$@.tmp2 >$@
	rm -f $@.tmp $@.tmp2

balance.csv:
	echo "perfect balance,1,2,3,4,5,6,7,8" >$@.tmp
	$(NOFIB_ANALYSE) >>$@.tmp --csv=Balance --no-normalise results/speedup/log*threaded*
	sed 's/^\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)$$/\1 (\9),1,\3,\4,\5,\6,\7,\8,\9/' <$@.tmp >$@.tmp2
	sort --numeric --field-separator=, --key=9 --reverse <$@.tmp2 >$@
	rm -f $@.tmp $@.tmp2

chunksize.csv:
	$(NOFIB_ANALYSE) >$@.tmp --csv=GCETime results/chunksize/log*
	sed 's/^\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)$$/\1 (\5),1,\3,\4,\5/' <$@.tmp >$@.tmp2
	sort --numeric --field-separator=, --key=5 --reverse <$@.tmp2 >$@
	rm -f $@.tmp $@.tmp2

show:
	@echo '$(VALUE)="$($(VALUE))"'
