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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#!/bin/bash
#
# "ldd" wrapper for scratchbox 2, to be used in the "devel" mode
# (this wrapper requires that target tools are available
# at "/target_root")
#
# "ldd" is used to print shared libraries required by a program.
# Our problem is that it can be used to both host- and target
# binaries; this wrapper first detects the type of the binary,
# and then
# - runs the "ldd" from /target_root for target binaries
# - If host CPU architecture != target CPU architecture,
# runs the binary with LD_TRACE_LOADED_OBJECTS=yes if
# it is a host binary (there were to be problems running
# the real "ldd" from inside sb2, but running ld.so
# with that env.variable produces the required result)
# - If host CPU architecture == target CPU architecture,
# assumes that all binaries belong to the target.
# runs the binary with LD_TRACE_LOADED_OBJECTS=yes
# with target's ld.so.
#
# FIXME: Command line options only work with target binaries!
#
# Copyright (c) 2008 Nokia Corporation.
# All rights reserved.
# Author: Lauri T. Aarnio
#
# Licensed under GPL version 2
args="$*"
prog="$0"
progbase=`basename $0`
function error_not_inside_sb2()
{
echo "SB2: $progbase wrapper: This wrapper can only be used from inside"
echo "the scratchbox 2'ed environment"
exit 1
}
# Some dynamic libraries are reported as "host/dynamic",
# some as "host/static" by # "sb2-show binarytype".
# If the target CPU arch. is
# ompatible with the host, try to resolve
function host_compatible_binary()
{
if [ -z "$conf_target_ld_so" ]; then
target_ld_so=`grep '^conf_target_ld_so=' $SBOX_SESSION_DIR/exec_config.lua`
eval $target_ld_so
target_libpath=`grep '^conf_target_ld_so_library_path=' $SBOX_SESSION_DIR/exec_config.lua`
eval $target_libpath
fi
case "$conf_target_ld_so" in
"") # Failed to read from config file
;;
nil) # not set; assume that it belongs to the host.
LD_TRACE_LOADED_OBJECTS=yes $1
;;
*)
mapped_file=`$SBOX_SESSION_DIR/bin/sb2-show which $1`
LD_TRACE_LOADED_OBJECTS=yes $conf_target_ld_so --library-path $conf_target_ld_so_library_path $mapped_file
;;
esac
}
if [ -z "$SBOX_SESSION_DIR" ]
then
error_not_inside_sb2
fi
. $SBOX_SESSION_DIR/sb2-session.conf
if [ -z "$sbox_mapmode" -o -z "$sbox_dir" ]
then
error_not_inside_sb2
fi
# read-in mode-specific settings
if [ -f $sbox_dir/share/scratchbox2/modeconf/sb2rc.$sbox_mapmode ]
then
. $sbox_dir/share/scratchbox2/modeconf/sb2rc.$sbox_mapmode "$progbase"
fi
OPTIONS=""
FILES=""
NUM_FILES=0
for k in $args
do
case $k in
-*) OPTIONS="$OPTIONS $k";;
*) FILES="$FILES $k"
NUM_FILES=`expr $NUM_FILES + 1`;;
esac
done
if [ $NUM_FILES -eq 0 ]
then
exec /target_root/usr/bin/ldd $OPTIONS
fi
for f in $FILES
do
if [ $NUM_FILES -gt 1 ]
then
echo "$f:"
fi
type=`$SBOX_SESSION_DIR/bin/sb2-show binarytype $f`
case "$type" in
target*) /target_root/usr/bin/ldd $OPTIONS $f;;
host/*) host_compatible_binary $f;;
*) echo "ldd wrapper: Don't know how to handle $f (type=$type)"
esac
done
|