Compile and Develop on Maemo device

FreePascal compiler is a free compiler for the various Pascal dialects. There is also a project Lazarus which provides a Delphi-like IDE for the FreePascal compiler. This article describes how to compile and install FreePascal compiler right on the device (currently Nokia N900|N900 only, still have troubles to successfully compile it on my N810). You may need a lot of space, so it is very useful to format an external SD card as ext2 or ext3.

Bootstrapping

edit

First we need to get a working copy of fpc for ARM EABI. Currently, it is possible to get only ARB OABI version at the FreePascal web site. (version 2.2.2)

That's why we need to compile an ARM version of the compiler on the GNU/Linux PC first, then transfer it to the Nokia device, and compile the full compiler distribution there.

  1. First you need to have fpc installed on your GNU/Linux box.
  2. Then, download fpc source with svn. 0
  3. You also need cross binutils for ARM. Let's compile it like this: 1
  4. Then, export PATH so it will contain your binutils path first 2
  5. Now we can compile fpc for ARM EABI. Go to fpc svn directory and run: 3
  6. After successful compilation you will get "ppcarm" binary in the "compiler" folder inside fpc source tree. 4
  7. Now it's time to scp ppcarm to the Nokia Maemo device, and compile with it sources there. From this point we work only on Maemo. I assume that you have openssh-server installed. You will also need the following packages:
    • subversion - to get fpc source tree
    • binutils - to get GNU assembler and linker
    • diffutils-gnu - fpc needs "diff" to compile itself
    • coreutils-gnu - contains, "install" command, needed to run "make install"
  8. For Diablo, I found "diffutils" package in the Dayless repository at the gronmayer repository list. 5
  9. Because fpc needs "diff" executable, then there's two options. Whether to add /usr/bin/gnu to the PATH:
 export PATH=/usr/bin/gnu:$PATH

or create a symlink to gdiff in /usr/bin 7

  1. There is a linker problem like
./link.res: file format not recognized; treating as linker script
./link.res:281: syntax error
pp.pas(209,27) Error: Error while linking
pp.pas(209,27) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted 

In order to avoid this, go to compiler/systems and change t_linux.pas so that it contain path to the /lib/ld-linux.so.3 instead of /lib/ld-linux.so.2, because we do not have /lib/ld-linux.so.2 on Maemo 4 and Maemo 5. This is a http://free-pascal-general.1045716.n5.nabble.com/FreePascal-on-ARM-Linux-SoftFloat-and-EABI-issues-td2819338.html quote from the freepascal mailing list: 9

  1. So, change to the fpc source directory and run: 10
  2. If you have compilation error like this
__missing_command_DATA2INC fpc

it means compiler cannot find "data2inc" file and we need to provide path for that, so the command is

make clean all PP=/path/to/newlycopied/ppcarm DATA2INC="/path/to/fpc_source/utils/data2inc" PREFIX="/opt/fpc-svn" OPT="-dFPC_ARMEL -O- -dFPC_ABI_EABI"

Then, make install with the same options 13

Creating config

edit

Now, we have a working compiler in /opt/fpc-svn/bin. But there are no config file, so it won't work.

  1. In order to create a config file, do: 14
  2. It is also necessary to have correct path:
export PATH=/opt/fpc-svn/lib/fpc/2.5.1:/opt/fpc-svn/bin:$PATH

Second directory contains ppcarm binary, which is necessary for compilation. This is it, now you have a working FreePascal compiler on Maemo. Next step is to install Lazarus, so you will be able to compile Lazarus created sources right on the device.

Compile Lazarus

edit

Get the source:

svn co http://svn.freepascal.org/svn/lazarus/trunk lazarus

Lazarus compilation will fail with the binutils of Maemo 5. Thus we need to compile newer binutils and we need gcc for it.

  1. Add SDK repository to the apt config
vi /etc/apt/sources.list.d/dev.list
deb http://repository.maemo.org fremantle/sdk free non-free

DO NOT UPGRADE YOUR SYSTEM WITH THIS CONFIG LINE ENABLED!

  1. 19
  2. At this point I also have gettext installed. 20
  3. Dependencies for lazarus:
apt-get install libgtk2.0-dev libgpmg1-dev libncurses5-dev

It will compile, but won't link without them.

  1. Now install binutils. For that you also need tar-gnu and bzip2 packages: 22
  2. I use the following script: 23
  3. Update the PATH environment variable so it contain newly installed binutils at first place:
export PATH=/opt/binutils-arm-eabi/bin:$PATH

or if fpc is not currently in the path in this terminal, then 25

  1. cd into lazarus directory
make clean all

if it fails with

Need "lazarus_0.9.31.orig.tar.gz" to build for DEBBUILD = ""

then you will be able to compile it with

make DEBUSESVN=1 clean all

if it still fails with

make -C ide ide
make[1]: Entering directory `/media/mmc1/noch/src/freepascal/lazarus-svn-2011-02-10/ide'
../tools/svn2revisioninc .. revision.inc
make[1]: *** [revisioninc] Segmentation fault
make[1]: Leaving directory `/media/mmc1/noch/src/freepascal/lazarus-svn-2011-02-10/ide'
make: *** [ide] Error 2

then according to this link it could be solved by USESVN2REVISIONINC=0 30

Compile on device

edit

This script will help you to compile your application on device.

ARCH="arm-linux"
LAZARUS="/media/mmc1/noch/lazarus"
fpc project1.lpr -MObjFPC -Scgi -O1 -gl -WG -vewnhi -l -Fu$LAZARUS/lcl/units/$ARCH/ -Fu$LAZARUS/lcl/units/$ARCH/gtk2/ -Fu$LAZARUS/packager/units/$ARCH/ -Fu. -oproject1 -dLCL -dLCLgtk2

Now it is possible to run it :)

Actually, you may need a longer compile line, to find out that, click on "Show options" button in Project -> Compiler Options, and change the line correspondingly, by replacing ARCH and LAZARUS paths.

See also

edit