blob: cfd6f6c756761ac54664f4c438b34a38a0b65a75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#!/bin/bash
set -e
IGNORE_INTERNAL=0
if [[ $1 = "--ignore-internal" ]]; then
IGNORE_INTERNAL=1
shift
fi
if [[ -z $1 ]]; then
echo "$(basename "$0") [options] <package file|extracted package dir>"
echo "Options:"
echo " --ignore-internal ignore internal libraries"
exit 1
fi
if [[ -d $1 ]]; then
cd $1
else
tmpdir=$(mktemp -d /tmp/find-sodeps.XXXXXXX)
trap "rm -rf '$tmpdir'" EXIT INT TERM
bsdtar -C $tmpdir -xf "$1" --include="*.so*"
cd $tmpdir
fi
in_array() {
local needle=$1; shift
[[ -z $1 ]] && return 1 # Not Found
local item
for item in "$@"; do
[[ $item = $needle ]] && return 0 # Found
done
return 1 # Not Found
}
find . -type f -name \*.so\* | while read filename
do
# check if we really have a shared object
if LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
# 64
soarch=$(LC_ALL=C readelf -h "$filename" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
# get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
sofile=$(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
[ -z "$sofile" ] && sofile="${filename##*/}"
# extract the library name: libfoo.so
soname="${sofile%%\.so\.*}.so"
# extract the major version: 1
soversion="${sofile##*\.so\.}"
if [[ "$soversion" = "$sofile" ]] && (($IGNORE_INTERNAL)); then
continue
fi
if ! in_array "${soname}=${soversion}-${soarch}" ${soprovides[@]}; then
# libfoo.so=1-64
echo "${soname}=${soversion}-${soarch}"
soprovides=(${soprovides[@]} "${soname}=${soversion}-${soarch}")
fi
fi
done
|