Building GCC can be a bit of a pain. Below is our approach for Linux and Mac:
Clone the repository and check out the feature branch.
> cd $GCC_PARENT> git clone firstname.lastname@example.org:lock3/gcc-new.git
Henceforth $GCC_REPO will be the cloned repository.
Check out the contracts branch.
> cd $GCC_REPO> git checkout contracts
> cd $GCC_REPO> ./contrib/download_prerequisites
This will download 4 or 5 external dependencies and make them top-level subprojects of GCC. This generally needs to be done only once. Version updates are infrequent.
Configure the build.
Like projects using CMake, GCC is built out-of-tree. You can place the build directory anywhere, including a subdirectory of the source directory. For example:
> cd $GCC_REPO> mkdir build> cd build
Henceforth $BUILD is the build directory.
The build is configured using the configure script:
> cd $BUILD> ../configure [options]
There are lots of options, all documented here. We recommend the following:
--prefix=$PATH: the installation path of the compiler
--enable-languages=c,c++: only build the C and C++ compilers
--disable-bootstrap: turn off the complete bootstrap build
--disable-multilib: turn off library builds for multiple targets.
--program-prefix=$prefix: add a prefix to the resulting binary names
(e.g. --program-prefix=l3- would result in a binary called l3-g++)
--program-suffix=$suffix: add a suffix to the resulting binary names
If you don't disable bootstrap, your initial build will take much longer. I've often found disabling multilib to be necessary for simple Debian builds.
Just run make.
> cd $BUILD> make
Parallelize with -jN for N parallel jobs.
A fresh non-bootstrap build can take between 15 minutes and an hour or so, depending on the system. A bootstrap build can take much longer.
Optionally run tests.
GCC's complete test suite takes a very, very long time to run. You will need to install a package called dejagnu on Ubuntu or deja-gnu on Mac OS X using Homebrew to run the test suite.
> cd $BUILD> make check
There are also a number of subproject tests:
> make check-gcc-c++
Runs the C++ compiler test suite.
You can also run subsets of the test suite:
> make check-gcc-c++ RUNTESTFLAGS="dg.exp=cpp2a/contracts*.C"
Will run only the subset of tests for contracts. The trailing file system glob names files found in $GCC_REPO/gcc/testsuite/g++.dg.
> cd $BUILD> make install
It should suffice to adjust your path to find the installed compiler or simply invoke it directly. Additional configuration should not be needed to find header files or link against the standard library on Mac.
On linux it may be necessary to point to the newly compiled standard library using the LD_LIBRARY_PATH environment variable. With $PATH being the argument to --prefix used when configuring this can be done while invoking the compiler: