Why package for Debian?
This Debian wiki page has some good points listed about why use Linux and Debian.
Aside from the philosophy and community aspects of Debian, an important factor for wanting to package for Debian is the huge amount of derivative distributions based on Debian (120+). Once you’ve packaged your software in Debian, it will automatically trickle down to all those distributions in their next versions. Instead of packaging a piece of software just for Ubuntu (for instance), you could package it for Debian and have all those other distributions (and ultimately potential users) have access to your software right from their package manager.
Another important fact is that due to the high quality standards promoted by the Debian project, getting your package right in Debian means you’ve done a quality job!
What do you need?
In order to package a program for Debian we will need the following:
- An installation of Debian Sid (the “unstable” version) [in VirtualBox]
- A program to package: GNU Hello
Preparation of the package
Download and extract the program:
mkdir -p devel/hello-deb cd devel/hello-deb/ wget http://ftp.gnu.org/gnu/hello/hello-2.7.tar.gz tar xvzf hello-2.7.tar.gz
Run ./configure and resolve any encountered problems (like missing packages), then build and test the program out:
./configure make ./src/hello
If the program runs properly, then we can start building the Debian package!
Building the package
Preparation of the build environment
The following list of packages are needed to build:
sudo aptitude install build-essential autoconf automake autotools-dev debhelper dh-make devscripts fakeroot gnupg lintian patch patchutils pbuilder quilt
Then, unzip the program again:
cd .. rm -rf hello-2.7 tar xvzf hello-2.7.tar.gz cd hello-2.7/
Set up dh_make:
$ cat >>~/.bashrc <<EOF DEBEMAIL="email@example.com" DEBFULLNAME="Firstname Lastname" export DEBEMAIL DEBFULLNAME EOF $ . ~/.bashrc
Now run the following command to start creating the Debian package:
dh_make -f ../hello-2.7.tar.gz
Select a type of package of single binary. This execution of dh_make creates a copy of the upstream tarball as hello_2.7.orig.tar.gz in the parent directory that will be uploaded to the Debian archive.
Editing debian/* files
From this point on we’ll edit files that are located in the ./debian directory. The previous call of dh_make has created a bunch of template files in the ./debian directory, if you are building a new package you would use those as examples. However, in order to speed up this presentation, I’ll use the files that are used to create the actual hello package in Debian.
The following 4 files are required in order to be able to build the package. Edit them to the adequate values.
This file contains various values which dpkg, dselect, apt-get, apt-cache, aptitude, and other package management tools will use to manage the package. More details.
This file contains information about the copyright and license of the upstream sources. More details.
This file’s format is used by dpkg and other programs to obtain the version number, revision, distribution, and urgency of your package. It is also really useful to have all changes that have been made to that package properly documented. More details.
This file contains the rules which dpkg-buildpackage will use to actually create the package. This file is in fact another Makefile, but different from the one(s) in the upstream source. Unlike other files in debian, this one is marked as executable. The default file sometimes needs to be adapted if you need to do some fancy stuff. Have a look at the DNMG for more details.
The watch file configures the uscan program to watch the site where you originally got the source from to determine if a new version has been released. It can also be configured to download the new tarball and unpack it, add the debian folder from the previous version so that you’re ready to package that new version. More details.
If there are files that need to be installed into your package but your standard make install won’t do it (would be the case if there is no Makefile made available by upstream for your package), put the filenames and destinations into this install file. They are installed by dh_install. You should first check there is not a more specific tool to use. For example, documents should be in the docs file and not in this one. More details.
The quilt command records modifications to the source as a stack of -p1 patch files in the debian/patches/ directory and the source tree is untouched outside of the debian directory. The order of these patches is recorded in the debian/patches/series file. Chapter 3, Modifying the source of the DNMG has more details on the process of patching the upstream source.
Every binary in Debian should have a man page explaining the commands and providing general help with the package. There are various formats available to create that manpage: nroff, SGML, XML. More details.
These postinst, preinst, postrm, and prerm files are called maintainer scripts. They are scripts which are run by dpkg when your package is installed, upgraded, or removed. As a novice maintainer, you should avoid any manual editing of maintainer scripts because they can be problematic. More details.
Build the package
To build without package signing, execute this command:
dpkg-buildpackage -us -uc
The following files have been created in the parent directory:
You can automate the dpkg-buildpackage command’s package build process further with the debuild command (DNMG section). For a clean room (chroot) build environment to verify the build dependencies, the pbuilder package is very useful. (DNMG section)
Testing the package
The previous build commands has created several files in the top level, one of which being the actual .deb package. You should first off review the list of files that are included in the package:
Then, install the newly created package:
sudo dpkg -i hello_2.7-1_i386.deb
Running the hello command should now work properly!
Once you’ve got your package ready, since we are [not yet?] official Debian Maintainers (DM) or Debian Developers (DD), we will need to find a mentor to upload our package to the official Debian repository. Head over to mentors.debian.net to learn more about the sponsorship process. The DNMG also has useful information about uploading.
The following pages contain useful information if you wish to do some packaging yourself!