1dpkg-buildpackage(1)              dpkg suite              dpkg-buildpackage(1)
2
3
4

NAME

6       dpkg-buildpackage - build binary or source packages from sources
7

SYNOPSIS

9       dpkg-buildpackage [option...]
10

DESCRIPTION

12       dpkg-buildpackage is a program that automates the process of building a
13       Debian package. It consists of the following steps:
14
15       1.  It prepares the build environment by setting various environment
16           variables (see ENVIRONMENT), runs the init hook, and calls dpkg-
17           source --before-build (unless -T or --target has been used).
18
19       2.  It checks that the build-dependencies and build-conflicts are
20           satisfied (unless -d or --no-check-builddeps is specified).
21
22       3.  If one or more specific targets have been selected with the -T or
23           --target option, it calls those targets and stops here. Otherwise
24           it runs the preclean hook and calls fakeroot debian/rules clean to
25           clean the build-tree (unless -nc or --no-pre-clean is specified).
26
27       4.  It runs the source hook and calls dpkg-source -b to generate the
28           source package (if a source build has been requested with --build
29           or equivalent options).
30
31       5.  It runs the build hook and calls debian/rules build-target, then
32           runs the binary hook followed by fakeroot debian/rules binary-
33           target (unless a source-only build has been requested with
34           --build=source or equivalent options).  Note that build-target and
35           binary-target are either build and binary (default case, or if an
36           any and all build has been requested with --build or equivalent
37           options), or build-arch and binary-arch (if an any and not all
38           build has been requested with --build or equivalent options), or
39           build-indep and binary-indep (if an all and not any build has been
40           requested with --build or equivalent options).
41
42       6.  It runs the buildinfo hook and calls dpkg-genbuildinfo to generate
43           a .buildinfo file.  Several dpkg-buildpackage options are forwarded
44           to dpkg-genbuildinfo.
45
46       7.  It runs the changes hook and calls dpkg-genchanges to generate a
47           .changes file.  The name of the .changes file will depend on the
48           type of build and will be as specific as necessary but not more;
49           for a build that includes any the name will be source-name_binary-
50           version_arch.changes, or otherwise for a build that includes all
51           the name will be source-name_binary-version_all.changes, or
52           otherwise for a build that includes source the name will be source-
53           name_source-version_source.changes.  Many dpkg-buildpackage options
54           are forwarded to dpkg-genchanges.
55
56       8.  It runs the postclean hook and if -tc or --post-clean is specified,
57           it will call fakeroot debian/rules clean again.
58
59       9.  It calls dpkg-source --after-build.
60
61       10. It runs the check hook and calls a package checker for the .changes
62           file (if a command is specified in DEB_CHECK_COMMAND or with
63           --check-command).
64
65       11. It runs the sign hook and signs using the OpenPGP backend (as long
66           as it is not an UNRELEASED build, or --no-sign is specified) to
67           sign the .dsc file (if any, unless -us or --unsigned-source is
68           specified), the .buildinfo file (unless -ui, --unsigned-buildinfo,
69           -uc or --unsigned-changes is specified) and the .changes file
70           (unless -uc or --unsigned-changes is specified).
71
72       12. It runs the done hook.
73

OPTIONS

