This tutorial walks you through patching an existing Debian package. It is useful if you want to create a
.deb of a package after fixing some bug or modifying the source in any other way. We will
hugin as our example.
We start by fetching the source package
$ apt-get source hugin
$ cd hugin-2017.0.0+dfsg
We will need a tool named
quilt to make the process easier.
# apt install quilt
quilt we want to make it aware of the
debian/patches directory which holds the patches. Adding the following lines to
~/.quiltrc will make quilt search up the directory tree the
d=. ; while [ ! -d $d/debian -a `readlink -e $d` != / ]; do d=$d/..; done
if [ -d $d/debian ] && [ -z $QUILT_PATCHES ]; then
# if in Debian packaging tree with unset $QUILT_PATCHES
QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto"
QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches; fi
Now starts the actual patching process. The patches are applies in series, and our new patch should be the last one. We start by applying any existing patches, and then creating a new patch
$ quilt push -a
$ quilt new 44_setlocale.patch
I chose the
44_ prefix because
hugin already has a patch named
43_fallbackhelp.patch and the convention is naming patches so the names reflect the order they are applied. Next we specify to
quilt which files we modify and then we edit them.
$ quilt add src/hugin1/hugin/huginApp.cpp
$ vim src/hugin1/hugin/huginApp.cpp
Alternatively, instead of editing the files manually,
quilt import can be used to import an existing patch.
Each patch comes with its own metadata to let other people know who wrote it and what it does. Use
$ quilt header --dep3 -e
to edit this metadata. For example:
Description: Call setlocale()
This fixes a bug in wxExecute, see https://trac.wxwidgets.org/ticket/16206
The patch has been submitted to upstream, https://groups.google.com/d/msg/hugin-ptx/FCi7ykPDZ5E/3w8E5U1SCQAJ
Author: Guy Rutenberg <email@example.com>
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
See [DEP-3](http://dep.debian.net/deps/dep3/) for more details about the different fields.
After we finish editing we finalize the patch, and unapply all the patches
$ quilt refresh
$ quilt pop -a
Now, you can continue to build the
deb from source as usual. We use
debchange to create a new version, and
debuild to build the package. After the package is build it can be installed using
$ DEBEMAIL="Guy Rutenberg <firstname.lastname@example.org>" debchange --nmu
$ debuild -us -uc -i -I -j7