linux嵌入式开发切换交叉编译器

最近工作闲暇时候做了一个脚本,方便虚拟机里面切换交叉编译器用,因为前段时间工作时候遇到几个项目同时开工的情况,只做了一个虚拟机,里面搭建了5个交叉编译环境,切换起来较为麻烦,故此做了脚本,分享如下

#!/bin/bash
if [ $BK_SUC ];then
  echo "ready to set PATHBK=$PATHBK !!!"
  export PATH=$PATHBK
else
  echo "first backup PATH=$PATH !!!"
  export PATHBK=$PATH
fi


export BK_SUC="lebaishi"


if [ $# -ne 1 ] ; then 
  echo "Please enter 'one' parameter,for example:/usr/local/arm/bin/arm-linux- !!!" 
  echo "now exit !!!" 
  #exit 1; 
#fi
elif [ "$1" = clean ];then
  echo "recover the PATH=$PATHBK !!!"
  export PATH=$PATHBK
elif [ ! -d "${1%/*}" ];then
  echo "Please enter a valid directory,for example:/usr/local/arm/bin/arm-linux- !!!"
else
  echo "now set the PATH=$PATH:${1%/*}"
  echo "now set the CROSS_COMPILE=${1##*/}"
  export PATH=$PATH:${1%/*}
  export ARCH=arm 
  export CROSS_COMPILE=${1##*/}
fi


用法较为简单,source +脚本名+全路径和前缀,举例:source set-arm-linux.sh /usr/local/arm/gcc-linaro-arm-4.7-ti/bin/arm-linux-gnueabihf-

会先把PATH还原,然后提炼到bin的路径追加给PATH,然后把后面的编译器前缀赋值给CROSS_COMPILE,ARCH一直都是arm,如果有用其他平台的可以手动改下

你可能感兴趣的:(linux)