#!/usr/bin/make -f

build_dir     = build
install_dir   = debian/tmp
pyvers       := $(shell pyversions -r)

-include /usr/share/python/python.mk

binary: binary-indep binary-arch

binary-arch: ;

binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs -A docs/changelog.txt
	dh_installmenu
	dh_installdocs
	dh_installman
	dh_install --list-missing --sourcedir $(install_dir)
	dh_fixperms
	dh_compress -X.py
	dh_python2
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

install: build
	dh_testdir
	dh_testroot
	dh_installdirs
	for py in $(pyvers); do \
	    $$py setup.py install --no-compile --root=debian/tmp ${py_setup_install_args}; done
	
	rm -f  $(install_dir)/usr/lib/python*/*-packages/PythonCard/install-pythoncard.py
	rm -f  $(install_dir)/usr/lib/python*/*-packages/PythonCard/PKG-INFO
	rm -f  $(install_dir)/usr/lib/python*/*-packages/PythonCard/README.txt
	rm -f  $(install_dir)/usr/lib/python*/*-packages/PythonCard/LICENSE.txt
	rm -f  $(install_dir)/usr/lib/python*/*-packages/PythonCard/setup.py
	rm -f  $(install_dir)/usr/lib/python*/*-packages/PythonCard/__version__.pyc
	rm -f  $(install_dir)/usr/lib/python*/*-packages/PythonCard/docs/changelog.txt
	rm -f  $(install_dir)/usr/lib/python*/*-packages/PythonCard/docs/readme.txt
	rm -rf $(install_dir)/usr/lib/python*/*-packages/PythonCard/tests
	rm -rf $(install_dir)/usr/lib/python*/*-packages/PythonCard/build
	
	# Fix 'executable-not-elf-or-script' lintian warnings.
	find $(install_dir)/usr/lib/python*/*-packages/PythonCard -executable | \
	    grep '\.\(jpg\|png\|rsrc\.py\|html\|txt\|/versionInfo\.py\)$$' | \
	    xargs chmod a-x

build: build-indep

build-arch:
	: # Nothing to do

build-indep: build-stamp
build-stamp: 
	dh_testdir
	set -e; \
	for py in $(pyvers); do \
	    $$py setup.py build ; done
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	-for py in $(pyvers); do \
	    $$py setup.py clean --all; done
	find . -name "*.pyc" | xargs rm -f
	find . -name "*.pyo" | xargs rm -f
	rm -rf $(build_dir) $(install_dir)
	dh_clean

.PHONY: binary binary-arch binary-indep install build build-arch build-indep clean
