Linux from Scratch - buid gtk+

This note is written on Jan. 10, 2017.
Translated from Chinese on demand.
Most of the packages chosen to build gtk+ are up to date.
Tested on Lichee One (Jan. 10, 2017)

Steps

  • Environment Variables
  • Build jpeg
  • Build zlib
  • Build libpng
  • Build libxml
  • Build libffi
  • Build ncurse
  • Build util-linux
  • Build libpcre
  • Build glib
  • Build atk
  • Build expat
  • Build freetype
  • Build freetype
  • Build DirectFB-flux support
  • Build DirectFB
  • Build pixman-1
  • Build libsvg
  • Build cairo
  • Build libsvg-cairo
  • Build harfbuzz
  • Build pango
  • Build gdk-pixbuf
  • Build gtk

Environment Variables

export ARM_PREFIX=/home/lichee-rootfs
export ARM_HOST=arm-linux-gnueabihf
export ARM_CFLAGS=-I$ARM_PREFIX/include
export ARM_LDFLAGS=-L$ARM_PREFIX/lib
export PKG_CONFIG_PATH=$ARM_PREFIX/lib/pkgconfig

Note:

  • $ARM_PREFIX specifies the root file system of the Lichee target.
  • $ARM_HOST specifies the tool chain.
  • $PKG_CONFIG_PATH tells pkg-config tool where to find config file. The tool is used to generate compile parameters for dependent libraries.

Build jpeg

Source: http://www.ijg.org/files/
Version: jpegsrc.v9b.tar.gz

./configure --enable-shared --enable-static --prefix=$ARM_PREFIX --with-gnu-ld --host=$ARM_HOST
make
make install

Note:

  • There are two groups of source package, one likes jpegsrc[xx].zip and the other jpegsrc.[xx].tar.gz. The latter is used to build under Linux.

Build zlib

Source: http://zlib.net
Version: zlib-1.2.8.tar.gz

export CHOST=$ARM_HOST
./configure --prefix=$ARM_PREFIX
make
make install

Build libpng

Source: http://www.libpng.org/pub/png/libpng.html
Version: libpng-1.6.27.tar.gz
Dependency: zlib

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
make install

Build libxml

Source: http://xmlsoft.org/sources/old
Version: libxml2-2.7.1.tar.gz

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST --with-zlib
make
make install

Build libffi

Source: ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
Version: libffi-3.2.1.tar.gz

export CC=$ARM_HOST-gcc
./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
make install

Build tslib

Source: https://github.com/kergoth/tslib/releases
Version: tslib-1.3.0-rc3.tar.gz
Dependent Tools: automake autoconf libtool

Build:

sudo apt-get install autoconf automake libtool
./autogen.sh
echo "ac_cv_func_malloc_0_nonnull=yes"> tmp.cache
./configure --prefix=$ARM_PREFIX --host=$ARM_HOST --enable-input=no --
make

Note:

  • Many tslib source packages don’t contain configure script, but rather an autogen.sh script. The latter generates the former one, with automake tool. Therefore automake has to be installed on the developping machine.
  • This library is not necessary since it is to provide tuch-screen support. In fact the compile failed when I tried.

Build ncurse

Source: https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.0.tar.gz

Version: ncurses-6.0.tar.gz

Compile:

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST --enable-widec --without-cxx
make
make install

Note:

  • the parameter --enable-widec is necessary. It tells the makefile to generate ncursesw that is needed by util-linux.

Build util-linux

Source: https://www.kernel.org/pub/linux/utils/util-linux/v2.29

Version: util-linux-2.29.tar.gz

Dependency: libncurses, ncursesw

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
sudo make install

Note:

  • There are chgrp tty [file] commands executed in the make install step. Root privilege is needed.

Build libpcre

Source: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre
Version: pcre-8.39.tar.gz

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST --disable-cpp --enable-static --enable-utf8 --with-link-size=4
make
make install

Build glib

Source: https://ftp.gnome.org/pub/gnome/sources/glib/2.50
Version: glib-2.50.2.tar.xz
Dependency: libffi libmount(in util-linux) libpcre
Dependent tools: gettext

