debian: convert to use build profile rules exclusively

This commit drops support for the debian/rules.custom file, and only
relies on build profiles.

This means we no longer need to build the control file from
control.in, which simplifies this; developers can now build a debian
package immediately after checking out the tree from git.  This also
implies that we are dropping support for Debian 7 (wheezy) and Ubuntu
Trusty (14.04LTS) and older releases.  (People who want to backport to
these older distributions will have to make manual adjustments to the
debian/control and debian/rules files.)

Instead of using SKIP_E2FSCK_STATIC in debian/rules.custom, use the
new build profile: pkg.e2fsprogs.no-static-e2fsck

Support for the old-style *-dbg files used in Debian Jessie (which did
not support dbgsym packages) is completely automated.  The system will
auto-detect systems which do not support dbgsym and automatically set
the pkg.e2fsprogs.legacy-pkg build profile.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
diff --git a/debian/control.in b/debian/control
similarity index 95%
rename from debian/control.in
rename to debian/control
index d03756e..2a96a1f 100644
--- a/debian/control.in
+++ b/debian/control
@@ -16,8 +16,8 @@
  writing from devices or image files containing ext2, ext3, and ext4
  file systems.
 
-ifdef(`E2FSCK_STATIC',``
 Package: e2fsck-static
+Build-Profiles: <!pkg.e2fsprogs.no-static-e2fsck>
 Priority: optional
 Depends: ${misc:Depends}
 Recommends: sash | bash-static | zsh-static | busybox-static
@@ -31,7 +31,6 @@
  .
  You may want to install a statically-linked shell as well, to be able
  to run this program if something like your C library gets corrupted.
-'')dnl
 
 Package: e2fsprogs-l10n
 Section: localization
@@ -107,7 +106,6 @@
  .
  This package contains the development environment for the ss library.
 
-ifdef(`UDEB_PKGS',``
 Package: e2fsprogs-udeb
 Build-Profiles: <!noudeb>
 Package-Type: udeb
@@ -119,9 +117,8 @@
  This package is an e2fsprogs package built for a reduced size, so that
  it can help to save space in debian-installer.
  .
- Don'''``t attempt to install this package, it has no support for a couple of
+ Don't attempt to install this package, it has no support for a couple of
  features you surely want.  Anyway it should refuse to install.
-'')dnl
 
 Package: e2fslibs
 Section: libs
@@ -173,8 +170,9 @@
  This package contains programs for creating, checking, and maintaining
  ext2/3/4-based file systems.  It also includes the "badblocks" program,
  which can be used to scan for bad blocks on a disk or other storage device.
-ifdef(`USE_DBGSYM',,``
+
 Package: e2fsprogs-dbg
+Build-Profiles: <pkg.e2fsprogs.legacy-dbg>
 Section: debug
 Priority: extra
 Depends: e2fsprogs (= ${binary:Version}), ${misc:Depends}
@@ -186,6 +184,7 @@
  dump analysis.
 
 Package: e2fslibs-dbg
+Build-Profiles: <pkg.e2fsprogs.legacy-dbg>
 Section: debug
 Priority: extra
 Depends: e2fslibs (= ${binary:Version}), ${misc:Depends}
@@ -196,6 +195,7 @@
  information is used for execution tracing and core dump analysis.
 
 Package: libcomerr2-dbg
+Build-Profiles: <pkg.e2fsprogs.legacy-dbg>
 Section: debug
 Priority: extra
 Depends: libcomerr2 (= ${binary:Version}), ${misc:Depends}
@@ -206,6 +206,7 @@
  information is used for execution tracing and core dump analysis.
 
 Package: libss2-dbg
+Build-Profiles: <pkg.e2fsprogs.legacy-dbg>
 Section: debug
 Priority: extra
 Depends: libss2 (= ${binary:Version}), ${misc:Depends}
@@ -214,4 +215,3 @@
  This package includes the debug information useful for debugging the
  ss library, contained in the libss2 package.  The debug information
  is used for execution tracing and core dump analysis.
-'')dnl
diff --git a/debian/rules b/debian/rules
index 2bdcbcc..e44422c 100755
--- a/debian/rules
+++ b/debian/rules
@@ -7,8 +7,6 @@
 # The `binary' target must be run as root, as it needs to install files with
 # specific ownerships.
 
--include debian/rules.custom
-
 .PHONY: binary binary-arch binary-indep build build-arch build-indep \
 	build-bf build-std install install-udeb \
 	clean checkroot mrproper debug_flags debian-files
@@ -39,6 +37,10 @@
 SKIP_FUSE2FS=yes
 endif
 
+ifneq ($(filter pkg.e2fsprogs.no-static-e2fsck,$(DEB_BUILD_PROFILES)),)
+SKIP_E2FSCK_STATIC=yes
+endif
+
 ifneq ($(filter noudeb,$(DEB_BUILD_PROFILES)),)
 SKIP_UDEB=yes
 endif
@@ -54,7 +56,10 @@
 else
 dh_strip_args = -p$(1) --dbg-package=$(1)-dbg
 dh_strip_args2 = -p$(1) --dbg-package=$(2)-dbg
+DBG_PACKAGES += -pe2fsprogs-dbg -pe2fslibs-dbg -plibcomerr2-dbg -plibss2-dbg
+export DEB_BUILD_PROFILES += pkg.e2fsprogs.legacy-dbg
 endif
+
 # find the version for the main package, from changelog file
 MAIN_VERSION = $(shell head -n 1 debian/changelog | cut '-d ' -f 2 | sed 's/[()]//g')
 # find versions for libraries going into their own packages, from their Makefile.in's,
@@ -91,7 +96,7 @@
 mandir		?= ${tmpdir}${MANDIR}
 
 UDEB_NAME 	?= $(package)-udeb_$(MAIN_VERSION)_$(DEB_HOST_ARCH).udeb
-UDEB_PRIORITY	?= $(shell grep '^Package: e2fsprogs-udeb' debian/control.in -A 10 | grep ^Priority: | cut -d ' ' -f 2)
+UDEB_PRIORITY	?= $(shell grep '^Package: e2fsprogs-udeb' debian/control -A 10 | grep ^Priority: | cut -d ' ' -f 2)
 
 STAMPSDIR	?= debian/stampdir
 CFGSTDSTAMP	?= ${STAMPSDIR}/configure-std-stamp
@@ -170,36 +175,15 @@
 	--disable-testio-debug --disable-uuidd --disable-tls \
 	--disable-tdb --disable-debugfs
 
-M4_ARGS=
 DBG_PACKAGES=
 
-ifeq ($(USE_DBGSYM),yes)
-M4_ARGS+=-DUSE_DBGSYM
-else
-DBG_PACKAGES += -pe2fsprogs-dbg -pe2fslibs-dbg -plibcomerr2-dbg -plibss2-dbg
-M4_ARGS+=-UUSE_DBGSYM
-endif
-
-ifneq ($(BUILD_E2FSCK_STATIC),no)
-M4_ARGS+=-DE2FSCK_STATIC
-else
-M4_ARGS+=-UE2FSCK_STATIC
-endif
-
 ifeq ($(SKIP_UDEB),)
 INSTALL_UDEB = install-udeb
-M4_ARGS+=-DUDEB_PKGS
-else
-M4_ARGS+=-UUDEB_PKGS
 endif
 
-debian-files: debian/control
+debian-files:
 
 mrproper: clean
-	rm debian/control
-
-debian/control: debian/control.in debian/rules
-	m4 $(M4_ARGS) < debian/control.in | grep -v ^REMOVE_ME$$ > $@
 
 ${CFGSTDSTAMP}:
 	dh_testdir
@@ -273,7 +257,7 @@
 ${BUILDSTDSTAMP}: ${CFGSTDSTAMP}
 	dh_testdir
 	$(MAKE) -C ${stdbuilddir} V=1 all
-ifneq ($(BUILD_E2FSCK_STATIC),no)
+ifneq ($(SKIP_E2FSCK_STATIC),yes)
 	$(MAKE) -C ${stdbuilddir}/e2fsck V=1 e2fsck.static
 endif
 	if ! test -d debian/orig-gmo ; then \
@@ -324,7 +308,7 @@
   # static libs and .h files
 	$(MAKE) -C ${stdbuilddir} V=1 install-libs DESTDIR=${tmpdir} LDCONFIG=true
 
-ifneq ($(BUILD_E2FSCK_STATIC),no)
+ifneq ($(SKIP_E2FSCK_STATIC),yes)
   # statically-linked fsck
 	${INSTALL_PROGRAM} $(E2FSCK_STATIC) ${tmpdir}/sbin
 	cp ${mandir}/man8/e2fsck.8 ${mandir}/man8/e2fsck.static.8
@@ -424,7 +408,7 @@
 	dh_installchangelogs -a
 	dh_fixperms -a
 	dh_strip $(call dh_strip_args,e2fsprogs)
-ifneq ($(BUILD_E2FSCK_STATIC),no)
+ifneq ($(SKIP_E2FSCK_STATIC),yes)
 	dh_strip $(call dh_strip_args2,e2fsck-static,e2fsprogs)
 endif
 	dh_strip $(call dh_strip_args,e2fslibs)