#!/usr/bin/make -f
# (c) 1998-2025 Roland Rosenfeld <roland@debian.org>

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

DROOT=`pwd`/debian/lbdb
EROOT=`pwd`/debian/elpa-lbdb

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --with elpa

override_dh_autoreconf:
#	preserve files overwritten by dh_autoreconf:
	tar cf debian/autoreconf.tar aclocal.m4 configure install-sh
	dh_autoreconf

override_dh_auto_configure:
	env SH=/bin/sh MAWK=/usr/bin/awk \
		./configure --prefix=/usr --libdir='$${prefix}/lib/lbdb' \
			--libexecdir='$${prefix}/libexec/lbdb' \
			--mandir='$${prefix}/share/man' --sysconfdir=/etc \
			--enable-lbdb-dotlock \
			--with-finger=/usr/bin/finger \
			--with-abook=/usr/bin/abook \
			--with-goobook=/usr/bin/goobook \
			--with-addr-email=/usr/bin/addr-email \
			--with-ypcat=/usr/bin/ypcat \
			--with-getent=/usr/bin/getent \
			--with-gpg=/usr/bin/gpg \
			--with-pgpk=/usr/bin/pgpk \
			--with-pgp=/usr/bin/pgp \
			--with-evolution-addressbook-export=auto \
			--with-khard=/usr/bin/khard \
			--with-mu=/usr/bin/mu

override_dh_auto_install:
	$(MAKE) install_prefix=$(DROOT) install

#	move from lbdb to elpa-lbdb, but not on binary-arch target:
	if [ -d $(EROOT)/usr/lib/lbdb/ ]; then \
	   mv $(DROOT)/usr/lib/lbdb/lbdb_bbdb_query.el $(EROOT)/usr/lib/lbdb/;\
	   rmdir $(DROOT)/usr/lib/lbdb;\
	else \
	   rm -f $(DROOT)/usr/lib/lbdb/lbdb_bbdb_query.el;\
	fi
	if [ -d $(EROOT)/usr/libexec/lbdb/ ]; then \
	   mv $(DROOT)/usr/libexec/lbdb/m_bbdb $(EROOT)/usr/libexec/lbdb/;\
	else \
	   rm -f $(DROOT)/usr/libexec/lbdb/m_bbdb;\
	fi

override_dh_elpa_test:
#	reenable dh_auto_test (this is usually otherwise by dh-elpa)
	dh_elpa_test
	dh_auto_test

override_dh_clean:
	dh_clean

#	restore files overwritten by dh_autoreconf:
	[ ! -f debian/autoreconf.tar ] || tar xf debian/autoreconf.tar
	rm -f debian/autoreconf.tar