#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
TMP := $(CURDIR)/debian/tmp

MANUAL =
ifneq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
  MANUAL = --disable-manual
endif

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
		--enable-ipv6 \
		--enable-ldap \
		--with-config-dir=.claws-mail $(MANUAL)

override_dh_clean:
	$(MAKE) -C debian/manpages clean
	rm -f src/plugins/perl/tools/matcherrc2perlfilter
	dh_clean

override_dh_auto_build:
	$(MAKE) -C debian/manpages
	pod2man --center="claws-mail-perl-filter" \
		--release="$(DEB_VERSION)" src/plugins/perl/cm_perl.pod \
		> debian/manpages/claws-mail-perl-filter.1
	cp -p src/plugins/perl/tools/matcherrc2perlfilter.pl \
		src/plugins/perl/tools/matcherrc2perlfilter
	dh_auto_build

override_dh_compress:
	dh_compress -Xclaws-mail/tools

override_dh_installdocs-arch:
ifeq (,$(MANUAL))
	dh_installdocs --arch -A
else
	dh_installdocs --arch -A -Xclaws-mail-doc
endif

override_dh_installdocs-indep:
ifeq (,$(MANUAL))
	dh_installdocs --indep -A
else
	dh_installdocs --indep -A -Xclaws-mail-doc
endif

override_dh_install:
ifneq (,$(MANUAL))
	mkdir -p $(TMP)/usr/share/doc/claws-mail/manual
	echo "Package built with 'nodoc' option" \
		> $(TMP)/usr/share/doc/claws-mail/manual/INFO
endif
	dh_install
