#! /usr/bin/env perl # reads a list of dependency files from a file, opens and # concatenates them, while eliding duplicate nop rules. sub read_depfiles($) { my $name = shift; my $depfh; my @files; open ($depfh, $name) || die "Can't open list of dependencies: $name: $!"; while (<$depfh>) { push @files, split(/\s+/, $_); } close ($depfh); # print STDERR "dep files: " . join ("'", @files) . "\n"; return @files; } my @depfiles = read_depfiles (shift @ARGV); my %rules; print "# concatenated, reduced dependencies generated by solenv/bin/concat-deps.pl\n"; for my $fname (@depfiles) { my $fileh; next if ($fname eq ''); open ($fileh, $fname) || die "Can't open $fname: $!\n"; my $last = ''; while (<$fileh>) { my $line = $_; if ($line eq "\n") { if ($last =~ /^(.*):\s*$/) { if (defined $rules{$1}) { $last = ''; next; } $rules{$1} = 1; } } print $last; $last = $line; } print $last; close ($fileh); }