#!/usr/bin/make -f
# ipython debian/rules file
DEB_PYTHON_SYSTEM = pysupport
PYVERS = $(shell pyversions -vd)

# Make sure the html documentation is not compressed and thus stays usable.
DEB_COMPRESS_EXCLUDE := manual/html/

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-distutils.mk
include /usr/share/cdbs/1/rules/patchsys-quilt.mk

# force using of correct version of python during build inside scratchbox
# this is a internal variable from /usr/share/cdbs/1/class/python-distutils.mk, not meant to be used outside
#cdbs_python_compile_version=$(PYVERS)

cdbs_python_current_binary := $(shell pyversions -d)

DEB_PYTHON_INSTALL_ARGS_ALL = --no-compile -O0 --install-layout=deb

install/ipython::
	# remove test suite script
	rm $(CURDIR)/debian/ipython/usr/bin/iptest
	# remove documentation
	rm $(CURDIR)/debian/ipython/usr/share/doc/ipython/manual/html/_static/jquery.js
	ln -s /usr/share/javascript/jquery/jquery.js \
		$(CURDIR)/debian/ipython/usr/share/doc/ipython/manual/html/_static/

	# add wrapper scripts for all python versions
	set -e ;\
	firstpyver="" ;\
	for pyvers in $(PYVERS); do \
	    if [ "$${firstpyver}" = "" ]; then \
	        install -m 755 debian/ipython.sh $(CURDIR)/debian/ipython/usr/bin/ipython$$pyvers ;\
	        firstpyver="$$pyvers" ;\
	    else \
	        dh_link /usr/bin/ipython$${firstpyver} /usr/bin/ipython$$pyvers ;\
	    fi ;\
	    dh_link /usr/share/man/man1/ipython.1.gz /usr/share/man/man1/ipython$$pyvers.1.gz ;\
	done

	# change permission on scripts
	chmod a-x $(CURDIR)/debian/ipython/usr/share/doc/ipython/examples/*

	install -D -m0644	debian/icon.png	$(CURDIR)/debian/ipython/usr/share/icons/hicolor/scalable/hildon/ipython.png
	install -D -m0644	debian/ipython.desktop	$(CURDIR)/debian/ipython/usr/share/applications/hildon/ipython.desktop
	
	# removing bogus usr/IPython directory
	rm -rf $(CURDIR)/debian/ipython/usr/IPython

binary-fixup/ipython::
	rm -rf $(CURDIR)/debian/ipython/usr/share/doc/ipython/extensions

clean::
	-rm -rf build
	find . -name \*.pyo | xargs rm -rf
	find . -name \*.pyc | xargs rm -rf

python-build-stamp-%:
ifeq (all, $(cdbs_python_module_arch))
	cd $(DEB_SRCDIR) && $(cdbs_python_current_binary) $(DEB_PYTHON_SETUP_CMD) build $(DEB_PYTHON_BUILD_ARGS)
else
	cd $(DEB_SRCDIR) && $(cdbs_python_current_binary) $(DEB_PYTHON_SETUP_CMD) build $(DEB_PYTHON_BUILD_ARGS)
endif # archall detection
	touch $@

# install stage
ifeq (all, $(cdbs_python_module_arch))
common-install-arch common-install-indep:: python-install-py
python-install-py:
	cd $(DEB_SRCDIR) && $(cdbs_python_current_binary) $(DEB_PYTHON_SETUP_CMD) install --root=$(DEB_DESTDIR) $(DEB_PYTHON_INSTALL_ARGS_ALL)
else
common-install-arch common-install-indep:: $(addprefix python-install-, $(cdbs_python_build_versions))
python-install-%:
	cd $(DEB_SRCDIR) && $(cdbs_python_current_binary) $(DEB_PYTHON_SETUP_CMD) install --root=$(DEB_DESTDIR) $(DEB_PYTHON_INSTALL_ARGS_ALL)
endif # archall detection
