add header subpackages
[openadk.git] / scripts / rstrip.sh
blob951362d35ecb69506e9fb9489ad2a537f27e3955
1 # This file is part of the OpenADK project. OpenADK is copyrighted
2 # material, please see the LICENCE file in the top-level directory.
4 [[ -n $BASH_VERSION ]] && shopt -s extglob
6 SELF=${0##*/}
8 if [[ -z $prefix ]]; then
9 echo >&2 "$SELF: strip command not defined ('prefix' variable not set)"
10 exit 1
13 if [[ $1 = +keep ]]; then
14 stripcomm=
15 shift
16 else
17 stripcomm=" -R .comment"
20 TARGETS=$*
22 if [[ -z $TARGETS ]]; then
23 echo >&2 "$SELF: no directories / files specified"
24 echo >&2 "usage: $SELF [PATH...]"
25 exit 1
28 find $TARGETS -type f -a -exec file {} \; | \
29 while IFS= read -r line; do
30 F=${line%%:*}
31 V=${F##*/fake-+([!/])/}
32 T="${prefix}strip"
33 T=$T$stripcomm
34 case $line in
35 *ELF*executable*statically\ linked*)
37 *ELF*relocatable*,\ not\ stripped*)
39 esac
40 case $line in
41 *ELF*executable*,\ not\ stripped*)
42 S=executable ;;
43 */lib/modules/2.*.o:*ELF*relocatable*,\ not\ stripped* | \
44 */lib/modules/2.*.ko:*ELF*relocatable*,\ not\ stripped*)
45 # kernel module parametres must not be stripped off
46 T="$T --strip-unneeded $(echo $(${prefix}nm $F | \
47 sed -n -e '/__param_/s/^.*__param_/-K /p' \
48 -e '/__module_parm_/s/^.*__module_parm_/-K /p'))"
49 S='kernel module' ;;
50 *ELF*shared\ object*,\ not\ stripped*)
51 S='shared object' ;;
53 continue ;;
54 esac
55 echo "$SELF: $V:$S"
56 echo "-> $T $F"
57 eval "chmod u+w $F"
58 eval "$T $F"
59 done
60 exit 0