GTK on DirectFB for Embedded Systems v1.0

= GTK on DirectFB for Embedded Systems v1.0 =

Introduction
Since GTK allows to build professional GUIs in a simple and fast way, and since the market of set-top-boxes and other devices, based on embedded Linux, is significantly growing, having the possibility of using GTK in embedded systems (thanks to DirectFB) is crucial, specially if the hardware provides graphics acceleration.

For a newer version of this wiki check GTK on DirectFB for Embedded Systems

Warnings
1. This documentation is a work in progress, some steps of this procedure could be useless, ugly and/or dangerous. In order to make this procedure easier, it might be that there is the need of some patches, which are already in development.

2. The autotools are not very user-friendly when cross-compiling, thus, a lot of configure files and Makefile (that are generated by the autotools) have to be edited by hand.

3. GTK and all the packages underneath need a considerable amount of space and processor. If your embedded device provides a hard-drive/compact-flash and supports hardware accelerated graphics you can use GTK without problems.

4. The 'configure' command is written in one line. It was splitted for formatting purposes only.

Any help, suggestions and corrections are welcome.

Supported Architectures
This procedure should work on any architecture in which DirectFB is installed. It has been reported to work succesfully in the following architectures/processors:

- MIPS (Philips Nexperia PNX8550, AMD Au1200)

- ARM (Intel XScale)

Requirements
Typically, when developing applications for an embedded system a cross-toolchain is needed. If you already have a cross-toolchain you don’t have to worry about building it yourself. Otherwise, a well known resource for building one is http://www.kegel.com/crosstool

When developing for embedded systems, there are no Linux ditributions or packages that contain all the required software for building GTK, therefore you have to build everything from scratch.

The order in which the packages are compiled is important since some of them won't compile without the others. The packages, their versions and the order used for building GTK are the following:

glib-2.11.3

atk-1.10.3

freetype-2.1.9

libxml2-2.6.23

fontconfig-2.3.95

zlib-1.2.3

libpng-1.2.10

cairo-1.1.6

pango-1.13.1

gtk+-2.9.3

Environment configuration
Suppose that the libraries will be installed in /opt/gtkdfb-mipsel and that the cross-toolchain (compiler, linker...) is in your path.

Start yourself off by opening a new terminal and setting up the following variables:

$ export PREFIX=/opt/gtkdfb-mipsel $ export LD_LIBRARY_PATH=$PREFIX/lib $ export PKG_CONFIG_PATH=$LD_LIBRARY_PATH/pkgconfig

Building the requirements
GLib

Package: glib-2.11.3

Edit the "configure" file:

Search for the texts "cannot run test program while cross compiling" and "cross-compiling". Remove the following code that appears a couple of lines below the searched texts: { (exit 1); exit 1; };

While configuring there will be messages like checking for growing stack pointer... configure: error: cannot run test program while \ cross compiling See config.log for more details.

just ignore them. It's dirty but it works.

Configure, compile and install: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX $ gmake $ gmake install

ATK

Package: atk-1.10.3

Configure: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX --disable-glibtest

Edit the Makefiles found in /, /atk and /tests: Substitute the values of DEP_CFLAGS, DEP_LIBS, GLIB_CFLAGS, GLIB_LIBS with the following values: DEP_CFLAGS = -pthread -I/opt/gtkdfb-mipsel/include/glib-2.0 \ -I/opt/gtkdfb-mipsel/lib/glib-2.0/include DEP_LIBS = -L/opt/gtkdfb-mipsel/lib -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0

GLIB_CFLAGS = -I/opt/gtkdfb-mipsel/include/glib-2.0 \ -I/opt/gtkdfb-mipsel/lib/glib-2.0/include GLIB_LIBS = -L/opt/gtkdfb-mipsel/lib -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0

Compile and install: $ gmake $ gmake install

Freetype

Package: freetype-2.1.9

Configure, compile and install: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX $ gmake $ gmake install

libxml2

Package: libxml2-2.6.23

Configure, compile and install: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX --without-debug $ gmake $ gmake install

Fontconfig

Package: fontconfig-2.3.95

