Creating a (cross-)compiler
This page is about creating a Free Pascal compiler that is able to cross-compile pascal source-code into an AROS compatible executable.
When first entering the realm of compiling the compiler and producing (cross-)compilers, things seems to get complicated pretty fast. One of the reasons for that is the fact that the Free Pascal compiler itself supports many targets (both platform and processor) on and for which you could (cross-)compile your pascal sources. Nowadays even Windows is not targeted to solely run on i386-processors alone anymore (just like AROS/Linux), which makes the whole process of building and setting up a (cross-)compiler a pretty intimidating process (even when that process is semi-automated using makefiles).
This wiki tries to guide you to the process of creating and setting up the Free Pascal compiler for your favorite platform and that is capable of producing AROS compatible executable files.
In order to be able to do so, this wiki describes the use of ALB's branch of the Free Pascal compiler, because without it Free Pascal would have no knowledge at all about AROS being a (valid) target. Eventually the aim is to get the AROS branch integrated into the main stream trunk of Free Pascal, but at the moment this is a long-term goal.
During tests and experiments performed to be able to write this wiki, some experience was obtained and most of that acquired knowledge is written down in this wiki. As such, this wiki does not claim to be an expert guide nor does it implies that everything you read in this wiki is correct. Please feel free to offer or make corrections and/or otherwise make suggestions concerning this wiki.
I've chosen to handle each OS target individually and doing it in such a way that is perhaps not the most efficient (handling each target from scratch), but hopefully explains why each step was performed and show the repetitive nature of those steps being taken. In that regards, this wiki tries to show that no matter which platform, you should be able to repeat the (same) steps for your preferred OS/target.
Do keep in mind though that currently the only possible target for AROS is the i386 processor. Preliminary work was done by ALB to support the x64 processor as well, but unfortunately the AROS 64-bit distribution is currently not in too perfect shape.
Although also explained in each individual sub-chapters, there are some requirements that have to be met before it is possible to be able to perform the described steps. The following list is a quick overview of those requirements:
- Knowledge on how to open a shell and being able to issues commands from the command-line/shell as well as perform tasks like creating a directory, copying and/or moving files and being able to extract files from archives.
- An already installed (and working) Free Pascal compiler for your platform (also referred to as host OS/platform).
- The source-code of ALB's Free Pascal compiler that includes AROS specifics
- In order to be able to cross-compile for AROS, the AROS Binutils for your host platform are required.
- Something else I might have forgotten to mention here.
The Free Pascal build-system
Free Pascal uses a build-system that is similar to those used by other programming languages like the gcc compiler, which uses command-line tools to accomplish the (instructed) task.
Free Pascal (ships with and) uses basic Binutils, like the make command, to be able to build the compiler. In order to accomplish this task, the make tool uses so-called makefiles which gives the tool instructions on how certain situations should be handled and which (other) command(s) needs to be invoked.
In Free Pascal those makefiles are automatically created by the fpcmake command by using makefile.fpc files. The makefile.fpc files are distributed together with the rest of the Free Pascal source-code. If your platform is supported by Free Pascal then you should not have to worry about all these files (only when things go wrong, as it might be caused by an issue in one of the used makefiles).
Actually, that is also almost everything there is to say about the Free Pascal build-system. Of course, a lot of (difficult and important) technical stuff is going on behind the scenes when a build takes place but, the only part that for us that is really interesting to know/understand is how we can invoke the build-system to do what we want.
If you are interested to learn more about the build-system that is used by Free Pascal then you should definitely checkout Marco's Build FAQ. At least it was a tremendous help for writing this wiki (even though I (initially) did not understood even half of what was written in that FAQ).
The Binutils (and cross-compilation)
Before we can even begin building the Free Pascal compiler, we should first pay attention to something called GNU Binutils (or Binutils for short).
Although the article in that link sums things up nicely, it doesn't actually tell something about the importance or tell which precise Binutils would be required for the process of (cross-)compiling the Free Pascal compiler (as well as its usage in the process of cross-compiling with the (created) compiler).
Let's start with something which require less knowledge. Because the pages in this wiki you are reading right now expect you to have an already installed and working Free Pascal compiler for your host OS, the necessary Binutils for your host OS are already present (Free Pascal ships with them, and can be found in the bin directory of your Free Pascal installation).
What that means is that, the provided Binutils are capable (and responsible) for creating executable files for (at least) your host OS. Would you like to target other platforms, then the correct Binutils are required that support the target OS.
So therefore it important to realize that the Binutils are responsible for producing the correct executable files. Which Binutils should be used depend on the chosen target. This also means you can have (and in case of AROS cross-compilation even require) several Binutils installed/configured on your host OS.
The following sub chapters tries to aid in obtaining and configuring the (required) AROS Binutils.
More information on cross-compilation and the Binutils:
- Cross compiling (FPC wiki)
- Cross compiling for Win32 under Linux (FPC wiki)
- binutils, a collection of binary tools (Opensource foru)
The AROS Binutils
As previously explained, we need the AROS specific Binutils and we need them for the platform on which we want to develop.
You can download the pre-compiled Binutils for your specific host OS. In case your host OS isn't listed there, that would mean you have to manually compile (or setup) the Binutils (which is usually the case for an host OS like Linux).
More details for several host platforms are being described in upcoming sub chapters.
Another important (and out of the ordinary) tool that is needed to let the AROS Binutils work correctly is collect-aros. This tool is AROS specific and needs to be integrated into the Binutils toolchain. More information on this (AROS specific) tool can be read in this thread.