1
0

rstrip.sh 1.4 KB

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