1- clone GCC repository
git clone git://gcc.gnu.org/git/gcc.git
2- add select branch
git branch -a #to list all branches
git checkout branch_name#to select wanted branch in our case it gcc-12
3- in the source folder you will find ./contrib/download_prerequisites
execute it to download dependencies
4- call configuration https://gcc.gnu.org/install/configure.html
% mkdir objdir
% cd objdir
% srcdir/configure [options] [target]
../gcc/configure --prefix=/home/malabdali/gcc-12 --enable-languages=c,c++ --disable-multilib
if it succeded makefiles it will be generated here (objdir)
not that build results will be saved here /home/malabdali/gcc-12
5- start call make
sudo make -j 8
6- call make install
sudo make install
after install you can find folder(bin,lib,include) inside /home/malabdali/gcc-12