summaryrefslogtreecommitdiff
path: root/Build/source/mswin32/fix-depend.pl
blob: a57a16e76f56bb8ecd438300c4fe0431388fee2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# Split makedepend generated lines
# to get at most one dependency per line
# to facilitate diffs
#
my $line;
my $depline;
my $target;
my @dep;
my %dependencies;
my @preamble;
my @postamble;
my @unmatched;

while (<>) {
  chomp;
  $line = $_;
  if ($line =~ m/^#/) {
    if (keys %dependencies) {
      push @postamble, $line;
    }
    else {
      push @preamble, $line;
    }
    break;
  }
  elsif ($line =~ m/^([^\s].*):\s+(.*)$/) {
    # new dependency
    $target = $1;
    push @{$dependencies{$target}}, $2;
    break;
  }
  elsif ($line =~ m/^\s+(.*)\s+\\$/) {
    # continuation
    push @{$dependencies{$target}}, $1;
    break;
  }
  elsif ($line =~ m/^\s+(.*)$/) {
    # final
    push @{$dependencies{$target}}, $1;
    break;
  }
  else {
    if ($line =~ m/[^\s]/) {
      push @unmatched, $line;
    }
  }

}

END {
  map { print "$_\n"; } @preamble;
  map {
    print "$_: \\\n";
    $depline = join (" ", @{$dependencies{$_}});
    my @dep = split("[ \t]", $depline);
    @dep = grep { $_ !~ m/^(\s*|\s*\\)$/ } @dep;
    $depline = join " \\\n\t", @dep;
    $depline = "\t" . $depline . "\n";
    print $depline;
    # skip one line
    print "\n";
  } (keys %dependencies);
  map { print "$_\n"; } @postamble;
  map { print STDERR "unmatched: $_\n"; } @unmatched;
}