sudo apt-get install gettext

export LIBFFI_LIBS="-L$ARM_PREFIX/lib -lffi"
export LIBFFI_CFLAGS=-I$ARM_PREFIX/lib/libffi-3.2.1/include
export LIBMOUNT_LIBS="-L$ARM_PREFIX/lib -lmount"
export LIBMOUNT_CFLAGS=-I$ARM_PREFIX/include/libmount
export PCRE_LIBS="-L$ARM_PREFIX/lib -lpcre"
export PCRE_CFLAGS=-I$ARM_PREFIX/include
echo glib_cv_stack_grows=no > tmp.cache
echo glib_cv_uscore=no >> tmp.cache
echo ac_cv_func_posix_getpwuid_r=yes >> tmp.cache
./configure --prefix=$ARM_PREFIX --host=$ARM_HOST --cache-file=tmp.cache
make
sudo make install

Note:

  • Root privilege is needed in the make install step.
  • In the version2.30.0 or higher, the definition of G_CONST_RETURN is marked as deprecated. There may be errors on not finding this definition.

Build atk

Source: http://ftp.acc.umu.se/pub/gnome/sources/atk
Version: atk-2.22.0.tar.xz
Dependency: glib, libffi, libpcre etc

sudo apt-get install libglib2.0-dev

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
sudo make install

Note:

  • The tool glib-genmarshal will be executed so as to generate necessary source code. This tool is built along with glib, only that it is for the lichee target. Therefore libglib2.0-dev should be installed.
  • I came across an error where ld can’t find libffi.so.6 and libpcre.so.1 when build under test directory. To solve this problem, you can modify Makefile, find the line LDFLAGS = and replace it with LDFLAGS=-L$ARM_PREFIX/lib -lffi -lpcre.

Build expat

Source: https://sourceforge.net/projects/expat
Version: expat-2.2.0.tar.bz2

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
make install

Build freetype

Source: http://download.savannah.gnu.org/releases/freetype
https://fossies.org/linux/misc/freetype-2.7.1.tar.gz
Version: freetype-2.7.1.tar.gz

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
make install

Build fontconfig

Source: https://www.freedesktop.org/software/fontconfig/release
Version: fontconfig-2.9.0.tar.gz
Dependency: freetype, libxml, expat

export EXPAT_LIBS=`pkg-config --libs expat`
export EXPAT_CFLAGS=`pkg-config --cflags expat`
export FREETYPE_LIBS=`pkg-config --libs freetype2`
export FREETYPE_CFLAGS=`pkg-config --cflags freetype2`
export LIBS=-Wl,-rpath,$ARM_PREFIX/lib
./configure --prefix=$ARM_PREFIX --host=$ARM_HOST --disable-docs --with-arch=ARM --with-freetype-config=$ARM_PREFIX/bin/freetype-config --with-expat-includes=$ARM_PREFIX/include --with-expat-lib=$ARM_PREFIX/lib
make
make install

Note:

  • I tried two newer versions, 2.12.1 and 2.10.95, before 2.9.0. The build will success, however when running on the lichee target, the binary tool (such as fc-cache, fc-scan) will stuck when scanning tff font files. I don’t know why. The new versions run well on x86 developping machine.

Build DirectFB-flux support

Source: https://github.com/Distrotech/flux

./configure
make
sudo make install

Note:

  • This is a tool running on the developing machine, instead of a library running on lichee.

Build DirectFB

Source: https://github.com/Distrotech/DirectFB/releases
Version: DirectFB-DIRECTFB_1_7_7.tar.gz
Dependency: flux
Dependent tool: g+±arm-linux-gnueabihf

sudo apt-get install g++-arm-linux-gnueabihf

./autogen.sh --help

export LIBS="-L$ARM_PREFIX/lib -lz-lpng16"
export LIBPNG_LIBS="-L$ARM_PREFIX/lib -lpng16"
export LIBPNG_CFLAGS="-I$ARM_PREFIX/include"
./configure\
  --prefix=$ARM_PREFIX\
  --host=$ARM_HOST \
  --with-gfxdrivers=none\
  --with-inputdrivers=all\
  --disable-tiff\
  --disable-svg\
  --disable-x11\
  --enable-png\
  --enable-jpeg\
  --enable-zlib\
  --enable-sdl=no\
  --enable-gif=no
