Goto Installing GCC- GNU Project it describes the generic installation procedure.
1. Retrieve source code GCC: Anonymous read-only Git access- GNU Project
git clone git://gcc.gnu.org/git/gcc.git srcdir
OR
git clone https://gcc.gnu.org/git/gcc.git srcdir
2. Prerequisites Downloading GCC- GNU Project
Go to srcdir, run contrib/download_prerequisites.
3. Download GMP, MPFR and/or MPC and/or isl.
apt-get install libgmp-dev libmpfr-dev libmpc-dev
OR
Download the package and build manually, go to Index of /pub/gcc/infrastructure .
4. Manual install GMP, MPFR and/or MPC and/or isl
- Download gmp-6.2.1.tar.xz The GNU MP Bignum Library
- tar xvf gmp-6.2.1.tar.xz
- ./configure --prefix=/usr/local/gmp
- make -j8 && make install
- Download mpfr-4.1.0.tar.xz Index of /gnu/mpfr
- tar xvf mpfr-4.1.0.tar.xz
- ./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
- make -j8 && make install
- Download mpc-1.2.1.tar.gz Index of /gnu/mpc
- tar xvf mpc-1.2.1.tar.gz
- ./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr/
- make -j8 && make install
- Download isl-0.24.tar.bz2 https://gcc.gnu.org/pub/gcc/infrastructure/
- tar xvf isl-1.2.1.tar.gz
- ./configure --prefix=/usr/local/isl --with-gmp-prefix=/usr/local/gmp/
- make -j8 && make install
5. If 4, export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/isl/lib:/usr/local/gmp:/usr/local/mpfr:/usr/local/mpc
6. Install flex, apt-get install flex.
7. Configure GCC:
- % mkdir objdir
- % cd objdir
- % srcdir/configure --disable-multilib --prefix=$srcdir/install
Any configure error, go to objdir/Config.log.
You can specify the path
--with-gmp=pathname
--with-gmp-include=pathname
--with-gmp-lib=pathname
--with-mpfr=pathname
--with-mpfr-include=pathname
--with-mpfr-lib=pathname
--with-mpc=pathname
--with-mpc-include=pathname
--with-mpc-lib=pathname
8. make -j`nproc` && make install
It install the gcc to $srcdir/install which is set in gcc configuration.
9. Use the manual gcc
export CC=$srcdir/install/gcc
export CXX=$srcdir/install/g++
10. Now, run cmake /path/to/your/project, it uses this manual build.