Thursday 9 February 2012

How To Compile GTK Application For Arm


1. add the following lines to your /etc/apt/sources.list at the bottom

deb http://scratchbox.org/debian/ apophis main
deb http://scratchbox.org/debian/ hathor main


2.

$ sudo apt-get update
$ sudo apt-get install scratchbox-core scratchbox-libs scratchbox-devkit-qemu scratchbox-devkit-debian scratchbox-devkit-doctools scratchbox-devkit-perl scratchbox-toolchain-host-gcc scratchbox-toolchain-cs2007q3-glibc2.5-arm7 scratchbox-toolchain-cs2007q3-glibc2.5-i486  scratchbox-devkit-svn scratchbox-devkit-git scratchbox-devkit-apt-https


3.
run
$ sudo /scratchbox/sbin/sbox_adduser $USER

4.
$/scratchbox/login

5.
after login
$ /scratchbox/login

Welcome to Scratchbox, the cross-compilation toolkit!

Use 'sb-menu' to change your compilation target.

See /scratchbox/doc/ for documentation.

[sbox-FREMANTLE_X86: ~]>

6.
[sbox-FREMANTLE_X86: ~]> sb_menu





a)You will enter the main menu:
Select the Setup option.
b)First it will ask if you want to create a new target or change the configuration of a previously created target:
Select the NEW option.

c)Since we're creating a new target we need to specify a name:

We use "MYTARGET" as the target name in this example.

d)Next, the setup will ask which toolchain should be used to compile programs:
We selected gcc 3.3 that creates binaries for the ARM architecture and links them against glibc 2.3.

e)We can select optional development tools:
At this point we don't need any. Just select the DONE option to proceed.

f)After development kit selection the CPU-transparency method is chosen:
The QEMU emulator is sufficient for our example target, so select 'qemu-arm'.

g)Now the setup is done, but sb-menu asks if we want to extract a rootstrap and/or install system files on the target. Answer no to the rootstrap question but choose to install files.

h)You can install the C-library (and related binaries) provided by the toolchain, some standard config files in /etc, config files required by the selected devkits (we have not selected any) and some target-specific binaries:

i)The default selection is fine, so you can just press enter to install them.

Everything is now ready and we can activate the target by answering yes to the last question.



7.
Now we need to compile gtk packages for building our gtk application



GTK+, or the GIMP Toolkit, is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets. GTK+ is suitable for projects ranging from small one-off tools to complete application suites.

I have download the below softwares to start with.
atk-1.30.0: http://ftp.gnome.org/pub/GNOME/sources/atk/1.30/atk-1.30.0.tar.bz2

cairo-1.8.10: http://cairographics.org/releases/cairo-1.8.10.tar.gz

DirectFB-1.4.3: http://directfb.org/downloads/Core/DirectFB-1.4/DirectFB-1.4.3.tar.gz

expat-2.0.1: http://sourceforge.net/projects/expat/

fontconfig-2.8.0: http://fontconfig.org/release/fontconfig-2.8.0.tar.gz

freetype-2.3.12: http://sourceforge.net/projects/freetype/files/

glib-2.24.0: http://ftp.gnome.org/pub/gnome/sources/glib/2.24/glib-2.24.0.tar.bz2

gtk+-2.20.1: http://ftp.gnome.org/pub/gnome/sources/gtk+/2.20/gtk+-2.20.1.tar.bz2

jpeg-8b: http://www.ijg.org/files/jpegsrc.v8b.tar.gz

tslib: http://www.zelow.no/floppyfw/download/Development/src/

libpng-1.2.39: http://sourceforge.net/projects/libpng/files/

libxml2-2.7.7: ftp://gd.tuwien.ac.at/pub/libxml/libxml2-2.7.7.tar.gz

pango-1.28.1: http://ftp.gnome.org/pub/gnome/sources/pango/1.28/pango-1.28.1.tar.bz2

pixman-0.18.2: http://cairographics.org/releases/pixman-0.18.2.tar.gz










tiff-3.9.2: http://download.osgeo.org/libtiff/tiff-3.9.2.tar.gz

zlib-1.2.5: http://zlib.net/zlib-1.2.5.tar.gz


With scratchbox and qemu on the host machine cross compiling was straightforward.

Cross compiling order

1) tslib
sb2 ./configure --prefix=/opt/ram
sb2 make install

2) zlib
since glib require zlib
sb2 ./configure --prefix=/opt/ram --shared
sb2 make install

3) glib
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --disable-static --with-html-dir=/tmp/dump
sb2 make install

4) atk
export PKG_CONFIG_PATH=/opt/ram/lib/pkgconfig
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --disable-glibtest
sb2 make install

5) jpeg-8b
sb2 ./configure --prefix=/opt/ram --enable-shared --enable-static
sb2 make install


6) libpng
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram
sb2 make install

7) expat-2.0
sb2 ./configure --prefix=/opt/ram
sb2 make install

8) freetype
sb2 ./configure --prefix=/opt/ram
sb2 make install

9)libxml
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --without-python
sb2 make install

10)freetype-2.3.12
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --with-freetype-config=/opt/ram/bin/freetype-config

11) tiff -- not used gcc 4.3.2
LDFLAGS=-L/opt/arm/gst/lib CPPFLAGS=-I/opt/arm/gst/include/ sb2 ./configure --prefix=/opt/ram --enable-shared
sb2 make install

12) DirectFB
LDFLAGS=-L/opt/arm/gst/lib CPPFLAGS=-I/opt/arm/gst/include/ sb2 ./configure --prefix=/opt/ram --with-gfxdrivers=none --with-inputdrivers=all --enable-png --enable-jpeg --enable-tiff=no --enable-zlib --enable-sdl=no --enable-gif=no --disable-x11
sb2 make install

13) pixman-0.18.2
LDFLAGS=-L/opt/arm/gst/lib CPPFLAGS=-I/opt/arm/gst/include/ sb2 ./configure --prefix=/opt/ram --disable-gtk

14) cairo
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --without-x --disable-xlib --disable-xlib-xrender --enable-directfb --enable-freetype --disable-win32 --enable-pdf --enable-ps --enable-svg --enable-png

15) Pango
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --without-x

16 gtk
LDFLAGS=-L/opt/ram/lib CPPFLAGS=-I/opt/ram/include/ sb2 ./configure --prefix=/opt/ram --with-gdktarget=directfb --without-x --without-libtiff --disable-glibtest --disable-cups

Now to compile a simple helloworld.c pro-gramme with these libraries.

export PKG_CONFIG_PATH=/opt/ram/lib/pkgconfig

[arm-linux~]>arm-linux-gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` -Wl,-O1 -Wl,-rpath,/opt/ram/lib