Creating Debian packages on your own

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Construction Site

The powerful tools with which you can build Debian packages (also used in Ubuntu) are available to any user. You can even save time by compiling them by hand.

No distribution provides its users with more packages than Debian. This implies that it also needs a well-developed system for building packages. Like its counterparts on RPM-based systems, it automates both source code compiling and creating packages. This article introduces the Debian build system that creates Debian packages from a program's source code fully automatically. I will explain the powerful tools that are available and provide guidance on improving your distro.

Germ Cell

To use the Debian build system with Ubuntu, you first need to install the build-essential, debhelper, dh-make, quilt, fakeroot, and devscripts packages. Next, export two environmental variables with your email address and name as shown below. It's best to add these to your .bashrc.

export DEBMAIL="<e-mail_address>@<domain>.<tld>"
export DEBFULLNAME="<first_name> <last_name>"

Both Debian and Ubuntu have their source code in their own repositories that you can identify with the keyword deb-src at the beginning of the line in /etc/apt/sources.list. The source repositories are activated by default after installation. The apt-get source <name> command downloads the sources for the name package into the current directory.

Avoid working with root privileges, because you'll be using the <name>_<version>.orig.tar.gz, <name>_<version>.debian.tar.gz, and <name>_<version>.dsc files as a normal user for further processing. Also added to the named files are patches with the .diff.gz extension that clean up errors in the code.

The file with the .orig.tar.gz extension, however, is missing in packages that the Debian maintainers monitor themselves and that don't have an upstream entity. However, if the program's upstream maintainers have provided the sources as "Debianized" (which include a controlling debian/ subdirectory), the <name>_<version>.debian.tar.gz file will be missing.

Unpack the tarball with apt-get source into the <name>_<version> directory. If you have the Launchpad [1] Debian sources, use dpkg-source -x <name>_<version>.dsc instead for manual unpacking. Using dpkg-buildpackage -uc -us from the unpacked source directory is enough to compile the software and integrate it into a dpkg installable binary package. The first use of dpkg-buildpackage often requires installing more dev packages.

Another call after importing the dependencies should always end with a functioning Debian package for sources from the current distribution, as long as the basic system components (libraries and compiler) are in a deliverable state. It pays to test dpkg-buildpackage against a current Linux distribution to see if it returns a message of a successful build in the console window.

You should see a line such as: dpkg-deb: Package <named> is built in "../<name>_<version>_i386.deb" at the end of the console output.

Switching and Swapping

Building packages starts to make a lot of sense as soon as you start building packages that aren't available for installation on your own system. The ffDiaporama package [2], for example, is a program for creating multimedia presentations and isn't included in the Ubuntu 12.04 repositories. Ubuntu 12.10 and 13.04 has packages for the program with associated sources [3]. I was curious whether the Ubuntu 12.10 sources would also compile under Ubuntu 12.04. If not, I wouldn't be able to install the package from the Ubuntu version because of unsatisfiable dependencies.

As a general rule, the requirements for translating from the sources are much less restrictive than the binary requirements of a specifically tailored program. For example, there are no bindings to a certain architecture (i386 or x86_64). Even porting between Debian and Ubuntu and back often works smoothly, because of the fact the lion's share of Ubuntu packages come from the Debian "unstable" sources.

You can get the ffDiaporama sources from the Launchpad site [3] in the Packages in Distributions section (Figure 1). Under "ffdiaporama" source package in Quantal, you will find the ffdiaporama_1.3-1.dsc, ffdiaporama_1.3.orig.tar.gz, and ffdiaporama_1.3-1.debian.tar.gz files that you can download into a common directory. The dpkg-source -x ffdiaporama_1.3-1.dsc command unpacks the source archive, and dpkg-buildpackage -uc -us then builds a package tailored for Ubuntu 12.04 from the created ffdiaporama-1.3 directory. Because this is a rather large package, compiling can take some time.

Figure 1: Launchpad is specifically tailored to Ubuntu development. Almost all hosted projects have Debian sources and often binary packages.

Thus, two commands are all you need to build installable binary packages automatically on your current system. If the sources don't come from your distribution themselves, success is by no means guaranteed. Chances are the program developers didn't test their sources against existing libraries or compiler versions. However, non-system Debian sources often compile just as smoothly as with ffDiaporama.

You can always deinstall the resulting Debian packages if they don't work and replace them with the versions supplied by your distribution. The package manager prevents any overwriting of files from other packages, so you don't need to fear any damages if you install ordinary applications. However, swapping system components can be risky even with the package manager.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content