-export DH_COMPAT = 4
-
-build:
- rm -rf deb-build deb-noadns build; mkdir deb-build deb-noadns
- cd deb-build; ../configure \
- --with-adns \
- --prefix=/usr \
- --mandir=/usr/share/man \
- --libexecdir=/usr/lib
- make -C deb-build
- make -C deb-build check
- cd deb-noadns; ../configure \
- --without-adns \
- --prefix=/usr \
- --mandir=/usr/share/man \
- --libexecdir=/usr/lib
- make -C deb-noadns
- make -C deb-noadns check
- touch build
-
-clean:
- dh_clean
- rm -rf deb-build deb-noadns build
-
-install: build
- dh_clean
- make -C deb-noadns install DESTDIR=`pwd`/debian/mlib2
- mkdir -p debian/mlib-dev/usr/lib
- mkdir -p debian/mlib-dev/usr/share/man
- mkdir -p debian/mlib-dev/usr/bin
- mkdir -p debian/mlib-dev/usr/lib/pkgconfig
- mv debian/mlib2/usr/lib/pkgconfig/mLib.pc \
- debian/mlib-dev/usr/lib/pkgconfig/
- mv debian/mlib2/usr/share/man/man3 debian/mlib-dev/usr/share/man
- mv debian/mlib2/usr/lib/*.a debian/mlib-dev/usr/lib
- mv debian/mlib2/usr/lib/*.so debian/mlib-dev/usr/lib
- mv debian/mlib2/usr/lib/*.la debian/mlib-dev/usr/lib
- mv debian/mlib2/usr/include debian/mlib-dev/usr
- mkdir -p debian/mlib-bin/usr/share/man
- mv debian/mlib2/usr/bin debian/mlib-bin/usr
- mv debian/mlib2/usr/share/man/man1 debian/mlib-bin/usr/share/man
- make -C deb-build install DESTDIR=`pwd`/debian/mlib2-adns
- rmdir debian/mlib2-adns/usr/lib/mLib
- rm -rf debian/mlib2-adns/usr/bin
- rm -rf debian/mlib2-adns/usr/lib/pkgconfig
- rm -rf debian/mlib2-adns/usr/share/man
- rm -rf debian/mlib2-adns/usr/include
- rm debian/mlib2-adns/usr/lib/*.a
- rm debian/mlib2-adns/usr/lib/*.so
- rm debian/mlib2-adns/usr/lib/*.la
- dh_strip -a
-
-binary-indep:
-
-binary-arch: install
- dh_testdir -a
- dh_testroot -a
- dh_makeshlibs -a -V"mlib2 (>= 2.0.3) | mlib2-adns (>= 2.0.3)"
- dh_installman -a
- dh_compress -a
- dh_installdocs -a
- dh_strip -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)
+
+## Check that the shared-library symbols are plausible.
+override_dh_makeshlibs:
+ dh_makeshlibs -- -c4
+
+###----- That's all, folks --------------------------------------------------