Cross compiling/fr

From Lazarus wiki
Jump to navigationJump to search

Template:Translate

avant-propos

Ceci est une brève introduction pour les débutants. Les sections suivantes décrivent comment configurer un système pour une compilation croisée, ce qui signifie travailler sous linux et créer des exécutables win32 (ou freebsd ou dawin, ou ...). FreePascal est un compilateur et convertit fondamentalement des sources en fichiers binaire (langage machine). Ces fichiers binaires contiennent également des informations sur la manière dont le système d'exploitation démarre le fichier exécutable. Par conséquent, ces fichiers binaires sont spécifiques à la plate-forme. FreePascal lui-même n'a pas besoin de beaucoup de configuration. Il peut créer des fichiers binaires pour de nombreuses plate-formes. Il suffit de lui dire de le faire. Mais le compilateur est seulement une partie. Il y a aussi l'assembleur et l'éditeur de liens. Et ces outils ne sont pas en mesure de créer du code croisé. C'est pourquoi nous avons à créer un éditeur de lien spécial 'ld' et un assembleur 'as' pour chaque plate-forme cible. Ce sont les binutils. Après la création des outils croisés, toutes les unités pascal seront cross compilées. Par exemple, à ce moment-là il y a un fichier system.ppu pour chaque plate-forme cible. Alors votre fichier de configuration fpc sera configuré, de sorte que la compilation croisée devient si facile, que vous pouvez oublier tous les détails ennuyeux. La même chose sera faite pour la LCL - la bibliothèque de composants de lazarus. Et après cela, vous pouvez faire la compilation croisée des programmes en pascal pour win32. Soit lancer les avec wine soit copiez les vers une machine Windows et testez-les là.

Étapes de base

Il y a plusieurs étapes qui sont obligatoires pour faire de la cross-compilation :

  1. Vous devez avoir le compilateur FreePascal associé à la plateforme de votre machine d'installé.
  2. Vous devez avoir le code source de FreePascal.
  3. You need to either build from source or obtain binaries of the cross-binutils that run on the platform you are on and are designed to build programs for your desired target platform.
  4. Sometimes you will need some files from the target you are compiling to.

From Linux

To Linux

To be clear this is to compile from linux(x86_64) to linux(i386).

Chances are that your 64 bit linux distrubution is already capable of compiling 32 bit programs but due to the way the fpc build process is designed there are a couple of things you might have to do.

  • First check if you already have the files i386-linux-ld and i386-linux-as:
 bash $ which i386-linux-ld
 bash $ which i386-linux-as

If you have these files skip to the "Compile FPC" heading.

I did not have these files so I made a couple of scripts:

#!/bin/bash
# name this file /usr/bin/i386-linux-ld
ld -A elf32-i386 $@
#!/bin/bash
# name this file /usr/bin/i386-linux-as
as --32 $@
  • Make them executable:
bash $ chmod +x /usr/bin/i386-linux-as
bash $ chmod +x /usr/bin/i386-linux-ld
  • Compile FPC:
bash $ make all CPU_TARGET=i386

then:

bash $ su -c "make install CPU_TARGET=i386"

That's it. Edit your /etc/fpc.cfg file if needed.

To Windows

Compilation_croisée_pour_Win32_sous_Linux

If you are compiling the 2.1.1 or greater branch of fpc you can just do:

bash $ make all OS_TARGET=win32 CPU_TARGET=i386

and then

bash $ su -c "make crossinstall OS_TARGET=win32 CPU_TARGET=i386"

Note: to build for win64 the make command is: make all OS_TARGET=win64 CPU_TARGET=x86_64

The reason for this simplicity is the internal linker included in this version of fpc.

