>From 875a7cc396ba293c2130ded9b9dd22dc9a77794c Mon Sep 17 00:00:00 2001
From: Florian Pritz <bluewind@xssn.at>
Date: Sat, 6 Feb 2010 00:19:07 +0100
Subject: [PATCH 2/2] makepkg: add sodepends support

Support-by: brain0 <thomas@archlinux.org>
Support-by: GNU\caustic <Christoph.Schied@uni-ulm.de>

Signed-off-by: Florian Pritz <bluewind@xssn.at>
---
 etc/makepkg.conf.in   |    3 ++-
 scripts/makepkg.sh.in |   24 +++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in
index 47b9209..aa17f71 100644
--- a/etc/makepkg.conf.in
+++ b/etc/makepkg.conf.in
@@ -68,8 +68,9 @@ BUILDENV=(fakeroot !distcc color !ccache)
 #-- zipman:    Compress manual (man and info) pages in MAN_DIRS with gzip
 #-- purge:     Remove files specified by PURGE_TARGETS
 #-- soprovides:add .so files to provides array
+#-- sodepends: add .so files to depends array
 #
-OPTIONS=(strip docs libtool emptydirs zipman purge soprovides)
+OPTIONS=(strip docs libtool emptydirs zipman purge soprovides !sodepends)
 
 #-- File integrity checks to use. Valid: md5, sha1, sha256, sha384, sha512
 INTEGRITY_CHECK=(md5)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 80c9d50..47ecf34 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -874,6 +874,23 @@ tidy_install() {
 	fi
 }
 
+find_sodepends() {
+	find $pkgdir -type f | while read filename
+	do
+		soarch=$(objdump -a "$filename" 2>/dev/null | sed -rn 's/.* file format (.*)$/\1/p' | tr - _)
+		[ -n "$soarch" ] || continue
+		for sofile in $(readelf -d "$filename" 2> /dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
+		do
+			soname=$(sed -rn 's/(.*)\.so.*/\1.so/p' <<< "$sofile")
+			soversion=$(sed -rn 's/.*\.so\.(.*)/\1/p' <<< "$sofile")
+			if in_array "${soname}" ${sodepends[@]}; then
+				echo "${soname}-${soarch}=${soversion}"
+				sodepends=(${sodepends[@]} "${soname}-${soarch}=${soversion}")
+			fi
+		done
+	done
+}
+
 find_soprovides() {
 	find $pkgdir -type f -name \*.so\* | while read filename
 	do
@@ -921,10 +938,15 @@ write_pkginfo() {
 		echo "force = true" >> .PKGINFO
 	fi
 
-	if [ "$(check_option soprovides)" != "n" ]; then
+	if [ "$(check_option soprovides)" != "n" ] || [ "$(check_option sodepends)" = "y" ]; then
 		_soprovides=$(find_soprovides)
 	fi
 		
+	if [ "$(check_option sodepends)" = "y" ]; then
+		_sodepends=$(find_sodepends)
+		depends=("${depends[@]}" ${_sodepends})
+	fi
+
 	if [ "$(check_option soprovides)" != "n" ]; then
 		provides=("${provides[@]}" ${_soprovides})
 	fi
-- 
1.6.6.1

