Tuesday, 30 April 2013

Building GCC 4.8.0

These notes describe building GCC 4.8.0 for Mac OS X, with Ada, C, C++, Fortran, Objective C, Objective C++, and various GNAT tools.

Build environment

I'm building on a 13" Macbook Pro with a 2.5 GHz Intel Core 2 i5 processor and 4 GB of RAM, running Mac OS X Mountain Lion 10.8.3 (Darwin 12.3.0) with Xcode 4.6.2.

The base compiler

FSF GCC Ada requires a working GNAT compiler. I started with GNAT GPL 2012, which I have installed at /opt/gnat-gpl-2012, so I adjusted my PATH to make this compiler the default choice:

$ PATH=/opt/gnat-gpl-2012/bin:$PATH


GCC used to be released as a complete package, and alternatively with a core and language modules. Now it appears to be released only as a complete package; I guess people are expected to have decent broadband!

I unpacked it in ~/tmp, creating ~/tmp/gcc-4.8.0.

Support libraries

GCC depends on several support libraries. The minimum set is

I used to build each of these on their own, but thanks to a helpful tip from Lucretia I've adopted the much better plan of linking their sources into the GCC source tree and letting the GCC Makefiles manage the build appropriately.

I unpacked the support libraries in a ~/tmp/gcc-support/ directory (I don't propose to change them) and then, in gcc-4.8.0/,

$ ln -s ~/tmp/gcc-support/gmp-5.1.0 gmp
$ ln -s ~/tmp/gcc-support/mpfr-3.1.1 mpfr
$ ln -s ~/tmp/gcc-support/mpc-1.0.1 mpc
(you may of course find later versions).


I used a build directory, ~/tmp/gcc-build/:

$ mkdir ~/tmp/gcc-build
$ cd ~/tmp/gcc-build/

and configured:

../gcc-4.8.0/configure \
  --prefix=/opt/gcc-4.8.0 \
  --disable-multilib \
  --enable-languages=c,c++,ada,fortran,objc,obj-c++ \
  --target=x86_64-apple-darwin12 \

The --prefix=/opt/gcc-4.8.0 is to keep different versions of compilers separate. Nothing so infuriating as accidentally overwriting your only compiler with a non-doing version!

If I had left the configure script to itself, it would have set build, host and target to x86_64-apple-darwin12.3.0. There's nothing intrinsically wrong with that, I think, I just prefer not to be so specific.

I include Fortran because of work on additional math extensions. Objective C and Objective C++ are included by popular request on the GNAT-OSX mailing list. Then,

$ make


You need to install Dejagnu, and put its runtest on your path. I have dejagnu-1.4.4 installed in /opt/gnu, so I say

$ PATH=/opt/gnu/bin:$PATH

From previous experience, it can take a very long time indeed to run the full test suite, even locking up the machine to the point of needing a power cycle. So it can make sense to run the individual test suites.

make check-objc

  === objc Summary ===

# of expected passes  5826
# of unexpected failures 34
# of expected failures  14
# of unresolved testcases 44
# of unsupported tests  77

make check-obj-c++

  === obj-c++ Summary ===

# of expected passes  2936
# of unexpected failures 25
# of expected failures  19
# of unresolved testcases 36
# of unsupported tests  59

make check-ada

               === acats Summary ===
# of expected passes            2320
# of unexpected failures        0

  === gnat Summary ===

# of expected passes  1160
# of expected failures  17
# of unsupported tests  5

make check-fortran

  === gfortran Summary ===

# of expected passes  43013
# of unexpected successes 8
# of expected failures  42
# of unsupported tests  70

(I assume that C and C++ will be adequately handled by the mainstream).

I don't know whether the objc(++) results are acceptable/expected, and I like the 'unexpected successes' in Fortran!

It's also possible to make check-gmp, make check-mpfr, make check-mpc (though the last fails).


$ sudo make install

... and now all you need to do is to put /opt/gcc-4.8.0/bin at the front of your PATH, and you're using the new compiler.

If you're into multiple-precision arithmetic, you might want to install the support libraries:

$ (cd gmp; sudo make install)
$ (cd mpfr; sudo make install)
$ (cd mpc; sudo make install)


There are several tools you would expect to find in the GNAT environment; they have to be built with the new compiler, so set your PATH:

$ PATH=/opt/gcc-4.8.0/bin:$PATH


This is needed by GPRbuild, see below.

The GPL 2012 download unpacks into xmlada-4.3w-src/. In that directory,

$ ./configure --prefix=/opt/gcc-4.8.0 --build=x86_64-apple-darwin12
$ make
$ sudo make install


As well as the archive from AdaCore, get the patch gprbuild-2012-src.diff.

The patch does three things:

  • It fixes a style error that prevents the build;
  • It stops ranlib being called with -c, which is deprecated by Apple and can cause problems with multiply-defined symbols;
  • It allows stand-alone static libraries to be built (the same problem occurs in gnatmake; I haven't fixed that in the compiler build, though of course you could).

The GPL 2012 download unpacks into gprbuild-2012-src/. In that directory,

$ patch -p1 <~/Downloads/gprbuild-2012-src.diff
$ ./configure --prefix=/opt/gcc-4.8.0 --build=x86_64-apple-darwin12
$ make
$ sudo make install


The GPL 2012 download unpacks into aunit-gpl-2012-src, and uses gprbuild not only to build the library but also to determine where the library should be installed. In that directory,

$ make
$ sudo make install


As well as the archive from AdaCore, get the patch asis-gpl-2012-gcc-4.8.0.diff.

The ASIS download contains compiler source units for GNAT GPL 2012, some of which are distributed with the source and some of which were generated during the compiler build. The patch picks up the corresponding units from the GCC 4.8.0 build that has just been completed; the patched Makefile contains, near the top, the lines

# These are the directories containing the GCC source tree and the GCC
# build, respectively, for obtaining the GCC source (original and
# generated) corresponding to the GCC compiler variant in use. THEY
GCC_SRC_BASE    ?= $(HOME)/tmp/gcc-4.8.0
GCC_BUILD_BASE  ?= $(HOME)/tmp/gcc-build

If your build is organised differently, you'll need to change these (or set the environment variables explicitly).

The GPL 2012 download unpacks into asis-gpl-2012-src/. In that directory,

$ patch -p1 <~/Downloads/asis-gpl-2012-gcc-4.8.0.diff
$ make
$ make tools
$ sudo make install
$ sudo make install-tools

(Note, there is another make target, gu_tools, which builds aunitstub, aunitglue, and gnattest. However, this requires GNATcoll, which would need to be built first).

No comments:

Post a Comment