make
make install

Note:

  • c++ tool is necessary to build this library.

Build pixman-1

Source: https://www.cairographics.org/releases
Version: pixman-0.34.0.tar.gz
Dependency: (none?)

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
make install

Build libsvg

Source: https://www.cairographics.org/releases
Version: libsvg-0.1.4.tar.gz

export CFLAGS=$ARM_CFLAGS
./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
make install

Build cairo

Source: https://cairographics.org/snapshots
Version: cairo-1.15.2.tar.xz
Dependency: directfb freetype libpng pixman-1

./configure\
  --prefix=$ARM_PREFIX\
  --host=$ARM_HOST \
  --without-x\
  --disable-xlib\
  --disable-xlib-xrender\
  --enable-svg\
  --enable-directfb\
  --enable-freetype\
  --enable-png
make
make install

Note:

  • The directfb surface backend feature is still under active development and is included in this release only as a preview. It does NOT fully work yet and incompatible changes may yet be made to directfb surface backend specific API.

Build libsvg-cairo

Source: https://cairographics.org/snapshots
Version: libsvg-cairo-0.1.6.tar.gz

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
make install

Build harfbuzz

Source: https://www.freedesktop.org/software/harfbuzz/release
Version: harfbuzz-1.4.1.tar.bz2
Dependency: pcre glib cairo fontconfig freetype expat libpng16 libz

export LIBS="-L$ARM_PREFIX/lib -lpcre -lpixman-1 -lfontconfig -lexpat -lfreetype -lpng16 -lz"
./configure --prefix=$ARM_PREFIX --host=$ARM_HOST

Build pango

Source: http://ftp.gnome.org/pub/GNOME/sources/pango
Version: pango-1.40.3.tar.xz
Dependency: glib, freetype, xml, cairo, harfbuzz, fontconfig

./configure --prefix=$ARM_PREFIX --host=$ARM_HOST
make
make install

Note:

  • This pango version needs fontconfig >= 2.10.91. You can install a newer fontconfig, build pango and replace fontconfig with 2.9.0.
  • An error may occur saying cannot find ‘hb-ft.h’. Simply find the header file and insert #include this header to the source file which caused this error.

Build gdk-pixbuf

Source: http://ftp.acc.umu.se/pub/gnome/sources/gdk-pixbuf/2.35
Version: gdk-pixbuf-2.22.1.tar.xz

echo gio_can_sniff=yes>tmp.cache
./configure --prefix=$ARM_PREFIX --host=$ARM_HOST --without-libtiff --without-libjasper --cache-file=tmp.cache
make
sudo make install

Build gtk+

Source: http://ftp.gnome.org/pub/gnome/sources/gtk+
Version: gtk±2.22.1.tar.gz

export LDFLAGS="-L$ARM_PREFIX/lib -Wl,-rpath,$ARM_PREFIX/lib"
export CPPFLAGS="-I$ARM_PREFIX/include"
export LIBS="-lpcre -lffi"
./configure --prefix=$ARM_PREFIX --host=$ARM_HOST --with-gdktarget=directfb --without-x

Note:

  • The env LDFLAGS is necessary when checking if gcc works in the configure step.
  • The env LIBS is necessary when checking if pango is available in the configure step.
  • There will be an error saying unknown type name ‘GdkPixdata’ when building under gtk dir. This is because GdkPixdata is labeled as a deprecated feature. Go to gtk dir and modify Makefile, delete the parameter -DGDK_PIXBUF_DISABLE_DEPRECATED.
  • There will be an error saying unknown type name ‘G_CONST_RETURN’. This is because G_CONST_RETURN in the glib is marked as a deprecated feature. Modify the Makefile, find -DG_DISABLE_DEPRECATED and delete the definition parameter.

Demo

would be perfect if convert this article to english totally :wink: