Remove extraneous output from util/mk scripts
[openssl.git] / util / mkdef.pl
index c0ca92cf21b4161a52bb934dc9439999b627d7bf..3151800007ac4197f5ed54b64d04d07d28d8ab5d 100755 (executable)
@@ -38,6 +38,9 @@
 #   exclude.
 #
 
+use lib ".";
+use configdata;
+
 my $debug=0;
 
 my $crypto_num= "util/libeay.num";
@@ -84,6 +87,8 @@ my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
                          "CRYPTO_MDEBUG",
                         # Engines
                          "STATIC_ENGINE", "ENGINE", "HW", "GMP",
+                        # Entropy Gathering
+                        "EGD",
                          # X.509v3 Signed Certificate Timestamps
                          "SCT",
                         # RFC3779
@@ -101,7 +106,9 @@ my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
                         # NEXTPROTONEG
                         "NEXTPROTONEG",
                         # Deprecated functions
-                        "DEPRECATED",
+                        "DEPRECATEDIN_0_9_8",
+                        "DEPRECATEDIN_1_0_0",
+                        "DEPRECATEDIN_1_1_0",
                         # SCTP
                         "SCTP",
                         # SRTP
@@ -121,17 +128,12 @@ my %disabled_algorithms;
 foreach (@known_algorithms) {
     $disabled_algorithms{$_} = 0;
 }
-
-my $options="";
-open(IN,"<Makefile") || die "unable to open Makefile!\n";
-while(<IN>) {
-    $options=$1 if (/^OPTIONS=(.*)$/);
-}
-close(IN);
+# disabled by default
+$disabled_algorithms{"STATIC_ENGINE"} = 1;
 
 my $zlib;
 
