5 # Copyright © 1996 Ian Jackson
6 # Copyright © 2000 Wichert Akkerman
7 # Copyright © 2006-2024 Guillem Jover <guillem@debian.org>
8 # Copyright © 2007 Frank Lichtenheld
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <https://www.gnu.org/licenses/>.
26 use File
::Path
qw(remove_tree);
28 use File
::Glob
qw(bsd_glob GLOB_TILDE GLOB_NOCHECK);
29 use POSIX
qw(:sys_wait_h);
33 use Dpkg
::ErrorHandling
;
35 use Dpkg
::BuildOptions
;
36 use Dpkg
::BuildProfiles
qw(set_build_profiles);
37 use Dpkg
::BuildDriver
;
39 use Dpkg
::Compression
;
44 use Dpkg
::Control
::Info
;
45 use Dpkg
::Changelog
::Parse
;
47 use Dpkg
::OpenPGP
::ErrorCodes
;
48 use Dpkg
::OpenPGP
::KeyHandle
;
49 use Dpkg
::Path
qw(find_command);
51 use Dpkg
::Vendor
qw(run_vendor_hook);
53 textdomain
('dpkg-dev');
56 printf g_
("Debian %s version %s.\n"), $Dpkg::PROGNAME
, $Dpkg::PROGVERSION
;
59 This is free software; see the GNU General Public License version 2 or
60 later for copying conditions. There is NO warranty.
66 'Usage: %s [<option>...] [--] [<filename.dsc>|<directory>]')
69 --build=<type>[,...] specify the build <type>: full, source, binary,
70 any, all (default is \'full\').
71 -F, --build=full normal full build (source and binary; default).
72 -g, --build=source,all source and arch-indep build.
73 -G, --build=source,any source and arch-specific build.
74 -b, --build=binary binary-only, no source files.
75 -B, --build=any binary-only, only arch-specific files.
76 -A, --build=all binary-only, only arch-indep files.
77 -S, --build=source source-only, no binary files.
78 -nc, --no-pre-clean do not pre clean source tree (implies -b).
79 --pre-clean pre clean source tree (default).
80 --no-post-clean do not post clean source tree (default).
81 -tc, --post-clean post clean source tree.
82 --sanitize-env sanitize the build environment.
83 -D, --check-builddeps check build dependencies and conflicts (default).
84 -d, --no-check-builddeps do not check build dependencies and conflicts.
85 --ignore-builtin-builddeps
86 do not check builtin build dependencies.
87 -P, --build-profiles=<profiles>
88 assume comma-separated build <profiles> as active.
89 --rules-requires-root assume legacy Rules-Requires-Root field value.
90 -R, --rules-file=<rules> rules file to execute (default is debian/rules).
91 -T, --rules-target=<target> call debian/rules <target>.
92 --as-root ensure -T calls the target with root rights.
93 -j, --jobs[=<jobs>|auto] jobs to run simultaneously (passed to <rules>),
94 (default; default is auto, opt-in mode).
95 -J, --jobs-try[=<jobs>|auto]
97 --jobs-force[=<jobs>|auto]
98 jobs to run simultaneously (passed to <rules>),
99 (default is auto, forced mode).
100 -r, --root-command=<command>
101 command to gain root rights (default is fakeroot).
102 --check-command=<command>
103 command to check the .changes file (no default).
104 --check-option=<opt> pass <opt> to check <command>.
105 --hook-<name>=<command> set <command> as the hook <name>, known hooks:
106 preinit init preclean source build binary
107 buildinfo changes postclean check sign done
108 --buildinfo-file=<file> set the .buildinfo filename to generate.
109 --buildinfo-option=<opt>
110 pass option <opt> to dpkg-genbuildinfo.
111 --changes-file=<file> set the .changes filename to generate.
112 --sign-backend=<backend>
113 OpenPGP backend to use to sign
115 -p, --sign-command=<command>
116 command to sign .dsc and/or .changes files
118 --sign-keyfile=<file> the key file to use for signing.
119 -k, --sign-keyid=<keyid> the key id to use for signing.
120 --sign-key=<keyid> alias for -k, --sign-keyid.
121 -ap, --sign-pause add pause before starting signature process.
122 -us, --unsigned-source unsigned source package.
123 -ui, --unsigned-buildinfo unsigned .buildinfo file.
124 -uc, --unsigned-changes unsigned .buildinfo and .changes file.
125 --no-sign do not sign any file.
126 --force-sign force signing the resulting files.
127 --admindir=<directory> change the administrative directory.
128 -?, --help show this help message.
129 --version show the version.')
131 'Options passed to dpkg-architecture:
132 -a, --host-arch <arch> set the host Debian architecture.
133 -t, --host-type <type> set the host GNU system type.
134 --target-arch <arch> set the target Debian architecture.
135 --target-type <type> set the target GNU system type.')
137 'Options passed to dpkg-genchanges:
138 -si source includes orig, if new upstream (default).
139 -sa source includes orig, always.
140 -sd source is diff and .dsc only.
141 -v<version> changes since version <version>.
142 -m, --source-by=<maint> maintainer for this source or build is <maint>.
143 --build-by=<maint> ditto.
144 -e, --release-by=<maint> maintainer for this change or release is <maint>.
145 --changed-by=<maint> ditto.
146 -C<descfile> changes are described in <descfile>.
147 --changes-option=<opt> pass option <opt> to dpkg-genchanges.')
149 'Options passed to dpkg-source:
150 -sn force Debian native source format.
151 -s[sAkurKUR] see dpkg-source for explanation.
152 -z, --compression-level=<level>
153 compression level to use for source.
154 -Z, --compression=<compressor>
155 compression to use for source (gz|xz|bzip2|lzma).
156 -i, --diff-ignore[=<regex>] ignore diffs of files matching <regex>.
157 -I, --tar-ignore[=<pattern>]
158 filter out files when building tarballs.
159 --source-option=<opt> pass option <opt> to dpkg-source.
164 my @debian_rules = ('debian/rules');
165 my @rootcommand = ();
170 my $sanitize_env = 0;
172 my $parallel_force = 0;
173 my $checkbuilddep = 1;
174 my $check_builtin_builddep = 1;
176 my $source_from_dsc = 0;
179 my $check_command = $ENV{DEB_CHECK_COMMAND
};
182 my $signkeyfile = $ENV{DEB_SIGN_KEYFILE
};
183 my $signkeyid = $ENV{DEB_SIGN_KEYID
};
185 my $signreleased = 1;
187 my $signbuildinfo = 1;
189 my $buildtarget = 'build';
190 my $binarytarget = 'binary';
193 my $target_arch = '';
194 my $target_type = '';
195 my @build_profiles = ();
197 my @call_target = ();
198 my $call_target_as_root = 0;
222 $hook{$_} = undef foreach @hook_names;
225 my $conf = Dpkg
::Conf
->new();
226 $conf->load_config('buildpackage.conf');
228 # Inject config options for command-line parser.
229 unshift @ARGV, @
{$conf};
231 my $build_opts = Dpkg
::BuildOptions
->new();
233 if ($build_opts->has('nocheck')) {
234 $check_command = undef;
235 } elsif (not find_command
($check_command)) {
236 $check_command = undef;
242 if (/^(?:--help|-\?)$/) {
245 } elsif (/^--version$/) {
248 } elsif (/^--admindir$/) {
249 $admindir = shift @ARGV;
250 } elsif (/^--admindir=(.*)$/) {
252 } elsif (/^--source-option=(.*)$/) {
253 push @source_opts, $1;
254 } elsif (/^--buildinfo-file=(.*)$/) {
255 $buildinfo_file = $1;
256 usageerr
(g_
('missing .buildinfo filename')) if not length $buildinfo_file;
257 } elsif (/^--buildinfo-option=(.*)$/) {
258 my $buildinfo_opt = $1;
259 if ($buildinfo_opt =~ m/^-O(.*)/) {
260 warning
(g_
('passing %s via %s is not supported; please use %s instead'),
261 '-O', '--buildinfo-option', '--buildinfo-file');
262 $buildinfo_file = $1;
264 push @buildinfo_opts, $buildinfo_opt;
266 } elsif (/^--changes-file=(.*)$/) {
268 usageerr
(g_
('missing .changes filename')) if not length $changes_file;
269 } elsif (/^--changes-option=(.*)$/) {
270 my $changes_opt = $1;
271 if ($changes_opt =~ m/^-O(.*)/) {
272 warning
(g_
('passing %s via %s is not supported; please use %s instead'),
273 '-O', '--changes-option', '--changes-file');
276 push @changes_opts, $changes_opt;
278 } elsif (/^--jobs(?:-try)?$/) {
281 } elsif (/^(?:-[jJ]|--jobs(?:-try)?=)(\d*|auto)$/) {
282 $parallel = $1 || '';
284 } elsif (/^--jobs-force(?:=(\d*|auto))?$/) {
285 $parallel = $1 || '';
287 } elsif (/^(?:-r|--root-command=)(.*)$/) {
289 @rootcommand = split ' ', $arg;
290 } elsif (/^--check-command=(.*)$/) {
292 } elsif (/^--check-option=(.*)$/) {
293 push @check_opts, $1;
294 } elsif (/^--hook-([^=]+)=(.*)$/) {
295 my ($hook_name, $hook_cmd) = ($1, $2);
296 usageerr
(g_
('unknown hook name %s'), $hook_name)
297 if not exists $hook{$hook_name};
298 usageerr
(g_
('missing hook %s command'), $hook_name)
299 if not defined $hook_cmd;
300 $hook{$hook_name} = $hook_cmd;
301 } elsif (/^(--buildinfo-id)=.*$/) {
303 warning
(g_
('%s is deprecated; it is without effect'), $1);
304 } elsif (/^--sign-backend=(.*)$/) {
306 } elsif (/^(?:-p|--sign-command=)(.*)$/) {
308 } elsif (/^--sign-keyfile=(.*)$/) {
310 } elsif (/^(?:-k|--sign-keyid=|--sign-key=)(.*)$/) {
312 } elsif (/^--(no-)?check-builddeps$/) {
313 $checkbuilddep = !(defined $1 and $1 eq 'no-');
314 } elsif (/^-([dD])$/) {
315 $checkbuilddep = ($1 eq 'D');
316 } elsif (/^--ignore-builtin-builddeps$/) {
317 $check_builtin_builddep = 0;
318 } elsif (/^-s(gpg|pgp)$/) {
320 warning
(g_
('-s%s is deprecated; always using gpg style interface'), $1);
321 } elsif (/^--force-sign$/) {
323 } elsif (/^--no-sign$/) {
328 } elsif (/^-us$/ or /^--unsigned-source$/) {
330 } elsif (/^-ui$/ or /^--unsigned-buildinfo$/) {
332 } elsif (/^-uc$/ or /^--unsigned-changes$/) {
335 } elsif (/^-ap$/ or /^--sign-pausa$/) {
337 } elsif (/^-a$/ or /^--host-arch$/) {
339 } elsif (/^-a(.*)$/ or /^--host-arch=(.*)$/) {
341 } elsif (/^-P(.*)$/ or /^--build-profiles=(.*)$/) {
343 @build_profiles = split /,/, $arg;
344 } elsif (/^-s[iad]$/) {
345 push @changes_opts, $_;
346 } elsif (/^--(?:compression-level|compression)=.+$/) {
347 push @source_opts, $_;
348 } elsif (/^--(?:diff-ignore|tar-ignore)(?:=.+)?$/) {
349 push @source_opts, $_;
350 } elsif (/^-(?:s[nsAkurKUR]|[zZ].*|i.*|I.*)$/) {
351 push @source_opts, $_; # passed to dpkg-source
352 } elsif (/^-tc$/ or /^--post-clean$/) {
354 } elsif (/^--no-post-clean$/) {
356 } elsif (/^--sanitize-env$/) {
358 } elsif (/^-t$/ or /^--host-type$/) {
359 $host_type = shift; # Order DOES matter!
360 } elsif (/^-t(.*)$/ or /^--host-type=(.*)$/) {
361 $host_type = $1; # Order DOES matter!
362 } elsif (/^--target-arch$/) {
363 $target_arch = shift;
364 } elsif (/^--target-arch=(.*)$/) {
366 } elsif (/^--target-type$/) {
367 $target_type = shift;
368 } elsif (/^--target-type=(.*)$/) {
370 } elsif (/^(?:--target|--rules-target|-T)$/) {
371 push @call_target, split /,/, shift @ARGV;
372 } elsif (/^(?:--target=|--rules-target=|-T)(.+)$/) {
374 push @call_target, split /,/, $arg;
375 } elsif (/^--rules-requires-root$/) {
376 $rrr_override = 'binary-targets';
377 } elsif (/^--as-root$/) {
378 $call_target_as_root = 1;
379 } elsif (/^--pre-clean$/) {
381 } elsif (/^-nc$/ or /^--no-pre-clean$/) {
383 } elsif (/^--build=(.*)$/) {
384 set_build_type_from_options
($1, $_);
386 set_build_type
(BUILD_BINARY
, $_);
388 set_build_type
(BUILD_ARCH_DEP
, $_);
390 set_build_type
(BUILD_ARCH_INDEP
, $_);
392 set_build_type
(BUILD_SOURCE
, $_);
394 set_build_type
(BUILD_SOURCE
| BUILD_ARCH_DEP
, $_);
396 set_build_type
(BUILD_SOURCE
| BUILD_ARCH_INDEP
, $_);
398 set_build_type
(BUILD_FULL
, $_);
399 } elsif (/^-v(.*)$/) {
401 } elsif (/^-m(.*)$/ or /^--(?:source|build)-by=(.*)$/) {
403 } elsif (/^-e(.*)$/ or /^--(?:changed|release)-by=(.*)$/) {
405 } elsif (/^-C(.*)$/) {
407 } elsif (m/^-[EW]$/) {
409 warning
(g_
('%s is deprecated; it is without effect'), $_);
410 } elsif (/^-R(.*)$/ or /^--rules-file=(.*)$/) {
412 @debian_rules = split ' ', $arg;
413 } elsif ($_ eq '--') {
414 $source = shift @ARGV;
417 usageerr
(g_
('unknown option or argument %s'), $_);
425 my $targets = join ',', @call_target;
426 set_build_type_from_targets
($targets, '--rules-target', nocheck
=> 1);
429 if (build_has_all
(BUILD_BINARY
)) {
430 $buildtarget = 'build';
431 $binarytarget = 'binary';
432 } elsif (build_has_any
(BUILD_ARCH_DEP
)) {
433 $buildtarget = 'build-arch';
434 $binarytarget = 'binary-arch';
435 } elsif (build_has_any
(BUILD_ARCH_INDEP
)) {
436 $buildtarget = 'build-indep';
437 $binarytarget = 'binary-indep';
441 # -nc without -b/-B/-A/-S/-F implies -b
442 set_build_type
(BUILD_BINARY
) if build_has_any
(BUILD_DEFAULT
);
443 # -nc with -S implies no dependency checks
444 $checkbuilddep = 0 if build_is
(BUILD_SOURCE
);
447 if ($call_target_as_root and @call_target == 0) {
448 error
(g_
('option %s is only meaningful with option %s'),
449 '--as-root', '--rules-target');
452 if ($check_command and not find_command
($check_command)) {
453 error
(g_
("check-command '%s' not found"), $check_command);
456 if ($signcommand and not find_command
($signcommand)) {
457 error
(g_
("sign-command '%s' not found"), $signcommand);
460 # Default to auto if none of parallel=N, -J or -j have been specified.
461 if (not defined $parallel and not $build_opts->has('parallel')) {
466 # Prepare the environment.
471 if (defined $parallel) {
472 if ($parallel eq 'auto') {
474 $parallel = qx(getconf _NPROCESSORS_ONLN
2>/dev/null
);
475 # Fallback for at least Irix.
476 $parallel = qx(getconf _NPROC_ONLN
2>/dev/null
) if $?
;
477 # Fallback to serial execution if cannot infer the number of online
479 $parallel = '1' if $?
;
482 if ($parallel_force) {
483 $ENV{MAKEFLAGS
} //= '';
484 $ENV{MAKEFLAGS
} .= " -j$parallel";
486 $build_opts->set('parallel', $parallel);
487 $build_opts->export();
490 if ($build_opts->has('terse')) {
491 $ENV{MAKEFLAGS
} //= '';
492 $ENV{MAKEFLAGS
} .= ' --no-print-directory';
495 set_build_profiles
(@build_profiles) if @build_profiles;
497 # Handle specified source trees.
498 if (defined $source) {
501 or syserr
(g_
('cannot change directory to %s'), $source);
502 } elsif (-f
$source) {
503 require Dpkg
::Source
::Package
;
505 if (build_has_any
(BUILD_SOURCE
)) {
506 error
(g_
('building source package would overwrite input source %s'),
510 if ($source =~ m{/}) {
511 error
(g_
('source package %s is expected in the current directory'),
515 my $srcpkg = Dpkg
::Source
::Package
->new(
519 no_overwrite_dir
=> 1,
520 require_valid_signature
=> 0,
521 require_strong_checksums
=> 0,
524 $srcdir = $srcpkg->get_basedirname();
527 error
(g_
('source directory %s exists already, aborting'), $srcdir);
530 info
(g_
('extracting source package %s'), $source);
532 run_cmd
('dpkg-source', @source_opts, '--extract', $source);
535 or syserr
(g_
('cannot change directory to %s'), $srcdir);
537 # Track whether we extracted the source from a specified .dsc.
538 $source_from_dsc = 1;
542 my $changelog = changelog_parse
();
543 my $ctrl = Dpkg
::Control
::Info
->new();
545 my $pkg = mustsetvar
($changelog->{source
}, g_
('source package'));
546 my $version = mustsetvar
($changelog->{version
}, g_
('source version'));
547 my $v = Dpkg
::Version
->new($version);
548 my ($ok, $error) = version_check
($v);
549 error
($error) unless $ok;
551 my $sversion = $v->as_string(omit_epoch
=> 1);
552 my $uversion = $v->version();
554 my $distribution = mustsetvar
($changelog->{distribution
}, g_
('source distribution'));
558 $maintainer = $changedby;
560 $maintainer = $maint;
562 $maintainer = mustsetvar
($changelog->{maintainer
}, g_
('source changed by'));
565 # <https://reproducible-builds.org/specs/source-date-epoch/>
566 $ENV{SOURCE_DATE_EPOCH
} ||= $changelog->{timestamp
} || time;
569 push @arch_opts, ('--host-arch', $host_arch) if $host_arch;
570 push @arch_opts, ('--host-type', $host_type) if $host_type;
571 push @arch_opts, ('--target-arch', $target_arch) if $target_arch;
572 push @arch_opts, ('--target-type', $target_type) if $target_type;
574 open my $arch_env, '-|', 'dpkg-architecture', '-f', @arch_opts
575 or subprocerr
('dpkg-architecture');
576 while (<$arch_env>) {
578 my ($key, $value) = split /=/, $_, 2;
581 close $arch_env or subprocerr
('dpkg-architecture');
584 if (build_has_any
(BUILD_ARCH_DEP
)) {
585 $arch = mustsetvar
($ENV{DEB_HOST_ARCH
}, g_
('host architecture'));
586 } elsif (build_has_any
(BUILD_ARCH_INDEP
)) {
588 } elsif (build_has_any
(BUILD_SOURCE
)) {
592 my $pv = "${pkg}_$sversion";
593 my $pva = "${pkg}_${sversion}_$arch";
597 if (defined $signkeyfile) {
598 $signkeytype = 'keyfile';
599 $signkeyhandle = bsd_glob
($signkeyfile, GLOB_TILDE
| GLOB_NOCHECK
);
600 } elsif (defined $signkeyid) {
601 $signkeytype = 'autoid';
602 $signkeyhandle = $signkeyid;
604 $signkeytype = 'userid';
605 $signkeyhandle = $maintainer;
607 my $signkey = Dpkg
::OpenPGP
::KeyHandle
->new(
608 type
=> $signkeytype,
609 handle
=> $signkeyhandle,
613 my $openpgp = Dpkg
::OpenPGP
->new(
614 backend
=> $signbackend // 'auto',
615 cmd
=> $signcommand // 'auto',
617 keystore
=> $signkey->needs_keystore(),
621 if (not $openpgp->can_use_secrets($signkey)) {
625 } elsif ($signforce) {
629 } elsif (($signsource or $signbuildinfo or $signchanges) and
630 $distribution eq 'UNRELEASED') {
637 if ($signsource && build_has_none
(BUILD_SOURCE
)) {
641 # Sanitize build environment.
643 run_vendor_hook
('sanitize-environment');
646 my $build_driver = Dpkg
::BuildDriver
->new(
648 debian_rules
=> \
@debian_rules,
649 root_cmd
=> \
@rootcommand,
650 as_root
=> $call_target_as_root,
651 rrr_override
=> $rrr_override,
655 # Preparation of environment stops here
660 $build_driver->pre_check();
662 if (scalar @call_target == 0) {
663 run_cmd
('dpkg-source', @source_opts, '--before-build', '.');
666 if ($checkbuilddep) {
667 my @checkbuilddep_opts;
669 push @checkbuilddep_opts, '-A' if build_has_none
(BUILD_ARCH_DEP
);
670 push @checkbuilddep_opts, '-B' if build_has_none
(BUILD_ARCH_INDEP
);
671 push @checkbuilddep_opts, '-I' if not $check_builtin_builddep;
672 push @checkbuilddep_opts, "--admindir=$admindir" if $admindir;
674 system('dpkg-checkbuilddeps', @checkbuilddep_opts);
675 if (not WIFEXITED
($?
)) {
676 subprocerr
('dpkg-checkbuilddeps');
677 } elsif (WEXITSTATUS
($?
)) {
678 warning
(g_
('build dependencies/conflicts unsatisfied; aborting'));
679 warning
(g_
('(Use -d flag to override.)'));
684 foreach my $call_target (@call_target) {
685 $build_driver->run_task($call_target);
687 exit 0 if scalar @call_target;
689 run_hook
('preclean', {
690 enabled
=> $preclean,
694 $build_driver->run_task('clean');
698 enabled
=> build_has_any
(BUILD_SOURCE
),
700 DPKG_BUILDPACKAGE_HOOK_SOURCE_OPTIONS
=> join(' ', @source_opts),
704 if (build_has_any
(BUILD_SOURCE
)) {
705 warning
(g_
('building a source package without cleaning up as you asked; ' .
706 'it might contain undesired files')) if not $preclean;
707 run_cmd
('dpkg-source', @source_opts, '-b', '.');
710 my $build_types = get_build_options_from_type
();
712 my $need_buildtask = $build_driver->need_build_task($buildtarget, $binarytarget);
715 enabled
=> build_has_any
(BUILD_BINARY
) && $need_buildtask,
717 DPKG_BUILDPACKAGE_HOOK_BUILD_TARGET
=> $buildtarget,
721 # If we are building rootless, there is no need to call the build target
722 # independently as non-root.
723 if (build_has_any
(BUILD_BINARY
) && $need_buildtask) {
724 $build_driver->run_build_task($buildtarget, $binarytarget);
727 if (build_has_any
(BUILD_BINARY
)) {
730 DPKG_BUILDPACKAGE_HOOK_BINARY_TARGET
=> $binarytarget,
733 $build_driver->run_task($binarytarget);
736 $buildinfo_file //= "../$pva.buildinfo";
738 if (build_has_none
(BUILD_DEFAULT
) || $source_from_dsc) {
739 my $buildinfo_buildtypes = $build_types;
741 # We can now let dpkg-genbuildinfo know that we can include the .dsc
742 # in the .buildinfo file as we handled it ourselves, and what we are
743 # building matches either the source we built or extracted it from.
744 $buildinfo_buildtypes .= ',source' if $source_from_dsc;
746 push @buildinfo_opts, "--build=$buildinfo_buildtypes";
748 push @buildinfo_opts, "--admindir=$admindir" if $admindir;
749 push @buildinfo_opts, "-O$buildinfo_file" if $buildinfo_file;
751 run_hook
('buildinfo', {
753 DPKG_BUILDPACKAGE_HOOK_BUILDINFO_OPTIONS
=> join(' ', @buildinfo_opts),
756 run_cmd
('dpkg-genbuildinfo', @buildinfo_opts);
758 $changes_file //= "../$pva.changes";
760 push @changes_opts, "--build=$build_types" if build_has_none
(BUILD_DEFAULT
);
761 push @changes_opts, "-m$maint" if defined $maint;
762 push @changes_opts, "-e$changedby" if defined $changedby;
763 push @changes_opts, "-v$since" if defined $since;
764 push @changes_opts, "-C$desc" if defined $desc;
765 push @changes_opts, "-O$changes_file";
767 my $changes = Dpkg
::Control
->new(type
=> CTRL_FILE_CHANGES
);
769 run_hook
('changes', {
771 DPKG_BUILDPACKAGE_HOOK_CHANGES_OPTIONS
=> join(' ', @changes_opts),
774 run_cmd
('dpkg-genchanges', @changes_opts);
775 $changes->load($changes_file);
777 run_hook
('postclean', {
778 enabled
=> $postclean,
782 $build_driver->run_task('clean');
785 run_cmd
('dpkg-source', @source_opts, '--after-build', '.');
787 info
(describe_build
($changes->{'Files'}));
790 enabled
=> $check_command,
792 DPKG_BUILDPACKAGE_HOOK_CHECK_OPTIONS
=> join(' ', @check_opts),
796 if ($check_command) {
797 run_cmd
($check_command, @check_opts, $changes_file);
800 if ($signpause && ($signsource || $signbuildinfo || $signchanges)) {
801 print g_
("Press <enter> to start the signing process.\n");
806 enabled
=> $signsource || $signbuildinfo || $signchanges,
812 # Recompute the checksums as the .dsc has changed now.
813 my $buildinfo = Dpkg
::Control
->new(type
=> CTRL_FILE_BUILDINFO
);
814 $buildinfo->load($buildinfo_file);
815 my $checksums = Dpkg
::Checksums
->new();
816 $checksums->add_from_control($buildinfo);
817 $checksums->add_from_file("../$pv.dsc", update
=> 1, key
=> "$pv.dsc");
818 $checksums->export_to_control($buildinfo);
819 $buildinfo->save($buildinfo_file);
821 if ($signbuildinfo) {
822 signfile
("$pva.buildinfo");
824 if ($signsource or $signbuildinfo) {
825 # Recompute the checksums as the .dsc and/or .buildinfo have changed.
826 my $checksums = Dpkg
::Checksums
->new();
827 $checksums->add_from_control($changes);
828 $checksums->add_from_file("../$pv.dsc", update
=> 1, key
=> "$pv.dsc")
830 $checksums->add_from_file($buildinfo_file, update
=> 1, key
=> "$pva.buildinfo");
831 $checksums->export_to_control($changes);
832 delete $changes->{'Checksums-Md5'};
833 update_files_field
($changes, $checksums, "$pv.dsc")
835 update_files_field
($changes, $checksums, "$pva.buildinfo");
836 $changes->save($changes_file);
839 signfile
("$pva.changes");
842 if (not $signreleased) {
843 warning
(g_
('not signing UNRELEASED build; use --force-sign to override'));
846 if ($source_from_dsc) {
847 info
(g_
('removing extracted source directory %s'), $srcdir);
849 or syserr
(g_
('cannot change directory to %s'), '..');
850 remove_tree
($srcdir);
856 my ($var, $text) = @_;
858 error
(g_
('unable to determine %s'), $text)
859 unless defined($var);
869 system @cmd and subprocerr
("@cmd");
873 my ($name, $opts) = @_;
874 my $cmd = $hook{$name};
875 $opts->{enabled
} //= 1;
879 info
("running hook $name");
883 'a' => $opts->{enabled
} ?
1 : 0,
885 'v' => $version // q{},
886 's' => $sversion // q{},
887 'u' => $uversion // q{},
890 my $subst_hook_var = sub {
893 if (exists $hook_vars{$var}) {
894 return $hook_vars{$var};
896 warning
(g_
('unknown %% substitution in hook: %%%s'), $var);
901 $cmd =~ s/\%(.)/$subst_hook_var->($1)/eg;
903 $opts->{env
}{DPKG_BUILDPACKAGE_HOOK_NAME
} = $name;
905 # Set any environment variables for this hook invocation.
906 local @ENV{keys %{$opts->{env
}}} = values %{$opts->{env
}};
911 sub update_files_field
{
912 my ($ctrl, $checksums, $filename) = @_;
914 my $md5sum_regex = checksums_get_property
('md5', 'regex');
915 my $md5sum = $checksums->get_checksum($filename, 'md5');
916 my $size = $checksums->get_size($filename);
917 my $file_regex = qr/$md5sum_regex\s+\d+\s+(\S+\s+\S+\s+\Q$filename\E)/;
919 $ctrl->{'Files'} =~ s/^$file_regex$/$md5sum $size $1/m;
922 sub signkey_validate
{
923 return unless $signkey->type eq 'keyid';
925 if (length $signkey->handle <= 8) {
926 error
(g_
('short OpenPGP key IDs are broken; ' .
927 'please use key fingerprints in %s or %s instead'),
928 '-k', 'DEB_SIGN_KEYID');
929 } elsif (length $signkey->handle <= 16) {
930 warning
(g_
('long OpenPGP key IDs are strongly discouraged; ' .
931 'please use key fingerprints in %s or %s instead'),
932 '-k', 'DEB_SIGN_KEYID');
938 my $signfile = "../$file";
940 printcmd
("signfile $file");
942 my $status = $openpgp->inline_sign($signfile, "$signfile.asc", $signkey);
943 if ($status == OPENPGP_OK
) {
944 move
("$signfile.asc", $signfile)
945 or syserror
(g_
('cannot move %s to %s'), "$signfile.asc", $signfile);
947 error
(g_
('failed to sign %s file: %s'), $signfile,
948 openpgp_errorcode_to_string
($status));
955 my ($files, $regex) = @_;
957 return $files !~ m/$regex$/m
962 my $ext = compression_get_file_extension_regex
();
964 if (fileomitted
($files, qr/\.deb/)) {
966 if (fileomitted
($files, qr/\.diff\.$ext/) and
967 fileomitted
($files, qr/\.debian\.tar\.$ext/)) {
968 return g_
('source-only upload: Debian-native package');
969 } elsif (fileomitted
($files, qr/\.orig\.tar\.$ext/)) {
970 return g_
('source-only, diff-only upload (original source NOT included)');
972 return g_
('source-only upload (original source is included)');
974 } elsif (fileomitted
($files, qr/\.dsc/)) {
975 return g_
('binary-only upload (no source included)');
976 } elsif (fileomitted
($files, qr/\.diff\.$ext/) and
977 fileomitted
($files, qr/\.debian\.tar\.$ext/)) {
978 return g_
('full upload; Debian-native package (full source is included)');
979 } elsif (fileomitted
($files, qr/\.orig\.tar\.$ext/)) {
980 return g_
('binary and diff upload (original source NOT included)');
982 return g_
('full upload (original source is included)');