From: Florian Pritz <[email protected]>

The user adds libaries to the depends array without a version. These
must end with .so.
Example: depends=(glibc libc.so)

find_sodepends() looks for ELF files (not symlinks because these could
point outside of pkgdir) in $pkgdir, extracts the library sonames the
binary liks to and outputs depends seperated by spaces.
This list contains all libraries needed by the package.
Example: libfoo.so=3-64

write_pkginfo() only keeps .so depends with version information and warns
the user about unneded ones.

Support-by: Thomas Bächler <[email protected]>
Support-by: Christoph Schied <[email protected]>
Signed-off-by: Florian Pritz <[email protected]>
---
 scripts/makepkg.sh.in |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 0d811b6..422b4c0 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -933,6 +933,31 @@ tidy_install() {
        fi
 }
 
+find_sodepends() {
+       local sodepends
+       find $pkgdir -type f | while read filename
+       do
+               # get architecture of the file; if soarch is empty it's not an 
ELF binary
+               soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 
's/.*Class.*ELF\(32\|64\)/\1/p')
+               [ -n "$soarch" ] || continue
+               # process all libraries needed by the binary
+               for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | 
sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
+               do
+                       # extract the library name: libfoo.so
+                       soname="${sofile%%\.so\.*}.so"
+                       # extract the major version: 1
+                       soversion="${sofile##*\.so\.}"
+                       if in_array "${soname}" ${depends[@]}; then
+                               if ! in_array 
"${soname}=${soversion}-${soarch}" ${sodepends[@]}; then
+                                       # libfoo.so=1-64
+                                       echo "${soname}=${soversion}-${soarch}"
+                                       sodepends=(${sodepends[@]} 
"${soname}=${soversion}-${soarch}")
+                               fi
+                       fi
+               done
+       done
+}
+
 find_soprovides() {
        local soprovides
        find "$pkgdir" -type f -name \*.so\* | while read filename
@@ -989,7 +1014,6 @@ write_pkginfo() {
        [[ $license ]]    && printf "license = %s\n"   "${license[@]}"
        [[ $replaces ]]   && printf "replaces = %s\n"  "${replaces[@]}"
        [[ $groups ]]     && printf "group = %s\n"     "${groups[@]}"
-       [[ $depends ]]    && printf "depend = %s\n"    "${depends[@]}"
        [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
        [[ $conflicts ]]  && printf "conflict = %s\n"  "${conflicts[@]}"
        [[ $backup ]]     && printf "backup = %s\n"    "${backup[@]}"
@@ -997,7 +1021,22 @@ write_pkginfo() {
        local it
 
        soprovides=$(find_soprovides)
+       sodepends=$(find_sodepends)
        provides=("${provides[@]}" ${soprovides})
+       depends=("${depends[@]}" ${sodepends})
+
+       for it in "${depends[@]}"; do
+               if [[ $it = *.so ]]; then
+                       # check if the entry has been found by find_sodepends
+                       # if not, it's unneeded; tell the user so he can remove 
it
+                       if [[ ! $sodepends =~ (^|\s)${it}=.* ]]; then
+                               error "$(gettext "Can't find library listed in 
\$depends: %s")" "$it"
+                               return 1
+                       fi
+               else
+                       echo "depend = $it"
+               fi
+       done
 
        for it in "${provides[@]}"; do
                # ignore versionless entires (those come from the PKGBUILD)
-- 
1.7.3.5

Reply via email to