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.
Only for files are really needed
debian/controlcontains 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/copyrightcontains information about upstream.
debian/changelogcontains the changelog for the package (not upstream). The format must be strictly followed, the easiest way of doing that is to use
dch --createwill create the file with the first entry.
debian/rulesis at the heart of packaging.
All of them are well described in Miriam’s document, but I have some thoughts on the last one.
This file is a makefile with three required targets:
clean– Cleans up the build area, both for the source and the stuff generated in
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
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.