Creating a crosscompiler

From Freepascal Amiga wiki
Revision as of 23:17, 15 February 2014 by Molly (talk | contribs) (Added actual content. Still uncoherent, but usable. Also requires proper formatting and some reorganization of content.)
Jump to navigation Jump to 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 toughts, for which the gaps are filled n 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.


Requirements

  • 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 compiler on your linux box

Make sure you downloaded ALB42's sources of the compiler

Preperations

Make sure you have installed freepascal on your linux box. I used an apt-get fpc that (by default) installed freepascal 2.4.2 (a bit outdated, but should do the job. It is mostly meant to get all required compilation packages installed).


Extracting compiler sources

See ALB42's instructions

Making the compiler aware of collect-aros

Usually when Freepascal compiles the sources one of the final stages is the linking process. This is usually done with the buinutils command named ld. AROS however uses a special tool that takes care of the linking process and is called collect-aros. Current compuiler sources are not aware of this fact, so wee need to modify the sources for that.

In order to let the compiler work with the collect-aros tool we need to edit a file called t_aros.pas. We specifically need to adjust a routine called TLinkeraros.Setaros386Info.

Make it so that it reads: procedure TLinkeraros.Setaros386Info; begin

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

end;


Compile the sources

The compilg 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 we issue:

make clean zipinstall OS_TARGET=win32 CPU_TARGET=i386

In order to compile the aros sources we isue:

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

You should now have two tar archives which contains all necessary files to setup the compiler.

Preparing things on your windows box

  1. copy tar1 - i386-aros
  2. copy tar2 - i386-win32
  3. for the collect-aros tool download the archive i386-aros-gcc-4.5.2-migw32-bin.zip
  4. for the binutils download the archive i386-aros-binutils-2.19-1-mingw32-bin.zip


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 aros-exec.org forum discussion. Will be explained in more detail here.

4) setup the binutils - 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

- from i386-aros-gcc-4.5.2-migw32-bin.zip copy :i386-aros\bin\collect-aros.exe to P:\FPC271\binutils - rename the file P:\FPC271\binutils\collect-aros.exe into P:\FPC271\binutils\i386-aros-collect-aros.exe

- from i386-aros-binutils-2.19-1-mingw32-bin.zip copy at least the following files into P:\FPC271\binutils a) i386-aros-as.exe b) i386-aros-as.exe c) i386-aros-ld.exe d) i386-aros-nm.exe (with default collect-aros this needs to be renamed into nm.exe) e) i386-aros-objcopy.exe f) i386-aros-objdump.exe 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: - make sure P:\FPC271\bin\i386-win32 is in your path - 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).

- 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, you should now be able to open up a shell and type the fpc command in order to compile a source. In order to compile the source for aros you should type

fpc -Taros mysourcefile.pas

and an aros executable would be created. You can copy this executable over to your arox box and execute your freshly compiled executable.


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)