#!/usr/bin/make -f
# -*- makefile -*-

export DPKG_GENSYMBOLS_CHECK_LEVEL=4
export QT_SELECT=qt5

ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
export QT_SELECT=qt5-$(DEB_BUILD_MULTIARCH)-$(DEB_HOST_MULTIARCH)
export PKG_CONFIG_PATH=/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
endif

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

%:
	dh $@

override_dh_auto_configure:
	# Backup .db file that gets modified during build...
	cp plugins/bn/src/database_bn.db plugins/bn/src/database_bn.db.bak
	dh_auto_configure -- -recursive \
	                     MALIIT_DEFAULT_PROFILE=lomiri \
	                     CONFIG+=debug \
	                     CONFIG+=nodoc \
	                     CONFIG+=enable-presage \
	                     CONFIG+=enable-hunspell \
	                     CONFIG+=enable-pinyin

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
	# Tests write $HOME/.presage/lm.db, make sure $HOME is
	# writable.
	rm -rf $(CURDIR)/debian/test-home
	mkdir -p $(CURDIR)/debian/test-home
	HOME=$(CURDIR)/debian/test-home xvfb-run -a make check
endif
endif

override_dh_clean:
	rm -rf $(CURDIR)/debian/test-home
	# Restore .db file that gets modified at build time
	-mv plugins/bn/src/database_bn.db.bak plugins/bn/src/database_bn.db
	# Remove .mo files from po/ after build (before next build)
	-rm po/*.mo
	dh_clean

override_dh_fixperms:
	dh_fixperms
	chmod 0644 debian/lomiri-keyboard-bengali-avro/usr/lib/lomiri-keyboard/plugins/bn-avro/data/regex.json

override_dh_install:
	dh_install
	rm -fv  debian/tmp/usr/bin/ut_*
	rm -Rfv debian/tmp/usr/share/maliit/tests/lomiri-keyboard/*

get-orig-source:
	uscan --noconf --force-download --rename --download-current-version --destdir=..
