Go to the first, previous, next, last section, table of contents.

# Installing GNU Pascal

This chapter covers:

- Compilation of the source distribution on a UNIX system
- Configuration dependent compilation notes
- Building and installing a cross-compiler
- Installation instructions for a GPC binary distribution

- compilation notes: Configuration dependent compilation notes
- crosscompilers: Building and Installing a crosscompiler
- binary distributions: Installation instructions for a GPC binary distribution

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 Installation instructions for a GPC binary distribution how to install a binary distribution.

GPC is based on GNU CC; you will need the GCC sources to build it. It must be the same version as the one GPC is implemented with. Although you need GCC to build the GNU Pascal compiler, you don't need GCC to compile Pascal programs once GNU Pascal is installed. Because GNU Pascal shares its backend with GNU CC, it should run on any system supported by GNU CC. A full list of platforms supported by GNU CC can be found in chapter 4 of the GCC manual, "Using and Porting GNU CC"

Here is the generic procedure for installing GNU Pascal on a Unix system. See section Configuration dependent compilation notes for extra information needed to install GPC on certain platforms.

1. Unpack the source distributions. Sources for GNU CC and GNU Pascal must be unpacked in separate directories. Do not move GNU Pascal files into the GNU C source directory. It is possible, though not required, to build the compiler(s) in a directory other than the one containing the sources. In either case, you need a ``make'` that understands the VPATH variable. GNU make does, although at least GNU make version 3.71 has a bug in the way it treats VPATH. GNU make version 3.74 is known to work. If you have built GNU Pascal previously in the same directory 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.
2. Configuring and building GNU CC GNU Pascal shares its configuration with GNU CC. The configuration options you select for GCC, apply for GNU Pascal too. Configuration of GNU CC is treated in depth in Chapter 4 of "Using and Porting GNU CC" Chdir to the GCC object directory. Usually,

       % ../gcc-2.7.2.1/configure --prefix=/usr

   will do the job. This creates all the necessary config files, links and Makefile in the GCC object directory.
3. The standard directory for installing GNU CC and GNU Pascal is ``/usr/local/lib'`. If you want to install its files somewhere else, specify ``--prefix=dir'` when you run ``configure'`. Here dir is a directory name to use instead of ``/usr/local'` for all purposes with one exception: the directory ``/usr/local/include'` is searched for header files no matter where you install the compiler. To override this name, use the `--local-prefix` option below.
4. Specify ``--local-prefix=dir'` if you want the compiler to search directory ``dir/include'` for locally installed header files instead of ``/usr/local/include'`. You should specify ``--local-prefix'` only if your site has a different convention (not ``/usr/local'`) for where to put site-specific files. Do not specify ``/usr'` as the ``--local-prefix'`! The directory you use for ``--local-prefix'` must not contain any of the system's standard header files. If it did contain them, certain programs would be miscompiled (including GNU Emacs, on certain targets), because this would override and nullify the header file corrections made by the `fixincludes` script.
5. Make sure the Bison parser generator is installed. (This is unnecessary if the Bison output files ``c-parse.c'` and ``cexp.c'` are more recent than ``c-parse.y'` and ``cexp.y'` and you do not plan to change the ``.y'` files.) Bison versions older than Sept 8, 1988 will produce incorrect output for ``c-parse.c'`.
6. If you have chosen a configuration for GNU Pascal which requires other GNU tools (such as GAS or the GNU linker) instead of the standard system tools, install the required tools in the 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'`. 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.
7. Build the C compiler:

       % make LANGUAGES=c

   (Just ``make'` would also build the C++ and Objective C compilers). You do not need to install the compiler you just built, but leave the objects in place, since GPC will directly load most of the GCC object files.
8. Configuring and building GNU Pascal for your system. Normally, you just ``cd'` to the directory containing the source code and type ``./configure'`. If you're using ``csh'` on an old version of System V, you might need to type ``sh configure'` instead to prevent ``csh'` from trying to execute ``configure'` itself (under AIX, you may need to use ksh instead of sh). To compile the GNU Pascal in a different directory from the one containing the source code, ``cd'` to the directory where you want the object files and executables to go and run the ``configure'` script. ``configure'` automatically checks for the source code in the directory that ``configure'` is in. If for some reason ``configure'` is not able to find the source directory, rerun ``configure'` with the option ``--srcdir=dir'`, where dir is the directory that contains the source code. Note that the gpc ``configure'` script does not accept most of the switches usually given to a ``configure'` script because it extracts this information from the GCC configuration files. Run ``configure --help'` to see the options supported by ``configure'`. Running ``configure'` takes a while. While it is running, it prints some messages that tell what it is doing. If you don't want to see any messages, run ``configure'` with its standard output redirected to /dev/null; for example, ``./configure >/dev/null'`. If ``configure'` is unable to locate GNU CC sources or object code, it will print an error message and exit. In that case, run ``configure'` again with ``--with-gccsrc=dir'` and / or ``--with-gccbin=dir'` arguments. When it is finished, ``configure'` prints a short summary of the information it has collected.

       --------------------------------------------------------------------------
       Configuration summary:
         Building a native i486-linux compiler

         GPC sources in:         .
         GCC sources in:         ../gcc-2.7.2.1
         GCC object code in:     ../gcc-2.7.2.1
         GCC version:            2.7.2.1

         Compiler for GPC:       gcc
         Compiler for libgpc.a:  gcc
         Compiler flags:         -g -O

         Installation path:      /usr/bin, /usr/lib/gcc-lib/i486-linux/2.7.2.1
       --------------------------------------------------------------------------

       Now, type `make' to build the compiler and runtime system.

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

       % make

   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'`
10. When everything compiles, you can verify what the `make -n install` command does, and if you are satisfied run it without the `-n` option to install the compiler (gpc1), front end (gpc), run time system (libgpc.a) to the same place where gcc was installed. It is sort of stupid to have a separate incarnation of ``gcc.c'`; the difference now is that ``gpc'` also searches from library ``libgpc.a'` and ``-lm'`. In addition ``gcc.c'` specifies the interface to the Pascal compiler (gpc1). This command will vanish when ``gcc'` knows how to compile Pascal programs.

## Configuration dependent compilation notes

- Alpha OSF/1: Installation on an Alpha OSF/1 system
- DOS: The DJGPP port of GNU compilers to MS-DOS
- DOS, OS/2: The EMX port of GNU compilers to MS-DOS and OS/2
- Win32: Installation on a Windows 95/NT system

### Alpha OSF/1

For alpha OSF/1 v3.2 (GCC 2.6.3): If your linker starts to output error messages like:

    Warning: Linking some objects which contain exception information sections
        and some which do not. This may cause fatal runtime exception handling
        problems (last obj encountered without exceptions was <OBJ/LIB>)

I do not know why these started to appear, but you can get rid of these if you do as follows in the GPC object directory.

You need to trigger the Makefile dependencies, e.g. by doing the touch command below. What happens is that it re-generates the version.c and rts/version.c files, which need to be recompiled with `ALPHA_BUG` defined.

Example:

    % touch Makefile
    % make MY_CFLAGS=-DALPHA_BUG other-make-flags-you-want-to-use

### MS-DOS with DJGPP

You cannot build GNU CC (or GNU Pascal) by itself on MS-DOS; it will not compile under any MS-DOS compiler except itself. The official MS-DOS port of GCC is called djgpp, and it is available from ``simtel.coast.net'` and it has mirrors all over the world. The ``configure'` script is replaced by an MS-DOS batch file called ``configure.bat'` wich does essentially the same. Detailed instructions are in the file ``config/msdos/README.dj'` of the GNU Pascal source distribution.

### MS-DOS or OS/2 with EMX

EMX is a FreeWare 32-bit DOS extender which adds some properties of UNIX to the DOS and OS/2 operating systems written by Eberhard Mattes. You can find it, for example, via anonymous ``ftp'` on the server ``ftp.uni-stuttgart.de'` in the directory ``pub/systems/os2/emx*'`.

The EMX extender for DOS and OS/2 makes it relatively easy to port GNU tools--such as the GNU Pascal Compiler--to these platforms. However, it is not straightforward to compile it.

1. I assume you have the EMX package installed with GNU development tools and the `dmake` make utility. You have compiled GNU C such that the object files are still in place. It is important that GNU C is the version matching ot GNU Pascal which is currently 2.7.2.1. If you have problems compiling GNU C: The directory ``config/emx'` contains drive-independent versions of ``dostage1.cmd'` and ``makeexe.cmd'`. If you are running DOS, you are in trouble now because the DOS command line is limited to 128 characters. If you succeed to compile GPC for EMX on a DOS system, please let us know. (However you can compile GPC for DJGPP on a DOS system.)
2. Unzip the source for GPC from the emx directory, so it will go into the gnu subdirectory. Unlike other EMX sources, the GPC source must *not* be extracted from the root directory.

         cd \emx
         pkunzip -d c:\gpc-2721

3. Configure and make your GNU Pascal compiler and runtime system. You need not call ``dmake'` directly; call ``make.cmd'`, instead.

         configur
         make

4. To install, type

         make install

### Windows NT and Windows 95 with cygwin32

cygwin32 is a project to make it easy to port Unix applications to machines which run an OS which supports the Win32 API - ie Windows 95 and Windows NT. Currently, cygwin32 is in beta stage; it is available from ``ftp://ftp.cygnus.com/pub/gnu-win32/'` Don't use gcc sources from the cygwin32 distribution. These are not just modified from FSF gcc-2.7.2 to support the win32 target, they are the "current development release", and too different from FSF gcc to be compatible with GNU Pascal, which is based on FSF sources.

Instead, apply ``config/cygwin32/gcc-2.7.2.cygwin32-beta16.diff'` to FSF gcc-2.7.2 to add cygwin32 platform support to gcc. The GNU pascal sources already have the cygwin32 support, so no further patching of gpc is needed

Currently, cygwin32 is not self-hosting: the preferred way to build the cygwin32-gpc binary is to use a unix system with a cygwin32 targeting crosscompiler. See section Crossbuilding a compiler.

GNU Pascal does not yet fully support the stack calling convention of the Win32 API, thus making it impossible to access system DLL's.

## Building and Installing a crosscompiler

GNU Pascal can function as a cross-compiler for many machines, but not all. Also, only a few combinations have been tested. If you need information about GNU tools in a cross-configuration, ``ftp://ftp.cygnus.com/pub/embedded/crossgcc/'` is the place to be.

- Cross-compilers for the Mips as target using the Mips assembler currently do not work, because the auxiliary programs ``mips-tdump.c'` and ``mips-tfile.c'` can't be compiled on anything but a Mips. It does work to cross compile for a Mips if you use the GNU assembler and linker.
- Cross-compilers between machines with different floating point formats have not all been made to work. GNU C now has a floating point emulator with which these can work, but each target machine description needs to be updated to take advantage of it.
- Cross-compilation between machines of different word sizes is somewhat problematic and sometimes does not work.

Since GNU Pascal generates assembler code, you probably need a cross-assembler that GNU Pascal can run, in order to produce object files. If you want to link on other than the target machine, you need a cross-linker as well. You also need header files and libraries suitable for the target machine that you can install on the host machine.

- Steps of Cross: Using a cross-compiler involves several steps that may be carried out on different machines.
- Configure Cross: Configuring a cross-compiler.
- Build Cross: Actually building a Pascal cross-compiler.
- Crossbuilding: Crossbuilding a Pascal compiler.

### Steps of Cross-Compilation

To compile and run a program using a cross-compiler involves several steps:

- Run the cross-compiler on the host machine to produce assembler files for the target machine. This requires header files for the target machine.
- Assemble the files produced by the cross-compiler. You can do this either with an assembler on the target machine, or with a cross-assembler on the host machine.
- Link those files to make an executable. You can do this either with a linker on the target machine, or with a cross-linker on the host machine. Whichever machine you use, you need libraries and certain startup files (typically ``crt....o'`) for the target machine.

It is most convenient to do all of these steps on the same host machine, since then you can do it all with a single invocation of GNU Pascal. This requires a suitable cross-assembler and cross-linker. For some targets, the GNU assembler and linker are available.

### Configuring GNU CC as a crosscompiler

No special actions have to be taken to configure GNU Pascal as a crosscompiler. Cross-compiler specific configuration is done only for GCC. Section 4.2 of "Using and Porting GNU CC" deals with cross-configurations in great detail. Once cross-binutils and a C library for the target machine are in place, GCC can be configured (from the GCC object directory). Suppose we are on a Linux system and want a cross-compiler that produces code that runs on MS-DOS:

    % ../gcc-2.7.2.1/configure --prefix=/usr --target=i386-go32

This creates all the necessary config files, links and Makefile in the GCC object directory. Now, proceed with the compilation and installation process like in the case of the native configuration described before. Do not remove files from the GCC object directory; the cross-compiler is used to compile the GNU Pascal runtime system (RTS) for the target system.

### Building the Pascal crosscompiler

Once you have verified the C crosscompiler, the Pascal cross-compiler can be configured and built. Note that the ``configure'` script does not require any cross-compiler related switches because GPC inherits all of this from GNU CC.

Sample output for a linux->msdos cross configuration:

    --------------------------------------------------------------------------
    Configuration summary:
      Building a i386-go32 crosscompiler hosted by i486-unknown-linux

      GPC sources in:         ../gpc-2.0
      GCC sources in:         ../gcc-2.7.2.1
      GCC object code in:     ../gcc
      GCC version:            2.7.2.1

      Compiler for GPC:       gcc
      Compiler for libgpc.a:  i386-go32-gcc
      Compiler flags:         -g -O

      Cross-ar utility:       i386-go32-ar
      Cross-ranlib utility:   i386-go32-ranlib

      Installation path:      /usr/bin, /usr/lib/gcc-lib/i386-go32/2.7.2.1
    --------------------------------------------------------------------------

    Now, type `make' to build the compiler and runtime system.

Building a cross-compiler requires cross-binutils for your target, i386-go32 in this examples. If ``configure'` is not able to find ``i386-go32-ar'` and/or ``i386-go32-ranlib'`, you may have to run it again with again with `--with-ar=your-cross-ar` or `--with-ranlib=your-cross-ranlib` switches.

Then, ``make'` and ``make install'` the cross-compiler like you would for a native configuration.

### Crossbuilding a compiler.

Yet another possibility is crossbuilding : Using a crosscompiler to build GNU Pascal results in a compiler binary that runs on the cross-target platform. A possible reason why anybody would want to do this, is when the platform on which you want to run the GNU Pascal compiler, is not self-hosting. An example is cygwin32.

To crossbuild GNU Pascal, you have to install a crosscompiler for your target first. This is covered in chapter 4 of "Using and Porting GNU CC". Assuming you want to build a native cygwin32 Pascal compiler on a Linux system, configure GCC:

    % ../gcc-2.7.2.1/configure --prefix=/usr --build=i486-linux \
    	--host=i386-cygwin32 --target=i386-cygwin32

Build it:

    % make CFLAGS=-O2 LANGUAGES=c

Now, configure and build GPC. The output of ``configure'` should look like:

    --------------------------------------------------------------------------
    Configuration summary:
      Building a i386-cygwin32 crosscompiler hosted by i386-cygwin32

      GPC sources in:         ../gpc-2.0
      GCC sources in:         ../gcc-2.7.2.1
      GCC object code in:     ../gcc
      GCC version:            2.7.2.1

      Compiler for GPC:       i386-cygwin32-gcc
      Compiler for libgpc.a:  i386-cygwin32-gcc
      Compiler flags:         -g -O

      Cross-ar utility:       i386-cygwin32-ar
      Cross-ranlib utility:   i386-cygwin32-ranlib

      Installation path:      /usr/bin, /usr/lib/gcc-lib/i386-cygwin32/2.7.2.1
    --------------------------------------------------------------------------

    Now, type `make' to build the compiler and runtime system.

Again, ``configure'` should be able to detect and configure this setup without additional flags. If not, specify ``--with-ar'`, ``--with-ranlib'`, ``--with-gcc'` and/or ``--with-rtsgcc'` as appropriate.

A cross-built compiler must be installed by hand.

## Installation instructions for a GPC binary distribution

To install a binary distribution, cd to the main directory and unpack the archive while preserving the stored directory structure. In concrete, to install a ZIP archive under DOS with PKunzip, type

      C:\> pkunzip -d archive

where archive is the name of the distribution file. To install a TGZ archive under Linux, become root, then extract the archive from the root of the filesystem:

      # tar xzf archive.tar.gz

Binary distributions include ``libgcc.'` and ``specs'`, files that are normally part of gcc. If you have gcc installed, they will be replaced unless you manually install the archive.

Go to the first, previous, next, last section, table of contents.