| Here's a script I've been using for several years on several different versions
of UNIX. I'm not the author, but I don't think there is a copyright problem in
posting it here. Feel free to use it yourself.
(Note that you might need to fix some line wrapping before use)
-Jeff
#!/bin/sh
#-------------------------------------------------------------------------------
#
# Script to produce consistent dynamic dependency information across platforms.
#
# Syntax: ldd <exe> ...
#
#-------------------------------------------------------------------------------
#
# To use the general code at the bottom of this script, you must define the
# following three functions:-
#
# need <file> - Returns the dynamic dependencies for the supplied
# file, one per line. If the dependency contains a "/"
# character then it will not be subject to a path
# search. A second word can be added to any line which
# supplies a default name to use if the search should
# fail.
#
# conlib <file> - Converts the supplied file name into a loader library
# reference (eg /lib/libc.a -> -lc) if it is of the
# correct form. Otherwise the original name will be
# returned.
#
# search <file> - Returns a colon separated search path for locating
# the dependencies of the supplied file.
#
#-------------------------------------------------------------------------------
#
# Switch on machine type
#
case `uname` in
#
# Use ldd for SunOS4
# - Loop over args as pipe suppresses output of filename
#
SunOS) for file do
if [ $# -gt 1 ]; then echo "$file:"; fi
/bin/ldd "$file" |
sed -e 's/^ / /' -e 's/ => / => /'
done
exit 0;;
#
# Define functions for HPUX 9
#
HP-UX) need() {
chatr $1 2>/dev/null | awk ' \
BEGIN { exe = 0; got = 0; } \
$0 ~ /^[ ]*shared executable[ ]*/ { exe = 1; } \
$0 ~ /^[ ]*demand load executable[ ]*/ { exe = 1; }
\
/^[ ]*shared library list:[ ]*$/ { \
got = 1; \
next; \
} \
got != 0 { \
if (NF == 2 && ($1 == "static" || $1 == "dynamic")) { \
if (!exe || got != 1) { \
if ($1 == "static") print $2; \
else { \
for (i=length($2)-1;i>0;i--) \
if (substr($2,i,1) == "/") break; \
print substr($2,i+1),$2; \
} \
} \
got++; \
} \
else got = 0; \
}'
}
conlib() {
echo "$1" | sed -e 's/^lib\(.*\)\.sl$/-l\1/'
}
search() {
temp=`chatr $1 2>/dev/null | awk ' \
BEGIN { got = 0; first=0; shlib=""; embed=""; } \
/^[ ]*shared library dynamic path search:[ ]*$/ { \
got = 1; \
next; \
} \
got != 0 { \
if ($1 == "SHLIB_PATH" && $2 == "enabled") { \
shlib = "$SHLIB_PATH"; \
first = ($3 == "first"); \
} \
if ($1 == "embedded" && $2 == "path" && $3 == "enabled"
&& (NF != 6 || $5 != "Not" || $6 != "Defined")) { \
first = ($4 != "first"); \
embed = $5; \
for (i=6; i<=NF; i++) embed = embed " " $i; \
} \
if (got++ > 2) exit; \
} \
END { \
if (first) print shlib ":" embed; \
else print embed ":" shlib; \
}'`
eval echo "$temp"
};;
#
# Define functions for Mips Irix 5
#
IRIX) need() {
odump -D $1 2>/dev/null |
sed -n 's/^[ ]*NEEDED:[ ]*//p'
}
rpath() {
odump -D $1 2>/dev/null |
sed -n 's/^[ ]*RPATH:[ ]*//p'
}
conlib() {
echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \
-e 's/^lib\(.*\)\.so$/-l\1/'
}
search() {
echo "`rpath
$1`:$LD_LIBRARY_PATH:/lib:/usr/lib:/lib/cmplrs/cc:/usr/lib/cmplrs/cc"
};;
#
# Define functions for Alpha OSF 1
#
OSF1) need() {
odump -D $1 2>/dev/null |
sed -n 's/^[ ]*NEEDED:[ ]*//p'
}
rpath() {
odump -D $1 2>/dev/null |
sed -n 's/^[ ]*RPATH:[ ]*//p'
}
conlib() {
echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \
-e 's/^lib\(.*\)\.so$/-l\1/'
}
search() {
echo "`rpath
$1`:$LD_LIBRARY_PATH:/usr/shlib:/usr/ccs/lib:/usr/lib/cmplrs/cc:/usr/lib:/usr/lo
cal/lib"
};;
#
# Define functions for Solaris 2
#
sparc_5) need() {
dump -Lv $1 2>/dev/null |
sed -n 's/^\[[0-9]*\][ ]*NEEDED[ ]*//p'
}
rpath() {
dump -Lv $1 2>/dev/null |
sed -n 's/^\[[0-9]*\][ ]*RPATH[ ]*//p'
}
conlib() {
echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \
-e 's/^lib\(.*\)\.so$/-l\1/'
}
search() {
echo "$LD_LIBRARY_PATH:`rpath $1`:/usr/ccs/lib:/usr/lib"
};;
#
# Unknown platforms
#
*) echo "$0 Not supported on this platform"
exit 1;;
esac
#
# Process files in turn
#
for file do
deps="`need $file`"
if [ -z "$deps" ]; then
if [ ! -f $file ]; then echo "$file: No such file or directory"
else echo "$file: Statically linked"; fi
continue
fi
if [ $# -gt 1 ]; then echo "$file:"; fi
scan=`search $file`
echo "$deps" | while read name def; do
case $name in
*/*) echo " $name";;
*) ( IFS=":"
soname=""
for path in $scan; do
if [ -f "$path/$name" ]; then
soname="$path/$name"
break;
fi
done
if [ -z "$soname" -a -f "$def" ]; then soname=$def; fi
echo " `conlib $name` => ${soname:-(not found)}"
);;
esac
done
done
|