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"};
60 # There is a dependency loop (gcc -> runtime/w32api -> gcc)
61 # which has to be manually resolved below. Break that loop.
62 my @gcc_brs = @{$br{"mingw-gcc"}};
63 @gcc_brs = grep { $_ ne "mingw-runtime" && $_ ne "mingw-w32api" } @gcc_brs;
64 $br{"mingw-gcc"} = \@gcc_brs;
66 # Use tsort to generate a topological ordering.
67 open TSORT,">/tmp/tsort.tmp" or die "/tmp/tsort.tmp: $!";
68 foreach $packagename (keys %br) {
70 foreach $br (@{$br{$packagename}}) {
71 print "writing $br $packagename\n" if $debug;
72 print TSORT $br, " ", $packagename, "\n";
77 system ("tsort < /tmp/tsort.tmp > /tmp/tsort2.tmp") == 0
78 or die "system: tsort: $?";
80 # Read in list of packages.
81 open PACKAGES,"/tmp/tsort2.tmp" or die "/tmp/tsort2.tmp: $!";
83 unlink "/tmp/tsort.tmp";
84 unlink "/tmp/tsort2.tmp";
93 print "considering $packagename\n" if $debug;
95 my @brs = @{$br{$packagename}};
97 # Are all BR RPMs installed?
100 if (! rpm_installed ($br)) {
101 print "as root # rpm -Uvh $br*.rpm\n";
105 # Special case for mingw-gcc deps.
106 if ($packagename eq "mingw-gcc" &&
107 (!rpm_installed ("mingw-runtime") ||
108 !rpm_installed ("mingw-w32api"))) {
109 print "rpmbuild -ba bootstrap/mingw-bootstrap.spec\n";
110 print "as root # rpm -Uvh mingw-bootstrap*.rpm\n"
114 my $specfile = "$dirname/$packagename.spec";
115 die "$specfile: file missing" unless -f $specfile;
117 print "rpmbuild -ba $specfile\n";
124 return (system ("rpm -q $_ > /dev/null") == 0);
138 $hash{$_} = 1 foreach (@_);
139 return sort keys %hash;
144 # and a few other exceptions
145 sub remove_trailers {
149 # -devel & -doc come from the base package.
154 s/^mingw-gcc-.*/mingw-gcc/;