From 9e9c20deed3e06bdebf04df47a57df04f6ef041a Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Thu, 5 Dec 2019 13:15:41 +0000
Subject: [PATCH] Put symbolic links to dependencies in their own package

This avoids the need to Build-Conflict with the -helpers package,
which we want to install in the SDK image.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 debian/control                                | 20 +++++++++++++-
 .../libsteam-runtime-tools-0-helpers.install  |  1 -
 debian/rules                                  | 27 ++++++++++++++-----
 3 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/debian/control b/debian/control
index 393211d94..69eec0dc6 100644
--- a/debian/control
+++ b/debian/control
@@ -23,7 +23,8 @@ Build-Depends:
 Build-Depends-Indep:
  libglib2.0-dev,
 Build-Conflicts:
- libsteam-runtime-tools-0-helpers,
+ libsteam-runtime-tools-0-helpers (<< 0.20191204.0~),
+ libsteam-runtime-tools-0-relocatable-libs,
 Vcs-Git: https://gitlab.steamos.cloud/steam/steam-runtime-tools.git
 Vcs-Browser: https://gitlab.steamos.cloud/steam/steam-runtime-tools
 
@@ -89,6 +90,23 @@ Description:
  This package contains helper tools used to examine the library stack
  available for each architecture.
 
+Package: libsteam-runtime-tools-0-relocatable-libs
+Architecture: amd64 i386
+Multi-Arch: same
+Section: misc
+Depends:
+ ${misc:Depends},
+ ${relocatable:Depends},
+Description:
+ The Steam Runtime is the library stack used to run the Steam client
+ on Linux. The Steam Runtime Tools utility library contains open-source
+ supporting code used by the Steam client to discover system information.
+ .
+ This package contains symbolic links to libraries depended on by the
+ steam-runtime-system-info and libsteam-runtime-tools-0-helpers packages,
+ which make it possible to run those tools from an LD_LIBRARY_PATH-style
+ Steam Runtime even if the LD_LIBRARY_PATH is not correctly set.
+
 Package: libsteam-runtime-tools-0-tests
 Architecture: any
 Section: misc
diff --git a/debian/libsteam-runtime-tools-0-helpers.install b/debian/libsteam-runtime-tools-0-helpers.install
index 4f58c509f..4d24bb6e6 100644
--- a/debian/libsteam-runtime-tools-0-helpers.install
+++ b/debian/libsteam-runtime-tools-0-helpers.install
@@ -1,2 +1 @@
-usr/lib/*/steam-runtime-tools-0/*
 usr/libexec/steam-runtime-tools-0/*
diff --git a/debian/rules b/debian/rules
index e8200469b..f786e2386 100755
--- a/debian/rules
+++ b/debian/rules
@@ -45,6 +45,7 @@ pkglibexecdir := $(libexecdir)/steam-runtime-tools-0
 libdir := lib/$(DEB_HOST_MULTIARCH)
 pkglibdir := $(libdir)/steam-runtime-tools-0
 DESTDIR := $(CURDIR)/debian/tmp
+relocatable_pkglibdir := $(CURDIR)/debian/libsteam-runtime-tools-0-relocatable-libs/usr/$(pkglibdir)
 
 override_dh_auto_configure:
 	meson builddir \
@@ -81,25 +82,37 @@ override_dh_auto_install:
 			ln -fnsv ../../steam-runtime-tools-0/$(DEB_HOST_MULTIARCH)-true "$$x"; \
 		fi; \
 	done
-	install -d $(DESTDIR)/usr/$(pkglibdir)
-	ln -fnsv ../libsteam-runtime-tools-0.so.0 $(DESTDIR)/usr/$(pkglibdir)/
+
+override_dh_shlibdeps:
+	dh_shlibdeps \
+		-plibsteam-runtime-tools-0-relocatable-libs \
+		-- \
+		-prelocatable \
+		-e$(DESTDIR)/usr/bin/steam-runtime-system-info \
+		-e$(DESTDIR)/usr/$(pkglibexecdir)/$(DEB_HOST_MULTIARCH)-check-locale \
+		$(NULL)
+	dh_shlibdeps
+
+override_dh_link:
+	dh_link
+	:
+	install -d $(relocatable_pkglibdir)
+	ln -fnsv ../libsteam-runtime-tools-0.so.0 $(relocatable_pkglibdir)
 	LD_LIBRARY_PATH='$(DESTDIR)/usr/$(libdir)' \
 	$(DEB_HOST_MULTIARCH)-capsule-capture-libs \
 		--container / \
-		--dest $(DESTDIR)/usr/$(pkglibdir) \
+		--dest $(relocatable_pkglibdir) \
 		--link-target / \
 		--no-glibc \
 		--provider / \
 		only-dependencies:path:$(DESTDIR)/usr/bin/steam-runtime-system-info \
 		only-dependencies:path:$(DESTDIR)/usr/$(pkglibexecdir)/$(DEB_HOST_MULTIARCH)-check-locale \
 		$(NULL)
-
-override_dh_link:
-	dh_link
+	:
 	# Make the links in $(pkglibdir) relative. This is contrary
 	# to Debian policy, but is what we need for the LD_LIBRARY_PATH
 	# Steam Runtime, where GLib is in /lib.
-	set -e; for link in debian/libsteam-runtime-tools-0-helpers/usr/$(pkglibdir)/lib*; do \
+	set -e; for link in $(relocatable_pkglibdir)/lib*; do \
 		target="$$(readlink -v "$$link")"; \
 		echo "before: $$link -> $$target"; \
 		case "$$target" in \
-- 
GitLab