3 # Build Fedora MinGW spec files in correct order.
4 # By Richard Jones <rjones@redhat.com>
15 my @specfiles = <*/*.spec>;
17 # Get BRs for each specfile.
18 foreach $specfile (@specfiles) {
19 $packagename = $specfile;
20 $packagename =~ s{^.*/}{};
21 $packagename =~ s{\.spec$}{};
23 $br{$packagename} = [];
25 open SPEC,$specfile or die "$specfile: $!";
27 if (m/^BuildRequires:(.*)/) {
29 my @brs = eval 'split /,/, $brs';
30 @brs = map { trim ($_) } @brs;
31 @brs = map { remove_trailers ($_) } @brs;
32 unshift @{$br{$packagename}}, @brs;
37 print "BRs for $packagename = [";
38 print (join "],[", @{$br{$packagename}});
43 foreach $packagename (keys %br) {
44 my @brs = @{$br{$packagename}};
45 @brs = uniq (sort @brs);
46 $br{$packagename} = \@brs;
49 print "uniq BRs for $packagename = [";
50 print (join "],[", @{$br{$packagename}});
55 # Some packages we want to ignore for now.
56 delete $br{"mingw-cyrus-sasl"};
57 delete $br{"mingw-nsis"};
58 delete $br{"mingw-wix"};
59 delete $br{"mingw-example"};
61 # There is a dependency loop (gcc -> runtime/w32api -> gcc)
62 # which has to be manually resolved below. Break that loop.
63 my @gcc_brs = @{$br{"mingw-gcc"}};
64 @gcc_brs = grep { $_ ne "mingw-runtime" && $_ ne "mingw-w32api" } @gcc_brs;
65 $br{"mingw-gcc"} = \@gcc_brs;
67 # Use tsort to generate a topological ordering.
68 open TSORT,">/tmp/tsort.tmp" or die "/tmp/tsort.tmp: $!";
69 foreach $packagename (keys %br) {
71 foreach $br (@{$br{$packagename}}) {
72 print "writing $br $packagename\n" if $debug;
73 print TSORT $br, " ", $packagename, "\n";
78 system ("tsort < /tmp/tsort.tmp > /tmp/tsort2.tmp") == 0
79 or die "system: tsort: $?";
81 # Read in list of packages.
82 open PACKAGES,"/tmp/tsort2.tmp" or die "/tmp/tsort2.tmp: $!";
84 unlink "/tmp/tsort.tmp";
85 unlink "/tmp/tsort2.tmp";
96 print "considering $packagename\n" if $debug;
98 my @brs = @{$br{$packagename}};
100 # Are all BR RPMs installed?
103 if (! rpm_installed ($br) && !exists $installed{$br}) {
104 print "as root # rpm -Uvh $br*.rpm\n";
109 # Special case for mingw-gcc deps.
110 if ($packagename eq "mingw-gcc" &&
111 (!rpm_installed ("mingw-runtime") ||
112 !rpm_installed ("mingw-w32api"))) {
113 print "rpmbuild -ba bootstrap/mingw-bootstrap.spec\n";
114 print "as root # rpm -Uvh mingw-bootstrap*.rpm\n";
115 $installed{"mingw-bootstrap"} = 1;
119 my $specfile = "$dirname/$packagename.spec";
120 die "$specfile: file missing" unless -f $specfile;
122 print "rpmbuild -ba $specfile\n";
129 return (system ("rpm -q $_ > /dev/null") == 0);
143 $hash{$_} = 1 foreach (@_);
144 return sort keys %hash;
149 # and a few other exceptions
150 sub remove_trailers {
154 # -devel & -doc come from the base package.
159 s/^mingw-gcc-.*/mingw-gcc/;