#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

SHELL=/bin/bash -O extglob

export DEB_BUILD_MAINT_OPTIONS=hardening=+all optimize=+lto

# LP: 1636781 - strip incompatible default linker option
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
  export DEB_LDFLAGS_MAINT_STRIP = -Wl,-Bsymbolic-functions
endif

# Macros to help move files to the module packages
VERSION_FULL = $(shell head -1 debian/changelog |sed -e 's/.* (\(.*\)) .*/\1/g')
VERSION_SHORT= $(shell echo $(VERSION_FULL)|sed -e 's/.*\:\(.*\)\-.*/\1/g')
export VERSION=$(shell echo $(VERSION_FULL)|sed -e 's/.*\:\(.*\)/\1/g')

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
	        --with-dovecot=/usr/lib/dovecot \
		--prefix=/usr \
		--sysconfdir=/etc \
		--libexecdir=\$${prefix}/lib \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--disable-static \
		--with-ldap=plugin \
		--with-retpoline=thunk-inline \
		--with-unfinished-features

override_dh_auto_build:
	dh_auto_build --parallel

override_dh_install:
	mkdir -p debian/tmp/usr/share/dovecot-pigeonhole
	grep PIGEONHOLE_ABI_VERSION pigeonhole-config.h \
		| perl -ne '/"(.+)"/ && print $$1' \
		| tr '[A-Z]' '[a-z]' > debian/tmp/usr/share/dovecot-pigeonhole/dovecot-pigeonhole-abi
	dh_install

override_dh_gencontrol:
	dh_gencontrol -- -Vdovecot-pigeonhole:ABI-Version=$(shell cat debian/tmp/usr/share/dovecot-pigeonhole/dovecot-pigeonhole-abi)

override_dh_strip:
	dh_strip --dbg-package=dovecot-pigeonhole-dbg

override_dh_makeshlibs:
	# Do not add an ldconfig trigger; none of the dovecot shared libraries
	# are public.
	dh_makeshlibs -n
