# Need for $((1+1))
SHELL=/bin/bash

#go2:
#	seq 15 | ./highest -n 5 --use-fibonacci-heap

go: test display
	
test: red_black_dict_mod.py red_black_dict_mod.py treap.py py_treap.py fibonacci_heap_mod.py
	./highesttest

red_black_dict_mod.py: red-black-tree-dir/red_black_tree_mod.m4
	cd red-black-tree-dir && make
	cp red-black-tree-dir/red_black_dict_mod.py .

treap.py py_treap.py: treap-dir/m4_treap.m4
	# We're ignoring the cython version
	cd treap-dir/pure-python && python3 setup.py build
	cp treap-dir/pure-python/treap.py treap-dir/pure-python/py_treap.py .

fibonacci_heap_mod.py: fibonacci-heap-mod/fibonacci_heap_mod.py
	cp fibonacci-heap-mod/fibonacci_heap_mod.py .

display: graph-n.pdf graph-m.pdf
	#eog graph-m.ppm graph-n.ppm
	#evince graph-m.ps graph-n.ps

highest-bisect-m.dat highest-heap-m.dat highest-treap-m.dat sort-m.dat: time-them-m
	./time-them-m

highest-bisect-n.dat highest-heap-n.dat highest-treap-n.dat sort-n.dat: time-them-n
	./time-them-n

graph-n.pdf: highest-bisect-n.dat highest-heap-n.dat highest-treap-n.dat sort-n.dat graph-n.gp
	#(echo 'set terminal postscript color enhanced'; echo 'set output "graph-n.ps"'; cat graph-n.gp) | gnuplot
	gnuplot -e 'set terminal pdf color enhanced; set output "graph-n.pdf"; load "graph-n.gp"'

graph-m.pdf: highest-bisect-m.dat highest-heap-m.dat highest-treap-m.dat sort-m.dat graph-m.gp
	gnuplot -e 'set terminal pdf color enhanced; set output "graph-m.pdf"; load "graph-m.gp"'

clean:
	rm -f *.dat
	rm -f *.pyc
	rm -f red_black_dict_mod.py
	rm -f treap.py py_treap.py
	rm -f fibonacci_heap_mod.py
	cd red-black-tree-dir && make clean
	cd treap-dir && python3 setup.py clean
	cd fibonacci-heap-mod/ && make clean
	rm -rf treap-dir/build
	rm -f treap-dir/py_treap.py
	rm -f treap-dir/pyx_treap.pyx

veryclean: clean
	rm -f graph-*.pdf

publish:
	cp highest graph-[nm].png graph-[nm].ps ~/public_html/highest/.

install: red_black_dict_mod.py treap.py fibonacci_heap_mod.py
	./install-file --file highest --directory /usr/local/bin/.
	./install-file --file nest.py --directory /usr/local/lib/.
	./install-file --file dupdict_mod.py --directory /usr/local/lib/.
	./install-file --file red_black_dict_mod.py --directory /usr/local/lib/.
	./install-file --file treap.py --directory /usr/local/lib/.
	./install-file --file py_treap.py --directory /usr/local/lib/.
	./install-file --file fibonacci_heap_mod.py --directory /usr/local/lib/.