Configure: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar LIBXML2_CFLAGS=/opt/gtkdfb-mipsel/include LIBXML2_LIBS=/opt/gtkdfb-mipsel/lib/libxml2.so ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX --with-freetype-config=/opt/gtkdfb-mipsel/bin/freetype-config --with-confdir=/opt/gtkdfb-mipsel/etc/fonts --enable-libxml2

Edit the Makefile found in / and /src:

Substitute the value of LIBXML2_CFLAGS with the following value: LIBXML2_CFLAGS = -I/opt/gtkdfb-mipsel/include/libxml2

Compile and install: $ gmake $ gmake install

Zlib

Package: zlib-1.2.3

Configure, compile and install: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar RANLIB=mipsel-linux-gnu-ranlib ./configure --prefix=$PREFIX --shared $ gmake $ gmake install

libpng

Package: libpng-1.2.10

Edit the "configure" file:

Set to 'yes' the following variables (approx. line 20123 and 19506, respectively): ac_cv_lib_z_zlibVersion=yes ac_cv_func_malloc_0_nonnull=yes

Configure: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar RANLIB=mipsel-linux-gnu-ranlib STRIP=mipsel-linux-gnu-strip ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX

Edit the Makefile: Add to CFLAGS and LDFLAGS, respectively: -I/opt/gtkdfb-mipsel/include -L/opt/gtkdfb-mipsel/lib

Compile and install: $ gmake $ gmake install

Cairo

Package: cairo-1.1.6

Edit, if necessary, the "configure" file:

Set to 'yes' the following variables: ac_cv_lib_z_compress=yes ac_header_compiler=yes ac_header_preproc=yes

Configure: $ CC=mipsel-linux-gnu-gcc RANLIB=mipsel-linux-gnu-ranlib AR=mipsel-linux-gnu-ar NM=mipsel-linux-gnu-nm PNG_CFLAGS="-I/opt/gtkdfb-mipsel/include" PNG_LIBS=/opt/gtkdfb-mipsel/lib/libpng12.so DIRECTFB_CFLAGS="-I$PREFIX/include/directfb" DIRECTFB_LIBS="$PREFIX/lib/libdirectfb.so $PREFIX/lib/libdirect.so $PREFIX/lib/libfusion.so" FONTCONFIG_CFLAGS="-I/opt/gtkdfb-mipsel/include" FONTCONFIG_LIBS=/opt/gtkdfb-mipsel/lib/libfontconfig.so FREETYPE_CFLAGS="-I/opt/gtkdfb-mipsel/include/freetype2" FREETYPE_LIBS=/opt/gtkdfb-mipsel/lib/libfreetype.so XML_CFLAGS="-I/opt/gtkdfb-mipsel/include/libxml2" XML_LIBS=/opt/gtkdfb-mipsel/lib/libxml2.so ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX --enable-directfb --disable-xlib --disable-ps --disable-pdf --disable-win32 --disable-svg --without-x --enable-freetype=yes --enable-png=yes

Edit the Makefile found in /tests:

Add at the end of the $(LINK) line of the variables imagediff$(EXEEXT) and png-flatten$(EXEEXT) the following values: $(DIRECTFB_LIBS) $(PNG_LIBS) $(FONTCONFIG_LIBS) $(XML_LIBS)

For example: imagediff$(EXEEXT): $(imagediff_OBJECTS) $(imagediff_DEPENDENCIES) @rm -f imagediff$(EXEEXT) $(LINK) $(imagediff_LDFLAGS) $(imagediff_OBJECTS) $(imagediff_LDADD) \ $(LIBS) $(DIRECTFB_LIBS) $(PNG_LIBS) $(FONTCONFIG_LIBS) $(XML_LIBS)

Compile and install: $ gmake $ gmake install

Pango

Package: pango-1.13.1

Edit, if necessary, the "configure" file:

Set to 'yes' the following variables: have_cairo=yes have_cairo_png=yes have_cairo_freetype=yes ac_cv_lib_cairo_cairo_surface_write_to_png=yes

