]> git.donarmstrong.com Git - debhelper.git/blob - dh_builddeb
fix exit status propigation
[debhelper.git] / dh_builddeb
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_builddeb - build Debian binary packages
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_builddeb> [S<I<debhelper options>>] [B<--destdir=>I<directory>] [B<--filename=>I<name>] [S<B<--> I<params>>]
15
16 =head1 DESCRIPTION
17
18 B<dh_builddeb> simply calls L<dpkg-deb(1)> to build a Debian package or
19 packages.
20
21 =head1 OPTIONS
22
23 =over 4
24
25 =item B<--destdir=>I<directory>
26
27 Use this if you want the generated F<.deb> files to be put in a directory
28 other than the default of "F<..>".
29
30 =item B<--filename=>I<name>
31
32 Use this if you want to force the generated .deb file to have a particular
33 file name. Does not work well if more than one .deb is generated!
34
35 =item B<--> I<params>
36
37 Pass I<params> to L<dpkg-deb(1)> when it is used to build the
38 package.
39
40 =item B<-u>I<params>
41
42 This is another way to pass I<params> to L<dpkg-deb(1)>.
43 It is deprecated; use B<--> instead.
44
45 =back
46
47 =cut
48
49 init(options => {
50         "filename=s" => \$dh{FILENAME},
51         "destdir=s" => \$dh{DESTDIR},
52 });
53
54 # Set the default destination directory.
55 if (! defined $dh{DESTDIR}) {
56         $dh{DESTDIR}='..';
57 }
58
59 if (! defined $dh{FILENAME}) {
60         $dh{FILENAME}='';
61 }
62 else {
63         $dh{FILENAME}="/$dh{FILENAME}";
64 }
65
66 my $max_procs=1;
67 if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS}=~/parallel=(\d+)/) {
68         $max_procs=$1;
69 }
70
71 my $processes=1;
72 my $exit=0;
73 sub reap {
74         if (wait == -1) {
75                 $processes=0;
76         }
77         else {
78                 $processes--;
79                 $exit=1 if $? != 0;
80         }
81 }
82
83 foreach my $package (@{$dh{DOPACKAGES}}) {
84         my $pid=fork();
85         if (! defined $pid) {
86                 error("fork failed! $!");
87         }
88         $processes++;
89         if ($pid) { # parent
90                 reap while $processes > $max_procs;
91                 next;
92         }
93
94         # child
95         my $tmp=tmpdir($package);
96         if (exists $ENV{DH_ALWAYS_EXCLUDE} && length $ENV{DH_ALWAYS_EXCLUDE}) {
97                 if (! compat(5)) {
98                         complex_doit("find $tmp $dh{EXCLUDE_FIND} | xargs rm -rf");
99                 }
100                 else {
101                         # Old broken code here for compatibility. Does not
102                         # remove everything.
103                         complex_doit("find $tmp -name $_ | xargs rm -rf")
104                                 foreach split(":", $ENV{DH_ALWAYS_EXCLUDE});
105                 }
106         }
107         if (! is_udeb($package)) {
108                 doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$dh{FILENAME});
109         }
110         else {
111                 my $filename=$dh{FILENAME};
112                 if (! $filename) {
113                         $filename="/".udeb_filename($package);
114                 }
115                 doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$filename);
116         }
117         exit 0;
118 }
119
120 reap while $processes;
121 exit $exit;
122
123 =head1 SEE ALSO
124
125 L<debhelper(7)>
126
127 This program is a part of debhelper.
128
129 =head1 AUTHOR
130
131 Joey Hess <joeyh@debian.org>
132
133 =cut