While rebuilding packages from their sources usually falls under administration tasks, also the average GNU/Linux user can certainly profit from it. The main advantage of a libre operating system is the control every user has on the software. A typical situation when this is much relevant is the case of a bug in a software released with the operating system. Debian provides easy access to the source files and complete tools to rebuild a package from scratch. We first provide an executive summary, and then describe a typical example where a bug is fixed by applying a patch.
Excellent references are the Debian manual and the Debian Administrator's Handbook.
We take a bug in the emacs24 Debian package as typical example. The well known program is part of the GNU operating system, and the source code is of course available. A bug report for the version 24.5+1-6+b2 as been filed (the problem concerns missing toolbar icons, but it is irrelevant here). Fortunately, the bug report also provides a patch that can easily be applied to emacs source files. Such patches are not guaranteed to solve completely the problem or to function properly in all cases, but it is easy to revert the modified packages.
$ apt-cache show emacs24 Package: emacs24 Source: emacs24 (24.5+1-6) Version: 24.5+1-6+b2 [...]
$ cd Sources/emacs/ $ apt-get source emacs24 $ ls emacs24-24.5+1 emacs24_24.5+1-6.dsc emacs24_24.5+1-6.debian.tar.xz emacs24_24.5+1.orig.tar.bz2We can access the source directory:
$ cd emacs24-24.5+1/The next step is to change version. It is useful to give priority to the modified version over the one available on Debian repositories already at this point, choosing an appropriate label. Here we choose the label +fm (my initials):
$ dch --local '+fm'The new version 24.5+1-6+fm1 to be created has priority over the bugged 24.5+1-6+b2, because b precedes f alphabetically. If the new label does not give priority to the version, it is always possible to pin a particular package in /etc/apt/preferences (see man 5 apt_preferences).
emacs24 (24.5+1-6+fm1) UNRELEASED; urgency=medium * Fix missing toolbar icons -- Francesco Montanari <email@example.com> Tue, 26 Jul 2016 12:13:03 +0300 [...]
$ patch -p1 < fix-missing-icons.patchThe argument -p1 (of the generic -p[num] option, see man 1 patch) is necessary because the format of the patch is:
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.elhence we want to skip the first directory (a/ or b/), which is present only for illustrative purposes.
$ cp debian/patches/0020-Handle-deprecated-Gtk-stuff-for-version-3.10.patch ./tmp.patch $ patch -p1 < tmp.patchNow that the changes are applied, remove the temporary unnecessary files (or move them somewhere else), so that they will not be identified as new source files:
$ rm fix-missing-icons.patch tmp.patch
# apt-get build-dep emacs24Keep track of the newly installed packages to remove them later, e.g., by saving the package names on a temporary file (or find them with apt-cache showsrc emacs24).
$ dpkg-buildpackage -us -ucThe re-built packages are available in the folder from where the sources were downloaded:
$ ls ../*.deb emacs24_24.5+1-6+fm1_amd64.deb emacs24-bin-common_24.5+1-6+fm1_amd64.deb emacs24-bin-common-dbgsym_24.5+1-6+fm1_amd64.deb emacs24-common_24.5+1-6+fm1_all.deb emacs24-dbg_24.5+1-6+fm1_amd64.deb emacs24-el_24.5+1-6+fm1_all.deb emacs24-lucid_24.5+1-6+fm1_amd64.deb emacs24-lucid-dbg_24.5+1-6+fm1_amd64.deb emacs24-nox_24.5+1-6+fm1_amd64.deb emacs24-nox-dbg_24.5+1-6+fm1_amd64.debNote the new version +fm1, which acquire priority over the version downloaded from the Debian repositories and can then be installed with dpkg. Due to dependencies problems, in this case it was necessary to fix the broken packages before installing the new ones:
# dpkg -i ../*.deb # apt full-upgrade # dpkg -i ../*.deb # dpkg -i ../emacs24_24.5+1-6+fm1_amd64.deb
$ apt-cache policy emacs24 emacs24: Installed: 24.5+1-6+fm1 Candidate: 24.5+1-6+fm1 Version table: *** 24.5+1-6+fm1 100 100 /var/lib/dpkg/status 24.5+1-6+b2 900 -10 http://ftp.fi.debian.org/debian unstable/main amd64 Packages 900 http://ftp.fi.debian.org/debian stretch/main amd64 Packages 24.4+1-5 -10 -10 http://ftp.fi.debian.org/debian jessie/main amd64 Packages
Back to top