#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)

# Build-deps not available on these archs
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
ifeq (,$(filter $(DEB_BUILD_ARCH), hurd-i386 kfreebsd-amd64 kfreebsd-i386))
    UNBOUND = --with-unbound
else
    UNBOUND =
endif

ifeq (,$(filter $(DEB_BUILD_ARCH), hurd-i386))
    ODBX = --with-odbx
else
    ODBX =
endif


override_dh_auto_configure:
	dh_testdir
	CONFIG_SHELL=/bin/sh  ./configure $(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info \
		--sysconfdir=/etc \
		CFLAGS="$(CFLAGS) $(CPPFLAGS)" \
		LDFLAGS="$(LDFLAGS) -Wl,-z,defs -L/usr/lib/libmilter" \
		--disable-live-testing \
		--enable-vbr \
		--enable-rbl \
		--enable-atps \
		--enable-stats \
		--enable-replace_rules \
		--enable-query_cache \
		--with-libmemcached \
		--with-openldap \
		--with-db \
		--with-sql-backend \
		--with-sasl \
		--with-domain=localhost \
		--with-lua \
		--enable-sender_macro \
		$(UNBOUND) \
		$(ODBX)

#ifneq (,$(filter $(DEB_HOST_ARCH), mips mipsel))
#override_dh_auto_test:
#	MILTERTEST_RETRY_SPEED_FACTOR=20 dh_auto_test
#endif

# test results on kfreebsd-* are inconsistent, but not due to package bugs.
#ifneq (,$(filter $(DEB_HOST_ARCH), kfreebsd-i386 kfreebsd-amd64))
override_dh_auto_test:
#endif

override_dh_install:
	dh_install
	mv $(CURDIR)/debian/opendkim-tools/usr/bin/convert_keylist.sh \
		 $(CURDIR)/debian/opendkim-tools/usr/bin/opendkim-convert-keylist

override_dh_installchangelogs:
	dh_installchangelogs RELEASE_NOTES

override_dh_installdocs:
	dh_installdocs
	cp opendkim/README $(CURDIR)/debian/opendkim/usr/share/doc/opendkim/

override_dh_auto_clean:
	dh_auto_clean
	rm -f $(CURDIR)/opendkim/tests/*.sock

