批处理打包

#!/bin/bash


ECHO_RED_FONT="\033[31m"
ECHO_GREEN_FONT="\033[32m"
ECHO_END="\033[0m"

function make_appinstall() {
    app_dir=$1
    make_cmd=$2
    app_configure=${app_dir}/configure
    if [ -f ${app_configure} ]; then
        if [ ! -x ${app_configure} ]; then
            chmod u+x ${app_configure}
        fi
        cd ${app_dir} && ./configure
    else
        cd ${app_dir}
    fi

    if [ ! ${make_cmd} ]; then
        make appclean && make appbuild && make appinstall
    else
        make $make_cmd
    fi

    if [ $? -ne 0 ]; then
        printf ${ECHO_RED_FONT}"$0 ${app_dir} error\n"${ECHO_END}
        exit $?
    fi
    printf ${ECHO_GREEN_FONT}"$0 ${app_dir} ok\n"${ECHO_END}
    cd -
}

function sdk_build() {
    sdkdir=$1
    echo ${sdkdir}
    if [[ ${sdkdir} =~ "/app_" ]]; then 
        make_appinstall ${sdkdir} $2
    else
        dirs=$(ls $sdkdir | grep app_)
        for dir in $dirs
        do
            app_dir=${sdkdir}/${dir}
            make_appinstall ${app_dir} $2
        done
    fi
}

# tag V210609T0 LINUX/tag/howen_20190916/ app_hw3521V2 funcmk
# type | branch | plaform  | func mk | version
function make_package() {
    printf "${ECHO_GREEN_FONT}:-->select $1 $2 $3 $4 $5 \n${ECHO_END}" 
    make clean SDK_BRANCH=$2 SDK_PLATFORM=$3
    make SDK_TYPE=$1 SDK_BRANCH=$2 SDK_PLATFORM=$3 USER_FUNC=$4
    make build SDK_TYPE=$1 SDK_BRANCH=$2 SDK_PLATFORM=$3 USER_FUNC=$4 VER=$5
}


function package() {
    version=$1
    sdkdir=$2
    funcmk=$3
    if [ ! $3 ]; then
        funcmk=common.mk
    fi
    OLD_IFS="$IFS"
    IFS="/"
    array=($sdkdir)
    IFS="$OLD_IFS"
    len=${#array[*]}

    if [[ ${sdkdir} =~ "/app_" ]]; then
        typeIdx=`expr ${len} - 3`
        platIdx=`expr ${len} - 1`
        # branchIdx=`awk -v a="${sdkdir}" -v b="/app_" 'BEGIN{print index(a,b)}'`
        branch=${sdkdir%app_*}
        make_package ${array[$typeIdx]]} ${branch} ${array[$platIdx]} ${funcmk} $version
    else
        dirs=$(ls $sdkdir | grep app_)
        for dir in $dirs
        do
            typeIdx=`expr ${len} - 2`
            make_package ${array[$typeIdx]]} ${sdkdir} ${dir} ${funcmk} $version 
        done
    fi
}

case $1 in
    help)
        printf "$0 sdk [dir] [cammand]\n"
        printf "\t[dir]\n"
        printf "\t     LINUX/tag/howen_20190916/app_hw3521V2\n"
        printf "\t     LINUX/tag/howen_20190916\n"
        printf "\t[cammand]\n"
        printf "\t     appclean && appbuild && appinstall [default]\n"
        printf "\t     appclean\n"
        printf "\t     ......\n"
        printf "\t     all\n"
        printf "\n"
        printf "$0 [version] [dir] [function.mk]\n"
        printf "\tverison: \n"
        printf "\t     V210609T0\n"
        printf "\t[dir]\n"
        printf "\t     LINUX/tag/howen_20190916/app_hw3521V2\n"
        printf "\t     LINUX/tag/howen_20190916\n"
        printf "\t[function.mk]\n"
        printf "\t     common.mk[default]\n"
        exit 0
        ;;
    sdk)
        sdk_build $2 $3
        exit 0
        ;;
    *)
        package $1 $2 $3
        exit 0
        ;;
esac
exit 0

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值