3 # mk-build-deps: make a dummy package to satisfy build-deps of a package
4 # Copyright 2008 by Vincent Fourmond
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 # * (Vincent Fourmond 4/4/2008): now take Build-Depends-Indep
26 mk-build-deps - build a package satisfying a package's build-dependencies
30 B<mk-build-deps> --help|--version
32 B<mk-build-deps> [options] <control file | package name> [...]
36 Given a package name and/or control file, B<mk-build-deps>
37 will use B<equivs> to generate a binary package which may be installed to
38 satisfy all the build dependencies of the given package.
40 If B<--build-dep> and/or B<--build-indep> are given, then the resulting binary
41 package(s) will depend solely on the Build-Depends/Build-Depends-Indep
42 dependencies, respectively.
48 =item B<-i>, B<--install>
50 Install the generated packages and its build-dependencies.
52 =item B<-t>, B<--tool>
54 When installing the generated package use the specified tool.
57 =item B<-r>, B<--remove>
59 Remove the package file after installing it. Ignored if used without
62 =item B<-a> I<foo>, B<--arch> I<foo>
64 If the source package has architecture-specific build dependencies, produce
65 a package for architecture I<foo>, not for the system architecture. (If the
66 source package does not have architecture-specific build dependencies,
67 the package produced is always for the pseudo-architecture B<all>.)
69 =item B<-B>, B<--build-dep>
71 Generate a package which only depends on the source package's Build-Depends
74 =item B<-A>, B<--build-indep>
76 Generate a package which only depends on the source package's
77 Build-Depends-Indep dependencies.
79 =item B<-h>, B<--help>
81 Show a summary of options.
83 =item B<-v>, B<--version>
85 Show version and copyright information.
91 B<mk-build-deps> is copyright by Vincent Fourmond and was modified for the
92 devscripts package by Adam D. Barratt <adam@adam-barratt.org.uk>.
94 This program comes with ABSOLUTELY NO WARRANTY.
95 You are free to redistribute this code under the terms of the GNU
96 General Public License, version 2 or later.
107 my $progname = basename($0);
110 my ($opt_help, $opt_version, $opt_arch, $opt_dep, $opt_indep);
116 my @config_files = ('/etc/devscripts.conf', '~/.devscripts');
118 'MKBUILDDEPS_TOOL' => 'apt-get',
119 'MKBUILDDEPS_REMOVE_AFTER_INSTALL' => 'no'
121 my %config_default = %config_vars;
125 foreach my $var (keys %config_vars) {
126 $shell_cmd .= qq[$var="$config_vars{$var}";\n];
128 $shell_cmd .= 'for file in ' . join(" ",@config_files) . "; do\n";
129 $shell_cmd .= '[ -f $file ] && . $file; done;' . "\n";
131 foreach my $var (keys %config_vars) { $shell_cmd .= "echo \$$var;\n" }
132 my $shell_out = `/bin/bash -c '$shell_cmd'`;
133 @config_vars{keys %config_vars} = split /\n/, $shell_out, -1;
136 $config_vars{'MKBUILDDEPS_TOOL'} =~ /./
137 or $config_vars{'MKBUILDDEPS_TOOL'}='/usr/bin/apt-get';
138 $config_vars{'MKBUILDDEPS_REMOVE_AFTER_INSTALL'} =~ /^(yes|no)$/
139 or $config_vars{'MKBUILDDEPS_REMOVE_AFTER_INSTALL'}='no';
141 $install_tool = $config_vars{'MKBUILDDEPS_TOOL'};
143 if ($config_vars{'MKBUILDDEPS_REMOVE_AFTER_INSTALL'} =~ /yes/) {
148 GetOptions("help|h" => \$opt_help,
149 "version|v" => \$opt_version,
150 "install|i" => \$opt_install,
151 "remove|r" => \$opt_remove,
152 "tool|t=s" => \$install_tool,
153 "arch|a=s" => \$opt_arch,
154 "build-dep|B" => \$opt_dep,
155 "build-indep|A" => \$opt_indep,
157 or pod2usage({ -exitval => 1, -verbose => 0 });
159 pod2usage({ -exitval => 0, -verbose => 1 }) if ($opt_help);
160 if ($opt_version) { version(); exit 0; }
163 if (-r 'debian/control') {
164 push(@ARGV, 'debian/control');
168 pod2usage({ -exitval => 1, -verbose => 0 }) unless @ARGV;
170 system("command -v equivs-build >/dev/null 2>&1");
172 die "$progname: You must have equivs installed to use this program.\n";
175 while ($control = shift) {
177 if (-r $control and -f $control) {
178 open $fh, $control || do {
179 warn "Unable to open $control: $!\n";
185 open $fh, "apt-cache showsrc $control |" || do {
186 warn "Unable to run apt-cache: $!\n";
192 my $ctrl = Dpkg::Control->new(type => CTRL_INFO_SRC);
193 if ($ctrl->parse($fh, $control)) {
196 my ($build_deps, $build_dep, $build_indep);
198 if (exists $ctrl->{'Build-Depends'}) {
199 $build_dep = $ctrl->{'Build-Depends'};
200 $build_dep =~ s/\n/ /g;
201 $build_deps = $build_dep;
203 if (exists $ctrl->{'Build-Depends-Indep'}) {
204 $build_indep = $ctrl->{'Build-Depends-Indep'};
205 $build_indep =~ s/\n/ /g;
206 $build_deps .= ', ' if $build_deps;
207 $build_deps .= $build_indep;
210 die "$progname: Unable to find build-deps for $ctrl->{$name}\n" unless $build_deps;
212 # Only build a package with both B-D and B-D-I in Depends if the
213 # B-D/B-D-I specific packages weren't requested
214 if (!($opt_dep || $opt_indep)) {
216 build_equiv({ depends => $build_deps,
217 name => $ctrl->{$name},
218 type => 'build-deps',
219 version => $ctrl->{Version} }));
224 build_equiv({ depends => $build_dep,
225 name => $ctrl->{$name},
226 type => 'build-deps-depends',
227 version => $ctrl->{Version} }));
231 build_equiv({ depends => $build_indep,
232 name => $ctrl->{$name},
233 type => 'build-deps-indep',
234 version => $ctrl->{Version} }));
238 die "$progname: Unable to find package name in '$control'\n";
242 use Text::ParseWords;
245 for my $package (@packages) {
246 my $file = glob "${package}_*.deb";
247 push @deb_files, $file;
250 system 'dpkg', '--unpack', @deb_files;
251 system shellwords($install_tool), '-f', 'install';
254 foreach my $file (@deb_files) {
262 This is $progname, from the Debian devscripts package, version ###VERSION###
263 Copyright (C) 2008 Vincent Fourmond
265 This program comes with ABSOLUTELY NO WARRANTY.
266 You are free to redistribute this code under the terms of the
267 GNU General Public License, version 2, or (at your option) any
278 if ($opts->{depends} =~ /\[|\]/) {
281 if (defined $opt_arch) {
282 $args = "--arch=$opt_arch ";
286 open EQUIVS, "| equivs-build $args-"
287 or die "$progname: Failed to execute equivs-build: $!\n";
288 print EQUIVS "Section: devel\n" .
289 "Priority: optional\n".
290 "Standards-Version: 3.7.3\n\n".
291 "Package: $opts->{name}-$opts->{type}\n".
292 "Architecture: $arch\n".
293 "Depends: build-essential, $opts->{depends}\n";
294 print EQUIVS "Version: $opts->{version}\n" if $opts->{version};
296 print EQUIVS "Description: build-dependencies for $opts->{name}\n" .
297 " Depencency package to build the '$opts->{name}' package\n";
300 return "$opts->{name}-$opts->{type}";