From f4f37a8fed617ffdbf9fc4c19fc5caadf6434bba Mon Sep 17 00:00:00 2001
From: Peter Palfrader <peter@palfrader.org>
Date: Tue, 16 Apr 2013 15:30:09 +0200
Subject: [PATCH] Modernize debian packaging

---
 debian/compat                              |   2 +-
 debian/control                             |   4 +-
 debian/copyright                           |   4 +-
 debian/patches/00list                      |   1 -
 debian/patches/14_fix_geoip_warning.dpatch |  38 -----
 debian/patches/improve-geoip-warning       |  12 ++
 debian/patches/series                      |   1 +
 debian/rules                               | 164 +++------------------
 debian/tor-dbg.links                       |   1 -
 debian/tor-geoipdb.dirs                    |   1 -
 debian/tor-geoipdb.install                 |   2 +
 debian/tor.dirs                            |   5 -
 debian/tor.install                         |   7 +
 13 files changed, 50 insertions(+), 192 deletions(-)
 delete mode 100644 debian/patches/00list
 delete mode 100755 debian/patches/14_fix_geoip_warning.dpatch
 create mode 100644 debian/patches/improve-geoip-warning
 create mode 100644 debian/patches/series
 delete mode 100644 debian/tor-dbg.links
 delete mode 100644 debian/tor-geoipdb.dirs
 create mode 100644 debian/tor-geoipdb.install
 create mode 100644 debian/tor.install

diff --git a/debian/compat b/debian/compat
index 7ed6ff82de..45a4fb75db 100644
--- a/debian/compat
+++ b/debian/compat
@@ -1 +1 @@
-5
+8
diff --git a/debian/control b/debian/control
index c9b2607846..7dcf78920b 100644
--- a/debian/control
+++ b/debian/control
@@ -2,9 +2,9 @@ Source: tor
 Section: net
 Priority: optional
 Maintainer: Peter Palfrader <weasel@debian.org>
-Build-Depends: debhelper (>= 6), libssl-dev, dpatch, zlib1g-dev, libevent-dev (>= 1.1), binutils (>= 2.14.90.0.7), hardening-includes, asciidoc (>= 8.2), docbook-xml, docbook-xsl, xmlto, dh-apparmor
+Build-Depends: debhelper (>= 8), quilt, libssl-dev, zlib1g-dev, libevent-dev (>= 1.1), binutils (>= 2.14.90.0.7), hardening-includes, asciidoc (>= 8.2), docbook-xml, docbook-xsl, xmlto, dh-apparmor
 Build-Conflicts: libnacl-dev
-Standards-Version: 3.8.1
+Standards-Version: 3.9.4
 Homepage: https://www.torproject.org/
 Vcs-Git: https://git.torproject.org/debian/tor.git
 Vcs-Browser: https://gitweb.torproject.org/debian/tor.git
diff --git a/debian/copyright b/debian/copyright
index a6f0307cb4..2d66acca3a 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -8,13 +8,13 @@ Upstream Author: The Tor Project - https://www.torproject.org/
 Copyright (c) 2001 Matej Pfajfar
 Copyright (c) 2001-2004, Roger Dingledine
 Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
-Copyright (c) 2007-2012, The Tor Project, Inc.
+Copyright (c) 2007-2013, The Tor Project, Inc.
 strlcat, strlcpy: Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
 ht.h: Copyright (c) 2002, Christopher Clark, 2006 Nick Mathewson
 OpenBSD_malloc_Linux.c: phk@FreeBSD.ORG
 OpenBSD queue.h: Copyright (c) 1991, 1993 The Regents of the University of California.
 Curve25519: Copyright (c) 2008 Google Inc.
-Modifications for Debian: Copyright (c) 2004-2012 Peter Palfrader
+Modifications for Debian: Copyright (c) 2004-2013 Peter Palfrader
 
 Tor is distributed under this license:
 ===============================================================================