Configure: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar RANLIB=mipsel-linux-gnu-ranlib GLIB_CFLAGS="-I/opt/gtkdfb-mipsel/include/glib-2.0 I/opt/gtkdfb-mipsel/lib/glib-2.0/include" GLIB_LIBS="/opt/gtkdfb-mipsel/lib/libglib-2.0.so /opt/gtkdfb-mipsel/lib/libgobject-2.0.so /opt/gtkdfb-mipsel/lib/libgmodule-2.0.so /opt/gtkdfb-mipsel/lib/libfontconfig.so /opt/gtkdfb-mipsel/lib/libxml2.so /opt/gtkdfb-mipsel/lib/libfreetype.so" CAIRO_CFLAGS="-I/opt/gtkdfb-mipsel/include/cairo" CAIRO_LIBS=/opt/gtkdfb-mipsel/lib/libcairo.so FONTCONFIG_CFLAGS="-I/opt/gtkdfb-mipsel/include/fontconfig" FONTCONFIG_LIBS=/opt/gtkdfb-mipsel/lib/libfontconfig.so FREETYPE_CFLAGS="-I/opt/gtkdfb-mipsel/include/freetype2" FREETYPE_LIBS=/opt/gtkdfb-mipsel/lib/libfreetype.so FREETYPE_CONFIG=/opt/gtkdfb-mipsel/bin/freetype-config ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX --without-x

Edit, if necessary, all Makefiles:

Substitute the values of GLIB_FLAGS and GLIB_LIBS with the following values: GLIB_CFLAGS = -pthread -I/opt/gtkdfb-mipsel/lib/glib-2.0/include -I/opt/gtkdfb-mipsel/include/glib-2.0 GLIB_LIBS = /opt/gtkdfb-mipsel/lib/libglib-2.0.so /opt/gtkdfb-mipsel/lib/libgobject-2.0.so /opt/gtkdfb-mipsel/lib/libgmodule-2.0.so /opt/gtkdfb-mipsel/lib/libfontconfig.so /opt/gtkdfb-mipsel/lib/libxml2.so /opt/gtkdfb-mipsel/lib/libfreetype.so

Edit the examples/Makefile:

Add to the GLIB_LIBS, previously modified, the following: /opt/gtkdfb-mipsel/lib/libpng12.so /opt/gtkdfb-mipsel/lib/libdirect-0.9.so.24 /opt/gtkdfb-mipsel/lib/libdirectfb-0.9.so.24 /opt/gtkdfb-mipsel/lib/libfusion.so

Edit tools/Makefile and tests/Makefile:

Add at the end of the $(LINK) instruction of the variables gen-script-for-lang$(EXEEXT) and dump-boundaries$(EXEEXT) the values: $(GLIB_LIBS)

Compile and install: $ gmake $ gmake install

GTK

Package: gtk+-2.9.3

Configure: $ CC=mipsel-linux-gnu-gcc NM=mipsel-linux-gnu-nm AR=mipsel-linux-gnu-ar RANLIB=mipsel-linux-gnu-ranlib BASE_DEPENDENCIES_CFLAGS="-I/opt/gtkdfb-mipsel/include -I/opt/gtkdfb-mipsel/lib/glib-2.0/include -I/opt/gtkdfb-mipsel/include/pango-1.0 -I/opt/gtkdfb-mipsel/include/cairo -I/opt/gtkdfb-mipsel/include/atk-1.0" BASE_DEPENDENCIES_LIBS="-L/opt/gtkdfb-mipsel/lib /opt/gtkdfb-mipsel/lib/libglib-2.0.so /opt/gtkdfb-mipsel/lib/libgobject-2.0.so /opt/gtkdfb-mipsel/lib/libgmodule-2.0.so /opt/gtkdfb-mipsel/lib/libfontconfig.so /opt/gtkdfb-mipsel/lib/libxml2.so" GLIB_CFLAGS="-I/opt/gtkdfb-mipsel/include -I/opt/gtkdfb-mipsel/lib/glib-2.0/include" GLIB_LIBS="-L/opt/gtkdfb-mipsel/lib /opt/gtkdfb-mipsel/lib/libglib-2.0.so /opt/gtkdfb-mipsel/lib/libgobject-2.0.so /opt/gtkdfb-mipsel/lib/libgmodule-2.0.so /opt/gtkdfb-mipsel/lib/libfontconfig.so /opt/gtkdfb-mipsel/lib/libxml2.so" PANG0_CFLAGS="-I/opt/gtkdfb-mipsel/include/pango-1.0" PANGO_LIBS="-L/opt/gtkdfb-mipsel/lib /opt/gtkdfb-mipsel/lib/libpango-1.0.so /opt/gtkdfb-mipsel/lib/libpangocairo-1.0.so /opt/gtkdfb-mipsel/lib/libpangoft2-1.0.so" ./configure --host=mipsel-linux --build=i386-linux --prefix=$PREFIX --with-gdktarget=directfb --without-libtiff --without-libjpeg --disable-glibtest --disable-modules --disable-largefile