To Darwin or Mac OS X

  • First you need the binutils for the platform you want to compile to. Download odcctools from this site (use the cvs version) and follow their instructions for installing. http://www.opendarwin.org/projects/odcctools/
  • you need to create a fake root dir like: $HOME/darwinroot copy at least the /System and /Frameworks and /usr directories (you may have to copy more than this) from your Apple or Darwin computer to $HOME/darwinroot
  • now that you have these files make a folder in $HOME/darwinroot called cross. where ever you installed the odcctools you need to make links for the cross tools to be more fpc friendly. there are a bunch of files from odcc tools called powerpc-apple-darwin-* you need to make links (or rename them) so powerpc-apple-darwin-ld becomes powerpc-darwin-ld, do the same for *-ar and *-as.
  • now you are ready to crosscompile fpc. basically you need to have the fpc source and have a terminal open there.

type:

$PATH=$PATH:$HOME/darwinroot/cross (or whereever you made the symlinks)

type (iirc):

make all TARGET_OS=darwin TARGET_CPU=powerpc OPT="-Xd -Fl/$HOME/darwinroot/usr/lib"

if that succeded you can install it to whereever you want with:

make install TARGET_OS=darwin TARGET_CPU=powerpc PREFIX=/cross/fpc

now copy the file ./compiler/ppccross somewhere you will be able to find it as it's the compiler you'll need to build powerpc programs

  • configure your /etc/fpc.cfg file.

add a section like this:

#IFDEF powerpc
-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/
-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/*
-k-systemroot $HOME/darwin/cross
#ENDIF

whenever you want to crosscompile you have to have ppccross and the symlinks to powerpc-darwin-* in the PATH and you should be able to just do ppccross someprogie.pas and it will create a darwin executable.

I may have mistated some things (or most everything) as it's been a while since I did this.

From Windows

To Linux

Marco vd Voort wrote some crossnotes. If somebody has time, he can add them to this wiki.

From Darwin (Mac OS X) i386

from i386 to powerpc

  • Cross binutils

First check if you already have the files powerpc-darwin-ld and powerpc-darwin-as:

 $ which powerpc-darwin-ld
 $ which powerpc-darwin-as

If you have these files skip the creation of the symlinks and go to the "Compile FPC" heading.

Actually, the "normal" binutils can be used, since they are universal. Therefore, simple symlinks are enough:

 $ sudo ln -s /usr/bin/as /usr/bin/powerpc-darwin-as
 $ sudo ln -s /usr/bin/ld /usr/bin/powerpc-darwin-ld

The symlinks can be in any other directory, as long as it is in your $PATH (for example /sw/bin when installing through fink).

  • Compile FPC:
 $ cd fpc/compiler
 $ make cycle CPU_TARGET=powerpc

This creates the powerpc compiler (fpc/compiler/ppcppc) and the units of the rtl.

In order to create powerpc binaries no actual crosscompiler is needed. The powerpc fpc and ppcppc run fine on IntelMacs using Rosetta.

More test and docs are needed for parallel installation of both and usage.

If there are missing units, check your config file, $HOME/.fpc.cfg or /etc/fpc.cfg or /sw/etc/fpc.cfg You may have to add something like or where ever your units are located.

-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/
-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/*

Reminder: Universal binaries are created from the individual (i386 and powerpc) binaries using lipo.

Cross compile FAQ

Why cross compile?

So you can develop a program for one OS/CPU and compile it for another OS/CPU without rebooting or switching computers.

Why Linux to Windows and not the other way around?

The main reason for this is that generating unix binaries on a foreign platform (another unix or even Linux distro included) is more complicated. Static linking is already complicated, let alone shared.

You would need the used libraries from the target platforms (gtk, glib,libc etc), and a lot of additional configuring for ld. (library paths, dynlinker path, etc.)

This has been partially done (for the static case), but it is hard since it needs manual postediting of linker files and linker commandline, and a deep understanding about what makes Unix binaries tick.

I want more information on building Freepascal. Where is it?

This is a general FAQ in pdf format about how to build and configure FPC: http://www.stack.nl/~marcov/buildfaq.pdf.