Packaging binaries as .deb
¶
To package binaries produced by source code as a .deb
file, the build system must be adapted
to generate a .deb
instead of raw binaries. This is achieved by using a Debian build tool,
such as dpkg-buildpackage
, to build the source code instead of the original build system.
The dpkg-buildpackage
tool acts as a wrapper around the original build system and relies on
a debian/
folder in the root directory of the source code. This folder contains metadata and
configuration files required to produce .deb
files. These tools utilize this information to
organize the binaries generated by the original build system into one or more .deb
files in
a standardized format.
Steps to package binaries as .deb
¶
Download the upstream source as a tarball:
wget http://www.example.org/download/debhello-0.0.tar.gz
Rename the tarball to
<source_package>_<upstream_version>.orig.tar.gz
(e.g.,debhello_0.0.orig.tar.gz
).Untar the tarball:
tar -xzmf debhello_0.0.orig.tar.gz
Rename the untarred directory to
<source_package>-<upstream_version>
(e.g.,debhello-0.0
).Install the
debmake
tool:sudo apt install debmake
Generate the
debian/
folder.Switch to the directory (e.g.,
debhello-0.0
) and rundebmake
, this creates thedebian/
folder:cd debhello-0.0 debmake
Customize the
debian/
folder.The
debian/
directory must now include templates for essential files. Among those are:debian/control
: Metadata about the package, such as its name, section, description, dependencies, and maintainer. See the Debian Policy Manual: Control Files for detailed information.debian/copyright
: Copyright details of the package. By default,debmake
creates it in the DEP-5 format.debian/rules
: A Makefile-style script specifying how to build the package. For more details, see Customizing debian/rules.debian/changelog
: History of changes to the package. This can be edited manually or with thedch
tool. After installation, it is stored at/usr/share/doc/<package>/changelog.Debian.gz
.
Customize the above files and remove unused ones to match your package requirements. A minimal
debian/
could look like:debian/ ├── changelog ├── control ├── copyright ├── gbp.conf ├── rules* ├── source/ │ └── format ├── tests/ │ └── control └── watch
Build the package.
Run the following commands to build the package locally:
dpkg-buildpackage
To skip signing the package, use:
dpkg-buildpackage -us -uc
For instructions on building for a PPA, see Upload to a PPA instead.
Customizing debian/rules
¶
The dpkg-buildpackage
command uses the debian/rules
file to build .deb
packages. This
file can be as simple as:
#!/usr/bin/make -f
#export DH_VERBOSE = 1
%:
dh $@
The dh
commands belong to the debhelper
suite, which automates common packaging tasks.
For more information, see the debhelper manual. Debhelper attempts to
detect the build system (e.g., Autotools, CMake, Python setup.py
, etc.) based on source files
and configures the build steps accordingly.
If autodetection fails, specific steps can be overridden in debian/rules
, e.g.:
override_dh_auto_configure:
./configure --prefix=/usr --enable-feature
override_dh_auto_build:
make -j4