#!/usr/bin/make -f
include /usr/share/gnome-pkg-tools/1/rules/gnome-get-source.mk
include /usr/share/gnome-pkg-tools/1/rules/gnome-version.mk
include /usr/share/dpkg/default.mk

export DEB_LDFLAGS_MAINT_APPEND = -Wl,-z,defs -Wl,--as-needed -Wl,-O1
# see https://bugzilla.gnome.org/show_bug.cgi?id=594473 for details
export DEB_LDFLAGS_MAINT_STRIP = -Wl,-Bsymbolic-functions
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --with gnome

DEB_REVISION := $(shell echo $(DEB_VERSION) | awk -F- '{ print $$NF }')

override_dh_auto_configure:
	dh_auto_configure -- \
		-DLIBEXEC_INSTALL_DIR=/usr/lib \
		-DSYSCONF_INSTALL_DIR=/etc \
		-DWITH_OPENLDAP=ON \
		-DENABLE_PLUGINS=all \
		-DENABLE_PST_IMPORT=ON \
		-DENABLE_CONTACT_MAPS=ON \
		-DENABLE_AUTOAR=ON \
		-DENABLE_INSTALLED_TESTS=ON \
		-DWITH_HELP=ON \
		-DENABLE_GTK_DOC=ON \
		-DVERSION_SUBSTRING=-$(DEB_REVISION)

# installed-tests are old and require python3-behave
# which is not in Debian yet
override_dh_install:
	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
	mv debian/tmp/usr/lib/pkgconfig/*.pc \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
	dh_install --fail-missing -X.la -Xlibevolutiontestsettings.so \
		-Xusr/lib/evolution/installed-tests -Xusr/share/installed-tests
ifneq ($(filter libevolution,$(shell dh_listpackages)),)
	find debian/libevolution/ -name 'module-bogofilter.so' -delete
	find debian/libevolution/ -name 'module-spamassassin.so' -delete
endif

override_dh_makeshlibs:
	dh_makeshlibs -V'libevolution (>= $(DEB_VERSION_UPSTREAM)), libevolution (<< $(DEB_GNOME_NEXTVERSION))' -n

override_dh_strip:
	dh_strip --dbgsym-migration='evolution-dbg (<< 3.18.5.2-1~)'
