#!/usr/bin/make -f
# -*- makefile -*-

# used only until dh_python3 pyremove is backported for wheezy 
PY3VERS := $(shell py3versions -vr)

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export PYBUILD_NAME=spyderlib
export PYBUILD_BUILD_ARGS=--no-doc
export PYBUILD_INSTALL_ARGS=--no-doc

%:
	dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild

override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=. http_proxy='localhost' sphinx-build -N -bhtml doc/ build/html  # HTML generator
	PYTHONPATH=. http_proxy='localhost' sphinx-build -N -bman doc/ build/man  # HTML generator

override_dh_auto_install:
	dh_auto_install
	# install the spyder-common files
	dh_install -p spyder-common spyderlib/images usr/share/spyderlib
	dh_install -p spyder-common spyderplugins/images usr/share/spyderplugins
	# install the spyder files
	dh_install --sourcedir=$(CURDIR)/debian/python-spyderlib -p spyder usr/bin
	dh_install --sourcedir=$(CURDIR)/debian/python-spyderlib -p spyder usr/share/applications/spyder.desktop
	dh_install --sourcedir=$(CURDIR)/debian/python-spyderlib -p spyder usr/share/pixmaps/spyder.png
	rm -rf $(CURDIR)/debian/python-spyderlib/usr/bin
	rm -rf $(CURDIR)/debian/python-spyderlib/usr/share/applications
	rm -rf $(CURDIR)/debian/python-spyderlib/usr/share/pixmaps
	rm -f $(CURDIR)/debian/spyder/usr/bin/*.py
	# install the spyder3 files
	dh_install --sourcedir=$(CURDIR)/debian/python3-spyderlib -p spyder3 usr/bin
	dh_install --sourcedir=$(CURDIR)/debian/python3-spyderlib -p spyder3 usr/share/applications/spyder3.desktop
	dh_install --sourcedir=$(CURDIR)/debian/python3-spyderlib -p spyder3 usr/share/pixmaps/spyder3.png
	rm -rf $(CURDIR)/debian/python3-spyderlib/usr/bin
	rm -rf $(CURDIR)/debian/python3-spyderlib/usr/share/applications
	rm -rf $(CURDIR)/debian/python3-spyderlib/usr/share/pixmaps
	rm -f $(CURDIR)/debian/spyder3/usr/bin/*.py
	# remove unwanted files until dh_python3 pyremove is backported to wheezy
	for v in $(PY3VERS); do \
		rm -rf $(CURDIR)/debian/python3-spyderlib/usr/lib/python$$v/dist-packages/spyderlib/images ;\
		rm -rf $(CURDIR)/debian/python3-spyderlib/usr/lib/python$$v/dist-packages/spyderplugins/images ;\
	done
