Packaging

= Creating Packages for Maemo =

Since Maemo is based on the Debian operating system, creating packages for Maemo borrows a lot of tools and techniques from Debian.

Checking Maemo Packages
Lintian dissects Debian packages and reports bugs and policy violations. It contains automated checks for many aspects of Debian policy as well as some checks for common errors. Unfortunately it does not check conformance to the additional Maemo policy.

Currently Maemo is creating Maemian to check its policy.

= A concrete example - hello =

Prerequisites
For the purposes of our article, we will be packaging a simple Hildon hello-world application. This will be a standard source tarball using autotools.

hello.c
The only C file in our project is hello.c:

Autotools
The rest of the project is a small number of files to allow us to make a standard "./configure && make && make install" project with automake, aclocal and autoconf.

Using the autotools for packaging is quite simple for small projects. You need two files to define the structure of your project,  and.

is a file used by automake and autoconf to generate the configure script, define the version of the resulting .tar.gz and include the tests which we need to ensure the presence of the appropriate versions of dependencies. Since  is so simple, we only need to check for the standard C library and a C compiler, and for the Hildon library. The Hildon library check is done by, which makes getting the right compiler and linker flags easy. The only output file generated by the configure script will be, from the input file  , which is in turn generated from

AC_INIT([hello], [0.1]) AM_INIT_AUTOMAKE([foreign]) AC_PROG_CC AC_PROG_INSTALL PKG_CHECK_MODULES([HILDON], [hildon-1]) AC_OUTPUT([Makefile])

defines the source structure of your project, listing the files to be installed, the binaries and object files to be generated, and the relationship between the binaries and source files.

You can see that our  is very simple, defining one source file, and one binary file. The "_SOURCES" line must start with a binary name from "bin_PROGRAMS" to make the link between the source file and the executable. The "_CPPFLAGS" and "_LDADD" lines take the Hildon compiler and library flags that are provided by  in.

bin_PROGRAMS = hello hello_SOURCES = hello.c hello_CPPFLAGS = $(HILDON_CFLAGS) hello_LDADD = $(HILDON_LIBS)

Once we have these files, we simply need to initialise our project, defining its license, and generating all of the required files for automake to do its thing. We do this by running:

autoreconf --force --install

The arguments to autoreconf copy required files to the project (including generic install instructions and a license).

Pay attention during the execution of autoreconf, the execution should be entirely silent if it runs correctly. If there are messages, read them and do what is required to address the issues.

Now to build your software, you have a standard configure script and can simply run

./configure make make install

and to build a distribution file, you have

make dist

which will create a file hello-0.1.tar.gz, which you can use for the rest of this packaging tutorial.

Packaging a .deb
The easiest way to package a .deb file is to use Debian's build helpers.

Package your application as you would distribute it in a .tar.gz (when using autotools, this is done with "make distcheck"). In our example, we uncompress hello-0.1.tar.gz, and change the current directory to hello-0.1.

$ tar xfz hello-0.1.tar.gz $ cd hello-0.1

Then we run dh_make, which initialises the Debian package management file structure (among other things): $ dh_make -e -f ../hello-0.1.tar.gz -c GPL

You can of course choose a different licence for your package.

Answer the resulting questions - in this case, we are packaging a single binary.

We can now edit the files in the  directory which has been created to their desired values, before packaging the software. In fact, we can delete many of these files. All of the files ending in “.ex” or “.EX” are example files, intended to help you package different types of software.

If you use a standard configure script, you do not need to modify any files except, where the Hildon build-time dependency should be added. Change the Build-Depends line to read (by adding "libhildon1" at the end):

Build-Depends: debhelper (>= 5), autotools-dev, libhildon1

Before creating a .deb, you should set a changelog entry. .deb changelogs follow a special format, so rather than editing the files by hand, use the dch helper application. This will allow you to add what new features went into this application, give credit, and so on. It is an especially important file because it sets the version and revision of the source and binary packages. On saving, a syntax check is performed which ensures that the resulting file is OK. The file format is completely documented in the Debian packaging guide.

Finally, we generate a .deb from the source code using the command: dpkg-buildpackage -sa -rfakeroot -k

You should now have several files created in the parent directory to where you unpacked the source code. I have;