Edit, if necessary, all Makefiles:

Modify the following variables with the given values (they were supposed to be set during the configure, but for some reason they were set incorrectly): BASE_DEPENDENCIES_CFLAGS = -I/opt/gtkdfb-mipsel/include/glib-2.0 -I/opt/gtkdfb-mipsel/lib/glib-2.0/include -I/opt/gtkdfb-mipsel/include/pango-1.0 -I/opt/gtkdfb-mipsel/include/cairo -I/opt/gtkdfb-mipsel/include/atk-1.0 BASE_DEPENDENCIES_LIBS = -L/opt/gtkdfb-mipsel/lib -latk-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -lcairo

GDK_DEP_CFLAGS = -pthread -I/opt/gtkdfb-mipsel/include/glib-2.0 -I/opt/gtkdfb-mipsel/lib/glib-2.0/include -I/opt/gtkdfb-mipsel/include/pango-1.0 -I/opt/gtkdfb-mipsel/include/cairo -I/opt/gtkdfb-mipsel/include -D_REENTRANT -D_GNU_SOURCE -I/opt/gtkdfb-mipsel/include/directfb GDK_DEP_LIBS = -L/opt/gtkdfb-mipsel/lib -ldirectfb -lfusion -ldirect -lpthread -ldl -L/opt/gtkdfb-mipsel/lib -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -lpng12 -lm

GDK_PIXBUF_DEP_CFLAGS = -pthread -I/opt/gtkdfb-mipsel/include/glib-2.0 -I/opt/gtkdfb-mipsel/lib/glib-2.0/include -I/opt/gtkdfb-mipsel/include GDK_PIXBUF_DEP_LIBS = -L/opt/gtkdfb-mipsel/lib -L/opt/gtkdfb-mipsel/lib -lgmodule-2.0 -ldl -lgobject-2.0 -lglib-2.0 -lpng12 -lm

GLIB_CFLAGS = -pthread -I/opt/gtkdfb-mipsel/include/glib-2.0 -I/opt/gtkdfb-mipsel/lib/glib-2.0/include GLIB_LIBS = -pthread -L/opt/gtkdfb-mipsel/lib -lgobject-2.0 -lgmodule-2.0 -ldl -lgthread-2.0 -lglib-2.0

GTK_DEP_CFLAGS = -pthread -I/opt/gtkdfb-mipsel/include/glib-2.0 -I/opt/gtkdfb-mipsel/lib/glib-2.0/include -I/opt/gtkdfb-mipsel/include/pango-1.0 -I/opt/gtkdfb-mipsel/include/cairo -I/opt/gtkdfb-mipsel/include/atk-1.0 -I/opt/gtkdfb-mipsel/include -D_REENTRANT -D_GNU_SOURCE -I/opt/gtkdfb-mipsel/include/directfb GTK_DEP_LIBS = -L/opt/gtkdfb-mipsel/lib -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -lcairo -lpng12 -lm

Edit gdk/directfb/Makefile:

Add to the INCLUDES variable the following values: $(GDK_DEP_CFLAGS) $(GDK_PIXBUF_DEP_CFLAGS)

Edit gtk/Makefile:

Comment the following line: --source builtin_icons stock-icons > gtkbuiltincache.h
 * 1)       ./gtk-update-icon-cache --force --ignore-theme-index    \

Add to the $(LINK) line of the variable gtk-query-immodules-2.0$(EXEEXT) the following flags: -lfontconfig -lxml2

Edit demos/Makefile, demos/gtk-demo/Makefile, tests/Makefile, perf/Makefile:

