>From 266c1769446675d6f2ca4ad35320c2366d7f647e Mon Sep 17 00:00:00 2001
From: Florian Pritz <bluewind@xssn.at>
Date: Sat, 6 Feb 2010 00:18:00 +0100
Subject: [PATCH 1/2] makepkg: add soprovides 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 |   26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in
index b92a697..47b9209 100644
--- a/etc/makepkg.conf.in
+++ b/etc/makepkg.conf.in
@@ -67,8 +67,9 @@ BUILDENV=(fakeroot !distcc color !ccache)
 #-- emptydirs: Leave empty directories in packages
 #-- 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
 #
-OPTIONS=(strip docs libtool emptydirs zipman purge)
+OPTIONS=(strip docs libtool emptydirs zipman purge soprovides)
 
 #-- 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 5bd294c..80c9d50 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -874,6 +874,24 @@ tidy_install() {
 	fi
 }
 
+find_soprovides() {
+	find $pkgdir -type f -name \*.so\* | while read filename
+	do
+    if readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
+			soarch=$(objdump -a "$filename" 2>/dev/null | sed -rn 's/.* file format (.*)$/\1/p' | tr - _)
+      sofile=$(readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Library soname: \[(.*)\].*/\1/p')
+			[ -z "$sofile" ] && sofile="$(basename "$filename")"
+			
+			soname=$(sed -rn 's/(.*)\.so.*/\1.so/p' <<< "$sofile")
+			soversion=$(sed -rn 's/.*\.so\.(.*)/\1/p' <<< "$sofile")
+
+			if in_array "$soname" ${soprovides[@]}; then
+				echo ${soname}-${soarch}=${soversion}
+			fi
+    fi
+	done
+}
+
 write_pkginfo() {
 	local builddate=$(date -u "+%s")
 	if [[ -n $PACKAGER ]]; then
@@ -903,6 +921,14 @@ write_pkginfo() {
 		echo "force = true" >> .PKGINFO
 	fi
 
+	if [ "$(check_option soprovides)" != "n" ]; then
+		_soprovides=$(find_soprovides)
+	fi
+		
+	if [ "$(check_option soprovides)" != "n" ]; then
+		provides=("${provides[@]}" ${_soprovides})
+	fi
+
 	local it
 	for it in "${license[@]}"; do
 		echo "license = $it" >>.PKGINFO
-- 
1.6.6.1

