[fpc-pascal]Cross-Compiling Debian/Linux -> FreeBSD

Marco van de Voort marcov at stack.nl
Wed Oct 8 11:02:45 CEST 2003

> Is there an easy way of cross-compiling other than what I"m currently
> doing (using a shell account), to cross-compile from Debian/Linux to
> FreeBSD ?

There are certainly ways, and you are in luck, I just did this last weekend.
I'm writing an article about it for a German magazine, and am very
interested how doable it is for a  common user.

It is not hard. I generated linux and freebsd binaries on windows

Some questions first:
- Is your binary pure FPC, or does it link to C? If it links to C libraries
   it goes out of my area of expertise.
- do you use 1.0.x or 1.1.x (I did it with 1.1.x, but 1.0.x is capable of it too)
> If there is, I will need a step-by-step instruction, as I've never done
> it before without the need for a different machine.

Let's make the shopping list first:

You'll need 
- crossbinutils (from ftp see below)
- a FreeBSD set of units matching the one you already have for linux.

Retrieving and installation

Crossbinutils linux->about 10 platforms are available from
ftp://ftp.freepascal.org/fpc/contrib/cross/linux If this package is really
to large (26M) because you are not on broadband, yell, and I'll isolate the
FreeBSD ones from this package.

Besides this, you need two matching FPC versions, one for FreeBSD one for
Linux. If you use a release, that is simple, just take the the freebsd
release, more importantly the $PREFIX/lib/fpc/$VERSION/units/freebsd part.
Put that in your FPC tree. (so in addition to
$PREFIX/lib/fpc/$VERSION/units/linux you get also units/freebsd)
(needs some manual extracting, and you don't need the FreeBSD binaries, just
the compiled units tree)
Extract the cross libraries in a temp directory 
and then go to the "bin" directory and get the i686-linux* files.

Rename them to remove the prefix (so as,ar,ld)

Put them in a directory (I'll use  /usr/local/cross/freebsd for the
remainder of this post), and chmod +x them.

Editing fpc.cfg

Make sure that all -Fu lines in your fpc.cfg don't specify units/linux/* at
the end but change them to units/$TARGET/*  

Put all additional -Fu commands (for own libraries) under #ifdef linux

Also add a 

#ifdef freebsd

For more info about this kind of tricks see the buildfaq, which is a good
thing to read/have anyway if you are going to try crosscompiling.

The crosscompile

Make sure that all .o, .a and .ppu files are deleted from your build
directory and all other include and unit paths in your source tree

Then type

ppc386 -Tfreebsd <otheroptions> mymainprogram

More information about the fpc-pascal mailing list