#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

DEB_CONFIGURE_EXTRA_FLAGS := --libdir=/usr/lib --enable-purple --disable-telepathy --with-vv --enable-openssl=no
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
# Disable compiler warning flags on armel and armhf due to
# sipe-core-private.h:238:28: error: cast increases required alignment of target type [-Werror=cast-align]
#  238 | #define SIPE_CORE_PRIVATE ((struct sipe_core_private *)sipe_public)
ifeq ($(DEB_HOST_ARCH),armel)
	DEB_CONFIGURE_EXTRA_FLAGS += --disable-quality-check
else ifeq ($(DEB_HOST_ARCH),armhf)
	DEB_CONFIGURE_EXTRA_FLAGS += --disable-quality-check
endif

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

override_dh_auto_configure:
	./autogen.sh
	dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS)

override_dh_auto_install:
	dh_auto_install

	find debian/pidgin-sipe -name *.la -delete

override_dh_installdocs:
	dh_installdocs --link-doc=pidgin-sipe

override_dh_auto_clean:
	# Preserve pot file from being deleted as it's a part of orig tarball.
	mv po/pidgin-sipe.pot po/pidgin-sipe.pot.keep
	dh_auto_clean
	mv po/pidgin-sipe.pot.keep po/pidgin-sipe.pot

	rm -f GITVERSION INSTALL aclocal.m4 compile config.guess config.h.in config.sub configure \
		depcomp install-sh intltool-extract.in intltool-merge.in intltool-update.in ltmain.sh \
		missing test-driver
	find -type f -name Makefile.in\* -delete

.PHONY: override_dh_auto_configure override_dh_auto_install override_dh_installdocs override_dh_auto_clean
