-build:
- rm -rf deb-build build; mkdir deb-build
- cd deb-build; ../configure \
- --prefix=/usr \
- --mandir=/usr/share/man \
- --libexecdir=/usr/lib
- make -C deb-build
- make -C deb-build check
- touch build
-
-clean:
- dh_clean
- rm -rf deb-build build
-
-install: build
- dh_clean
- make -C deb-build install DESTDIR=`pwd`/debian/tmp
- rm -f debian/tmp/usr/lib/*.la
- mkdir -p debian/mlib-dev/usr/lib
- mkdir -p debian/mlib-dev/usr/share/man
- mkdir -p debian/mlib-dev/usr/bin
- mv debian/tmp/usr/bin/mLib-config debian/mlib-dev/usr/bin
- mv debian/tmp/usr/share/man/man3 debian/mlib-dev/usr/share/man
- mv debian/tmp/usr/lib/*.a debian/mlib-dev/usr/lib
- mv debian/tmp/usr/lib/*.so debian/mlib-dev/usr/lib
- mv debian/tmp/usr/include debian/mlib-dev/usr
- dh_strip -a
-
-binary-indep:
-
-binary-arch: install
- dh_testdir -a
- dh_testroot -a
- dh_makeshlibs -a
- dh_installman -a
- dh_compress -a
- dh_installdocs -a
- dh_shlibdeps -a
- dh_gencontrol -a
- dh_fixperms -a
- dh_installdeb -a
- dh_md5sums -a
- dh_builddeb -a
-
-binary: binary-indep binary-arch
-
-source:
- rm -rf deb-build/*.tar.gz deb-build/=deb=
- make -C deb-build dist PACKAGE=mlib
- mkdir deb-build/=deb=
- cd deb-build/=deb=; tar xvfz ../*.tar.gz
- d=`pwd`; cd ..; dpkg-source -i -b $$d/deb-build/=deb=/*
- rm -rf deb-build/=deb=
-
-.PHONY: binary binary-arch binary-indep clean install source
+###--------------------------------------------------------------------------
+### Preliminary definitions.
+
+## The multiarch triple.
+DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
+a := $(DEB_HOST_MULTIARCH)
+
+## My version number, shorn of the Debian package version if any.
+DEB_UPSTREAM_VERSION ?= \
+ $(shell dpkg-parsechangelog | \
+ sed -n "/^Version: \([^-]*\)\(-.*\)\?/s//\1/p")
+v := $(DEB_UPSTREAM_VERSION)
+
+## Default Debhelper options.
+DH_OPTIONS = --parallel
+
+## Default Debhelper actions.
+%:; dh $@ $(DH_OPTIONS)
+
+###--------------------------------------------------------------------------
+### Multiple flavours.
+
+## The various flavours of the library which we must build.
+FLAVOURS = noadns adns
+
+## The build actions which we have to override.
+DH_BUILD_OVERRIDES = configure clean build install test
+
+## How to perform build action for a particular library flavour.
+define flavour-build-action
+dh_auto_$1 -Bdebian/build-$2 \
+ $(DH_OPTIONS) $(DH_OPTIONS_$2) \
+ $(DH_$1_OPTIONS) $(DH_$1_OPTIONS_$2)
+
+endef
+
+## Override the build actions, and perform the relevant action for each
+## flavour in turn.
+$(foreach t, $(DH_BUILD_OVERRIDES), dh-$t-hook):: %:; @:
+$(foreach t, $(DH_BUILD_OVERRIDES), override_dh_auto_$t): \
+ override_dh_auto_%: dh-%-hook
+ $(foreach f, $(FLAVOURS), $(call flavour-build-action,$*,$f))
+
+## Configuration options.
+DH_configure_OPTIONS = -- --libexecdir='$${libdir}'
+DH_configure_OPTIONS_noadns = --without-adns
+DH_configure_OPTIONS_adns = --with-adns
+
+## Cleaning options.
+dh-clean-hook::
+ rm -rf debian/tmp-adns
+
+## Installation options.
+DH_install_OPTIONS_adns = --destdir=debian/tmp-adns
+
+###--------------------------------------------------------------------------
+### Additional tweaks.
+
+## Some of the install lists need to be generated. This is a little
+## annoying.
+GEN_INSTALL_PKGS = mlib2-adns
+GEN_INSTALL_FILES = $(foreach p, $(GEN_INSTALL_PKGS), debian/$p.install)
+$(GEN_INSTALL_FILES): debian/%.install: \
+ debian/%.install.in debian/changelog debian/rules
+ sed 's,@ARCH@,$a,g' $< >$@.new && mv $@.new $@
+dh-install-hook:: $(GEN_INSTALL_FILES); @:
+dh-clean-hook::
+ rm -f $(GEN_INSTALL_FILES)
+
+## Override the shared-library dependency information to allow any flavour.
+override_dh_makeshlibs:
+ dh_makeshlibs -V"mlib2 (>= $v) | mlib2-adns (>= $v)"
+
+###----- That's all, folks --------------------------------------------------