Fix various windows compilation issues
[openssl.git] / util / mkdef.pl
index 3dc846f6aa13c7c1295d986dcaec16a939943499..faed4028b52cda331b5ade3d254b11353058192a 100755 (executable)
@@ -72,16 +72,15 @@ my $VMSVAX=0;
 my $VMSNonVAX=0;
 my $VMS=0;
 my $W32=0;
-my $W16=0;
 my $NT=0;
 my $OS2=0;
 # Set this to make typesafe STACK definitions appear in DEF
 my $safe_stack_def = 0;
 
-my @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT",
+my @known_platforms = ( "__FreeBSD__", "PERL5",
                        "EXPORT_VAR_AS_FUNCTION", "ZLIB",
                        "OPENSSL_FIPS", "OPENSSL_FIPSCAPABLE" );
-my @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" );
+my @known_ossl_platforms = ( "VMS", "WIN32", "WINNT", "OS2" );
 my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
                         "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
                         "SHA256", "SHA512", "RIPEMD",
@@ -98,16 +97,14 @@ my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
                         "FP_API", "STDIO", "SOCK", "KRB5", "DGRAM",
                         # Engines
                         "STATIC_ENGINE", "ENGINE", "HW", "GMP",
-                        # RFC3779
-                        "RFC3779",
                         # TLS
                         "TLSEXT", "PSK", "SRP", "HEARTBEATS",
                         # CMS
                         "CMS",
                         # CryptoAPI Engine
                         "CAPIENG",
-                        # SSL v2
-                        "SSL2",
+                        # SSL v3 method
+                        "SSL3_METHOD",
                         # JPAKE
                         "JPAKE",
                         # NEXTPROTONEG
@@ -117,9 +114,15 @@ my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
                         # Hide SSL internals
                         "SSL_INTERN",
                         # SCTP
-                        "SCTP",
+                        "SCTP",
+                        # SRTP
+                        "SRTP",
                         # SSL TRACE
-                        "SSL_TRACE");
+                        "SSL_TRACE",
+                        # Unit testing
+                        "UNIT_TEST",
+                        # OCB mode
+                        "OCB");
 
 my $options="";
 open(IN,"<Makefile") || die "unable to open Makefile!\n";
@@ -137,9 +140,10 @@ my $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
 my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5;
 my $no_ec; my $no_ecdsa; my $no_ecdh; my $no_engine; my $no_hw;
 my $no_fp_api; my $no_static_engine=1; my $no_gmp; my $no_deprecated;
-my $no_rfc3779; my $no_psk; my $no_tlsext; my $no_cms; my $no_capieng;
-my $no_jpake; my $no_ssl2; my $no_ec2m; my $no_nextprotoneg;
-my $no_srp; my $no_nistp_gcc; my $no_sctp; my $no_ssl_trace;
+my $no_psk; my $no_tlsext; my $no_cms; my $no_capieng;
+my $no_jpake; my $no_srp; my $no_ec2m; my $no_nistp_gcc; 
+my $no_nextprotoneg; my $no_sctp; my $no_srtp; my $no_ssl_trace;
+my $no_unit_test; my $no_ssl3_method; my $no_ocb;
 
 my $fips;
 
