#!/usr/bin/make -f

unexport LDFLAGS
export FFLAGS="-fPIC"
export ATLAS=None

PYVERS:= $(shell pyversions -v -r debian/control)
BASE=$(shell pwd)/debian

%:
	dh --with python-central $@

override_dh_auto_clean:
	rm -rf build
	find . -name "*.pyc" -exec rm {} \;

override_dh_auto_install:
	set -e; for v in $(PYVERS); do                                   \
		d=$(BASE)/python-scipy;                                  \
		mkdir -m 755 -p $$d/usr/share/doc/python-scipy;          \
		python$$v setup.py config_fc --noarch build;             \
		python$$v setup.py install --prefix $$d/usr              \
			--no-compile --install-layout=deb;               \
		rm -f $$d/usr/lib/python$$v/*-packages/scipy/LICENSE.txt;\
		python$$v setup.py clean --all;                          \
	done
	set -e; for v in $(PYVERS); do                                   \
		d=$(BASE)/python-scipy-dbg;                              \
		mkdir -m 755 -p $$d/usr/share/doc/python-scipy-dbg;      \
		CFLAGS="-g -ggdb" python$$v-dbg setup.py config_fc       \
					--noarch build;                  \
		python$$v-dbg setup.py install --prefix $$d/usr          \
			--no-compile --install-layout=deb;               \
		rm -f $$d/usr/lib/python$$v/*-packages/scipy/LICENSE.txt;\
		python$$v-dbg setup.py clean --all;                      \
	done
	find debian/python-scipy-dbg ! -type d ! -name '*_d.so' | xargs rm -f
	find debian/python-scipy-dbg -depth -empty -exec rmdir {} \;
	rm -fr $(BASE)/python-scipy*/usr/lib/python*/*-packages/scipy/weave/examples/

override_dh_fixperms:
	dh_fixperms
	set -e; for i in `find debian -mindepth 2 -type f ! -perm 755`; do \
		if head -1 $$i | grep -q '^#!' ; then                      \
	    		chmod +x $$i;                                      \
		fi ;                                                       \
	done
	sed -i '1s|.|#!/usr/bin/python\n&|' $(BASE)/python-scipy/`pycentral pycentraldir python-scipy`/scipy/cluster/tests/vq_test.py
	sed -i '1s|.|#!/usr/bin/python\n&|' $(BASE)/python-scipy/`pycentral pycentraldir python-scipy`/scipy/stats/tests/test_stats.py

override_dh_strip:
	dh_strip --dbg-package=python-scipy-dbg
