#!/bin/bash

# Download
rm -rf /tmp/gcc
mkdir -pv /tmp/gcc
cd /tmp/gcc
#wget https://mirrors.ustc.edu.cn/gnu/gcc/gcc-9.4.0/gcc-9.4.0.tar.xz
#wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
#wget https://mirrors.ustc.edu.cn/gnu/gmp/gmp-6.1.0.tar.bz2
#wget https://mirrors.ustc.edu.cn/gnu/mpfr/mpfr-3.1.4.tar.gz
#wget https://mirrors.ustc.edu.cn/gnu/mpc/mpc-1.0.3.tar.gz
wget https://tools.mindspore.cn/tools/build/gcc/gcc-9.4.0/source/gcc-9.4.0.tar.gz
wget https://tools.mindspore.cn/tools/build/gcc/gcc-9.4.0/source/gmp-6.1.0.tar.bz2
wget https://tools.mindspore.cn/tools/build/gcc/gcc-9.4.0/source/isl-0.16.1.tar.bz2
wget https://tools.mindspore.cn/tools/build/gcc/gcc-9.4.0/source/mpc-1.0.3.tar.gz
wget https://tools.mindspore.cn/tools/build/gcc/gcc-9.4.0/source/mpfr-3.1.4.tar.gz

# Decompress
cd /tmp/gcc
tar -zxf gcc-9.4.0.tar.gz
tar -zxf mpc-1.0.3.tar.gz
tar -zxf mpfr-3.1.4.tar.gz
tar -jxf gmp-6.1.0.tar.bz2
tar -jxf isl-0.16.1.tar.bz2

# Copy depend lib
cd /tmp/gcc
mv gmp-6.1.0 gcc-9.4.0/gmp
mv isl-0.16.1 gcc-9.4.0/isl
mv mpc-1.0.3 gcc-9.4.0/mpc
mv mpfr-3.1.4 gcc-9.4.0/mpfr

# Install(Path: /usr/local/gcc/gcc940)
mkdir -pv /usr/local/gcc/gcc940
cd /tmp/gcc/gcc-9.4.0
mkdir build
cd build
../configure --prefix=/usr/local/gcc/gcc730 -enable-checking=release -enable-languages=c,c++ -disable-multilib
make -j16
make install-strip

# Set chmod
chmod 755 -R /usr/local/gcc

# Set link
cd /usr/local/gcc/gcc940/bin
ln -s gcc cc

# Make run package
#cd /usr/local/gcc
#tar -jcf gcc940.tar.bz2 gcc940

# Delete package
rm -rf /tmp/gcc
