# Makefile for qp-numpy - should figure everything out by itself

PY_PREFIX = $(shell python -c "import sys ; print sys.prefix")
PY_VERSION = $(shell python -c "import sys ; print sys.version[:3]")

PY_INCLUDE = $(PY_PREFIX)/include/python$(PY_VERSION) 

QPmodule.so: qld.o qld_wrap.o
	gcc -shared $^ -o $@ -lf2c -lm

qld_wrap.o: qld_wrap.c
	gcc -Wall -fPIC -I$(PY_INCLUDE) -c qld_wrap.c


qld.o : qld_patch.f
	g77 -fPIC -ffast-math -O3 -o qld.o -c qld_patch.f

qld_patch.f : 
	sed -e 's/COMMON \/CMACHE\/EPS/EPS=2.23e-16/' < qld.f > qld_patch.f

clean:
	rm -f qld_patch.f
	rm -f *.o
	rm -f QPmodule.so

install: QPmodule.so
	install -m 644 $^ $(PY_PREFIX)/lib/python$(PY_VERSION)/site-packages/Numeric
	rm $^

test:	
	python test.py
