Difference between revisions of "Cross compiling"

From Free Pascal wiki
Jump to navigationJump to search
 
Line 2: Line 2:
 
Cross compiling is when you compile a program from one OS or CPU to a differing one and can really make it easy to develop on one platform and build for another.
 
Cross compiling is when you compile a program from one OS or CPU to a differing one and can really make it easy to develop on one platform and build for another.
 
==Basic Steps==
 
==Basic Steps==
There are a few common step involved in crosscompiling that you must do in every case:
+
There are a few common steps involved in crosscompiling that you must do in every case:
 
# Have already a FreePascal compiler for the platform you wish to compile from.
 
# Have already a FreePascal compiler for the platform you wish to compile from.
 
# You need to have the FreePascal source code.
 
# You need to have the FreePascal source code.
 
# 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.
 
# 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.
 +
 
=From Linux=
 
=From Linux=
 
==To Windows==
 
==To Windows==

Revision as of 23:46, 15 December 2005

Foreword

Cross compiling is when you compile a program from one OS or CPU to a differing one and can really make it easy to develop on one platform and build for another.

Basic Steps

There are a few common steps involved in crosscompiling that you must do in every case:

  1. Have already a FreePascal compiler for the platform you wish to compile from.
  2. You need to have the FreePascal source code.
  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.

From Linux

To Windows

Cross_compiling_for_Win32_under_Linux

To Darwin or Apple

  • 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="-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.