diff --git a/debian/patches/00list b/debian/patches/00list
deleted file mode 100644
index 75797f54dc..0000000000
--- a/debian/patches/00list
+++ /dev/null
@@ -1 +0,0 @@
-14_fix_geoip_warning
diff --git a/debian/patches/14_fix_geoip_warning.dpatch b/debian/patches/14_fix_geoip_warning.dpatch
deleted file mode 100755
index aaa6e85cc5..0000000000
--- a/debian/patches/14_fix_geoip_warning.dpatch
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /bin/sh -e
-## 14_fix_geoip_warning.dpatch by  <weasel@debian.org>
-##
-## All lines beginning with `## DP:' are a description of the patch.
-## DP: Change geoipdb open failed message
-
-if [ $# -lt 1 ]; then
-    echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
-    exit 1
-fi
-
-[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
-patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}"
-
-case "$1" in
-    -patch) patch -p1 ${patch_opts} < $0;;
-    -unpatch) patch -R -p1 ${patch_opts} < $0;;
-    *)
-        echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
-        exit 1;;
-esac
-
-exit 0
-
-@DPATCH@
-diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' tor~/src/or/geoip.c tor/src/or/geoip.c
---- tor~/src/or/geoip.c	2012-09-13 23:13:52.000000000 +0200
-+++ tor/src/or/geoip.c	2012-09-19 10:32:40.869252859 +0200
-@@ -207,7 +207,8 @@
-   crypto_digest_t *geoip_digest_env = NULL;
-   clear_geoip_db();
-   if (!(f = tor_fopen_cloexec(filename, "r"))) {
--    log_fn(severity, LD_GENERAL, "Failed to open GEOIP file %s.  %s",
-+    log_fn(severity, LD_GENERAL, "Failed to open GEOIP file %s.  %s"
-+           " Do you have the tor-geoipdb package installed?",
-            filename, msg);
-     return -1;
-   }
diff --git a/debian/patches/improve-geoip-warning b/debian/patches/improve-geoip-warning
new file mode 100644
index 0000000000..e00c7942cb
--- /dev/null
+++ b/debian/patches/improve-geoip-warning
@@ -0,0 +1,12 @@
+--- a/src/or/geoip.c
++++ b/src/or/geoip.c
+@@ -301,7 +301,8 @@
+   tor_assert(family == AF_INET || family == AF_INET6);
+ 
+   if (!(f = tor_fopen_cloexec(filename, "r"))) {
+-    log_fn(severity, LD_GENERAL, "Failed to open GEOIP file %s.  %s",
++    log_fn(severity, LD_GENERAL, "Failed to open GEOIP file %s.  %s"
++           " Do you have the tor-geoipdb package installed?",
+            filename, msg);
+     return -1;
+   }
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000000..19e8864ab2
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+improve-geoip-warning
diff --git a/debian/rules b/debian/rules
index 6cd458d958..27773bc2fa 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,61 +1,7 @@
 #!/usr/bin/make -f
 # -*- makefile -*-
-# Sample debian/rules that uses debhelper.
-# GNU copyright 1997 to 1999 by Joey Hess.
 
-# Uncomment this to turn on verbose mode.
-#export DH_VERBOSE=1
-
-export PACKAGE=tor
-include /usr/share/dpatch/dpatch.make
-
-# enable hardning options
-include /usr/share/hardening-includes/hardening.make
-CFLAGS += $(HARDENING_CFLAGS)
-LDFLAGS += $(HARDENING_LDFLAGS)
-
-# These are used for cross-compiling and for saving the configure script
-# from having to guess our platform (since we know it already)
-#
-# See /usr/share/doc/autotools-dev/README.Debian.gz which suggests
-# this way of passing --build and --host.  Also see the thread on
-# debian-devel './configure in debian/rules' from February/March 2006,
-# starting with <43FF212C.5020800@xs4all.nl> by Pjotr Kourzanov.
-export DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
-export DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
-ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
-  confflags += --build $(DEB_HOST_GNU_TYPE)
-else
-  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
-endif
-
-CFLAGS ?= -Wall -g
-
-# Do not optimize the build with "noopt"
-ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
-	CFLAGS += -O0
-else
-	CFLAGS += -O2
-endif
-
-# Do not strip the binary with "nostrip"
-#ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
-#	INSTALL_PROGRAM += -s
-#endif
-
-# Prevent the unit tests from being run with "nocheck"
-ifneq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
-	RUN_TEST = no
-endif
-ifneq (,$(findstring notest,$(DEB_BUILD_OPTIONS)))
-	RUN_TEST = no
-endif
-
-# Support passing of parallel=<n> in build options
-ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
-	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
-	MAKEFLAGS += -j$(NUMJOBS)
-endif
+DH_VERBOSE ?= 1
 
 # allow building against libdmalloc4 - it better be installed
 ifneq (,$(findstring with-dmalloc,$(DEB_BUILD_OPTIONS)))
@@ -66,13 +12,16 @@ ifneq (,$(findstring enable-openbsd-malloc,$(DEB_BUILD_OPTIONS)))
 	confflags += --enable-openbsd-malloc
 endif
 
-export LDFLAGS
-export CFLAGS
+%:
+	dh \
+		$@ \
+		--with quilt \
+		--builddirectory=build \
+		--parallel
 
-configure: patch-stamp
-config.status: configure
-	dh_testdir
-	./configure \
+override_dh_auto_configure:
+	! [ -e debian/micro-revision.i ] || cp debian/micro-revision.i src/or/micro-revision.i
+	dh_auto_configure -- \
 		$(confflags) \
 		--prefix=/usr \
 		--mandir=\$${prefix}/share/man \
@@ -81,99 +30,32 @@ config.status: configure
 		--sysconfdir=/etc \
 		--disable-silent-rules
 
-
-build: build-stamp
-
-
-build-stamp:  config.status $(MANPAGE_INS)
-	dh_testdir
-	! [ -e debian/micro-revision.i ] || cp debian/micro-revision.i src/or/micro-revision.i
-
-	$(MAKE)
-	@echo
-	@echo
-	# Running unit tests
-	@if [ "$(RUN_TEST)" != "no" ]; then \
-		make check; \
-	else \
-		echo; echo; echo "Skipping unittests"; echo; \
-	fi
-	@echo
-	touch build-stamp
-
-clean: unpatch
-	dh_testdir
-	dh_testroot
-	rm -f build-stamp
-	rm -f src/common/common_sha1.i src/or/or_sha1.i
-	rm -f src/or/micro-revision.i
-
-	[ ! -f Makefile ] || $(MAKE) distclean
+override_dh_clean:
 	! [ -e debian/micro-revision.i ] || rm -f src/or/micro-revision.i
 
-	# Normally the .deb wouldn't ship with a ../.git
+	# Normally the .deb wouldn't ship with a ../.git, but if we do, include the revision number
 	if [ -d .git ] && which git >/dev/null; then \
 		echo "\"`git rev-parse --short=16 HEAD`\"" > "debian/micro-revision.i" ; \
 	fi
 
 	# these get autobuilt from the .txt files, some of which we also patch
-	rm -f doc/*.in
+	rm -vf doc/*.in
 
 	dh_clean
 
-install: build
-	dh_testdir
-	dh_testroot
-	dh_clean -k
-	dh_installdirs
-	dh_lintian
+override_dh_install:
+	dh_install --fail-missing
 
-	$(MAKE) install DESTDIR=$(CURDIR)/debian/tor
-	# move tor things around
-	mv $(CURDIR)/debian/tor/etc/tor/torrc.sample $(CURDIR)/debian/tor/etc/tor/torrc
+	mv debian/tor/etc/tor/torrc.sample debian/tor/etc/tor/torrc
 
-	install -m 755 contrib/torify $(CURDIR)/debian/tor/usr/bin
-	install -m 644 debian/tor-service-defaults-torrc $(CURDIR)/debian/tor/usr/share/tor
-
-	install -m 644 debian/tor.apparmor-profile $(CURDIR)/debian/tor/etc/apparmor.d/system_tor
-	install -m 644 debian/tor.apparmor-profile.abstraction $(CURDIR)/debian/tor/etc/apparmor.d/abstractions/tor
+	cp debian/tor.apparmor-profile             debian/tor/etc/apparmor.d/system_tor
+	cp debian/tor.apparmor-profile.abstraction debian/tor/etc/apparmor.d/abstractions/tor
 	dh_apparmor --profile-name=system_tor -ptor
 
-	# tor-geoip
-	mv $(CURDIR)/debian/tor/usr/share/tor/geoip $(CURDIR)/debian/tor-geoipdb/usr/share/tor
-	mv $(CURDIR)/debian/tor/usr/share/tor/geoip6 $(CURDIR)/debian/tor-geoipdb/usr/share/tor
-	rmdir $(CURDIR)/debian/tor/usr/share/tor || true
-
-# Must not depend on anything. This is to be called by
-# binary-arch/binary-indep
-# in another 'make' thread.
-binary-common:
-	dh_testdir
-	dh_testroot
-	dh_link
-	dh_installchangelogs ChangeLog
+override_dh_installdocs:
+	dh_installdocs -ptor-dbg --link-doc=tor
 	dh_installdocs
-	dh_installexamples
-	dh_installlogrotate
-	dh_installinit --error-handler=tor_error_init
-	dh_installcron
-	dh_installman
+override_dh_strip:
 	dh_strip --dbg-package=tor-dbg
-	dh_compress
-	dh_fixperms
-	dh_installdeb
-	dh_shlibdeps
-	dh_gencontrol
-	dh_md5sums
-	dh_builddeb
-
-# Build architecture independant packages using the common target.
-binary-indep: install
-	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
-
-# Build architecture dependant packages using the common target.
-binary-arch: install
-	$(MAKE) -f debian/rules DH_OPTIONS=-s binary-common
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-common binary-indep binary-arch binary install
+override_dh_installinit:
+	dh_installinit --error-handler=tor_error_init
diff --git a/debian/tor-dbg.links b/debian/tor-dbg.links
deleted file mode 100644
index eb369cd4a8..0000000000
--- a/debian/tor-dbg.links
+++ /dev/null
@@ -1 +0,0 @@
-/usr/share/doc/tor /usr/share/doc/tor-dbg
diff --git a/debian/tor-geoipdb.dirs b/debian/tor-geoipdb.dirs
deleted file mode 100644
index fef29b06c8..0000000000
--- a/debian/tor-geoipdb.dirs
+++ /dev/null
@@ -1 +0,0 @@
-usr/share/tor
diff --git a/debian/tor-geoipdb.install b/debian/tor-geoipdb.install
new file mode 100644
index 0000000000..7f3d5d4625
--- /dev/null
+++ b/debian/tor-geoipdb.install
@@ -0,0 +1,2 @@
+usr/share/tor/geoip
+usr/share/tor/geoip6
diff --git a/debian/tor.dirs b/debian/tor.dirs
index 4410d918d4..f69395602c 100644
--- a/debian/tor.dirs
+++ b/debian/tor.dirs
@@ -1,6 +1 @@
 etc/apparmor.d/abstractions
-etc/tor
-var/lib/tor
-var/log/tor
-usr/bin
-usr/share/tor
diff --git a/debian/tor.install b/debian/tor.install
new file mode 100644
index 0000000000..fc589f2136
--- /dev/null
+++ b/debian/tor.install
@@ -0,0 +1,7 @@
+usr/bin
+usr/share/doc
+usr/share/man
+etc/tor
+
+build/contrib/torify usr/bin
+debian/tor-service-defaults-torrc usr/share/tor
-- 
GitLab