Index: debian/rules
===================================================================
--- debian/rules	(revision 560d0a0c4cc61e8ed68a80a04491af024254684c)
+++ debian/rules	(revision 6be46b37a167031f7a6888be03c2611f0762639a)
@@ -1,104 +1,113 @@
 #!/usr/bin/make -f
-#
-# Finally switching to debhelper.
-#
-# Not using debhelper was an exercise suggested to me by my AM (Gergely
-# Nagy). It was educating at the time but I finally decided that the
-# exercise is over now.
-#
 
-BITLBEE_CONFIGURE_FLAGS ?=
 DEBUG ?= 0
 
-ifndef BITLBEE_VERSION
+ifdef BITLBEE_VERSION
+BITLBEE_FORCE_VERSION=1
+else
 # Want to use the full package version number instead of just the release.
-BITLBEE_CONFIGURE_VERSION ?= BITLBEE_VERSION=\"$(shell dpkg-parsechangelog | grep ^Version: | awk '{print $$2}')\"
+BITLBEE_VERSION ?= "$(shell dpkg-parsechangelog | grep ^Version: | awk '{print $$2}')"
+export BITLBEE_VERSION
 endif
 
-build: build-stamp
-build-stamp:
-	dh_testdir
-
-	mkdir -p debian/build-native
-	ROOT=$$PWD; cd debian/build-native; $(BITLBEE_CONFIGURE_VERSION) $$ROOT/configure --debug=$(DEBUG) --prefix=/usr --etcdir=/etc/bitlbee --events=libevent $(BITLBEE_CONFIGURE_FLAGS)
-	$(MAKE) -C debian/build-native
-
-	mkdir -p debian/build-libpurple
-	ROOT=$$PWD; cd debian/build-libpurple; $(BITLBEE_CONFIGURE_VERSION) $$ROOT/configure --debug=$(DEBUG) --prefix=/usr --etcdir=/etc/bitlbee --purple=1 $(BITLBEE_CONFIGURE_FLAGS)
-	$(MAKE) -C debian/build-libpurple
-
-	$(MAKE) -C doc
-
-	touch build-stamp
+build-arch: build-arch-stamp
+build-arch-stamp:
+	[ -d debian ]
+	./configure --debug=$(DEBUG) --prefix=/usr --etcdir=/etc/bitlbee --events=libevent
+	$(MAKE)
+#	$(MAKE) -C doc/ all
+	touch build-arch-stamp
 
 clean:
