[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3 Compiling GPC

The preferred way to distribute GNU software is distribution of the source code. However, it can be a non-trivial exercise to build GNU Pascal on some non-Unix systems, so we also provide ready-to-run binaries for a number of platforms. (See section 5.2 Installation instructions for a GPC binary distribution for how to install a binary distribution.)

GPC is based on the GNU Compiler Collection, GNU CC or GCC. You will need the GCC sources to build it. It must be the same version as the one GPC is implemented with -- 2.95.x as of this writing. Although you need GCC to build the GNU Pascal compiler, you don't need GCC to compile Pascal programs once GNU Pascal is installed. (However, using certain libraries will require compiling C wrappers, so it is a good idea to install the C compiler as well.)

Because GNU Pascal shares its back-end with GCC, it should run on any system supported by GCC. A full list of platforms supported by GCC can be found in section `Chapter 4' in "Using and Porting GNU CC".

The GCC source can be obtained from any mirror of the GNU FTP site, ftp://ftp.gnu.org/gnu/gcc/. The "core" distribution is sufficient for GPC.

Here is the generic procedure for installing GNU Pascal on a Unix system. See section 5.4 Compilation notes for specific platforms for extra information needed to install GPC on DOS-like platforms.

  1. Checking the prerequisites

    Make sure that GNU make is installed. (In the following, we will simply speak of `make' when invoking GNU make; you might need to call `gmake' instead.)

    For extracting the example programs from the documentation to the `doc/docdemos' directory a non-crippled `sed' is needed. GNU sed is known to work.

    If you want to build the GPC WWW pages you will also need: `texi2html' version 1.61 (older versions are missing some needed features; newer versions suffer from a bug), `texi2dvi', TeX, `gzip', `dvips', `dviselect', and `dviconcat'.

    If you run into trouble during the installation process, please check whether you are using outdated versions of the required utilities and upgrade if necessary.

    The GNU versions of the packages above are available from the GNU FTP server or any of its mirrors. Package package is usually located in the directory `gnu/package'.

  2. Unpacking the source

    From a directory of your choice (e.g. `/home/fred'), unpack the GCC and GNU Pascal source distributions. This will create separate subdirectories for GCC and GPC. Let us assume `gcc-2.95.1' and `gpc-20000535' in this example.
     
    % cd /home/fred
    % gzip -c -d gcc-core-2.95.1.tar.gz | tar xf -
    % gzip -c -d gpc-20000535.tar.gz | tar xf -
    

    `cd' to the GPC directory and move the contents (a subdirectory `p') to the subdirectory `gcc' of the GCC directory:

     
    % cd /home/fred/gpc-20000535
    % mv p /home/fred/gcc-2.95.1/gcc/
    

    It is recommended, though not required, to use a separate directory for building the compiler, rather than compiling in the source directory. In this example, let us create `/home/fred/gpc-build' for this purpose:

     
    % mkdir /home/fred/gpc-build
    

    If you use a separate directory, you do not need to write into the GCC source directory once you have patched the GCC source (see below), and can build GPC for more than one platform from the same source tree.

    In case you are re-using a directory where you have already built GCC and/or GPC for a different target machine, do `make distclean' to delete all files that might be invalid. One of the files this deletes is `Makefile'; if `make distclean' complains that `Makefile' does not exist, it probably means that the directory is already suitably clean.

  3. Configuring and building GCC

    GNU Pascal is automatically configured with GCC. Configuration of GCC is treated in depth in section `Chapter 4' in "Using and Porting GNU CC". The normal procedure is as follows:

    `cd' to the GPC build directory. From there, run the `configure' script in the GCC source directory:

     
    % cd /home/fred/gpc-build
    % /home/fred/gcc-2.95.1/configure --enable-languages=pascal
    

    This creates all the necessary config files, links and Makefile in the GCC object directory.

    Note 1: The configuration will prompt you for patching the GCC source for GPC support, so you need write access to that directory. All changes to GCC are surrounded by `#ifdef GPC ... #endif', so they should not interfere when you build a C compiler from this source tree.

    Note 2: The `--enable-languages=pascal' option means that we only want to build the Pascal compiler and not, for instance, the C++ compiler.

    Note 3: The standard base directory for installing GCC and GPC is `/usr/local'. If you want to install files to an alternate directory dir, specify `--prefix=dir' when you run `configure'.

  4. Putting other GNU tools in place

    Some environments require other GNU tools (such as the GNU assembler or linker) instead of the standard system tools for GCC to work. (See the GCC installation instructions for details.) If this is the case for your system, install the required tools in the GPC build directory under the names `as', `ld', or whatever is appropriate. This will enable the compiler to find the proper tools for compilation of the program `enquire' (a part of GCC) and to install the GNU tools to a place where they are found by GCC but do not interfere with the standard system tools.

    Alternatively, you can do subsequent compilation using a value of the PATH environment variable such that the necessary GNU tools come before the standard system tools.

  5. Compiling GPC

    Once you are satisfied with the configuration as determined by `configure', you can build the compiler:

     
    % make
    

    Notice that this procedure will build the C compiler (and maybe some other compilers) too, because that is used to compile the GPC runtime library.

    Optionally, you may supply CFLAGS, LDFLAGS or RTSFLAGS. CFLAGS is used for compiler and RTS, RTSFLAGS are for RTS only, i.e.: `make CFLAGS="-O2" RTSFLAGS=-Wall'

  6. Completing the installation

    When everything has been compiled, you can check the installation process with:

     
    % make -n install
    

    To complete the installation, run the command `make install'. You need write access to the target directories (`/usr/local/bin', `/usr/local/lib', `/usr/local/info', `/usr/local/doc', and `/usr/local/man' in this example), so this is usually done as `root':

     
    % su -c "make install"
    

    If you want to install only the Pascal compiler (for example if you already have the correct version of GCC installed), `cd' to the `gcc' subdirectory of the build directory (e.g. `/home/fred/gpc-build/gcc') and run `make pascal.install'. This installation process does not overwrite existing copies of `libgcc.a' or `specs', should they exist.

    There is a (partial) translation of the GPC manual into Croatian available now. It is not installed by default. If you want to install it, do a `pascal.install-hr' in the `gcc' directory. This will install the manpage `gpc-hr.1' and the info documentation `gpc-hr.info*'. Other formats like PS, PDF and HTML can be built manually (it's also easy to add appropriate make targets for them when needed).

    Also from the `gcc' subdirectory you can do some more "exotic" builds. For instance, you can build the GPC WWW pages by typing `make pascal.html' or a binary distribution by typing `make pascal.bindist'. See the `Makefile' in that directory for more examples.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html