Kernel .config
[tomato.git] / release / tools / optimize_lib.sh
blobc3e6dd6dbef36b7b307a58af2d2f3a25f1afcdc8
1 #!/bin/sh
3 #set -x
5 NM=mipsel-uclibc-nm
6 LD=mipsel-uclibc-ld
7 STRIP=mipsel-uclibc-strip
9 DIR=$1
10 LIB_SO=$2
11 LIB_A=$3
12 LIB_SO_M=$4
13 SEARCHDIR=$5
14 INSTALLLIB=$6
16 MAP=${DIR}/.map
17 SYM=${DIR}/.sybmols
18 UNR=${DIR}/.unresolved
19 BINARIES=`find $SEARCHDIR -path $SEARCHDIR/lib -prune -o -type f -print | file -f - | grep ELF | cut -d':' -f1`
21 if [ ! -f ${DIR}/${LIB_SO} ] ; then
22 echo "Cann't find ${DIR}/${LIB_SO}";
23 exit 0;
26 if [ ! -f ${DIR}/${LIB_A} ] ; then
27 echo "Cann't find ${DIR}/${LIB_A}";
28 exit 0;
31 rm -f $MAP
32 rm -f $SYM
33 rm -f $UNR
35 $NM -o --defined-only --no-sort ${DIR}/${LIB_SO} | cut -d' ' -f3 > $MAP
36 $NM --dynamic -u --no-sort $BINARIES | sort -u > $UNR
37 for symbol in `cat $UNR` ; do
38 if grep -q "^$symbol" $MAP ; then echo "-u $symbol" >> $SYM ;
39 fi ; done
41 if ls $SYM ; then
42 xargs -t $LD -shared -o ${DIR}/${LIB_SO_M} ${DIR}/${LIB_A} < $SYM ;
45 if [ "a$INSTALLLIB" != "a" -a -f ${DIR}/${LIB_SO_M} ] ; then
46 install ${DIR}/${LIB_SO_M} $INSTALLLIB
47 $STRIP $INSTALLLIB