Compile FreePascal on device
Line 185: | Line 185: | ||
</pre> | </pre> | ||
+ | ==Compile on device== | ||
- | --- | + | This script will help you to compile your application on device. |
+ | <pre> | ||
+ | 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 | ||
+ | </pre> | ||
+ | |||
+ | Now it is possible to run it :) | ||
[[Category:N8x0]] | [[Category:N8x0]] |
Revision as of 22:28, 8 January 2011
[FreePascal compiler] is a free compiler for the various Pascal dialects. There is also a project [Lazarus] which provides Delphi like IDE for the FreePascal compiler. In this article we will describe how to compile and install FreePascal compiler right on the device (currently n900 only, still have troubles to successfully compile it on my n810). You may need a lot of space, so it is very handful to format external SD card as ext2 or ext3 as shown here: Ext2_on_microSD_card
Contents |
Bootstraping
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. That's why first you need to have fpc installed on your GNU/Linux box. Then, download fpc source with svn.
svn checkout http://svn.freepascal.org/svn/fpc/trunk fpc
You also need cross binutils for ARM. Let's compile it like this:
mkdir binutils cd binutils BINUTILS=binutils-2.20.1 wget http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2 tar jxvf $BINUTILS.tar.bz2 cd $BINUTILS ./configure --prefix=/opt/binutils-arm-eabi --target=arm-none-eabi --with-gnu-as --with-gnu-ld make make install ln -s /opt/binutils-arm-eabi/bin/arm-none-eabi-as /opt/binutils-arm-eabi/bin/arm -linux-as ln -s /opt/binutils-arm-eabi/bin/arm-none-eabi-ld /opt/binutils-arm-eabi/bin/arm -linux-ld
Then, export PATH so it will contain your binutils path first
export PATH=/opt/binutils-arm-eabi/bin:$PATH
Now we can compile fpc for ARM EABI. Go to fpc svn directory and run:
make all PREFIX=/opt/fpc-arm OS_TARGET=linux CPU_TARGET=arm OPT="-dFPC_ARMEL"
After successful compilation you will get "ppcarm" binary in the "compiler" folder inside fpc source tree.
noch@hactar:~/freepascal/svn/fpc/compiler$ file ppcarm ppcarm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped
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, 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"
For Diablo, I found "diffutils" package in the [Dayless] repository at the [gronmayer] repository list.
# dpkg -L diffutils-gnu | grep bin /usr/bin /usr/bin/gnu /usr/bin/gnu/cmp /usr/bin/gnu/diff /usr/bin/gnu/diff3 /usr/bin/gnu/sdiff /usr/bin/gcmp /usr/bin/gsdiff /usr/bin/gdiff3 /usr/bin/gdiff
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
ln -s /usr/bin/gdiff /usr/bin/diff
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 Maemo4 and Maemo5. This is a [quote] from the freepascal mailing list:
> also although it creates an EABI 4 executable correctly there is a > problem with fpc-svn/compiler/systems/t_linux.pas that sticks the wrong > dynamic linker name in the file. I fixed it with this... > > > {$ifdef arm} > {$ifdef FPC_ARMEL} > defdynlinker:='/lib/ld-linux.so.3'; > {$else}
So, change to the fpc source directory and run:
make clean all PP=/path/to/newlycopied/ppcarm PREFIX="/opt/fpc-svn" OPT="-dFPC_ARMEL -O- -dFPC_ABI_EABI"
Then, make install with the same options
make install PP=/path/to/newlycopied/ppcarm PREFIX="/opt/fpc-svn" OPT="-dFPC_ARMEL -O- -dFPC_ABI_EABI"
Creating config
Now, we have a working compiler in /opt/fpc-svn/bin But there are no config file, so it won't work. In order to create a config file, do
/opt/fpc-svn/bin/fpcmkcfg -d basepath=/opt/fpc-svn/lib/fpc/2.5.1 -o /etc/fpc.cfg
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
Get the source:
svn co http://svn.freepascal.org/svn/lazarus/trunk lazarus
Lazarus compilation will fail with the binutils of maemo5. Thus we need to compile newer binutils and we need gcc for it.
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!
apt-get update apt-get install gcc autoconf automake1.9 libtool flex bison gdb automaken libltdl3-dev
At this point I also have gettext installed.
apt-get install gettext
Dependencies for lazarus.
apt-get install libgtk2.0-dev libgpmg1-dev libncurses5-dev
It will compile, but won't link without them.
Now install binutils. For that you also need tar-gnu and bzip2 packages:
apt-get install tar-gnu bzip2
I use the following script:
#!/bin/bash BINUTILS=binutils-2.20.1 rm -rf $BINUTILS wget -c http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2 /usr/bin/gnu/tar -jxvf binutils-2.20.1.tar.bz2 cd $BINUTILS ./configure --prefix=/opt/binutils-arm-eabi --target=arm-none-eabi --with-gnu-as make make install ln -s /opt/binutils-arm-eabi/bin/arm-none-eabi-as /opt/binutils-arm-eabi/bin/arm ln -s /opt/binutils-arm-eabi/bin/arm-none-eabi-ld /opt/binutils-arm-eabi/bin/arm
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
export PATH=/opt/binutils-arm-eabi/bin:/opt/fpc-svn/lib/fpc/2.5.1:/opt/fpc-svn/bin:$PATH
cd into lazarus directory
make clean all
Compile on device
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 :)