Creating a Nokia 770 Debian Package for a Mono Application

Introduction

The first thing you want to do if you intend to develop mono applications that will target the Nokia 770 would be to read the tutorial at the maemo Wiki. You may also want to review their instructions and recommendations for building a package that the Application Installer applet in the 770's control panel will handle. Of course, as a dedicated mono developer we assume that you have already memorized our own set of guidelines for application deployment :)

Over the next paragraphs I will try to show a simplified and minimalistic approach to creating a Debian package that can easily install and uninstall on the 770.

Conventions and Assumptions

For the purpose of this article, let us assume that the base directory from which we will be working is my home directory /home/pacomart. This directory contains a subdirectory download which in turn has a subdirectory called deb and another called tarball. For simplicity, we will now refer to /home/pacomart using $PREFIX for now on. Therefore, when referring to /home/pacomart/download/tarball we will note it as $PREFIX/download/tarball.

Prerequisites

You will need Paolo Molaro's latest and greatest mono-nokia package that gives you all of the mono runtime and serves as the substrate to your application's needs. At the time of this writing, the mono-nokia_0.1_arm.deb was only available here, but it should soon be available in the mono-project downloads page. The word folder will be use interchangeably with the word directory -- as in a file system object.

I do most of my assembling and disassembling of Debian packages in SUSE Linux 10.0 so I only needed deb-1.10.27-7 rpm. This rpm contains dpkg and dpkg-deb which I used extensively during my research.

Overview

In the article we will create a working directory that we will use as a scratch pad or pre-mastering area. Later we will extract the contents of a pre-existing package so we can study its parts. Then we will add a file and follow up with a repackaging. Finally, the resulting package will be installed on a 770 as a function test.

Creating a Pre-mastering Folder

We begin by opening a terminal session -- gnome-terminal or xterm will do fine. At the prompt, change to the directory that you will use as $PREFIX (if you are not already there) with:

cd $PREFIX

Create the following folders with the next two command lines:

mkdir -p download/deb
mkdir fakeroot

The use of -p on the mkdir command will permit creating the download directory as parent folder of deb if it does not exist already. Change the working directory to $PREFIX/download/deb and download the sample mono application Debian package. You may use your favorite browser or wget. Should you want to remain working from the command line use:

wget http://www.mfconsulting.com/tutorial/nokia770/deb/maemo_peditgtksharp_0.1_arm.deb

Extracting the Contents of the Debian Package and Recreating the Control Files

Change to your pre-mastering folder ($PREFIX/fakeroot) and execute the following two command lines:

dpkg -x ../download/deb/maemo_peditgtksharp_0.1_arm.deb ./
dpkg -e ../download/deb/maemo_peditgtksharp_0.1_arm.deb

The first instruction will extract the contents of the deb file and will create an expanded directory structure rooted at $PREFIX/fakeroot. To illustrate this fact, we can see how the file peditgtk.png which was originally packaged as ./usr/share/icons/hicolor/26x26/hildon/peditgtk.png can now be found at $PREFIX/fakeroot/usr/share/icons/hicolor/26x26/hildon/peditgtk.png.

The second instruction will create a directory called DEBIAN that contains the control files for the deb package. Therefore, you will end up with at least the file $PREFIX/DEBIAN/control.

Points of Interest on the Extracted Mono Application Package

A useful representation of the contents of the extracted package can be achieved by using the tree command. It is recommended that in your study of the extracted files and directories you pay attention so the file attributes and modes. Immediately visible thanks to the tree command's ability to color code its output is the files peditgtk and PeditGtkSharp.exe, both are sort of green color which denotes that they have executable attributes.

Directory Tree

Aside from the DEBIAN folder (this was created by you invoking dpkg -e earlier) the other directories form a directory structure that has an etc branch and a usr branch.

The etc branch exist to host a copy to the *.desktop file for your application or a link to the one stored in $PREFIX/usr/share/applications/hildon/. This file is common in the GNOME Desktop and helps advertise the presence of an application through the Desktop menus. Windows programmers may relate to this file type by comparing it with the Start Menu Short-cut files *.lnk (except that the *.desktop is a text file).

