| 
GHC=            ghc
GHCFLAGS=       -cpp -O2 -funbox-strict-fields -no-recomp -v0
PKG=            -i..
#PKG=            -package fps
#GHC=            /usr/obj/build/compiler/stage2/ghc-inplace
#PKG=            
BIN=            run-utests run-qtests
all:  prop prop-fusion-compiled prop-compiled prop-opt units-compiled
fast: prop-fast
everything: prop hugs prop-compiled prop-fusion-compiled runbench fusionbench wc spellcheck letter_frequency linesort fuse down-fuse inline zipwith unpack groupby run-lazybuild run-lazybuildcons
# ---------------------------------------------
# Boot in-place
.PHONY: boot-in-place
boot-in-place:
	cd .. && ${GHC} ${GHCFLAGS} --make Data/*hs Data/*/*hs Data/*/*/*hs
# ---------------------------------------------
# HUnit
# compiled
.PHONY: units-compiled
units-compiled:
	@echo "Compiled, rules off"
	${GHC} ${PKG} ${GHCFLAGS} -frules-off --make Units.hs -o u -package HUnit
	time ./u
# ---------------------------------------------
# QuickCheck
# interpreted
.PHONY: prop hugs
prop:: 
	@echo "Interpreted"	
	runhaskell ${PKG} Properties.hs
hugs::
	runhugs -98 Properties.hs
# interpreted fast. Just a quick check.
.PHONY: prop-fast
prop-fast::
	runhaskell ${PKG} Properties.hs 10
# compiled
.PHONY: prop-compiled
prop-compiled: 
	@echo "Compiled, rules off"	
	${GHC} ${PKG} ${GHCFLAGS} -frules-off --make Properties.hs -o p -package QuickCheck
	time ./p
# rules-on
.PHONY: prop-opt
prop-opt: 
	@echo "Compiled, rules on"	
	${GHC} ${PKG} ${GHCFLAGS} --make Properties.hs -o p -package QuickCheck
	time ./p
#
# test rewriting is correct and working.
#
.PHONY: prop-fusion-compiled
prop-fusion-compiled:
	${GHC} ${PKG} ${GHCFLAGS} --make FusionProperties.hs -o fp -package QuickCheck
	time ./fp
# ---------------------------------------------------------
# Benchmarking
.PHONY: runbench
runbench: bench
	./bench +RTS -H64m
bench::
	@if [ ! -f "bigdata" ] ; then ln -s data bigdata ; fi
	${GHC} ${PKG} ${GHCFLAGS} --make Bench.hs -o bench
fusionbench::
	${GHC} ${PKG} ${GHCFLAGS} --make FusionBench.hs -ddump-simpl-stats -o fusionbench
# ---------------------------------------------------------
# Profiling
.PHONY: prof
prof::
	@if [ ! -f "bigdata" ] ; then ln -s data bigdata ; fi
	${GHC} ${PKG} ${GHCFLAGS} -prof -auto-all --make Bench.hs -o bench
	./bench +RTS -H64m -p
fusionprof::
	@if [ ! -f "bigdata" ] ; then ln -s data bigdata ; fi
	${GHC} ${PKG} ${GHCFLAGS} -prof -auto-all --make FusionBench.hs -o fusionbench
	./bench +RTS -H64m -p
# ---------------------------------------------------------
# Small programs
wc: wc.o
	@if [ ! -f "bigdata" ] ; then ln -s data bigdata ; fi
	time ./wc bigdata
wc.o: wc.hs
	${GHC} ${PKG} ${GHCFLAGS} -ddump-simpl-stats wc.hs -o wc
spellcheck: spellcheck.o
	time ./spellcheck < spellcheck-input.txt
spellcheck.o: spellcheck.hs
	${GHC} ${PKG} ${GHCFLAGS} $< -o spellcheck
letter_frequency: letter_frequency.o
	time ./letter_frequency < Usr.Dict.Words
letter_frequency.o: letter_frequency.hs
	${GHC} ${PKG} ${GHCFLAGS}  $< -o letter_frequency -ddump-simpl-stats
linesort: linesort.o
	time ./linesort < Usr.Dict.Words
linesort.o: linesort.hs
	${GHC} ${PKG} ${GHCFLAGS} $< -o linesort
fuse: fuse.o
	time ./fuse < Usr.Dict.Words
fuse.o: fuse.hs
	${GHC} ${PKG} ${GHCFLAGS} $< -o fuse -ddump-simpl-stats
down-fuse: down-fuse.o
	time ./down-fuse
down-fuse.o: down-fuse.hs
	${GHC} ${PKG} ${GHCFLAGS} $< -o ./down-fuse -ddump-simpl-stats
.PHONY: run-lazybuild
run-lazybuild: lazybuild
	time ./lazybuild 100000000 > /dev/null
lazybuild: lazybuild.hs
	${GHC} ${PKG} ${GHCFLAGS} --make $< -o lazybuild
.PHONY: run-lazybuildcons
run-lazybuildcons: lazybuildcons
	time ./lazybuildcons 100000000 > /dev/null
lazybuildcons: lazybuildcons.hs
	${GHC} ${PKG} ${GHCFLAGS} --make $< -o lazybuildcons
lazylines: lazylines.o
	time ./lazylines < bigdata
lazylines.o: lazylines.hs
	${GHC} ${PKG} ${GHCFLAGS} $< -o lazylines
inline: inline.o
	time ./inline
inline.o: inline.hs
	${GHC} ${PKG} ${GHCFLAGS} $< -o inline
zipwith: zipwith.o
	time ./zipwith
zipwith.o: zipwith.hs
	${GHC} ${PKG} ${GHCFLAGS} -ddump-simpl-stats $< -o zipwith
unpack: unpack.o
	time ./unpack
unpack.o: unpack.hs
	${GHC} ${PKG} ${GHCFLAGS} -ddump-simpl-stats $< -o unpack
groupby: groupby.o
	time ./groupby
groupby.o: groupby.hs
	${GHC} ${PKG} ${GHCFLAGS} $< -o groupby
# ---------------------------------------------------
# Plotting graphs
results: bench
	./bench +RTS -H64m > results
.PHONY: plot
plot:: results
	echo -e 'set terminal png          \n \
             set output "results.png"  \n \
             set yrange [0:2]          \n \
             plot "results" using ($$1):($$2) with boxes, "" using ($$1):($$3) with boxes' |\
             gnuplot ;
	xv results.png    
# ---------------------------------------------------
# Cleaning
.PHONY: clean
clean:
	rm -f *~ *.o *.hi $(BIN) bench */*.o */*.hi */*~ 
	rm -f wc letter_frequency spellcheck linesort fuse inline p u fp lazylines lazybuild lazybuildcons
	rm -f down-fuse zipwith fusionbench unpack groupby
 |