From 074bd10d66c627e166830a3fdecd1b643f09e4d3 Mon Sep 17 00:00:00 2001
From: Niels Thykier <niels@thykier.net>
Date: Wed, 6 Nov 2024 11:01:30 +0000
Subject: [PATCH 1/4] Rewrite packaging to use `dh` sequencer and remove the
 need for `fakeroot`

Known issues:
 * Upstream's build system does not insert a build-id into libauthbind.so.1.0
   triggering a warning from `dh_strip`. This means the -dbgsym package
   does not include debug symbols for that library. It still provides
   debug for other binaries such `usr/lib/authbind/helper`, so still
   a net improvement. Fixing this would probably require patching
   upstream's Makefile or manually compiling the library. However, it was
   not a "low-enough" hanging fruit that I fixed as it.

Remarks on the diffoscope delta for the `.deb`:
 * New control files: md5sums, shlibs, and triggers. These match the
   expected outcome of (now) using `dh_md5sums` and `dh_makeshlibs`.
 * Content deltas of ELF binaries. This is expected. The strip process
   now also removes `.comment`. Additionally, debug links are inserted
   into the binaries. No delta in the instructions/binary code.
 * The Debian changelog is now trimmed (size delta), which is expected
   with dh_installchangelogs (as of `debhelper/13.10`).
 * Delta of symlinks mode in data.tar (g+w): Benign delta. The mode
   is not relevant for the symlink and was caused by tar preserving
   a recursive `chmod g-w` that is now removed (replaced by `dh_strip`)

Closes: #1086628
---
 debian/control |  2 ++
 debian/rules   | 93 +++++++++++++-------------------------------------
 2 files changed, 25 insertions(+), 70 deletions(-)

diff --git a/debian/control b/debian/control
index d36c6e3..0a49d0e 100644
--- a/debian/control
+++ b/debian/control
@@ -3,6 +3,8 @@ Section: utils
 Priority: optional
 Maintainer: Ian Jackson <ijackson@chiark.greenend.org.uk>
 Standards-Version: 3.9.1
+Build-Depends: debhelper-compat (= 13),
+Rules-Requires-Root: no
 
 Package: authbind
 Architecture: any
diff --git a/debian/rules b/debian/rules
index b4f4dc5..b0407cc 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,7 +1,7 @@
 #! /usr/bin/make -f
 #
 # debian/rules for authbind
-# 
+#
 # authbind is Copyright (C) 1998 Ian Jackson
 #
 # This program is free software; you can redistribute it and/or modify
@@ -16,47 +16,19 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #
 # $Id$
 
-SHELL=/bin/bash
-
 package=authbind
-major=1
-minor=0
-
-arch = $(shell dpkg --print-architecture)
-
-TOOL_PREFIX = $(shell set -x; a=`dpkg-architecture -q DEB_HOST_GNU_TYPE`; echo $$a$${a+-})
-ifeq ($(origin CC),default)
-CC=$(TOOL_PREFIX)gcc
-endif
-
-export SOURCE_DATE_EPOCH = $(shell date -d "$$(dpkg-parsechangelog --count 1 -SDate)" +%s)
 
 INSTALL = install
-INSTALL_FILE    = $(INSTALL) -p    -o root -g root  -m  644
-INSTALL_PROGRAM = $(INSTALL) -p    -o root -g root  -m  755
-INSTALL_SCRIPT  = $(INSTALL) -p    -o root -g root  -m  755
-INSTALL_DIR     = $(INSTALL) -p -d -o root -g root  -m  755
+INSTALL_FILE    = $(INSTALL) -p    -m  644
+INSTALL_PROGRAM = $(INSTALL) -p    -m  755
+INSTALL_SCRIPT  = $(INSTALL) -p    -m  755
+INSTALL_DIR     = $(INSTALL) -p -d -m  755
+STRIP = true
 
-CFLAGS = -O2 -Wall
-LDFLAGS = 
-
-
-CFLAGS += -g
-LDFLAGS += -g 
-
-ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
-STRIP=$(TOOL_PREFIX)strip
-INSTALL_PROGRAM += -s --strip-program=$(STRIP)
-else
-STRIP=:
-endif
-
-export CFLAGS
-export LDFLAGS
 export INSTALL
 export INSTALL_FILE
 export INSTALL_PROGRAM
@@ -65,43 +37,24 @@ export INSTALL_DIR
 export STRIP
 
 
-build: 
-	$(MAKE) prefix=/usr CC='$(CC)' LD='$(TOOL_PREFIX)ld'
-
-clean:	
-	$(MAKE) distclean
-	rm -rf debian/{files,substvars,tmp} build
-	rm -f debian/*~ debian/#*# debian/core debian/*.bak
+%:
+	dh $@
 
-binary-indep:   checkroot build
-	$(checkdir)
-# There are no architecture-independent files to be uploaded
-# generated by this package.  If there were any they would be
-# made here.
 
-lab=libauthbind.so.$(major).$(minor)
-udp=debian/tmp/usr/share/doc/$(package)
+override_dh_auto_build:
+	# prefix is needed here because it is recorded in the authbind binary
+	# (as a part of an error message). It would probably be fine without it,
+	# but it seems weird to be inconsistent between the installed location
+	# and the error message.
+	dh_auto_build -- prefix=/usr
 
-binary-arch:	checkroot build
-	rm -rf debian/tmp
-	install -d -g root -m 755 -o root debian/tmp/DEBIAN $(udp) \
-		debian/tmp/usr/{bin,lib/$(package),share/man}
-	$(MAKE) prefix=debian/tmp/usr etc_dir=debian/tmp/etc/authbind \
-		man_dir=debian/tmp/usr/share/man  install install_man
-	$(INSTALL_FILE) debian/changelog $(udp)/changelog
-	gzip -9n debian/tmp/usr/share/man/man*/* $(udp)/*
-	$(INSTALL_FILE) debian/copyright $(udp)/.
-	$(INSTALL_SCRIPT) debian/{postrm,prerm,postinst} debian/tmp/DEBIAN
-	dpkg-shlibdeps ./authbind
-	dpkg-gencontrol -isp
-	chown -R root.root debian/tmp
-	chmod -R g-ws debian/tmp
-	find debian/tmp -newermt "@$$SOURCE_DATE_EPOCH" -print0 | \
-		xargs -0r touch --no-dereference --date="@$$SOURCE_DATE_EPOCH"
-	dpkg --build debian/tmp ..
 
-binary:	 binary-indep binary-arch
+override_dh_auto_install:
+	# Upstream's make install forgets to create usr/bin (but only that one) as of 2.1.2
+	$(INSTALL_DIR) debian/$(package)/usr/bin
+	dh_auto_install -- prefix=debian/$(package)/usr etc_dir=debian/$(package)/etc/authbind \
+		install install_man
 
-checkroot:
-	$(checkdir)
-	test root = "`whoami`"
+execute_after_dh_fixperms:
+	# Redo the setuid mode that `dh_fixperms` removes
+	chmod u+s debian/$(package)/usr/lib/authbind/helper
-- 
2.45.2

