#!/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

include /usr/share/dpkg/default.mk

# Explicitly selecting a G{CC,++}-version here to avoid accidental
# ABI breaks introduced by toolchain updates.
export CC=$(DEB_HOST_GNU_TYPE)-gcc-4.9
export CXX=$(DEB_HOST_GNU_TYPE)-g++-4.9

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

# Enable verbose debugging output from the testsuite
export MIR_SERVER_LOGGING = on
override_dh_auto_test:
ifneq ($(DEB_HOST_ARCH),powerpc)
	GTEST_OUTPUT=xml:./ dh_auto_test --max-parallel=1 -- ARGS="-V"
else
	echo "Testsuite disabled on powerpc due to lack of big-endian support."
endif

COMMON_CONFIGURE_OPTIONS = \
  -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
ifneq ($(filter arm64 powerpc ppc64el,$(DEB_HOST_ARCH)),)
	dh_auto_configure -- \
	  $(COMMON_CONFIGURE_OPTIONS) \
	  -DMIR_PLATFORM=mesa
else
	dh_auto_configure -- \
	  $(COMMON_CONFIGURE_OPTIONS) \
	  -DMIR_PLATFORM=mesa\;android
endif
endif

# Only build the docs when we need them
override_dh_auto_build-indep:
	dh_auto_build -- doc

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

override_dh_install:
# Nothing outside Mir should link to libmirprotobuf directly.
# Delete the symlink so that --fail-missing doesn't think we've missed it
# accidentally.
	-rm debian/tmp/usr/lib/*/libmirprotobuf.so
	dh_install --fail-missing
