#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/buildvars.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/class/gnome.mk
include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/rules/autoreconf.mk
include /usr/share/gnome-pkg-tools/1/rules/gnome-get-source.mk
include /usr/share/gnome-pkg-tools/1/rules/gnome-version.mk

DEB_SHLIBDEPS_INCLUDE += debian/tmp/usr/lib
DEB_DH_AUTORECONF_ARGS = --as-needed

LIBCAMEL := $(shell grep '^Package: libcamel-' debian/control | awk '{ print $$2 }')

DEB_DH_MAKESHLIBS_ARGS_ALL += -V
DEB_DH_MAKESHLIBS_ARGS_$(LIBCAMEL) = -V'$(LIBCAMEL) (>= $(DEB_GNOME_VERSION)), $(LIBCAMEL) (<< $(DEB_GNOME_NEXTVERSION))'

DEB_DH_INSTALL_ARGS = --fail-missing -X.la

# We can't add -- -c4 above as libcamel will get "-V -- -c4 -V'...'" because
# it gets $(_ALL) first and then $(_libcamel). So use the env variable.
export DPKG_GENSYMBOLS_CHECK_LEVEL=4

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
DEB_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

#ifeq ($(DEB_HOST_ARCH_OS),linux)
#	DEB_CONFIGURE_EXTRA_FLAGS += --with-phonenumber=/usr
#endif

DEB_CONFIGURE_EXTRA_FLAGS += \
	--sysconfdir=/etc \
	--libexecdir=\$${prefix}/lib/evolution \
	--with-openldap \
	--with-krb5=/usr \
	--with-libdb=/usr \
	--enable-gtk \
	--enable-gtk-doc \
	--enable-goa \
	--enable-google \
	--enable-vala-bindings \
	--enable-uoa \
	$(NULL)

DEB_DH_MAKESHLIBS_ARGS_evolution-data-server += -Xusr/lib/evolution-data-server/
DEB_FIXPERMS_EXCLUDE_evolution-data-server += usr/lib/evolution/camel-lock-helper*

# don't configure with --libdir, but move the files manually, because
# /usr/lib/evolution-data-server must not change.
common-install-impl::
	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
	mv debian/tmp/usr/lib/*.so debian/tmp/usr/lib/*.so.* debian/tmp/usr/lib/girepository-1.0 \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
	mv debian/tmp/usr/lib/pkgconfig/lib* debian/tmp/usr/lib/pkgconfig/camel* \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
	

binary-install/evolution-data-server::
	chgrp mail $(CURDIR)/debian/evolution-data-server/usr/lib/evolution/camel-lock-helper*
	chmod g+s $(CURDIR)/debian/evolution-data-server/usr/lib/evolution/camel-lock-helper*
	chrpath -d -k $(CURDIR)/debian/evolution-data-server/usr/lib/evolution-data-server/*/*.so \
		$(CURDIR)/debian/evolution-data-server/usr/lib/evolution/camel*1.2
	rm $(CURDIR)/debian/tmp/usr/lib/evolution-data-server/*/*.la
	rm $(CURDIR)/debian/tmp/usr/lib/*.la
