rstrip.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # $Id: rstrip.sh 440 2009-05-13 16:09:54Z wbx $
  2. #-
  3. # This file is part of the OpenADK project. OpenADK is copyrighted
  4. # material, please see the LICENCE file in the top-level directory.
  5. [[ -n $BASH_VERSION ]] && shopt -s extglob
  6. SELF=${0##*/}
  7. if [[ -z $prefix ]]; then
  8. echo >&2 "$SELF: strip command not defined ('prefix' variable not set)"
  9. exit 1
  10. fi
  11. if [[ $1 = +keep ]]; then
  12. stripcomm=
  13. shift
  14. else
  15. stripcomm=" -R .comment"
  16. fi
  17. TARGETS=$*
  18. if [[ -z $TARGETS ]]; then
  19. echo >&2 "$SELF: no directories / files specified"
  20. echo >&2 "usage: $SELF [PATH...]"
  21. exit 1
  22. fi
  23. find $TARGETS -type f -a -exec file {} \; | \
  24. while IFS= read -r line; do
  25. F=${line%%:*}
  26. V=${F##*/fake-+([!/])/}
  27. T="${prefix}strip"
  28. T=$T$stripcomm
  29. case $line in
  30. *ELF*executable*statically\ linked*)
  31. echo >&2 "$SELF: *WARNING* '$V' is not dynamically linked!"
  32. ;;
  33. esac
  34. case $line in
  35. *ELF*executable*,\ not\ stripped*)
  36. S=executable ;;
  37. */lib/modules/2.*.o:*ELF*relocatable*,\ not\ stripped* | \
  38. */lib/modules/2.*.ko:*ELF*relocatable*,\ not\ stripped*)
  39. # kernel module parametres must not be stripped off
  40. T="$T --strip-unneeded $(echo $(${prefix}nm $F | \
  41. sed -n -e '/__param_/s/^.*__param_/-K /p' \
  42. -e '/__module_parm_/s/^.*__module_parm_/-K /p'))"
  43. S='kernel module' ;;
  44. *ELF*relocatable*,\ not\ stripped*)
  45. S=relocatable ;;
  46. *ELF*shared\ object*,\ not\ stripped*)
  47. S='shared object' ;;
  48. *)
  49. continue ;;
  50. esac
  51. echo "$SELF: $V:$S"
  52. #echo "+ $T $F"
  53. eval "$T $F"
  54. done