I just show an idea, how to adapt different compiler by switch them in shell
I provide you my solution base on my installation, the precondition is you already know where is your latest g++
and previous version of g++
s. I would like do in this way:
#I create some color for $PS1 use
black="\[\033[1;30m\]"
red="\[\033[1;31m\]"
green="\[\033[1;32m\]"
yellow="\[\033[1;33m\]"
blue="\[\033[1;34m\]"
purple="\[\033[1;35m\]"
cyan="\[\033[1;36m\]"
white="\[\033[1;37m\]"
coloroff="\[\033[0m\]"
highlight="\[\033[1m\]"
underline="\[\033[4m\]"
twinkle="\[\033[5m\]"
reverse="\[\033[7m\]"
unvisible="\[\033[8m\]"
#you can add some default path, I just list my daily use path for you, you need modify them
DEFAULT_PATH="/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$HOME/bin"
#default setting, I usually use gcc, so you need modify to g++
function default(){
export PATH="$DEFAULT_PATH"
PS1="\[\033]2;\u@\h:\w\a\]$red[GNU-GCC]$blue\u@\h:$coloroff\w\n-> "
gcc_ver=`gcc --version | head -n 1`
}
#you can add more compiler, even some dedicate old version of g++, just copy my function and modify the bin path
#arm-linux-gcc setting, I also use cross compiler
function armlinuxgcc(){
export PATH="$DEFAULT_PATH"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM-Linux-GCC]$blue\u@\h:$coloroff\w\n-> "
arm_linux_gcc_ver=`arm-linux-gnueabi-gcc-4.7 --version | head -n 1`
}
#I also use dedicate compiler provide by arm
function RVCT22B616(){
#for RVCT2.2
export PATH="$DEFAULT_PATH:$HOME/Software/RVS22-BN-00000-r2p2-01rel0/rvds_2_2_1_dist241_linux/RVCT/Programs/2.2/503/linux-pentium"
export RVCT22INC="$HOME/Software/RVS22-BN-00000-r2p2-01rel0/rvds_2_2_1_dist241_linux/RVCT/Data/2.2/503/include/unix"
export RVCT22LIB="$HOME/Software/RVS22-BN-00000-r2p2-01rel0/rvds_2_2_1_dist241_linux/RVCT/Data/2.2/503/lib"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM2.2B616]$blue\u@\h:$coloroff\w\n-> "
armcc_ver=`armcc --vsn | head -n 1`
#end of RVCT2.2
}
function RVCT31B1055(){
#for RVCT3.1
export PATH="$DEFAULT_PATH:$HOME/Software/RVP31-PA-00001-r3p1-09rel0/linux-pentium"
export RVCT31INC="$HOME/Software/RVP31-PA-00001-r3p1-09rel0/include/unix"
export RVCT31LIB="$HOME/Software/RVP31-PA-00001-r3p1-09rel0/lib"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM3.1B1055]$blue\u@\h:$coloroff\w\n-> "
armcc_ver=`armcc --vsn | head -n 1`
#end of RVCT3.1
}
function RVCT41B894(){
#for RVCT4.1
export PATH="$DEFAULT_PATH:$HOME/Software/RVP41-PA-00001-r4p1-05rel0/standard-linux-pentium-rel/linux-pentium"
export ARMCC41INC="$HOME/Software/RVP41-PA-00001-r4p1-05rel0/standard-linux-pentium-rel/include/unix"
export ARMCC41LIB="$HOME/Software/RVP41-PA-00001-r4p1-05rel0/standard-linux-pentium-rel/lib"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM4.1B894]$blue\u@\h:$coloroff\w\n-> "
armcc_ver=`armcc --vsn | head -n 1`
#end of RVCT4.1
}
function DS5B94(){
#for DS-5
export PATH="$DEFAULT_PATH:/usr/local/DS-5/bin/"
export ARMCC5INC="/usr/local/DS-5/include/"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM5.0B94]$blue\u@\h:$coloroff\w\n-> "
armcc_ver=`armcc --vsn | head -n 1`
#end of DS-5
}
Then, let user can choose these compiler:
default
function sel_env(){
echo "**************************"
echo "* Switch Compile env:"
echo "* 1. ARMCC 2.2 Build[616]"
echo "* 2. ARMCC 3.1 Build[1055]"
echo "* 3. ARMCC 4.1 Build[894]"
echo "* 4. ARMCC 5.0 Build[94]"
echo "* 5. ARM-Linux-GUNEABI-GCC"
echo "* 6. GCC"
echo "**************************"
read choose;
#select choose in "1" "2" "3"; do
case $choose in
1) RVCT22B616
echo "CC -> $armcc_ver"
echo "Compile Firmware and Boot Core";;
2) RVCT31B1055
echo "CC -> $armcc_ver"
echo "Compile Boot Core";;
3) RVCT41B894
echo "CC -> $armcc_ver"
echo "Compile Firmware";;
4) DS5B94
echo "CC -> $armcc_ver"
echo "Compile Firmware";;
5) armlinuxgcc
echo "CC -> $arm_linux_gcc_ver"
echo "Corss compile";;
*) default
echo "CC -> $gcc_ver";;
esac
#done
}
now, after you open your terminal, first source
this env file, or add this operation in .bashrc
file in your $HOME
, and just type sel_env
. I show you the result if you just source
this file:
how@ubuntu-sw:~/Work/.env$ ls
work.env
how@ubuntu-sw:~/Work/.env$ source work.env
[GNU-GCC]how@ubuntu-sw:~/Work/.env
-> ls
work.env
[GNU-GCC]how@ubuntu-sw:~/Work/.env
-> sel_env
**************************
* Switch Compile env:
* 1. ARMCC 2.2 Build[616]
* 2. ARMCC 3.1 Build[1055]
* 3. ARMCC 4.1 Build[894]
* 4. ARMCC 5.0 Build[94]
* 5. ARM-Linux-GUNEABI-GCC
* 6. GCC
**************************
then if I choose 1
for example:
[GNU-GCC]how@ubuntu-sw:~/Work/.env
-> sel_env
**************************
* Switch Compile env:
* 1. ARMCC 2.2 Build[616]
* 2. ARMCC 3.1 Build[1055]
* 3. ARMCC 4.1 Build[894]
* 4. ARMCC 5.0 Build[94]
* 5. ARM-Linux-GUNEABI-GCC
* 6. GCC
**************************
1
ARM/Thumb C/C++ Compiler, RVCT2.2 [Build 616]
CC ->
Compile Firmware and Boot Core
[ARM2.2B616]how@ubuntu-sw:~/Work/.env
->
hope this option can help you when you work on multiple compiler. If your think this way is too over-killed, I suggest you can also use symbol link, and because your install your compiler to /opt
, normally this /opt
folder should in your system defined path. but you need run like g++_withyour_version
somehow, then you can create a symbol link, ln -s /opt/gcc-4.8.2 /opt/gcc
, then, you can only type gcc
for version 4.8.2