This repository has been archived by the owner on Jan 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
strip.sh
executable file
·69 lines (60 loc) · 2.31 KB
/
strip.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
RO_ROOT=romfs
TOOLSPREFIX=./toolchain/bin/mipsel-linux-uclibc
STRIPOPT="-R .note -R .comment -R .pdr -R .mdebug.abi32 -R .note.gnu.build-id -R .gnu.attributes -R .reginfo -g --strip-unneeded"
STRIP="$TOOLSPREFIX-strip $STRIPOPT"
OBJCOPY="$TOOLSPREFIX-objcopy $STRIPOPT"
SSTRIP="./toolchain/tools/bin/sstrip"
echo --------------------------------GENERATE CONFIG-----------------------------
. linux/.config
. config/.config
SCONFIG_SH=$RO_ROOT/etc/scripts/config.sh
:>"$SCONFIG_SH"
echo "Search for parameters used"
PARAMS=
tmp=
for dir in $RO_ROOT/etc/rc.d $RO_ROOT/etc/scripts
do
tmp="$( grep -r -o "\$CONFIG_[^ \t\"]\+" "$dir"/* | sed 's/^.*$CONFIG_\(.\+\)$/\1/' | sort -u )"
PARAMS="$PARAMS $tmp"
done
echo "Need variables: $PARAMS"
for i in $PARAMS; do
var=$( eval "echo \$CONFIG_$i" )
if [ $var ]; then
echo "Found CONFIG_$i"
echo "CONFIG_$i=$var" >> "$SCONFIG_SH"
fi
done
sort -u "$SCONFIG_SH" > "$SCONFIG_SH.tmp"
mv -f "$SCONFIG_SH.tmp" "$SCONFIG_SH"
chmod 777 "$SCONFIG_SH"
echo -------------------------------FIND FILES TO STRIP-----------------------------
NON_STRIPS_BIN=`find $RO_ROOT/bin -type f -print -exec file {} \; | grep -vE "modules|icon|start|/rc|/fs|\.sh|\.dat" | cut -d":" -f1`
NON_STRIPS_LIB=`find $RO_ROOT/lib -type f -print -exec file {} \; | grep -vE "modules|libc.so|libpthread.so|\.a|\.la|\.pc|\.dat" | cut -d":" -f1`
echo -----------------------------------STRIP BIN----------------------------------
for i in $NON_STRIPS_BIN; do
echo $i;
$OBJCOPY $i $i
done
if [ -n "$NON_STRIPS_BIN" ]; then
echo BIN: $NON_STRIPS_BIN
$STRIP $NON_STRIPS_BIN
$SSTRIP $NON_STRIPS_BIN
fi
echo -----------------------------------STRIP LIB----------------------------------
for i in $NON_STRIPS_LIB; do
echo $i;
$OBJCOPY $i $i
done
if [ "$NON_STRIPS_LIB" != "" ]; then
echo LIB: $NON_STRIPS_LIB
$STRIP $NON_STRIPS_LIB
$SSTRIP $NON_STRIPS_LIB
fi
echo -----------------------------------STRIP MODULES----------------------------------
find $RO_ROOT/lib/modules -type f -name '*.ko' | xargs -r $STRIP $STRIPOPT
find $RO_ROOT/lib/modules -type f -name '*.ko' -print -print | xargs -n2 -r $OBJCOPY $STRIPOPT
echo -----------------------------------SYNC!!-------------------------------------
sync
echo ----------------------------APP STRIP AND COPY OK-----------------------------