hello_0.1.orig.tar.gz hello_0.1-1_i386.deb hello_0.1-1.diff.gz hello_0.1-1.dsc hello_0.1-1_i386.changes

Now change the target architecture to ARMEL and rebuild it, to generate hello_0.1-1_arm.deb

Additional information
If you use git then you may not want to include the entire git repo in your source bundle. With dpkg-source version 1.13.25 the -i option is not git-aware so you can do:

dpkg-buildpackage -rfakeroot -sa -i -I.git

You may verify that your  field in debian/control is complete by running:

dpkg-depcheck -m dpkg-buildpackage -rfakeroot -b

in the source tree. (You will need to  for this to work).

Uploading to extras-devel
= Porting an existing Debian package =

Finding your package in Debian
If you want to port a Debian package to Maemo, you should check and see if it is already packaged for Debian and use that package if you can - this will save you time and effort. You can search in Debian's Package Tracking System (PTS) to see if it is there. There is a search system on the PTS page, under the "distribution" drop-down, select 'any', this will search throughout Debian's repositories to find the package. Debian has more than 20,000 packages just in its stable distribution so your application is likely already packaged.

If you find the package already exists in Debian, you can get the source, including the packaging source, with apt-get. To do this, you'll have to edit your /etc/apt/sources.list, you can follow this recipe;

$ echo "deb http://ftp.it.debian.org/debian/ unstable main contrib non-free" >> /etc/apt/sources.list $ echo "deb-src http://ftp.it.debian.org/debian/ unstable main contrib non-free" >> /etc/apt/sources.list $ apt-get update $ apt-cache search "application name" $ apt-get source "application name"

To learn more about the  you can do a 'man sources.list' if you are running Debian or a Debian-based GNU/Linux distro.

Modifying a Debian package for Maemo
Once you have the source of the Debian package, you will need to make some modifications to that package for it to build under Maemo. See the Maemo packaging policy for more information.

The maintainer field (in the  file) must be changed if the upstream package is modified, for example: Maintainer: Tcl/Tk Debian Packagers  should be replaced by Maintainer: My Name  XSBC-Original-Maintainer: Tcl/Tk Debian Packagers 

You must add a new entry to  and append   to the version, for example: tk8.5 (8.5.8-1) unstable; urgency=low becomes: tk8.5 (8.5.8-1maemo1) fremantle; urgency=low This indicates that there have been Maemo-specific changes to the packaging. If you upload new changes, you must add a new changelog entry and increment the version number, for example ).

The "Debian way" is to keep all modifications to the package in the  file and to leave the   file untouched. There are several ways to apply patches with Debian packaging, and some are described in the patching section of the New Maintainer's Guide

However, the  cannot store binary files like icons. A possible workaround is to uuencode the binary file, for example (in ): uuencode -m icon.png icon.png > icon.png.b64 and in the rules file decode the file to debian/icon.png before installation uudecode debian/icon.png.b64 For this solution you have to add  to the.

If the package should be visible in the Application Manager, the Section field should begin with, with the valid sections listed below. You should also add and install a  file for starting the application, if one does not already exist.

Differences between Debian/Ubuntu and Maemo
The are a couple of important differences between a Debian system and Maemo:


 * Busybox: Maemo uses busybox to replace most of bsdutils, coreutils, findutils and bash, therefore most of the extended options for the commands and shell are not available. Check the postinstall and other package scripts for such options and try to replace or emulate them.


 * Outdated build and configuration tools: the SDK and autobuilder provide only outdated versions of gcc, dpkg, debhelper, cdbs, debconf, ucf and other build tools. Try to replace the  in the   file with older versions or use backports like debhelper7


 * Directories for temporary files: is only 900 kB and should only be used for very small temporary files.   on the NAND is larger. A new temporary directory in   could be even larger. Replace constructs like   in shell scripts with   (the same applies to  ).


 * Optification may confuse programs: some programs try to find their data files relative to the binary location. Such a program stored in  would search, for instance, in   while the actual data may be in.


 * Installation in : if you want to perform manual optification (e.g. using  ) you should store "none" in   and add some to the postinst script which symlinks the binaries and libraries of the package to   and , respectively.


 * Documentation: do not install documentation in  or   - docpurge will remove it. You may install it in the   hierarchy, however.

= Maemo-specific packaging information =

