#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
include /usr/share/python/python.mk

# Work-around for gtk-doc bug:
# https://bugzilla.gnome.org/show_bug.cgi?id=783926
export PYTHONIOENCODING="utf-8"

PYVERS := $(shell pyversions --requested -v debian/control) $(shell py3versions --supported -v)
FLAVOURS := $(PYVERS) $(patsubst %,%-dbg,$(PYVERS))

configure_flags += \
		--disable-silent-rules \
		$(NULL)

%:
	dh $@ --with python2,python3,autoreconf

override_dh_auto_configure:
	set -e && for x in $(FLAVOURS); do \
	    dh_auto_configure --builddirectory=build-$$x -- PYTHON=/usr/bin/python$$x $(configure_flags) \
	        --with-libpython-dir="`/usr/bin/python$$x-config --configdir`" ; \
	done

override_dh_auto_build:
	set -e && for x in $(FLAVOURS); do \
	    dh_auto_build --builddirectory=build-$$x; \
	done

override_dh_auto_install:
	set -e && for x in $(FLAVOURS); do \
	    INST=debian/install-`echo $$x | sed 's/\.[0-9]*//'`; \
	    dh_auto_install --builddirectory=build-$$x --destdir=$$INST; \
	    find $$INST \( -name '*.pyc' -o -name '*.pyo' -o -name '*.la' \) -delete; \
	done

override_dh_auto_clean:
	rm -rf build-*
	rm -rf debian/install-*
	dh_auto_clean

override_dh_install:
	dh_install -ppython-gst-1.0 --sourcedir=debian/install-2
	dh_install -ppython-gst-1.0-dbg --sourcedir=debian/install-2-dbg
	dh_install -ppython3-gst-1.0 -pgstreamer1.0-python3-plugin-loader --sourcedir=debian/install-3
	dh_install -ppython3-gst-1.0-dbg -pgstreamer1.0-python3-dbg-plugin-loader --sourcedir=debian/install-3-dbg