-foreach (@ARGV, split(/ /, $options))
+foreach (@ARGV, split(/ /, $config{options}))
        {
        $debug=1 if $_ eq "debug";
        $W32=1 if $_ eq "32";
@@ -174,8 +176,23 @@ foreach (@ARGV, split(/ /, $options))
        $do_ctestall=1 if $_ eq "ctestall";
        $do_checkexist=1 if $_ eq "exist";
        #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
-
-       if (/^(enable|disable|no)-(.*)$/) {
+       if (/^--api=(\d+)\.(\d+)\.(\d+)$/) {
+               my $apiv = sprintf "%x%02x%02x", $1, $2, $3;
+               foreach (keys %disabled_algorithms) {
+                       if (/^DEPRECATEDIN_(\d+)_(\d+)_(\d+)$/) {
+                               my $depv = sprintf "%x%02x%02x", $1, $2, $3;
+                               $disabled_algorithms{$_} = 1 if $apiv ge $depv;
+                       }
+               }
+       }
+       if (/^no-deprecated$/) {
+               foreach (keys %disabled_algorithms) {
+                       if (/^DEPRECATEDIN_/) {
+                               $disabled_algorithms{$_} = 1;
+                       }
+               }
+       }
+       elsif (/^(enable|disable|no)-(.*)$/) {
                my $alg = uc $2;
         $alg =~ tr/-/_/;
                if (exists $disabled_algorithms{$alg}) {
@@ -275,7 +292,6 @@ $crypto.=" include/openssl/comp.h" ; # unless $no_comp;
 $crypto.=" include/openssl/ocsp.h";
 $crypto.=" include/openssl/ui.h";
 #$crypto.=" include/openssl/store.h";
-$crypto.=" include/openssl/pqueue.h";
 $crypto.=" include/openssl/cms.h";
 $crypto.=" include/openssl/jpake.h";
 $crypto.=" include/openssl/srp.h";
@@ -439,14 +455,15 @@ sub do_defs
                print STDERR "DEBUG: parsing ----------\n" if $debug;
                while(<IN>) {
                        if($parens > 0) {
-                               #Inside a DECLARE_DEPRECATED
+                               #Inside a DEPRECATEDIN
                                $stored_multiline .= $_;
                                chomp $stored_multiline;
-                               print STDERR "DEBUG: Continuing multiline DEPRECATED: $stored_multiline\n" if $debug;
+                               print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug;
                                $parens = count_parens($stored_multiline);
                                if ($parens == 0) {
-                                       $stored_multiline =~ /^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/;
-                                       $def .= "$1(void);";
+                                       $def .= do_deprecated($stored_multiline,
+                                                       \@current_platforms,
+                                                       \@current_algorithms);
                                }
                                next;
                        }
@@ -840,14 +857,16 @@ sub do_defs
                                        &$make_variant("_shadow_$2","_shadow_$2",
                                                      "EXPORT_VAR_AS_FUNCTION",
                                                      "FUNCTION");
-                               } elsif (/^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/) {
+                               } elsif (/^\s*DEPRECATEDIN/) {
                                        $parens = count_parens($_);
                                        if ($parens == 0) {
-                                               $def .= "$1(void);";
+                                               $def .= do_deprecated($_,
+                                                       \@current_platforms,
+                                                       \@current_algorithms);
                                        } else {
                                                $stored_multiline = $_;
                                                chomp $stored_multiline;
-                                               print STDERR "DEBUG: Found multiline DEPRECATED starting with: $stored_multiline\n" if $debug;
+                                               print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug;
                                                next;
                                        }
                                } elsif ($tag{'CONST_STRICT'} != 1) {
@@ -912,21 +931,6 @@ sub do_defs
 
                        $p = $plats;
                        $a = $algs;
-                       $a .= ",BF" if($s =~ /EVP_bf/);
-                       $a .= ",CAST" if($s =~ /EVP_cast/);
-                       $a .= ",DES" if($s =~ /EVP_des/);
-                       $a .= ",DSA" if($s =~ /EVP_dss/);
-                       $a .= ",IDEA" if($s =~ /EVP_idea/);
-                       $a .= ",MD2" if($s =~ /EVP_md2/);
-                       $a .= ",MD4" if($s =~ /EVP_md4/);
-                       $a .= ",MD5" if($s =~ /EVP_md5/);
-                       $a .= ",RC2" if($s =~ /EVP_rc2/);
-                       $a .= ",RC4" if($s =~ /EVP_rc4/);
-                       $a .= ",RC5" if($s =~ /EVP_rc5/);
-                       $a .= ",RMD160" if($s =~ /EVP_ripemd/);
-                       $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
-                       $a .= ",RSA" if($s =~ /RSAPrivateKey/);
-                       $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
 
                        $platform{$s} =
                            &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
@@ -1024,7 +1028,8 @@ sub reduce_platforms
        return $ret;
 }
 
-sub info_string {
+sub info_string
+{
        (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
 
        my %a = defined($algorithms) ?
@@ -1042,13 +1047,13 @@ sub info_string {
        return $ret;
 }
 
-sub maybe_add_info {
+sub maybe_add_info
+{
        (my $name, *nums, my @symbols) = @_;
        my $sym;
        my $new_info = 0;
        my %syms=();
 
-       print STDERR "Updating $name info\n";
        foreach $sym (@symbols) {
                (my $s, my $i) = split /\\/, $sym;
                if (defined($nums{$s})) {
@@ -1072,12 +1077,11 @@ sub maybe_add_info {
                }
        }
        if ($new_info) {
-               print STDERR "$new_info old symbols got an info update\n";
+               print STDERR "$name: $new_info old symbols have updated info\n";
                if (!$do_rewrite) {
                        print STDERR "You should do a rewrite to fix this.\n";
                }
        } else {
-               print STDERR "No old symbols needed info update\n";
        }
 }
 
@@ -1167,15 +1171,9 @@ sub print_test_file
        }
 }
 
-sub get_version {
-   local *MF;
-   my $v = '?';
-   open MF, 'Makefile' or return $v;
-   while (<MF>) {
-     $v = $1, last if /^VERSION=(.*?)\s*$/;
-   }
-   close MF;
-   return $v;
+sub get_version
+{
+   return $config{version};
 }
 
 sub print_def_file
@@ -1191,7 +1189,7 @@ sub print_def_file
        my $prevsymversion = "", $prevprevsymversion = "";
         # For VMS
         my $prevnum = 0;
-        my $symbolcount = 0;
+        my $symvtextcount = 0;
 
        if ($W32)
                { $libname.="32"; }
@@ -1227,11 +1225,13 @@ EOF
                 {
                 my $libref = $name eq "ssl" ? "LIBCRYPTO.EXE /SHARE" : "";
                 print OUT <<"EOF";
-IDENTIFICATION="LIB$libname V$version"
+IDENTIFICATION="V$version"
+CASE_SENSITIVE=YES
 LIB$libname.OLB /LIBRARY
 $libref
 SYMBOL_VECTOR=(-
 EOF
+                $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
                 }
 
        (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
@@ -1295,25 +1295,34 @@ EOF
                                                print OUT "        $s2;\n";
                                         } elsif ($VMS) {
                                             while(++$prevnum < $n) {
-                                                if ($symbolcount > 1023) {
+                                                my $symline="SPARE, SPARE -";
+                                                if ($symvtextcount + length($symline) + 1 > 1024) {
                                                     print OUT ")\nSYMBOL_VECTOR=(-\n";
-                                                    $symbolcount = 0;
+                                                    $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
                                                 }
-                                                print OUT $symbolcount
-                                                    ? "    ," : "    ";
-                                                print OUT "dummy$prevnum=PRIVATE_PROCEDURE -\n";
-                                                $symbolcount++;
+                                                if ($symvtextcount > 16) {
+                                                    $symline = ",".$symline;
+                                                }
+                                                print OUT "    $symline\n";
+                                                $symvtextcount += length($symline);
                                             }
                                             (my $s_uc = $s) =~ tr/a-z/A-Z/;
-                                            if ($symbolcount > 1023) {
+                                            my $symtype=
+                                                $v ? "DATA" : "PROCEDURE";
+                                            my $symline=
+                                                ($s_uc ne $s
+                                                 ? "$s_uc/$s=$symtype, $s=$symtype"
+                                                 : "$s=$symtype, SPARE")
+                                                ." -";
+                                            if ($symvtextcount + length($symline) + 1 > 1024) {
                                                 print OUT ")\nSYMBOL_VECTOR=(-\n";
-                                                $symbolcount = 0;
+                                                $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
+                                            }
+                                            if ($symvtextcount > 16) {
+                                                $symline = ",".$symline;
                                             }
-                                            print OUT $symbolcount
-                                                ? "    ," : "    ";
-                                            print OUT "$s_uc/$s="
-                                                , ($v ? "DATA" : "PROCEDURE"), " -\n";
-                                            $symbolcount++;
+                                            print OUT "    $symline\n";
+                                            $symvtextcount += length($symline);
                                        } elsif($v && !$OS2) {
                                                printf OUT "    %s%-39s @%-8d DATA\n",
                                                                ($W32)?"":"_",$s2,$n;
@@ -1423,8 +1432,6 @@ sub rewrite_numbers
        (*OUT,$name,*nums,@symbols)=@_;
        my $thing;
 
-       print STDERR "Rewriting $name\n";
-
        my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
        my $r; my %r; my %rsyms;
        foreach $r (@r) {
@@ -1473,8 +1480,6 @@ sub update_numbers
 
        ($basevers, $vers) = get_openssl_version();
 
-       print STDERR "Updating $name numbers\n";
-
        my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
        my $r; my %r; my %rsyms;
        foreach $r (@r) {
@@ -1504,9 +1509,9 @@ sub update_numbers
                }
        }
        if($new_syms) {
-               print STDERR "$new_syms New symbols added\n";
+               print STDERR "$name: Added $new_syms new symbols\n";
        } else {
-               print STDERR "No New symbols Added\n";
+               print STDERR "$name: No new symbols added\n";
        }
 }
 
@@ -1552,7 +1557,7 @@ sub get_openssl_version()
        while(<IN>) {
                if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
                        my $suffix = $2;
-                       my $baseversion = $1 =~ s/\./_/gr;
+                       (my $baseversion = $1) =~ s/\./_/g;
                        close IN;
                        return ($baseversion."0", $baseversion.$suffix);
                }
@@ -1672,3 +1677,16 @@ sub check_version_lte()
                        if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));
        }
 }
+
+sub do_deprecated()
+{
+       my ($decl, $plats, $algs) = @_;
+       $decl =~ /^\s*(DEPRECATEDIN_\d+_\d+_\d+)\s*\((.*)\)\s*$/
+            or die "Bad DEPRECTEDIN: $decl\n";
+       my $info1 .= "#INFO:";
+       $info1 .= join(',', @{$plats}) . ":";
+       my $info2 = $info1;
+       $info1 .= join(',',@{$algs}, $1) . ";";
+       $info2 .= join(',',@{$algs}) . ";";
+       return $info1 . $2 . ";" . $info2;
+}