1
0

rstrip.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/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. #
  8. SELF=${0##*/}
  9. [ -z "$STRIP" ] && {
  10. echo "$SELF: strip command not defined (STRIP variable not set)"
  11. exit 1
  12. }
  13. TARGETS=$*
  14. [ -z "$TARGETS" ] && {
  15. echo "$SELF: no directories / files specified"
  16. echo "usage: $SELF [PATH...]"
  17. exit 1
  18. }
  19. find $TARGETS -type f -a -exec file {} \; | \
  20. sed -n -e 's/^\(.*\):.*ELF.*\(executable\|relocatable\|shared object\).*,.*/\1:\2/p' | \
  21. (
  22. IFS=":"
  23. while read F S; do
  24. echo "$SELF: $F: $S"
  25. [ "${S}" = "relocatable" ] && {
  26. eval "$STRIP_KMOD $F"
  27. } || {
  28. b=$(stat -c '%a' $F)
  29. [ -z "$PATCHELF" ] || [ -z "$TOPDIR" ] || {
  30. old_rpath="$($PATCHELF --print-rpath $F)"; new_rpath=""
  31. for path in $old_rpath; do
  32. case "$path" in
  33. /lib/[^/]*|/usr/lib/[^/]*|\$ORIGIN/*|\$ORIGIN) new_rpath="${new_rpath:+$new_rpath:}$path" ;;
  34. *) echo "$SELF: $F: removing rpath $path" ;;
  35. esac
  36. done
  37. [ "$new_rpath" = "$old_rpath" ] || $PATCHELF --set-rpath "$new_rpath" $F
  38. }
  39. eval "$STRIP $F"
  40. a=$(stat -c '%a' $F)
  41. [ "$a" = "$b" ] || chmod $b $F
  42. }
  43. done
  44. true
  45. )