-foreach my $name (@names) {
- my @buildrequires = @{$srpms{$name}->{buildrequires}};
- foreach (@buildrequires) {
- print $fh "$_ $name\n"
+ my ($fh, $filename) = tempfile ();
+
+ foreach my $name (@names) {
+ my @buildrequires = @{$srpms{$name}->{buildrequires}};
+ foreach (@buildrequires) {
+ print $fh "$_ $name\n"
+ }
+ # Add a self->self dependency. This ensures that any
+ # packages which don't have or appear as a dependency of
+ # any other package still get built.
+ print $fh "$name $name\n"
+ }
+ close $fh;
+
+ get_lines "tsort $filename";
+}
+
+# Sort the initial list of package names.
+
+my @names = sort keys %srpms;
+my @buildorder = tsort (@names);
+
+# With --chain flag we print the packages in groups for chain building.
+
+if ($chain) {
+ my %group = ();
+ my $name;
+
+ print 'make chain-build CHAIN="';
+
+ foreach $name (@buildorder) {
+ my @br = @{$srpms{$name}->{buildrequires}};
+
+ # If a BR occurs within the current group, then start the next group.
+ my $occurs = 0;
+ foreach (@br) {
+ if (exists $group{$_}) {
+ $occurs = 1;
+ last;
+ }
+ }
+
+ if ($occurs) {
+ %group = ();
+ print ": ";
+ }
+
+ $group{$name} = 1;
+ print "$name ";