75       All long options can be specified both on the command line and in the
76       dpkg-buildpackage system and user configuration files.  Each line in
77       the configuration file is either an option (exactly the same as the
78       command line option but without leading hyphens) or a comment (if it
79       starts with a ‘#’).
80
81       --build=type
82           Specifies the build type from a comma-separated list of components
83           (since dpkg 1.18.5).  All the specified components get combined to
84           select the single build type to use, which implies a single build
85           run with a single .changes file generated.  Passed to dpkg-
86           genchanges.
87
88           The allowed values are:
89
90           source
91               Builds the source package.
92
93               Note: When using this value standalone and if what you want is
94               simply to (re-)build the source package from a clean source
95               tree, using dpkg-source directly is always a better option as
96               it does not require any build dependencies to be installed
97               which are otherwise needed to be able to call the clean target.
98
99           any Builds the architecture specific binary packages.
100
101           all Builds the architecture independent binary packages.
102
103           binary
104               Builds the architecture specific and independent binary
105               packages.  This is an alias for any,all.
106
107           full
108               Builds everything.  This is an alias for source,any,all, and
109               the same as the default case when no build option is specified.
110
111       -g  Equivalent to --build=source,all (since dpkg 1.17.11).
112
113       -G  Equivalent to --build=source,any (since dpkg 1.17.11).
114
115       -b  Equivalent to --build=binary or --build=any,all.
116
117       -B  Equivalent to --build=any.
118
119       -A  Equivalent to --build=all.
120
121       -S  Equivalent to --build=source.
122
123       -F  Equivalent to --build=full, --build=source,binary or
124           --build=source,any,all (since dpkg 1.15.8).
125
126       --target=target[,...]
127       --target target[,...]
128       -T, --rules-target=target[,...]
129           Calls debian/rules target once per target specified, after having
130           setup the build environment (except for calling dpkg-source
131           --before-build), and stops the package build process here (since
132           dpkg 1.15.0, long option since dpkg 1.18.8, multi-target support
133           since dpkg 1.18.16).  If --as-root is also given, then the command
134           is executed as root (see --root-command).  Note that known targets
135           that are required to be run as root do not need this option (i.e.
136           the clean, binary, binary-arch and binary-indep targets).
137
138       --as-root
139           Only meaningful together with --target (since dpkg 1.15.0).
140           Requires that the target be run with root rights.
141
142       -si
143       -sa
144       -sd
145       -vversion
146       -Cchanges-description
147       -mmaintainer-address
148       -emaintainer-address
149           Passed unchanged to dpkg-genchanges. See its manual page.
150
151       --build-by=maintainer-address
152       --source-by=maintainer-address (since dpkg 1.21.10)
153           Pass as -m to dpkg-genchanges. See its manual page.
154
155       --release-by=maintainer-address
156       --changed-by=maintainer-address (since dpkg 1.21.10)
157           Pass as -e to dpkg-genchanges. See its manual page.
158
159       -a, --host-arch architecture
160           Specify the Debian architecture we build for (long option since
161           dpkg 1.17.17).  The architecture of the machine we build on is
162           determined automatically, and is also the default for the host
163           machine.
164
165       -t, --host-type gnu-system-type
166           Specify the GNU system type we build for (long option since dpkg
167           1.17.17).  It can be used in place of --host-arch or as a
168           complement to override the default GNU system type of the host
169           Debian architecture.
170
171       --target-arch architecture
172           Specify the Debian architecture the binaries built will build for
173           (since dpkg 1.17.17).  The default value is the host machine.
174
175       --target-type gnu-system-type
176           Specify the GNU system type the binaries built will build for
177           (since dpkg 1.17.17).  It can be used in place of --target-arch or
178           as a complement to override the default GNU system type of the
179           target Debian architecture.
180
181       -P, --build-profiles=profile[,...]
182           Specify the profile(s) we build, as a comma-separated list (since
183           dpkg 1.17.2, long option since dpkg 1.18.8).  The default behavior
184           is to build for no specific profile. Also sets them (as a space
185           separated list) as the DEB_BUILD_PROFILES environment variable
186           which allows, for example, debian/rules files to use this
187           information for conditional builds.
188
189       -j, --jobs[=jobs|auto]
190           Specifies the number of jobs allowed to be run simultaneously
191           (since dpkg 1.14.7, long option since dpkg 1.18.8).  The number of
192           jobs matching the number of online processors if auto is specified
193           (since dpkg 1.17.10), or unlimited number if jobs is not specified.
194           The default behavior is auto (since dpkg 1.18.11) in non-forced
195           mode (since dpkg 1.21.10), and as such it is always safer to use
196           with any package including those that are not parallel-build safe.
197           Setting the number of jobs to 1 will restore serial execution.
198
199           Will add parallel=jobs or parallel to the DEB_BUILD_OPTIONS
200           environment variable which allows debian/rules files to opt-in to
201           use this information for their own purposes.  The jobs value will
202           override the parallel=jobs or parallel option in the
203           DEB_BUILD_OPTIONS environment variable.  Note that the auto value
204           will get replaced by the actual number of currently active
205           processors, and as such will not get propagated to any child
206           process. If the number of online processors cannot be inferred then
207           the code will fallback to using serial execution (since dpkg
208           1.18.15), although this should only happen on exotic and
209           unsupported systems.
210
211       -J, --jobs-try[=jobs|auto]
212           This option (since dpkg 1.18.2, long option since dpkg 1.18.8) is
213           equivalent to the -j above.
214
215           Since the behavior for -j changed in dpkg 1.21.10 to the opt-in
216           mode, you can use this option instead if you need to guarantee
217           semantics across dpkg release series.
218
219       --jobs-force[=jobs|auto]
220           This option (since dpkg 1.21.10) is equivalent to the --jobs option
221           except that it will enable forced parallel mode, by adding the make
222           -j option with the computed number of parallel jobs to the
223           MAKEFLAGS environment variable.
224
225           This should cause all subsequent make invocations to inherit the
226           option, thus forcing the parallel setting on the packaging (and
227           possibly the upstream build system if that uses make(1)) regardless
228           of their support for parallel builds, which might cause build
229           failures.
230
231           Note: Any Makefile that is not parallel-safe should be considered
232           to be buggy.  These should either be made parallel-safe, or marked
233           as not being safe with the make(1) .NOTPARALLEL target.
234
235       -D, --check-builddeps
236           Check build dependencies and conflicts; abort if unsatisfied (long
237           option since dpkg 1.18.8).  This is the default behavior.
238
239       -d, --no-check-builddeps
240           Do not check build dependencies and conflicts (long option since
241           dpkg 1.18.8).
242
243       --ignore-builtin-builddeps
244           Do not check built-in build dependencies and conflicts (since dpkg
245           1.18.2).  These are the distribution specific implicit build
246           dependencies usually required in a build environment, the so called
247           Build-Essential package set.
248
249       --rules-requires-root
250           Do not honor the Rules-Requires-Root field, falling back to its
251           legacy default value (since dpkg 1.19.1).
252
253       -nc, --no-pre-clean
254           Do not clean the source tree before building (long option since
255           dpkg 1.18.8).  Implies -b if nothing else has been selected among
256           -F, -g, -G, -B, -A or -S.  Implies -d with -S (since dpkg 1.18.0).
257
258       --pre-clean
259           Clean the source tree before building (since dpkg 1.18.8).  This is
260           the default behavior.
261
262       -tc, --post-clean
263           Clean the source tree (using gain-root-command debian/rules clean)
264           after the package has been built (long option since dpkg 1.18.8).
265
266       --no-post-clean
267           Do not clean the source tree after the package has been built
268           (since dpkg 1.19.1).  This is the default behavior.
269
270       --sanitize-env
271           Sanitize the build environment (since dpkg 1.20.0).  This will
272           reset or remove environment variables, umask, and any other process
273           attributes that might otherwise adversely affect the build of
274           packages.  Because the official entry point to build packages is
275           debian/rules, packages cannot rely on these settings being in
276           place, and thus should work even when they are not.  What to
277           sanitize is vendor specific.
278
279       -r, --root-command=gain-root-command
280           When dpkg-buildpackage needs to execute part of the build process
281           as root, it prefixes the command it executes with gain-root-command
282           if one has been specified (long option since dpkg 1.18.8).
283           Otherwise, if none has been specified, fakeroot will be used by
284           default, if the command is present.  gain-root-command should start
285           with the name of a program on the PATH and will get as arguments
286           the name of the real command to run and the arguments it should
287           take.  gain-root-command can include parameters (they must be
288           space-separated) but no shell metacharacters.  gain-root-command
289           might typically be fakeroot, sudo, super or really.  su is not
290           suitable, since it can only invoke the user's shell with -c instead
291           of passing arguments individually to the command to be run.
292
293       -R, --rules-file=rules-file
294           Building a Debian package usually involves invoking debian/rules as
295           a command with several standard parameters (since dpkg 1.14.17,
296           long option since dpkg 1.18.8).  With this option it's possible to
297           use another program invocation to build the package (it can include
298           space separated parameters).  Alternatively it can be used to
299           execute the standard rules file with another make program (for
300           example by using /usr/local/bin/make -f debian/rules as rules-
301           file).
302
303       --check-command=check-command
304           Command used to check the .changes file itself and any artifact
305           built referenced in the file (since dpkg 1.17.6).  The command
306           should take the .changes pathname as an argument. This command will
307           usually be lintian.
308
309       --check-option=opt
310           Pass option opt to the check-command specified with
311           DEB_CHECK_COMMAND or --check-command (since dpkg 1.17.6).  Can be
312           used multiple times.
313
314       --hook-hook-name=hook-command
315           Set the specified shell code hook-command as the hook hook-name,
316           which will run at the times specified in the run steps (since dpkg
317           1.17.6).  The hooks will always be executed even if the following
318           action is not performed (except for the binary hook).  All the
319           hooks will run in the unpacked source directory.
320
321           Note: Hooks can affect the build process, and cause build failures
322           if their commands fail, so watch out for unintended consequences.
323
324           The current hook-name supported are:
325
326           init preclean source build binary buildinfo changes postclean check
327           sign done
328
329           The hook-command supports the following substitution format string,
330           which will get applied to it before execution:
331
332           %%  A single % character.
333
334           %a  A boolean value (0 or 1), representing whether the following
335               action is being performed.
336
337           %p  The source package name.
338
339           %v  The source package version.
340
341           %s  The source package version (without the epoch).
342
343           %u  The upstream version.
344
345       --buildinfo-file=filename
346           Set the filename for the generated .buildinfo file (since dpkg
347           1.21.0).
348
349       --buildinfo-option=opt
350           Pass option opt to dpkg-genbuildinfo (since dpkg 1.18.11).  Can be
351           used multiple times.
352
353       --sign-backend=sign-backend
354           Specify an OpenPGP backend interface to use when invoking the sign-
355           command (since dpkg 1.21.10).
356
357           The default is auto, where the best current backend available will
358           be used.  The specific OpenPGP backends supported in order of
359           preference are:
360
361           sop (any conforming Stateless OpenPGP implementation)
362           sq (from Sequoia-PGP)
363           gpg (from GnuPG)
364       -p, --sign-command=sign-command
365           When dpkg-buildpackage needs to execute an OpenPGP backend command
366           to sign a source control (.dsc) file or a .changes file it will run
367           sign-command (searching the PATH if necessary) instead of the
368           default or auto-detected backend command (long option since dpkg
369           1.18.8).  sign-command will get all the arguments defined by the
370           --sign-backend.  sign-command should not contain spaces or any
371           other shell metacharacters.
372
373       -k, --sign-keyid=key-id
374       --sign-key=key-id
375           Specify an OpenPGP key-ID (either a fingerprint or a user-ID) for
376           the secret key to use when signing packages (--sign-key since dpkg
377           1.18.8, --sign-keyid since dpkg 1.21.10).
378
379       --sign-keyfile=key-file
380           Specify an OpenPGP key-file containing the secret key to use when
381           signing packages (since dpkg 1.21.10).
382
383           Note: For security reasons the key-file is best kept locked with a
384           password.
385
386       -us, --unsigned-source
387           Do not sign the source package (long option since dpkg 1.18.8).
388
389       -ui, --unsigned-buildinfo
390           Do not sign the .buildinfo file (since dpkg 1.18.19).
391
392       -uc, --unsigned-changes
393           Do not sign the .buildinfo and .changes files (long option since
394           dpkg 1.18.8).
395
396       --no-sign
397           Do not sign any file, this includes the source package, the
398           .buildinfo file and the .changes file (since dpkg 1.18.20).
399
400       --force-sign
401           Force the signing of the resulting files (since dpkg 1.17.0),
402           regardless of -us, --unsigned-source, -ui, --unsigned-buildinfo,
403           -uc, --unsigned-changes or other internal heuristics.
404
405       -sn
406       -ss
407       -sA
408       -sk
409       -su
410       -sr
411       -sK
412       -sU
413       -sR
414       -i, --diff-ignore[=regex]
415       -I, --tar-ignore[=pattern]
416       -z, --compression-level=level
417       -Z, --compression=compressor
418           Passed unchanged to dpkg-source. See its manual page.
419
420       --source-option=opt
421           Pass option opt to dpkg-source (since dpkg 1.15.6).  Can be used
422           multiple times.
423
424       --changes-file=filename
425           Set the filename for the generated .changes file (since dpkg
426           1.21.0).
427
428       --changes-option=opt
429           Pass option opt to dpkg-genchanges (since dpkg 1.15.6).  Can be
430           used multiple times.
431
432       --admindir=dir
433       --admindir dir
434           Change the location of the dpkg database (since dpkg 1.14.0).  The
435           default location is /var/lib/dpkg.
436
437       -?, --help
438           Show the usage message and exit.
439
440       --version
441           Show the version and exit.
442

ENVIRONMENT

444   External environment
445       DEB_CHECK_COMMAND
446           If set, it will be used as the command to check the .changes file
447           (since dpkg 1.17.6).  Overridden by the --check-command option.
448
449       DEB_SIGN_KEYID
450           If set, it will be used to sign the .changes, .buildinfo and .dsc
451           files (since dpkg 1.17.2).  Overridden by the --sign-key option.
452
453       DEB_SIGN_KEYFILE
454           If set, it will be used to sign the .changes, .buildinfo and .dsc
455           files (since dpkg 1.21.10).  Overridden by the --sign-keyfile
456           option.
457
458       DEB_BUILD_OPTIONS
459           If set, it will contain a space-separated list of options that
460           might affect the build process in debian/rules, and the behavior of
461           some dpkg commands.
462
463           With nocheck the DEB_CHECK_COMMAND variable will be ignored.  With
464           parallel=N the parallel jobs will be set to N, overridden by the
465           --jobs-try option.
466
467       DEB_BUILD_PROFILES
468           If set, it will be used as the active build profile(s) for the
469           package being built (since dpkg 1.17.2).  It is a space separated
470           list of profile names.  Overridden by the -P option.
471
472       DPKG_COLORS
473           Sets the color mode (since dpkg 1.18.5).  The currently accepted
474           values are: auto (default), always and never.
475
476       DPKG_NLS
477           If set, it will be used to decide whether to activate Native
478           Language Support, also known as internationalization (or i18n)
479           support (since dpkg 1.19.0).  The accepted values are: 0 and 1
480           (default).
481
482   Internal environment
483       Even if dpkg-buildpackage exports some variables, debian/rules should
484       not rely on their presence and should instead use the respective
485       interface to retrieve the needed values, because that file is the main
486       entry point to build packages and running it standalone should be
487       supported.
488
489       DEB_BUILD_*
490       DEB_HOST_*
491       DEB_TARGET_*
492           dpkg-architecture is called with the -a and -t parameters
493           forwarded. Any variable that is output by its -s option is
494           integrated in the build environment.
495
496       DEB_RULES_REQUIRES_ROOT
497           This variable is set to the value obtained from the Rules-Requires-
498           Root field or from the command-line.  When set, it will be a valid
499           value for the Rules-Requires-Root field.  It is used to notify
500           debian/rules whether the rootless-builds.txt specification is
501           supported.
502
503       DEB_GAIN_ROOT_CMD
504           This variable is set to gain-root-command when the field Rules-
505           Requires-Root is set to a value different to no and binary-targets.
506
507       SOURCE_DATE_EPOCH
508           This variable is set to the Unix timestamp since the epoch of the
509           latest entry in debian/changelog, if it is not already defined.
510

FILES

512       /etc/dpkg/buildpackage.conf
513           System wide configuration file
514
515       $XDG_CONFIG_HOME/dpkg/buildpackage.conf or
516       $HOME/.config/dpkg/buildpackage.conf
517           User configuration file.
518

NOTES

520   Compiler flags are no longer exported
521       Between dpkg 1.14.17 and 1.16.1, dpkg-buildpackage exported compiler
522       flags (CFLAGS, CXXFLAGS, FFLAGS, CPPFLAGS and LDFLAGS) with values as
523       returned by dpkg-buildflags. This is no longer the case.
524
525   Default build targets
526       dpkg-buildpackage is using the build-arch and build-indep targets since
527       dpkg 1.16.2. Those targets are thus mandatory. But to avoid breakages
528       of existing packages, and ease the transition, if the source package
529       does not build both architecture independent and dependent binary
530       packages (since dpkg 1.18.8) it will fallback to use the build target
531       if make -f debian/rules -qn build-target returns 2 as exit code.
532

BUGS

534       It should be possible to specify spaces and shell metacharacters and
535       initial arguments for gain-root-command and sign-command.
536

SEE ALSO

538       /usr/share/doc/dpkg/spec/rootless-builds.txt, dpkg-source(1), dpkg-
539       architecture(1), dpkg-buildflags(1), dpkg-genbuildinfo(1), dpkg-
540       genchanges(1), fakeroot(1), lintian(1),
541       <https://datatracker.ietf.org/doc/draft-dkg-openpgp-stateless-cli/>,
542       sq(1), gpg(1).
543
544
545
5461.21.21                           2023-02-25              dpkg-buildpackage(1)
Impressum