-export LC_ALL=C
-include debian/scripts/vars
-
-BUILD_DIR := $(SOURCE_DIR)/$(TAR_DIR)
-B := $(BUILD_DIR)
-D := $(CURDIR)/debian/mutt
-
-# Comment this line if you want the header cache with qdbm or gdbm
-HCACHE_WITH_DB := --without-qdbm --without-gdbm
-
-clean:
- $(MAKE) -f debian/sys-build.mk source.clean
+include /usr/share/quilt/quilt.make
+
+###################### user serviceable parts ######################
+
+###
+# build a separate mutt-patched package?
+BUILD_PATCHED := yes
+###
+# header cache backend
+# HCACHE_DB := bdb
+HCACHE_DB := gdbm
+# HCACHE_DB := qdbm
+###
+# GPGME backend
+GPGME := --enable-gpgme
+###
+
+###################### variables ######################
+
+ifneq ($(BUILD_PATCHED),yes)
+export DH_OPTIONS := -Nmutt-patched
+endif
+
+# Configure arguments
+
+ifeq ($(HCACHE_DB),bdb)
+ hcache_db := --without-gdbm --without-qdbm --without-tokyocabinet
+endif
+ifeq ($(HCACHE_DB),gdbm)
+ hcache_db := --without-qdbm --without-bdb --without-tokyocabinet
+endif
+ifeq ($(HCACHE_DB),qdbm)
+ hcache_db := --without-gdbm --without-bdb --without-tokyocabinet
+endif
+
+confflags = --prefix=/usr \
+ --sysconfdir=/etc \
+ --mandir=/usr/share/man \
+ --with-sharedir=/usr/share/mutt \
+ --with-docdir=/usr/share/doc \
+ --with-mailpath=/var/mail \
+ \
+ --disable-dependency-tracking \
+ \
+ --enable-compressed \
+ --enable-debug \
+ --enable-fcntl \
+ --enable-hcache \
+ $(GPGME) \
+ --enable-imap \
+ --enable-smtp \
+ --enable-inodesort \
+ --enable-pop \
+ \
+ --with-curses \
+ --with-gnutls \
+ --with-gss \
+ --with-idn \
+ --with-mixmaster \
+ --with-sasl \
+ \
+ $(hcache_db)
+
+DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+confflags += --build $(DEB_BUILD_GNU_TYPE)
+# Only specify --host when cross-compiling
+ifneq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
+ confflags += --host $(DEB_HOST_GNU_TYPE)
+endif
+
+# CFLAGS
+CFLAGS = -Wall -g
+CPPFLAGS = -I/usr/include/qdbm
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+
+# Directory to make the build on
+objdir = $(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)
+
+###################### main ######################
+
+$(objdir)-patched/build-stamp: $(QUILT_STAMPFN)
+ dh_testdir