How to build a Debian package v2.0
A few months ago, I wrote a post with a brief guide to create a Debian package.
As you will know, I’ve released DeTraS 0.5.0 recently, and I’ve been messing around with packaging again. I remember that packaging DeTraS 0.4.2 was a pain in the neck, specially because I had some troubles to upload a working version of the package to my PPA, so this time I’ve been playing with some other utilities to make it easier.
In first place, I still recommend you to read Debian New Maintainers’ Guide. It will help you to understand what is going on the process of creating a Debian package. Anyway, this time I have an additional guide for you. In my opinion it is another must if you want to build Debian packages, because it has a lot of information, it is easy to read and it is updated. I’m talking about the Complete Packaging Guide on Ubuntu Wiki.
Another topic of the former post was chroot. I still encourage you to use chroot, but instead of using it directly as I did in the past, I highly recommend you to employ pbuilder to handle your chroot.
Pbuilder provides a clean environment where you can build Debian packages just based on dependencies you have set on your package. Isn’t that what chroot provides? Not really, because when you create a chroot manually you have to install needed packages by yourself, leading to a dirty installation, where you will have extra packages, maybe including some dependencies you haven’t set on your package. In this case, you will be able to build your package on your chroot, but not outside it. Using pbuilder you will avoid this problem, because every time you build a package using it, it will install needed dependencies for your package and it will clean your chroot after built to keep a minimal installation. A good guide to use pbuilder is Pbuilder Howto on Ubuntu Wiki.
After all this information, we can start building a package:
Build a source package
This option will provide you a base to build a binary package on your system or in a repository. Follow these steps to generate a source package:
- Given a tarball of the program you want to create a package, uncompress it and go to its root directory.
- If you are using autotools to generate your configuration script and Makefile, execute:
- Now run:
dh_make -f ../<tarball-package>
to generate an orig.tar.gz file and skeleton of needed files to build your package.
- Modify files under debian directory as Debian New Maintainers’ Guide and Complete Packaging Guide recommend.
- Once you are ready, generate the package by executing:
Build a binary (deb) package
The following steps will generate Debian packages for your application:
- In most of the cases, if it’s the first time you use pbuilder, you will want to have multiple pbuilders for different distributions or architectures. Here is the method I have followed to achieve this behaviour.
- Create your pbuilder executing this command:
sudo DIST=karmic ARCH=i386 pbuilder create
As you can see, you can specify distribution and architecture of your pbuilder (Ubuntu Karmic on a i386 machine on this example). If you followed instructions on previous step, you can create several pbuilder for diferent distros and architectures. You only need to do this step the first time you use pbuilder. If you have already created a pbuilder, you should update it before building (see step 5).
- Now it’s time to build your package by executing:
sudo DIST=karmic ARCH=i386 pbuilder build <package>_<version>.dsc
- If everything goes right, you can get resulting packages on /var/cache/pbuilder/<distribution>-<architecture>.
- If you want to update your pbuilder environment, all you have to do is to execute
sudo DIST=karmic ARCH=i386 pbuilder update
That’s all for now. I hope you find this guide useful😉
Filed under: Tutorials | 1 Comment