#!/usr/bin/make -f

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

# disable all CPU specific optimizations in commands launched by this Makefile
# using liboil; this is to work around liboil related build failures which
# are not specially interesting to catch on buildds as these might run very
# specific hardware
OIL_CPU_FLAGS := 0
export OIL_CPU_FLAGS

ifeq "$(DEB_BUILD_ARCH)" "armhf"
	EXTRA_OPTIONS = -Dgl_winsys=x11,gbm,wayland
endif

version=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
gst_version=$(shell echo $(version) | cut -d '-' -f 1)

%:
	dh $@ -Smeson --with quilt,gir

override_dh_auto_configure:
	dh_auto_configure -- \
	--default-library shared \
	-Dpackage-name="GStreamer Base Plugins (Marillat/DMO)" \
	-Dpackage-origin="https://www.deb-multimedia.org/" \
	-Dinstall_plugins_helper="/usr/bin/gstreamer-codec-install" \
	$(EXTRA_OPTIONS)

#	exit 1

override_dh_makeshlibs:
	dh_makeshlibs -plibgstreamer-plugins-base1.0-0 -X "/usr/lib/$(DEB_HOST_MULTIARCH)/gstreamer-1.0" -V 'libgstreamer-plugins-base1.0-0 (>= $(gst_version))' -- -c4
	dh_makeshlibs -plibgstreamer-gl1.0-0 -X "/usr/lib/$(DEB_HOST_MULTIARCH)/gstreamer-1.0" -V 'libgstreamer-gl1.0-0 (>= $(gst_version))' -- -c4

execute_after_dh_install:
	mkdir -p $(CURDIR)/fake-home
	HOME=$(CURDIR)/fake-home \
	LD_LIBRARY_PATH=debian/libgstreamer-plugins-base1.0-0/usr/lib/$(DEB_HOST_MULTIARCH):debian/libgstreamer-gl1.0-0/usr/lib/$(DEB_HOST_MULTIARCH):$(LD_LIBRARY_PATH) \
	    dh_gstscancodecs
	rm -rf $(CURDIR)/fake-home

override_dh_auto_test:
ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64))
	xvfb-run dh_auto_test
else
	xvfb-run dh_auto_test || true
endif
