#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# examples/Makefile is autogenerated before being shipped; we want to
# make sure it picks a standard shell for reproducibility
export CONFIG_SHELL = /bin/sh

# only invoke dh --with=cli if cli-common-dev is present
ifeq (,$(wildcard /usr/share/perl5/Debian/Debhelper/Sequence/cli.pm))
WITH_CLI =
CONFIGURE_MONO_FLAGS = --enable-mono=no
else
WITH_CLI = ,cli
CONFIGURE_MONO_FLAGS = CSC=/usr/bin/mono-csc
endif

override_dh_auto_configure:
	dh_auto_configure -- \
		$(shell dpkg-buildflags --export=configure) \
		--enable-vala \
		--enable-gtk-doc \
		--disable-rpath \
		--enable-largefile \
		--enable-smime \
		--enable-introspection \
		$(CONFIGURE_MONO_FLAGS)

# https://bugs.debian.org/806033 -- dh_clideps expects to see
# dh_makeshlibs called before it, but dh_makeshlibs is never called
# when building only arch-indep packages.  So we force the issue by
# making a phony shlibs.local file that dh_clideps will accept, if no
# others exist:
override_dh_clideps:
	if ! grep -q . debian/*/DEBIAN/shlibs; then echo libgmime-2.6 0 libgmime-2.6-0 > debian/shlibs.local; fi
	dh_clideps
	rm -f debian/shlibs.local

override_dh_auto_build-indep:
	dh_auto_build
	mdoc update -o $(CURDIR)/mono/monodocer $(CURDIR)/mono/gmime-sharp.dll
	mdoc assemble -o $(CURDIR)/mono/gmime-sharp-2.6 $(CURDIR)/mono/monodocer

%:
	dh $@ --with=autoreconf,gir$(WITH_CLI)
