1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > linux下多版本gcc编译器管理方法

linux下多版本gcc编译器管理方法

时间:2019-11-01 00:38:40

相关推荐

linux下多版本gcc编译器管理方法

一般在开发嵌入式程序中,经常会遇到需要不同版本的编译器问题,管理起来是个麻烦事,总是用环境量久了也不爽,敲arm-linux补全时一堆出来了。为此写了一个脚本用来管理不同的编译器,需要时直接切换即可,相对来说我还是比较喜欢。

完整的脚本如下:

#!/bin/bashif [ -z $1 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh config "exit 1fiif [ "$1" = "config" ]; thenif [ -z $2 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh config gcc_type "exit 1fiif [ "$2" = "arm-linux-gnueabihf-" ];thentype=$2fiif [ "$2" = "gcc" ];thentype=fisudo update-alternatives --config ${type}gccsudo update-alternatives --config ${type}g++sudo update-alternatives --config ${type}arsudo update-alternatives --config ${type}ldsudo update-alternatives --config ${type}readelfsudo update-alternatives --config ${type}ranlibsudo update-alternatives --config ${type}nmsudo update-alternatives --config ${type}objcopysudo update-alternatives --config ${type}objdumpsudo update-alternatives --config ${type}sizesudo update-alternatives --config ${type}stringssudo update-alternatives --config ${type}stripsudo update-alternatives --config ${type}gcovsudo update-alternatives --config ${type}gfortransudo update-alternatives --config ${type}gproffiif [ "$1" = "install" ]; thenif [ -z $4 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh install gcc_type gcc_path 50"exit 1fiif [ "$2" = "arm-linux-gnueabihf-" ];thentype=$2fiif [ "$2" = "gcc" ];thentype=fisudo update-alternatives --install /usr/bin/${type}gcc ${type}gcc $3/${type}gcc $4sudo update-alternatives --install /usr/bin/${type}g++ ${type}g++ $3/${type}g++ $4sudo update-alternatives --install /usr/bin/${type}ar ${type}ar $3/${type}ar $4sudo update-alternatives --install /usr/bin/${type}ld ${type}ld $3/${type}ld $4sudo update-alternatives --install /usr/bin/${type}readelf ${type}readelf $3/${type}readelf $4sudo update-alternatives --install /usr/bin/${type}ranlib ${type}ranlib $3/${type}ranlib $4sudo update-alternatives --install /usr/bin/${type}nm ${type}nm $3/${type}nm $4sudo update-alternatives --install /usr/bin/${type}objcopy ${type}objcopy $3/${type}objcopy $4sudo update-alternatives --install /usr/bin/${type}objdump ${type}objdump $3/${type}objdump $4sudo update-alternatives --install /usr/bin/${type}size ${type}size $3/${type}size $4sudo update-alternatives --install /usr/bin/${type}strings ${type}strings $3/${type}strings $4sudo update-alternatives --install /usr/bin/${type}strip ${type}strip $3/${type}strip $4sudo update-alternatives --install /usr/bin/${type}gcov ${type}gcov $3/${type}gcov $4sudo update-alternatives --install /usr/bin/${type}gfortran ${type}gfortran $3/${type}gfortran $4sudo update-alternatives --install /usr/bin/${type}gprof ${type}gprof $3/${type}gprof $4fiif [ "$1" = "remove" ]; thenif [ -z $3 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh remove gcc_type gcc_path"exit 1fiif [ "$2" = "arm-linux-gnueabihf-" ];thentype=$2fiif [ "$2" = "gcc" ];thentype=fisudo update-alternatives --remove ${type}gcc $3/${type}gccsudo update-alternatives --remove ${type}g++ $3/${type}g++sudo update-alternatives --remove ${type}ar $3/${type}arsudo update-alternatives --remove ${type}ld $3/${type}ldsudo update-alternatives --remove ${type}readelf$3/${type}readelfsudo update-alternatives --remove ${type}ranlib$3/${type}ranlibsudo update-alternatives --remove ${type}nm$3/${type}nmsudo update-alternatives --remove ${type}objcopy$3/${type}objcopysudo update-alternatives --remove ${type}objdump$3/${type}objdumpsudo update-alternatives --remove ${type}size$3/${type}sizesudo update-alternatives --remove ${type}strings$3/${type}stringssudo update-alternatives --remove ${type}strip$3/${type}stripsudo update-alternatives --remove ${type}gcov$3/${type}gcovsudo update-alternatives --remove ${type}gfortran$3/${type}gfortransudo update-alternatives --remove ${type}gprof$3/${type}gproffi

上面保存为toolchain-mana.sh文件。

使用方法: 配置:toolchain-mana.sh config type,example:toolchain-mana.sh config arm-linux-gnueabihf-;

安装:toolchain-mana.sh install type path priority,example:toolchain-mana.sh install arm-linux-gnueabihf- /usr/local/arm/gcc-4.9.4-arm-linux-gnueabihf/bin 60;

删除:toolchain-mana.sh remove type path,example:toolchain-mana.sh remove arm-linux-gnueabihf- /usr/local/arm/gcc-4.9.4-arm-linux-gnueabihf/bin.

宿主机的版本如下:

#!/bin/bashif [ "$1" = "config" ]; thenif [ -z $2 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh select gcc "exit 1fisudo update-alternatives --config $2fiif [ "$1" = "install" ]; thenif [ -z $4 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh set gcc gcc-4.8 50"exit 1fisudo update-alternatives --install /usr/bin/$2 $2 /usr/bin/$3 $4fiif [ "$1" = "remove" ]; thenif [ -z $3 ]; thenecho "Fail: You must specify one parameter!"echo "Example: gxx_config.sh remove gcc gcc-4.8"exit 1fisudo update-alternatives --remove $2 /usr/bin/$3fi

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。