Debian package from scratch

Since I’ve re-joined the mothership (I recently moved back to Debian (Sid) after about a year using Ubuntu and a couple of months using ArchLinux) I thought it’d be a good time to do that one thing that’s been on my todo-list for years now–grok Debian package building.

I’ve built a few packages over the years but I’ve never really understood the magic of debian/rules. For my first package I used debhelper, then I discovered CDBS. Both of these systems (especially CDBS) are great, but I never really understood what was going on. I came across a tutorial on building a Debian package without debhelper a while ago and ever since I’ve been planning to reading it. It turns out Miriam Ruiz has made an excellent job in explaining how to package. This post reflects my current understanding of Debian packaging.

###The basics

Only for files are really needed

  1. debian/control contains source and package information such as dependencies and a description of the package. It’s handy to use that package names defined in this file as install directories for the actual packages when building, e.g. build the package foo in debian/foo/.
  2. debian/copyright contains information about upstream.
  3. debian/changelog contains the changelog for the package (not upstream). The format must be strictly followed, the easiest way of doing that is to use dch. dch --create will create the file with the first entry.
  4. debian/rules is at the heart of packaging.

All of them are well described in Miriam’s document, but I have some thoughts on the last one.

###The rules

This file is a makefile with three required targets:

  • clean - Cleans up the build area, both for the source and the stuff generated in debian/.
  • build - Build the software
  • binary-arch - Create packages for architecture specific parts, e.g. binary executables and libraries.
  • binary-indep - Create packages for architecture independent parts, e.g. documentation.
  • binary - This is often an empty target that depends on the two previous ones.

*-stamp targets are used to make sure things happen in the right order. Everything else is convenience, really.

###Where to put things

The upstream source is installed, by convention in debian/<package name> (or debian/tmp). Package control files go in debian/<package name>/DEBIAN. The very last step of packaging is to create the package itself by calling dpkg --build (or dpkg-deb -b).


Miriam has made a conscious choice to leave Debhelper out of her document. I think this is wise. However, I think any packager would benefit from getting familiar with the d_* commands. They aren’t very easy to use, and though their manpages are well written they don’t contain any expamples. Luckily there’s a load of examples in Debian’s source repos. Debhelper’s dh_make is also an excellent way of learning-by-example.

Leave a comment