2 Installating Gnat on Linux

 

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

 

Gnat is a part of the gcc project. The gcc command itself isn't a compiler: it's a program that determines the kind of source file you have and runs the appropriate compiler for you. For example, the Ada compiler is called gnat1, and the C compiler is called cc1. When gcc detects an Ada source file, it runs gnat1 to compile it.

Because gcc and Gnat must work as a team, specific versions of Gnat are created for specific versions of gcc. Gnat 3.10p is compiled against the gcc for 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.

The standard 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.
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 ALT 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 being merged with gcc for the upcoming release of gcc 3.0. ACT has announced plans to fold Gnat into the Gcc project for Gcc 3.1 and have moved some of their discussions to the gcc mailing list.

2.1 Installing the ALT RPMs

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.

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.

  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.2 Installing the ACT Binaries

The latest version of the Gnat compiler is available from the ACT FTP site. These binaries 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.

The latest public version from ACT is 3.13p, which has been compiled for gcc 2.8.1.

By default, Gnat is installed in a /usr/gnat subdirectory.

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.3 Compiling Gnat from its Sources

Occasionally you may want to compile Gnat yourself from its sources. For example, In order to recompile Gnat, 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.

[More here - KB]

2.4 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.  

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