Building Debian packages with Scratchbox

1. Problems with Debian package compilation

Many packages in Debian require a lot of other Debian packages to be installed before they can built from sources. Some of those dependensies are also circular meaning that for package A to be built, package B has to be installed, but either directly or through other dependencies package B requires package A to be installed before it can be built.

Optimal solution would be that all developement tools that are required in build processes would be run on the developement host which is faster than the target platform, but including everything provided by Debian in scratchbox is not very practical and in any case we need libraries for the target platform when linking software or testing the compiled binaries.

2. What is Rootstrap?

Normally when one compiles Debian packages on a host natively Debian is already installed on that machine providing needed libraries, programs and a (hopefully) intact dpkg package database.

As it is hard to do a normall install to the target platform inside scratchbox (especially when some packages might require more resources at install time than the target platform has to offer) we did a "pre-installation" of the packages and packaged them into a tar archive which can be extracted directly to the "/targets/<TARGETNAME>/" directory inside scratchbox. It contains enough packages for 'apt-get source -b galculator' to work "out-of-the-box".

3. Installing Rootstrap

  1. Start Scratchbox

    $ /scratchbox/users/username/run.sh

  2. Make sure you have created the ARM target (see Configuring Scratchbox for ARM)

  3. You can download a preliminary version of rootstrap from the download section.

    Eexample: wget http://scratchbox.org/download/files/crocodile-files/rootstrap_0.9.7.1-1.tar.gz

  4. Extract rootstrap inside Scratchbox to your target directory

    Example: $ xfz rootstrap_0.9.7.1-1.tar.gz -C /targets/ARM

  5. Post-installation of rootstrap is not automated/scripted yet so you need to

    1. Add your useraccount to /etc/passwd, /etc/group

      Example: echo "$USER:x:$UID:$UID:,,,:/home/$USER:/bin/bash" >> /etc/passwd echo "$USER:x:$UID:" >> /etc/group

    2. Fix /etc/resolv.conf to match your network settings

      Example: From OUTSIDE of scratchbox $ cp /etc/resolv.conf /scratchbox/users/$USER/targets/ARM/etc/resolv.conf

    3. Setup .bashrc with Scratchbox specific variables

      Example: INSIDE scratchbox [sbox-ARM: ~ ] > cat > ~/.bashrc <<EOF # Unset verbose cputransparency as it interferes with some configure scripts unset SBOX_CPUTRANSPARENCY_VERBOSE # Setup binary redirection for some executables export SBOX_REDIRECT_BINARIES=/usr/bin/perl:/scratchbox/tools/bin/perl export SBOX_REDIRECT_BINARIES=$SBOX_REDIRECT_BINARIES#/usr/bin/make:/scratchbox/tools/bin/make export SBOX_REDIRECT_BINARIES=$SBOX_REDIRECT_BINARIES#/usr/bin/file:/scratchbox/tools/bin/file export SBOX_REDIRECT_BINARIES=$SBOX_REDIRECT_BINARIES#/usr/bin/msgmerge:/scratchbox/tools/bin/msgmerge export SBOX_REDIRECT_BINARIES=$SBOX_REDIRECT_BINARIES#/usr/bin/msgfmt:/scratchbox/tools/bin/msgfmt export SBOX_REDIRECT_BINARIES=$SBOX_REDIRECT_BINARIES#/usr/bin/awk:/scratchbox/tools/bin/awk # Setup perl to also search for modules from target directories export PERL5LIB=/usr/lib/perl/5.8.0:/usr/lib/perl5:/usr/share/perl/5.8.0:/usr/share/perl5 # Set scratchboxes dpkg architecture export SBOX_DPKG_INST_ARCH=arm # Set scratchboxes architecture export SBOX_UNAME_MACHINE=arm # Setup TMPDIR to something that is also available on CPU transparency device # /tmp is not mounted via NFS normally export TMPDIR=/var/tmp # Some buildscripts require these export PERL=/usr/bin/perl export PERL_PATH=/usr/bin/perl export PKG_CONFIG_PATH=/usr/lib/pkgconfig export BUILDCC=host-gcc EOF

  6. Include the settings generated in the current bash session

    [sbox-ARM: ~] > source .~/bashrc

  7. Make sure Debian devkit is enabled in scratchbox

    [sbox-ARM: ~ ] > sbox-config -sd debian

  8. Check for updates to the rootstrap packages

    [sbox-ARM: ] > apt-get update [sbox-ARM: ] > fakeroot apt-get upgrade

  9. Your Scratchbox is now be set up for GUI application cross-development for the ARM target platform. Test your installation by building the Hello World application from GTK+ 2.0 Tutorial:

    gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags --libs gtk+-2.0`

  10. Copy the "helloworld" binary executable over to the target device, ensure that you have a windowing system, gtk libraries, and all dependencies installed, and run the program. It should produce a simple window with a single button on the target device screen.

    NOTE It is very important that build environment libraries and includes match those on the target device. Any discrepancies can lead to errors that are very hard to track down.

    Rootstrap is meant for development purposes only.

4. Various tricks

5. Using Rootstrap to build Debian packages