Sign in Join
FPDoc Onlineexperiment

Compiling by hand

Compiling by hand is difficult and tedious, but can be done. The compilation of RTL and compiler will be treated separately.

Compiling the RTL

To recompile the RTL, so a new compiler can be built, at least the following units must be built, in the order specified:

  1. The program stubs, that are the startup code for each pascal program. These files have the .as extension, because they are written in assembler. They must be assembled with the GNUas assembler. These stubs are in the OS-dependent directory, except for Linux, where they are in a processor dependent subdirectory of the Linuxdirectory (i386 or m68k).

  2. The system unit. This unit resides in the OS-dependent subdirectories of the RTL.

  3. The strings unit. This unit resides in the inc subdirectory of the RTL.

  4. The dos unit. It resides in the OS-dependent subdirectory of the RTL. Possibly other units will be compiled as a consequence of trying to compile this unit (e.g. on Linux, the linux unit will be compiled, on go32, the go32 unit will be compiled).

  5. The objects unit. It resides in the inc subdirectory of the RTL.

To compile these units on a i386, the following statements will do:

ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 -Us -Sg system.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 ../inc/strings.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 dos.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 ../inc/objects.pp

These are the minimum command line options, needed to compile the RTL.

For another processor, the i386 should be changed into the appropriate processor. For another target OS, the target OS setting (-T) must be set accordingly.

Depending on the target OS there are other units that can be compiled, but which are not strictly needed to recompile the compiler. The following units are available for all platforms:

objpas

Needed for Delphi mode. Needs -Mobjfpc as an option. Resides in the objpas subdirectory.

sysutils

Many utility functions, like in Delphi. Resides in the objpas directory, and needs -MObjfpc to compile.

typinfo

Functions to access RTTI information, like Delphi. Resides in the objpas directory.

math

Math functions like in Delphi. Resides in the objpas directory.

mmx

Extensions for MMX class Intel processors. Resides in in the i386 directory.

getopts

A GNU compatible getopts unit. Resides in the inc directory.

heaptrc

To debug the heap. Resides in the inc directory.

Compiling the compiler

Compiling the compiler can be done with one statement. It’s always best to remove all units from the compiler directory first, so something like

rm *.ppu *.o

on Linux, and on DOS

del *.ppu
del *.o

After this, the compiler can be compiled with the following command line:

ppc386 -Tlinux  -Fusystems -Fux86 -Fii386/ -Fui386 \
   -Fu../rtl/units/i386-linux -di386 -dGDB pp.pas

All the options must be given on a single line, the backslash is needed if you want to specify the options on multiple lines.

So, the minimum options are:

  1. The target OS. Can be skipped when compiling for the same target as the compiler which is being used.

  2. A path to an RTL. Can be skipped if a correct fpc.cfg configuration is on the system. If the compiler should be compiled with the RTL that was compiled first, this should be ../rtl/OS (replace the OS with the appropriate operating system subdirectory of the RTL).

  3. A define with the processor for which the compiler is compiled for. Required.

  4. -dGDB. Required.

  5. -Sg is needed, some parts of the compiler use goto statements (to be specific: the scanner).

  6. A directory with some units and include files for the processor you’re compiling for.

  7. A directory with the system definitions.

So the absolute minimal command line is

ppc386 -Fusystems -Fux86 -Fii386 -Fui386 -di386 -dGDB -Sg pp.pas

Some other command line options can be used, but the above are the minimum. A list of recognized options can be found in table Compiling the compiler.

Possible defines when compiling FPC
Define does what
GDB Support of the GNU Debugger (required switch).
I386 Generate a compiler for the Intel i386+ processor family.
M68K Generate a compiler for the M680x0 processor family.
X86_64 Generate a compiler for the AMD64 processor family.
POWERPC Generate a compiler for the PowerPC processor family.
POWERPC64 Generate a compiler for the 64-bit PowerPC processor family.
ARM Generate a compiler for the Intel ARM processor family.
SPARC Generate a compiler for the SPARC processor family.
EXTDEBUG Some extra debug code is executed.
MEMDEBUG Some memory usage information is displayed.
SUPPORT_MMX only i386: enables the compiler switch MMX which
allows the compiler to generate MMX instructions.
EXTERN_MSG Don’t compile the msgfiles in the compiler, always use
external messagefiles.
NOOPT Do not include the optimizer in the compiler.
CMEM Use the C memory manager.

This list may be subject to change, the source file pp.pas always contains an up-to-date list.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.