stripper: Strip static archives.
[people/teissler/ipfire-2.x.git] / src / stripper
1 #!/bin/bash
2
3 function _strip() {
4 local file=${1}
5
6 local cmd="${STRIP-strip}"
7
8 case "$(file -bi ${file})" in
9 application/x-sharedlib*|application/x-archive*)
10 cmd="${cmd} --strip-debug --remove-section=.comment --remove-section=.note"
11 ;;
12 *)
13 cmd="${cmd} --strip-unneeded"
14 ;;
15 esac
16
17 echo "Stripping ${file}..."
18 ${cmd} ${file}
19 }
20
21 for dir in $@; do
22 # Strip shared objects.
23 find ${dir} -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
24 | file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped/\1/p' |
25 while read file; do
26 _strip ${file}
27 done
28
29 # Strip static archives.
30 find ${dir} -name \*.a -a -exec file {} \; \
31 | grep 'current ar archive' | sed -n -e 's/^\(.*\):[ ]*current ar archive/\1/p' |
32 while read file; do
33 _strip ${file}
34 done
35 done