@@ -150,7 +154,7 @@ foreach (@ARGV, split(/ /, $options))
        {
        $debug=1 if $_ eq "debug";
        $W32=1 if $_ eq "32";
-       $W16=1 if $_ eq "16";
+       die "win16 not supported" if $_ eq "16";
        if($_ eq "NT") {
                $W32 = 1;
                $NT = 1;
@@ -227,18 +231,21 @@ foreach (@ARGV, split(/ /, $options))
        elsif (/^no-engine$/)   { $no_engine=1; }
        elsif (/^no-hw$/)       { $no_hw=1; }
        elsif (/^no-gmp$/)      { $no_gmp=1; }
-       elsif (/^no-rfc3779$/)  { $no_rfc3779=1; }
        elsif (/^no-tlsext$/)   { $no_tlsext=1; }
        elsif (/^no-cms$/)      { $no_cms=1; }
        elsif (/^no-ec2m$/)     { $no_ec2m=1; }
        elsif (/^no-ec-nistp224-64-gcc-128$/)   { $no_nistp_gcc=1; }
        elsif (/^no-nextprotoneg$/)     { $no_nextprotoneg=1; }
-       elsif (/^no-ssl2$/)     { $no_ssl2=1; }
+       elsif (/^no-ssl3-method$/) { $no_ssl3_method=1; }
        elsif (/^no-ssl-trace$/) { $no_ssl_trace=1; }
        elsif (/^no-capieng$/)  { $no_capieng=1; }
        elsif (/^no-jpake$/)    { $no_jpake=1; }
        elsif (/^no-srp$/)      { $no_srp=1; }
        elsif (/^no-sctp$/)     { $no_sctp=1; }
+       elsif (/^no-srtp$/)     { $no_srtp=1; }
+       elsif (/^no-unit-test$/){ $no_unit_test=1; }
+       elsif (/^no-deprecated$/) { $no_deprecated=1; }
+       elsif (/^no-ocb/){ $no_ocb=1; }
        }
 
 
@@ -252,15 +259,10 @@ if (!$libname) {
 }
 
 # If no platform is given, assume WIN32
-if ($W32 + $W16 + $VMS + $OS2 == 0) {
+if ($W32 + $VMS + $OS2 == 0) {
        $W32 = 1;
 }
 
-# Add extra knowledge
-if ($W16) {
-       $no_fp_api=1;
-}
-
 if (!$do_ssl && !$do_crypto)
        {
        print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n";
@@ -307,6 +309,7 @@ $crypto.=" crypto/ec/ec.h" ; # unless $no_ec;
 $crypto.=" crypto/ecdsa/ecdsa.h" ; # unless $no_ecdsa;
 $crypto.=" crypto/ecdh/ecdh.h" ; # unless $no_ecdh;
 $crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac;
+$crypto.=" crypto/cmac/cmac.h" ;
 
 $crypto.=" crypto/engine/engine.h"; # unless $no_engine;
 $crypto.=" crypto/stack/stack.h" ; # unless $no_stack;
@@ -342,7 +345,6 @@ $crypto.=" crypto/cms/cms.h";
 $crypto.=" crypto/jpake/jpake.h";
 $crypto.=" crypto/srp/srp.h";
 $crypto.=" crypto/modes/modes.h";
-#$crypto.=" fips/fips.h fips/rand/fips_rand.h";
 
 my $symhacks="crypto/symhacks.h";
 
@@ -426,6 +428,7 @@ sub do_defs
                                # is the same name as the original.
        my $cpp;
        my %unknown_algorithms = ();
+       my $parens = 0;
 
        foreach $file (split(/\s+/,$symhacksfile." ".$files))
                {
@@ -436,6 +439,7 @@ sub do_defs
                        (map { $_ => 0 } @known_platforms),
                        (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
                        (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
+                       (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
                        NOPROTO         => 0,
                        PERL5           => 0,
                        _WINDLL         => 0,
@@ -498,6 +502,11 @@ sub do_defs
 
                print STDERR "DEBUG: parsing ----------\n" if $debug;
                while(<IN>) {
+                       if($parens > 0) {
+                               #Inside a DECLARE_DEPRECATED
+                               $parens += count_parens($_);
+                               next;
+                       }
                        if (/\/\* Error codes for the \w+ functions\. \*\//)
                                {
                                undef @tag;
@@ -601,6 +610,8 @@ sub do_defs
                                        pop(@tag);
                                        if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
                                                $t=$1;
+                                       } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
+                                               $t=$1;
                                        } else {
                                                $t="";
                                        }
@@ -650,10 +661,15 @@ sub do_defs
                                           map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
                                                     $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_  : "" }
                                           @known_ossl_platforms);
+                               @current_algorithms = ();
                                @current_algorithms =
                                    grep(!/^$/,
                                         map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
                                         @known_algorithms);
+                               push @current_algorithms
+                                   , grep(!/^$/,
+                                        map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
+                                        @known_algorithms);
                                $def .=
                                    "#INFO:"
                                        .join(',',@current_platforms).":"
@@ -819,10 +835,9 @@ sub do_defs
                                } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
                                         /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
                                         /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
-                                       # Things not in Win16
                                        $def .=
                                            "#INFO:"
-                                               .join(',',"!WIN16",@current_platforms).":"
+                                               .join(',',@current_platforms).":"
                                                    .join(',',@current_algorithms).";";
                                        $def .= "int PEM_read_$1(void);";
                                        $def .= "int PEM_write_$1(void);";
@@ -837,10 +852,9 @@ sub do_defs
                                } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
                                        /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
                                         /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
-                                       # Things not in Win16
                                        $def .=
                                            "#INFO:"
-                                               .join(',',"!WIN16",@current_platforms).":"
+                                               .join(',',@current_platforms).":"
                                                    .join(',',@current_algorithms).";";
                                        $def .= "int PEM_write_$1(void);";
                                        $def .=
@@ -852,10 +866,9 @@ sub do_defs
                                        next;
                                } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
                                         /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
-                                       # Things not in Win16
                                        $def .=
                                            "#INFO:"
-                                               .join(',',"!WIN16",@current_platforms).":"
+                                               .join(',',@current_platforms).":"
                                                    .join(',',@current_algorithms).";";
                                        $def .= "int PEM_read_$1(void);";
                                        $def .=
@@ -884,6 +897,10 @@ sub do_defs
                                        &$make_variant("_shadow_$2","_shadow_$2",
                                                      "EXPORT_VAR_AS_FUNCTION",
                                                      "FUNCTION");
+                               } elsif (/^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/) {
+                                       $def .= "$1(void);";
+                                       $parens = count_parens($_);
+                                       next;
                                } elsif ($tag{'CONST_STRICT'} != 1) {
                                        if (/\{|\/\*|\([^\)]*$/) {
                                                $line = $_;
@@ -958,7 +975,6 @@ sub do_defs
                        $a .= ",RC4" if($s =~ /EVP_rc4/);
                        $a .= ",RC5" if($s =~ /EVP_rc5/);
                        $a .= ",RIPEMD" if($s =~ /EVP_ripemd/);
-                       $a .= ",SHA" if($s =~ /EVP_sha/);
                        $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
                        $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
                        $a .= ",RSA" if($s =~ /RSAPrivateKey/);
@@ -988,7 +1004,7 @@ sub do_defs
        # Prune the returned symbols
 
         delete $syms{"bn_dump1"};
-       $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh";
+       $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
 
        $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
        $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
@@ -1135,14 +1151,13 @@ sub is_valid
                        if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; }
                        if ($keyword eq "VMS" && $VMS) { return 1; }
                        if ($keyword eq "WIN32" && $W32) { return 1; }
-                       if ($keyword eq "WIN16" && $W16) { return 1; }
                        if ($keyword eq "WINNT" && $NT) { return 1; }
                        if ($keyword eq "OS2" && $OS2) { return 1; }
                        # Special platforms:
                        # EXPORT_VAR_AS_FUNCTION means that global variables
                        # will be represented as functions.  This currently
                        # only happens on VMS-VAX.
-                       if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) {
+                       if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32)) {
                                return 1;
                        }
                        if ($keyword eq "OPENSSL_FIPSCAPABLE") {
@@ -1193,7 +1208,6 @@ sub is_valid
                        if ($keyword eq "FP_API" && $no_fp_api) { return 0; }
                        if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; }
                        if ($keyword eq "GMP" && $no_gmp) { return 0; }
-                       if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; }
                        if ($keyword eq "TLSEXT" && $no_tlsext) { return 0; }
                        if ($keyword eq "PSK" && $no_psk) { return 0; }
                        if ($keyword eq "CMS" && $no_cms) { return 0; }
@@ -1201,13 +1215,16 @@ sub is_valid
                                        { return 0; }
                        if ($keyword eq "EC2M" && $no_ec2m) { return 0; }
                        if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; }
