]> git.donarmstrong.com Git - debhelper.git/blob - dh_builddeb
dh_builddeb: support for parallel builds of debs
[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 $processes=1;
67 my $max_procs=1;
68 if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS}=~/parallel=(\d+)/) {
69         $max_procs=$1;
70 }
71
72 foreach my $package (@{$dh{DOPACKAGES}}) {
73         my $pid=0;
74
75         if ($max_procs > 1) {
76                 while ($processes > $max_procs) {
77                         wait;
78                         $processes--;
79                 }
80                 $pid=fork();
81         }
82
83         if ($pid == 0) {
84                 my $tmp=tmpdir($package);
85                 if (exists $ENV{DH_ALWAYS_EXCLUDE} && length $ENV{DH_ALWAYS_EXCLUDE}) {
86                         if (! compat(5)) {
87                                 complex_doit("find $tmp $dh{EXCLUDE_FIND} | xargs rm -rf");
88                         }
89                         else {
90                                 # Old broken code here for compatibility. Does not
91                                 # remove everything.
92                                 complex_doit("find $tmp -name $_ | xargs rm -rf")
93                                         foreach split(":", $ENV{DH_ALWAYS_EXCLUDE});
94                         }
95                 }
96                 if (! is_udeb($package)) {
97                         doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$dh{FILENAME});
98                 }
99                 else {
100                         my $filename=$dh{FILENAME};
101                         if (! $filename) {
102                                 $filename="/".udeb_filename($package);
103                         }
104                         doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$filename);
105                 }
106                 exit (0) if ($max_procs > 1);
107         } else {
108                 if (!defined $pid) {
109                         error("fork failed!");
110                 }
111                 $processes++;
112         }
113 }
114 while (($max_procs > 0) && (wait != -1)) {}
115
116 =head1 SEE ALSO
117
118 L<debhelper(7)>
119
120 This program is a part of debhelper.
121
122 =head1 AUTHOR
123
124 Joey Hess <joeyh@debian.org>
125
126 =cut