#!/usr/bin/make -f

#export DH_VERBOSE=1

export PYTHONWARNINGS=d

export CFLAGS = $(shell dpkg-buildflags --get CFLAGS)
export CPPFLAGS = $(shell dpkg-buildflags --get CPPFLAGS)
export LDFLAGS = $(shell dpkg-buildflags --get LDFLAGS)

PYVERS = $(shell pyversions -vr)
PACKAGE_NAME = python-pywt
MODULE_NAME = PyWavelets

TESTS = \
	test_doc.py \
	test_perfect_reconstruction.py \
	test_regression.py

pythonpath = $$(_py_=$(strip $(1)); _py_=$${_py_\#python}; ls -d $(CURDIR)/build/lib.*-$${_py_})

clean:
	dh_testdir
	dh_testroot
	rm -rf build doc/build src/_pywt.[ch]
	rm -rf $(MODULE_NAME).egg-info
	find . -name '*\.py[co]' -delete
	dh_clean install-stamp install-ext-* build-stamp build-ext-* build-docs

build: build-arch build-indep
build-arch: build-stamp
build-indep:
build-stamp: build-docs $(PYVERS:%=build-ext-%)
	touch $@

build-docs:
	make -C doc html
	touch $@

build-ext-%:
	dh_testdir
	python$* setup.py build

ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	set -e; \
	cd tests; \
	for test in $(TESTS); do \
		PYTHONPATH=$(call pythonpath,python$*) python$* $$test; \
	done
endif

	touch $@

install: install-stamp
install-stamp: build-stamp $(PYVERS:%=install-ext-%)
install-ext-%:
	python$* setup.py install \
		--root $(CURDIR)/debian/$(PACKAGE_NAME) --install-layout=deb

binary-indep:

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs CHANGES.txt
	dh_installdocs
	dh_sphinxdoc
	dh_link usr/share/doc/python-pywt/copyright usr/share/doc/python-pywt/html/_downloads/COPYING.txt
	dh_installexamples -a
	dh_python2 -a
	dh_strip -a
	dh_compress -X.py -Xobjects.inv -X.txt
	dh_fixperms
	dh_installdeb
	dh_shlibdeps -a
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

.PHONY: clean binary-indep binary-arch binary