-	dh_testdir
-	dh_testroot
-	rm -f build-stamp
+	[ "`whoami`" = "root" -a -d debian ]
+	rm -rf build-arch-stamp debian/bitlbee debian/*.substvars debian/files debian/bitlbee-dev
+	$(MAKE) distclean
+#	-$(MAKE) -C doc/ clean
+				
 
-	rm -rf build-arch-stamp debian/build-*
-	$(MAKE) distclean
+install-arch: build-arch
+	[ "`whoami`" = "root" -a -d debian ]
+	mkdir -p debian/bitlbee/DEBIAN/
+	$(MAKE) install install-etc DESTDIR=`pwd`/debian/bitlbee
 
-	dh_clean
+	mkdir -p debian/bitlbee/usr/share/doc/bitlbee/
+	cp doc/user-guide/user-guide.txt debian/bitlbee/usr/share/doc/bitlbee/
+	cp doc/user-guide/user-guide.html debian/bitlbee/usr/share/doc/bitlbee/
 
-install: build
-	dh_testdir
-	dh_testroot
-	dh_clean -k
-	dh_installdirs
+install-indep: install-arch
+	[ "`whoami`" = "root" -a -d debian ]
+	mkdir -p debian/bitlbee-dev/DEBIAN/
+	$(MAKE) install-dev DESTDIR=`pwd`/debian/bitlbee-dev
 
-	$(MAKE) -C debian/build-native install install-etc DESTDIR=`pwd`/debian/bitlbee
-	$(MAKE) -C debian/build-libpurple install install-etc DESTDIR=`pwd`/debian/bitlbee-libpurple
-	$(MAKE) -C debian/build-native install-dev DESTDIR=`pwd`/debian/bitlbee-dev
+	mkdir -p debian/bitlbee-dev/usr/share/doc/bitlbee-dev/
 
-	patch debian/bitlbee/etc/bitlbee/bitlbee.conf debian/patches/bitlbee.conf.diff
-	patch debian/bitlbee-libpurple/etc/bitlbee/bitlbee.conf debian/patches/bitlbee.conf.diff
+binary-arch: build-arch install-arch
+	[ "`whoami`" = "root" -a -d debian ]
 
-	mkdir -p debian/bitlbee-common/usr
-	mv debian/bitlbee/usr/share debian/bitlbee-common/usr
-	rm -rf debian/bitlbee-libpurple/usr/share
+	chmod 755 debian/post* debian/pre* debian/config debian/bitlbee.init
 
-binary-common:
-	dh_testdir
-	dh_testroot
+	mkdir -p debian/bitlbee/usr/share/doc/bitlbee/examples/ debian/bitlbee/etc/init.d/
+	-cp doc/RELEASE-SPEECH* debian/bitlbee/usr/share/doc/bitlbee/ && gzip -9 debian/bitlbee/usr/share/doc/bitlbee/RELEASE-SPEECH*
+	cp doc/CREDITS doc/AUTHORS doc/README doc/FAQ debian/README.Debian debian/bitlbee/usr/share/doc/bitlbee/
+	cp debian/changelog debian/bitlbee/usr/share/doc/bitlbee/changelog.Debian
+	cp debian/copyright debian/bitlbee/usr/share/doc/bitlbee/copyright
+	cp doc/CHANGES debian/bitlbee/usr/share/doc/bitlbee/changelog
+	cp utils/* debian/bitlbee/usr/share/doc/bitlbee/examples/
+	cp debian/bitlbee.init debian/bitlbee/etc/init.d/bitlbee
+	patch -p0 < debian/patches/bitlbee.conf.diff
+	cd debian/bitlbee/usr/share/; \
+		gzip -9 doc/bitlbee/changelog.Debian doc/bitlbee/changelog doc/bitlbee/user-guide.txt \
+		        doc/bitlbee/examples/* man/man8/bitlbee.8 man/man5/bitlbee.conf.5
+	
+	chown -R root:root debian/bitlbee/
+	find debian/bitlbee/usr/share/ -type d -exec chmod 755 {} \;
+	find debian/bitlbee/usr/share/ -type f -exec chmod 644 {} \;
+	
+	cp debian/prerm debian/bitlbee/DEBIAN/
+	cp debian/postinst debian/bitlbee/DEBIAN/
+	cp debian/postrm debian/bitlbee/DEBIAN/
+	cp debian/config debian/bitlbee/DEBIAN/
 
-	dh_installchangelogs doc/CHANGES
-	dh_installexamples
-	dh_installdocs #--link-doc=bitlbee-common
-	# TODO: Restore --link-doc up here and remove the hack below once
-	# Hardy and Lenny are deprecated.
-	for p in bitlbee bitlbee-libpurple bitlbee-dev; do rm -rf debian/$$p/usr/share/doc/$$p; ln -s bitlbee-common debian/$$p/usr/share/doc/$$p; done
-	dh_installdebconf
-	dh_installinit
-ifeq ($(DH_OPTIONS),-a)
-	cp -a debian/bitlbee/etc debian/bitlbee-libpurple
+	po2debconf debian/templates > debian/bitlbee/DEBIAN/templates
+	cp debian/conffiles debian/bitlbee/DEBIAN/
+	
+	if [ "$(DEBUG)" = "0" ]; then strip -R .comment -R .note debian/bitlbee/usr/sbin/bitlbee; fi
+
+	cd debian/bitlbee; \
+		find usr -type f -exec md5sum {} \; > DEBIAN/md5sums
+	dpkg-shlibdeps -Tdebian/bitlbee.substvars -dDepends debian/bitlbee/usr/sbin/bitlbee
+ifdef BITLBEE_FORCE_VERSION
+	dpkg-gencontrol -ldebian/changelog -isp -pbitlbee -Tdebian/bitlbee.substvars -Pdebian/bitlbee -v1:$(BITLBEE_VERSION)-0 -V'debconf-depends=debconf (>= 1.2.0) | debconf-2.0'
+else
+	dpkg-gencontrol -ldebian/changelog -isp -pbitlbee -Tdebian/bitlbee.substvars -Pdebian/bitlbee -V'debconf-depends=debconf (>= 1.2.0) | debconf-2.0'
 endif
-	dh_installman
-	dh_strip
-	dh_link
-	dh_compress
-	dh_fixperms
-	dh_installdeb
-ifeq ($(DH_OPTIONS),-a)
-	cp -a debian/bitlbee/DEBIAN/post* debian/bitlbee/DEBIAN/pre* debian/bitlbee-libpurple/DEBIAN
+
+	dpkg --build debian/bitlbee ..
+
+binary-indep: install-indep
+	[ "`whoami`" = "root" -a -d debian ]
+
+	chown -R root.root debian/bitlbee-dev/
+	find debian/bitlbee-dev/usr/share/ -type d -exec chmod 755 {} \;
+	find debian/bitlbee-dev/usr/share/ -type f -exec chmod 644 {} \;
+
+	cp debian/changelog debian/bitlbee-dev/usr/share/doc/bitlbee-dev/changelog.Debian
+	gzip -9 debian/bitlbee-dev/usr/share/doc/bitlbee-dev/changelog.Debian
+	cp debian/copyright debian/bitlbee-dev/usr/share/doc/bitlbee-dev/copyright
+
+	cd debian/bitlbee-dev; \
+		find usr -type f -exec md5sum {} \; > DEBIAN/md5sums
+
+ifdef BITLBEE_FORCE_VERSION
+	dpkg-gencontrol -ldebian/changelog -isp -pbitlbee-dev -Pdebian/bitlbee-dev -v1:$(BITLBEE_VERSION)-0
+else
+	dpkg-gencontrol -ldebian/changelog -isp -pbitlbee-dev -Pdebian/bitlbee-dev
 endif
-	dh_shlibdeps
-ifdef BITLBEE_VERSION
-	dh_gencontrol -- -v1:$(BITLBEE_VERSION)-0  -Vbee:Version=1:$(BITLBEE_VERSION)-0
-else
-	dh_gencontrol -- -Vbee:Version=$(shell dpkg-parsechangelog | grep ^Version: | awk '{print $$2}' | sed -e 's/+[^+]*$$//')
-endif
-	dh_md5sums
-	dh_builddeb
 
-binary-indep: build install
-	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
+	dpkg --build debian/bitlbee-dev ..
 
-binary-arch: build install
-	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
+binary: binary-arch binary-indep
+build: build-arch
+install: install-arch install-indep
 
-binary-%: build install
-	make -f debian/rules binary-common DH_OPTIONS=-p$*
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary-common binary install
+.PHONY: build-arch build clean binary-arch binary install-arch install binary-indep install-indep
