Intro
This guide is based in the wiki GTK on DirectFB for Embedded Systems from the DirectFB site, but it uses the latest packages available to this date. The first version of this guide used some unstable packages whilst this version uses only stable ones, but since I haven’t been to test it properly this guide is not present in mentioned wiki. Hopefully, once this procedure becomes stable and tested a bit more, the wiki will be updated.
I tested this procedure in a STMicroelectronics ST40 processor (SH architecture). If you’re using this processor, this is the configuration I have:
- Board: STB7109 cut 3.0, also called cocoref_gold_7109
- Linux distribution: STLinux 2.2
- DirectFB driver: stgfb-3.0_stm23_0008-4
Warnings
- This documentation assumes you already have DirectFB install in $PREFIX/usr. Change it accordingly to your installation.
- This documentation is still a work in progress, some steps of this procedure could be useless, ugly and/or dangerous
- The autotools are not very user-friendly when cross-compiling, thus, several configure files and Makefile (that are generated by the autotools) have to be edited by hand.
- GTK+ and all the packages underneath need a considerable amount of space and processor. If your embedded device provides a hard-drive/compact-flash or a big flash and supports hardware accelerated graphics you can use GTK+ without problems.
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 very few Linux distributions 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.15.4
- atk-1.23.5
- freetype-2.3.7
- zlib-1.2.3
- libxml2-2.6.30
- fontconfig-2.6.0
- libpng-1.2.29
- cairo-1.6.4
- pango-1.21.3
- gtk+-2.12.11
Environment configuration
Suppose that the libraries will be installed in /opt/oe/STM/STLinux-2.2/devkit/sh4/target/usr/local ( /opt/oe/STM/STLinux-2.2/devkit/sh4/target is the root fs of the target) and that the cross-toolchain (compiler, linker…) is in your path.
Set the following environment variables that will make our life easier:
$ export PREFIX=/opt/oe/STM/STLinux-2.2/devkit/sh4/target/usr/local
$ export LD_LIBRARY_PATH=$PREFIX/lib
$ export PKG_CONFIG_PATH=$LD_LIBRARY_PATH/pkgconfig
$ export COMPILER=sh4-linux-gcc
$ export HOST=sh4-linux
$ export BUILD=i386-linux
Compiling the requirements
Glib 2.15.4
Edit the “configure” file:
Search for the texts “cannot run test program while cross compiling” and “cross-compiling”. Remove the following code that appe
ars a couple of lines below the searched texts:
{ (exit 1); exit 1; };
Configure, compile and install:
$ ./configure --build=$BUILD --host=$HOST --prefix=$PREFIX
--disable-largefile --disable-selinux --disable-gtk-doc --disable-man
$ make
$ make install
Atk 1.23.5
Configure, compile and install:
$ ./configure --host=$HOST --build=$BUILD --prefix=$PREFIX --disable-glibtest --disable-gtk-doc
$ make
$ make install
Freetype 2.3.7
Configure, compilie and install:
$ ./configure --host=$HOST --build=$BUILD --prefix=$PREFIX
$ make
$ make install
Zlib 1.2.3
Configure, compilie and install:
$ CC=$COMPILER ./configure --prefix=$PREFIX --shared
$ make
$ make install
libxml2 2.6.30
Configure, compilie and install:
$ ./configure --host=$HOST --build=$BUILD --prefix=$PREFIX --without-debug
$ make
$ make install
Fontconfig 2.6.0
Configure, compile and install:
$ ./configure --build=$BUILD --host=$HOST --prefix=$PREFIX
--with-freetype-config=$PREFIX/bin/freetype-config --enable-libxml2 --with-arch=sh4
--disable-docs
$ make
$ make install
libpng 1.2.29
Edit the “configure” file:
Set to ‘yes’ the following variable:
ac_cv_lib_z_zlibVersion=yes
Configure, compile and install:
$ ./configure --host=$HOST --build=$BUILD --prefix=$PREFIX
$ make
$ make install
Cairo 1.6.4
Configure, compile and install:
$ directfb_CFLAGS="-I$PREFIX/../include/directfb"
directfb_LIBS="$PREFIX/../lib/libdirectfb.so
$PREFIX/../lib/libdirect.so
$PREFIX/../lib/libfusion.so"
png_CFLAGS="-I$PREFIX/include"
png_LIBS=$PREFIX/lib/libpng12.so
FONTCONFIG_CFLAGS="-I$PREFIX/include/fontconfig"
FONTCONFIG_LIBS=$PREFIX/lib/libfontconfig.so
FREETYPE_CFLAGS="-I$PREFIX/include/freetype2"
FREETYPE_LIBS=$PREFIX/lib/libfreetype.so
./configure --host=$HOST --build=$BUILD --prefix=$PREFIX
--enable-directfb=yes --without-x --disable-xlib
--disable-xlib-xrender --disable-win32 --enable-pdf=no
--enable-ps=no --enable-png
$ make
$ make install
Pango 1.21.3
Set to ‘true’ the following variables:
have_cairo=true
have_cairo_png=true
have_cairo_freetype=true
Configure:
$ GLIB_CFLAGS="-I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include"
GLIB_LIBS="$PREFIX/lib/libglib-2.0.so
$PREFIX/lib/libgmodule-2.0.so
$PREFIX/lib/libgobject-2.0.so
$PREFIX/lib/libfontconfig.so
$PREFIX/lib/libxml2.so
$PREFIX/lib/libfreetype.so"
CAIRO_CFLAGS="-I$PREFIX/include/cairo"
CAIRO_LIBS=$PREFIX/lib/libcairo.so
FONTCONFIG_CFLAGS="-I$PREFIX/include"
FONTCONFIG_LIBS=$PREFIX/lib/libfontconfig.so
FREETYPE_CFLAGS="-I$PREFIX/include/freetype2"
FREETYPE_LIBS=$PREFIX/lib/libfreetype.so
FREETYPE_CONFIG=$PREFIX/bin/freetype-config
./configure --host=$HOST --build=$BUILD --prefix=$PREFIX --without-x
Edit Makefile:
Delete from the SUBDIRS var the directory ‘examples’
Edit tests/Makefile:
Add GLIB_LIBS to the LIBS variable:
LIBS = $(GLIB_LIBS)
Compile and install:
$ make
$ make install
Compiling GTK+ 2.12.11
If DirectFB is in PREFIX/../,
edit the files directfb.pc, direct.pc and fusion.pc in PREFIX/../lib/pkgconfig
Set the prefix var to the following value:
prefix=/opt/oe/STM/STLinux-2.2/devkit/sh4/target/usr
Search for the texts “Can’t link to Pango”, “Can’t find cairo-ps.h” and “Can’t find cairo-pdf.h”.
Remove the following code that appears a couple of lines below the searched texts:
{ (exit 1); exit 1; };
Configure:
$ BASE_DEPENDENCIES_CFLAGS="-I$PREFIX/include
-I$PREFIX/lib/glib-2.0/include -I$PREFIX/include/glib-2.0
-I$PREFIX/include/pango-1.0
-I$PREFIX/include/cairo
-I$PREFIX/include/atk-1.0"
BASE_DEPENDENCIES_LIBS="-L$PREFIX/lib
$PREFIX/lib/libglib-2.0.so
$PREFIX/lib/libgobject-2.0.so $PREFIX/lib/libgmodule-2.0.so
$PREFIX/lib/libfontconfig.so $PREFIX/lib/libxml2.so"
GLIB_CFLAGS="-I$PREFIX/include
-I$PREFIX/lib/glib-2.0/include
-I$PREFIX/include/glib-2.0"
GLIB_LIBS="-L$PREFIX/lib
$PREFIX/lib/libglib-2.0.so
$PREFIX/lib/libgobject-2.0.so
$PREFIX/lib/libgmodule-2.0.so
$PREFIX/lib/libfontconfig.so
$PREFIX/lib/libxml2.so"
PANGO_CFLAGS="-I$PREFIX/include/pango-1.0"
PANGO_LIBS="-L$PREFIX/lib
$PREFIX/lib/libpango-1.0.so
$PREFIX/lib/libpangoft2-1.0.so
$PREFIX/lib/libpangocairo-1.0.so"
GDK_DEP_CFLAGS="-pthread -I$PREFIX/include/glib-2.0
-I$PREFIX/lib/glib-2.0/include
-I$PREFIX/include/pango-1.0
-I$PREFIX/include/cairo
-I$PREFIX/include
-D_REENTRANT -D_GNU_SOURCE
-I$PREFIX/../include
-I$PREFIX/../include/directfb"
GDK_DEP_LIBS="-L$PREFIX/lib -lpthread -ldl -lpangocairo-1.0
-lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lpng12 -lm
$PREFIX/../lib/libdirectfb.so
$PREFIX/../lib/libdirect.so
$PREFIX/../lib/libfusion.so"
GDK_PIXBUF_DEP_CFLAGS="-pthread -I$PREFIX/include/glib-2.0
-I$PREFIX/lib/glib-2.0/include
-I$PREFIX/include
-I$PREFIX/../include"
GDK_PIXBUF_DEP_LIBS="-L$PREFIX/lib
-lgmodule-2.0 -ldl -lgobject-2.0 -lglib-2.0 -lpng12 -lm"
GTK_DEP_CFLAGS="-pthread -I$PREFIX/include/glib-2.0
-I$PREFIX/lib/glib-2.0/include
-I$PREFIX/include/pango-1.0
-I$PREFIX/include/cairo
-I$PREFIX/include -D_REENTRANT -D_GNU_SOURCE
-I$PREFIX/../include/directfb
-I$PREFIX/include/atk-1.0
-I$PREFIX/../include"
GTK_DEP_LIBS="-L$PREFIX/lib
-lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lgobject-2.0 -lgmodule-2.0
-ldl -lglib-2.0 -lcairo -lpng12 -lm
$PREFIX/../lib/libdirectfb.so
$PREFIX/../lib/libdirect.so
$PREFIX/../lib/libfusion.so"
GDK_EXTRA_CFLAGS="-I$PREFIX/../include"
GDK_EXTRA_LIBS="-L$PREFIX/../lib -lz -lpthread -ldl
$PREFIX/../lib/libdirectfb.so
$PREFIX/../lib/libdirect.so
$PREFIX/../lib/libfusion.so"
./configure --host=$HOST --build=$BUILD --prefix=$PREFIX
--with-gdktarget=directfb --without-libtiff --without-libjpeg
--disable-glibtest --disable-largefile --disable-modules
--with-included-loaders=gif,png,xpm
Edit gtk/Makefile:
Add to the GTK_DEP_LIBS var the following value:
-lfontconfig -lfreetype
Remove the linking line of the rule gtk-query-immodules-2.0$(EXEEXT).
Warning: This means that we won’t have this command available in the target.
#$(LINK)
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.
If you want to add to add PDF/PS support you can try Poppler.
Edit the files:
* gtk/gtkprintoperation.c
* gtk/gtkprintoperation-unix.c
* modules/printbackends/lpr/gtkprintbackendlpr.c
* modules/printbackends/file/gtkprintbackendfile.c
Comment the lines in all these files that contains the following includes or function calls:
#include
#include
cairo_pdf_surface_set_size()
cairo_pdf_surface_create()
cairo_ps_surface_create_for_stream()
Compile and install:
$ make
$ make install
That’s it. Feel free to contact for any comment/idea/hint if you have any problem or want to improve this procedure.
Additional notes
If you want to include libjpeg you new to remove the option –without-libjpeg and add it to the option –with-included-loaders=gif,png,xpm,jpeg