Debian offers a clean way to recompile packages with different options. This guide will show how to recompile a source-package, in this example Samba, in order to enable avahi.
apt-get install build-essential fakeroot dpkg-dev devscripts
The following commands will download the Samba source and install the necessary development packages that are necessary to compile Samba. The development packages may be deleted later.
apt-get source samba apt-get build-dep samba
In some instances, you will need to retrieve a certain version of the source. You can do that by appending the equal sign and the version to fetch. For instance, if you were to want to download Samba 3.5.6, you would issue:
apt-get source samba=3.5.6
The different versions can be found using:
apt-cache policy samba
To make changes, simply change directory to the source package and then to the debian
folder.
cd samba-3.5.6~dfsg/debian/
The debian
folder inside the source directory contains the build-scripts that build the package. One interesting file, for example, is the rules
file. We edit that file and change –disable-avahi
to –enable-avahi
as in the example below:
... --enable-external-libtalloc \ --without-libtalloc \ --enable-avahi ifeq ($(DEB_HOST_ARCH_OS),linux) conf_args += \ ...
After installing the package later, if we run the upgrade command, Debian will want to replace the package with a package from the official repository. One way around this, aside from creating your own repository, is to append a tag to the package version. This will give the package a higher priority for the current package as well as allow upgrades from the official repositories when the package maintainer pushes a new release.
In order to append a minor version, we first change directory to the source directory using:
cd samba-3.5.6~dfsg/
and then use dch
(can be installed with aptitude install devscripts
) and issue:
dch -i
which will increment the version number.
A different method, would be to issue:
dch --local me
where me
is a name to tag the version with - that way it is easy to differentiate between an official package and your package.
To recompile the package, while being in the source directory, we issue:
dpkg-buildpackage -rfakeroot -b
This will build the package and place deb
files on the upper-level directory (cd ../
). When packages with multiple components are compiled, this will generate multiple deb
files.
Check which packages you have installed, for example:
aptitude search samba
and then install the replacement deb
files:
dpkg -i samba_3.5.6~dfsg-3squeeze9-local1_amd64.deb samba-common_3.5.6~dfsg-3squeeze9-local1_all.deb samba-common-bin_3.5.6~dfsg-3squeeze9-local1_amd64.deb