pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
py = python2.2 python2.1 python2 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

all : cursexmodule.so YahooMD5module.so curphoo
cursexmodule.so : cursex.o cursex_wrap.o
	$(CC) -shared cursex.o cursex_wrap.o -lncurses -ocursexmodule.so

cursex_wrap.o :
	$(CC) -c cursex_wrap.c -I$(pyinc) -I$(pylib)/config

cursex.o :
	$(CC) -c cursex.c -I$(pyinc) -I$(pylib)/config

sha.o: sha.c sha.h
	$(CC) -c sha.c

md5.o :
	$(CC) -c md5.c

yahoo.o :
	$(CC)  -c yahoo.c

crypt.o :
	$(CC)  -c crypt.c

YahooMD5_wrap.o :
	$(CC) -c yahoo.c YahooMD5_wrap.c -I$(pyinc) -I$(pylib)/config

YahooMD5module.so : YahooMD5_wrap.o crypt.o md5.o yahoo.o sha.o
	$(CC) -shared YahooMD5_wrap.o crypt.o md5.o yahoo.o sha.o -o YahooMD5module.so

clean :
	@rm -vf *.pyc *.o *.so curphoo

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

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

.PHONY : testversion curphoo 

