These notes describe building GCC 5.1.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 Mavericks (Darwin 13.4.0) with the Command Line Tools for Xcode 6.2.
The base compiler
FSF GCC Ada requires a working GNAT compiler. I started with FSF GCC 4.9.1, which I have installed at /opt/gcc-4.9.1, so I adjusted my PATH to make this compiler the default choice:
$ PATH=/opt/gcc-4.9.1/bin:$PATH
Download
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-5.1.0.
Support libraries
GCC depends on several support libraries. The minimum set is
- GNU Multiple Precision Library (GMP) version 4.3.2 (or later)
- MPFR Library version 2.4.2 (or later)
- MPC Library version 0.8.1 (or later)
I unpacked the support libraries in a ~/tmp/gcc-support/ directory (I don't propose to change them) and then, in gcc-5.1.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 applied the patch pr61027-1.diff from GCC bug 61027.
Building
I used a build directory, ~/tmp/gcc-5.1.0-build/:
$ mkdir ~/tmp/gcc-5.1.0-build $ cd ~/tmp/gcc-5.1.0-build/
and configured:
../gcc-5.1.0/configure \ --prefix=/usr/local/gnat/5.1.0 \ --disable-multilib \ --disable-nls \ --enable-languages=c,c++,ada,fortran,objc,obj-c++ \ --host=x86_64-apple-darwin13 \ --target=x86_64-apple-darwin13 \ --build=x86_64-apple-darwin13 \ --with-boot-libs=no \ --with-boot-ldflags=no
The --prefix=/usr/local/gnat/5.1.0 has two purposes:
- First, to keep different versions of compilers separate. Nothing so infuriating as accidentally overwriting your only compiler with a non-doing version!
- Second, because the patch applied above makes the compiler use shared libraries, especially for the GNAT tools, and the installation process needs to rewrite run path information in the executables and the shared libraries; so it doesn't do for the original run path prefix to be too short, as my preferred /opt/gcc-5.1.0 would have been.
If I had left the configure script to itself, it would have set build, host and target to x86_64-apple-darwin13.4.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.
--with-boot-libs=no and --with-boot-ldflags=no are part of the fix for GCC bug 61027.
Then,
$ make
which will fail at the start of stage 2; the problem is that the tools built in stage 1 expect to find shared libraries in the ultimate install location.
There may well be better ways than the approach I adopted, which was to install the libraries in the proper place:
mkdir -p /usr/local/gnat/5.1.0/lib for l in `find stage1-x86_64-apple-darwin13/ -type f -name \*.dylib`; do sudo cp $l /usr/local/gnat/5.1.0/lib/; done
and then delete the whole build directory and start over from the configuration step (trying to carry on from the point of failure resulted in failure at 'compare stage 2 and stage 3').
Testing
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. I ony ran Ada and Fortran.
make check-ada
=== acats Summary === # of expected passes 2320 # of unexpected failures 0 === gnat Summary === # of expected passes 1327 # of expected failures 20 # of unsupported tests 9
make check-fortran
=== gfortran Summary === # of expected passes 48034 # of expected failures 64 # of unsupported tests 78
(I assume that C and C++ will be adequately handled by the mainstream).
It's also possible to make check-gmp, make check-mpfr, make check-mpc (though the last failed the last time I tried it).
Installation
$ sudo make install
... and now all you need to do is to put /usr/local/gnat/5.1.0/bin at the front of your PATH, and you're using the new compiler.
Shared libraries
There's one glitch new to GCC 5 vs GCC 4; one part of gprbuild derives the shared library name from the header at the start of .ali files (used to be "GNAT Lib v4.9", now "GNAT Lib v5", and another (the part to do with building shared libraries) derives it from - I think - the output of gnatls -v, for example GNATLS 5.1.0. This means that you need to provide the libraries under both name styles; the compiler build only generates one, for example libgnat-5.dylib.
cd /usr/local/gnat/5.1.0/lib/gcc/x86_64-apple-darwin13/5.1.0/adalib sudo ln -s libgnarl-5.dylib libgnarl-5.1.dylib sudo ln -s libgnat-5.dylib libgnat-5.1.dylib
Support libraries
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)
Tools
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=/usr/local/gnat/5.1.0/bin:$PATH
XML/Ada GPL
This is needed by GPRbuild, see below.
The GPL 2014 download unpacks into xmlada-2014-src/. In that directory,
$ ./configure --prefix=/usr/local/gnat/5.1.0 --build=x86_64-apple-darwin13 $ make $ sudo make install
GPRbuild
As well as the archive from AdaCore, get the patch gprbuild-2014-src-gcc-5.1.0.diff.
The patch does two things:
- 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 2014 download unpacks into gprbuild-2014-src/. In that directory,
$ patch -p1 <~/Downloads/gprbuild-2014-src-gcc-5.1.0.diff $ ./configure --prefix=/usr/local/gnat/5.1.0 --build=x86_64-apple-darwin13 $ make $ sudo make install
XML/Ada SVN
You may want to install the version of XML/Ada from the public Subversion repository, which has the advantage of being licenced with the GCC Runtime Library Exception.
One patch is still required; for revision 238235 it is xmlada-238235.diff.
AUnit
The GPL 2014 download unpacks into aunit-gpl-2014-src, and uses gprbuild not only to build the library but also to determine where the library should be installed. In aunit-gpl-2014-src,
$ make $ sudo make install
GNAT_Util
Since GNAT GPL 2013, AdaCore have extracted internal compiler components, used by (at least) ASIS and GNATColl, into a separate library gnat_util.
At least for ASIS, the components used to build it must match the components in the compiler, so building ASIS for use with FSF GCC 5.1.0 requires a version of GNAT Util which contains components from FSF GCC 5.1.0.
The GNAT Util Library project at SourceForge provides the source of such a version. Download the 5.1.0 version, implement the directions in the README, make, sudo make install.
GNATColl
Get the patch gnatcoll-gpl-2014-src-gcc-5.1.0.diff as well as the AdaCore download.
The GPL 2014 download unpacks into gnatcoll-gpl-2014-src/. Apply the patch.
I configured with
./configure \ --prefix=/usr/local/gnat/5.1.0 \ --build=x86_64-apple-darwin13 \ --enable-gpl \ --without-postgresql
which is minimal apart from GNU Readline being enabled and PostGres being disabled. You may wish to reconfigure for your own requirements.
The resulting overall configuration is
Shared libraries: yes (default: static) Gtk+: no (requires pkg-config and gtkada.gpr) Python: yes /System/Library/Frameworks/Python.framework/Versions/2.7 (see --with-python) PyGtk: no (see --enable-pygtk) PyGObject: no (see --enable-pygobject) Syslog: yes (see --enable-syslog) Readline (GPL license): yes (see --with-readline --enable-gpl) gmp: no (see --with-gmp) PostgreSQL: no (see --with-postgresql) Sqlite: embedded (see --with-sqlite) Iconv: yes (see --with-iconv) Projects: yes
Then,
$ make $ sudo make install
ASIS
As well as the archive from AdaCore, get the patch asis-gpl-2014-gcc-5.1.0.diff.
The GPL 2014 download unpacks into asis-gpl-2014-src/. In that directory,
$ patch -p1 <~/Downloads/asis-gpl-2014-gcc-5.1.0.diff $ make all tools $ sudo make install install-tools
GDB
The GPL 2014 download unpacks into gdb-7.7-gpl-2014-src/. Configure with
./configure \ --prefix=/usr/local/gnat/5.1.0 \ --build=x86-apple-darwin13 \ --disable-werror
Then,
make cd gdb sudo make install
(you really don't want to make install from the top-level directory! it will install all sorts of tools that you didn't want (ar, nm, ranlib ...) and that won't work properly.)
None of the other tools would be required for a cross-compiler. However, if you're going to go on to build one, you'll want GDB, and you'll need to make distclean here first. A better alternative would probably be to build in a parallel directory.
Note that gdb has to be 'code-signed' (unless you're willing to run it as root!). See the instructions for this.
Note also that there are problems with 'catch exception'; one workround is to invoke GDB with the '-readnow' switch. See GDB bug 11385.
No comments:
Post a Comment