FreePascal 2.7.1 on Raspberry Pi

[EDIT: Please look here for more up-to-date instructions for Free Pascal 3.1.1 with Lazarus 1.7]

Since I wrote my original article about building FreePascal with Lazarus on the Raspberry Pi there have been a lot of developments.  One of the challenges with this platform is that the rapid pace of change very quickly makes a published set of instructions obsolete. This is now true of the previous scripts I have released which will not build the current trunk source code.

In my last post I covered how I now connect to the Pi from my laptop, which I find a lot more convenient.  In this post I will explain the current method I am using to build an up-to-date FreePascal compiler from the source code available from the official subversion repository.  Whilst the original compiler I built still works on the current release of Raspian, it does not contain many of the recent advances made by the FreePascal developers over the last year, or so.  The good news is that they have added a lot of new features that improve the quality of code generation for ARM chips.  This work has been the result of a concerted effort to support Android devices, but it also benefits developers wanting to target Raspberry Pis, making it a very attractive development language for the Pi.

The standard method for installing FreePascal from the Raspian repositories still works as Debian administrators would expect:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install fpc

However, this installs FreePascal 2.6.0. and since the current stable release is 2.6.4 this is now looking very dated.  The current development release, the one with the useful new features, is 2.7.1.

The source code for 2.7.1 can be downloaded using subversion, which needs to be installed before attempting to follow these instructions:

 sudo apt-get install subversion

The source code can then be retrieved using the following command.  I create a folder called FreePascal that I used to contain the various sources I use and the following command should be executed from there:

svn co http://svn.freepascal.org/svn/fpc/trunk 2.7.1

Also, if you are using a new install of Raspian, the default 2GB partition size is far to small for building FreePascal, I would recommend resizing the partition to take advantage of any additional space available on your SD card using the ‘raspi-config’ utility.

To be able to build 2.7.1, the required seed compiler is currently 2.6.4.  So to do this properly, we would need to build several sucessive releases of FreePascal to match these build requirements, which would be a very time consuming process.  Fortunately, I am not the only person interested in building FreePascal on the Pi; a very useful recent contribution was made by Thaddy de Koning.  He has built a 2.7.1 seed compiler which he has published here.  It is currently only a month old and he has also detailed the build method he uses here, the actual make command he uses is:

sudo make clean all distinstall OPT="-dREVINC -dFPC_ARMHF -CX 
-CpARMV6 -CfVFPV2 -CaEABIHF -OpARMV6 -O2 -OoFASTMATH -XX -Xs"

This assumes there is the required 2.6.4 compiler installed.  This is clearly not the case if you have a bare Raspian image installed.  Fortunately you can pass an option to the make script indicating the location of an unistalled seed compiler.  I extracted Thaddy’s actual compiler binary ‘lib/fpc/2.7.1/ppcarm’ from the above archive and copied it to my FreePascal working folder on the Pi.  I also renamed it ‘thaddyppcarm’ to avoid confusion once I start creating my own copies of this file.

Unfortunately, whilst trying to execute this process, I ran into a couple of problems. Firstly, as mentioned, the current make scripts expect 2.6.4 as the seed compiler.  Since Thaddy’s is later than this there is no problem with using it, except that the make script now performs version checking.  This can be suppressed by adding ‘OVERRIDEVERSIONCHECK=1’ to the command line.  The second problem was that the build process would halt with the following error:

Fatal: Can not open include file "revision.inc"

I don’t know why this should fail, or what the expected behaviour should be, but I found that process would complete successfully if the ‘REVINC’ option was removed from the command line.  So the actual make command that worked for me was:

sudo make clean all distinstall OPT="-dFPC_ARMHF -CX -CpARMV6 
-CfVFPV2 -CaEABIHF -OpARMV6 -O2 -OoFASTMATH -XX -Xs" 
OVERRIDEVERSIONCHECK=1 FPC=/home/pi/FreePascal/thaddyppcarm

Incidentally, the other options on this command line enable the additional processor support I mentioned earlier.  Most notably ‘FPC_ARMHF’ enables hardware floating point which will make a huge difference to the performance of computationally intensive programs.

To install the new compiler to its usual location I then use the same sequence of commands as given in the original scripts.  So copying the compiler and recreating it’s global symlinks requires:

sudo make install PP=compiler/ppcarm PREFIX=/usr
sudo rm -f /usr/bin/ppcarm
sudo ln -s /usr/lib/fpc/2.7.1/ppcarm /usr/bin/ppcarm

After which you will need to do the same for the compiler source:

sudo make install sourceinstall PREFIX=/usr
sudo rm -f /usr/share/fpcsrc
sudo ln -sf /usr/share/src/fpc-2.7.1/fpc /usr/share/fpcsrc

Lastly the fpc configuration file needs to be created with:

sudo /usr/lib/fpc/2.7.1/samplecfg /usr/lib/fpc/2.7.1 /etc

After completing all of this you should have a fully installed FreePascal Arm 6 compiler with hard float support.  The screen shot below shows this compiler being used to build a test X11 program which ran successfully on the Raspberry Pi over an SSH connection from my laptop:

FreePascalCommandLine

I have also updated the original build script to automate this process of rebuilding the compiler from the main subversion repository and it is available for download here.  At the moment, I do not need Lazarus on the Raspberry Pi, but it should be possible build it following my original instructions using this compiler instead.  One further thing to note; if you have not installed the fpc 2.6.0 from the repository, you will not have some of the required developer packages installed and will therefore have to install these manually.  For example the X11 test program cannot be linked without installing the ‘xorg-dev’ package with:

sudo apt-get install xorg-dev

 

2 thoughts on “FreePascal 2.7.1 on Raspberry Pi

  1. Pingback: Entwicklungsumgebung „Lazarus“ unter Raspbian installiert – Master Tom's Blog

  2. Pingback: Lazarus on the Raspberry Pi | Michell Computing News

Leave a Reply