2007年6月26日 星期二

檢查 library dependency 的小工具

在開發"手工打造"的 Embedded System 時,可能會遇到library depency 的問題
而我們不見得能一下子就知道這個 library 的 dependency (請使用 ldd or objdump)

愛偷懶的小弟因為懶得算 dependency,就寫了一支小 script 幫我算

它可以把我所指定的程式所依賴的 library 找出來,如果在我的 target 之中沒有它就把它從 library source copy 過來 (這樣就可以找出 library 的最小集合)

它可以搭配其它 script 使用,做到完全自動化計算 library dependency

個人覺得還蠻方便的,分享給大家

File: checklib.sh


#!/bin/bash
# This software may be used and distributed according to the terms
# of the GNU General Public License (GPL), incorporated herein by reference.

# Drivers based on this skeleton fall under the GPL and must retain
# the authorship (implicit copyright) notice.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

# General Public License for more details.

#composer Tick


LIB_SOURCE_PATH="/Project/tank/lib/ /usr/toolchain/arm-linux/arm-linux/lib"
REFERENCE_LIB_PATH="/path to my project rootfs/disk/lib/"
TARGET_LIB_PATH="/path to my project rootfs/disk/lib/"

LIBS=""
for file_tmp in $@;do
FILE=`file $file_tmp`
if (( `echo $FILE | grep "dynamically linked" | wc -l` == 0 )) ;then
continue;
fi
if [ "`echo $FILE | awk '{print $7}'`" = "80386," ];then
OBJDUMP="objdump"
else
OBJDUMP="arm-linux-objdump"
fi
LIBS+=`${OBJDUMP} -p $file_tmp | awk '/NEEDED/ {printf("%s ",$2); }'`
done

for lib_tmp in $LIBS;do
IS_exist=0
for SS in ${REFERENCE_LIB_PATH};do
if (( `find $SS -name ${lib_tmp} | wc -l` > 0));then
IS_exist=1;
break;
fi
done
if (( ${IS_exist} > 0 )); then
continue;
fi
SRC_LIB=""
for SS in ${LIB_SOURCE_PATH};do
SRC_LIB="${SRC_LIB} `find ${SS} -name ${lib_tmp}`"
done
if [ $SRC_LIB ];then
SRC_BASE=`echo $SRC_LIB | awk '{stop=index($0,".so");ans=substr($0,0,stop-1);print ans}'`
echo "You are going to copy the following libraries to ${TARGET_LIB_PATH}:"
echo "cp -av ${SRC_BASE}[0-9.]*[!a] to ${TARGET_LIB_PATH}"
echo -n "continue? "
read ans;
if [ "$ans" = "y" ] || [ "$ans" = "Y" ];then
cp -av ${SRC_BASE}[\.0-9\-]*[!a] ${TARGET_LIB_PATH}
fi
else
echo "Warning: I cannot find ${lib_tmp} from the LIB_SOURCE_PATH you set!!"
echo "It might be missed not in somewhere else."
echo "Please check if it is not in '${LIB_SOURCE_PATH}'"
fi
echo
echo
done

1 則留言:

Biby Cletus 提到...

Hi, i just surfed in searching for interesting blogs on Spirituality, you have a cool blog. Do keep up the good work. I'll be back even though i live far from where you live. its nice to be able to see what people from across the world thinks.

Warm Regards from the Other Side of the Moon.

On a related note perhaps you might find the following link interesting. Its propossing a theory and i'll like to hear your take on the subject via comments. See ya...

Was
Jesus an Essenes ?


Bibby

Kerala, India