summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/speclib
blob: bea9cbc4aff17cbcba221527efbdf02455168ecb (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
#!/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;