Include <ucred.h> if we have getpeerucred()
[heimdal.git] / cf / w32-def-from-dll.pl
blobd7c412a405cf6085115542173cbe99b14c3a5009
1 my $show_module_name = 1;
2 my $use_indent = 1;
3 my $strip_leading_underscore = 0;
4 my $module_name = "";
5 my %target_exports = ();
6 my %local_exports = ();
8 sub build_target_exports_list($)
10 $fn = shift;
12 print STDERR "Processing defs from file [$fn]\n";
14 open(SP, '-|', "dumpbin /exports \"".$fn."\"") or die "Can't open pipe for $fn";
16 LINE:
17 while (<SP>) {
18 # 112 6F 00071CDC krb5_encrypt_size
20 /^ +([[:digit:]]+)\s+[[:xdigit:]]+\s[[:xdigit:]]{8,}\s+(\S+)(?:| = (\S*))$/ && do {
21 my ($ordinal, $symbol, $in) = ($1, $2, $3);
23 if ($in eq "") { $in = $symbol };
24 $target_exports{$symbol} = $in;
28 close SP;
31 # Dump all symbols for the given dll file that are defined and have
32 # external scope.
34 sub build_glue_exports_list($)
36 $fn = shift;
38 print STDERR "Opening dump of DLL [$fn]\n";
40 open(SP, '-|', "dumpbin /exports \"".$fn."\"") or die "Can't open pipe for $fn";
42 LINE:
43 while (<SP>) {
44 # 112 6F 00071CDC krb5_encrypt_size
46 /^ +([[:digit:]]+)\s+[[:xdigit:]]+\s[[:xdigit:]]{8,}\s+(\S+)(?:| = (\S*))$/ && do {
47 my ($ordinal, $symbol, $in) = ($1, $2, $3);
49 if ($strip_leading_underscore && $symbol =~ /_(.*)/) {
50 $symbol = $1;
52 if (exists $local_exports{$symbol}) {
53 print "\t".$symbol;
54 print " = ".$local_exports{$symbol};
55 if ($in ne $local_exports{$symbol} and $in ne "") {
56 print STDERR "Incorrect calling convention for local $symbol\n";
57 print STDERR " ".$in." != ".$local_exports{$symbol}."\n";
59 print "\t@".$ordinal."\n";
60 } elsif (exists $local_exports{"SHIM_".$symbol}) {
61 print "\t".$symbol;
62 print " = ".$local_exports{"SHIM_".$symbol};
63 print "\t@".$ordinal."\n";
64 } elsif (exists $target_exports{$symbol}) {
65 print "\t".$symbol;
66 print " = ".$module_name;
67 if ($in ne $target_exports{$symbol} and $in ne "") {
68 print STDERR "Incorrect calling convention for $symbol\n";
69 print STDERR " ".$in." != ".$target_exports{$symbol}."\n";
71 my $texp = $target_exports{$symbol};
72 if ($texp =~ /^_([^@]+)$/) { $texp = $1; }
73 print $texp."\t@".$ordinal."\n";
74 } else {
75 print STDERR "Symbol not found: $symbol\n";
80 close SP;
83 sub build_local_exports_list($)
85 $fn = shift;
87 print STDERR "Opening dump of object [$fn]\n";
89 open(SP, '-|', "dumpbin /symbols \"".$fn."\"") or die "Can't open pipe for $fn";
91 LINE:
92 while (<SP>) {
93 # 009 00000010 SECT3 notype () External | _remove_error_table@4
94 m/^[[:xdigit:]]{3,}\s[[:xdigit:]]{8,}\s(\w+)\s+\w*\s+(?:\(\)| )\s+(\w+)\s+\|\s+(\S+)$/ && do {
95 my ($section, $visibility, $symbol) = ($1, $2, $3);
97 if ($section ne "UNDEF" && $visibility eq "External") {
99 my $exp_name = $symbol;
101 if ($symbol =~ m/^_(\w+)(?:@.*|)$/) {
102 $exp_name = $1;
105 if ($symbol =~ m/^_([^@]+)$/) {
106 $symbol = $1;
109 $local_exports{$exp_name} = $symbol;
114 close SP;
117 sub process_file($)
119 $fn = shift;
121 if ($fn =~ m/\.dll$/i) {
122 build_glue_exports_list($fn);
123 } elsif ($fn =~ m/\.obj$/i) {
124 build_local_exports_list($fn);
125 } else {
126 die "File type not recognized for $fn.";
130 sub use_response_file($)
132 $fn = shift;
134 open (RF, '<', $fn) or die "Can't open response file $fn";
136 while (<RF>) {
137 /(\S+)/ && do {
138 process_file($1);
141 close RF;
144 print "; This is a generated file. Do not modify directly.\n";
145 print "EXPORTS\n";
147 for (@ARGV) {
148 ARG: {
149 /-m(.*)/ && do {
150 $module_name = $1.".";
151 last ARG;
154 /-e(.*)/ && do {
155 build_target_exports_list($1);
156 last ARG;
159 /@(.*)/ && do {
160 use_response_file($1);
161 last ARG;
164 process_file($_);