Packaging policy
Maemo packages follow the Debian Policy, but there are some items where Maemo:
 * Is more strict (it is an embedded distribution)
 * Is more relaxed:
 * A single target device (per release)
 * A single specified UI (Hildon)
 * A single user
 * Differs from Debian because Maemo has different:
 * Objectives
 * Maintainers
 * Infrastructure

Most of the specifics for Maemo packaging are outlined in the Maemo packaging policy. The policy is still in the draft stage, so certain parts are still incomplete or not entirely up to date.

Sections
This is the list used in Fremantle/Maemo5 and is the same as the final list for Diablo as discussed in the task.

If the package's section starts "user/", but is not any of the above, the Application Manager forces them into an "Other" section.

Desktop files
Desktop files are used for application icons in menus on the Linux desktop. The Maemo application menu uses the same desktop files, but installs them to a slightly different location;  instead of. You can add the desktop file to the  file for your application so that it is installed to the correct place, for example, if you have , adding the line:

application.desktop usr/share/applications/hildon

would install  to the correct location. The location is also available with, for example:

pkg-config --variable=desktopentrydir osso-af-settings

which can be used in a Makefile to install the desktop file to the correct location.

There is some official documentation on desktop files for Maemo applications.

Maemo-specific fields
There are a number of Maemo-specific package fields that are handled by Application manager. The Application manager documentation outlines them.

Displaying an icon in the Application Manager next to your package
Displaying an icon in the Application Manager next to your package makes it look pretty and makes your package stand out, and it is not that hard to do.

apt-get update apt-get install sharutils uuencode -m > .base64
 * 1) Make an image that is 48x48 pixels. The image can be saved in any format that is supported by GdkPixbufLoader on Maemo, but PNG is commonly used.
 * 2) base64 encode the image. This can be done in many ways, depending on the platform, but assuming you are in scratchbox:
 * 1) Add the field XB-Maemo-Icon-26 to your   (in Maemo4 the size of the icons was 26x26, hence the name of the field, which has not changed)
 * 2) Open the base64 version of your image and copy from the line under begin-base64 644  to the line above the ===
 * 3) Add this to the XB-Maemo-Icon-26 field
 * 4) Add a space in front of every line of the encoded icon

Here is an example of a properly formatted Maemo-Icon-26: (of wrong image size) Description: Chess... XB-Maemo-Icon-26: iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAABGdBTUEAAK/INwWK6QAAABl0 RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAALxSURBVHja3FZNTBNREP669J/S XYxtKRWl1JOSFBIPhkitCQeNiaKBmzdj9Ggk0ZOBxHDWixcTjV6MF+WiIB40YEyMBMGYEqQK tLS2lG7pdre0pF3WtxslgJRuD2J0kpfdTN7O976Z782sRpIk7IZR2C2TGW1cv8xaY5WuXLy8 iW5XV5fk8/kkr9e7ya/T6SSNRiOViikvbbmDDD590SusZBGYDiDwJbDud7vdvYIgIJfLYXV1 tSwhrQrSfRX6/26N/j+gkjW6ce06HE4HGEctGuj9oEwUzFYz5ubmEA6HQVEUisUi8vn8b4rd zjRbNxCZrr+3t7XTzjrnvMfdxMi7xj6OIRaPIbWcQjabVdRWKBTkrX4SZ2SjvCtKXf+tkxxD M5MetwfHj/lwwueHy+WCVqvdehdHKq7R6JvbpfNMAGiGhs1mg9ls3sS+4hodbDqCwef9mA9P 7vhhVVWV3BGUOomiaCSufEWMxNwimlweMFYbpoMfyp70J6t8xanLZgWs8Ak07N0Hau0P3qOs wIHnl5FJx2E1WlUFuXrzIS713KusRplMCoLAgl2O4N34ODQ4VRaot6cbUzMRNNQ/w/uJWXWM eH5JARkYHsLQMIe1NZEpB7Sn1uKFhkL3maO4cL5NHVAo+hkPnrzEq2HqQIf/3ICzvr7FXmeH 3qBXlslkgtFoVBS3YfbcKRRFfJpagE6vUwd0//FbjI7mkcvnGoNfg51ORx3sNju+hWYxMxsk jHlF2jJgdXU1DAaDrDx/kQAVRREJlldXo8kJoPlQ8wHSevosFgs5MmE5H0IingDP8eAzPAQC tkJakDz05Hsks+poPzwg6+Luo9chVb2O3Hilv7V6W5nO02cVX3wxjsj3CMKRBUSjUcQWY0iy SQVoi6XJaiQxubKpI02yj2xk6BoaBr0BqXRKCZpYSiCZlIXCguM4pWtvY0ypyUtt87PSIj/t pJ/JICzLKiBLySTYVArpdFrp3DuMhRZVqfvnJ+wPAQYA1hdr5EDqltYAAAAASUVORK5CYII=

