#! /usr/bin/perl -w use strict; use Dpkg::Deps; # Get the first in a list of or-ed dependencies. sub first_dep ($) { my $inner = shift; while ($inner->isa('Dpkg::Deps::OR')) { my @deps = $inner->get_deps(); $inner = $deps[0]; } unless ($inner->isa('Dpkg::Deps::Simple')) { die sprintf "Couldn't reduce %s to a simple dependency!\n", $inner->dump(); } return $inner; } my $control = 'debian/control'; unless (-e $control) { $control = '../debian/control'; unless (-e $control) { die "cannot find debian/control"; } } my %builddeps; # Always include base ubiquity build dependencies. my @basebd = ( 'apt', 'dctrl-tools', 'debhelper (>= 7.0.1)', 'dh-di (>= 3)', 'dpkg-dev (>= 1.14.4)', 'intltool (>= 0.40.0)', 'keymapper (>= 0.5.3-7)', 'po-debconf (>= 1.0)', 'python-all-dev (>= 2.6)', 'python-central (>= 0.5)', 'xkb-data (>= 0.9)', 'xkb-data-i18n', ); my $basebd = join ', ', @basebd; my $parsed = Dpkg::Deps::parse($basebd, reduce_arch => 1); for my $bd ($parsed->get_deps()) { my $firstbd = first_dep($bd); $builddeps{$firstbd->{package}} = $firstbd; } for my $source () { # We don't build console-setup, so skip its build-dependencies. next if $source eq 'source/console-setup/debian/control'; open SOURCE, '<', $source or die "can't open $source: $!"; while () { if (/^Build-Depends(?:-Indep)?:\s*(.*)/i) { $parsed = Dpkg::Deps::parse($1, reduce_arch => 1); for my $bd ($parsed->get_deps()) { # Reduce any or-ed dependencies to the first # alternative. my $firstbd = first_dep($bd); my $package = $firstbd->{package}; if (not exists $builddeps{$package} or $firstbd->implies($builddeps{$package})) { $builddeps{$package} = $firstbd; } } next; } } close SOURCE; } my $builddeps = join ', ', map { $builddeps{$_}->dump() } sort keys %builddeps; open IN, '<', $control or die "can't open $control: $!"; open OUT, '>', "$control.tmp" or die "can't open $control.tmp for writing: $!"; foreach () { s/^(Build-Depends:\s*)(.*)/$1$builddeps/; print OUT or die "can't print to $control.tmp: $!"; } close OUT or die "can't close $control.tmp: $!"; close IN; rename "$control.tmp", $control or die "can't rename $control.tmp to $control: $!";