From be8964b0dd568f2501df1a63577f6f0273ad46e9 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Thu, 4 Mar 2021 20:10:40 +0000
Subject: [PATCH] debian: Make symlinks in RPATH point to libraries by SONAME

This means they don't stop working when the real path to a library
happens to have changed, for example upgrading GLib 2.32.3 to 2.32.4,
which changes the real file implementing the library from
libglib-2.0.so.0.3200.3 to libglib-2.0.so.0.3200.4.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 debian/rules | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/debian/rules b/debian/rules
index 40489f926..c716248f1 100755
--- a/debian/rules
+++ b/debian/rules
@@ -126,14 +126,27 @@ override_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 $(relocatable_pkglibdir)/lib*; do \
+	# Also make them point to the SONAME if possible.
+	set -e; \
+	cd $(relocatable_pkglibdir); \
+	for link in lib*; do \
 		target="$$(readlink -v "$$link")"; \
 		echo "before: $$link -> $$target"; \
+		by_soname="$${target%/*}/$$link"; \
+		if ! [ -e "$$by_soname" ]; then \
+			echo "$$by_soname does not exist"; \
+		elif ! command test "$$target" -ef "$$by_soname"; then \
+			echo "$$target is not the same file as $$by_soname"; \
+		else \
+			target="$$by_soname"; \
+		fi; \
 		case "$$target" in \
 			(/*) \
-				ln -fnsv "../../../..$${target}" "$${link}"; \
+				target="../../../..$${target}"; \
 				;; \
 		esac; \
+		echo "after:  $$link -> $$target"; \
+		ln -fnsv "$${target}" "$${link}"; \
 	done
 
 override_dh_missing:
-- 
GitLab