Fix (hopefully) some oversights in recent Bison cleanup patch.
[PostgreSQL.git] / src / tools / msvc / gendef.pl
blobd30417c009f1094c4c79c8cce197c2894601edbf
1 my @def;
3 # Script that generates a .DEF file for all objects in a directory
4 #
5 # $PostgreSQL$
8 die "Usage: gendef.pl <modulepath>\n" unless ($ARGV[0] =~ /\\([^\\]+$)/);
9 my $defname = uc $1;
11 if (-f "$ARGV[0]/$defname.def")
13 print "Not re-generating $defname.DEF, file already exists.\n";
14 exit(0);
17 print "Generating $defname.DEF from directory $ARGV[0]\n";
19 while (<$ARGV[0]/*.obj>)
21 my $symfile = $_;
22 $symfile=~ s/\.obj$/.sym/i;
23 print ".";
24 system("dumpbin /symbols /out:symbols.out $_ >NUL") && die "Could not call dumpbin";
25 open(F, "<symbols.out") || die "Could not open symbols.out for $_\n";
26 while (<F>)
28 s/\(\)//g;
29 my @pieces = split;
30 next unless $pieces[0] =~ /^[A-F0-9]{3,}$/;
31 next unless $pieces[6];
32 next if ($pieces[2] eq "UNDEF");
33 next unless ($pieces[4] eq "External");
34 next if $pieces[6] =~ /^@/;
35 next if $pieces[6] =~ /^\(/;
36 next if $pieces[6] =~ /^__real/;
37 next if $pieces[6] =~ /^__imp/;
38 next if $pieces[6] =~ /NULL_THUNK_DATA$/;
39 next if $pieces[6] =~ /^__IMPORT_DESCRIPTOR/;
40 next if $pieces[6] =~ /^__NULL_IMPORT/;
41 next if $pieces[6] =~ /^\?\?_C/;
43 push @def, $pieces[6];
45 close(F);
46 rename("symbols.out",$symfile);
48 print "\n";
50 open(DEF,">$ARGV[0]/$defname.def") || die "Could not write to $defname\n";
51 print DEF "EXPORTS\n";
52 my $i = 0;
53 my $last = "";
54 foreach my $f (sort @def)
56 next if ($f eq $last);
57 $last = $f;
58 $f =~ s/^_//;
59 $i++;
61 # print DEF " $f \@ $i\n"; # ordinaled exports?
62 print DEF " $f\n";
64 close(DEF);
65 print "Generated $i symbols\n";