#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
DEB_PYTHON_SYSTEM = pysupport
DEB_PYTHON_MODULE_PACKAGES = python-guppy python-guppy-lib python-guppy-lib-dbg
include /usr/share/cdbs/1/class/python-distutils.mk

# Add here any variable or target overrides you need.
# install directly into package directory (despite multiple packages)
DEB_DESTDIR = $(CURDIR)/debian/python-guppy

#
# Main and -lib
#

install/python-guppy-lib::
# Run tests before moving .so's away
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	for buildver in $(cdbs_python_build_versions); do \
		echo "I: Running guppy unittests using python$$buildver"; \
        cd $(CURDIR) && cd $(DEB_SRCDIR)/build/lib.*-$$buildver && \
		PYTHONPATH=. \
         $(call cdbs_python_binary,python$$buildver) \
              -c 'from guppy import hpy; hpy().test()'; \
    done
endif
# move libraries into the python-guppy-lib package
#	mkdir -p debian/python-guppy-lib/usr/
	find $(DEB_DESTDIR) -iname *so | \
	  while read so; do \
	    d=$$(dirname $$so); \
	    d=$$(echo $$d | sed -e 's,python-guppy/,python-guppy-lib/,g'); \
	    ddbg=$$(echo $$d | sed -e 's,python-guppy/,python-guppy-lib-dbg/,g'); \
	    mkdir -p $$d $$ddbg; cp -p $$so $$ddbg; mv $$so $$d; \
	  done

# we need to move libraries away first, hence dependence on -lib
# Also without this step, movemodules from pysupport would not
# move arch-indep part of the module under pyshared
install/python-guppy:: install/python-guppy-lib

# Install emacs mode manually
install/python-guppy::
	install -D --mode 644 gsl-mode-*.el \
	   $(DEB_DESTDIR)/usr/share/emacs/site-lisp/gsl/gsl-mode.el

#
# Debugging version -lib-dbg
#

# Re-build using python-dbg
install/python-guppy-lib-dbg ::
	for i in $(cdbs_python_build_versions); do \
	  python$$i-dbg ./setup.py install $(DEB_PYTHON_INSTALL_ARGS_ALL) \
		 --root $(DEB_DESTDIR)-lib-dbg; \
	done
	find $(DEB_DESTDIR)-lib-dbg \
	  ! -type d ! -name '*_d.so' | xargs rm -f
# Prune empty directories
	find $(DEB_DESTDIR)-lib-dbg -depth -empty -exec rmdir \{\} \;

binary-predeb/python-guppy-lib-dbg::
	rm -rf $(DEB_DESTDIR)-lib-dbg/usr/share/doc/python-guppy-lib-dbg
	ln -s python-guppy-lib \
	  $(DEB_DESTDIR)-lib-dbg/usr/share/doc/python-guppy-lib-dbg


# immediately useable documentation
# and exemplar data (they are small excerpts anyways)
DEB_COMPRESS_EXCLUDE := .py .pdf .html .css .jpg .txt .js .json .rtc .par .bin