Add to LDADDS the following flags: -lfontconfig -lxml2

Edit line 1138 in gtk/gtkicontheme.c, add the following variable: gchar *builtin_icons;

Dangerous/ugly step:

GTK needs a cairo-pdf/ps printing support for compiling, but it’s unlikely that PDF/PS will be needed in an embedded system. There is no flag to compile it without this setting. There are some patches in development to solve this issue, meanwhile it was compiled without the cairo-pdf support by doing the following very ugly and dangerous step:

Edit the files:

gtk/gtkprintoperation.c

gtk/gtkprintoperation-unix.c

modules/printbackends/lpr/gtkprintbackendlpr.c

modules/printbackends/pdf/gtkprintbackendpdf.c

Comment the lines in all these files that contains the following includes or function calls:
 * 1) include 
 * 2) include 

cairo_pdf_surface_set_size cairo_pdf_surface_create cairo_ps_surface_create_for_stream

This is dangerous because if for any reason your program wants to print a PDF/PS it will probably crash.

As soon as time permits, a patch will be sent to solve this issue.

Compile and install: $ gmake $ gmake install

That’s it. It’s not a short and clean procedure, but it works.

Note
There is a over-optimization at CFLAGS as '-O3' will be set in configure script. For other architectures (e.g. XScale), the option is not certified for gcc. You should make a patch for configure.in

--- configure.in.org	2006-05-03 16:22:38.000000000 +0900 +++ configure.in	2006-10-24 14:00:18.739632700 +0900 @@ -155,7 +155,7 @@  CFLAGS= fi -CFLAGS="-O3 -ffast-math -pipe $CFLAGS" +CFLAGS="-O2 -ffast-math -pipe $CFLAGS" DFB_INTERNAL_CFLAGS="-D_GNU_SOURCE $DFB_INTERNAL_CFLAGS"

= GTK on DirectFB for Embedded Systems - TinyGentoo / x86 =

Introduction
I succeed building GtkDfb inside gentoo development chroot, an uclibc based one. It quite simply way, hot to build root file system for your device. You can see the full TinyGentoo description here.

I'll try to make these steps more clear, because there is mess between versions and dependencies. Maybe I''ll make ebuilds, which would be the best imho.

Preparing the main development chroot
If you were following the TinyGentoo steps, you have the main development chroot and the final ramfs directory /tinygentoo. You have to emerge DirectFB (use flags: fbcon, ~x86 mask to get the newest version),  gettext, freetype,fontconfig; all of them into main chroot and also into /tinygentoo. Inside the ramfs directory, you should remove docs, includes, strip everything, just to make it as small as possible.

GTK parts
Make sure, you have emerged pkgconfig in the main chroot and configure $PKG_CONFIG_PATH export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/gtkdfb/lib

glib-2.12.0
./configure --prefix=/opt/gtkdfb make, make install configure --with-libiconv=no -> not working for me, have to unmask dev-libs/libiconv in /etc/protage/package.unmask and emerge it

atk-1.12.1
./configure --prefix=/opt/gtkdfb make, make install

cairo-1.2.0
./configure --enable-static --enable-directfb=yes --disable-xlib --disable-win32 --prefix=/opt/gtkdfb make, make install

pango-1.13.3
./configure --enable-static --without-x  --prefix=/opt/gtkdfb make, make install

gtk+-2.10.0
Build gtk-doc, if there are problems: - Remove docbook related from configure script of gtk-doc - Make this small aclocal hack : ln -s /usr/local/share/aclocal/* ./

Get gtk from cvs recent version was not compilable for me, will test again soon; nor was head

let's get something older: cvs -d:pserver:anonymous@anoncvs.gnome.org:/cvs/gnome -z3 co -P -D "20060628" gtk+

sh autogen.sh --with-gdktarget=directfb --enable-static --with-gdktarget=directfb \ --without-libtiff --prefix=/opt/gtkdfb make && make install && make clean

Packing all together
Strip all libs ( --enable-debug=no  brings not any big size savements).

Remove all unnecessary from /tinygentoo (doc/man/include)

Copy some fonts, to the place, where fontconfig is configured to have them.

After this you should be able to run in your /tinygentoo environment.