#!/usr/bin/make -f

export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

CONFIGURE_OPTIONS = -Dglade=true -Dgir=true

ifneq ($(filter libparlatype-doc,$(shell dh_listpackages)),)
CONFIGURE_OPTIONS += -Dgtk-doc=true
else
CONFIGURE_OPTIONS += -Dgtk-doc=false
endif

# Configure without ASR (Automatic Speech Recognition) on architectures
# that don't have libsphinxbase/libpocketsphinx.
# Recheck this list with next release.
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
ifneq (,$(filter mips64el mipsel s390x alpha ia64 powerpc,$(DEB_HOST_ARCH)))
CONFIGURE_OPTIONS += -Dasr=false
override_dh_install:
	dh_install -Xlibgstparlasphinx.so \
	           -Xasr.page \
	           -Xasr-setup.page
else
CONFIGURE_OPTIONS += -Dasr=true
endif

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_OPTIONS)

override_dh_makeshlibs:
	dh_makeshlibs -X/usr/lib/$(DEB_HOST_MULTIARCH)/gstreamer-1.0/libgstparlasphinx

# dconf in dbus-run-session expects a writable XDG_RUNTIME_DIR
RUN_DIR=$(CURDIR)/debian/tmp/run
override_dh_auto_test:
	mkdir -p -m0700 $(RUN_DIR)
	XDG_RUNTIME_DIR=$(RUN_DIR) dbus-run-session -- xvfb-run dh_auto_test

%:
	dh $@ --with gir --buildsystem=meson
