3 # Show the order to build Fedora MinGW spec files.
4 # By Richard Jones <rjones@redhat.com>
9 chomp (my $pwd = `pwd`);
16 my @specfiles = <*/*.spec>;
18 # Get BRs for each specfile.
19 foreach $specfile (@specfiles) {
20 $packagename = $specfile;
21 $packagename =~ s{^.*/}{};
22 $packagename =~ s{\.spec$}{};
24 $br{$packagename} = [];
26 open SPEC,$specfile or die "$specfile: $!";
28 if (m/^BuildRequires:(.*)/) {
30 my @brs = eval 'split /,/, $brs';
31 @brs = map { trim ($_) } @brs;
32 @brs = map { remove_trailers ($_) } @brs;
33 unshift @{$br{$packagename}}, @brs;
38 print "BRs for $packagename = [";
39 print (join "],[", @{$br{$packagename}});
44 foreach $packagename (keys %br) {
45 my @brs = @{$br{$packagename}};
46 @brs = uniq (sort @brs);
47 $br{$packagename} = \@brs;
50 print "uniq BRs for $packagename = [";
51 print (join "],[", @{$br{$packagename}});
56 # Some packages we want to ignore for now.
57 delete $br{"mingw-cyrus-sasl"};
58 delete $br{"mingw-nsis"};
59 delete $br{"mingw-wix"};
60 delete $br{"mingw-example"};
61 delete $br{"mingw-gdb"};
63 # There is a dependency loop (gcc -> runtime/w32api -> gcc)
64 # which has to be manually resolved below. Break that loop.
65 my @gcc_brs = @{$br{"mingw-gcc"}};
66 @gcc_brs = grep { $_ ne "mingw-runtime" && $_ ne "mingw-w32api" } @gcc_brs;
67 $br{"mingw-gcc"} = \@gcc_brs;
69 # Use tsort to generate a topological ordering.
70 open TSORT,">/tmp/tsort.tmp" or die "/tmp/tsort.tmp: $!";
71 foreach $packagename (keys %br) {
73 foreach $br (@{$br{$packagename}}) {
74 print "writing $br $packagename\n" if $debug;
75 print TSORT $br, " ", $packagename, "\n";
80 system ("tsort < /tmp/tsort.tmp > /tmp/tsort2.tmp") == 0
81 or die "system: tsort: $?";
83 # Read in list of packages.
84 open PACKAGES,"/tmp/tsort2.tmp" or die "/tmp/tsort2.tmp: $!";
86 unlink "/tmp/tsort.tmp";
87 unlink "/tmp/tsort2.tmp";
98 print "considering $packagename\n" if $debug;
100 my @brs = @{$br{$packagename}};
102 # Are all BR RPMs installed?
105 if (! rpm_installed ($br) && !exists $installed{$br}) {
106 print "# as root: rpm -Uvh $br*.rpm\n";
111 # Special case for mingw-gcc deps.
112 if ($packagename eq "mingw-gcc" &&
113 (!rpm_installed ("mingw-runtime") ||
114 !rpm_installed ("mingw-w32api"))) {
115 print "rpmbuild -ba --define \"_sourcedir $pwd/runtime-bootstrap\" runtime-bootstrap/mingw-runtime-bootstrap.spec\n";
116 print "# as root: rpm -Uvh mingw-runtime-bootstrap*.rpm\n";
117 $installed{"mingw-runtime-bootstrap"} = 1;
119 print "rpmbuild -ba --define \"_sourcedir $pwd/w32api-bootstrap\" w32api-bootstrap/mingw-w32api-bootstrap.spec\n";
120 print "# as root: rpm -Uvh mingw-w32api-bootstrap*.rpm\n";
121 $installed{"mingw-w32api-bootstrap"} = 1;
125 my $specfile = "$dirname/$packagename.spec";
126 die "$specfile: file missing" unless -f $specfile;
129 "rpmbuild -ba --define \"_sourcedir $pwd/$dirname\"";
130 print "$rpmbuild $specfile\n";
137 return (system ("rpm -q $_ > /dev/null") == 0);
151 $hash{$_} = 1 foreach (@_);
152 return sort keys %hash;
157 # and a few other exceptions
158 sub remove_trailers {
162 # -devel & -doc come from the base package.
167 s/^mingw-gcc-.*/mingw-gcc/;