Yet another practical packaging session, this ine on how to build a Debian package from scratch. This one too is based on the packaging tutorial and practical sessions of Lucas Nussbaum.
We are going to download the source code of gnujump from upstream, and use the pbuilder tool to package it. The advantages of pbuider is that it creates a minimal chroot jail that helps you track any dependencies you might forgot to specify in debian/control. Also it gives you the opportunity to build Debian packages on Ubuntu and vice-versa. You can also build packages for releases other than your own.
Prerequisites
- A recent Debian or Ubuntu system.
Preparation of the pbuilder jail
Install pbuilder and relevant packages:
$ sudo apt-get -y install pbuilder debootstrap devscripts packaging-dev debian-keyring ubuntu-archive-keyring
NOTE: use ubuntu-keyring instead of ubuntu-archive-keyring if your build station is Ubuntu
Prepare the target environment. For example for Ubuntu trusty use can use this setup:
$ sudo pbuilder create --debootstrapopts --variant=buildd --mirror http://cy.archive.ubuntu.com/ubuntu --distribution trusty --architecture amd64 --components main --debbuildopts -mJohn Doe <john.doe@example.net>
Prepare the new package
- Download the source:
$ wget https://ftp.gnu.org/gnu/gnujump/gnujump-1.0.8.tar.gz
- Extract the archive and change into the source tree:
$ tar xvzf gnujump-1.0.8.tar.gz $ cd gnujump-1.0.8/
Prepare for debian packaging
- We are going to use the
dh_make
utility to prepare the debian directory and all the necessary files:$ DEBFULLNAME="John Doe" DEBEMAIL="john.doe@example.net" dh_make -s -y --createorig
Check if all necessary files are there:
$ find debian/ debian/ debian/compat debian/manpage.1.ex debian/preinst.ex debian/rules debian/gnujump.default.ex debian/README.Debian debian/copyright debian/gnujump.cron.d.ex debian/gnujump.doc-base.EX debian/changelog debian/README.source debian/control debian/menu.ex debian/manpage.sgml.ex debian/docs debian/init.d.ex debian/source debian/source/format debian/watch.ex debian/postrm.ex debian/prerm.ex debian/manpage.xml.ex debian/postinst.ex
Now Check the contents of the debian/changelog, debian/rules and debian/control files.
-
We will need to make some changes in the debian/control file:
Source: gnujump Section: games Priority: optional Maintainer: John Doe <john .doe@example.net> Build-Depends: debhelper (>= 9), autotools-dev, libsdl1.2-dev, libsdl-image1.2-dev, libsdl-mixer1.2-dev Standards-Version: 3.9.5 Homepage: http://gnujump.es.gnu.org ...
The libsdl1.2-dev, libsdl-image1.2-dev and libsdl-mixer1.2-dev have been discovered by repeatedly compiling and failing until you get it right. The you can use the
apt-cache search
andapt-file search
commands to discover the packages corresponding to the missing dependencies. -
Edit the debian/rules file to look like this:
DH_VERBOSE = 1 DPKG_EXPORT_BUILDFLAGS = 1 include /usr/share/dpkg/default.mk export DEB_BUILD_MAINT_OPTIONS = hardening=+all export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed %: dh $@ --with autotools-dev CFLAGS += -lm
- Edit the debian/changelog, with
dch -e
, to look like this:gnujump (1.0.8-1) unstable; urgency=low * Initial release -- John Doe</john><john .doe@example.net> Mon, 22 Jun 2015 17:41:22 +0300
Build the package
Run this command from the source tree:
$ pdebuild
Give your password when asked. pdebuild
will download and install all dependencies in the pbuilder jail and then build the package. Changes will be lost from the jail, the next time you use it but if all goes well, you should see these files under /var/cache/pbuilder/result:
$ ls -la /var/cache/pbuilder/result/
total 5776
drwxr-xr-x 2 root root 4096 Ιούν 22 17:52 .
drwxr-xr-x 9 root root 4096 Ιούν 22 11:26 ..
-rw-r--r-- 1 john john 1449 Ιούν 22 17:52 gnujump_1.0.8-1_amd64.changes
-rw-r--r-- 1 john john 1560574 Ιούν 22 17:52 <strong>gnujump_1.0.8-1_amd64.deb</strong>
-rw-rw-r-- 1 john john 9228 Ιούν 22 17:52 gnujump_1.0.8-1.debian.tar.xz
-rw-rw-r-- 1 john john 885 Ιούν 22 17:52 gnujump_1.0.8-1.dsc
-rw-rw-r-- 1 john john 2508641 Ιούλ 24 2012 gnujump_1.0.8.orig.tar.gz
-rw-rw-r-- 1 john john 1814056 Ιούν 22 17:41 gnujump_1.0.8.orig.tar.xz
Checking the result
- View the information related to the package file:
$ dpkg -I /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb new debian package, version 2.0. size 1560574 bytes: control archive=5550 bytes. 419 bytes, 11 lines control 18390 bytes, 233 lines md5sums Package: gnujump Version: 1.0.8-1 Architecture: amd64 Maintainer: John Doe </john><john .doe@example.net> Installed-Size: 2355 Depends: libc6 (>= 2.14), libgl1-mesa-glx | libgl1, libsdl-image1.2 (>= 1.2.10), libsdl-mixer1.2, libsdl1.2debian (>= 1.2.11) Section: games Priority: optional Homepage: http://gnujump.es.gnu.org Description: <insert up to 60 chars description> </insert><insert long description, indented with spaces>
As you can see our work is not finished. We need to add a description in debian/control and rebuild it.
- Check the contents of the package file:
$ dpkg -I /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb
Install the package
Now we can install the package:
$ sudo dpkg -i /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb
Now run the gnujump
software and check if it works.
This is not the whole story of course. You have to check the package against Lintian to see if it complies with the Debian Policy. And if it’s not compliant, you may need to use Quilt to patch it. You will need to fill debian/watch so you can track updates on the upstream with uscan
. The work of a Debian packager never ends.
References
- https://wiki.ubuntu.com/PbuilderHowto
- https://www.debian.org/doc/manuals/packaging-tutorial/packaging-tutorial.en.pdf</insert></john>