3 # Script to install host system binaries along with required libraries.
5 # Copyright (C) 2012-2013 Jo-Philipp Wich <jow@openwrt.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 cp ${VERBOSE:+-v} -L "$1" "$2" || {
25 echo "cp($1 $2) failed" >&2
31 mkdir ${VERBOSE:+-v} -p "$1" || {
32 echo "mkdir($1) failed" >&2
38 ln ${VERBOSE:+-v} -sf "$1" "$2" || {
39 echo "ln($1 $2) failed" >&2
44 for LDD in ${PATH//://ldd }/ldd; do
45 "$LDD" --version >/dev/null 2>/dev/null && break
49 [ -n "$LDD" -a -x "$LDD" ] || LDD=
52 [ -n "$BIN" -a -x "$BIN" -a -n "$DIR" ] || {
53 echo "Usage: $0 <destdir> <executable> ..." >&2
57 [ ! -d "$DIR/bundled/lib" ] && {
58 _md "$DIR/bundled/lib"
59 _md "$DIR/bundled/usr"
60 _ln "../lib" "$DIR/bundled/usr/lib"
65 echo "Bundling ${BIN##*/}"
67 for token in $("$LDD" "$BIN" 2>/dev/null); do
68 case "$token" in */*.so*)
70 *ld-*.so*) LDSO="${token##*/}" ;;
71 *) echo " * lib: ${token##*/}" ;;
74 dest="$DIR/bundled/lib/${token##*/}"
77 [ -f "$token" -a ! -f "$dest" ] && {
87 # is a dynamically linked executable
88 if [ -n "$LDSO" ]; then
89 _cp "$BIN" "$DIR/bundled/${BIN##*/}"
91 RUN="${LDSO#ld-}"; RUN="run-${RUN%%.so*}.sh"
93 [ -x "$DIR/bundled/$RUN" ] || {
94 cat <<-EOF > "$DIR/bundled/$RUN"
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"
103 _ln "./bundled/$RUN" "$DIR/${BIN##*/}"
105 # is a static executable or non-elf binary
107 [ -n "$LDD" ] && echo " * not dynamically linked"
108 _cp "$BIN" "$DIR/${BIN##*/}"