Friday, 4 November 2011

Building GCC again

A colleague suggested that I write up building FSF GCC with GNAT for Mac OS X. The notes of an experimental process using GCC 4.6.1 are here; this is somewhat less experimental, and uses the GCC repository.

Build environment

I'm building on a 15" Macbook Pro with a 2.4 GHz Intel Core 2 Duo processor and 4 GB of RAM, running Mac OS X Lion 10.7.2 with Xcode 4.2. FSF GCC Ada requires a working GNAT compiler. I started with GNAT GPL 2011, which I installed at /opt/gnat-gpl-2011, so I adjust my PATH to make this compiler the default choice:
$ PATH=/opt/gnat-gpl-2011/bin:$PATH
Note, this is OK if you're building GCC later than 4.6 (in which the build of gnatbind uses a flag which is deprecated in 4.6 but not supported in GNAT GPL 2011). Otherwise, you'll need a GCC 4.5- or 4.6-based compiler. Fortunately, there's one available at Dropbox or Sourceforge (it also includes C++, Fortran, AUnit, GNATcoll, and XML/Ada - but who's counting!)

GCC in a Distributed Version Control System?

Normally you'd use a source release, from one of the GCC mirror sites. However, this time round I'm going to be working from the GCC repository. This is a Subversion repository (note, SVN is migrating to Apache), which is a centralised VCS. I would feel much safer keeping local changes in a VCS than having patches scattered around, so I'd like to use a DVCS if possible. There is a mirror supported by Git (see here); there's also a Mercurial mirror, but it's not been updated for almost a year. I'm not sure what I have against Git; perhaps it's just that the name is (deliberately?) offensive. Anyway, it seems to me (I may well be mistaken!) that there may be issues tracking the official SVN revision numbers. So I'll stay with SVN for now, checking out the trunk into gcc-trunk-svn/:
svn checkout svn:// gcc-trunk-svn
To update the tree later on, don't just svn update; instead, from gcc-trunk-svn/,
$ contrib/gcc_update
which updates timestamps.

Support libraries

GCC depends on several support libraries. The minimum set is
I originally built 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-trunk-svn/,
$ ln -s ~/tmp/gcc-support/gmp-5.0.2 gmp
$ ln -s ~/tmp/gcc-support/mpfr-3.0.1 mpfr
$ ln -s ~/tmp/gcc-support/mpc-0.9 mpc
(you may of course find later versions).


I use a build directory, ~/tmp/gcc-build/:
$ mkdir ~/tmp/gcc-build
$ cd ~/tmp/gcc-build/
and configure:
$ ../gcc-trunk-svn/configure \
 --prefix=/opt/gcc-4.7-180524 \
 --disable-multilib \
 --enable-languages=c,ada \
The CC='gcc -D_FORTIFY_SOURCE=0' is because of a problem with Lion and GCC. The --prefix=/opt/gcc-4.7-180524 is to keep different versions of compilers separate (the 180524 was the SVN revision I'd updated to). Nothing so infuriating as accidentally overwriting your only compiler with a non-doing version! Then,
$ make
... which succeeded after 38 minutes.


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-ada

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

   === gnat Summary ===
   # of expected passes  940
   # of expected failures 11
   # of unsupported tests 4
It's also possible to make check-gmp, make check-mpfr, make check-mpc, make check-c.


$ sudo make install
... and now all you need to do is to put /opt/gcc-4.7-180524/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)

Update 5.xi.11: Explained "180524". Corrected the final Path setting.
Update 21.i.12: Added backslash in the last line but 1 of the configure command.

No comments:

Post a Comment