| #!/bin/bash | 
|   | 
| #+-------------------------------------------------------------------------------------------- | 
| #|Description:  This is shell script used to download a zbarapplication | 
| #|             and cross compile it. | 
| #|     Author:  GuoWenxue <guowenxue@gmail.com> | 
| #|  ChangeLog: | 
| #|           1, Initialize 1.0.0 on 2011.12.26 | 
| #+-------------------------------------------------------------------------------------------- | 
|   | 
| set -e | 
|   | 
| PRJ_PATH=`pwd` | 
|   | 
| APP_NAME=zbar-latest | 
| APP_PACK=$APP_NAME.tar.bz2 | 
|   | 
| INST_PATH=$PRJ_PATH/../install | 
|   | 
| CROSS=/opt/crosstool/cortex-a7/bin/arm-linux-gnueabi- | 
|   | 
| LYFTP_SRC=ftp://master.iot-yun.club/src/ | 
|   | 
| # arg1 is the packet download address | 
| # arg2 is the download packet rename name | 
| function download_packet() | 
| { | 
|     if [ $# -lt 1 ] ; then | 
|         echo "ERROR: $0 without argument for packet download address" | 
|         exit; | 
|     fi | 
|   | 
|     rename=0 | 
|   | 
|     dl_addr=$1 | 
|     dl_file=`basename $dl_addr` | 
|   | 
|     if [ $# -ge 2 ] ; then | 
|         pack=$2 | 
|         rename=1 | 
|     else | 
|         pack=$dl_file | 
|     fi | 
|   | 
|     if [ -s $pack ] ; then | 
|         echo "INFO: $pack already exist, skip download it" | 
|         return 0; | 
|     fi | 
|   | 
|     echo "INFO: Start to download packet $pack now" | 
|     wget $dl_addr  | 
|   | 
|     if [ $? != 0  ] ; then | 
|         echo "ERROR: Download $pack failure, exit now..." | 
|         exit; | 
|     fi  | 
|     echo "INFO: Download $pack ok!" | 
|   | 
|     if [ $rename != 0 ] ; then | 
|         mv  $dl_file $pack | 
|     fi | 
|   | 
|     return 0; | 
| } | 
|   | 
| function decompress_packet() | 
| ( | 
|    echo "+---------------------------------------------+" | 
|    echo "|  Decompress $1 now"   | 
|    echo "+---------------------------------------------+" | 
|    rv=0; | 
|   | 
|     ftype=`file "$1"` | 
|     case "$ftype" in | 
|        "$1: Zip archive"*) | 
|            unzip "$1" ;; | 
|   | 
|        "$1: gzip compressed"*) | 
|            if [ 0 != `expr "$1" : ".*.tar.*" ` ] ; then | 
|                tar -xzf $1 | 
|            else | 
|                gzip -d "$1" | 
|            fi ;; | 
|   | 
|        "$1: bzip2 compressed"*) | 
|            if [ 0 != `expr "$1" : ".*.tar.*" ` ] ; then | 
|                tar -xjf $1 | 
|            else | 
|                bunzip2 "$1" | 
|            fi ;; | 
|   | 
|        "$1: POSIX tar archive"*) | 
|            tar -xf "$1" ;; | 
|   | 
|        "$1: LZMA compressed data, streamed"*) | 
|            xz -d $1 && tar -xf `ls *.tar` ;; | 
|   | 
|        *) | 
|            rv=1; | 
|            echo "$1 is unknow compress format";; | 
|     esac | 
|   | 
|     if [ $rv != 0 ] ; then | 
|         echo "ERROR: Decompress $1 failure, exit now..." | 
|         exit 1; | 
|     fi | 
|   | 
|     return $rv; | 
| ) | 
|   | 
| export CC=${CROSS}gcc  | 
| export CXX=${CROSS}g++  | 
| export AR=${CROSS}ar  | 
| export AS=${CROSS}as  | 
| export LD=${CROSS}ld  | 
| export NM=${CROSS}nm  | 
| export RANLIB=${CROSS}ranlib  | 
| export STRIP=${CROSS}strip | 
|   | 
| if [ -d $INST_PATH ] ; then | 
|     echo "INFO: $APP_NAME already cross compiled, exit now ..." | 
|     #exit; | 
| fi | 
|   | 
|   | 
| LIB_ZLIB=zlib-1.2.11 | 
| PACK_ZLIB=$LIB_ZLIB.tar.gz | 
|   | 
| if [ ! -f $INST_PATH/lib/libz.so ] ; then | 
|   | 
|     download_packet  ${LYFTP_SRC}/${PACK_ZLIB}  | 
|   | 
|     if [ ! -d $LIB_ZLIB ] ; then | 
|         decompress_packet $PACK_ZLIB | 
|         if [ $? != 0 ] ; then | 
|             exit 1; | 
|         fi | 
|     fi | 
|   | 
|     echo "+------------------------------------------------------------------+" | 
|     echo "|          Build $LIB_ZLIB for $ARCH " | 
|     echo "| Crosstool:  $CROSS" | 
|     echo "+------------------------------------------------------------------+" | 
|   | 
|     cd $LIB_ZLIB | 
|     ./configure --prefix=$INST_PATH  | 
|     make && make install | 
|     cd - | 
| else | 
|     echo "+------------------------------------------------------------------+" | 
|     echo "|          $LIB_ZLIB already ready " | 
|     echo "+------------------------------------------------------------------+" | 
| fi | 
|   | 
| LIB_IMGIC=ImageMagick6-6.9.4-0  | 
| PACK_IMGIC=$LIB_IMGIC.tar.gz | 
|   | 
| if [ ! -f $INST_PATH/lib/libMagickCore-6.Q16.a ] ; then | 
|   | 
|     download_packet  ${LYFTP_SRC}/${PACK_IMGIC} | 
|   | 
|     if [ ! -d $LIB_IMGIC ] ; then | 
|         decompress_packet $PACK_IMGIC | 
|         if [ $? != 0 ] ; then | 
|             exit 1; | 
|         fi | 
|     fi | 
|   | 
|     echo "+------------------------------------------------------------------+" | 
|     echo "|          Build $LIB_IMGIC for $ARCH " | 
|     echo "| Crosstool:  $CROSS" | 
|     echo "+------------------------------------------------------------------+" | 
|   | 
|     cd $LIB_IMGIC | 
|   | 
|     CFLAGS="-I${INST_PATH}/include -DMAGICKCORE_QUANTUM_DEPTH=16" LDFLAGS=-L${INST_PATH}/lib \ | 
|     ./configure --host=arm-linux --enable-static --disable-shared --prefix=$INST_PATH \ | 
|     --without-magick-plus-plus --without-perl --without-x --without-dps --without-xml \ | 
|     --without-pango --without-freetype --without-png | 
|    | 
|     make && make install | 
|     cd - | 
| else | 
|     echo "+------------------------------------------------------------------+" | 
|     echo "|          $LIB_IMGIC already ready " | 
|     echo "+------------------------------------------------------------------+" | 
| fi | 
|   | 
|   | 
| # Download source code packet | 
| download_packet ${LYFTP_SRC}/zbar-latest.tar.bz2 | 
|   | 
| # Decompress source code packet  | 
| if [ ! -d $APP_NAME ] ; then  | 
|     decompress_packet $APP_PACK | 
|     if [ $? != 0 ] ; then | 
|         exit 1; | 
|     fi | 
| fi | 
|   | 
|   | 
| echo "+------------------------------------------------------------------+" | 
| echo "|          Build $APP_NAME for $ARCH " | 
| echo "| Crosstool:  $CROSS" | 
| echo "+------------------------------------------------------------------+" | 
|   | 
| cd $APP_NAME | 
|    git checkout 8edfa5f8c4d11a54 && rm -rf * && git checkout . | 
|    autoreconf --install | 
|    CFLAGS="-DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16" \ | 
|        ./configure --host=arm-linux --enable-static --enable-shared --prefix=$INST_PATH \ | 
|    --without-gtk --without-python --without-qt --without-x --without-java  \ | 
|    --with-imagemagick=${INST_PATH}/ --without-graphicsmagick \ | 
|    MAGICK_CFLAGS=-I${INST_PATH}//include/ImageMagick-6  MAGICK_LIBS="-L${INST_PATH}/lib -lMagickWand-6.Q16 -lMagickCore-6.Q16 -lm -lz -L`pwd`/zbar/.libs/ -lzbar " | 
|    | 
|    mkdir -p ./doc/man/ | 
|    touch ./doc/man/zbarimg.1 | 
|    touch ./doc/man/zbarcam.1 | 
|    make all && make install | 
| cd - |