pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
py = python2.2 python2.1 python2.0 python
pybin = $(firstword $(foreach e,$(py),$(call pathsearch,$(e))))
pyver = `$(pybin) -c 'import sys; print sys.version[:3]'`
pyprefix = `$(pybin) -c 'import sys; print sys.prefix'`
pyinc = $(pyprefix)/include/python$(pyver)
pylib = $(pyprefix)/lib/python$(pyver)
prefix = /usr/local
bindir = $(prefix)/bin

install : testversion curphoo
	$(pybin) setup.py install -O1
	install curphoo $(bindir)

uninstall :
	@rm -f $(bindir)/curphoo
	@rm -rf $(pylib)/site-packages/Curphoo


clean :
	@rm -rf build
	@rm -f *.o *.so curphoo

testversion :
	@$(pybin) -c 'import sys; sys.version_info[0] == 2 or sys.exit(1)'

curphoo :
	@$(pybin) -c "print '''#!$(pybin)\n\nfrom Curphoo import boot\n__name__=='__main__' and boot.go()'''" >curphoo

.PHONY : testversion curphoo 

