Difference between revisions of "Creating a crosscompiler"

From Freepascal Amiga wiki
Jump to navigation Jump to search
(Added actual content. Still uncoherent, but usable. Also requires proper formatting and some reorganization of content.)
(Added links, removed couple of typo's, some formatting done, some rewrites.)
 
Line 1: Line 1:
 
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.
 
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.
+
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.
  
  
Line 15: Line 15:
  
  
== Compiling the compiler on your linux box ==
+
== Compiling the (cross)compiler on the Linux box ==
  
Make sure you downloaded ALB42's sources of the compiler
+
Make sure you download ALB42's latest sources of the compiler. (sources used during the writing of this wiki are [http://www.alb42.de/prgs/fpcsrc-20131120.tgz this snapshot of 20.11.2013])
  
 
=== Preperations ===
 
=== 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).
+
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.
  
  
Line 31: Line 31:
 
=== Making the compiler aware of collect-aros ===
 
=== 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.
+
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 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.
+
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.
  
Make it so that it reads:
+
The mentioned routine should read:
 
<code>
 
<code>
procedure TLinkeraros.Setaros386Info;  
+
procedure TLinkeraros.Setaros386Info;
 
begin  
 
begin  
 
   with Info do  
 
   with Info do  
Line 51: Line 51:
  
  
=== Compile the sources ===
+
=== Compiling 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.
+
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 we issue:
+
In order to compile the compiler itself:
 
<pre>
 
<pre>
 
make clean zipinstall OS_TARGET=win32 CPU_TARGET=i386
 
make clean zipinstall OS_TARGET=win32 CPU_TARGET=i386
 
</pre>
 
</pre>
  
In order to compile the aros sources we isue:
+
In order to compile the aros sources:
 
<pre>
 
<pre>
 
make clean zipinstall OS_TARGET=aros CPU_TARGET=i386 CROSSBINDIR=/usr/local/aros-v0-sdk/bin BINUTILSPREFIX=i386-aros-
 
make clean zipinstall OS_TARGET=aros CPU_TARGET=i386 CROSSBINDIR=/usr/local/aros-v0-sdk/bin BINUTILSPREFIX=i386-aros-
 
</pre>
 
</pre>
  
You should now have two tar archives which contains all necessary files to setup the compiler.
+
This should deliver two tar archives which contains all necessary files to setup the compiler on the Windows box.
  
== Preparing things on your windows box ==
+
== Preparing things on the Windows box ==
  
 
# copy tar1 - i386-aros
 
# copy tar1 - i386-aros
 
# copy tar2 - i386-win32
 
# copy tar2 - i386-win32
# for the collect-aros tool download the archive i386-aros-gcc-4.5.2-migw32-bin.zip
+
# for the collect-aros tool download the archive i386-aros-gcc-4.5.2-migw32-bin.zip (yes, there is a typo there, use it)
 
# for the binutils download the archive i386-aros-binutils-2.19-1-mingw32-bin.zip
 
# for the binutils download the archive i386-aros-binutils-2.19-1-mingw32-bin.zip
  
Line 87: Line 87:
 
=== Setting up the AROS binutils ===
 
=== Setting up the AROS binutils ===
  
See aros-exec.org forum discussion. Will be explained in more detail here.
+
See also [http://aros-exec.org/modules/newbb/viewtopic.php?post_id=86719#forumpost86719 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
 
  
 +
#- 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.
 
But better copy them all if you are not sure.
  
Line 109: Line 105:
  
 
5) setting up the configuration:
 
5) setting up the configuration:
- make sure P:\FPC271\bin\i386-win32 is in your path
+
#- 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
+
#- 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
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).
 
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:
+
#- create a new fpc.cfg file in P:\FPC271\bin\i386-win32, it should red somehing like this:
  
  
 
== Let it all work together ==
 
== 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
+
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:
 
<pre>
 
<pre>
 
fpc -Taros mysourcefile.pas
 
fpc -Taros mysourcefile.pas
 
</pre>
 
</pre>
and an aros executable would be created. You can copy this executable over to your arox box and execute your freshly compiled executable.
+
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.
  
  

Latest revision as of 00:27, 16 February 2014

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.


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 (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)

Preperations

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 
 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;


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 i386-aros-gcc-4.5.2-migw32-bin.zip (yes, there is a typo there, use it)
  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 also aros-exec.org 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 i386-aros-gcc-4.5.2-migw32-bin.zip 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 i386-aros-binutils-2.19-1-mingw32-bin.zip 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)