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