Caution
The Packaging and Development guide is currently undergoing a major overhaul to bring it up to date. The current state you are seeing now is a preview of this effort.
The current version is unstable (changing URLs can occur at any time) and most content is not in properly reviewed yet. Proceed with caution and be aware of technical inaccuracies.
If you are an experienced packager and would like to contribute, we would love for you to be involved! See our contribution page for details of how to join in.
Basic overview of the debian/ directory¶
This article will briefly explain the different files important to the packaging
of Ubuntu packages which are contained in the debian/ directory. The
most important of them are debian/changelog, debian/control,
debian/copyright, and debian/rules. These are required for all
packages. A number of additional files in the debian/ directory may be
used in order to customise and configure the behaviour of the package. Some of
these files are discussed in this article, but this is not meant to be a
complete list.
The changelog file¶
This file is a listing of the changes made in each version. It has a specific
format that gives the package name, version, distribution changes, and who made
the changes at a given time. The following is a template
debian/changelog:
package (version) distribution; urgency=urgency
[optional blank line(s), stripped]
* change details
- more change details
* even more change details
[optional blank line(s), stripped]
-- maintainer name <email address>[two spaces] date
package and version are the source package name and version number,
respectively.
The distribution field lists the distribution(s) in which this release
should be installed.
urgency describes how important an upgrade is. Its value can be one of the
following: low, medium, high, emergency, or critical.
The change details consist of lines indented by at least two spaces, but these conventionally are a list. Major bullet points use an asterisk “*”, while minor bullet points are indicated by a dash “-“.
The changelog entry ends with a line indented by one space that contains the name, email of the maintainer, and date of change. The maintainer here is the one responsible for the release, but it need not be the package maintainer.
Note
If you have a signing key (see
Getting set up), then make sure to use the
same name and email address in debian/changelog entry as you have in
your key.
Important
The date should be in RFC 5322 format, which can be obtained by using the
command date -R. For convenience, the command dch may
be used to edit the changelog. It will update the date automatically. For
further information, see dch(1).
If you are packaging from scratch, dch --create (dch is in
the devscripts package) will create a standard debian/changelog for
you.
Here is a sample debian/changelog file for hello:
hello (2.8-0ubuntu1) trusty; urgency=low
* New upstream release with lots of bug fixes and feature improvements.
-- Jane Doe <[email protected]> Thu, 21 Oct 2013 11:12:00 -0400
Notice that the version has a -0ubuntu1 appended to it, this is the
distribution revision, used so that the package can be updated (to fix bugs for
example) with new uploads within the same source release version.
Ubuntu and Debian have slightly different package versioning schemes to avoid
conflicting packages with the same source version. If a Debian package has been
changed in Ubuntu, it has ubuntuX (where X is the Ubuntu revision
number) appended to the end of the Debian version. So if the Debian hello
2.6-1 package was changed by Ubuntu, the version string would be
2.6-1ubuntu1. If a package for the application does not exist in Debian,
then the Debian revision is 0 (e.g. 2.6-0ubuntu1).
For further information, see the changelog section (Section 4.4) of the Debian Policy Manual.
The control file¶
The debian/control file contains the information that the
package manager (such as APT) uses, build-time
dependencies, maintainer information, and much more. The file consists of one
or more stanzas of fields, with each stanza separated by empty lines. The fields
consist of key-value pairs separated by a colon “:”; conventionally, a single
space follows the colon.
For the Ubuntu hello package, the debian/control file looks
something like this:
Source: hello
Section: devel
Priority: optional
Maintainer: Ubuntu Developers <[email protected]>
XSBC-Original-Maintainer: Jane Doe <[email protected]>
Standards-Version: 4.6.2
Build-Depends: debhelper-compat (= 13), help2man, texinfo
Homepage: https://www.gnu.org/software/hello/
Package: hello
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: The classic greeting, and a good example
The GNU hello program produces a familiar, friendly greeting. It
allows non-programmers to use a classic computer science tool which
would otherwise be unavailable to them. Seriously, though: this is
an example of how to do a Debian package. It is the Debian version of
the GNU Project's `hello world' program (which is itself an example
for the GNU Project).
The first stanza describes the source package. It contains the following fields:
Source(required): The name of the source package.Maintainer(required): The name and email of the package maintainer.
Note
In Ubuntu, we set the Maintainer field to a general address
because anyone can change any package (this differs from Debian where
changing packages is usually restricted to an individual or a team).
Packages in Ubuntu should generally have the Maintainer field set to
Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>. If the
Maintainer field is modified, the old value should be saved in the
XSBC-Original-Maintainer field. This can be done automatically with the
update-maintainer script available in the ubuntu-dev-tools package.
For further information, see the
Debian Maintainer Field spec on the Ubuntu wiki.
Uploaders: The list of names and email addresses of co-maintainers.Section(recommended): The application area into which the package has been classified.Priority(recommended): How important the package is.Build-Dependsfields: Lists the packages required to build the package from source. For a full list of theStandards-Version(required): The version of Debian Policy that the package complies with.Homepage: The upstream home page.Version Control System fields:
VCS-Browser: Web interface to browse the repository.VCS-<type>: The repository location. See Version Control System fields (Section 5.6.26) of the Debian Policy Manual for more details.
Testsuite: A comma-separated list of values allowing test execution environments to discover packages which provide tests.Rules-Requires-Root: Defines whether the source package requires root access during selected targets.
Each additional stanza describes a binary package to be built. These stanzas contain the following fields:
Package(required): The name of the binary package.Architecture(required): The architectures supported.Section(recommended): The application area into which the package has been classified.Priority(recommended): How important the package is.Essential: Optional boolean field to prevent the package manager from removing the package when set toyes. When this field is absent, the default behaviour isno.Dependsfields:Description(required): Contains a description of the binary package. This field consists of a synopsis and a long description.Homepage: The upstream home page.Built-Using: This field is used in cases where the package incorporates parts of other packages and relies on specific versions.Package-Type: Indicates the type of the package, for example:deborudeb.
For further information, see the control file section (Chapter 5) of the Debian Policy Manual.
The copyright file¶
This file gives the copyright information for both the
upstream source and the packaging. Ubuntu and
Debian Policy (Section 12.5) require that each package
installs a verbatim copy of its copyright and license information to
/usr/share/doc/$(package_name)/copyright.
Generally, copyright information is found in the COPYING file in the
program’s source directory. This file should include such information as the
names of the author and the packager, the URL from which the source came, a
copyright line with the year and copyright holder, and the text of the copyright
itself. An example template would be:
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Hello
Source: ftp://ftp.example.com/pub/games
Files: *
Copyright: Copyright 1998 John Doe <[email protected]>
License: GPL-2+
Files: debian/*
Copyright: Copyright 1998 Jane Doe <[email protected]>
License: GPL-2+
License: GPL-2+
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
.
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more
details.
.
You should have received a copy of the GNU General Public
License along with this package; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA
.
On Debian systems, the full text of the GNU General Public
License version 2 can be found in the file
`/usr/share/common-licenses/GPL-2'.
This example follows the Machine-readable debian/copyright format. You are encouraged to use this format as well.
The rules file¶
The debian/rules file does all the work for creating our package. It is
a Makefile with targets to compile and install the application, then create the
.deb file from the installed files. It also has a target to clean up all
the build files so you end up with just a source package again.
More specifically, the debian/rules file has the following targets:
build(required)This target configures and compiles the package.
build-arch(required),build-indep(required)The
build-archtarget configures and compiles architecture-dependent binary packages (distinguished by not having theallvalue in theArchitecturefield).The
build-indeptarget configures and compiles architecture-independent binary packages (distinguished by theallvalue for theArchitecturefield).binary(required),binary-arch(required),binary-indep(required)The
binarytarget is all that the user needs to build the binary package(s) from the source package. It is typically an empty target that depends on its two parts,binary-archandbinary-indep.The
binary-archtarget builds the binary packages which are architecture-dependent.The
binary-indeptarget builds the binary packages which are architecture-independent.clean(required)This target undoes the effects of the
buildandbinarytargets, but it does not affect output files that abinarytarget creates in the parent directory.patch(optional)This target prepares the source for editing. For example, it may unpack additional upstream archives, apply patches, etc.
Here is a simplified version of the debian/rules file created by
dh_make (which can be found in the dh-make package):
#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@
Let us go through this file in some detail. What this does is pass every build
target that debian/rules is called with as an argument to
/usr/bin/dh, which itself will call the necessary dh_* commands.
dh runs a sequence of debhelper commands. The supported sequences correspond
to the targets of a debian/rules file: build, clean,
install, binary-arch, binary-indep, and binary. In order to see
what commands are run in each target, run:
dh binary-arch --no-act
Commands in the binary-indep sequence are passed the “-i” option to ensure
they only work on binary independent packages, and commands in the binary-arch
sequences are passed the “-a” option to ensure they only work on architecture
dependent packages.
Each debhelper command will record when it’s successfully run in
debian/package.debhelper.log (which dh_clean deletes). So dh can
tell which commands have already been run, for which packages, and skip running
those commands again.
Each time dh is run, it examines the log, and finds the last logged command
that is in the specified sequence. It then continues with the next command in
the sequence. The --until, --before, --after, and --remaining
options can override this behaviour.
If debian/rules contains a target with a name like
override_dh_command, then when it gets to that command in the sequence,
dh will run that target from the rules file, rather than running the actual
command. The override target can then run the command with additional options,
or run entirely different commands instead.
Note
To use the override feature, you should Build-Depend on debhelper
version 7.0.50 or above.
Have a look at /usr/share/doc/debhelper/examples/ and dh(1)
for more examples. Also see the rules section (Section 4.9)
of the Debian Policy Manual.
Additional files¶
The install file¶
The install file is used by dh_install to install files into the
binary package. It has two standard use cases:
To install files into your package that are not handled by the upstream build system
Splitting a single large source package into multiple binary packages.
In the first case, the install file should have one line per file
installed, specifying both the file and the installation directory. For example,
the following install file would install the script foo in the
source package’s root directory to usr/bin and a desktop file in the
debian directory to usr/share/applications:
foo usr/bin
debian/bar.desktop usr/share/applications
When a source package is producing multiple binary packages dh will install
the files into debian/tmp rather than directly into
debian/<package>. Files installed into debian/tmp can then be
moved into separate binary packages using multiple $package_name.install
files. This is often done to split large amounts of architecture independent
data out of architecture dependent packages and into Architecture: all
packages. In this case, only the name of the files (or directories) to be
installed are needed without the installation directory. For example,
foo.install containing only the architecture dependent files might look
like:
usr/bin/
usr/lib/foo/*.so
While the foo-common.install containing only the architecture
independent file might look like:
/usr/share/doc/
/usr/share/icons/
/usr/share/foo/
/usr/share/locale/
This would create two binary packages, foo and foo-common. Both would
require their own stanza in debian/control.
See dh_install(1) and the install file section (Section 5.11) of the Debian New Maintainers’ Guide for additional details.
The watch file¶
The debian/watch file allows us to check automatically for new upstream
versions using the tool uscan found in the devscripts package. The
first line of the watch file must be the format version (4, at the time of this
writing), while the following lines contain any URLs to parse. For example:
version=4
http://ftp.gnu.org/gnu/hello/hello-(.*).tar.gz
Note
If your tarballs live on Launchpad, the debian/watch file is
a little more complicated (see Question 21146 and
Bug 231797 for why this is). In that case, use something
like:
version=4
https://launchpad.net/flufl.enum/+download http://launchpad.net/flufl.enum/.*/flufl.enum-(.+).tar.gz
Running uscan in the root source directory will now compare the
upstream version number in the debian/changelog with the latest upstream
version. If a new upstream version is found, it will be automatically
downloaded. For example:
$ uscan
hello: Newer version (2.7) available on remote site:
http://ftp.gnu.org/gnu/hello/hello-2.7.tar.gz
(local version is 2.6)
hello: Successfully downloaded updated package hello-2.7.tar.gz
and symlinked hello_2.7.orig.tar.gz to it
For further information, see uscan(1) and the watch file section (Section 4.11) of the Debian Policy Manual.
The source/format file¶
This file indicates the format of the source package. It should contain a single line indicating the desired format:
3.0 (native)for Debian native packages (no upstream version)3.0 (quilt)for packages with a separate upstream tarball1.0for packages wishing to explicitly declare the default format
Note
The debian/source/format file should always exist. If the file can
not be found, the format 1.0 is assumed for backwards compatibility, but
lintian(1) will warn you about it when you try to build a source
package.
You are strongly recommended to use the newer 3.0 source format. It provides
a number of new features:
Support for additional compression formats:
bzip2,lzmaandxzSupport for multiple upstream tarballs
Not necessary to repack the upstream tarball to strip the debian directory
Debian-specific changes are no longer stored in a single
.diff.gzbut in multiple patches compatible with quilt underdebian/patches/. The patches to be applied automatically are listed in thedebian/patches/seriesfile.
The Debian DebSrc3.0 page summarises additional information
concerning the switch to the 3.0 source package formats.
See dpkg-source(1) and the source/format section (Section 5.21) of the Debian New Maintainers’ Guide for additional details.
Additional Resources¶
In addition to the links to the Debian Policy Manual in each section above, the Debian New Maintainers’ Guide has more detailed descriptions of each file. Chapter 4, “Required files under the debian directory” further discusses the control, changelog, copyright and rules files. Chapter 5, “Other files under the debian directory” discusses additional files that may be used.