scripts: bundle-libraries.sh: fix broken SDK compiler
[openwrt/openwrt.git] / scripts / bundle-libraries.sh
index 4662b98dee9a77a3730fbe48888baef349d5bc0d..90002453ecce6764afe0d01f4275c9783de7841e 100755 (executable)
@@ -125,6 +125,23 @@ _patch_glibc() {
        fi
 }
 
+should_be_patched() {
+       local bin="$1"
+
+       [ -x "$bin" ] || return 1
+
+       case "$bin" in
+               *.so|*.so.[0-9]*)
+                       return 1
+               ;;
+               *)
+                       file "$bin" | grep -sqE "ELF.*(executable|interpreter)" && return 0
+               ;;
+       esac
+
+       return 1
+}
+
 for LDD in ${PATH//://ldd }/ldd; do
        "$LDD" --version >/dev/null 2>/dev/null && break
        LDD=""
@@ -150,23 +167,22 @@ for BIN in "$@"; do
 
        LDSO=""
 
-       [ -n "$LDD" ] && [ -x "$BIN" ] && file "$BIN" | grep -sqE "ELF.*(executable|interpreter)" && {
+       [ -n "$LDD" ] && should_be_patched "$BIN" && {
                for token in $("$LDD" "$BIN" 2>/dev/null); do
                        case "$token" in */*.so*)
                                dest="$DIR/lib/${token##*/}"
                                ddir="${dest%/*}"
 
+                               case "$token" in
+                                       */ld-*.so*) LDSO="${token##*/}" ;;
+                               esac
+
                                [ -f "$token" -a ! -f "$dest" ] && {
                                        _md "$ddir"
                                        _cp "$token" "$dest"
                                        case "$token" in
-                                               *ld-*.so*)
-                                                       LDSO="${token##*/}"
-                                                       _patch_ldso "$dest"
-                                               ;;
-                                               libc.so.6|*/libc.so.6)
-                                                       _patch_glibc "$dest"
-                                               ;;
+                                               */ld-*.so*) _patch_ldso "$dest" ;;
+                                               */libc.so.6) _patch_glibc "$dest" ;;
                                        esac
                                }
                        ;; esac