1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use warnings; |
---|
4 | use strict; |
---|
5 | |
---|
6 | my $psuite = $ARGV[0]; |
---|
7 | $psuite or die "Usage: gen-build-deps <previous suite name>"; |
---|
8 | $ENV{DEBATHENA_APT} or $ENV{DEBATHENA_APT}="/mit/debathena/apt"; |
---|
9 | |
---|
10 | sub list { |
---|
11 | my ($l) = @_; |
---|
12 | my @a = split(/, /, $l); |
---|
13 | foreach (@a) { |
---|
14 | s/ \(.*\)$//; |
---|
15 | s/ \|.*$//; |
---|
16 | s/ \[.*$//; |
---|
17 | } |
---|
18 | return @a; |
---|
19 | } |
---|
20 | |
---|
21 | # For each source package, add its build-deps to the list |
---|
22 | open(DPKG, '-|', "zcat $ENV{DEBATHENA_APT}/dists/$psuite/*/source/Sources.gz | dpkg-awk -f - -- Package Build-Depends") or die; |
---|
23 | my %src_deps = (); |
---|
24 | while (<DPKG>) { |
---|
25 | last if /^$/; |
---|
26 | my ($source) = /^Package: (.*)$/ or die; |
---|
27 | @{$src_deps{$source}} = (); |
---|
28 | while (<DPKG>) { |
---|
29 | last if ($_ eq "\n"); |
---|
30 | if (my ($depends) = /^Build-Depends: (.*)$/) { |
---|
31 | push @{$src_deps{$source}}, $_ for (list($depends)); |
---|
32 | } else { |
---|
33 | die; |
---|
34 | } |
---|
35 | } |
---|
36 | } |
---|
37 | close DPKG; |
---|
38 | |
---|
39 | # For each binary package, add itself as a source and provider. If |
---|
40 | # there are actually different Sources and Provides for the package, |
---|
41 | # use them instead. Note: This will fail miserably if we ever build |
---|
42 | # packages only for one architecture. |
---|
43 | open(DPKG, '-|', "zcat $ENV{DEBATHENA_APT}/dists/$psuite/debathena/binary-amd64/Packages.gz | dpkg-awk -f - -- Package Source Provides Depends") or die; |
---|
44 | my %pkg_src = (); |
---|
45 | my %pkg_provider = (); |
---|
46 | my %pkg_deps=(); |
---|
47 | while (<DPKG>) { |
---|
48 | last if /^$/; |
---|
49 | my ($package) = /^Package: (.*)$/ or die; |
---|
50 | $pkg_src{$package} = $package; |
---|
51 | $pkg_provider{$package} = $package; |
---|
52 | @{$pkg_deps{$package}} = (); |
---|
53 | while (<DPKG>) { |
---|
54 | last if ($_ eq "\n"); |
---|
55 | if (my ($source) = /^Source: (.*)$/) { |
---|
56 | $pkg_src{$package} = $source; |
---|
57 | } elsif (my ($provides) = /^Provides: (.*)$/) { |
---|
58 | $pkg_provider{$_} = $package for (list($provides)); |
---|
59 | } elsif (my ($depends) = /^Depends: (.*)$/) { |
---|
60 | push @{$pkg_deps{$package}}, $_ for (list($depends)); |
---|
61 | } else { |
---|
62 | die; |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | for my $source (keys %src_deps) { |
---|
68 | print "build-all: \$(call package,$source)\n"; |
---|
69 | if ($source ne "debathena-build-depends") { |
---|
70 | print "\$(call package,debathena-build-depends): \$(call package,$source)\n"; |
---|
71 | } |
---|
72 | for (@{$src_deps{$source}}) { |
---|
73 | print "\$(call package,$source): \$(call package,$pkg_src{$pkg_provider{$_}})\n" if (defined $pkg_provider{$_}); |
---|
74 | foreach my $dep (@{$pkg_deps{$_}}) { |
---|
75 | print "\$(call package,$source): \$(call package,$pkg_src{$dep})\n" if (defined $pkg_provider{$dep}); |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|