下载并交叉编译busybox的shell脚本

来源:互联网 发布:卫生部网络直报系统 编辑:程序博客网 时间:2024/06/05 10:44

原文地址:http://hi.baidu.com/kkernel/item/7b9b9bd4222ec82d39f6f795

[root:/root/workpath/rootfs/busybox]#tree -L 3

.

|-- build.sh

|-- busybox-1.18.4.tar.bz2

`-- patch

    `-- busybox-1.18.4.config

 

1 directory, 3 files

[root:/root/workpath/rootfs/busybox]#cat build.sh

#!/bin/sh #+--------------------------------------------------------------------------------------------#|Description:  This shell script used to download busybox source code and cross compile it.#|     Author:  GuoWenxue <guowenxue@gmail.com>#|  ChangeLog:#|           1, Initialize 1.0.0 on 2011.04.21#+-------------------------------------------------------------------------------------------- PRJ_PATH=`pwd` APP_NAME="busybox-1.18.4"PACK_SUFIX="tar.bz2"DL_ADDR="http://www.busybox.net/downloads/busybox-1.18.4.tar.bz2"INST_PATH= ARCH=$1 ARM920T_CROSS="/opt/buildroot-2011.02/arm920t/usr/bin/arm-linux-"ARM926T_CROSS="/opt/buildroot-2011.02/arm926ejs/usr/bin/arm-linux-" sup_arch=("" "s3c2410" "s3c2440" "at91sam9260") function select_arch(){   echo "Current support ARCH: "   i=1   len=${#sup_arch[*]}    while [ $i -lt $len ]; do     echo "$i: ${sup_arch[$i]}"     let i++;   done    echo "Please select: "   index=   read index   ARCH=${sup_arch[$index]}}  function decompress_packet()(   echo "+---------------------------------------------+"   echo "|  Decompress $1 now"     echo "+---------------------------------------------+"    if [ `ls $1 | grep "tar.bz2"` ] ; then       set -x       tar -xjf $1       set +x   fi    if [ `ls $1 | grep "tar.gz"` ] ; then       set -x       tar -xzf $1       set +x   fi) if [ -z $ARCH ] ; then  select_archfi if [ $ARCH = "s3c2440" -o $ARCH = "s3c2410" ] ; then     CROSS="$ARM920T_CROSS"elif [ $ARCH = "at91sam9260" ] ; then    CROSS="$ARM926T_CROSS"else    echo "+------------------------------------------------------------------+"    echo "|  ERROR: Unsupport platform to cross compile "      echo "+------------------------------------------------------------------+"    exit -1;fi  # Download source code packetif [ ! -s $APP_NAME.$PACK_SUFIX ] ; then   echo "+------------------------------------------------------------------+"   echo "|  Download $APP_NAME.$PACK_SUFIX  now "     echo "+------------------------------------------------------------------+"    wget $DL_ADDRfi # Decompress source code packetif [ ! -d $APP_NAME ] ; then    decompress_packet $APP_NAME.tar.*fi #Copy the configure fileif [ ! -s .config ]; then    cp patch/$APP_NAME.config $APP_NAME/.configfi if [ ! -s $APP_NAME/.config ]; then   echo "+------------------------------------------------------------------+"   echo "| ERROR: Miss default configure file"     echo "+------------------------------------------------------------------+"   exit -2fi if [ -z $INST_PATH ] ; then   INST_PATH=$PRJ_PATH/../$ARCH/mntfi cd $APP_NAME     #Modify the cross config in the configure file   line=`sed -n '/CONFIG_CROSS_COMPILER_PREFIX/=' .config`   sed -i -e ${line}s"|.*|CONFIG_CROSS_COMPILER_PREFIX=\"$CROSS\"|" .config    #Modify the install path in the configure file   line=`sed -n '/CONFIG_PREFIX=/=' .config`   sed -i -e ${line}s"|.*|CONFIG_PREFIX=\"$INST_PATH\"|" .config    echo "+------------------------------------------------------------------+"   echo "|         Cross compile $APP_NAME  now "     echo "|  ARCH: \"$ARCH\""   echo "| CROSS: \"$CROSS\""   echo "+------------------------------------------------------------------+"   set -x   make clean   make   set +x    #Check Root filesystem mount or not   mountpoint $INST_PATH   if [ 0 != $? ] ; then       echo "+------------------------------------------------------------------+"      echo "| WARNING: Root Filesystem $INST_PATH not mounted, don't install."        echo "+------------------------------------------------------------------+"      exit   fi    #install busybox   sudo rm -rf $INST_PATH/bin/*   sudo rm -rf $INST_PATH/sbin/*   make install cd