dpkg-buildpackage (1) Linux Manual Page
NAME
dpkg-buildpackage – build binary or source packages from sources
SYNOPSIS
dpkg-buildpackage [option…]
DESCRIPTION
dpkg-buildpackage is a program that automates the process of building a Debian package. It consists of the following steps:
1.- It prepares the build environment by setting various environment variables (see
ENVIRONMENT), runs theinithook, and callsdpkg-source –before-build(unless-Tor–targethas been used). 2.- It checks that the build-dependencies and build-conflicts are satisfied (unless
-dor–no-check-builddepsis specified). 3.- If one or more specific targets have been selected with the
-Tor–targetoption, it calls those targets and stops here. Otherwise it runs theprecleanhook and callsfakeroot debian/rules cleanto clean the build-tree (unless-ncor–no-pre-cleanis specified). 4.- It runs the
sourcehook and callsdpkg-source -bto generate the source package (if asourcebuild has been requested with–buildor equivalent options). 5.- It runs the
buildhook and callsdebian/rulesbuild-target, then runs thebinaryhook followed byfakeroot debian/rulesbinary-target (unless a source-only build has been requested with–build=sourceor equivalent options). Note that build-target and binary-target are eitherbuildandbinary(default case, or if ananyandallbuild has been requested with–buildor equivalent options), orbuild-archandbinary-arch(if ananyand notallbuild has been requested with–buildor equivalent options), orbuild-indepandbinary-indep(if analland notanybuild has been requested with–buildor equivalent options). 6.- It runs the
buildinfohook and callsdpkg-genbuildinfoto generate a.buildinfofile. Severaldpkg-buildpackageoptions are forwarded todpkg-genbuildinfo. 7.- It runs the
changeshook and callsdpkg-genchangesto generate a.changesfile. The name of the.changesfile will depend on the type of build and will be as specific as necessary but not more; for a build that includesanythe name will be source-name_binary-version_arch.changes, or otherwise for a build that includesallthe name will be source-name_binary-version_all.changes, or otherwise for a build that includessourcethe name will be source-name_source-version_source.changes. Manydpkg-buildpackageoptions are forwarded todpkg-genchanges. 8.- It runs the
postcleanhook and if-tcor–post-cleanis specified, it will callfakeroot debian/rules cleanagain. 9.- It calls
dpkg-source –after-build. 10.- It runs the
checkhook and calls a package checker for the.changesfile (if a command is specified inDEB_CHECK_COMMANDor with–check-command). 11.- It runs the
signhook and callsgpg(as long as it is not an UNRELEASED build, or–no-signis specified) to sign the.dscfile (if any, unless-usor–unsigned-sourceis specified), the.buildinfofile (unless-ui,–unsigned-buildinfo,-ucor–unsigned-changesis specified) and the.changesfile (unless-ucor–unsigned-changesis specified). 12.- It runs the
donehook.
OPTIONS
All long options can be specified both on the command line and in the dpkg-buildpackage system and user configuration files. Each line in the configuration file is either an option (exactly the same as the command line option but without leading hyphens) or a comment (if it starts with a ‘#‘).
–build=type- Specifies the build type from a comma-separated list of components (since dpkg 1.18.5). Passed to
dpkg-genchanges.The allowed values are:
-
source- Builds the source package.
Note:When using this value standalone and if what you want is simply to (re-)build the source package from a clean source tree, usingdpkg-sourcedirectly is always a better option as it does not require any build dependencies to be installed which are otherwise needed to be able to call thecleantarget. any- Builds the architecture specific binary packages.
all- Builds the architecture independent binary packages.
binary- Builds the architecture specific and independent binary packages. This is an alias for
any,all. full- Builds everything. This is an alias for
source,any,all, and the same as the default case when no build option is specified.
-g- Equivalent to
–build=source,all(since dpkg 1.17.11). -G- Equivalent to
–build=source,any(since dpkg 1.17.11). -b- Equivalent to
–build=binaryor–build=any,all. -B- Equivalent to
–build=any. -A- Equivalent to
–build=all. -S- Equivalent to
–build=source. -F- Equivalent to
–build=full,–build=source,binaryor–build=source,any,all(since dpkg 1.15.8). –target=target[,…]–targettarget[,…]-T,–rules-target=target[,…]- Calls
debian/rulestarget once per target specified, after having setup the build environment (except for callingdpkg-source –before-build), and stops the package build process here (since dpkg 1.15.0, long option since dpkg 1.18.8, multi-target support since dpkg 1.18.16). If–as-rootis also given, then the command is executed as root (see–root-command). Note that known targets that are required to be run as root do not need this option (i.e. theclean,binary,binary-archandbinary-indeptargets). –as-root- Only meaningful together with
–target(since dpkg 1.15.0). Requires that the target be run with root rights. -si-sa-sd-vversion-Cchanges-description-m,–release-by=maintainer-address-e,–build-by=maintainer-address- Passed unchanged to
dpkg-genchanges. See its manual page. -a,–host-archarchitecture- Specify the Debian architecture we build for (long option since dpkg 1.17.17). The architecture of the machine we build on is determined automatically, and is also the default for the host machine.
-t,–host-typegnu-system-type- Specify the GNU system type we build for (long option since dpkg 1.17.17). It can be used in place of
–host-archor as a complement to override the default GNU system type of the host Debian architecture. –target-archarchitecture- Specify the Debian architecture the binaries built will build for (since dpkg 1.17.17). The default value is the host machine.
–target-typegnu-system-type- Specify the GNU system type the binaries built will build for (since dpkg 1.17.17). It can be used in place of
–target-archor as a complement to override the default GNU system type of the target Debian architecture. -P,–build-profiles=profile[,…]- Specify the profile(s) we build, as a comma-separated list (since dpkg 1.17.2, long option since dpkg 1.18.8). The default behavior is to build for no specific profile. Also sets them (as a space separated list) as the
DEB_BUILD_PROFILESenvironment variable which allows, for example,debian/rulesfiles to use this information for conditional builds. -j,–jobs[=jobs|auto]- Number of jobs allowed to be run simultaneously, number of jobs matching the number of online processors if
autois specified (since dpkg 1.17.10), or unlimited number if jobs is not specified, equivalent to themake(1) option of the same name (since dpkg 1.14.7, long option since dpkg 1.18.8). Will add itself to theMAKEFLAGSenvironment variable, which should cause all subsequent make invocations to inherit the option, thus forcing the parallel setting on the packaging (and possibly the upstream build system if that uses make) regardless of their support for parallel builds, which might cause build failures. Also addsparallel=jobs orparallelto theDEB_BUILD_OPTIONSenvironment variable which allows debian/rules files to use this information for their own purposes. The-jvalue will override theparallel=jobs orparalleloption in theDEB_BUILD_OPTIONSenvironment variable. Note that theautovalue will get replaced by the actual number of currently active processors, and as such will not get propagated to any child process. If the number of online processors cannot be inferred then the code will fallback to using serial execution (since dpkg 1.18.15), although this should only happen on exotic and unsupported systems. -J,–jobs-try[=jobs|auto]- This option (since dpkg 1.18.2, long option since dpkg 1.18.8) is equivalent to the
-joption except that it does not set theMAKEFLAGSenvironment variable, and as such it is safer to use with any package including those that are not parallel-build safe.autois the default behavior (since dpkg 1.18.11). Setting the number of jobs to 1 will restore a serial behavior. -D,–check-builddeps- Check build dependencies and conflicts; abort if unsatisfied (long option since dpkg 1.18.8). This is the default behavior.
-d,–no-check-builddeps- Do not check build dependencies and conflicts (long option since dpkg 1.18.8).
–ignore-builtin-builddeps- Do not check built-in build dependencies and conflicts (since dpkg 1.18.2). These are the distribution specific implicit build dependencies usually required in a build environment, the so called Build-Essential package set.
–rules-requires-root- Do not honor the
Rules-Requires-Rootfield, falling back to its legacy default value (since dpkg 1.19.1). -nc,–no-pre-clean- Do not clean the source tree before building (long option since dpkg 1.18.8). Implies
-bif nothing else has been selected among-F,-g,-G,-B,-Aor-S. Implies-dwith-S(since dpkg 1.18.0). –pre-clean- Clean the source tree before building (since dpkg 1.18.8). This is the default behavior.
-tc,–post-clean- Clean the source tree (using gain-root-command
debian/rules clean) after the package has been built (long option since dpkg 1.18.8). –no-post-clean- Do not clean the source tree after the package has been built (since dpkg 1.19.1). This is the default behavior.
–sanitize-env- Sanitize the build environment (since dpkg 1.20.0). This will reset or remove environment variables, umask, and any other process attributes that might otherwise adversely affect the build of packages. Because the official entry point to build packages is
debian/rules, packages cannot rely on these settings being in place, and thus should work even when they are not. What to sanitize is vendor specific. -r,–root-command=gain-root-command- When
dpkg-buildpackageneeds to execute part of the build process as root, it prefixes the command it executes with gain-root-command if one has been specified (long option since dpkg 1.18.8). Otherwise, if none has been specified,fakerootwill be used by default, if the command is present. gain-root-command should start with the name of a program on thePATHand will get as arguments the name of the real command to run and the arguments it should take. gain-root-command can include parameters (they must be space-separated) but no shell metacharacters. gain-root-command might typically befakeroot,sudo,superorreally.suis not suitable, since it can only invoke the user’s shell with-cinstead of passing arguments individually to the command to be run. -R,–rules-file=rules-file- Building a Debian package usually involves invoking
debian/rulesas a command with several standard parameters (since dpkg 1.14.17, long option since dpkg 1.18.8). With this option it’s possible to use another program invocation to build the package (it can include space separated parameters). Alternatively it can be used to execute the standard rules file with another make program (for example by using/usr/local/bin/make -f debian/rulesas rules-file). –check-command=check-command- Command used to check the
.changesfile itself and any artifact built referenced in the file (since dpkg 1.17.6). The command should take the.changespathname as an argument. This command will usually belintian. –check-option=opt- Pass option opt to the check-command specified with
DEB_CHECK_COMMANDor–check-command(since dpkg 1.17.6). Can be used multiple times. –hook-hook-name=hook-command- Set the specified shell code hook-command as the hook hook-name, which will run at the times specified in the run steps (since dpkg 1.17.6). The hooks will always be executed even if the following action is not performed (except for the
binaryhook). All the hooks will run in the unpacked source directory.Note:Hooks can affect the build process, and cause build failures if their commands fail, so watch out for unintended consequences.The current hook-name supported are:
init preclean source build binary buildinfo changes postclean check sign doneThe hook-command supports the following substitution format string, which will get applied to it before execution:
-
%%- A single % character.
- %a
- A boolean value (0 or 1), representing whether the following action is being performed.
- %p
- The source package name.
- %v
- The source package version.
- %s
- The source package version (without the epoch).
- %u
- The upstream version.
–buildinfo-file=filename- Set the filename for the generated
.buildinfofile (since dpkg 1.21.0). –buildinfo-option=opt- Pass option opt to
dpkg-genbuildinfo(since dpkg 1.18.11). Can be used multiple times. -p,–sign-command=sign-command- When
dpkg-buildpackageneeds to execute GPG to sign a source control (.dsc) file or a.changesfile it will run sign-command (searching thePATHif necessary) instead ofgpg(long option since dpkg 1.18.8). sign-command will get all the arguments thatgpgwould have gotten. sign-command should not contain spaces or any other shell metacharacters. -k,–sign-key=key-id- Specify a key-ID to use when signing packages (long option since dpkg 1.18.8).
-us,–unsigned-source- Do not sign the source package (long option since dpkg 1.18.8).
-ui,–unsigned-buildinfo- Do not sign the
.buildinfofile (since dpkg 1.18.19). -uc,–unsigned-changes- Do not sign the
.buildinfoand.changesfiles (long option since dpkg 1.18.8). –no-sign- Do not sign any file, this includes the source package, the
.buildinfofile and the.changesfile (since dpkg 1.18.20). –force-sign- Force the signing of the resulting files (since dpkg 1.17.0), regardless of
-us,–unsigned-source,-ui,–unsigned-buildinfo,-uc,–unsigned-changesor other internal heuristics. -sn-ss-sA-sk-su-sr-sK-sU-sR-i,–diff-ignore[=regex]-I,–tar-ignore[=pattern]-z,–compression-level=level-Z,–compression=compressor- Passed unchanged to
dpkg-source. See its manual page. –source-option=opt- Pass option opt to
dpkg-source(since dpkg 1.15.6). Can be used multiple times. –changes-file=filename- Set the filename for the generated
.changesfile (since dpkg 1.21.0). –changes-option=opt- Pass option opt to
dpkg-genchanges(since dpkg 1.15.6). Can be used multiple times. –admindir=dir–admindirdir- Change the location of the
dpkgdatabase (since dpkg 1.14.0). The default location is /var/lib/dpkg. -?,–help- Show the usage message and exit.
–version- Show the version and exit.
ENVIRONMENT
External environment
DEB_CHECK_COMMAND- If set, it will be used as the command to check the
.changesfile (since dpkg 1.17.6). Overridden by the–check-commandoption. DEB_SIGN_KEYID- If set, it will be used to sign the
.changesand.dscfiles (since dpkg 1.17.2). Overridden by the–sign-keyoption. DEB_BUILD_OPTIONS- If set, it will contain a space-separated list of options that might affect the build process in debian/rules, and the behavior of some dpkg commands.
With
nochecktheDEB_CHECK_COMMANDvariable will be ignored. Withparallel=N the parallel jobs will be set to N, overridden by the–jobs-tryoption. DEB_BUILD_PROFILES- If set, it will be used as the active build profile(s) for the package being built (since dpkg 1.17.2). It is a space separated list of profile names. Overridden by the
-Poption. DPKG_COLORS- Sets the color mode (since dpkg 1.18.5). The currently accepted values are:
auto(default),alwaysandnever. DPKG_NLS- If set, it will be used to decide whether to activate Native Language Support, also known as internationalization (or i18n) support (since dpkg 1.19.0). The accepted values are:
0and1(default).
Internal environment
Even if dpkg-buildpackage exports some variables, debian/rules should not rely on their presence and should instead use the respective interface to retrieve the needed values, because that file is the main entry point to build packages and running it standalone should be supported.
DEB_BUILD_*DEB_HOST_*DEB_TARGET_*-
dpkg-architectureis called with the-aand-tparameters forwarded. Any variable that is output by its-soption is integrated in the build environment. DEB_RULES_REQUIRES_ROOT- This variable is set to the value obtained from the
Rules-Requires-Rootfield or from the command-line. When set, it will be a valid value for theRules-Requires-Rootfield. It is used to notifydebian/ruleswhether therootless-builds.txtspecification is supported. DEB_GAIN_ROOT_CMD- This variable is set to gain-root-command when the field
Rules-Requires-Rootis set to a value different tonoandbinary-targets. SOURCE_DATE_EPOCH- This variable is set to the Unix timestamp since the epoch of the latest entry in debian/changelog, if it is not already defined.
FILES
- /etc/dpkg/buildpackage.conf
- System wide configuration file
- $XDG_CONFIG_HOME/dpkg/buildpackage.conf or
- $HOME/.config/dpkg/buildpackage.conf
- User configuration file.
NOTES
Compiler flags are no longer exported
Between dpkg 1.14.17 and 1.16.1, dpkg-buildpackage exported compiler flags (CFLAGS, CXXFLAGS, FFLAGS, CPPFLAGS and LDFLAGS) with values as returned by dpkg-buildflags. This is no longer the case.
Default build targets
dpkg-buildpackage is using the build-arch and build-indep targets since dpkg 1.16.2. Those targets are thus mandatory. But to avoid breakages of existing packages, and ease the transition, if the source package does not build both architecture independent and dependent binary packages (since dpkg 1.18.8) it will fallback to use the build target if make -f debian/rules -qn build-target returns 2 as exit code.
BUGS
It should be possible to specify spaces and shell metacharacters and initial arguments for gain-root-command and sign-command.
SEE ALSO
dpkg-source(1), dpkg-architecture(1), dpkg-buildflags(1), dpkg-genbuildinfo(1), dpkg-genchanges(1), fakeroot(1), lintian(1), gpg(1).
