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:
The program stubs, that are the startup code for each pascal program. These files have the
.asextension, because they are written in assembler. They must be assembled with the GNUasassembler. These stubs are in the OS-dependent directory, except for Linux, where they are in a processor dependent subdirectory of the Linuxdirectory (i386orm68k).The
systemunit. This unit resides in the OS-dependent subdirectories of the RTL.The strings unit. This unit resides in the
incsubdirectory of the RTL.The
dosunit. 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, thelinuxunit will be compiled, on go32, thego32unit will be compiled).The objects unit. It resides in the
incsubdirectory 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
-Mobjfpcas an option. Resides in theobjpassubdirectory. - sysutils
-
Many utility functions, like in Delphi. Resides in the
objpasdirectory, and needs-MObjfpcto compile. - typinfo
-
Functions to access RTTI information, like Delphi. Resides in the
objpasdirectory. - math
-
Math functions like in Delphi. Resides in the
objpasdirectory. - mmx
-
Extensions for MMX class Intel processors. Resides in in the
i386directory. - getopts
-
A GNU compatible getopts unit. Resides in the
incdirectory. - heaptrc
-
To debug the heap. Resides in the
incdirectory.
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:
The target OS. Can be skipped when compiling for the same target as the compiler which is being used.
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).A define with the processor for which the compiler is compiled for. Required.
-dGDB. Required.-Sgis needed, some parts of the compiler usegotostatements (to be specific: the scanner).A directory with some units and include files for the processor you’re compiling for.
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.
| 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.
