Merge remote-tracking branch 'origin/next' into thirteen
[ipfire-2.x.git] / src / stripper
CommitLineData
bc259fdc
MT
1#!/tools/bin/bash
2
3dirs=""
4excludes="/dev /proc /sys /run"
5
6while [ $# -gt 0 ]; do
7 case "${1}" in
8 --exclude=*)
9 excludes="${excludes} ${1#*=}"
10 ;;
11 *)
12 dirs="${dirs} ${1}"
13 ;;
14 esac
15 shift
16done
fc44fa1f
MT
17
18function _strip() {
19 local file=${1}
fc44fa1f
MT
20 local cmd="${STRIP-strip}"
21
bc259fdc
MT
22 local exclude l
23 for exclude in ${excludes}; do
24 l=${#exclude}
25 if [ "${file:0:${l}}" = "${exclude}" ]; then
26 return 0
27 fi
28 done
29
fc44fa1f 30 case "$(file -bi ${file})" in
d9bb5239 31 application/x-sharedlib*|application/x-archive*)
fc44fa1f
MT
32 cmd="${cmd} --strip-debug --remove-section=.comment --remove-section=.note"
33 ;;
34 *)
35 cmd="${cmd} --strip-unneeded"
36 ;;
37 esac
38
39 echo "Stripping ${file}..."
40 ${cmd} ${file}
41}
42
bc259fdc 43for dir in ${dirs}; do
d9bb5239 44 # Strip shared objects.
fc44fa1f
MT
45 find ${dir} -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
46 | file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped/\1/p' |
47 while read file; do
48 _strip ${file}
49 done
d9bb5239
MT
50
51 # Strip static archives.
52 find ${dir} -name \*.a -a -exec file {} \; \
53 | grep 'current ar archive' | sed -n -e 's/^\(.*\):[ ]*current ar archive/\1/p' |
54 while read file; do
55 _strip ${file}
56 done
fc44fa1f 57done