交叉编译工具链设置环境变量脚本

#!/bin/bash

print_help() {
cat <<EOF
Usage: command

command:
    export cross_compiler
    unset

example:
    source ./toolchain.sh export arm-linux-androideabi
    source ./toolchain.sh unset

EOF
}

main() {
    if [ $# -lt 1 ]; then
        print_help
        return
    fi
    COMMAND=$1

    if [ $COMMAND = "export" ]; then
        if [ $# -lt 2 ]; then
            print_help
            return
        fi
        CROSS=$2
        if [ ${CROSS:${#CROSS}-1:1} != "-" ]; then
            CROSS=${CROSS}-
        fi
        echo "CROSS  =   $CROSS"
        export CC=${CROSS}gcc
        export CXX=${CROSS}g++
        export AR=${CROSS}ar
        export AS=${CROSS}as
        export LD=${CROSS}ld
        export STRIP=${CROSS}strip
        export RANLIB=${CROSS}ranlib
        export NM=${CROSS}nm
    elif [ $COMMAND = "unset" ]; then
        unset  CC
        unset  CXX
        unset  AR
        unset  AS
        unset  LD
        unset  STRIP
        unset  RANLIB
        unset  NM
    else
        print_help
        return
    fi
}

main $@
echo "CC     =   $CC"
echo "CXX    =   $CXX"
echo "AR     =   $AR"
echo "AS     =   $AS"
echo "LD     =   $LD"
echo "STRIP  =   $STRIP"
echo "RANLIB =   $RANLIB"
echo "NM     =   $NM"

用法:

source ./toolchain.sh export arm-linux-androideabi
发布了130 篇原创文章 · 获赞 147 · 访问量 29万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 代码科技 设计师: Amelia_0503

分享到微信朋友圈

×

扫一扫,手机浏览