3 # Script to install host system binaries along with required libraries.
4 # Refer to the --help output for more information.
6 # Copyright (C) 2012 Jo-Philipp Wich <jow@openwrt.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 cp ${VERBOSE:+-v} -L "$1" "$2" || {
26 echo "cp($1 $2) failed" >&2
32 mkdir ${VERBOSE:+-v} -p "$1" || {
33 echo "mkdir($1) failed" >&2
39 ln ${VERBOSE:+-v} -sf "$1" "$2" || {
40 echo "ln($1 $2) failed" >&2
45 for LDD in ${PATH//://ldd }/ldd; do
46 "$LDD" --version >/dev/null 2>/dev/null && break
50 [ -n "$LDD" -a -x "$LDD" ] || {
51 echo "Unable to find working ldd" >&2
56 [ -n "$BIN" -a -x "$BIN" -a -n "$DIR" ] || {
57 echo "Usage: $0 <destdir> <executable> ..." >&2
61 [ ! -d "$DIR/bundled/lib" ] && {
62 _md "$DIR/bundled/lib"
63 _md "$DIR/bundled/usr"
64 _ln "../lib" "$DIR/bundled/usr/lib"
69 echo "Bundling ${BIN##*/}"
70 for token in $("$LDD" "$BIN" 2>/dev/null); do
71 case "$token" in */*.so*)
73 *ld-*.so*) LDSO="${token##*/}" ;;
74 *) echo " * lib: ${token##*/}" ;;
77 dest="$DIR/bundled/lib/${token##*/}"
80 [ -f "$token" -a ! -f "$dest" ] && {
89 # is a dynamically linked executable
90 if [ -n "$LDSO" ]; then
91 _cp "$BIN" "$DIR/bundled/${BIN##*/}"
93 [ -x "$DIR/bundled/run.sh" ] || {
94 cat <<-EOF > "$DIR/bundled/run.sh"
96 dir="\$(dirname "\$0")"
97 bin="\$(basename "\$0")"
98 exec -a "\$0" "\$dir/bundled/lib/$LDSO" --library-path "\$dir/bundled/lib" "\$dir/bundled/\$bin" "\$@"
100 chmod ${VERBOSE:+-v} 0755 "$DIR/bundled/run.sh"
103 _ln "./bundled/run.sh" "$DIR/${BIN##*/}"
105 # is a static executable or non-elf binary
107 echo " * not dynamically linked"
108 _cp "$BIN" "$DIR/${BIN##*/}"