#!/usr/bin/make -f

DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
EXACT_PACKAGE_VERSION = $(shell dpkg-parsechangelog | grep Version | cut -d' ' -f 2)

export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

%:
	dh $@ --parallel --fail-missing

#overrding dh_auto_test to get rid of --parallel during testing
override_dh_auto_test:
	GTEST_OUTPUT=xml:./ dh_auto_test --max-parallel=1

COMMON_CONFIGURE_OPTIONS = \
  -DBUILD_DOXYGEN=YES \
  -DCMAKE_INSTALL_LIBEXECDIR="lib/$(DEB_HOST_MULTIARCH)/mir"

override_dh_auto_configure:
ifeq ($(DEB_HOST_ARCH),armhf)
	dh_auto_configure -- \
	  $(COMMON_CONFIGURE_OPTIONS) \
	  -DMIR_RUN_ACCEPTANCE_TESTS=OFF \
	  -DMIR_RUN_INTEGRATION_TESTS=OFF \
	  -DMIR_PLATFORM=android\;mesa
else
ifeq ($(DEB_HOST_ARCH),arm64)
	dh_auto_configure -- \
	  $(COMMON_CONFIGURE_OPTIONS) \
	  -DMIR_PLATFORM=mesa
else
	dh_auto_configure -- \
	  $(COMMON_CONFIGURE_OPTIONS) \
	  -DMIR_PLATFORM=mesa\;android
endif
endif

# TODO: we'll use a symbol file once mir is abi stable
override_dh_makeshlibs:
	dh_makeshlibs -V

override_dh_install:
	dh_install --fail-missing \
	  -Xusr/lib/$(DEB_HOST_MULTIARCH)/libmirplatformgraphics.so \
	  -Xusr/lib/$(DEB_HOST_MULTIARCH)/libmirclientplatform.so
	sh debian/install_ld_so_conf.sh $(DEB_HOST_MULTIARCH)

override_dh_installdeb:
	sh debian/create_postinst_prerm_scripts.sh $(DEB_HOST_MULTIARCH)
	dh_installdeb
