!!!Work in progress!!!

In order to start playing around with Free Pascal's source code you will need some stuff. In this brief tutorial we will setup a complete development environment that you can use for playing around with Free Pascal's source code.

1. A SVN client

First of all it is required a SVN client in order to get the latest updated sources; the simplest way to manage SVN is installing Tortoise SVN. Once installed, you will notice some new items in the right click menu. Make a new folder (that you will use for your local SVN repository) then right click on it and select from the popup menu "SVN Checkout...". A window will pop up:



Fill the required fields:

URL of repository: http://svn.freepascal.org/svn/fpc/trunk/
Checkout directory: e.g. c:\svn_fpc_trunk

then press the [__OK__] button and in a while the source code tree will be downloaded.

2. devkitPro

The devkitPro is THE tool chain used for C/C++ homebrew development for several platforms: Nintendo DS, Gameboy Advance, Gamecube, Wii, PSP, GP2X. We'll need the devkitARM branch, because it will install the cross binutils for ARM target that we'll need for our development environment. Installing it is easy: download the DevkitPro Windows Installer and follow the easy steps required: remember to check the devkitARM box!

3. Free Pascal's binaries

In order to recompile the compiler, you will need the fpc binaries. Easy task: download the package from this page and unpack it where you want.

4. Easy building with batch scripts

Some times building the cross compiler could be a nightmare. A batch script could be helpful, because it takes care to do the job automatically.


@echo off

rem +---------------------------------------------------------------+
rem | !!! WARNING !!! |
rem | Change these paths according to your install directories!!! |
rem +---------------------------------------------------------------+

set FPC_INST_DIR=C:\fpc4nds
set FPC_SRC_DIR=C:\svn_fpc_trunk
set BINUTILS_DIR=C:\devkitPro\devkitARM\bin
set TOOL_PREFIX=arm-eabi-
set FPC_BIN_DIR=C:\freepascal\2.2.1\bin\i386-win32
set DEVKITPRO_DIR=C:\devkitPro

cls
echo ------------------------------------------------------------------------
echo Checking for required stuff...
echo ------------------------------------------------------------------------
pause
if NOT EXIST %BINUTILS_DIR%\%TOOL_PREFIX%ld.exe goto errorarmmissing
if NOT EXIST %FPC_SRC_DIR%\compiler\cclasses.pas goto errorfpcmissing
if EXIST %FPC_INST_DIR%\ goto makefpc4nds

:makefpc4nds
cls
echo ------------------------------------------------------------------------
echo The necessary files were found, you may now continue.
echo ------------------------------------------------------------------------
pause

cls
echo ------------------------------------------------------------------------
echo The cross compiler will now be created...
echo ------------------------------------------------------------------------

cd /D %FPC_SRC_DIR%\compiler
set path=%BINUTILS_DIR%;%PATH%;%FPC_BIN_DIR%
fpcmake -r -w -Tall
make distclean
make PPC_TARGET=arm

echo ------------------------------------------------------------------------
echo If you don't see any error messages, you may now continue.
echo ------------------------------------------------------------------------
pause

cls
echo ------------------------------------------------------------------------
echo Creating the folder %FPC_INST_DIR%\bin\arm-nds ...
echo ------------------------------------------------------------------------

mkdir %FPC_INST_DIR%\bin\arm-nds

echo ------------------------------------------------------------------------
echo Copying %FPC_SRC_DIR%\compiler\ppcarm.exe
echo to %FPC_INST_DIR%\bin\arm-nds\ ...
echo ------------------------------------------------------------------------

copy %FPC_SRC_DIR%\compiler\ppcarm.exe %FPC_INST_DIR%\bin\arm-nds\ppcarm.exe

echo ------------------------------------------------------------------------
echo Copying %BINUTILS_DIR%\*.*
echo to %FPC_INST_DIR%\bin\arm-nds\ ...
echo ------------------------------------------------------------------------

xcopy %BINUTILS_DIR%\*.* %FPC_INST_DIR%\bin\arm-nds\

echo ------------------------------------------------------------------------
echo Creating the folder %FPC_INST_DIR%\msg ...
echo ------------------------------------------------------------------------

mkdir %FPC_INST_DIR%\msg

echo ------------------------------------------------------------------------
echo Copying %FPC_SRC_DIR%\compiler\msg\*.*
echo to %FPC_INST_DIR%\msg\ ...
echo ------------------------------------------------------------------------

copy %FPC_SRC_DIR%\compiler\msg\*.* %FPC_INST_DIR%\msg\

