~ubuntu-branches/ubuntu/lucid/nspluginwrapper/lucid

« back to all changes in this revision

Viewing changes to utils/getdeps.sh

  • Committer: Bazaar Package Importer
  • Author(s): Rob Andrews
  • Date: 2007-05-10 12:17:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070510121709-xb8fx1cmr6kae2ba
Tags: upstream-0.9.91.4
ImportĀ upstreamĀ versionĀ 0.9.91.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
#  getdeps.sh - get dependent libs of a program
 
4
#
 
5
#  nspluginwrapper (C) 2005-2007 Gwenole Beauchesne
 
6
#
 
7
 
 
8
# FIXME: needs pango config files, extra X11 libraries, etc. Thus it's
 
9
# better to rewrite the script so that to install from the actual RPMs...
 
10
 
 
11
function fatal_error() {
 
12
    echo "Error:" ${1+"$@"} >/dev/stderr
 
13
    exit 1
 
14
}
 
15
 
 
16
if [[ $# -ne 1 ]]; then
 
17
    echo "Usage: $0 <PROGRAM>"
 
18
    exit 1
 
19
fi
 
20
 
 
21
FILE=$1
 
22
[[ -f "$FILE" ]] || fatal_error "specified program $file does not exist"
 
23
 
 
24
nLIBS=0
 
25
declare -a LIBS
 
26
 
 
27
nDEPS=0
 
28
declare -a DEPS
 
29
 
 
30
function path_find() {
 
31
    local var=$1
 
32
    local path=$2
 
33
    eval "echo \" \${$var[*]} \"" | grep -q $path
 
34
}
 
35
 
 
36
function path_add() {
 
37
    local var=$1
 
38
    local path=$2
 
39
    path_find $var $path || {
 
40
        eval "$var[n$var]=$path ; n$var=\$((n$var+1))"
 
41
        [[ -L $path ]] && {
 
42
            link=`readlink $path`
 
43
            case $link in
 
44
                /*|../*)
 
45
                    fatal_error "links to files in other paths are not supported"
 
46
                    ;;
 
47
                *)
 
48
                    link="`dirname $path`/$link"
 
49
            esac
 
50
            eval "$var[n$var]=$link ; n$var=\$((n$var+1))"
 
51
        }
 
52
    }
 
53
}
 
54
 
 
55
function get_deps() {
 
56
    local file=$1
 
57
    path_find LIBS $file || {
 
58
        path_add LIBS $file
 
59
        local paths=`ldd $file | sed -n '/^[^l]*\(lib[^ ]*\) => \(\/[^ ]*\).*/s//\2/p'`
 
60
        for fullpath in $paths; do
 
61
            local path=`echo $fullpath | sed -e 's/\(\/lib[0-9]*\)\/\(tls\|i686\|mmx\|sse[23]*\)/\1/'`
 
62
            path_add DEPS $path
 
63
            get_deps $path
 
64
        done
 
65
    }
 
66
}
 
67
 
 
68
ldso=`ldd $FILE | sed -n '/^[^\/]*\(\/[^ ]*ld-[^ ]*\) .*/s//\1/p'`
 
69
path_add DEPS $ldso
 
70
 
 
71
get_deps $FILE
 
72
echo ${DEPS[*]}
 
73
exit 0