blob: 4a94dc4dbdd25380da44df07b375a8611058a7dc [file] [log] [blame]
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001#!/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
Dr. Stephen Henson06c68491999-03-03 02:01:26 +000012$W32=1;
13$NT=0;
Dr. Stephen Henson28a98801999-04-14 23:44:41 +000014# Set this to make typesafe STACK definitions appear in DEF
15$safe_stack_def = 1;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000016foreach (@ARGV)
17 {
Dr. Stephen Henson06c68491999-03-03 02:01:26 +000018 $W32=1 if $_ eq "32";
19 $W32=0 if $_ eq "16";
20 if($_ eq "NT") {
21 $W32 = 1;
22 $NT = 1;
23 }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000024 $do_ssl=1 if $_ eq "ssleay";
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +000025 $do_ssl=1 if $_ eq "ssl";
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000026 $do_crypto=1 if $_ eq "libeay";
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +000027 $do_crypto=1 if $_ eq "crypto";
28 $do_update=1 if $_ eq "update";
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000029 }
30
31if (!$do_ssl && !$do_crypto)
32 {
33 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 ]\n";
34 exit(1);
35 }
36
37%ssl_list=&load_numbers($ssl_num);
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +000038$max_ssl = $max_num;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000039%crypto_list=&load_numbers($crypto_num);
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +000040$max_crypto = $max_num;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000041
42$ssl="ssl/ssl.h";
43
44$crypto ="crypto/crypto.h";
45$crypto.=" crypto/des/des.h";
46$crypto.=" crypto/idea/idea.h";
47$crypto.=" crypto/rc4/rc4.h";
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000048$crypto.=" crypto/rc5/rc5.h";
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000049$crypto.=" crypto/rc2/rc2.h";
50$crypto.=" crypto/bf/blowfish.h";
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000051$crypto.=" crypto/cast/cast.h";
52$crypto.=" crypto/md2/md2.h";
53$crypto.=" crypto/md5/md5.h";
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000054$crypto.=" crypto/mdc2/mdc2.h";
55$crypto.=" crypto/sha/sha.h";
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000056$crypto.=" crypto/ripemd/ripemd.h";
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000057
58$crypto.=" crypto/bn/bn.h";
59$crypto.=" crypto/rsa/rsa.h";
60$crypto.=" crypto/dsa/dsa.h";
61$crypto.=" crypto/dh/dh.h";
62
63$crypto.=" crypto/stack/stack.h";
64$crypto.=" crypto/buffer/buffer.h";
65$crypto.=" crypto/bio/bio.h";
66$crypto.=" crypto/lhash/lhash.h";
67$crypto.=" crypto/conf/conf.h";
68$crypto.=" crypto/txt_db/txt_db.h";
69
70$crypto.=" crypto/evp/evp.h";
71$crypto.=" crypto/objects/objects.h";
72$crypto.=" crypto/pem/pem.h";
73#$crypto.=" crypto/meth/meth.h";
74$crypto.=" crypto/asn1/asn1.h";
75$crypto.=" crypto/asn1/asn1_mac.h";
76$crypto.=" crypto/err/err.h";
77$crypto.=" crypto/pkcs7/pkcs7.h";
Dr. Stephen Hensonee0508d1999-03-29 17:50:26 +000078$crypto.=" crypto/pkcs12/pkcs12.h";
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000079$crypto.=" crypto/x509/x509.h";
80$crypto.=" crypto/x509/x509_vfy.h";
Dr. Stephen Henson679ab7c1999-01-30 17:35:01 +000081$crypto.=" crypto/x509v3/x509v3.h";
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000082$crypto.=" crypto/rand/rand.h";
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000083$crypto.=" crypto/hmac/hmac.h";
Ralf S. Engelschalldfeab061998-12-21 11:00:56 +000084$crypto.=" crypto/comp/comp.h";
85$crypto.=" crypto/tmdiff.h";
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000086
87$match{'NOPROTO'}=1;
88$match2{'PERL5'}=1;
89
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +000090@ssl_func = &do_defs("SSLEAY", $ssl);
91@crypto_func = &do_defs("LIBEAY", $crypto);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000092
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +000093if ($do_update) {
94
95if ($do_ssl == 1) {
96 open(OUT, ">>$ssl_num");
97 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl, @ssl_func);
98 close OUT;
99}
100
101if($do_crypto == 1) {
102 open(OUT, ">>$crypto_num");
103 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto, @crypto_func);
104 close OUT;
105}
106
107} else {
108
109 &print_def_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func)
110 if $do_ssl == 1;
111
112 &print_def_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func)
113 if $do_crypto == 1;
114
115}
116
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000117
118sub do_defs
119 {
120 local($name,$files)=@_;
121 local(@ret);
122
123 $off=-1;
124 foreach $file (split(/\s+/,$files))
125 {
126# print STDERR "reading $file\n";
127 open(IN,"<$file") || die "unable to open $file:$!\n";
128 $depth=0;
129 $pr=-1;
130 @np="";
131 $/=undef;
132 $a=<IN>;
133 while (($i=index($a,"/*")) >= 0)
134 {
135 $j=index($a,"*/");
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +0000136 last unless ($j >= 0);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000137 $a=substr($a,0,$i).substr($a,$j+2);
138 # print "$i $j\n";
139 }
140 foreach (split("\n",$a))
141 {
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000142 if (/^\#\s*ifndef (.*)/)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000143 {
144 push(@tag,$1);
145 $tag{$1}=-1;
146 next;
147 }
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000148 elsif (/^\#\s*if !defined\(([^\)]+)\)/)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000149 {
150 push(@tag,$1);
151 $tag{$1}=-1;
152 next;
153 }
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000154 elsif (/^\#\s*ifdef (.*)/)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000155 {
156 push(@tag,$1);
157 $tag{$1}=1;
158 next;
159 }
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000160 elsif (/^\#\s*if defined(.*)/)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000161 {
162 push(@tag,$1);
163 $tag{$1}=1;
164 next;
165 }
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000166 elsif (/^\#\s*endif/)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000167 {
168 $tag{$tag[$#tag]}=0;
169 pop(@tag);
170 next;
171 }
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000172 elsif (/^\#\s*else/)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000173 {
174 $t=$tag[$#tag];
175 $tag{$t}= -$tag{$t};
176 next;
177 }
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000178#printf STDERR "$_\n%2d %2d %2d %2d %2d $W32\n",
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000179#$tag{'NOPROTO'},$tag{'FreeBSD'},$tag{'WIN16'},$tag{'PERL5'},$tag{'NO_FP_API'};
180
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000181 $t=undef;
182 if (/^extern .*;$/)
183 { $t=&do_extern($name,$_); }
Dr. Stephen Henson28a98801999-04-14 23:44:41 +0000184 elsif ($safe_stack_def &&
185 /^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/)
186 {
187 push(@ret,"sk_${1}_new");
188 push(@ret,"sk_${1}_new_null");
189 push(@ret,"sk_${1}_free");
190 push(@ret,"sk_${1}_num");
191 push(@ret,"sk_${1}_value");
192 push(@ret,"sk_${1}_set");
193 push(@ret,"sk_${1}_zero");
194 push(@ret,"sk_${1}_push");
Dr. Stephen Hensonf5fedc01999-04-20 01:10:33 +0000195 push(@ret,"sk_${1}_pop");
Dr. Stephen Henson28a98801999-04-14 23:44:41 +0000196 push(@ret,"sk_${1}_find");
197 push(@ret,"sk_${1}_delete");
198 push(@ret,"sk_${1}_delete_ptr");
199 push(@ret,"sk_${1}_set_cmp_func");
200 push(@ret,"sk_${1}_dup");
201 push(@ret,"sk_${1}_pop_free");
202 push(@ret,"sk_${1}_shift");
203 }
204 elsif ($safe_stack_def &&
205 /^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/)
206 {
207 push(@ret,"d2i_ASN1_SET_OF_${1}");
208 push(@ret,"i2d_ASN1_SET_OF_${1}");
209 }
210 elsif (($tag{'NOPROTO'} == 1) &&
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000211 ($tag{'FreeBSD'} != 1) &&
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000212 (($W32 && ($tag{'WIN16'} != 1)) ||
213 (!$W32 && ($tag{'WIN16'} != -1))) &&
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000214 ($tag{'PERL5'} != 1) &&
215# ($tag{'_WINDLL'} != -1) &&
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000216 ((!$W32 && $tag{'_WINDLL'} != -1) ||
217 ($W32 && $tag{'_WINDLL'} != 1)) &&
218 ((($tag{'NO_FP_API'} != 1) && $W32) ||
219 (($tag{'NO_FP_API'} != -1) && !$W32)))
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000220 { $t=&do_line($name,$_); }
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000221 else
222 { $t=undef; }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000223 if (($t ne undef) && (!$done{$name,$t}))
224 {
225 $done{$name,$t}++;
226 push(@ret,$t);
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000227#printf STDERR "one:$t\n" if $t =~ /BIO_/;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000228 }
229 }
230 close(IN);
231 }
232 return(@ret);
233 }
234
235sub do_line
236 {
237 local($file,$_)=@_;
238 local($n);
239
240 return(undef) if /^$/;
241 return(undef) if /^\s/;
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000242#printf STDERR "two:$_\n" if $_ =~ /BIO_/;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000243 if (/(CRYPTO_get_locking_callback)/)
244 { return($1); }
245 elsif (/(CRYPTO_get_id_callback)/)
246 { return($1); }
247 elsif (/(CRYPTO_get_add_lock_callback)/)
248 { return($1); }
249 elsif (/(SSL_CTX_get_verify_callback)/)
250 { return($1); }
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000251 elsif (/(SSL_get_info_callback)/)
252 { return($1); }
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000253 elsif ((!$W32) && /(ERR_load_CRYPTO_strings)/)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000254 { return("ERR_load_CRYPTOlib_strings"); }
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000255 elsif (!$W32 && /BIO_s_file/)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000256 { return(undef); }
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000257 elsif (!$W32 && /BIO_new_file/)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000258 { return(undef); }
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000259 elsif (!$W32 && /BIO_new_fp/)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000260 { return(undef); }
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000261 elsif ($W32 && /BIO_s_file_internal/)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000262 { return(undef); }
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000263 elsif ($W32 && /BIO_new_file_internal/)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000264 { return(undef); }
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000265 elsif ($W32 && /BIO_new_fp_internal/)
266 { return(undef); }
Dr. Stephen Henson6e064241999-03-08 18:41:15 +0000267 elsif (/SSL_add_dir_cert_subjects_to_stack/)
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000268 { return(undef); }
269 elsif (!$NT && /BIO_s_log/)
Ralf S. Engelschall58964a41998-12-21 10:56:39 +0000270 { return(undef); }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000271 else
272 {
273 /\s\**(\S+)\s*\(/;
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000274 $_ = $1;
275 tr/()*//d;
276#print STDERR "$1 : $_\n";
277 return($_);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000278 }
279 }
280
281sub do_extern
282 {
283 local($file,$_)=@_;
284 local($n);
285
286 /\s\**(\S+);$/;
287 return($1);
288 }
289
290sub print_def_file
291 {
292 local(*OUT,$name,*nums,@functions)=@_;
293 local($n)=1;
294
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000295 if ($W32)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000296 { $name.="32"; }
297 else
298 { $name.="16"; }
299
300 print OUT <<"EOF";
301;
Dr. Stephen Henson9b3086f1999-01-31 17:30:18 +0000302; Definition file for the DLL version of the $name library from OpenSSL
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000303;
304
305LIBRARY $name
306
Dr. Stephen Henson9b3086f1999-01-31 17:30:18 +0000307DESCRIPTION 'OpenSSL $name - http://www.openssl.org/'
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000308
309EOF
310
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000311 if (!$W32)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000312 {
313 print <<"EOF";
314CODE PRELOAD MOVEABLE
315DATA PRELOAD MOVEABLE SINGLE
316
317EXETYPE WINDOWS
318
319HEAPSIZE 4096
320STACKSIZE 8192
321
322EOF
323 }
324
325 print "EXPORTS\n";
326
327
328 (@e)=grep(/^SSLeay/,@functions);
329 (@r)=grep(!/^SSLeay/,@functions);
330 @functions=((sort @e),(sort @r));
331
332 foreach $func (@functions)
333 {
334 if (!defined($nums{$func}))
335 {
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +0000336 printf STDERR "$func does not have a number assigned\n"
337 if(!$do_update);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000338 }
339 else
340 {
341 $n=$nums{$func};
Dr. Stephen Henson06c68491999-03-03 02:01:26 +0000342 printf OUT " %s%-40s@%d\n",($W32)?"":"_",$func,$n;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000343 }
344 }
345 printf OUT "\n";
346 }
347
348sub load_numbers
349 {
350 local($name)=@_;
351 local($j,@a,%ret);
352
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +0000353 $max_num = 0;
354
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000355 open(IN,"<$name") || die "unable to open $name:$!\n";
356 while (<IN>)
357 {
358 chop;
359 s/#.*$//;
360 next if /^\s*$/;
361 @a=split;
362 $ret{$a[0]}=$a[1];
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +0000363 $max_num = $a[1] if $a[1] > $max_num;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000364 }
365 close(IN);
366 return(%ret);
367 }
Dr. Stephen Henson55a9cc61999-02-11 01:39:30 +0000368
369sub update_numbers
370 {
371 local(*OUT,$name,*nums,$start_num, @functions)=@_;
372 my $new_funcs = 0;
373 print STDERR "Updating $name\n";
374 foreach $func (@functions)
375 {
376 if (!defined($nums{$func}))
377 {
378 $new_funcs++;
379 printf OUT "%s%-40s%d\n","",$func, ++$start_num;
380 }
381 }
382 if($new_funcs) {
383 print STDERR "$new_funcs New Functions added\n";
384 } else {
385 print STDERR "No New Functions Added\n";
386 }
387 }