diff --git a/find-libdeps.in b/find-libdeps.in
index a7f2b82df5facf8e4a0e268786d0a0eccf1ecbd2..36e2c43ce2ce0dbfbf38ab3b94e5ea3712cb928d 100644
--- a/find-libdeps.in
+++ b/find-libdeps.in
@@ -3,6 +3,7 @@
 m4_include(lib/common.sh)
 
 set -e
+shopt -s extglob
 
 IGNORE_INTERNAL=0
 
@@ -40,7 +41,7 @@ fi
 
 process_sofile() {
 	# extract the library name: libfoo.so
-	soname="${sofile%%\.so\.*}.so"
+	soname="${sofile%.so?(+(.+([0-9])))}".so
 	# extract the major version: 1
 	soversion="${sofile##*\.so\.}"
 	if [[ "$soversion" = "$sofile" ]] && (($IGNORE_INTERNAL)); then