blob: 2aa7e96fdac6fb8af02f04a29a3cbb146a545cda [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/usr/bin/env bash
2#
3# Copyright (C) 2006 OpenWrt.org
4#
5# This is free software, licensed under the GNU General Public License v2.
6# See /LICENSE for more information.
7#
8SELF=${0##*/}
9
10[ -z "$STRIP" ] && {
11 echo "$SELF: strip command not defined (STRIP variable not set)"
12 exit 1
13}
14
15TARGETS=$*
16
17[ -z "$TARGETS" ] && {
18 echo "$SELF: no directories / files specified"
19 echo "usage: $SELF [PATH...]"
20 exit 1
21}
22
23find $TARGETS -not -path \*/lib/firmware/\* -a -type f -a -exec file {} \; | \
24 sed -n -e 's/^\(.*\):.*ELF.*\(executable\|relocatable\|shared object\).*,.*/\1:\2/p' | \
25(
26 IFS=":"
27 while read F S; do
28 echo "$SELF: $F: $S"
29 [ "${S}" = "relocatable" ] && {
30 [ "${F##*.}" == "o" ] && continue
31 eval "$STRIP_KMOD $F"
32 } || {
33 b=$(stat -c '%a' $F)
34 [ -z "$PATCHELF" ] || [ -z "$TOPDIR" ] || {
35 old_rpath="$($PATCHELF --print-rpath $F)"; new_rpath=""
36 for path in $old_rpath; do
37 case "$path" in
38 /lib/[^/]*|/usr/lib/[^/]*|\$ORIGIN/*|\$ORIGIN) new_rpath="${new_rpath:+$new_rpath:}$path" ;;
39 *) echo "$SELF: $F: removing rpath $path" ;;
40 esac
41 done
42 [ "$new_rpath" = "$old_rpath" ] || $PATCHELF --set-rpath "$new_rpath" $F
43 }
44 eval "$STRIP $F"
45 a=$(stat -c '%a' $F)
46 [ "$a" = "$b" ] || chmod $b $F
47 }
48 done
49 true
50)