Building modified debian packages

I recently had to create modified versions of some debian packages, to apply some custom patches and use some special compilation options for a scratchbox environment. It was time that I learnt something about actually making debian packages. These were packages that Daniel Holbach couldn’t do for me, but he did explain some stuff, which I’ll note here for my reference. He’s not to blame for my errors.

To get existing debian package stuff, make a directory and do this:

This gives you 3 files, of these types:

  • .orig.tar.gz: The original source tarball, exactly as you would get it if you downloaded the source code directly.
  • .dsc: The Debian Source Control file.
  • .diff.gz: A patch to add the debian sub-directory.

You don’t need to uncompress and apply all that manually. There are tools to help:

  • dpkg-source -x something.dsc, to expand the source tarball and apply the .diff.gz patch. You then have the source directory, with the debian sub-directory inside. If you did apt-get source then this has been done for you already.
  • cd into the source directory.
  • Do debuild (or debuild -us -uc to avoid the GPG signing). This builds the package, by reading information from the debian sub-directory, building the source, and putting it all in .debs in the parent directory.
    (On scratchbox, where debuild does not work due to fakeroot problems, do dpkg-buildpackage -rfakeroot -sa)

That should confirm that you can actually build the packages. If you are missing some dependencies, try “apt-get build-dep yourpackagname”.

Now you might want to change some things before building the packages again. For instance:

  • Using a newer source tarball release:
    • Get the source tarball of the latest release.
    • Rename it to match the debian convention. For instance:
      mv gconfmm-2.14.1.tar.gz gconfmm2.6_2.14.1.orig.tar.gz
    • Unpack the new tarball.
    • Copy the debian directory from the old source directory to the new one.
    • cd to the new source directory.
    • Do dch -i to edit debian/changelog with the editor. Export EDITOR=editoryoulike if you don’t like vi.
    • Change the version number in the new changelog entry. debuild/dpkg-buildpackge actually uses the version number in the changelog for the version number of the debian packages.
  • Changing dependencies:
  • Using special compiler options, or configure options:
    • Edit debian/rules and edit the appropriate makefile rule. Try to use a makefile variable, to keep things simple. Some debian/rules files already use CFLAGS or CXXFLAGS variables.
  • Apply patches:
    • Some debian/rules files have makefile rules to automatically apply any .patch files. If yours does then just add the .patch file in appropriate place. Otherwise, just apply the patch manually and store it in a debian/patches_applied/ directory.

After you have changed the sources and the debian files appropriately, debuild (or dpkg-buildpackage – see above), should build the packages again, putting them in the parent directory. It will even create the .dsc and .diff.gz files, completing the circle.

6 thoughts on “Building modified debian packages

  1. Really nice quickstart tutorial.

    A small note though: When packaging a new upstream release you can just do uupdate in the current source directory. uupdate will automatically produce a new directory with the debian directory and the correct version so that dch -i knows reliably which version to pick next.

    In most Debian packages nowdays there’s also a debian/watch file which describes under which URL new upstream releases can be found. In this case you just have to run uscan to download the new release. uupdate will be called automatically.

  2. Good concise summary. One point, I don’t think you need to have uid=0 for dpkg-source, just debuild/dpkg-buildpackage.

    I’m not familiar with the new stuff that is being developed for Fedora which simulates some of this stuff: perhaps a follow-up article in the same vein? :)

  3. Thanks!

    was looking at how to build custom deb packages, but information was a bit scarce or too technical too really understand what i needed to do, but your little guide helped me heaps :)

  4. I just corrected the “apt-get install build-dep yourpackagname” in this post to “apt-get build-dep yourpackagname”. It’s surprising that nobody mentioned it until now.

  5. Thanks for this deb re-packaging guide! a life saver! just a small nitpicks I encountered while using it to repackage/backport nginx-1.3.9 for debian 6 (squeeze):

    – Needed to apt-get install devscripts to obtaing debuild, debsign, and so on.
    – I got the following error:
    dpkg-source error can't build with source format '3.0 (quilt)' no orig.tar file found

    I solved it by just adding the -b switch to debuild command, so my debuild command was:
    debuild -b -us -uc -sa


Comments are closed.