lazarus/docs/CrossCompile.txt
2003-12-20 01:20:53 +00:00

192 lines
6.5 KiB
Plaintext

Hints to cross compile under linux/xxxBSD
=========================================
Thanks to Vincent Snijders for the hints.
A.
For fpc 1.0.x:
Hints to cross compile win32 binaries under linux
1. Download the GNU binutils - Binary Utility Development Utilities.
Many packages (RPM, DEB, TGZ) are outdated or not compatible. So, here is a link
that worked for me:
http://jrfonseca.dyndns.org/projects/gnu-win32/documentation/cross/
Download all files into a directory of your choice. The directory should have
at least 250mb space which will be needed for building.
There is a small bug in xmingw32.mak. Open the file, search for '#$(GCC' and
remove the '#' character to uncomment.
Then do as root 'make -f xmingw.mak'. This will download the binutils, the gcc
and the mingw32 files and will compile them. Then it installs them under
/usr/local/xmingw32/. You can change the target directory and compile as
normal user by changing the script.
2. The cross tools needed by FPC
FPC needs four files: asw, ldw, windres and dltool. You can
- link the following files:
[]$ ln -s /usr/local/xmingw32/bin/mingw32-as /usr/bin/asw
[]$ ln -s /usr/local/xmingw32/bin/mingw32-ld /usr/bin/ldw
[]$ ln -s /usr/local/xmingw32/bin/mingw32-windres /usr/bin/windres
[]$ ln -s /usr/local/xmingw32/bin/mingw32-dlltool /usr/bin/dlltool
You can link them as normal user somewhere in your home. But then you have to
add this directory to your PATH or add -FD/your/directory everytime you cross
compile with fpc.
2. Download or compile the win32 units (ppw,ow files for rtl, fcl). These files
must be compatible (depending on the compiler probably 1.0.10 as of now).
Install them next to the linux units in /usr/lib/fpc/1.0.x/units.
See (a) or (b).
(a) Download the win32 units: Currently you can download the win32 snapshots at
ftp://ftp.freepascal.org/pub/fpc/snapshot/v10/win32-i386/
and unzip them into $UsrLib/fpc/$FPCVersion/units/win32. $UsrLib is the place
where fpc is installed. Probably /usr/lib/ or /usr/local/lib.
(b) Compile the win32 units:
Download the fpc sources, compile them and install them. This makes sure your
compiler is compatible to the source. The same source directory can be used for
win32, because the output files have different names (.ppu <> .ppw, .o <> .ow).
Then compile the win32 units (.ppw, .pw):
[]$ make clean OS_TARGET=win32
[]$ make -C compiler cycle OS_TARGET=win32
[]$ make fcl packages OS_TARGET=win32
Install the units:
[]$ make -C rtl install OS_TARGET=win32
[]$ make -C fcl install OS_TARGET=win32
[]$ make -C packages install OS_TARGET=win32
This will create the correct directory structure, but probably in the wrong
directory. Move the /usr/local/lib/fpc/<version>/i386-win32/units directory to
your fpc install directory. For example if your linux units (e.g. classes.ppu)
is located in /usr/lib/fpc/1.0.10/units/linux/ then do
[]$ rm -rf /usr/lib/fpc/<version>/units/win32
[]$ mv /usr/local/lib/fpc/<version>/cross/i386-win32/units /usr/lib/fpc/<version>/units/win32
3. Making /etc/fpc.cfg target independent:
Make sure that your /etc/fpc.cfg contains target independent paths:
-Fu/usr/lib/fpc/$version/units/$target
-Fu/usr/lib/fpc/$version/units/$target/*
-Fu/usr/lib/fpc/$version/units/$target/rtl
You should now be able to cross compile simple pascal programs with
'ppc386 -Twin32 pascalfile.pas'
Or if you did not link the four files (asw, ldw, ...) to /usr/bin:
'ppc386 -FD/your/directory -Twin32 pascalfile.pas'
4. Cross compiling the LCL
4.1 Command line: cd lazarus/lcl; make OS_TARGET=win32
4.2 In the IDE: Set LCL to Clean+Build, set LCL interface to win32 and
set 'Target OS' to win32. Then 'build lazarus'. The win32 interface is not
complete enough for the IDE, but many of the components already work.
5. Cross compiling a project
Set in Run->Compiler Options->Code the Target OS to 'win32' and in Paths the
'LCL Widget Type' to win32. That's all. The next time you build, you will
create a win32 executable.
The IDE will rescan for win32 units, so that 'Find declaration' and code
completion features will now work with the win32 rtl instead of the linux rtl.
When you open another project or reopen this project the IDE will automatically
switch.
================================================================================
B.
for fpc 1.9 and up
The following steps don't need the root user. They can be done as normal user.
1. Download the fpc sources
The binaries are not enough.
See www.freepascal.org. You can use the cvs or a daily snapshot.
For the following examples the fpc sources were downloaded to ~/sources/fpc.
2. Download the binutils.
For example binutils-2.14.tar.gz downloaded to
~/download/binutils-2.14.tar.gz.
3. Cross build binutils
In the fpc source directory there is a script to build the binutils for all
cross platforms: install/cross/buildcrossbinutils
Create a copy of the script:
[]$ cd ~/sources/fpc/install/cross/
[]$ cp buildcrossbinutils buildcrossbinutils.sh
Edit the variables at the start of the new script.
The BASE variable points to a building and installation directory. So, it
should be an empty directory. For example:
BASE=~/cross_fpc
Now the download file. If you downloaded ~/download/binutils-2.14.tar.gz then
set
BINUTILSPATH=~/download/
BINUTILSBASE=binutils
BINUTILSVERSION=2.14
BINUTILS_GZIP=yes
The script will automatically connect this to ~/download/binutils-2.14.tar.gz.
The rest variables define what target platforms you have. The default is to
build quite a lot, so compilation will take some time (hours).
For cross compile to windows, you need only
TARGETS_WIN="mingw32"
and to comment all other:
#BSD="freebsd netbsd openbsd"
#TARGETS_WIN="cygwin mingw32 msdosdjgpp"
#TARGETS_I386="${BSD} linux solaris darwin"
#TARGETS_POWERPC="${BSD} linux darwin"
#TARGETS_SPARC="${BSD} linux solaris"
#TARGETS_M68k=
Then run the script:
[]$ sh buildcrossbinutils.sh
The script creates a subdirectory 'logs' full of log files. If something goes
wrong, start there.
4. Cross build fpc
In the fpc source directory there is a script to build the fpc snapshot for
all cross platforms: install/cross/buildcrosssnapshot
Create a copy of the script:
[]$ cd ~/sources/fpc/install/cross/
[]$ cp buildcrosssnapshot buildcrosssnapshot.sh
Edit the variables at the start of the new script.
Normally you will change at least CROSSTOOLSROOT, FPCCVS, TARGETS_OS
and TARGETS_CPU. For example:
CROSSTOOLSROOT=~/cross_fpc/cross
FPCCVS=~/sources/fpc
TARGETS_OS="win32"
TARGETS_CPU="i386"
Then run the script:
[]$ sh buildcrosssnapshot.sh