python_version=2.6

go: funnelsort_py.py funnelsort.so
	rm -f *.dat
	# this does a line-resolution profiling, if you decorate relevant functions with @profile
	#kernprof.py -l -v ./test-funnelsort
	./test-funnelsort

go2: test-smallsorts funnelsort_py.py funnelsort.so
	kernprof.py -l -v ./test-smallsorts

# unused, but nice to know it's there
funnelsort_py.py: funnelsort.m4 this-pylint
	m4 --define=m4purepy=1 < funnelsort.m4 > funnelsort_py.py
	# pylint barks about the @profile decorator that kernprof requires
	sed 's/@profile//' < funnelsort_py.py > funnelsort_py_for_linting.py
	./this-pylint funnelsort_py_for_linting.py 

funnelsort.pyx: funnelsort.m4
	m4 --define=m4pyx=1 < funnelsort.m4 > funnelsort.pyx
	
funnelsort.c: funnelsort.pyx
	cython funnelsort.pyx

funnelsort.o: funnelsort.c
	gcc -O3 -c -fPIC -I /usr/include/python$(python_version) funnelsort.c

funnelsort.so: funnelsort.o
	gcc -shared funnelsort.o -o funnelsort.so

dats=funnelsort.dat timsort.dat
graph.ps: graph-ps.gp $(dats)
	gnuplot graph-ps.gp

clean:
	rm -f *.dat graph.ps funnelsort.pyx funnelsort.c *.so *.o funnelsort_py.py funnelsort_py_for_linting.py *.lprof *.pyc