#!/usr/bin/make -f
# (c) 1998-2018  Roland Rosenfeld <roland@debian.org>
# Based on sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.

# 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_auto_configure:
	env SH=/bin/sh MAWK=/usr/bin/awk \
		./configure --prefix=/usr --libdir='$${prefix}/lib/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/;\
	   mv $(DROOT)/usr/lib/lbdb/m_bbdb $(EROOT)/usr/lib/lbdb/;\
	else \
	   rm -f $(DROOT)/usr/lib/lbdb/lbdb_bbdb_query.el;\
	   rm -f $(DROOT)/usr/lib/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
