2 Installating Gnat on Linux

 

  <--Last Chapter Table of Contents Next Chapter-->  

 

GCC Ada was original called Gnat. Over the years it has undergone many changes, with different download sites, versions and patches. This chapter covers the various version, where to get them and how to install them.

GCC Ada is a part of the GCC (GNU Compiler Collection) project. The "gcc" command itself isn't a compiler: it's a program that determines the appropriate software to comple your source code file. The Ada compiler is called gnat1. The C compiler is cc1. When gcc detects an Ada source file, it runs the gnat1 program to compile it.

Because the gcc system and GCC Ada must work as a team, specific versions of Ada are created for specific versions of gcc. Gnat 3.10p was compiled against the gcc for Linux kernel 2.0.29 (for example, the version of gcc used in the Slackware 3.2 distribution). Gnat 3.11p, 3.12p and 3.13p are compiled against gcc 2.8.1.

NoteTo find out which version of gcc you have, run gcc with the -v switch.
 

There are public (unsupported) and commerical versions of GCC Ada. Prior to GCC 3.0, the public version of Gnat was distributed separately from the GCC project and was available from ftp://cs.nyu.edu/pub/gnat. The GNU Ada Team (http://gnuada.sourceforge.net) release RPMs for Linux and other OS's. of Ada for different versions of Linux. Some people refer to these older versions as GNAT/GPL, to distingiush them from GNAT/GCC.

