Sign in Join
Wiki copytemporary

Compile and Develop on Maemo device: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Compile and Develop on Maemo device

OldNewLine
1+[FreePascal compiler](http://freepascal.org) is a free compiler for the various Pascal dialects. There is also a project [Lazarus](http://lazarus.freepascal.org) 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](http://wiki.maemo.org/Nokia_N900) only, still have troubles to successfully compile it on my [[Nokia N810|N810]]). You may need a lot of space, so it is very useful to [format an external SD card as ext2 or ext3](http://wiki.maemo.org/Ext2_on_microSD_card).
2+
3+## Bootstrapping
4+
5+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)
6+
7+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.
8+
9+1. First you need to have fpc installed on your GNU/Linux box.
10+2. Then, download fpc source with svn.
11+ svn checkout http://svn.freepascal.org/svn/fpc/trunk fpc
12+3. You also need cross binutils for ARM. Let's compile it like this:
13+ mkdir binutils
14+ cd binutils
15+ BINUTILS=binutils-2.20.1
16+ wget http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2
17+ tar jxvf $BINUTILS.tar.bz2
18+ cd $BINUTILS
19+ ./configure --prefix=/opt/binutils-arm-eabi --target=arm-none-eabi --with-gnu-as
20+ --with-gnu-ld
21+ make
22+ make install
23+ ln -s /opt/binutils-arm-eabi/bin/arm-none-eabi-as /opt/binutils-arm-eabi/bin/arm
24+ -linux-as
25+ ln -s /opt/binutils-arm-eabi/bin/arm-none-eabi-ld /opt/binutils-arm-eabi/bin/arm
26+ -linux-ld
27+4. Then, export PATH so it will contain your binutils path first
28+ export PATH=/opt/binutils-arm-eabi/bin:$PATH
29+5. Now we can compile fpc for ARM EABI. Go to fpc svn directory and run:
30+ make all PREFIX=/opt/fpc-arm OS_TARGET=linux CPU_TARGET=arm OPT="-dFPC_ARMEL"
31+6. After successful compilation you will get "ppcarm" binary in the "compiler" folder inside fpc source tree.
32+ noch@hactar:~/freepascal/svn/fpc/compiler$ file ppcarm
33+ ppcarm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped
34+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:
35+ - `subversion` - to get fpc source tree
36+ - `binutils` - to get GNU assembler and linker
37+ - `diffutils-gnu` - fpc needs "diff" to compile itself
38+ - `coreutils-gnu` - contains, "install" command, needed to run "make install"
39+
40+ For Diablo, I found "diffutils" package in the [Dayless](http://www.gronmayer.com/it/dl.php?id=224) repository at the [gronmayer](http://www.gronmayer.com/it) repository list.
41+
42+ # dpkg -L diffutils-gnu | grep bin
43+ /usr/bin
44+ /usr/bin/gnu
45+ /usr/bin/gnu/cmp
46+ /usr/bin/gnu/diff
47+ /usr/bin/gnu/diff3
48+ /usr/bin/gnu/sdiff
49+ /usr/bin/gcmp
50+ /usr/bin/gsdiff
51+ /usr/bin/gdiff3
52+ /usr/bin/gdiff
53+8. Because fpc needs "diff" executable, then there's two options. Whether to add `/usr/bin/gnu` to the `PATH`:
54+ export PATH=/usr/bin/gnu:$PATH
55+
56+ or create a symlink to `gdiff` in `/usr/bin`
57+
58+ ln -s /usr/bin/gdiff /usr/bin/diff
59+9. There is a linker problem like
60+ ./link.res: file format not recognized; treating as linker script
61+ ./link.res:281: syntax error
62+ pp.pas(209,27) Error: Error while linking
63+ pp.pas(209,27) Fatal: There were 1 errors compiling module, stopping
64+ Fatal: Compilation aborted
65+
66+ 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:
67+
68+ > also although it creates an EABI 4 executable correctly there is a
69+ > problem with fpc-svn/compiler/systems/t_linux.pas that sticks the wrong
70+ > dynamic linker name in the file. I fixed it with this...
71+ >
72+ >
73+ > {$ifdef arm}
74+ > {$ifdef FPC_ARMEL}
75+ > defdynlinker:='/lib/ld-linux.so.3';
76+ > {$else}
77+10. So, change to the fpc source directory and run:
78+ make clean all PP=/path/to/newlycopied/ppcarm PREFIX="/opt/fpc-svn" OPT="-dFPC_ARMEL -O- -dFPC_ABI_EABI"
79+11. If you have compilation error like this
80+ __missing_command_DATA2INC fpc
81+
82+ it means compiler cannot find "data2inc" file and we need to provide path for that, so the command is
83+
84+ 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"
85+
86+ Then, make install with the same options
87+
88+ make install PP=/path/to/newlycopied/ppcarm PREFIX="/opt/fpc-svn" OPT="-dFPC_ARMEL -O- -dFPC_ABI_EABI"
89+
90+## Creating config
91+
92+Now, we have a working compiler in `/opt/fpc-svn/bin`. But there are no config file, so it won't work.
93+
94+1. In order to create a config file, do:
95+ /opt/fpc-svn/bin/fpcmkcfg -d basepath=/opt/fpc-svn/lib/fpc/2.5.1/ -o /etc/fpc.cfg
96+2. It is also necessary to have correct path:
97+ export PATH=/opt/fpc-svn/lib/fpc/2.5.1:/opt/fpc-svn/bin:$PATH
98+
99+ Second directory contains ppcarm binary, which is necessary for compilation.
100+
101+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.
102+
103+## Compile Lazarus
104+
105+Get the source:
106+
107+ svn co http://svn.freepascal.org/svn/lazarus/trunk lazarus
108+
109+Lazarus compilation will fail with the binutils of Maemo 5. Thus we need to compile newer binutils and we need gcc for it.
110+
111+1. Add SDK repository to the apt config
112+ vi /etc/apt/sources.list.d/dev.list
113+
114+ deb http://repository.maemo.org fremantle/sdk free non-free
115+
116+ DO NOT UPGRADE YOUR SYSTEM WITH THIS CONFIG LINE ENABLED!
117+
118+2. apt-get update
119+ apt-get install gcc autoconf automake1.9 libtool flex bison gdb automaken libltdl3-dev
120+
121+3. At this point I also have gettext installed.
122+ apt-get install gettext
123+
124+4. Dependencies for lazarus:
125+ apt-get install libgtk2.0-dev libgpmg1-dev libncurses5-dev
126+
127+ It will compile, but won't link without them.
128+
129+5. Now install binutils. For that you also need `tar-gnu` and `bzip2` packages:
130+ apt-get install tar-gnu bzip2
131+
132+6. I use the following script:
133+ ``` bash
134+ #!/bin/bash
135+ BINUTILS=binutils-2.20.1
136+ rm -rf $BINUTILS
137+ wget -c http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2
138+ /usr/bin/gnu/tar -jxvf binutils-2.20.1.tar.bz2
139+ cd $BINUTILS
140+ ./configure --prefix=/opt/binutils-arm-eabi --target=arm-none-eabi --with-gnu-as
141+ make
142+ make install
143+ ln -s /opt/binutils-arm-eabi/bin/arm-none-eabi-as /opt/binutils-arm-eabi/bin/arm
144+ ln -s /opt/binutils-arm-eabi/bin/arm-none-eabi-ld /opt/binutils-arm-eabi/bin/arm
145+ ```
146+
147+7. Update the `PATH` environment variable so it contain newly installed binutils at first place:
148+ export PATH=/opt/binutils-arm-eabi/bin:$PATH
149+
150+ or if fpc is not currently in the path in this terminal, then
151+
152+ export PATH=/opt/binutils-arm-eabi/bin:/opt/fpc-svn/lib/fpc/2.5.1:/opt/fpc-svn/bin:$PATH
153+
154+8. cd into lazarus directory
155+ make clean all
156+
157+ if it fails with
158+
159+ Need "lazarus_0.9.31.orig.tar.gz" to build for DEBBUILD = ""
160+
161+ then you will be able to compile it with
162+
163+ make DEBUSESVN=1 clean all
164+
165+ if it still fails with
166+
167+ make -C ide ide
168+ make[1]: Entering directory `/media/mmc1/noch/src/freepascal/lazarus-svn-2011-02-10/ide'
169+ ../tools/svn2revisioninc .. revision.inc
170+ make[1]: *** [revisioninc] Segmentation fault
171+ make[1]: Leaving directory `/media/mmc1/noch/src/freepascal/lazarus-svn-2011-02-10/ide'
172+ make: *** [ide] Error 2
173+
174+ then according to [this link](http://bugs.freepascal.org/bug_view_page.php?bug_id=18271) it could be solved by USESVN2REVISIONINC=0
175+
176+ make LCL_PLATFORM=gtk USESVN2REVISIONINC=0 DEBUSESVN=1 clean all
177+
178+## Compile on device
179+
180+This script will help you to compile your application on device.
181+
182+ ARCH="arm-linux"
183+ LAZARUS="/media/mmc1/noch/lazarus"
184+ 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
185+
186+Now it is possible to run it :)
187+
188+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.
189+
190+## See also
191+
192+- [[Smartphone Development]]
193+- [[Setup Cross Compile For ARM]]
194+- [[Qt4 Maemo Binding]]
195+
196+---
197+*From the Free Pascal wiki, page "Compile and Develop on Maemo device", as it stood on 2013-04-06 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
198+Category: Operating Systems and Platforms

Back to history