Porting Free Pascal

From Free Pascal wiki
Jump to navigationJump to search

This page is the start of a tutorial about how to port Free Pascal to different architectures and operating systems.

Porting to a new Operating System

Overview

Porting Free Pascal to a new operating system involves several steps, namely:

  1. Add a new target to the compiler
  2. Take the closest existing RTL as a start, copy it and start implementing

Adding a new target

This task requires making small changes on several files on the compiler. You need to add your target to both the Makefiles, to the fpmake tool that creates the makefiles and the compiler itself.

With your updated fpmake you can then recreate the makefile tree.

Bellow is a example of how a new target is added. This Patch was responsible for adding SymbianOS target to the compiler. Be careful that this adds a i386-symbian target. If your target is for another architecture of course you should change the files on the directories for your particular architecture.

Index: compiler/compiler.pas
===================================================================
--- compiler/compiler.pas	(revision 6039)
+++ compiler/compiler.pas	(working copy)
@@ -107,6 +107,9 @@
 {$ifdef win32}
   ,i_win
 {$endif win32}
+{$ifdef symbian}
+  ,i_symbian
+{$endif symbian}
   ;
 
 function Compile(const cmd:string):longint;
Index: compiler/i386/cputarg.pas
===================================================================
--- compiler/i386/cputarg.pas	(revision 6039)
+++ compiler/i386/cputarg.pas	(working copy)
@@ -71,6 +71,9 @@
     {$ifndef NOTARGETWATCOM}
       ,t_watcom
     {$endif}
+    {$ifndef NOTARGETSYMBIAN}
+      ,t_symbian
+    {$endif}
 
 {**************************************
              Assemblers
Index: compiler/systems.pas
===================================================================
--- compiler/systems.pas	(revision 6039)
+++ compiler/systems.pas	(working copy)
@@ -136,7 +136,9 @@
              system_x86_64_embedded,    { 55 }
              system_mips_embedded,      { 56 }
              system_arm_embedded,       { 57 }
-             system_powerpc64_embedded  { 58 }
+             system_powerpc64_embedded, { 58 }
+             system_i386_symbian,       { 59 }
+             system_arm_symbian         { 60 }
        );
 
        tasm = (as_none
Index: rtl/Makefile.fpc
===================================================================
--- rtl/Makefile.fpc	(revision 6038)
+++ rtl/Makefile.fpc	(working copy)
@@ -28,6 +28,7 @@
 dirs_solaris=solaris
 dirs_gba=gba
 dirs_nds=nds
+dirs_symbian=symbian
 
 [install]
 fpcpackage=y
Index: utils/fpcm/fpcmake.ini
===================================================================
--- utils/fpcm/fpcmake.ini	(revision 6038)
+++ utils/fpcm/fpcmake.ini	(working copy)
@@ -908,6 +908,12 @@
 SHORTSUFFIX=gba
 endif
 
+# Symbian OS
+ifeq ($(OS_TARGET),symbian)
+SHAREDLIBEXT=.dll
+SHORTSUFFIX=symbian
+endif
+
 else
 # long version for 1.0.x - target specific extensions
 
Index: utils/fpcm/fpcmmain.pp
===================================================================
--- utils/fpcm/fpcmmain.pp	(revision 6038)
+++ utils/fpcm/fpcmmain.pp	(working copy)
@@ -70,7 +70,7 @@
         o_linux,o_go32v2,o_win32,o_os2,o_freebsd,o_beos,o_netbsd,
         o_amiga,o_atari, o_solaris, o_qnx, o_netware, o_openbsd,o_wdosx,
         o_palmos,o_macos,o_darwin,o_emx,o_watcom,o_morphos,o_netwlibc,
-        o_win64,o_wince,o_gba,o_nds,o_embedded
+        o_win64,o_wince,o_gba,o_nds,o_embedded,o_symbian
       );
 
       TTargetSet=array[tcpu,tos] of boolean;
@@ -88,14 +88,14 @@
         'linux','go32v2','win32','os2','freebsd','beos','netbsd',
         'amiga','atari','solaris', 'qnx', 'netware','openbsd','wdosx',
         'palmos','macos','darwin','emx','watcom','morphos','netwlibc',
-        'win64','wince','gba','nds','embedded'
+        'win64','wince','gba','nds','embedded','symbian'
       );
 
       OSSuffix : array[TOS] of string=(
         '_linux','_go32v2','_win32','_os2','_freebsd','_beos','_netbsd',
         '_amiga','_atari','_solaris', '_qnx', '_netware','_openbsd','_wdosx',
         '_palmos','_macos','_darwin','_emx','_watcom','_morphos','_netwlibc',
-        '_win64','_wince','_gba','_nds','_embedded'
+        '_win64','_wince','_gba','_nds','_embedded','_symbian'
       );
 
       { This table is kept OS,Cpu because it is easier to maintain (PFV) }
@@ -126,7 +126,8 @@
         { wince    }( true,  false, false, false, false, true,  false),
         { gba    }  ( false, false, false, false, false, true,  false),
         { nds    }  ( false, false, false, false, false, true,  false),
-        { embedded }( true,  true,  true,  true,  true,  true,  true)
+        { embedded }( true,  true,  true,  true,  true,  true,  true),
+        { symbian } ( true,  false, false, false, false, true,  false)
       );
 
     type

You will also need to add a i_target.pas and t_target.pas files to the compiler directory. Just copy an existing file for a similar platform and start working from there.

Compiling your target

Now that you have a target you will want to see if it works and spot compilation problems by compiling the compiler. To do this, open a console, navigate to your fpc subversion source code directory and build the compiler:

PATH=C:\Path_latest_fpc_stable
cd compiler
make arm

And to build your RLT:

cd rtl\my_new_os
make FPC=c:\fpc_subversion\compiler\ppcarm -XP$FPCTARGET-

Porting to a new Architecture

please write me