In addition, GNAT/GPL has a GPL restriction on the Ada Run-time library. The RTL provides much of the basic functionality of Ada and is required for most Ada programs to run--for example, Text_IO is in the RTL and switching off the RTL would prevent put_line( "Hello World!") from running. This means that programs written in older versions of GNAT must conform to the GPL license. (I don't know for sure but this is probably an oversight by Ada Core Technologies since they have always insisted that GNAT can be used to develop non-GPL applications.) GNAT/GCC removed the GPL requirement from the Run-Time Library so that programs written in modern versions of GNAT are not restricted to a particular license.

The GNAT compiler source code is distributed with a license called GNAT- Modified GPL (GMGPL). This is an extension of GPL to allow open use of Generics/Templates which are not covered in the regular GPL.

With GCC 3.0, the public version of Ada is included in GCC and GCC Ada is available for most Linux distributions. To test to see if you have Ada support, create a file called "hello.adb" and try compiling it with "gcc hello.adb". If gcc recognizes the file as an Ada program, then your copy of gcc has Ada support included.

The version included with GCC 3.0 to 3.3 was Gnat 5 and was considered experimental. That is, it hadn't undergone rigorous testing and changes to the gcc system may introduce new bugs. GCC 3.4 to 4.x are considered stable.

Commercial supported versions (GNAT Pro) and academic versions of GCC Ada are available from Ada Core Technologies (ACT). They also have a software buildle called "GNAT/GPL" containing the Gnat compiler, various libraries (XML, CORBA, GTK, GLADE distributed processing) available through their web site.

You can check which version of Gnat you are running using like this:

$ gnatmake -v 2>&1 | head

GNATMAKE 4.0.2 20050901 (prerelease) (SUSE Linux)
Copyright 1995-2004 Free Software Foundation, Inc.
Usage: gnatmake  opts  name  {[-cargs opts] [-bargs opts] [-largs opts] [-margs opts]}

2.1 Installing GCC Ada on Linux

GCC Ada is included in most modern versions of Linux, although it may not be installed by default. Use your installation tool to search for "Gnat" or "GCC Ada". In some cases, it may be a part of the "extras" archive for your distribution (that is, software not included standard but available for download from the distribution's web site). For Novell's OpenSUSE 10, Ada can be found by installing for "gcc-ada" and "libada" with YAST. On Red Hat Fedora, GCC Ada is automatically included with a full install. Slackware Linux, Debian and even FreeBSD have versions of GCC Ada available.

You can also look for installable versions GCC Ada at http://sourceforge.net/projects/gnuada. The source code for GCC Ada, of course, is a part of the GCC source code available at the GCC home page.

Be aware that some versions of Linux include the old "GNAT" version of Ada (usually version 3.14p or 3.15p). These versions are based on the GCC 2 and are out-of-date. They are missing many modern features, such as support for the new Ada 2005 standard.

2.2 Building GCC Ada from Sources

Occasionally you may want to compile Gnat yourself from its sources. For example,

GCC Ada is a standard part of the GCC languages. However, GCC Ada requires GCC Ada in order to build a new version. Bootstrapping GCC Ada on a machine without an Ada compiler is beyond the scope of this book.

In simple terms, follow the directions to build GCC included in the GCC source code or from http://gcc.gnu.org/install/. When it is time to specify what languages you would like to build, include "ada" in the language list. (Even "all" will not include Ada--it must be requested explicitly. "all" represents the most common GCC languages.)

Rumour has it that GNAT 3.15p can be used to bootstrap GCC 4.1 or newer. You will need to run configure with "CC=adagcc configure" to do this. Older versions of GCC are not so GNAT 3.15 friendly.

2.3 Installing the old NYU Gnat

Ada versions 0.0 to 3.x are available for download from the NYU web site. The version refers to the version of the Ada compiler, not GCC. These all all built for GCC 2.x.

You may want to install the old public versions of Gnat on very old versions of Linux. The standalone Gnat distribution from ACT comes with its copy of the correct version of gcc and can install Gnat and its gcc in a separate directory. The binary versions from ACT's web site have C++ support removed, so if you want gcc to support C++ and Ada simultaneously, you'll have to recompile gcc and Gnat from their sources.

The ACT releases of GNAT include letter codes:

The version numbers have special meaning:

NoteIt is possible to install one version of gcc overtop of another and to select one version or the other using the gcc -V switch, but gcc must again be recompiled from its (newest) sources to make it aware of the other version.

There are patches available via the Ada Linux Team web site for compiling gnat from the sources for the egcs compiler instead of gcc. egcs (pronounced "eggs") is a variation of gcc designed specifically for Pentium computers. Egcs is based on gcc 2.8.0. Slackware 3.6, for example, used egcs. The egcs optimizations are obsolete with GCC 3.0.

The binaries on the NYU web site (http://cs.nyu.edu/pub/gnat) do not have the extra features available with the ALT RPMs, but they include extra installation information, including how to install Gnat's various add-ons. There are also versions for other operating systems besides Linux.

Note Gnat 3.12 and older have an additional install option to overwrite you're existing copy of gcc, provided it is right version. Since it is rare that a distribution has the exact same version of gcc, this option is no longer provided.

ACT will sometimes release several versions of Gnat for different C libraries. When downloading the binaries, make sure that you download the version compiled against the appropriate C library. This is due to the constantly evolving nature of Linux.

NoteTo find out which libc library your distribution uses, examine the /lib/libc.so link to find out which file it points to. For example, if /lib/libc.so points to a libc5 library, then you'll need the libc5 version.

For example, version 3.13p has been compiled for gcc 2.8.1. If you don't have gcc 2.8.1, you can specify a separate directory where gnat will install itself and its own personal copy of gcc 2.8.1. Using this method, you need to perform an additional step. The installation program (doconfig) creates a shell script containing environment variables that you can copy to your shell startup script (under bash, this is usually the .profile file in your home directory). Gcc uses these variables to locate the gnat files.

You will need to include the gnat directory in the front of your PATH variable to prevent gnat from using the gcc that came with your Linux distribution. For example, use the shell command:

  export PATH="/usr/gnat/bin:$PATH"

Only use this command when you want to use Gnat since it effectively hides the copy of gcc that came with your distribution.

If you don't want gnat to be enabled by default, you can write a short shell script that assigns the environment variables, sets the path, and starts a new shell.

2.4 Installing the old ALT Gnat

The Ada Linux Team version of Gnat is available from their web site. Versions exist for the Red Hat, S.u.S.E. and Debian distributions. They may also work on the Mandrake and Caldera distributions.

Recently, the chief ALT maintainer has moved onto other interests and the ALT web site is out-of-date. Due to Gnat's integration into Gcc 3.x, there has been less interested in Gnat RPMS. However, there are still RPMs around hosted by other people (and usually based on the ALT system). Check out other sites such as ftp.ada95.com/pub/gnat-3.14p/RH-7/ or http://prdownloads.sourceforge.net/gnuada/.

The ALT versions include support for ASIS, GLADE and native Linux threads. The package includes gnatgcc, a version of gcc with Gnat and C++ support, and gnatgdb, a version of gdb that supports Ada source code, plus gnatprep and the other Gnat utilities.

NoteThe rpm files are built for Red Hat and S.u.S.E. distributions. If you try installing it on another distribution, use --nodep to ignore any package dependency warnings.

RPMS for Version 3.15p for Red Hat 7.2 are available at http://www.alex.wubn.net/packages/3.15p/RPMS and http://www.alex.wubn.net/packages/3.15p/SRPMS.

 
  1. Download and read the readme file.
  2. Download the gnat-3.xxp-runtime* rpm file (where xx is the current version of Gnat and * is the rest of the filename). For older RPMs, this is gnat-3.xxp*.
  3. Download the gnat-3.xxp rpm file. For older RPMs, this is gnat-3.xxp-devel*.
  4. rpm -i gnat-3.xxp-runtime*
  5. rpm -i gnat-3.xxp*
  6. Download and install any of the additional Gnat packages you need
The rpm files on the ALT site are configured to work with the ALT version of gnat. To install them, simply download them and run rpm with the -i switch.

The ALT GNAT build system is available for those wanting to know more about how the RPMs are constructed. Using CVS, you can check our the source code.

   export CVSROOT=":pserver:anoncvs@hornet.rus.uni-stuttgart.de:/var/cvs"
   cd $HOME
   cvs login  # (use empty password)
   cvs -z9 co -d ALT gnuada/alt-build
 

2.5 Compiling Older Versions of Gnat from Sources

In order to recompile Gnat 3.x, you'll need the following:

  1. A copy of the gcc sources in order to build a copy of gcc that's compatible with Gnat. The required version is listed in the Gnat documentation.
  2. A copy of the gnat sources. The sources are available for download from the gnat download site and its mirrors.
[I should compile gnat and make notes and flush out the details more--KB]

First, you need to recompile the gcc compiler. Make sure you follow gcc's instructions for activating Ada support.

make CFLAGS="-g -fsigned-char" LANGUAGES="c c++ ada"
make stage1
make CC="stage1/xgcc -Bstage1/" CC="-g -O2 -fsigned-char" STAGE_PREFIX="stage1/" LANGUAGES="c c++ ada"
<build tools and lib with CC="./xgcc -B./">
There are two problems that can arise:
  1. The standard C library may have changed.
  2. The souce code for the gcc compiler itself may have changed.
Changes to the C library rare unless the library is several generations out of date. Even so, by consulting the man pages you can usually find out the new parameters the various C functions expect.

Upgrading gcc to a new version of gcc, however, can be difficult. Gnat's gcc patches are designed for a specific version of gcc. It is usually a good idea to get a copy of the source code for the version of gcc Gnat was designed for and compile a second gcc compiler just for use with Gnat. For gnat 3.13, you'll need the gcc 2.8.1 source code. You should be able to compile an older version of gcc to work with newer C libraries, provided the compiler is only a few months out of date.

Now follow the directions to compile Gnat. Make sure libgnat.a is accessible to the linker. If it isn't, copy it to /usr/lib and run ldconfig to update Linux's shared library tables.

2.6 Case Study: Installing Gnat 3.11 on over an old Linux Distribution

We installed Gnat 3.11p on a Pentium running a Slackware distribution with egcs and lib6. We wanted to replace egcs with gcc 2.8.1 and install the Gnat binaries (compiled for 2.8.1) over top.

We first went to the Sunsite mirror which provides Linux compiled binaries of gcc, ready to be unpacked and installed Unfortunately, the readme file reported they had trouble compiling gcc and supplied egcs instead. egcs is based on gcc 2.8.0 which meant that we couldn't use it with gnat 3.11. Instead we downloaded the gcc 2.8.1 source code from a GNU FTP mirror site and prepared to build the compiler from scratch.

  1. We ran Gnat doconfig program and select option 1. The gcc path that it's expecting is displayed as i686-pc-linux-gnu. This was going to be our configuration host setting for gcc.
  2. We followed the instructions in the gcc INSTALL file. configure --with-gnu-as --with-gnu-ld --enable-threads=posix --host i686-pc-linux-gnu
  3. We checked the gcc makefile to make sure i686-pc-linux-gnu was reasonable. It required lib6 and lib6 was installed. The Makefile also showed that the i686 setting is compatible with our Pentium (i586).
  4. Before running make, we changed the Makefile's OLDCC variable from cc to /usr/bin/gcc. There was a cpp syntax error while building libgcc1.a, probably the error the Slackware people encountered. We tracked down the line causing the problem in the Makefile and discovered they were calling cc to do the compiling, which doesn't handle the C preprocessor (cpp) properly. Typing in the line at the shell prompt showed that /usr/bin/gcc worked fine while /usr/bin/cc would not. The note in the Makefile said we shouldn't use gcc to avoid circular references in some of the functions (that is, that it might inadvertantly call the 2.8.1 compiler instead of the old 2.7.2.3 compiler), so we made sure we included the full path.
  5. make LANGUAGES="c c++"
  6. mkdir stage1; make stage1
    make CC="stage1/xgcc -Bstage1/" CFLAGS="-g -O2 -fsigned-char"
  7. mkdir stage2; make stage2
    make CC="stage2/xgcc -Bstage2/" CFLAGS="-g -O2 -fsigned-char"
  8. make compare reported no errors.
  9. make install CC="stage2/xgcc" -Bstage2/" CFLAGS="-g -O2" LANGUAGES="c c++"
  10. gcc -v  and  gcc -dumpversion reported the correct version. We deleted the old /usr/lib/gcc-lib/i486-linux directory to save some space.
  11. We installed gnat by running doinstall

If we were doing C++ programming, we would need to install the standard C++ library, libstdc++, as well. In this case, we enabled C++ support to avoid recompiling gcc for C++ in the future.

2.7 Gnat and Windows

Although this is a Linux book, here's some tips for Windows users:

Most Gcc uses use the Cygwin system which has a POSIX-compliant run-time system. This makes it easier to port and run programs from UNIX-like systems, including Linux. However, Gnat is based on Mingw and it uses the msvcrt runtime. (The reason for Mingw is, apparently, a problem with the Cygwin licensing agreement.) Unfortunately, because they have different run-time systems, Cygwin and Mingw are not compatible with one another.

If you want to build it on windows, you'll need the Mingw compiler. Try http://www.mingw.org/download.shtml" and look for the "experimental/test packages" section. If you have Cygwin and want it to use Gnat at the same time, you'll modify the registry entries for Gnat and replace GCC for GNAT_GCC in key names/values. If you're willing to use the Mingwin version of Gcc for your C programs, put the Gnat/Mingwin path ahead of the Cygwin path in your environment PATH variable.

For those simply looking for a compiler to run at the DOS prompt, DJGPP (the Gcc for MS-DOS project) supports recent versions of Gnat.

ACT sells commerical support for Gnat on VxWorks, the Windows emulator for Linux.

 

  <--Last Chapter Table of Contents Next Chapter-->