首页 > 代码库 > linux下移植指定的二进制程序脚本

linux下移植指定的二进制程序脚本

一个程序所依赖的库文件可以由:ldd  命令路径来显示

ldd /bin/cat  输出详解

第一行输出为库入口,非库文件

which ls|grep -v alias|grep -o‘[^[:space:]]*‘

 

脚本中调试方法

declare –i Debuglevel=1

Debuglevel={0|1}

[ $Debuglevel –eq 1 ] && echo …$…….

 

移植脚本如下所示

#!/bin/bash

#

declare -i DebugLevel=0

 

Target=/mnt/sysroot

[ -d $Target ] || mkdir $Target &>/dev/null

 

read -p "A command: " Command

 

while [ $Command != ‘q‘ -a $Command != ‘Q‘]; do

Command=`which $Command | grep -v"^alias" | grep -o "[^[:space:]]*"`

[ $DebugLevel -eq 1 ] && echo$Command

 

ComDir=${Command%/*}

[ $DebugLevel -eq 1 ] && echo$ComDir

 

[ -d ${Target}${ComDir} ] || mkdir -p${Target}${ComDir}

[ ! -f ${Target}${Command} ] && cp$Command ${Target}${Command} && echo "Copy $Command to $Targetfinished."

 

for Lib in `ldd $Command | grep -o"[^[:space:]]*/lib[^[:space:]]*"`; do

 LibDir=${Lib%/*}

  [$DebugLevel -eq 1 ] && echo $LibDir

 

  [-d ${Target}${LibDir} ] || mkdir -p ${Target}${LibDir}

  [ !-f ${Target}${Lib} ] && cp $Lib ${Target}${Lib} && echo"Copy $Lib to $Target finished."

done

read -p "A command: " Command

done


本文出自 “就让我更饿一点” 博客,请务必保留此出处http://ufirst.blog.51cto.com/7628670/1432613