#!/bin/sh
# @function - install gcc 6.3.x
function InstallST2GCC()
{
    ShowResult "[green]正在安装GCC 6.3.x ... [/green]" 1
    OUTPUT_LIB_PATH=/usr/lib64/
    eval yum -y install kernel-devel ${_SYS_SHOW_INSTALL_DETAILS_}
    eval yum -y install glibc-headers ${_SYS_SHOW_INSTALL_DETAILS_}
    eval yum -y install build-essential ${_SYS_SHOW_INSTALL_DETAILS_}
    ldconfig
    
    cd ${_PATH_COMPILATION_} ${_SYS_SHOW_INSTALL_DETAILS_}
    tar zxvf ${_PATH_SOFTWARE_}/gcc-6.*.tar.gz ${_SYS_SHOW_INSTALL_DETAILS_}
    cd gcc-6.* ${_SYS_SHOW_INSTALL_DETAILS_}
    tar xjf ${_PATH_SOFTWARE_}/mpfr-2.*.tar.bz2
    ln -sf mpfr-2.* mpfr
    tar xjf ${_PATH_SOFTWARE_}/gmp-4.*.tar.bz2
    ln -sf gmp-4.* gmp
    tar xzf ${_PATH_SOFTWARE_}/mpc-0.*.tar.gz
    ln -sf mpc-0.* mpc
    tar xjf ${_PATH_SOFTWARE_}/isl-0.*.tar.bz2
    sed -e 's/isl_stat_ok = 0,/isl_stat_ok = 0/' isl-0.*/include/isl/ctx.h
    ln -sf isl-0.* isl
    chown -R root:root ${_PATH_COMPILATION_}/gcc-6.*
    [ ! -d ./build ] && mkdir build ${_SYS_SHOW_INSTALL_DETAILS_}
    cd build ${_SYS_SHOW_INSTALL_DETAILS_}
    ../configure  --prefix=/usr/local/gcc -enable-checking=release -enable-languages=c,c++ -disable-multilib ${_SYS_SHOW_INSTALL_DETAILS_}
    eval make ${_SYS_MAKE_EXT_} ${_SYS_SHOW_INSTALL_DETAILS_} 
    eval make install ${_SYS_SHOW_INSTALL_DETAILS_}
    ShowStatus $?
    
    cp /usr/local/gcc/lib64/libstdc++.so.6.0.22 ${OUTPUT_LIB_PATH} ${_SYS_SHOW_INSTALL_DETAILS_}
    cp /usr/local/gcc/lib64/libstdc++.so.6.0.22 ${OUTPUT_LIB_PATH} ${_SYS_SHOW_INSTALL_DETAILS_}
    cp /usr/local/gcc/lib64/libgcc_s.so ${OUTPUT_LIB_PATH} ${_SYS_SHOW_INSTALL_DETAILS_}
    cp /usr/local/gcc/lib64/libgcc_s.so.1 ${OUTPUT_LIB_PATH} ${_SYS_SHOW_INSTALL_DETAILS_}
    cp /usr/local/gcc/lib64/libatomic.so.1.2.0 ${OUTPUT_LIB_PATH} ${_SYS_SHOW_INSTALL_DETAILS_}

    ln -s -f /usr/local/gcc/lib64/libstdc++.so.6.0.22 ${OUTPUT_LIB_PATH}/libstdc++.so.6 ${_SYS_SHOW_INSTALL_DETAILS_}
    ln -s -f /usr/local/gcc/ib64/libstdc++.so.6.0.22 ${OUTPUT_LIB_PATH}/libstdc++.so  ${_SYS_SHOW_INSTALL_DETAILS_}

    cd /usr/bin ${_SYS_SHOW_INSTALL_DETAILS_}
    ln -s -f /usr/local/gcc/bin/gcc gcc ${_SYS_SHOW_INSTALL_DETAILS_}
    ln -s -f /usr/local/gcc/bin/g++ g++ ${_SYS_SHOW_INSTALL_DETAILS_}
    ln -s -f /usr/local/gcc/bin/gcc cc ${_SYS_SHOW_INSTALL_DETAILS_}
    ln -s -f /usr/local/gcc/bin/c++ c++ ${_SYS_SHOW_INSTALL_DETAILS_}
    ln -s -f /usr/local/gcc/bin/cpp cpp ${_SYS_SHOW_INSTALL_DETAILS_}

    sed -i '/\/usr\/local\/lib/d' /etc/ld.so.conf ${_SYS_SHOW_INSTALL_DETAILS_}
    sed -i '/\/usr\/local\/lib64/d' /etc/ld.so.conf ${_SYS_SHOW_INSTALL_DETAILS_}
    sed -i '$a /usr/local/lib' /etc/ld.so.conf ${_SYS_SHOW_INSTALL_DETAILS_}
    sed -i '$a /usr/local/lib64' /etc/ld.so.conf ${_SYS_SHOW_INSTALL_DETAILS_}
 
    ldconfig ${_SYS_SHOW_INSTALL_DETAILS_}
    
    ShowStatus $?
}

