rstrip.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. *ELF*relocatable*,\ not\ stripped*)
  34. echo >&2 "$SELF: *WARNING* '$V' is a relocatable!"
  35. ;;
  36. esac
  37. case $line in
  38. *ELF*executable*,\ not\ stripped*)
  39. S=executable ;;
  40. */lib/modules/2.*.o:*ELF*relocatable*,\ not\ stripped* | \
  41. */lib/modules/2.*.ko:*ELF*relocatable*,\ not\ stripped*)
  42. # kernel module parametres must not be stripped off
  43. T="$T --strip-unneeded $(echo $(${prefix}nm $F | \
  44. sed -n -e '/__param_/s/^.*__param_/-K /p' \
  45. -e '/__module_parm_/s/^.*__module_parm_/-K /p'))"
  46. S='kernel module' ;;
  47. *ELF*shared\ object*,\ not\ stripped*)
  48. S='shared object' ;;
  49. *)
  50. continue ;;
  51. esac
  52. echo "$SELF: $V:$S"
  53. echo "-> $T $F"
  54. eval "$T $F"
  55. done