]> granicus.if.org Git - postgresql/blob - src/tools/msvc/gendef.pl
Run newly-configured perltidy script on Perl files.
[postgresql] / src / tools / msvc / gendef.pl
1 my @def;
2
3 #
4 # Script that generates a .DEF file for all objects in a directory
5 #
6 # src/tools/msvc/gendef.pl
7 #
8
9 die "Usage: gendef.pl <modulepath> <platform>\n"
10   unless (($ARGV[0] =~ /\\([^\\]+$)/)
11         && ($ARGV[1] == 'Win32' || $ARGV[1] == 'x64'));
12 my $defname  = uc $1;
13 my $platform = $ARGV[1];
14
15 if (-f "$ARGV[0]/$defname.def")
16 {
17         print "Not re-generating $defname.DEF, file already exists.\n";
18         exit(0);
19 }
20
21 print "Generating $defname.DEF from directory $ARGV[0], platform $platform\n";
22
23 while (<$ARGV[0]/*.obj>)
24 {
25         my $symfile = $_;
26         $symfile =~ s/\.obj$/.sym/i;
27         print ".";
28         system("dumpbin /symbols /out:symbols.out $_ >NUL")
29           && die "Could not call dumpbin";
30         open(F, "<symbols.out") || die "Could not open symbols.out for $_\n";
31         while (<F>)
32         {
33                 s/\(\)//g;
34                 my @pieces = split;
35                 next unless $pieces[0] =~ /^[A-F0-9]{3,}$/;
36                 next unless $pieces[6];
37                 next if ($pieces[2] eq "UNDEF");
38                 next unless ($pieces[4] eq "External");
39                 next if $pieces[6] =~ /^@/;
40                 next if $pieces[6] =~ /^\(/;
41                 next if $pieces[6] =~ /^__real/;
42                 next if $pieces[6] =~ /^__imp/;
43                 next if $pieces[6] =~ /NULL_THUNK_DATA$/;
44                 next if $pieces[6] =~ /^__IMPORT_DESCRIPTOR/;
45                 next if $pieces[6] =~ /^__NULL_IMPORT/;
46                 next if $pieces[6] =~ /^\?\?_C/;
47
48                 push @def, $pieces[6];
49         }
50         close(F);
51         rename("symbols.out", $symfile);
52 }
53 print "\n";
54
55 open(DEF, ">$ARGV[0]/$defname.def") || die "Could not write to $defname\n";
56 print DEF "EXPORTS\n";
57 my $i    = 0;
58 my $last = "";
59 foreach my $f (sort @def)
60 {
61         next if ($f eq $last);
62         $last = $f;
63         $f =~ s/^_//
64           unless ($platform eq "x64");    # win64 has new format of exports
65         $i++;
66
67         #   print DEF "  $f \@ $i\n";  # ordinaled exports?
68         print DEF "  $f\n";
69 }
70 close(DEF);
71 print "Generated $i symbols\n";