From 21b3c4962055f4b7ba6be6af9347db6e0f750b76 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@debian.org>
Date: Tue, 16 Sep 2025 23:21:09 +0200
Subject: [PATCH] Fix SONAME filename handling

The shared library should be installed as its SONAME, because the
package that provides it also ships the shlibs metadata file. Otherwise
dpkg-shlibdeps cannot find the mapping between the SONAME used by other
objects with the package containing the shlibs file.

This problem has been shadowed on users with merged-/usr with aliased
directories because the dpkg-shlibdeps code was failing to locate the
library under /lib (instead of the canonical location under /usr/lib)
and was then using a fallback code path where it would canonicalize
the filename, and would then find the actual shared library in the
libgctp-2.0.0 package and then be able to find the shlibs file
(instead of trying to look into the libgctp-dev package).

On systems with merged-/usr with aliased filenames or once the /lib
directory gets removed from the ld.so.conf pathnames, then
dpkg-shlibdeps is unable to find the shlibs file.

Although shipping a .so filename in a non-dev package is unconventional,
this is the expected thing to do with shared libraries with SONAME
denoting an unstable interface (like lib<name>-<version>.so). A similar
example would be libbinutils. Ideally upstream would switch from using
-release to -version-info in the build-system (but that's going to be
an ABI break, and upstream does not look very active).
---
 debian/control               | 3 ++-
 debian/libgctp-2.0.0.install | 2 +-
 debian/libgctp-2.0.0.links   | 3 ++-
 debian/libgctp-dev.links     | 3 +--
 debian/rules                 | 1 -
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/debian/control b/debian/control
index d2c3aca..cfa1f3c 100644
--- a/debian/control
+++ b/debian/control
@@ -14,7 +14,8 @@ Package: libgctp-2.0.0
 Section: libs
 Architecture: any
 Multi-Arch: same
-Breaks: libgctp-dev (<< 2.0.0-9)
+Breaks: libgctp-dev (<< 2.0.0-13~)
+Replaces: libgctp-dev (<< 2.0.0-13~)
 Depends: ${shlibs:Depends}, ${misc:Depends}
 Description: General Cartographic Transformation Package Library
  The General Cartographic Transformation Package (GCTP) is a system of
diff --git a/debian/libgctp-2.0.0.install b/debian/libgctp-2.0.0.install
index 5eaf89a..5e8fd16 100644
--- a/debian/libgctp-2.0.0.install
+++ b/debian/libgctp-2.0.0.install
@@ -1 +1 @@
-/usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.so.2.0.0
+/usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.0.0.so
diff --git a/debian/libgctp-2.0.0.links b/debian/libgctp-2.0.0.links
index dd33a8e..3972f00 100644
--- a/debian/libgctp-2.0.0.links
+++ b/debian/libgctp-2.0.0.links
@@ -1 +1,2 @@
-/usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.so.2.0.0  /usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.0.0.so.2
+/usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.0.0.so  /usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.0.0.so.2
+/usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.0.0.so  /usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.so.2.0.0
diff --git a/debian/libgctp-dev.links b/debian/libgctp-dev.links
index cec3ceb..2e227f2 100644
--- a/debian/libgctp-dev.links
+++ b/debian/libgctp-dev.links
@@ -1,2 +1 @@
-/usr/lib/${DEB_HOST_MULTIARCH}//libgctp-2.so.2.0.0  /usr/lib/${DEB_HOST_MULTIARCH}/libgctp-2.0.0.so
-/usr/lib/${DEB_HOST_MULTIARCH}//libgctp-2.so.2.0.0  /usr/lib/${DEB_HOST_MULTIARCH}/libgctp.so
+/usr/lib/${DEB_HOST_MULTIARCH}//libgctp-2.0.0.so  /usr/lib/${DEB_HOST_MULTIARCH}/libgctp.so
diff --git a/debian/rules b/debian/rules
index 2458a3b..6b43de7 100755
--- a/debian/rules
+++ b/debian/rules
@@ -32,5 +32,4 @@ override_dh_auto_install:
 	dh_auto_install -- 'CC=$(CC)'
 	rm $(INSTDIR)/libgctp.la $(INSTDIR)/libgctp.so
 	mv $(INSTDIR)/libgctp.a $(INSTDIR)/libgctp2.a
-	mv $(INSTDIR)/libgctp-2.0.0.so $(INSTDIR)/libgctp-2.so.2.0.0
 
-- 
2.51.0

