#!/usr/bin/make -f
%:
	dh $@ --with python2

override_dh_auto_build:
	rm -f cpyamf/*.c
	cython cpyamf/*.pyx
	dh_auto_build
	# the documentation is not built due to a missing dependency
	# cd doc && sphinx-build -b html . ../build/html

override_dh_auto_clean:
	find pyamf/tests -type f -name '*.pyc' -delete
	dh_auto_clean
	rm -rf PyAMF.egg-info cpyamf/*.so cpyamf/*.c

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# the test suite does not 100% pass at present.
	# See http://dev.pyamf.org/ticket/821
	set -e; \
	for python in $(shell pyversions -r); do \
		$$python setup.py test; \
		$$python-dbg setup.py test; \
	done || true
endif

override_dh_link:
#	# remove redundant copies of swfobject.js
#	set -e; \
#	for js in $(shell find debian/python-pyamf-doc -name swfobject.js); do \
#		[ "$$(dirname $$js)" != "debian/python-pyamf-doc/usr/share/doc/python-pyamf-doc/assets" ] && \
#		dh_link -p python-pyamf-doc \
#			usr/share/doc/python-pyamf-doc/assets/swfobject.js \
#			`echo $$js | sed 's_^debian/python-pyamf-doc/__'` ; \
#	done
	# remove bundled copies of mootools javascript library
	set -e; \
	for js in $(shell find debian/python-pyamf-doc -name mootools.js); do \
		dh_link -p python-pyamf-doc \
			usr/share/javascript/mootools/mootools.js \
			`echo $$js | sed 's_^debian/python-pyamf-doc/__'` ; \
	done

override_dh_compress:
	dh_compress -X.py -X.js

override_dh_strip:
ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
	# Stripped symbols go into python-pyamf-dbg
	dh_strip --dbg-package=python-pyamf-dbg
endif

get-orig-source:
	cd $(dir $(firstword $(MAKEFILE_LIST)))../ && \
	uscan --rename --force-download --watchfile debian/watch --destdir $(CURDIR)