-                       if ($keyword eq "SSL2" && $no_ssl2) { return 0; }
+                       if ($keyword eq "SSL3_METHOD" && $no_ssl3_method) { return 0; }
                        if ($keyword eq "SSL_TRACE" && $no_ssl_trace) { return 0; }
                        if ($keyword eq "CAPIENG" && $no_capieng) { return 0; }
                        if ($keyword eq "JPAKE" && $no_jpake) { return 0; }
                        if ($keyword eq "SRP" && $no_srp) { return 0; }
                        if ($keyword eq "SCTP" && $no_sctp) { return 0; }
+                       if ($keyword eq "SRTP" && $no_srtp) { return 0; }
+                       if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; }
                        if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; }
+                       if ($keyword eq "OCB" && $no_ocb) { return 0; }
 
                        # Nothing recognise as true
                        return 1;
@@ -1286,8 +1303,6 @@ sub print_def_file
 
        if ($W32)
                { $libname.="32"; }
-       elsif ($W16)
-               { $libname.="16"; }
        elsif ($OS2)
                { # DLL names should not clash on the whole system.
                  # However, they should not have any particular relationship
@@ -1312,19 +1327,6 @@ LIBRARY         $libname $liboptions
 
 EOF
 
-       if ($W16) {
-               print <<"EOF";
-CODE            PRELOAD MOVEABLE
-DATA            PRELOAD MOVEABLE SINGLE
-
-EXETYPE                WINDOWS
-
-HEAPSIZE       4096
-STACKSIZE      8192
-
-EOF
-       }
-
        print "EXPORTS\n";
 
        (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
@@ -1540,3 +1542,13 @@ sub check_existing
        }
 }
 
+sub count_parens
+{
+       my $line = shift(@_);
+
+       my $open = $line =~ tr/\(//;
+       my $close = $line =~ tr/\)//;
+
+       return $open - $close;
+}
+