Under the usr directory hierarchy you should see bin, lib and share. The bin folder should contain the shell script that invokes mono and your executable assembly. The lib directory contains a subdirectory structure to support dbus. The heart of you distribution will probably be stored in $PREFIX/usr/lib/<app specific directory>. In our example, I chose to call it $PREFIX/usr/lib/peditgtksharp and it contains the PeditGtkSharp.exe. The last sub branch of the usr folder is the subfolders of the share directory. Common directories here include applications, icons and doc. The $PREFIX/usr/share/applications/hildon holds the peditgtksharp.desktop file. The last subdirectory system in share is the icons subfolders. These have png files of various resolutions that are referenced in the values stated inside the *.desktop files.

Below are links to the contents of the application's shell script located in the bin directory, the desktop file and the dbus service file:

peditgtk

peditgtksharp.desktop

com.mfconsulting.peditgtksharp.service

Analysis of the DEBIAN Directory and its Control Files

Unlike packages meant for Debian Linux or its variants (like Ubuntu), the Application Installer applet in the Nokia 770 Control Panel will not make use of postinstall or prerm scripts contained in the DEBIAN folder of a Debian package. Moreover, the inclusion of these script files in your package may keep it from installing altogether. The two files that are most commonly found in the DEBIAN folder of a deb package intended for the Nokia 770 are the control file (required) and the md5sum file (optional).

The description of the package and its dependencies are specified in the control file. This file is a text file that has key value pairs. The maemo folks recommend to keep dependencies to a minimum and have your applications as self contained as possible. Ideally, your Depends variable would only have maemo as its value. However, since we are deploying mono applications, our Depends variable will have the value:

maemo, mono-nokia

Since the mono-nokia package already Depends on maemo, you may get away with just specifying the mono-nokia as the value of your Depends variable in your control file.

The md5sum file contains a list of checksum values for the files listed. As mentioned earlier, this is an optional file and its absence will not keep your package from installing. A simple way to generate the checksum file for your package would be to change to your pre-mastering folder ($PREFIX/fakeroot) and execute the following command:

find ./ -type f -exec md5sum {} \; >./DEBIAN/md5sum

If you already had files in the DEBIAN folder (like the control file) you may opt to edit the resulting md5sum file and remove the lines that may contain references to files in the DEBIAN folder.

Building the Debian Package

To build a Debian package for the folder that you have been creating you would only have to follow these simple steps:

Change to the directory $PREFIX by typing the line below at the command line:

cd $PREFIX/

Build the actual deb file by entering the command line

dpkg-deb -b fakeroot maemo_peditgtksharp_0.1_arm.deb

If everyting works correctly, the build process will show a message like the one below just before returning you to the prompt:

dpkg-deb: building package `peditgtksharp' in `maemo_peditgtksharp_0.1_arm.deb'.

You can now put the resulting package in the memory card of the 770, connect to your development PC using a USB connection and uploading the package into the tablet or upload the file to a web accessible location and use the 770's web browser to download to a location of your choice.

Installing and Testing your Mono Application on the Nokia 770

At this time you can either open the File Manager application that is included with the 770 to locate and launch the Debian package you created or use the Application Installer program located in Control Panel and search for the application package you placed in your tablet.

Using the Application Installer program is recommended since this will also show you the packages that are already installed as well as the package information (This comes from the control file in the package)

Final Notes

The PeditGtkSharp application used for this sample is a simple mono program that was NOT design exclusively for the maemo SDK. The file system that the Nokia 770 uses is very restrictive so that the one user of the tablet (/home/user) only interacts with a subset of directories that are normally hidden (these are .* directories) under /home/user/MyDocs. The UI conventions are also different from those of the GNOME Desktop. In fact the maemo SDK uses the Hildon guidelines for desktop applications. However, it is quite possible to successfully run -- as my humble app demonstrates -- to run Gtk# 2.0 applications in it.

Because of the limitation on running scripts during the installation and/or removal of deb packages in the 770, we have not yet managed to affect the environment with the addition of mono specific variables and other goodies. Therefore you may consider reading and following the recommendations offered in the README file included in the mono-nokia package.