#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpkg/architecture.mk

export CFLAGS := $(shell dpkg-buildflags --get CFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
export CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed
export QT_SELECT := qt5

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- QT_BUILD_PARTS+=tests CONFIG+="lang-all handwriting"

override_dh_auto_build-indep:
	dh_auto_build -- docs

override_dh_auto_install-indep:
	dh_auto_build -- INSTALL_ROOT=$(CURDIR)/debian/tmp install_docs

override_dh_auto_install-arch:
	dh_auto_install

	# We do not ship CMake files for plugins.
	rm -vf $(CURDIR)/debian/tmp/usr/lib/*/cmake/Qt5Gui/Qt5Gui_QVirtualKeyboardPlugin.cmake

override_dh_missing:
	dh_missing --fail-missing

override_dh_auto_test-arch:
ifeq ($(DEB_HOST_ARCH_ENDIAN),little)
	LIPI_ROOT=$(CURDIR)/src/virtualkeyboard/3rdparty/lipi-toolkit LIPI_LIB=$(CURDIR)/plugins/lipi_toolkit \
	         xvfb-run -a -s "-screen 0 1024x768x24 +extension RANDR +extension RENDER +extension GLX" \
	         dh_auto_test --max-parallel=1 -- -k -Ctests/auto \
	         QT_PLUGIN_PATH=$(CURDIR) QML2_IMPORT_PATH=$(CURDIR)/qml \
	         HOME=$(CURDIR) LD_LIBRARY_PATH=$(CURDIR)/lib
else
	# Make the tests non-fatal on big endian architectures because of
	# https://bugreports.qt.io/browse/QTBUG-70833
	-LIPI_ROOT=$(CURDIR)/src/virtualkeyboard/3rdparty/lipi-toolkit LIPI_LIB=$(CURDIR)/plugins/lipi_toolkit \
	         xvfb-run -a -s "-screen 0 1024x768x24 +extension RANDR +extension RENDER +extension GLX" \
	         dh_auto_test --max-parallel=1 -- -k -Ctests/auto \
	         QT_PLUGIN_PATH=$(CURDIR) QML2_IMPORT_PATH=$(CURDIR)/qml \
	         HOME=$(CURDIR) LD_LIBRARY_PATH=$(CURDIR)/lib
endif

override_dh_clean:
	rm -f src/virtualkeyboard/layouts.qrc
	dh_clean

override_dh_auto_test-indep:
