-
Notifications
You must be signed in to change notification settings - Fork 1
Building GCC
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 git@github.com:lock3/gcc.git
Henceforth $GCC_REPO will be the cloned repository.
Check out the combined or contracts branch.
> cd $GCC_REPO
> git checkout combined
- Download prerequisites.
> 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.
If building the combined branch libcody is an additional prerequisite dependency. More information on building libcody can be found on the upstream cxx-modules build documentation.
- 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 calledl3-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.
- Build GCC.
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"
> make check-gcc-c++ RUNTESTFLAGS="modules.exp=*" # (only available on the combined branch)
Will run only the subset of tests for contracts followed by the modules tests. The trailing file system glob names files found in $GCC_REPO/gcc/testsuite/g++.dg.
- Installing GCC
Easy:
> 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:
> LD_LIBRARY_PATH=$PATH/lib64 $PATH/bin/g++ ...
or exporting the environment variable:
> export LD_LIBRARY_PATH=$PATH/lib64
> $PATH/bin/g++ ...