Please note that if you are packaging a command-line only program that can be executed by the user, you should use the CLI icon only.

Bugtracker location
As a requirement for your package being promoted from Extras-testing to Extras, your  file must have a link to a bugtracker, which is visible in the maemo.org packages interface. It is possible to request a component at bugs.maemo.org or use a Garage project bugtracker, or even an email address.

Add the field ‘XSBC-Bugtracker’ to your, for example: XSBC-Bugtracker: https://bugs.maemo.org/enter_bug.cgi?product=mypackage

Alternatively for e-mail addresses, you can use the following format: XSBC-Bugtracker: mailto:yourname@example.com

Pretty names
A package can specify a pretty name for itself. This name is displayed in the Application manager UI instead of the real package name.

The pretty name is specified with the ' ' field in your  file, for example: XB-Maemo-Display-Name: My package name

Maemo revision string
If an upstream package is re-packaged or modified for Maemo, the Maemo revision string should be appended to the upstream revision, in the  file. So if in Debian the package name was something like "Myapp-0.4-2" in maemo this package will be called "Myapp-0.4-2maemo0". The number after the "maemo" string is a progressive number.

Maemo upgrade description
Tell users what changed in the update: XB-Maemo-Upgrade-Description: Formatted like "Description". Will be displayed if user upgrades to new version and clicks on "Details". . Human-readable and translatable. As with all Maemo-specific fields, the "XB-" prefix is needed so the field will remain in the binary package.

Translations of text fields
The following fields can be translated to the end user's local language: Maemo-Display-Name, Description and Maemo-Upgrade-Description. It is strongly recommended to make use of this possibility so that end users understand what the application does for them while browsing through the Application Manager.

The translation is done by adding a suffix like "-de_DE" to the respective field name, where "de_DE" is the locale the translated text is for. For example, if LC_MESSAGES equals de_DE, the Application Manager first tries "Description-de_DE" to find the description of a package and then falls back to "Description".

Here's an example: Description: Chess... XB-Maemo-Display-Name: My package name XB-Maemo-Upgrade-Description: Formatted like "Description". XB-Description-de_DE: Schach... XB-Maemo-Display-Name-de_DE: Mein Packetname XB-Maemo-Upgrade-Description-de_DE: Formatiert wie "Description". Note how "Description" becomes "XB-Description-xx_YY" when a locale suffix is added. This is because it's not a standard Debian field any longer.

Debhelper 7
A backport of Debhelper 7 for Fremantle is available in extras-devel. It works transparently and can coexist with debhelper 5 in the SDK. It even works on the autobuilder, if the package specifies the correct build-dependency of. The following lines in  are necessary to use the new debhelper:

PATH:=/usr/bin/dh7:/usr/bin:$(PATH) export PATH SBOX_REDIRECT_IGNORE=/usr/bin/perl export SBOX_REDIRECT_IGNORE

Further information about the updated debhelper is available at User:Tanner.

If you also need a more recent CDBS, then use the package cdbs-dh7, which conflicts with the standard CDBS and does not work on autobuilder yet.

Alternatively, you can try to use debhelper 5. Debian packages that require level 7 need some changes, for example:
 * debian/compat: 7 -> 5
 * debian/control: Build-Depends: debhelper (>= 7) -> debhelper (>= 5)
 * Possibly, comment out a few dh_* calls from debian/rules, which might not exist on level 5

Things might get complex if the packaging already uses some new features of level 7, like CDBS-style helper rules. In such cases, looking at versions of packages written prior to the compatibility level upgrade might help doing the downgrade (and most Debian packages are kept in public SCMs like svn.debian.org).