4 # Script that generates a .DEF file for all objects in a directory
6 # src/tools/msvc/gendef.pl
9 die "Usage: gendef.pl <modulepath> <platform>\n"
10 unless (($ARGV[0] =~ /\\([^\\]+$)/)
11 && ($ARGV[1] == 'Win32' || $ARGV[1] == 'x64'));
13 my $platform = $ARGV[1];
15 if (-f "$ARGV[0]/$defname.def")
17 print "Not re-generating $defname.DEF, file already exists.\n";
21 print "Generating $defname.DEF from directory $ARGV[0], platform $platform\n";
23 while (<$ARGV[0]/*.obj>)
26 $symfile =~ s/\.obj$/.sym/i;
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";
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/;
48 push @def, $pieces[6];
51 rename("symbols.out", $symfile);
55 open(DEF, ">$ARGV[0]/$defname.def") || die "Could not write to $defname\n";
56 print DEF "EXPORTS\n";
59 foreach my $f (sort @def)
61 next if ($f eq $last);
64 unless ($platform eq "x64"); # win64 has new format of exports
67 # print DEF " $f \@ $i\n"; # ordinaled exports?
71 print "Generated $i symbols\n";