diff -pruN 0.16.35/debian/changelog 0.16.36/debian/changelog
--- 0.16.35/debian/changelog	2025-09-12 18:56:58.000000000 +0000
+++ 0.16.36/debian/changelog	2025-09-19 18:07:26.000000000 +0000
@@ -1,3 +1,9 @@
+haskell-devscripts (0.16.36) unstable; urgency=medium
+
+  * Introduce config_to_package_id method
+
+ -- Ilias Tsitsimpis <iliastsi@debian.org>  Fri, 19 Sep 2025 21:07:26 +0300
+
 haskell-devscripts (0.16.35) experimental; urgency=medium
 
   * dh_haskell_provides_ghc: strip "-inplace" from configs.
diff -pruN 0.16.35/dh_haskell_depends_cabal 0.16.36/dh_haskell_depends_cabal
--- 0.16.35/dh_haskell_depends_cabal	2022-05-30 01:36:08.000000000 +0000
+++ 0.16.36/dh_haskell_depends_cabal	2025-09-19 18:07:26.000000000 +0000
@@ -35,6 +35,7 @@ use Debian::Debhelper::Buildsystem::Hask
   ghc_pkg_command
   load_ghc_database
   hashed_id_to_virtual_installable
+  config_to_package_id
 );
 use Debian::Debhelper::Dh_Lib;
 
@@ -149,10 +150,10 @@ sub cabal_depends {
     my @prerequisites;
     for my $config (@configs) {
 
-        my $name = path($config)->basename(qr{ [.]conf $}x);
+        my $package_id = config_to_package_id($config, $ghc_pkg, $tmp_db);
         my $depends
           = run($ghc_pkg, '--package-db', $tmp_db, qw{--simple-output field},
-            $name, 'depends');
+            '--unit-id', $package_id, 'depends');
         push(@prerequisites, split($SPACE, $depends // $EMPTY));
     }
 
diff -pruN 0.16.35/dh_haskell_provides_ghc 0.16.36/dh_haskell_provides_ghc
--- 0.16.35/dh_haskell_provides_ghc	2025-09-12 18:56:16.000000000 +0000
+++ 0.16.36/dh_haskell_provides_ghc	2025-09-19 18:07:26.000000000 +0000
@@ -36,6 +36,7 @@ use Debian::Debhelper::Buildsystem::Hask
   ghc_pkg_command
   load_ghc_database
   hashed_id_to_virtual_installable
+  config_to_package_id
 );
 use Debian::Debhelper::Dh_Lib;
 
@@ -71,16 +72,8 @@ for my $installable (@{ $dh{DOPACKAGES}
 
     my @hashed_ids;
     for my $config (@configs) {
-
-        my $name = path($config)->basename(qr{ [.]conf $}x);
-	(my $namever = $name) =~ s/-inplace$//;
-        push(
-            @hashed_ids,
-            run(
-                $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE},
-                qw{--simple-output field},
-                $namever, 'id'
-            ));
+        my $package_id = config_to_package_id($config, $ghc_pkg, $ENV{DEB_GHC_DATABASE});
+        push(@hashed_ids, $package_id);
     }
 
     my $substvars_path = "debian/$installable.substvars";
diff -pruN 0.16.35/dh_haskell_shlibdeps 0.16.36/dh_haskell_shlibdeps
--- 0.16.35/dh_haskell_shlibdeps	2022-05-30 01:36:08.000000000 +0000
+++ 0.16.36/dh_haskell_shlibdeps	2025-09-19 18:07:26.000000000 +0000
@@ -35,6 +35,7 @@ use Debian::Debhelper::Buildsystem::Hask
   hc_pkgdir
   ghc_pkg_command
   load_ghc_database
+  config_to_package_id
 );
 use Debian::Debhelper::Dh_Lib;
 
@@ -60,23 +61,27 @@ for my $installable (@{ $dh{DOPACKAGES}
 
     my @gcc_args;
 
-    my @hashed_ids = map { path($_)->basename(qr{ [.]conf $}x) } @configs;
-    for my $hashed_id (@hashed_ids) {
+    my @package_ids;
+    for my $config (@configs) {
+        my $package_id = config_to_package_id($config, $ghc_pkg, $ENV{DEB_GHC_DATABASE});
+        push(@package_ids, $package_id);
+    }
+    for my $package_id (@package_ids) {
 
         my $libdir_string = decode_utf8(
             run(
-                $ghc_pkg, '--package-db',
-                $ENV{DEB_GHC_DATABASE}, qw{--simple-output field},
-                $hashed_id, 'library-dirs'
+                $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE},
+                qw{--simple-output field},
+                '--unit-id', $package_id, 'library-dirs'
             ));
         my @lib_dirs = split($SPACE, $libdir_string);
         push(@gcc_args, (map { "-L$_" } @lib_dirs));
 
         my $library_string = decode_utf8(
             run(
-                $ghc_pkg, '--package-db',
-                $ENV{DEB_GHC_DATABASE}, qw{--simple-output field},
-                $hashed_id, 'extra-libraries'
+                $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE},
+                qw{--simple-output field},
+                '--unit-id', $package_id, 'extra-libraries'
             ));
         my @libraries = split($SPACE, $library_string);
         push(@gcc_args, (map { "-l$_" } @libraries));
diff -pruN 0.16.35/lib/Debian/Debhelper/Buildsystem/Haskell/Recipes.pm 0.16.36/lib/Debian/Debhelper/Buildsystem/Haskell/Recipes.pm
--- 0.16.35/lib/Debian/Debhelper/Buildsystem/Haskell/Recipes.pm	2025-03-29 15:21:30.000000000 +0000
+++ 0.16.36/lib/Debian/Debhelper/Buildsystem/Haskell/Recipes.pm	2025-09-19 18:07:26.000000000 +0000
@@ -43,6 +43,7 @@ BEGIN {
       load_ghc_database
       own_cabal_prerequisites
       hashed_id_to_virtual_installable
+      config_to_package_id
       clean_recipe
       make_setup_recipe
       configure_recipe
@@ -481,6 +482,24 @@ sub hashed_id_to_virtual_installable {
     return $virtual;
 }
 
+=item config_to_package_id
+
+=cut
+
+sub config_to_package_id {
+    my ($config, $ghc_pkg, $package_db) = @_;
+
+    my $name = path($config)->basename(qr { [.]conf $}x);
+
+    $name =~ m/^([^ ]*?)-(\d[\d.]*)(-\S+)?$/;
+    $name = "$1-$2";
+
+    my $package_id = run($ghc_pkg, '--package-db', $package_db,
+        qw{--simple-output field}, $name, 'id');
+
+    return $package_id;
+}
+
 =item clean_recipe
 
 =cut
