\subchapter{Application development}{Objective: Compile and run your
  own DirectFB application on the target.}

\section{Setup}

Go to the \code{/home/<user>/felabs/sysdev/appdev} directory.

\section{Compile your own application}

We will re-use the system built during the {\em Buildroot lab} and add
to it our own application.

First, instead of using an \code{ext2} image, we will mount the root
filesystem over NFS to make it easier to test our application. So,
create a \code{qemu-rootfs/} directory, and inside this directory,
uncompress the tarball generated by Buildroot in the previous lab (in
the \code{output/images/} directory). Don't forget to extract the
archive as \code{root} since the archive contains device files.

First, if you haven't done it yet in the manual cross-compiling lab,
modify the \code{/etc/qemu-ifup} script so that it just contains 2 lines:
\begin{verbatim}
#!/bin/sh
/sbin/ifconfig $1 172.20.0.1
\end{verbatim}

Then, adapt the \code{run_qemu} script to your configuration, and
verify that the system works as expected.

Now, our application. In the lab directory the file \code{data/app.c}
contains a very simple DirectFB application that displays the
\code{data/background.png} image for five seconds. We will compile and
integrate this simple application to our Linux system.

Buildroot has generated toolchain wrappers in
\code{output/host/usr/bin}, which make it easier to use the toolchain,
since those wrappers pass some mandatory flags (especially the
\code{--sysroot} gcc flag, which tells gcc where to look for the
headers and libraries).

Let's add this directory to our PATH:
\begin{verbatim}
export PATH=/home/<user>/felabs/sysdev/buildroot/output/host/usr/bin:$PATH
\end{verbatim}

Let's try to compile the application:

\begin{verbatim}
arm-linux-gcc -o app app.c
\end{verbatim}

It complains that it cannot find the directfb.h header. This is
normal, since we didn't tell the compiler where to find it. So let's
use \code{pkg-config} to query the {\em pkg-config} database about the
location of the header files and the list of libraries needed to build
an application against DirectFB:

\small
\begin{verbatim}
export BUILDROOT_OUTPUT=/home/<user>/felabs/sysdev/buildroot/output/
export PKG_CONFIG_PATH=$BUILDROOT_OUTPUT/staging/usr/lib/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=$BUILDROOT_OUTPUT/staging/
arm-linux-gcc -o app app.c $(pkg-config --libs --cflags directfb)
\end{verbatim}
\normalsize

Our application is now compiled! Copy the generated binary and the
\code{background.png} image to the NFS root filesystem (in the
\code{root/} directory for example), start your system, and run your
application!
