#!/usr/bin/perl

# the file bla.txt is grabbed from nohup output written while
# compiling the gcj compiler (with static libgcj.a). It provides
# the list, which *.o's (with path) are linked into the libgcj.a.
# We need the -fPIC variants of this source files (not mangled
# with the libtool extension "ltNumber-bla.o".

open(INF, "bla.txt") || die;
while(<INF>)
{
  chomp;
  if (m#(\S+)\s+(\S+)#s)
  {
    my $a = $1;
    my $b = $2;
    $b =~ s#^.*/##s;
    if (!($a =~ m#\.a/#s))
    {
      $a =~ s#[^/]+$#.libs/$&#s;
      $a =~ s#\.libs/\.libs#.libs#s;
    }
    $ALL{$b} = $a;
  }
  else
  {
    m#([^/]+)$# || die($_);
    my $a = $_;
    my $b = $1;
    if (!defined($ALL{$b}))
      {
      if (!($a =~ m#\.a/#s))
      {
        $a =~ s#[^/]+$#.libs/$&#s;
        $a =~ s#\.libs/\.libs#.libs#s;
      }
      $ALL{$b} = $a;
      #print "ALL{$b}=$ALL{$b}\n";
    }
  }
}
close(INF);

foreach(`ls agcj/*.o`)
{
  chomp;
  s#.*/##s;
  if (defined($ALL{$_}))
  {
    if (-f "libgcj/$ALL{$_}")
    {
      print "$ALL{$_}\n";
    }
    else
    {
      print STDERR "no $_=libgcj/$ALL{$_}\n";
    }
  }
  else
  {
    print "Missing: $_\n";
  }
}
