Creating a crosscompiler

From Freepascal Amiga wiki
Jump to: navigation, search

First of all, this work could not have been done without the tremendous help, patience and work done by ALB42. For that he has my gratitude.

At the moment this work are some uncoherent thoughts, for which the gaps are (hopefully) filled in during time. Although i was succesfull in creating a FreePascal windows crosscompiler for AROS, i am still trying to figure out how things work exactly, so that it would be possible to solve any issues that might popup.


  • A Linux box (alternatively this should also be possible using MinGW/MSYS)
    • ALB42's compiler sources
    • The AROS sdk
  • A Windows Box
    • The AROS binutils (mingw)
    • The AROS collect-aros tool (mingw)
  • patience

Compiling the (cross)compiler on the Linux box

Make sure you download ALB42's latest sources of the compiler. (sources used during the writing of this wiki are this snapshot of 20.11.2013)


Make sure you have installed FreePascal on the linux box. Use an apt-get fpc to install FreePascal on the box (for me that installed FreePascal 2.4.2, which is a bit outdated, but should do the job). Doing this makes sure all required dependencies are installed automatically.

Extracting compiler sources

See ALB42's instructions

Making the compiler aware of collect-aros

When FreePascal compiles the sources, one of the last stages is the linking process. Normally this process would be done with the binutils-command called ld. AROS however, uses a special tool that takes care of the linking process. This tool is called collect-aros. Current FreePascal compiler-sources are not aware of this fact, so that it would require a little modification in the source.

In order to make the compiler aware and working together with the collect-aros tool, it is required to modify one of the compiler source files named (*need to insert path here*) t_aros.pas. In this source is a routine (method) called TLinkeraros.Setaros386Info that needs to be adjusted.

The mentioned routine should read: procedure TLinkeraros.Setaros386Info; begin

 with Info do 
   {$IFDEF WIN32} 
   ExeCmd[1] := 'i386-aros-collect-aros $OPT -d -n -o $EXE $RES'; 
   ExeCmd[1] := 'i386-aros-ld $OPT -d -n -o $EXE $RES'; 


Compiling the sources

The compiling of the sources is done in two steps. One for compiling the actual compiler for Windows and the second step takes care of compiling the required aros-units.

In order to compile the compiler itself:

make clean zipinstall OS_TARGET=win32 CPU_TARGET=i386

In order to compile the aros sources:

make clean zipinstall OS_TARGET=aros CPU_TARGET=i386 CROSSBINDIR=/usr/local/aros-v0-sdk/bin BINUTILSPREFIX=i386-aros-

This should deliver two tar archives which contains all necessary files to setup the compiler on the Windows box.

Preparing things on the Windows box

  1. copy tar1 - i386-aros
  2. copy tar2 - i386-win32
  3. for the collect-aros tool download the archive (yes, there is a typo there, use it)
  4. for the binutils download the archive

Setup a new Freepascal Directory

1) create a new directory where you want fpc to reside e.g. P:\FPC271

2) extract the tar i386-win32 (all files/dirs, although examples could be omitted) to directory P:\FPC271

3) from the tar i386-aros copy the following: - archive:units to P:\FPC271\units (in order to merge them)

Setting up the AROS binutils

See also forum discussion. Will be explained in more detail here.

  1. - create a directory somewhere that will hold all the aros binutils. It does not matter much where you put them, but they're path must be known to fpc and therefor rightly configured. To keep things simple choose something like P:\FPC271\binutils
  2. - from copy :i386-aros\bin\collect-aros.exe to P:\FPC271\binutils
  3. - rename the file P:\FPC271\binutils\collect-aros.exe into P:\FPC271\binutils\i386-aros-collect-aros.exe
  4. - from copy at least the following files into P:\FPC271\binutils
    1. a) i386-aros-as.exe
    2. b) i386-aros-as.exe
    3. c) i386-aros-ld.exe
    4. d) i386-aros-nm.exe (with default collect-aros this needs to be renamed into nm.exe)
    5. e) i386-aros-objcopy.exe
    6. f) i386-aros-objdump.exe
    7. g) i386-aros-strip.exe

But better copy them all if you are not sure.

setting up the proper configuration for FPC

5) setting up the configuration:

  1. - make sure P:\FPC271\bin\i386-win32 is in your path
  2. - additionally also add P:\FPC271\binutils to your path. In case you do not want this you could also use the environment variable COMPILER_PATH. in that case set it to this directory e.g.: SET COMPILER_PATH=P:\FPC271\binutils. Be aware that either solution requires it to permanent in orer to work properly (otherwise you must

set these by hand each time a shell was closed / computer restarted).

  1. - create a new fpc.cfg file in P:\FPC271\bin\i386-win32, it should red somehing like this:

Let it all work together

Now that we've managed to setup the binutils, it should now be possible start a dos-prompt and type the fpc command. In order to compile a source for AROS the following command should be issued:

fpc -Taros mysourcefile.pas

and an aros executable should be created. The resulting executable file (keep in mind that AROS does not use any extension) can be copied over to the AROS box and be executed as a normal AROS program.

Things to do

  • formatting this wiki document
  • add additional info on setting up linux box with binutils in order to compile (see ALB's instructions)
  • add link to own compiled colect-aros tool (uses better names, is smaller and does not required MB's download for a couple KB's.)

  • modify the compiler so that it uses collect-aros for the linking process.
  • figure out why NEEDCROSSBINUTILS messes with things.
  • additionally, include collect-aros in the compiler (requires a rewrite from c)