update from main archive 970120
[platform/upstream/glibc.git] / elf / ldd.bash.in
1 #! @BASH@
2
3 # Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
10
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Library General Public License for more details.
15
16 # You should have received a copy of the GNU Library General Public
17 # License along with the GNU C Library; see the file COPYING.LIB.  If not,
18 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
20
21
22 # This is the `ldd' command, which lists what shared libraries are
23 # used by given dynamically-linked executables.  It works by invoking the
24 # run-time dynamic linker as a command and setting the environment
25 # variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
26
27 # We should be able to find the translation right at the beginning.
28 TEXTDOMAIN=libc
29 TEXTDOMAINDIR=@TEXTDOMAINDIR@
30
31 RTLD=@RTLD@
32 RELOCS=
33
34 while test $# -gt 0; do
35   case "$1" in
36   --v | --ve | --ver | --vers | --versi | --versio | --version)
37     echo $"ldd (GNU libc) @VERSION@
38 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
39 This is free software; see the source for copying conditions.  There is NO
40 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
41     exit 0 ;;
42   --h | --he | --hel | --help)
43     echo $"ldd [OPTION]... FILE...
44       --help              print this help and exit
45       --version           print version information and exit
46   -d, --data-relocs       process data relocations
47   -r, --function-relocs   process data and function relocations
48 Report bugs using the \`glibcbug' script to <bugs@gnu.ai.mit.edu>."
49     exit 0 ;;
50   -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
51   --data-rel | --data-relo | --data-reloc | --data-relocs)
52     RELOCS='--data-relocs'
53     shift ;;
54   -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
55   --function | --function- | --function-r | --function-re | --function-rel | \
56   --function-relo | --function-reloc | --function-relocs)
57     RELOCS='--function-relocs'
58     shift ;;
59   --)           # Stop option processing.
60     shift; break ;;
61   -*)
62     echo >&2 $"ldd: unrecognized option" "\`$1'"
63     echo >&2 $"Try \`ldd --help' for more information."
64     exit 1 ;;
65   *)
66     break ;;
67   esac
68 done
69
70 case $# in
71 0)
72   echo >&2 $"ldd: missing file arguments"
73   echo >&2 $"Try \`ldd --help' for more information."
74   exit 1 ;;
75 1)
76   # We don't list the file name when there is only one.
77   case "$1" in
78   /*) file="$1" ;;
79   *) file="./$1" ;;
80   esac
81   if test ! -f "$file"; then
82     echo "${file}:" $"no such file"
83     exit 1
84   else
85     test -x "$file" ||
86       echo $"warning: you do not have execution permission for" "\`$file'"
87     if ${RTLD} --verify "$file"; then
88       LD_TRACE_LOADED_OBJECTS=1 exec ${RTLD} ${RELOCS} "$file" || exit 1
89     else
90       echo $"   not a dynamic executable"
91       exit 1
92     fi
93   fi
94   exit ;;
95 *)
96   set -e        # Bail out immediately if ${RTLD} loses on any argument.
97   result=0
98   for file; do
99     echo "${file}:"
100     case "$file" in
101     /*) : ;;
102     *) file="./$file" ;;
103     esac
104     if test ! -f "$file"; then
105       echo "${file}:" $"no such file"
106       result=1
107     else
108       test -x "$file" ||
109         echo $"warning: you do not have execution permission for" "\`$file'"
110       if ${RTLD} --verify "$file"; then
111         LD_TRACE_LOADED_OBJECTS=1 ${RTLD} ${RELOCS} "$file" || result=1
112       else
113         echo $" not a dynamic executable"
114         result=1
115       fi
116     fi
117   done
118 esac
119
120 exit $result
121 # Local Variables:
122 #  mode:ksh
123 # End: