debhelper(7) | Debhelper | debhelper(7) |
debhelper - the debhelper tool suite
dh_* [-v] [-a] [-i] [--no-act] [-ppackage] [-Npackage] [-Ptmpdir]
Debhelper is used to help you build a Debian package. The philosophy behind debhelper is to provide a collection of small, simple, and easily understood tools that are used in debian/rules to automate various common aspects of building a package. This means less work for you, the packager. It also, to some degree means that these tools can be changed if Debian policy changes, and packages that use them will require only a rebuild to comply with the new policy.
A typical debian/rules file that uses debhelper will call several debhelper commands in sequence, or use dh(1) to automate this process. Examples of rules files that use debhelper are in /usr/share/doc/debhelper/examples/
To create a new Debian package using debhelper, you can just copy one of the sample rules files and edit it by hand. Or you can try the dh-make package, which contains a dh_make command that partially automates the process. For a more gentle introduction, the maint-guide Debian package contains a tutorial about making your first package using debhelper.
Except where the tool explicitly denotes otherwise, all of the debhelper tools assume that they run from the root directory of an unpacked source package. This is so they can locate find files like debian/control when needed.
Here is the list of debhelper commands you can use. See their man pages for additional documentation.
A few debhelper commands are deprecated and should not be used.
If a program's name starts with dh_, and the program is not on the above lists, then it is not part of the debhelper package, but it should still work like the other programs described on this page.
Many debhelper commands make use of files in debian/ to control what they do. Besides the common debian/changelog and debian/control, which are in all packages, not just those using debhelper, some additional files can be used to configure the behavior of specific debhelper commands. These files are typically named debian/package.foo (where package of course, is replaced with the package that is being acted on).
For example, dh_installdocs uses files named debian/package.docs to list the documentation files it will install. See the man pages of individual commands for details about the names and formats of the files they use. Generally, these files will list files to act on, one file per line. Some programs in debhelper use pairs of files and destinations or slightly more complicated formats.
Note for the first (or only) binary package listed in debian/control, debhelper will use debian/foo when there's no debian/package.foo file. However, it is often a good idea to keep the package. prefix as it is more explicit. The primary exception to this are files that debhelper by default installs in every binary package when it does not have a package prefix (such as debian/copyright or debian/changelog).
In some rare cases, you may want to have different versions of these files for different architectures or OSes. If files named debian/package.foo.ARCH or debian/package.foo.OS exist, where ARCH and OS are the same as the output of "dpkg-architecture -qDEB_HOST_ARCH" / "dpkg-architecture -qDEB_HOST_ARCH_OS", then they will be used in preference to other, more general files.
Mostly, these config files are used to specify lists of various types of files. Documentation or example files to install, files to move, and so on. When appropriate, in cases like these, you can use standard shell wildcard characters (? and * and [..] character classes) in the files. You can also put comments in these files; lines beginning with # are ignored.
The syntax of these files is intentionally kept very simple to make them easy to read, understand, and modify.
In compatibility level 13 and later, it is possible to use simple substitutions in debhelper config files for the following tools:
All substitution variables are of the form ${foo} and the braces are mandatory. Variable names are case-sensitive and consist of alphanumerics (a-zA-Z0-9), hyphens (-), underscores (_), and colons (:). The first character must be an alphanumeric.
If you need a literal dollar sign that cannot trigger a substitution, you can either use the ${Dollar} substitution or the sequence ${}.
The following expansions are available:
When in doubt, the DEB_HOST_* variant is the one that will work both for native and cross builds.
For performance reasons, debhelper will attempt to resolve these names from the environment first before consulting dpkg-architecture(1). This is mostly mentioned for completeness as it will not matter for most cases.
# Triggers an error ${NO_SUCH_TOKEN} # Expands to the literal value "${NO_SUCH_TOKEN}" ${Dollar}{NO_SUCH_TOKEN}
This variable equivalent to the sequence ${} and the two can be used interchangeably.
This can be useful if you need to include a literal whitespace character (e.g. space) where it would otherwise be stripped or used as a separator.
Note that all variables must expand to a defined value. As an example, if debhelper sees ${env:FOO}, then it will insist that the environment variable FOO is set (it can be set to the empty string).
Substitution limits
To avoid infinite loops and resource exhaustion, debhelper will stop with an error if the text contains many substitution variables (50) or they expand beyond a certain size (4096 characters or 3x length of the original input - whichever is bigger).
If you need additional flexibility, many of the debhelper tools (e.g. dh_install(1)) support executing a config file as a script.
To use this feature, simply mark the config file as executable (e.g. chmod +x debian/package.install) and the tool will attempt to execute it and use the output of the script. In many cases, you can use dh-exec(1) as interpreter of the config file to retain most of the original syntax while getting the additional flexibility you need.
When using executable debhelper config files, please be aware of the following:
Otherwise, the output will be used exactly as-is. Notably, debhelper will not expand wildcards or strip comments or strip whitespace in the output.
If you need the package to build on a file system where you cannot disable the executable bit, then you can use dh-exec(1) and its strip-output script.
The following command line options are supported by all debhelper programs.
Note that verbose mode may also output other "internal" commands that do not directly affect the package build directory.
This option is removed in compat 12.
The following command line options are supported by some debhelper programs. See the man page of each program for a complete explanation of what each option does.
The following command line options are supported by all of the dh_auto_* debhelper programs. These programs support a variety of build systems, and normally heuristically determine which to use, and how to use them. You can use these command line options to override the default behavior. Typically these are passed to dh(1), which then passes them to all the dh_auto_* programs.
Pass none as buildsystem to disable auto-selection.
Warning: The --sourcedir variant matches a similar named option in dh_install and dh_missing (etc.) for historical reasons. While they have a similar name, they have very distinct purposes and in some cases it can cause errors when this variant is passed to dh (when then passes it on to all tools).
If this option is not specified, building will be done in source by default unless the build system requires or prefers out of source tree building. In such a case, the default build directory will be used even if --builddirectory is not specified.
If the build system prefers out of source tree building but still allows in source building, the latter can be re-enabled by passing a build directory path that is the same as the source directory path.
If neither option is specified, debhelper currently defaults to --parallel in compat 10 (or later) and --no-parallel otherwise.
As an optimization, dh will try to avoid passing these options to subprocesses, if they are unnecessary and the only options passed. Notably this happens when DEB_BUILD_OPTIONS does not have a parallel parameter (or its value is 1).
Notably, setting the maximum to 1 is effectively the same as using --no-parallel.
When passing this option, the concrete dh_auto_* tool will ignore the cache from dh(1) and retrigger a rebuild of these variables. This is useful in the very rare case where the package need to do multiple builds but with different ...FLAGS options. A concrete example would be needing to change the -O parameter in CFLAGS in the second build:
export DEB_CFLAGS_MAINT_APPEND=-O3 %: dh $@ override_dh_auto_configure: dh_auto_configure -Bbuild-deb ... DEB_CFLAGS_MAINT_APPEND=-Os dh_auto_configure \ --reload-all-buildenv-variables -Bbuild-udeb ...
Without --reload-all-buildenv-variables in the second call to dh_auto_configure(1), the change in DEB_CFLAGS_MAINT_APPEND would be ignored as dh_auto_configure(1) would use the cached value of CFLAGS set by dh(1).
This option is only available with debhelper (>= 12.7~) when the package uses compatibility level 9 or later.
From time to time, major non-backwards-compatible changes need to be made to debhelper, to keep it clean and well-designed as needs change and its author gains more experience. To prevent such major changes from breaking existing packages, the concept of debhelper compatibility levels was introduced. You must tell debhelper which compatibility level it should use, and it modifies its behavior in various ways.
In current debhelper, you can specify the compatibility level in debian/control by adding a Build-Depends on the debhelper-compat package. For example, to use v13 mode, ensure debian/control has:
Build-Depends: debhelper-compat (= 13)
This also serves as an appropriate versioned build dependency on a sufficient version of the debhelper package, so you do not need to specify a separate versioned build dependency on the debhelper package unless you need a specific point release of debhelper (such as for the introduction of a new feature or bugfix within a compatibility level).
Note that debhelper does not provide debhelper-compat for experimental or beta compatibility levels; packages experimenting with those compatibility levels should use debian/compat (or, if only for selected commands, DH_COMPAT).
Prior versions of debhelper required specifying the compatibility level in the file debian/compat, and current debhelper still supports this for backward compatibility. To use this method, the debian/compat file should contain the compatibility level as a single number, and no other content. If you specify the compatibility level by this method, your package will also need a versioned build dependency on a version of the debhelper package equal to (or greater than) the compatibility level your package uses. So, if you specify compatibility level 13 in debian/compat, ensure debian/control has:
Build-Depends: debhelper (>= 13~)
Note that you must use either the build-dependency on debhelper-compat or the debian/compat file. Whenever possible, the debhelper-compat build-dependency is recommended.
If needed be, the DH_COMPAT environment variable can be used to override the compat level for a given command. The feature is mostly useful for either temporarily upgrading a few commands to a new compat level or keeping a few commands on a lower compat level. The feature is best used sparingly as it effectively introduces special-cases into the debian/rules file that may be surprising to maintainers or reviewers (or, in the long term, to yourself).
Unless otherwise indicated, all debhelper documentation assumes that you are using the most recent compatibility level, and in most cases does not indicate if the behavior is different in an earlier compatibility level, so if you are not using the most recent compatibility level, you're advised to read below for notes about what is different in earlier compatibility levels.
The list of supported compatibility levels and the related upgrade check list has moved to debhelper-compat-upgrade-checklist(7).
If your source package generates more than one binary package, debhelper programs will default to acting on all binary packages when run. If your source package happens to generate one architecture dependent package, and another architecture independent package, this is not the correct behavior, because you need to generate the architecture dependent packages in the binary-arch debian/rules target, and the architecture independent packages in the binary-indep debian/rules target.
To facilitate this, as well as give you more control over which packages are acted on by debhelper programs, all debhelper programs accept the -a, -i, -p, and -s parameters. These parameters are cumulative. If none are given, debhelper programs default to acting on all packages listed in the control file, with the exceptions below.
First, any package whose Architecture field in debian/control does not match the DEB_HOST_ARCH architecture will be excluded ("Debian Policy, section 5.6.8").
Also, some additional packages may be excluded based on the contents of the DEB_BUILD_PROFILES environment variable and Build-Profiles fields in binary package stanzas in debian/control, according to the draft policy at <https://wiki.debian.org/BuildProfileSpec>.
Interaction between package selections and Build-Profiles
Build-Profiles affect which packages are included in the package selections mechanisms in debhelper. Generally, the package selections are described from the assumption that all packages are enabled. This section describes how the selections react when a package is disabled due to the active Build-Profiles (or lack of active Build-Profiles).
Note you will receive a warning if all packages related to these selections are disabled. In that case, it generally does not make sense to do the build in the first place.
Note that it does not matter whether a package is enabled or disabled by default.
Some debhelper commands will automatically generate parts of Debian maintainer scripts. If you want these automatically generated things included in your existing Debian maintainer scripts, then you need to add #DEBHELPER# to your scripts, in the place the code should be added. #DEBHELPER# will be replaced by any auto-generated code when you run dh_installdeb.
If a script does not exist at all and debhelper needs to add something to it, then debhelper will create the complete script.
All debhelper commands that automatically generate code in this way let it be disabled by the -n parameter (see above).
Note that the inserted code will be shell code, so you cannot directly use it in a Perl script. If you would like to embed it into a Perl script, here is one way to do that (note that I made sure that $1, $2, etc are set with the set command):
my $temp="set -e\nset -- @ARGV\n" . << 'EOF'; #DEBHELPER# EOF if (system($temp)) { my $exit_code = ($? >> 8) & 0xff; my $signal = $? & 0x7f; if ($exit_code) { die("The debhelper script failed with error code: ${exit_code}"); } else { die("The debhelper script was killed by signal: ${signal}"); } }
Some debhelper commands may make the generated package need to depend on some other packages. For example, if you use dh_installdebconf(1), your package will generally need to depend on debconf. Or if you use dh_installxfonts(1), your package will generally need to depend on a particular version of xutils. Keeping track of these miscellaneous dependencies can be annoying since they are dependent on how debhelper does things, so debhelper offers a way to automate it.
All commands of this type, besides documenting what dependencies may be needed on their man pages, will automatically generate a substvar called ${misc:Depends}. If you put that token into your debian/control file, it will be expanded to the dependencies debhelper figures you need.
This is entirely independent of the standard ${shlibs:Depends} generated by dh_makeshlibs(1), and the ${perl:Depends} generated by dh_perl(1). You can choose not to use any of these, if debhelper's guesses don't match reality.
By default, all debhelper programs assume that the temporary directory used for assembling the tree of files in a package is debian/package.
Sometimes, you might want to use some other temporary directory. This is supported by the -P flag. For example, "dh_installdocs -Pdebian/tmp", will use debian/tmp as the temporary directory. Note that if you use -P, the debhelper programs can only be acting on a single package at a time. So if you have a package that builds many binary packages, you will need to also use the -p flag to specify which binary package the debhelper program will act on.
Debhelper includes support for udebs. To create a udeb with debhelper, add "Package-Type: udeb" to the package's stanza in debian/control. Debhelper will try to create udebs that comply with debian-installer policy, by making the generated package files end in .udeb, not installing any documentation into a udeb, skipping over preinst, postrm, prerm, and config scripts, etc.
This section describes some of the environment variables that influences the behaviour of debhelper or which debhelper interacts with.
It is important to note that these must be actual environment variables in order to affect the behaviour of debhelper (not simply Makefile variables). To specify them properly in debian/rules, be sure to "export" them. For example, "export DH_VERBOSE".
Ignored if DH_VERBOSE is also set or -v / --verbose is passed.
When using dh(1), it can be passed options that will be passed on to each debhelper command, which is generally better than using DH_OPTIONS.
This can be useful if you are doing a build from a CVS source tree, in which case setting DH_ALWAYS_EXCLUDE=CVS will prevent any CVS directories from sneaking into the package you build. Or, if a package has a source tarball that (unwisely) includes CVS directories, you might want to export DH_ALWAYS_EXCLUDE=CVS in debian/rules, to make it take effect wherever your package is built.
Multiple things to exclude can be separated with colons, as in DH_ALWAYS_EXCLUDE=CVS:.svn
This is intended to be used by downstreams or specific local configurations that require a debhelper addon to be run during multiple builds without having to patch a large number of rules file. If at all possible, this should be avoided in favor of a --with flag in the rules file.
Note that DPKG_COLOR also affects a number of dpkg related tools and debhelper uses it on the assumption that you want the same color setting for dpkg and debhelper. In the off-hand chance you want different color setting for debhelper, you can use DH_COLORS instead or in addition to DPKG_COLORS.
The variable is defined according to <https://no-color.org/>. In this project, the environment variables (such as DH_COLORS) are considered an explicit request for color.
The HOME directory will be created as an empty directory but it will be reused between calls to dh_auto_*. Any content will persist until explicitly deleted or dh_clean.
Please note that this variable should not be altered by package maintainers inside debian/rules to change the behaviour of debhelper. Instead, where the package maintainer need these features, they should look disabling the relevant feature directly (e.g. by overriding the concrete tools).
It is documented here because it has a similar name to DEB_BUILD_OPTIONS, which make some people mistakenly assume that debhelper will also react to this variable.
The debhelper tool suite reacts to the following flags in DEB_BUILD_OPTIONS.
When dherroron is present and set to obsolete-compat-levels, then debhelper tools will promote deprecation warnings for usage of old soon to be removed compat levels into errors.
This is useful for automated checking for code relying on deprecated compat levels that is scheduled for removal.
This option is intended for testing purposes; not production builds.
This value will cause the official debhelper tools will skip actions and helpers that either remove, detach or deduplicate debugging symbols in ELF binaries.
This value affects dh_dwz(1) and dh_strip(1).
Package maintainers looking to avoid running the upstream tests should not rely on this. Instead, they can add an empty override target to skip dh_auto_test.
This value affects dh_auto_test(1).
This value will cause several debhelper tools to skip installation of documentation such as manpages or upstream provided documentation. Additionally, the tools will also ignore if declared documentation is "missing" on the assumption that the documentation has not been built.
This value effects tools like dh_installdocs(1), which knows it is working with documentation.
This value will cause dh_installchangelogs(1) to act as if it had been passed the --no-trim option, forcing it to forgo removing older entries from changelogs.
This value causes debhelper to skip the generation of automatically generated debug symbol packages.
This value affects dh_strip(1).
This value affects many debhelper tools. Most notably dh_auto_*, which will attempt to run the underlying upstream build system with that number of threads.
This value affects most dh_auto_* tools directly. For commands provided by the debhelper package, it also causes the tools to act like the DH_QUIET environment variable was non-empty.
Unknown flags are silently ignored.
Note third-party debhelper-like tools or third-party provided build systems may or may not react to the above flags. This tends to depend on implementation details of the tool.
Joey Hess <joeyh@debian.org>
2024-03-01 | 13.14.1ubuntu5 |