kernel: update to 4.14.173
[ipfire-2.x.git] / src / stripper
CommitLineData
6c4cc7ea 1#!/usr/bin/env bash
bc259fdc
MT
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}
25d50589 20 local strip="${STRIP-strip}"
fc44fa1f 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
25d50589
MT
30 local cmd=( "${strip}" )
31
fc44fa1f 32 case "$(file -bi ${file})" in
25d50589
MT
33 application/x-archive*)
34 cmd+=( "--strip-debug" "--remove-section=.comment" "--remove-section=.note" )
fc44fa1f
MT
35 ;;
36 *)
25d50589 37 cmd+=( "--strip-all" )
fc44fa1f
MT
38 ;;
39 esac
40
41 echo "Stripping ${file}..."
25d50589 42 ${cmd[*]} ${file}
fc44fa1f
MT
43}
44
bc259fdc 45for dir in ${dirs}; do
d9bb5239 46 # Strip shared objects.
fc44fa1f 47 find ${dir} -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
2ee623a8 48 | file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped.*/\1/p' |
fc44fa1f 49 while read file; do
b98ca5fa
MT
50 _strip ${file} || exit $?
51 done || exit $?
d9bb5239
MT
52
53 # Strip static archives.
54 find ${dir} -name \*.a -a -exec file {} \; \
55 | grep 'current ar archive' | sed -n -e 's/^\(.*\):[ ]*current ar archive/\1/p' |
56 while read file; do
b98ca5fa
MT
57 _strip ${file} || exit $?
58 done || exit $?
fc44fa1f 59done