]>
Commit | Line | Data |
---|---|---|
d02b48c6 RE |
1 | #!/usr/local/bin/perl |
2 | # | |
3 | # generate a .def file | |
4 | # | |
5 | # It does this by parsing the header files and looking for the | |
6 | # non-prototyped functions. | |
7 | # | |
8 | ||
9 | $crypto_num="util/libeay.num"; | |
10 | $ssl_num= "util/ssleay.num"; | |
11 | ||
12 | $NT=1; | |
13 | foreach (@ARGV) | |
14 | { | |
15 | $NT=1 if $_ eq "32"; | |
16 | $NT=0 if $_ eq "16"; | |
17 | $do_ssl=1 if $_ eq "ssleay"; | |
18 | $do_crypto=1 if $_ eq "libeay"; | |
19 | } | |
20 | ||
21 | if (!$do_ssl && !$do_crypto) | |
22 | { | |
23 | print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 ]\n"; | |
24 | exit(1); | |
25 | } | |
26 | ||
27 | %ssl_list=&load_numbers($ssl_num); | |
28 | %crypto_list=&load_numbers($crypto_num); | |
29 | ||
30 | $ssl="ssl/ssl.h"; | |
31 | ||
32 | $crypto ="crypto/crypto.h"; | |
33 | $crypto.=" crypto/des/des.h"; | |
34 | $crypto.=" crypto/idea/idea.h"; | |
35 | $crypto.=" crypto/rc4/rc4.h"; | |
58964a49 | 36 | $crypto.=" crypto/rc5/rc5.h"; |
d02b48c6 RE |
37 | $crypto.=" crypto/rc2/rc2.h"; |
38 | $crypto.=" crypto/bf/blowfish.h"; | |
58964a49 RE |
39 | $crypto.=" crypto/cast/cast.h"; |
40 | $crypto.=" crypto/md2/md2.h"; | |
41 | $crypto.=" crypto/md5/md5.h"; | |
d02b48c6 RE |
42 | $crypto.=" crypto/mdc2/mdc2.h"; |
43 | $crypto.=" crypto/sha/sha.h"; | |
58964a49 | 44 | $crypto.=" crypto/ripemd/ripemd.h"; |
d02b48c6 RE |
45 | |
46 | $crypto.=" crypto/bn/bn.h"; | |
47 | $crypto.=" crypto/rsa/rsa.h"; | |
48 | $crypto.=" crypto/dsa/dsa.h"; | |
49 | $crypto.=" crypto/dh/dh.h"; | |
50 | ||
51 | $crypto.=" crypto/stack/stack.h"; | |
52 | $crypto.=" crypto/buffer/buffer.h"; | |
53 | $crypto.=" crypto/bio/bio.h"; | |
54 | $crypto.=" crypto/lhash/lhash.h"; | |
55 | $crypto.=" crypto/conf/conf.h"; | |
56 | $crypto.=" crypto/txt_db/txt_db.h"; | |
57 | ||
58 | $crypto.=" crypto/evp/evp.h"; | |
59 | $crypto.=" crypto/objects/objects.h"; | |
60 | $crypto.=" crypto/pem/pem.h"; | |
61 | #$crypto.=" crypto/meth/meth.h"; | |
62 | $crypto.=" crypto/asn1/asn1.h"; | |
63 | $crypto.=" crypto/asn1/asn1_mac.h"; | |
64 | $crypto.=" crypto/err/err.h"; | |
65 | $crypto.=" crypto/pkcs7/pkcs7.h"; | |
66 | $crypto.=" crypto/x509/x509.h"; | |
67 | $crypto.=" crypto/x509/x509_vfy.h"; | |
68 | $crypto.=" crypto/rand/rand.h"; | |
58964a49 | 69 | $crypto.=" crypto/hmac/hmac.h"; |
d02b48c6 RE |
70 | |
71 | $match{'NOPROTO'}=1; | |
72 | $match2{'PERL5'}=1; | |
73 | ||
74 | &print_def_file(*STDOUT,"SSLEAY",*ssl_list,&do_defs("SSLEAY",$ssl)) | |
75 | if $do_ssl == 1; | |
76 | ||
77 | &print_def_file(*STDOUT,"LIBEAY",*crypto_list,&do_defs("LIBEAY",$crypto)) | |
78 | if $do_crypto == 1; | |
79 | ||
80 | sub do_defs | |
81 | { | |
82 | local($name,$files)=@_; | |
83 | local(@ret); | |
84 | ||
85 | $off=-1; | |
86 | foreach $file (split(/\s+/,$files)) | |
87 | { | |
88 | # print STDERR "reading $file\n"; | |
89 | open(IN,"<$file") || die "unable to open $file:$!\n"; | |
90 | $depth=0; | |
91 | $pr=-1; | |
92 | @np=""; | |
93 | $/=undef; | |
94 | $a=<IN>; | |
95 | while (($i=index($a,"/*")) >= 0) | |
96 | { | |
97 | $j=index($a,"*/"); | |
98 | break unless ($j >= 0); | |
99 | $a=substr($a,0,$i).substr($a,$j+2); | |
100 | # print "$i $j\n"; | |
101 | } | |
102 | foreach (split("\n",$a)) | |
103 | { | |
58964a49 | 104 | if (/^\#\s*ifndef (.*)/) |
d02b48c6 RE |
105 | { |
106 | push(@tag,$1); | |
107 | $tag{$1}=-1; | |
108 | next; | |
109 | } | |
58964a49 | 110 | elsif (/^\#\s*if !defined\(([^\)]+)\)/) |
d02b48c6 RE |
111 | { |
112 | push(@tag,$1); | |
113 | $tag{$1}=-1; | |
114 | next; | |
115 | } | |
58964a49 | 116 | elsif (/^\#\s*ifdef (.*)/) |
d02b48c6 RE |
117 | { |
118 | push(@tag,$1); | |
119 | $tag{$1}=1; | |
120 | next; | |
121 | } | |
58964a49 | 122 | elsif (/^\#\s*if defined(.*)/) |
d02b48c6 RE |
123 | { |
124 | push(@tag,$1); | |
125 | $tag{$1}=1; | |
126 | next; | |
127 | } | |
58964a49 | 128 | elsif (/^\#\s*endif/) |
d02b48c6 RE |
129 | { |
130 | $tag{$tag[$#tag]}=0; | |
131 | pop(@tag); | |
132 | next; | |
133 | } | |
58964a49 | 134 | elsif (/^\#\s*else/) |
d02b48c6 RE |
135 | { |
136 | $t=$tag[$#tag]; | |
137 | $tag{$t}= -$tag{$t}; | |
138 | next; | |
139 | } | |
58964a49 RE |
140 | #printf STDERR "$_\n%2d %2d %2d %2d %2d $NT\n", |
141 | #$tag{'NOPROTO'},$tag{'FreeBSD'},$tag{'WIN16'},$tag{'PERL5'},$tag{'NO_FP_API'}; | |
142 | ||
d02b48c6 RE |
143 | $t=undef; |
144 | if (/^extern .*;$/) | |
145 | { $t=&do_extern($name,$_); } | |
146 | elsif ( ($tag{'NOPROTO'} == 1) && | |
147 | ($tag{'FreeBSD'} != 1) && | |
148 | (($NT && ($tag{'WIN16'} != 1)) || | |
149 | (!$NT && ($tag{'WIN16'} != -1))) && | |
58964a49 RE |
150 | ($tag{'PERL5'} != 1) && |
151 | # ($tag{'_WINDLL'} != -1) && | |
152 | ((!$NT && $tag{'_WINDLL'} != -1) || | |
153 | ($NT && $tag{'_WINDLL'} != 1)) && | |
154 | ((($tag{'NO_FP_API'} != 1) && $NT) || | |
155 | (($tag{'NO_FP_API'} != -1) && !$NT))) | |
d02b48c6 | 156 | { $t=&do_line($name,$_); } |
58964a49 RE |
157 | else |
158 | { $t=undef; } | |
d02b48c6 RE |
159 | if (($t ne undef) && (!$done{$name,$t})) |
160 | { | |
161 | $done{$name,$t}++; | |
162 | push(@ret,$t); | |
58964a49 | 163 | #printf STDERR "one:$t\n" if $t =~ /BIO_/; |
d02b48c6 RE |
164 | } |
165 | } | |
166 | close(IN); | |
167 | } | |
168 | return(@ret); | |
169 | } | |
170 | ||
171 | sub do_line | |
172 | { | |
173 | local($file,$_)=@_; | |
174 | local($n); | |
175 | ||
176 | return(undef) if /^$/; | |
177 | return(undef) if /^\s/; | |
58964a49 | 178 | #printf STDERR "two:$_\n" if $_ =~ /BIO_/; |
d02b48c6 RE |
179 | if (/(CRYPTO_get_locking_callback)/) |
180 | { return($1); } | |
181 | elsif (/(CRYPTO_get_id_callback)/) | |
182 | { return($1); } | |
183 | elsif (/(CRYPTO_get_add_lock_callback)/) | |
184 | { return($1); } | |
185 | elsif (/(SSL_CTX_get_verify_callback)/) | |
186 | { return($1); } | |
58964a49 RE |
187 | elsif (/(SSL_get_info_callback)/) |
188 | { return($1); } | |
189 | elsif ((!$NT) && /(ERR_load_CRYPTO_strings)/) | |
190 | { return("ERR_load_CRYPTOlib_strings"); } | |
191 | elsif (!$NT && /BIO_s_file/) | |
192 | { return(undef); } | |
193 | elsif (!$NT && /BIO_new_file/) | |
194 | { return(undef); } | |
195 | elsif (!$NT && /BIO_new_fp/) | |
196 | { return(undef); } | |
197 | elsif ($NT && /BIO_s_file_internal/) | |
198 | { return(undef); } | |
199 | elsif ($NT && /BIO_new_file_internal/) | |
200 | { return(undef); } | |
201 | elsif ($NT && /BIO_new_fp_internal/) | |
202 | { return(undef); } | |
d02b48c6 RE |
203 | else |
204 | { | |
205 | /\s\**(\S+)\s*\(/; | |
206 | return($1); | |
207 | } | |
208 | } | |
209 | ||
210 | sub do_extern | |
211 | { | |
212 | local($file,$_)=@_; | |
213 | local($n); | |
214 | ||
215 | /\s\**(\S+);$/; | |
216 | return($1); | |
217 | } | |
218 | ||
219 | sub print_def_file | |
220 | { | |
221 | local(*OUT,$name,*nums,@functions)=@_; | |
222 | local($n)=1; | |
223 | ||
224 | if ($NT) | |
225 | { $name.="32"; } | |
226 | else | |
227 | { $name.="16"; } | |
228 | ||
229 | print OUT <<"EOF"; | |
230 | ; | |
231 | ; Definition file for the DDL version of the $name library from SSLeay | |
232 | ; | |
233 | ||
234 | LIBRARY $name | |
235 | ||
236 | DESCRIPTION 'SSLeay $name - eay\@cryptsoft.com' | |
237 | ||
238 | EOF | |
239 | ||
240 | if (!$NT) | |
241 | { | |
242 | print <<"EOF"; | |
243 | CODE PRELOAD MOVEABLE | |
244 | DATA PRELOAD MOVEABLE SINGLE | |
245 | ||
246 | EXETYPE WINDOWS | |
247 | ||
248 | HEAPSIZE 4096 | |
249 | STACKSIZE 8192 | |
250 | ||
251 | EOF | |
252 | } | |
253 | ||
254 | print "EXPORTS\n"; | |
255 | ||
256 | ||
257 | (@e)=grep(/^SSLeay/,@functions); | |
258 | (@r)=grep(!/^SSLeay/,@functions); | |
259 | @functions=((sort @e),(sort @r)); | |
260 | ||
261 | foreach $func (@functions) | |
262 | { | |
263 | if (!defined($nums{$func})) | |
264 | { | |
265 | printf STDERR "$func does not have a number assigned\n"; | |
266 | } | |
267 | else | |
268 | { | |
269 | $n=$nums{$func}; | |
270 | printf OUT " %s%-35s@%d\n",($NT)?"":"_",$func,$n; | |
271 | } | |
272 | } | |
273 | printf OUT "\n"; | |
274 | } | |
275 | ||
276 | sub load_numbers | |
277 | { | |
278 | local($name)=@_; | |
279 | local($j,@a,%ret); | |
280 | ||
281 | open(IN,"<$name") || die "unable to open $name:$!\n"; | |
282 | while (<IN>) | |
283 | { | |
284 | chop; | |
285 | s/#.*$//; | |
286 | next if /^\s*$/; | |
287 | @a=split; | |
288 | $ret{$a[0]}=$a[1]; | |
289 | } | |
290 | close(IN); | |
291 | return(%ret); | |
292 | } |