newlib/winsup/cygwin/speclib

53 lines
1.1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl
use Getopt::Long;
use File::Temp qw'tempdir';
use File::Basename;
use strict;
my $nm = shift;
my $dlltool = shift;
my $def = shift;
my $lib = pop;
my $inverse;
if ($ARGV[$#ARGV] ne '-v') {
$inverse = 0;
} else {
$inverse = 1;
$#ARGV--;
}
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
die "$0: execution of $nm for object files failed - $!\n";
while (<$nm_fd>) {
next unless /\S+\s+[A-Z]+\s+_(.*)$/o;
if ($inverse) {
delete $defsyms{$1};
} else {
$newdef .= $defsyms{$1} if exists $defsyms{$1};
}
}
close $nm_fd;
$newdef .= join '', sort values %defsyms if $inverse;
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;
exit 0;