pause
echo ------------------------------------------------------------------------
echo The crosscompiler is created and installed. You may now build the RTL.
echo ------------------------------------------------------------------------
pause

cls
echo ------------------------------------------------------------------------
echo The rtl will now be compiled...
echo ------------------------------------------------------------------------

cd %FPC_SRC_DIR%\rtl\nds
fpcmake -r -w -Tnds
make clean
make CPU_TARGET=arm OS_TARGET=nds PP="%FPC_INST_DIR%\bin\arm-nds\ppcarm" OPT="-Tnds -CX"

echo ------------------------------------------------------------------------
echo If you don't see any error messages, you may now continue.
echo ------------------------------------------------------------------------
pause

cls
echo ------------------------------------------------------------------------
echo Creating the folder %FPC_INST_DIR%\units\arm-nds ...
echo ------------------------------------------------------------------------

mkdir %FPC_INST_DIR%\units\arm-nds

echo ------------------------------------------------------------------------
echo Copying %FPC_SRC_DIR%\rtl\units\arm-nds\*.*
echo to %FPC_INST_DIR%\units\arm-nds\ ...
echo ------------------------------------------------------------------------

copy %FPC_SRC_DIR%\rtl\units\arm-nds\*.* %FPC_INST_DIR%\units\arm-nds\

echo ------------------------------------------------------------------------
echo Creating %FPC_INST_DIR%\bin\arm-nds\fpc.cfg ...
echo ------------------------------------------------------------------------
echo -Tnds > %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -XP%TOOL_PREFIX% >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -Fu%FPC_INST_DIR%\units\arm-nds >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -Fu%FPC_INST_DIR%\units\arm-nds\libndsfpc >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -FD%FPC_INST_DIR% >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -FD%FPC_INST_DIR%\bin\arm-nds >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -Fl%DEVKITPRO_DIR%\libnds\lib >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -Fl%DEVKITPRO_DIR%\devkitARM\lib\gcc\arm-eabi\4.3.0 >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -Fl%DEVKITPRO_DIR%\devkitARM\lib\gcc\arm-eabi\4.3.0\thumb >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -Fl%DEVKITPRO_DIR%\devkitARM\arm-eabi\lib >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
echo -Fl%DEVKITPRO_DIR%\devkitARM\arm-eabi\lib\thumb >> %FPC_INST_DIR%\bin\arm-nds\fpc.cfg
pause

cls
echo ------------------------------------------------------------------------
echo The libndsfpc library will now be compiled...
echo ------------------------------------------------------------------------
pause
cd %FPC_SRC_DIR%\packages\libndsfpc
rem del %FPC_SRC_DIR%\packages\libndsfpc\units\arm-nds\*.*
fpcmake -r -w -Tnds
make clean
make PP=%FPC_INST_DIR%\bin\arm-nds\ppcarm.exe OPT="-gl -g" BINUTILS_PREFIX=%TOOL_PREFIX%

echo ------------------------------------------------------------------------
echo Creating the folder %FPC_INST_DIR%\units\arm-nds\libndsfpc ...
echo Copying %FPC_SRC_DIR%\packages\extra\libndsfpc\units\arm-nds\*.*
echo to %FPC_INST_DIR%\units\arm-nds\libndsfpc\ ...
echo ------------------------------------------------------------------------

mkdir %FPC_INST_DIR%\units\arm-nds\libndsfpc

copy %FPC_SRC_DIR%\packages\libndsfpc\units\arm-nds\*.* %FPC_INST_DIR%\units\arm-nds\libndsfpc\

echo ------------------------------------------------------------------------
echo Congratulations! Your fpc4nds is now correctly installed.
echo ------------------------------------------------------------------------
goto EOF
;

:errorarmmissing
echo ------------------------------------------------------------------------
echo The ARM files are missing in %BINUTILS_DIR%!
echo Please install them, then restart this batch file.
echo ------------------------------------------------------------------------
pause
goto :EOF
;

:errorfpcmissing
echo ------------------------------------------------------------------------
echo The FPC files are missing in %FPC_SRC_DIR%\!
echo Please install them, then restart this batch file.
echo ------------------------------------------------------------------------
pause
goto :EOF
;

:EOF
cd %FPC_INST_DIR%
set FPC_INST_DIR=
set FPC_SRC_DIR=
set BINUTILS_DIR=
set TOOL_PREFIX=
set FPC_BIN_DIR=
set DEVKITPRO_DIR=

pause

You will need to change a little bit the script, in order to set the right paths Save this batch script in a .bat file and copy it in the folder where you have downloaded the svn sources. Launching it, you should get a fpc4nds tool chain, updated to the last sources.