add some debug output, which has the nice side effect to fix timing issues while...
[openadk.git] / scripts / rstrip.sh
blob00feb8cf822d1936b4b0d0fe63b8f706e82cc097
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 D=${TARGETS}-dbg
32 V=${F##*/fake-+([!/])/}
33 P=${F##*/pkg-+([!/])/}
34 Q=${P%/*}
35 R=${P##*/}
36 T="${prefix}strip"
37 O="${prefix}objcopy"
38 T=$T$stripcomm
39 case $line in
40 *ELF*executable*statically\ linked*)
42 *ELF*relocatable*,\ not\ stripped*)
44 esac
45 case $line in
46 *ELF*executable*,\ not\ stripped*)
47 S=executable ;;
48 */lib/modules/*.o:*ELF*relocatable*,\ not\ stripped* | \
49 */lib/modules/*.ko:*ELF*relocatable*,\ not\ stripped*)
50 # kernel module parametres must not be stripped off
51 T="$T --strip-unneeded $(echo $(${prefix}nm $F | \
52 sed -n -e '/__param_/s/^.*__param_/-K /p' \
53 -e '/__module_parm_/s/^.*__module_parm_/-K /p'))"
54 S='kernel module' ;;
55 *ELF*shared\ object*,\ not\ stripped*)
56 S='shared object' ;;
57 *current\ ar\ archive*)
58 S='static library'
59 T="$T -S" ;;
61 continue ;;
62 esac
63 echo "$SELF: $V:$S"
64 echo "-> $T $F"
65 eval "chmod u+w $F"
66 if [[ $debug -ne 0 ]];then
67 eval "mkdir -p $D/usr/lib/debug/$Q"
68 eval "$O --only-keep-debug $F $D/usr/lib/debug/$P.debug"
70 eval "$T $F"
71 if [[ $debug -ne 0 ]];then
72 eval "cd $D/usr/lib/debug/$Q && $O --add-gnu-debuglink=$R.debug $F"
74 done
75 exit 0