1
0

rstrip.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. [[ -n $BASH_VERSION ]] && shopt -s extglob
  4. SELF=${0##*/}
  5. if [[ -z $prefix ]]; then
  6. echo >&2 "$SELF: strip command not defined ('prefix' variable not set)"
  7. exit 1
  8. fi
  9. if [[ $1 = +keep ]]; then
  10. stripcomm=
  11. shift
  12. else
  13. stripcomm=" -R .comment"
  14. fi
  15. TARGETS=$*
  16. if [[ -z $TARGETS ]]; then
  17. echo >&2 "$SELF: no directories / files specified"
  18. echo >&2 "usage: $SELF [PATH...]"
  19. exit 1
  20. fi
  21. find $TARGETS -type f -a -exec file {} \; | \
  22. while IFS= read -r line; do
  23. F=${line%%:*}
  24. D=${TARGETS}-dbg
  25. V=${F##*/fake-+([!/])/}
  26. P=${F##*/pkg-+([!/])/}
  27. Q=${P%/*}
  28. R=${P##*/}
  29. T="${prefix}strip"
  30. O="${prefix}objcopy"
  31. T=$T$stripcomm
  32. case $line in
  33. *ELF*executable*statically\ linked*)
  34. ;;
  35. *ELF*relocatable*,\ not\ stripped*)
  36. ;;
  37. esac
  38. case $line in
  39. *ELF*executable*,\ not\ stripped*)
  40. S=executable ;;
  41. */lib/modules/3.*.o:*ELF*relocatable*,\ not\ stripped* | \
  42. */lib/modules/3.*.ko:*ELF*relocatable*,\ not\ stripped*)
  43. # kernel module parametres must not be stripped off
  44. T="$T --strip-unneeded $(echo $(${prefix}nm $F | \
  45. sed -n -e '/__param_/s/^.*__param_/-K /p' \
  46. -e '/__module_parm_/s/^.*__module_parm_/-K /p'))"
  47. S='kernel module' ;;
  48. *ELF*shared\ object*,\ not\ stripped*)
  49. S='shared object' ;;
  50. *current\ ar\ archive*)
  51. S='static library'
  52. T="$T -S" ;;
  53. *)
  54. continue ;;
  55. esac
  56. echo "$SELF: $V:$S"
  57. echo "-> $T $F"
  58. eval "chmod u+w $F"
  59. if [[ $debug -ne 0 ]];then
  60. echo "mkdir for $D" >> /tmp/debug
  61. eval "mkdir -p $D/usr/lib/debug/$Q"
  62. eval "$O --only-keep-debug $F $D/usr/lib/debug/$P.debug"
  63. fi
  64. eval "$T $F"
  65. if [[ $debug -ne 0 ]];then
  66. eval "cd $D/usr/lib/debug/$Q && $O --add-gnu-debuglink=$R.debug $F"
  67. fi
  68. done
  69. exit 0