2 # Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 # generate a .def file
12 # It does this by parsing the header files and looking for the
13 # prototyped functions: it then prunes the output.
15 # Intermediary files are created, call libcrypto.num and libssl.num,
16 # The format of these files is:
18 # routine-name nnnn vers info
20 # The "nnnn" and "vers" fields are the numeric id and version for the symbol
21 # respectively. The "info" part is actually a colon-separated string of fields
22 # with the following meaning:
24 # existence:platform:kind:algorithms
26 # - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
27 # found somewhere in the source,
28 # - "platforms" is empty if it exists on all platforms, otherwise it contains
29 # comma-separated list of the platform, just as they are if the symbol exists
30 # for those platforms, or prepended with a "!" if not. This helps resolve
31 # symbol name variants for platforms where the names are too long for the
32 # compiler or linker, or if the systems is case insensitive and there is a
33 # clash, or the symbol is implemented differently (see
34 # EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found
35 # in the file crypto/symhacks.h.
36 # The semantics for the platforms is that every item is checked against the
37 # environment. For the negative items ("!FOO"), if any of them is false
38 # (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
39 # used. For the positive itms, if all of them are false in the environment,
40 # the corresponding symbol can't be used. Any combination of positive and
41 # negative items are possible, and of course leave room for some redundancy.
42 # - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious.
43 # - "algorithms" is a comma-separated list of algorithm names. This helps
44 # exclude symbols that are part of an algorithm that some user wants to
50 use File::Spec::Functions;
52 use if $^O ne "VMS", 'File::Glob' => qw/glob/;
56 my $crypto_num= catfile($config{sourcedir},"util","libcrypto.num");
57 my $ssl_num= catfile($config{sourcedir},"util","libssl.num");
66 my $do_checkexist = 0;
73 # Set this to make typesafe STACK definitions appear in DEF
74 my $safe_stack_def = 0;
76 my @known_platforms = ( "__FreeBSD__", "PERL5",
77 "EXPORT_VAR_AS_FUNCTION", "ZLIB", "_WIN32"
79 my @known_ossl_platforms = ( "UNIX", "VMS", "WIN32", "WINNT", "OS2" );
80 my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
81 "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
82 "SHA256", "SHA512", "RMD160",
83 "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "EC2M",
84 "HMAC", "AES", "CAMELLIA", "SEED", "GOST", "ARIA",
85 "SCRYPT", "CHACHA", "POLY1305", "BLAKE2",
88 "EC_NISTP_64_GCC_128",
89 # Envelope "algorithms"
90 "EVP", "X509", "ASN1_TYPEDEFS",
92 "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
94 # External "algorithms"
95 "FP_API", "STDIO", "SOCK", "DGRAM",
98 "STATIC_ENGINE", "ENGINE", "HW", "GMP",
101 # Certificate Transparency
106 "PSK", "SRP", "HEARTBEATS",
113 "SSL3_METHOD", "TLS1_METHOD", "TLS1_1_METHOD", "TLS1_2_METHOD", "DTLS1_METHOD", "DTLS1_2_METHOD",
116 # Deprecated functions
117 "DEPRECATEDIN_0_9_8",
118 "DEPRECATEDIN_1_0_0",
119 "DEPRECATEDIN_1_1_0",
120 "DEPRECATEDIN_1_2_0",
136 # APPLINK (win build feature?)
140 my %disabled_algorithms;
142 foreach (@known_algorithms) {
143 $disabled_algorithms{$_} = 0;
145 # disabled by default
146 $disabled_algorithms{"STATIC_ENGINE"} = 1;
148 my $apiv = sprintf "%x%02x%02x", split(/\./, $config{api});
149 foreach (keys %disabled_algorithms) {
150 if (/^DEPRECATEDIN_(\d+)_(\d+)_(\d+)$/) {
151 my $depv = sprintf "%x%02x%02x", $1, $2, $3;
152 $disabled_algorithms{$_} = 1 if $apiv ge $depv;
158 foreach (@ARGV, split(/ /, $config{options}))
160 $debug=1 if $_ eq "debug";
161 $W32=1 if $_ eq "32";
162 die "win16 not supported" if $_ eq "16";
171 $VMS=1 if $_ eq "VMS";
172 if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
173 || $_ eq "enable-zlib-dynamic") {
177 $do_ssl=1 if $_ eq "libssl";
182 $do_crypto=1 if $_ eq "libcrypto";
183 if ($_ eq "crypto") {
187 $do_update=1 if $_ eq "update";
188 $do_rewrite=1 if $_ eq "rewrite";
189 $do_ctest=1 if $_ eq "ctest";
190 $do_ctestall=1 if $_ eq "ctestall";
191 $do_checkexist=1 if $_ eq "exist";
192 if (/^(enable|disable|no)-(.*)$/) {
195 if (exists $disabled_algorithms{$alg}) {
196 $disabled_algorithms{$alg} = $1 eq "enable" ? 0 : 1;
207 $libname="LIBCRYPTO";
211 # If no platform is given, assume WIN32
212 if ($W32 + $VMS + $linux == 0) {
215 die "Please, only one platform at a time"
216 if ($W32 + $VMS + $linux > 1);
218 if (!$do_ssl && !$do_crypto)
220 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 | linux | VMS ]\n";
224 %ssl_list=&load_numbers($ssl_num);
226 %crypto_list=&load_numbers($crypto_num);
227 $max_crypto = $max_num;
229 my $ssl="include/openssl/ssl.h";
230 $ssl.=" include/openssl/sslerr.h";
231 $ssl.=" include/openssl/tls1.h";
232 $ssl.=" include/openssl/srtp.h";
234 # When scanning include/openssl, skip all SSL files and some internal ones.
236 foreach my $f ( split(/\s+/, $ssl) ) {
239 $skipthese{'include/openssl/conf_api.h'} = 1;
240 $skipthese{'include/openssl/ebcdic.h'} = 1;
241 $skipthese{'include/openssl/opensslconf.h'} = 1;
243 # We use headers found in include/openssl and include/internal only.
244 # The latter is needed so libssl.so/.dll/.exe can link properly.
245 my $crypto ="include/internal/dso.h";
246 $crypto.=" include/internal/o_dir.h";
247 $crypto.=" include/internal/o_str.h";
248 $crypto.=" include/internal/err.h";
249 foreach my $f ( glob(catfile($config{sourcedir},'include/openssl/*.h')) ) {
250 my $fn = "include/openssl/" . lc(basename($f));
251 $crypto .= " $fn" if !defined $skipthese{$fn} && $f !~ m@/[a-z]+err\.h$@;
254 my $symhacks="include/openssl/symhacks.h";
256 my @ssl_symbols = &do_defs("LIBSSL", $ssl, $symhacks);
257 my @crypto_symbols = &do_defs("LIBCRYPTO", $crypto, $symhacks);
263 &maybe_add_info("LIBSSL",*ssl_list,@ssl_symbols);
264 if ($do_rewrite == 1) {
265 open(OUT, ">$ssl_num");
266 &rewrite_numbers(*OUT,"LIBSSL",*ssl_list,@ssl_symbols);
268 open(OUT, ">>$ssl_num");
270 &update_numbers(*OUT,"LIBSSL",*ssl_list,$max_ssl,@ssl_symbols);
274 if($do_crypto == 1) {
276 &maybe_add_info("LIBCRYPTO",*crypto_list,@crypto_symbols);
277 if ($do_rewrite == 1) {
278 open(OUT, ">$crypto_num");
279 &rewrite_numbers(*OUT,"LIBCRYPTO",*crypto_list,@crypto_symbols);
281 open(OUT, ">>$crypto_num");
283 &update_numbers(*OUT,"LIBCRYPTO",*crypto_list,$max_crypto,@crypto_symbols);
287 } elsif ($do_checkexist) {
288 &check_existing(*ssl_list, @ssl_symbols)
290 &check_existing(*crypto_list, @crypto_symbols)
292 } elsif ($do_ctest || $do_ctestall) {
296 /* Test file to check all DEF file symbols are present by trying
297 * to link to all of them. This is *not* intended to be run!
303 &print_test_file(*STDOUT,"LIBSSL",*ssl_list,$do_ctestall,@ssl_symbols)
306 &print_test_file(*STDOUT,"LIBCRYPTO",*crypto_list,$do_ctestall,@crypto_symbols)
313 &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
316 &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
324 my($name,$files,$symhacksfile)=@_;
328 my %platform; # For anything undefined, we assume ""
329 my %kind; # For anything undefined, we assume "FUNCTION"
330 my %algorithm; # For anything undefined, we assume ""
332 my %variant_cnt; # To be able to allocate "name{n}" if "name"
333 # is the same name as the original.
335 my %unknown_algorithms = ();
338 foreach $file (split(/\s+/,$symhacksfile." ".$files))
340 my $fn = catfile($config{sourcedir},$file);
341 print STDERR "DEBUG: starting on $fn:\n" if $debug;
342 open(IN,"<$fn") || die "Can't open $fn, $!,";
343 my $line = "", my $def= "";
345 (map { $_ => 0 } @known_platforms),
346 (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
347 (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
348 (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
349 (grep /^DEPRECATED_/, @known_algorithms),
356 my $symhacking = $file eq $symhacksfile;
357 my @current_platforms = ();
358 my @current_algorithms = ();
360 # params: symbol, alias, platforms, kind
361 # The reason to put this subroutine in a variable is that
362 # it will otherwise create it's own, unshared, version of
363 # %tag and %variant...
364 my $make_variant = sub
366 my ($s, $a, $p, $k) = @_;
369 print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
374 map { $tag{$_} == 1 ? $_ : "" }
381 map { $tag{$_} == 1 ? $_ : "" }
386 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
387 @known_ossl_platforms));
388 print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
389 if ($a1 eq "") { $a1 = $a2; }
390 elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
393 if (!defined($variant_cnt{$s}))
395 $variant_cnt{$s} = 0;
398 $a .= "{$variant_cnt{$s}}";
400 my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
401 my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
402 if (!grep(/^$togrep$/,
403 split(/;/, defined($variant{$s})?$variant{$s}:""))) {
404 if (defined($variant{$s})) { $variant{$s} .= ";"; }
405 $variant{$s} .= $toadd;
407 print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
410 print STDERR "DEBUG: parsing ----------\n" if $debug;
413 #Inside a DEPRECATEDIN
414 $stored_multiline .= $_;
415 $stored_multiline =~ s|\R$||; # Better chomp
416 print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug;
417 $parens = count_parens($stored_multiline);
419 $def .= do_deprecated($stored_multiline,
421 \@current_algorithms);
425 if (/\/\* Error codes for the \w+ functions\. \*\//)
436 $line = $`; # keep what was before the backslash
441 if (not /\*\//) { # multiline comment...
442 $line = $_; # ... just accumulate
445 s/\/\*.*?\*\///gs;# wipe it
451 $cpp-- if /^#\s*endif/;
454 if (/^#.*ifdef.*cplusplus/) {
459 s/{[^{}]*}//gs; # ignore {} blocks
460 print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
461 print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
462 if (/^\#\s*if\s+OPENSSL_API_COMPAT\s*(\S)\s*(0x[0-9a-fA-F]{8})L\s*$/) {
465 if ($op ne '<' && $op ne '>=') {
466 die "$file unacceptable operator $op: $_\n";
468 my ($one, $major, $minor) =
472 my $t = "DEPRECATEDIN_${one}_${major}_${minor}";
475 $tag{$t}=($op eq '<' ? 1 : -1);
476 print STDERR "DEBUG: $file: found tag $t = $tag{$t}\n" if $debug;
477 } elsif (/^\#\s*ifndef\s+(.*)/) {
481 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
482 } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
484 if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
487 foreach $tmp_ (split '\&\&',$tmp_1) {
488 $tmp_ =~ /!defined\(([^\)]+)\)/;
489 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
494 print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
495 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
499 } elsif (/^\#\s*ifdef\s+(\S*)/) {
503 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
504 } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
506 if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
509 foreach $tmp_ (split '\|\|',$tmp_1) {
510 $tmp_ =~ /defined\(([^\)]+)\)/;
511 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
516 print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
517 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
521 } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
523 while($tag[$tag_i] ne "-") {
524 if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
525 $tag{$tag[$tag_i]}=2;
526 print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
530 } elsif (/^\#\s*endif/) {
532 while($tag_i > 0 && $tag[$tag_i] ne "-") {
534 print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
540 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
542 if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
544 } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
550 && !grep(/^$t$/, @known_algorithms)) {
551 $unknown_algorithms{$t} = 1;
552 #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
557 } elsif (/^\#\s*else/) {
559 die "$file unmatched else\n" if $tag_i < 0;
560 while($tag[$tag_i] ne "-") {
563 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
566 } elsif (/^\#\s*if\s+1/) {
571 print STDERR "DEBUG: $file: found 1\n" if $debug;
572 } elsif (/^\#\s*if\s+0/) {
577 print STDERR "DEBUG: $file: found 0\n" if $debug;
578 } elsif (/^\#\s*if\s+/) {
579 #Some other unrecognized "if" style
581 } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
582 && $symhacking && $tag{'TRUE'} != -1) {
583 # This is for aliasing. When we find an alias,
585 &$make_variant($1,$2);
586 print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
591 map { $tag{$_} == 1 ? $_ :
592 $tag{$_} == -1 ? "!".$_ : "" }
594 push @current_platforms
596 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
597 $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
598 @known_ossl_platforms);
599 @current_algorithms = ();
600 @current_algorithms =
602 map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
604 push @current_algorithms
606 map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
608 push @current_algorithms,
609 grep { /^DEPRECATEDIN_/ && $tag{$_} == 1 }
613 .join(',',@current_platforms).":"
614 .join(',',@current_algorithms).";";
617 if ($tag{'TRUE'} != -1) {
618 if (/^\s*DEFINE_STACK_OF\s*\(\s*(\w*)\s*\)/
619 || /^\s*DEFINE_STACK_OF_CONST\s*\(\s*(\w*)\s*\)/) {
621 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
622 $def .= "int d2i_$3(void);";
623 $def .= "int i2d_$3(void);";
624 # Variant for platforms that do not
625 # have to access globale variables
626 # in shared libraries through functions
629 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
630 .join(',',@current_algorithms).";";
631 $def .= "OPENSSL_EXTERN int $2_it;";
634 .join(',',@current_platforms).":"
635 .join(',',@current_algorithms).";";
636 # Variant for platforms that have to
637 # access globale variables in shared
638 # libraries through functions
639 &$make_variant("$2_it","$2_it",
640 "EXPORT_VAR_AS_FUNCTION",
643 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
644 $def .= "int d2i_$3(void);";
645 $def .= "int i2d_$3(void);";
646 $def .= "int $3_free(void);";
647 $def .= "int $3_new(void);";
648 # Variant for platforms that do not
649 # have to access globale variables
650 # in shared libraries through functions
653 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
654 .join(',',@current_algorithms).";";
655 $def .= "OPENSSL_EXTERN int $2_it;";
658 .join(',',@current_platforms).":"
659 .join(',',@current_algorithms).";";
660 # Variant for platforms that have to
661 # access globale variables in shared
662 # libraries through functions
663 &$make_variant("$2_it","$2_it",
664 "EXPORT_VAR_AS_FUNCTION",
667 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
668 /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
669 $def .= "int d2i_$1(void);";
670 $def .= "int i2d_$1(void);";
671 $def .= "int $1_free(void);";
672 $def .= "int $1_new(void);";
673 # Variant for platforms that do not
674 # have to access globale variables
675 # in shared libraries through functions
678 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
679 .join(',',@current_algorithms).";";
680 $def .= "OPENSSL_EXTERN int $1_it;";
683 .join(',',@current_platforms).":"
684 .join(',',@current_algorithms).";";
685 # Variant for platforms that have to
686 # access globale variables in shared
687 # libraries through functions
688 &$make_variant("$1_it","$1_it",
689 "EXPORT_VAR_AS_FUNCTION",
692 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
693 $def .= "int d2i_$2(void);";
694 $def .= "int i2d_$2(void);";
695 # Variant for platforms that do not
696 # have to access globale variables
697 # in shared libraries through functions
700 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
701 .join(',',@current_algorithms).";";
702 $def .= "OPENSSL_EXTERN int $2_it;";
705 .join(',',@current_platforms).":"
706 .join(',',@current_algorithms).";";
707 # Variant for platforms that have to
708 # access globale variables in shared
709 # libraries through functions
710 &$make_variant("$2_it","$2_it",
711 "EXPORT_VAR_AS_FUNCTION",
714 } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
715 $def .= "int $1_free(void);";
716 $def .= "int $1_new(void);";
718 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
719 $def .= "int d2i_$2(void);";
720 $def .= "int i2d_$2(void);";
721 $def .= "int $2_free(void);";
722 $def .= "int $2_new(void);";
723 # Variant for platforms that do not
724 # have to access globale variables
725 # in shared libraries through functions
728 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
729 .join(',',@current_algorithms).";";
730 $def .= "OPENSSL_EXTERN int $2_it;";
733 .join(',',@current_platforms).":"
734 .join(',',@current_algorithms).";";
735 # Variant for platforms that have to
736 # access globale variables in shared
737 # libraries through functions
738 &$make_variant("$2_it","$2_it",
739 "EXPORT_VAR_AS_FUNCTION",
742 } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
743 # Variant for platforms that do not
744 # have to access globale variables
745 # in shared libraries through functions
748 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
749 .join(',',@current_algorithms).";";
750 $def .= "OPENSSL_EXTERN int $1_it;";
753 .join(',',@current_platforms).":"
754 .join(',',@current_algorithms).";";
755 # Variant for platforms that have to
756 # access globale variables in shared
757 # libraries through functions
758 &$make_variant("$1_it","$1_it",
759 "EXPORT_VAR_AS_FUNCTION",
762 } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
763 $def .= "int i2d_$1_NDEF(void);";
764 } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
766 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
767 $def .= "int $1_print_ctx(void);";
769 } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
770 $def .= "int $2_print_ctx(void);";
772 } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
774 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
775 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
776 /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
779 .join(',',@current_platforms).":"
780 .join(',',"STDIO",@current_algorithms).";";
781 $def .= "int PEM_read_$1(void);";
782 $def .= "int PEM_write_$1(void);";
785 .join(',',@current_platforms).":"
786 .join(',',@current_algorithms).";";
787 # Things that are everywhere
788 $def .= "int PEM_read_bio_$1(void);";
789 $def .= "int PEM_write_bio_$1(void);";
791 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
792 /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
793 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
796 .join(',',@current_platforms).":"
797 .join(',',"STDIO",@current_algorithms).";";
798 $def .= "int PEM_write_$1(void);";
801 .join(',',@current_platforms).":"
802 .join(',',@current_algorithms).";";
803 # Things that are everywhere
804 $def .= "int PEM_write_bio_$1(void);";
806 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
807 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
810 .join(',',@current_platforms).":"
811 .join(',',"STDIO",@current_algorithms).";";
812 $def .= "int PEM_read_$1(void);";
815 .join(',',@current_platforms).":"
816 .join(',',"STDIO",@current_algorithms).";";
817 # Things that are everywhere
818 $def .= "int PEM_read_bio_$1(void);";
820 } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
821 # Variant for platforms that do not
822 # have to access globale variables
823 # in shared libraries through functions
826 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
827 .join(',',@current_algorithms).";";
828 $def .= "OPENSSL_EXTERN int _shadow_$2;";
831 .join(',',@current_platforms).":"
832 .join(',',@current_algorithms).";";
833 # Variant for platforms that have to
834 # access globale variables in shared
835 # libraries through functions
836 &$make_variant("_shadow_$2","_shadow_$2",
837 "EXPORT_VAR_AS_FUNCTION",
839 } elsif (/^\s*DEPRECATEDIN/) {
840 $parens = count_parens($_);
842 $def .= do_deprecated($_,
844 \@current_algorithms);
846 $stored_multiline = $_;
847 $stored_multiline =~ s|\R$||;
848 print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug;
851 } elsif ($tag{'CONST_STRICT'} != 1) {
852 if (/\{|\/\*|\([^\)]*$/) {
861 die "$file: Unmatched tags\n" if $#tag >= 0;
866 print STDERR "DEBUG: postprocessing ----------\n" if $debug;
867 foreach (split /;/, $def) {
868 my $s; my $k = "FUNCTION"; my $p; my $a;
872 next if(/typedef\W/);
875 # Reduce argument lists to empty ()
876 # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
878 s/\([^\(\)]+\)/\{\}/gs;
879 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
881 # pretend as we didn't use curly braces: {} -> ()
884 s/STACK_OF\(\)/void/gs;
885 s/LHASH_OF\(\)/void/gs;
887 print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
888 if (/^\#INFO:([^:]*):(.*)$/) {
891 print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
893 } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
896 print STDERR "DEBUG: found external variable $s\n" if $debug;
897 } elsif (/TYPEDEF_\w+_OF/s) {
899 } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
900 $s = $1; # a function name!
901 print STDERR "DEBUG: found function $s\n" if $debug;
902 } elsif (/\(/ and not (/=/)) {
903 print STDERR "File $file: cannot parse: $_;\n";
916 &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
917 $algorithm{$s} .= ','.$a;
919 if (defined($variant{$s})) {
920 foreach $v (split /;/,$variant{$s}) {
921 (my $r, my $p, my $k) = split(/:/,$v);
922 my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
924 if (!defined($k)) { $k = $kind{$s}; }
925 $kind{$r} = $k."(".$s.")";
926 $algorithm{$r} = $algorithm{$s};
927 $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
928 $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
929 print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
932 print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
936 # Prune the returned symbols
938 delete $syms{"bn_dump1"};
939 $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
941 $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
942 $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
943 $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
944 $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
948 push @ret, map { $_."\\".&info_string($_,"EXIST",
951 $algorithm{$_}) } keys %syms;
953 if (keys %unknown_algorithms) {
954 print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
955 print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
960 # Param: string of comma-separated platform-specs.
963 my ($platforms) = @_;
964 my $pl = defined($platforms) ? $platforms : "";
965 my %p = map { $_ => 0 } split /,/, $pl;
968 print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
970 # We do this, because if there's code like the following, it really
971 # means the function exists in all cases and should therefore be
972 # everywhere. By increasing and decreasing, we may attain 0:
979 foreach $platform (split /,/, $pl) {
980 if ($platform =~ /^!(.*)$/) {
986 foreach $platform (keys %p) {
987 if ($p{$platform} == 0) { delete $p{$platform}; }
992 $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
993 print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
1000 (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
1002 my %a = defined($algorithms) ?
1003 map { $_ => 1 } split /,/, $algorithms : ();
1004 my $k = defined($kind) ? $kind : "FUNCTION";
1006 my $p = &reduce_platforms($platforms);
1013 $ret .= ":".join(',',sort keys %a);
1019 (my $name, *nums, my @symbols) = @_;
1024 foreach $sym (@symbols) {
1025 (my $s, my $i) = split /\\/, $sym;
1026 if (defined($nums{$s})) {
1027 $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
1028 (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
1029 if (!defined($dummy) || $i ne $dummy) {
1030 $nums{$s} = $n."\\".$vers."\\".$i;
1032 print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
1038 my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
1040 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1041 if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
1043 print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
1047 print STDERR "$name: $new_info old symbols have updated info\n";
1049 print STDERR "You should do a rewrite to fix this.\n";
1055 # Param: string of comma-separated keywords, each possibly prefixed with a "!"
1058 my ($keywords_txt,$platforms) = @_;
1059 my (@keywords) = split /,/,$keywords_txt;
1060 my ($falsesum, $truesum) = (0, 1);
1062 # Param: one keyword
1065 my ($keyword,$platforms) = @_;
1069 if ($keyword eq "UNIX" && $UNIX) { return 1; }
1070 if ($keyword eq "VMS" && $VMS) { return 1; }
1071 if ($keyword eq "WIN32" && $W32) { return 1; }
1072 if ($keyword eq "_WIN32" && $W32) { return 1; }
1073 if ($keyword eq "WINNT" && $NT) { return 1; }
1074 # Special platforms:
1075 # EXPORT_VAR_AS_FUNCTION means that global variables
1076 # will be represented as functions.
1077 if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && $W32) {
1080 if ($keyword eq "ZLIB" && $zlib) { return 1; }
1084 if ($disabled_algorithms{$keyword} == 1) { return 0;}
1086 # Nothing recognise as true
1091 foreach $k (@keywords) {
1092 if ($k =~ /^!(.*)$/) {
1093 $falsesum += &recognise($1,$platforms);
1095 $truesum *= &recognise($k,$platforms);
1098 print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
1099 return (!$falsesum) && $truesum;
1104 (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
1105 my $n = 1; my @e; my @r;
1106 my $sym; my $prev = ""; my $prefSSLeay;
1108 (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1109 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1110 @symbols=((sort @e),(sort @r));
1112 foreach $sym (@symbols) {
1113 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1115 $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
1116 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1117 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1118 if (!defined($nums{$s})) {
1119 print STDERR "Warning: $s does not have a number assigned\n"
1121 } elsif (is_valid($p,1) && is_valid($a,0)) {
1122 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1124 print OUT "\t/* The following has already appeared previously */\n";
1125 print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1127 $prev = $s2; # To warn about duplicates...
1129 (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
1131 print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
1133 print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
1141 return $config{version};
1146 (*OUT,my $name,*nums,my @symbols)=@_;
1147 my $n = 1; my @e; my @r; my @v; my $prev="";
1149 my $libname = $name;
1150 my $http_vendor = 'www.openssl.org/';
1151 my $version = get_version();
1152 my $what = "OpenSSL: implementation of Secure Socket Layer";
1153 my $description = "$what $version, $name - http://$http_vendor";
1154 my $prevsymversion = "", $prevprevsymversion = "";
1157 my $symvtextcount = 0;
1166 ; Definition file for the DLL version of the $name library from OpenSSL
1169 LIBRARY $libname $liboptions
1181 $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1184 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1185 (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
1187 # VMS needs to have the symbols on slot number order
1188 @symbols=(map { $_->[1] }
1189 sort { $a->[0] <=> $b->[0] }
1190 map { (my $s, my $i) = $_ =~ /^(.*?)\\(.*)$/;
1191 die "Error: $s doesn't have a number assigned\n"
1192 if !defined($nums{$s});
1193 (my $n, my @rest) = split /\\/, $nums{$s};
1194 [ $n, $_ ] } (@e, @r, @v));
1196 @symbols=((sort @e),(sort @r), (sort @v));
1199 my ($baseversion, $currversion) = get_openssl_version();
1202 if (!defined($thisversion)) {
1203 $thisversion = $baseversion;
1205 $thisversion = get_next_version($thisversion);
1207 foreach $sym (@symbols) {
1208 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1210 $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
1211 if (!defined($nums{$s})) {
1212 die "Error: $s does not have a number assigned\n"
1215 (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
1217 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1218 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1219 if (is_valid($p,1) && is_valid($a,0)) {
1220 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1222 print STDERR "Warning: Symbol '",$s2,
1223 "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
1224 ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1226 $prev = $s2; # To warn about duplicates...
1228 next if $symversion ne $thisversion;
1229 if ($symversion ne $prevsymversion) {
1230 if ($prevsymversion ne "") {
1231 if ($prevprevsymversion ne "") {
1232 print OUT "} OPENSSL_"
1233 ."$prevprevsymversion;\n\n";
1238 print OUT "OPENSSL_$symversion {\n global:\n";
1239 $prevprevsymversion = $prevsymversion;
1240 $prevsymversion = $symversion;
1242 print OUT " $s2;\n";
1244 while(++$prevnum < $n) {
1245 my $symline=" ,SPARE -\n ,SPARE -\n";
1246 if ($symvtextcount + length($symline) - 2 > 1024) {
1247 print OUT ")\nSYMBOL_VECTOR=(-\n";
1248 $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1250 if ($symvtextcount == 16) {
1251 # Take away first comma
1255 $symvtextcount += length($symline) - 2;
1257 (my $s_uc = $s) =~ tr/a-z/A-Z/;
1259 $v ? "DATA" : "PROCEDURE";
1262 ? " ,$s_uc/$s=$symtype -\n ,$s=$symtype -\n"
1263 : " ,$s=$symtype -\n ,SPARE -\n");
1264 if ($symvtextcount + length($symline) - 2 > 1024) {
1265 print OUT ")\nSYMBOL_VECTOR=(-\n";
1266 $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
1268 if ($symvtextcount == 16) {
1269 # Take away first comma
1273 $symvtextcount += length($symline) - 2;
1275 printf OUT " %s%-39s DATA\n",
1278 printf OUT " %s%s\n",
1284 } while ($linux && $thisversion ne $currversion);
1286 if ($prevprevsymversion ne "") {
1287 print OUT " local: *;\n} OPENSSL_$prevprevsymversion;\n\n";
1289 print OUT " local: *;\n};\n\n";
1293 (my $libvmaj, my $libvmin, my $libvedit) =
1294 $currversion =~ /^(\d+)_(\d+)_(\d+)$/;
1295 # The reason to multiply the edit number with 100 is to make space
1296 # for the possibility that we want to encode the patch letters
1297 print OUT "GSMATCH=LEQUAL,",($libvmaj * 100 + $libvmin),",",($libvedit * 100),"\n";
1313 my ($baseversion, $currversion) = get_openssl_version();
1315 open(IN,"<$name") || die "unable to open $name:$!\n";
1317 s|\R$||; # Better chomp
1321 if (defined $ret{$a[0]}) {
1322 # This is actually perfectly OK
1323 #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
1325 if ($max_num > $a[1]) {
1326 print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
1328 elsif ($max_num == $a[1]) {
1329 # This is actually perfectly OK
1330 #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
1331 if ($a[0] eq $prev) {
1333 $a[0] .= "{$prev_cnt}";
1340 # Existence will be proven later, in do_defs
1344 #Sanity check the version number
1345 if (defined $prevversion) {
1346 check_version_lte($prevversion, $a[2]);
1348 check_version_lte($a[2], $currversion);
1349 $prevversion = $a[2];
1350 $ret{$a[0]}=$a[1]."\\".$a[2]."\\".$a[3]; # \\ is a special marker
1352 $max_num = $a[1] if $a[1] > $max_num;
1356 print STDERR "Warning: $num_noinfo symbols were without info.";
1358 printf STDERR " The rewrite will fix this.\n";
1360 printf STDERR " You should do a rewrite to fix this.\n";
1369 (my $str, my $what) = @_;
1370 (my $n, my $v, my $i) = split(/\\/,$str);
1380 (*OUT,$name,*nums,@symbols)=@_;
1383 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1384 my $r; my %r; my %rsyms;
1386 (my $s, my $i) = split /\\/, $r;
1387 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1388 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1389 $r{$a} = $s."\\".$i;
1394 foreach $_ (@symbols) {
1395 (my $n, my $i) = split /\\/;
1400 &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
1404 (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
1405 next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
1406 next if defined($rsyms{$sym});
1407 print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
1408 $i="NOEXIST::FUNCTION:"
1409 if !defined($i) || $i eq "" || !defined($syms{$sym});
1411 $s2 =~ s/\{[0-9]+\}$//;
1412 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1413 if (exists $r{$sym}) {
1414 (my $s, $i) = split /\\/,$r{$sym};
1416 $s2 =~ s/\{[0-9]+\}$//;
1417 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
1424 (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
1429 ($basevers, $vers) = get_openssl_version();
1431 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1432 my $r; my %r; my %rsyms;
1434 (my $s, my $i) = split /\\/, $r;
1435 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1436 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1437 $r{$a} = $s."\\".$i;
1441 foreach $sym (@symbols) {
1442 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1443 next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
1444 next if defined($rsyms{$sym});
1445 die "ERROR: Symbol $sym had no info attached to it."
1447 if (!exists $nums{$s}) {
1450 $s2 =~ s/\{[0-9]+\}$//;
1451 printf OUT "%s%-39s %d\t%s\t%s\n","",$s2, ++$start_num,$vers,$i;
1452 if (exists $r{$s}) {
1453 ($s, $i) = split /\\/,$r{$s};
1454 $s =~ s/\{[0-9]+\}$//;
1455 printf OUT "%s%-39s %d\t%s\t%s\n","",$s, $start_num,$vers,$i;
1460 print STDERR "$name: Added $new_syms new symbols\n";
1462 print STDERR "$name: No new symbols added\n";
1468 (*nums, my @symbols)=@_;
1469 my %existing; my @remaining;
1471 foreach $sym (@symbols) {
1472 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1475 foreach $sym (keys %nums) {
1476 if (!exists $existing{$sym}) {
1477 push @remaining, $sym;
1481 print STDERR "The following symbols do not seem to exist:\n";
1482 foreach $sym (@remaining) {
1483 print STDERR "\t",$sym,"\n";
1490 my $line = shift(@_);
1492 my $open = $line =~ tr/\(//;
1493 my $close = $line =~ tr/\)//;
1495 return $open - $close;
1498 #Parse opensslv.h to get the current version number. Also work out the base
1499 #version, i.e. the lowest version number that is binary compatible with this
1501 sub get_openssl_version()
1503 my $fn = catfile($config{sourcedir},"include","openssl","opensslv.h");
1504 open (IN, "$fn") || die "Can't open opensslv.h";
1507 if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
1509 (my $baseversion = $1) =~ s/\./_/g;
1511 return ($baseversion."0", $baseversion.$suffix);
1514 die "Can't find OpenSSL version number\n";
1517 #Given an OpenSSL version number, calculate the next version number. If the
1518 #version number gets to a.b.czz then we go to a.b.(c+1)
1519 sub get_next_version()
1521 my $thisversion = shift;
1523 my ($base, $letter) = $thisversion =~ /^(\d_\d_\d)([a-z]{0,2})$/;
1525 if ($letter eq "zz") {
1526 my $lastnum = substr($base, -1);
1527 return substr($base, 0, length($base)-1).(++$lastnum);
1529 return $base.get_next_letter($letter);
1532 #Given the letters off the end of an OpenSSL version string, calculate what
1533 #the letters for the next release would be.
1534 sub get_next_letter()
1536 my $thisletter = shift;
1537 my $baseletter = "";
1540 if ($thisletter eq "") {
1543 if ((length $thisletter) > 1) {
1544 ($baseletter, $endletter) = $thisletter =~ /([a-z]+)([a-z])/;
1546 $endletter = $thisletter;
1549 if ($endletter eq "z") {
1550 return $thisletter."a";
1552 return $baseletter.(++$endletter);
1556 #Check if a version is less than or equal to the current version. Its a fatal
1557 #error if not. They must also only differ in letters, or the last number (i.e.
1558 #the first two numbers must be the same)
1559 sub check_version_lte()
1561 my ($testversion, $currversion) = @_;
1566 my ($cvnums) = $currversion =~ /^(\d_\d_\d)[a-z]*$/;
1567 my ($tvnums) = $testversion =~ /^(\d_\d_\d)[a-z]*$/;
1569 #Die if we can't parse the version numbers or they don't look sane
1570 die "Invalid version number: $testversion and $currversion\n"
1571 if (!defined($cvnums) || !defined($tvnums)
1572 || length($cvnums) != 5
1573 || length($tvnums) != 5);
1575 #If the base versions (without letters) don't match check they only differ
1577 if ($cvnums ne $tvnums) {
1578 die "Invalid version number: $testversion "
1579 ."for current version $currversion\n"
1580 if (substr($cvnums, 0, 4) ne substr($tvnums, 0, 4));
1583 #If we get here then the base version (i.e. the numbers) are the same - they
1584 #only differ in the letters
1586 $lentv = length $testversion;
1587 $lencv = length $currversion;
1589 #If the testversion has more letters than the current version then it must
1590 #be later (or malformed)
1591 if ($lentv > $lencv) {
1592 die "Invalid version number: $testversion "
1593 ."is greater than $currversion\n";
1596 #Get the last letter from the current version
1597 my ($cvletter) = $currversion =~ /([a-z])$/;
1598 if (defined $cvletter) {
1599 ($cvbase) = $currversion =~ /(\d_\d_\d[a-z]*)$cvletter$/;
1601 $cvbase = $currversion;
1603 die "Unable to parse version number $currversion" if (!defined $cvbase);
1605 my ($tvletter) = $testversion =~ /([a-z])$/;
1606 if (defined $tvletter) {
1607 ($tvbase) = $testversion =~ /(\d_\d_\d[a-z]*)$tvletter$/;
1609 $tvbase = $testversion;
1611 die "Unable to parse version number $testversion" if (!defined $tvbase);
1613 if ($lencv > $lentv) {
1614 #If current version has more letters than testversion then testversion
1615 #minus the final letter must be a substring of the current version
1616 die "Invalid version number $testversion "
1617 ."is greater than $currversion or is invalid\n"
1618 if (index($cvbase, $tvbase) != 0);
1620 #If both versions have the same number of letters then they must be
1621 #equal up to the last letter, and the last letter in testversion must
1622 #be less than or equal to the last letter in current version.
1623 die "Invalid version number $testversion "
1624 ."is greater than $currversion\n"
1625 if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));
1631 my ($decl, $plats, $algs) = @_;
1632 $decl =~ /^\s*(DEPRECATEDIN_\d+_\d+_\d+)\s*\((.*)\)\s*$/
1633 or die "Bad DEPRECTEDIN: $decl\n";
1634 my $info1 .= "#INFO:";
1635 $info1 .= join(',', @{$plats}) . ":";
1637 $info1 .= join(',',@{$algs}, $1) . ";";
1638 $info2 .= join(',',@{$algs}) . ";";
1639 return $info1 . $2 . ";" . $info2;