2009-01-02 07:57:14 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use Getopt::Long;
|
|
|
|
use File::Temp qw'tempdir';
|
|
|
|
use File::Basename;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $nm = shift;
|
2009-03-28 05:55:36 +01:00
|
|
|
my $dlltool = shift;
|
|
|
|
my $def = shift;
|
|
|
|
my $lib = pop;
|
|
|
|
|
|
|
|
my $inverse;
|
|
|
|
if ($ARGV[$#ARGV] ne '-v') {
|
|
|
|
$inverse = 0;
|
|
|
|
} else {
|
|
|
|
$inverse = 1;
|
|
|
|
$#ARGV--;
|
|
|
|
}
|
2009-01-02 07:57:14 +01:00
|
|
|
|
2009-03-28 05:55:36 +01:00
|
|
|
open my $def_fd, '<', $def or die "$0: couldn't open \"$def\" - $!\n";
|
|
|
|
my %defsyms = ();
|
|
|
|
my $newdef = '';
|
|
|
|
while (<$def_fd>) {
|
|
|
|
if (/^\s*(?:EXPORTS\b|LIBRARY\b|\s*$)/o) {
|
|
|
|
$newdef .= $_;
|
|
|
|
} else {
|
|
|
|
my $sym = (split ' ')[0];
|
|
|
|
$defsyms{$sym} = $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $def_fd;
|
|
|
|
|
|
|
|
open my $nm_fd, '-|', $nm, '-pg', '--defined-only', @ARGV or
|
2009-01-02 07:57:14 +01:00
|
|
|
die "$0: execution of $nm for object files failed - $!\n";
|
|
|
|
|
|
|
|
while (<$nm_fd>) {
|
2009-03-28 05:55:36 +01:00
|
|
|
next unless /\S+\s+[A-Z]+\s+_(.*)$/o;
|
|
|
|
if ($inverse) {
|
|
|
|
delete $defsyms{$1};
|
|
|
|
} else {
|
|
|
|
$newdef .= $defsyms{$1} if exists $defsyms{$1};
|
|
|
|
}
|
2009-01-02 07:57:14 +01:00
|
|
|
}
|
|
|
|
close $nm_fd;
|
|
|
|
|
2009-03-28 05:55:36 +01:00
|
|
|
$newdef .= join '', sort values %defsyms if $inverse;
|
2009-01-02 07:57:14 +01:00
|
|
|
|
2009-03-28 05:55:36 +01:00
|
|
|
open my $dlltool_fd, '|-', $dlltool, '-d', '/proc/self/fd/0', '-D', 'cygwin1.dll', '-l', $lib or
|
|
|
|
die "$0: couldn't start dlltool - $dlltool - $!\n";
|
|
|
|
print $dlltool_fd $newdef;
|
|
|
|
close $dlltool_fd or exit 1;
|
2009-01-02 07:57:14 +01:00
|
|
|
exit 0;
|