155714Skris#!/usr/local/bin/perl -w 255714Skris# 355714Skris# generate a .def file 455714Skris# 555714Skris# It does this by parsing the header files and looking for the 655714Skris# prototyped functions: it then prunes the output. 755714Skris# 868651Skris# Intermediary files are created, call libeay.num and ssleay.num,... 968651Skris# Previously, they had the following format: 1068651Skris# 1168651Skris# routine-name nnnn 1268651Skris# 1368651Skris# But that isn't enough for a number of reasons, the first on being that 1468651Skris# this format is (needlessly) very Win32-centric, and even then... 1568651Skris# One of the biggest problems is that there's no information about what 1668651Skris# routines should actually be used, which varies with what crypto algorithms 1768651Skris# are disabled. Also, some operating systems (for example VMS with VAX C) 1868651Skris# need to keep track of the global variables as well as the functions. 1968651Skris# 2068651Skris# So, a remake of this script is done so as to include information on the 2168651Skris# kind of symbol it is (function or variable) and what algorithms they're 2268651Skris# part of. This will allow easy translating to .def files or the corresponding 2368651Skris# file in other operating systems (a .opt file for VMS, possibly with a .mar 2468651Skris# file). 2568651Skris# 2668651Skris# The format now becomes: 2768651Skris# 2868651Skris# routine-name nnnn info 2968651Skris# 3068651Skris# and the "info" part is actually a colon-separated string of fields with 3168651Skris# the following meaning: 3268651Skris# 3368651Skris# existence:platform:kind:algorithms 3468651Skris# 3568651Skris# - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is 3668651Skris# found somewhere in the source, 3768651Skris# - "platforms" is empty if it exists on all platforms, otherwise it contains 3868651Skris# comma-separated list of the platform, just as they are if the symbol exists 3968651Skris# for those platforms, or prepended with a "!" if not. This helps resolve 40109998Smarkm# symbol name variants for platforms where the names are too long for the 4168651Skris# compiler or linker, or if the systems is case insensitive and there is a 42109998Smarkm# clash, or the symbol is implemented differently (see 43109998Smarkm# EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found 44109998Smarkm# in the file crypto/symhacks.h. 45109998Smarkm# The semantics for the platforms is that every item is checked against the 46109998Smarkm# environment. For the negative items ("!FOO"), if any of them is false 47109998Smarkm# (i.e. "FOO" is true) in the environment, the corresponding symbol can't be 48109998Smarkm# used. For the positive itms, if all of them are false in the environment, 49109998Smarkm# the corresponding symbol can't be used. Any combination of positive and 50109998Smarkm# negative items are possible, and of course leave room for some redundancy. 5168651Skris# - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious. 5268651Skris# - "algorithms" is a comma-separated list of algorithm names. This helps 5368651Skris# exclude symbols that are part of an algorithm that some user wants to 5468651Skris# exclude. 5568651Skris# 5655714Skris 57109998Smarkmmy $debug=0; 58109998Smarkm 5968651Skrismy $crypto_num= "util/libeay.num"; 6068651Skrismy $ssl_num= "util/ssleay.num"; 61109998Smarkmmy $libname; 6255714Skris 6355714Skrismy $do_update = 0; 64109998Smarkmmy $do_rewrite = 1; 6555714Skrismy $do_crypto = 0; 6655714Skrismy $do_ssl = 0; 6759191Skrismy $do_ctest = 0; 6868651Skrismy $do_ctestall = 0; 69109998Smarkmmy $do_checkexist = 0; 7055714Skris 71109998Smarkmmy $VMSVAX=0; 72205128Ssimonmy $VMSNonVAX=0; 7368651Skrismy $VMS=0; 7468651Skrismy $W32=0; 7568651Skrismy $W16=0; 7659191Skrismy $NT=0; 77109998Smarkmmy $OS2=0; 7855714Skris# Set this to make typesafe STACK definitions appear in DEF 7968651Skrismy $safe_stack_def = 0; 8055714Skris 81238405Sjkimmy @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT", 82238405Sjkim "EXPORT_VAR_AS_FUNCTION", "ZLIB", "OPENSSL_FIPS" ); 83109998Smarkmmy @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" ); 8468651Skrismy @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF", 85109998Smarkm "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1", 86160814Ssimon "SHA256", "SHA512", "RIPEMD", 87238405Sjkim "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "ECDH", "ECDSA", "EC2M", 88238405Sjkim "HMAC", "AES", "CAMELLIA", "SEED", "GOST", 89238405Sjkim # EC_NISTP_64_GCC_128 90238405Sjkim "EC_NISTP_64_GCC_128", 91109998Smarkm # Envelope "algorithms" 92109998Smarkm "EVP", "X509", "ASN1_TYPEDEFS", 93109998Smarkm # Helper "algorithms" 94109998Smarkm "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR", 95109998Smarkm "LOCKING", 96109998Smarkm # External "algorithms" 97160814Ssimon "FP_API", "STDIO", "SOCK", "KRB5", "DGRAM", 98160814Ssimon # Engines 99160814Ssimon "STATIC_ENGINE", "ENGINE", "HW", "GMP", 100238405Sjkim # RFC3779 101167612Ssimon "RFC3779", 102238405Sjkim # TLS 103238405Sjkim "TLSEXT", "PSK", "SRP", "HEARTBEATS", 104194206Ssimon # CMS 105194206Ssimon "CMS", 106194206Ssimon # CryptoAPI Engine 107194206Ssimon "CAPIENG", 108238405Sjkim # SSL v2 109238405Sjkim "SSL2", 110298999Sjkim # SSL v2 method 111298999Sjkim "SSL2_METHOD", 112276864Sjkim # SSL v3 method 113276864Sjkim "SSL3_METHOD", 114194206Ssimon # JPAKE 115194206Ssimon "JPAKE", 116238405Sjkim # NEXTPROTONEG 117238405Sjkim "NEXTPROTONEG", 118160814Ssimon # Deprecated functions 119238405Sjkim "DEPRECATED", 120238405Sjkim # Hide SSL internals 121238405Sjkim "SSL_INTERN", 122238405Sjkim # SCTP 123269686Sjkim "SCTP", 124273149Sjkim # SRTP 125273149Sjkim "SRTP", 126269686Sjkim # Unit testing 127269686Sjkim "UNIT_TEST"); 12868651Skris 12959191Skrismy $options=""; 130142425Snectaropen(IN,"<Makefile") || die "unable to open Makefile!\n"; 13155714Skriswhile(<IN>) { 13255714Skris $options=$1 if (/^OPTIONS=(.*)$/); 13355714Skris} 13455714Skrisclose(IN); 13555714Skris 13659191Skris# The following ciphers may be excluded (by Configure). This means functions 13759191Skris# defined with ifndef(NO_XXX) are not included in the .def file, and everything 13859191Skris# in directory xxx is ignored. 13959191Skrismy $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf; 140238405Sjkimmy $no_cast; my $no_whirlpool; my $no_camellia; my $no_seed; 14168651Skrismy $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2; 142109998Smarkmmy $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5; 143238405Sjkimmy $no_ec; my $no_ecdsa; my $no_ecdh; my $no_engine; my $no_hw; 144238405Sjkimmy $no_fp_api; my $no_static_engine=1; my $no_gmp; my $no_deprecated; 145238405Sjkimmy $no_rfc3779; my $no_psk; my $no_tlsext; my $no_cms; my $no_capieng; 146238405Sjkimmy $no_jpake; my $no_srp; my $no_ssl2; my $no_ec2m; my $no_nistp_gcc; 147273149Sjkimmy $no_nextprotoneg; my $no_sctp; my $no_srtp; 148298999Sjkimmy $no_unit_test; my $no_ssl3_method; my $no_ssl2_method; 149238405Sjkim 150194206Ssimonmy $fips; 15159191Skris 152238405Sjkimmy $zlib; 153160814Ssimon 154238405Sjkim 15555714Skrisforeach (@ARGV, split(/ /, $options)) 15655714Skris { 157109998Smarkm $debug=1 if $_ eq "debug"; 15855714Skris $W32=1 if $_ eq "32"; 15968651Skris $W16=1 if $_ eq "16"; 16055714Skris if($_ eq "NT") { 16155714Skris $W32 = 1; 16255714Skris $NT = 1; 16355714Skris } 164109998Smarkm if ($_ eq "VMS-VAX") { 165109998Smarkm $VMS=1; 166109998Smarkm $VMSVAX=1; 167109998Smarkm } 168205128Ssimon if ($_ eq "VMS-NonVAX") { 169109998Smarkm $VMS=1; 170205128Ssimon $VMSNonVAX=1; 171109998Smarkm } 17268651Skris $VMS=1 if $_ eq "VMS"; 173109998Smarkm $OS2=1 if $_ eq "OS2"; 174194206Ssimon $fips=1 if /^fips/; 175238405Sjkim if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic" 176238405Sjkim || $_ eq "enable-zlib-dynamic") { 177238405Sjkim $zlib = 1; 178194206Ssimon } 179194206Ssimon 18055714Skris $do_ssl=1 if $_ eq "ssleay"; 181109998Smarkm if ($_ eq "ssl") { 182109998Smarkm $do_ssl=1; 183109998Smarkm $libname=$_ 184109998Smarkm } 18555714Skris $do_crypto=1 if $_ eq "libeay"; 186109998Smarkm if ($_ eq "crypto") { 187109998Smarkm $do_crypto=1; 188109998Smarkm $libname=$_; 189109998Smarkm } 190160814Ssimon $no_static_engine=1 if $_ eq "no-static-engine"; 191160814Ssimon $no_static_engine=0 if $_ eq "enable-static-engine"; 19255714Skris $do_update=1 if $_ eq "update"; 19368651Skris $do_rewrite=1 if $_ eq "rewrite"; 19459191Skris $do_ctest=1 if $_ eq "ctest"; 19568651Skris $do_ctestall=1 if $_ eq "ctestall"; 196109998Smarkm $do_checkexist=1 if $_ eq "exist"; 19768651Skris #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK"; 19855714Skris 19955714Skris if (/^no-rc2$/) { $no_rc2=1; } 20055714Skris elsif (/^no-rc4$/) { $no_rc4=1; } 20155714Skris elsif (/^no-rc5$/) { $no_rc5=1; } 20255714Skris elsif (/^no-idea$/) { $no_idea=1; } 20372613Skris elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; } 20455714Skris elsif (/^no-bf$/) { $no_bf=1; } 20555714Skris elsif (/^no-cast$/) { $no_cast=1; } 206238405Sjkim elsif (/^no-whirlpool$/) { $no_whirlpool=1; } 20755714Skris elsif (/^no-md2$/) { $no_md2=1; } 20868651Skris elsif (/^no-md4$/) { $no_md4=1; } 20955714Skris elsif (/^no-md5$/) { $no_md5=1; } 21055714Skris elsif (/^no-sha$/) { $no_sha=1; } 21155714Skris elsif (/^no-ripemd$/) { $no_ripemd=1; } 21255714Skris elsif (/^no-mdc2$/) { $no_mdc2=1; } 21355714Skris elsif (/^no-rsa$/) { $no_rsa=1; } 21455714Skris elsif (/^no-dsa$/) { $no_dsa=1; } 21555714Skris elsif (/^no-dh$/) { $no_dh=1; } 216109998Smarkm elsif (/^no-ec$/) { $no_ec=1; } 217160814Ssimon elsif (/^no-ecdsa$/) { $no_ecdsa=1; } 218160814Ssimon elsif (/^no-ecdh$/) { $no_ecdh=1; } 21955714Skris elsif (/^no-hmac$/) { $no_hmac=1; } 220109998Smarkm elsif (/^no-aes$/) { $no_aes=1; } 221162911Ssimon elsif (/^no-camellia$/) { $no_camellia=1; } 222194206Ssimon elsif (/^no-seed$/) { $no_seed=1; } 223109998Smarkm elsif (/^no-evp$/) { $no_evp=1; } 224109998Smarkm elsif (/^no-lhash$/) { $no_lhash=1; } 225109998Smarkm elsif (/^no-stack$/) { $no_stack=1; } 226109998Smarkm elsif (/^no-err$/) { $no_err=1; } 227109998Smarkm elsif (/^no-buffer$/) { $no_buffer=1; } 228109998Smarkm elsif (/^no-bio$/) { $no_bio=1; } 229109998Smarkm #elsif (/^no-locking$/) { $no_locking=1; } 230109998Smarkm elsif (/^no-comp$/) { $no_comp=1; } 231109998Smarkm elsif (/^no-dso$/) { $no_dso=1; } 232109998Smarkm elsif (/^no-krb5$/) { $no_krb5=1; } 233111147Snectar elsif (/^no-engine$/) { $no_engine=1; } 234111147Snectar elsif (/^no-hw$/) { $no_hw=1; } 235160814Ssimon elsif (/^no-gmp$/) { $no_gmp=1; } 236167612Ssimon elsif (/^no-rfc3779$/) { $no_rfc3779=1; } 237194206Ssimon elsif (/^no-tlsext$/) { $no_tlsext=1; } 238194206Ssimon elsif (/^no-cms$/) { $no_cms=1; } 239238405Sjkim elsif (/^no-ec2m$/) { $no_ec2m=1; } 240238405Sjkim elsif (/^no-ec_nistp_64_gcc_128$/) { $no_nistp_gcc=1; } 241238405Sjkim elsif (/^no-nextprotoneg$/) { $no_nextprotoneg=1; } 242238405Sjkim elsif (/^no-ssl2$/) { $no_ssl2=1; } 243298999Sjkim elsif (/^no-ssl2-method$/) { $no_ssl2_method=1; } 244276864Sjkim elsif (/^no-ssl3-method$/) { $no_ssl3_method=1; } 245194206Ssimon elsif (/^no-capieng$/) { $no_capieng=1; } 246194206Ssimon elsif (/^no-jpake$/) { $no_jpake=1; } 247238405Sjkim elsif (/^no-srp$/) { $no_srp=1; } 248238405Sjkim elsif (/^no-sctp$/) { $no_sctp=1; } 249273149Sjkim elsif (/^no-srtp$/) { $no_srtp=1; } 250269686Sjkim elsif (/^no-unit-test$/){ $no_unit_test=1; } 25155714Skris } 25255714Skris 25359191Skris 254109998Smarkmif (!$libname) { 255109998Smarkm if ($do_ssl) { 256109998Smarkm $libname="SSLEAY"; 257109998Smarkm } 258109998Smarkm if ($do_crypto) { 259109998Smarkm $libname="LIBEAY"; 260109998Smarkm } 261109998Smarkm} 262109998Smarkm 26368651Skris# If no platform is given, assume WIN32 264109998Smarkmif ($W32 + $W16 + $VMS + $OS2 == 0) { 26568651Skris $W32 = 1; 26668651Skris} 26768651Skris 26868651Skris# Add extra knowledge 26968651Skrisif ($W16) { 27068651Skris $no_fp_api=1; 27168651Skris} 27268651Skris 27355714Skrisif (!$do_ssl && !$do_crypto) 27455714Skris { 275109998Smarkm print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n"; 27655714Skris exit(1); 27755714Skris } 27855714Skris 27955714Skris%ssl_list=&load_numbers($ssl_num); 28055714Skris$max_ssl = $max_num; 28155714Skris%crypto_list=&load_numbers($crypto_num); 28255714Skris$max_crypto = $max_num; 28355714Skris 28459191Skrismy $ssl="ssl/ssl.h"; 285109998Smarkm$ssl.=" ssl/kssl.h"; 286194206Ssimon$ssl.=" ssl/tls1.h"; 287238405Sjkim$ssl.=" ssl/srtp.h"; 28855714Skris 28959191Skrismy $crypto ="crypto/crypto.h"; 290238405Sjkim$crypto.=" crypto/cryptlib.h"; 291160814Ssimon$crypto.=" crypto/o_dir.h"; 292238405Sjkim$crypto.=" crypto/o_str.h"; 293238405Sjkim$crypto.=" crypto/o_time.h"; 294109998Smarkm$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des; 295109998Smarkm$crypto.=" crypto/idea/idea.h" ; # unless $no_idea; 296109998Smarkm$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4; 297109998Smarkm$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5; 298109998Smarkm$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2; 299109998Smarkm$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf; 300109998Smarkm$crypto.=" crypto/cast/cast.h" ; # unless $no_cast; 301238405Sjkim$crypto.=" crypto/whrlpool/whrlpool.h" ; 302109998Smarkm$crypto.=" crypto/md2/md2.h" ; # unless $no_md2; 303109998Smarkm$crypto.=" crypto/md4/md4.h" ; # unless $no_md4; 304109998Smarkm$crypto.=" crypto/md5/md5.h" ; # unless $no_md5; 305109998Smarkm$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2; 306109998Smarkm$crypto.=" crypto/sha/sha.h" ; # unless $no_sha; 307109998Smarkm$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd; 308109998Smarkm$crypto.=" crypto/aes/aes.h" ; # unless $no_aes; 309162911Ssimon$crypto.=" crypto/camellia/camellia.h" ; # unless $no_camellia; 310194206Ssimon$crypto.=" crypto/seed/seed.h"; # unless $no_seed; 31155714Skris 31255714Skris$crypto.=" crypto/bn/bn.h"; 313109998Smarkm$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa; 314109998Smarkm$crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa; 315109998Smarkm$crypto.=" crypto/dh/dh.h" ; # unless $no_dh; 316109998Smarkm$crypto.=" crypto/ec/ec.h" ; # unless $no_ec; 317160814Ssimon$crypto.=" crypto/ecdsa/ecdsa.h" ; # unless $no_ecdsa; 318160814Ssimon$crypto.=" crypto/ecdh/ecdh.h" ; # unless $no_ecdh; 319109998Smarkm$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac; 320238405Sjkim$crypto.=" crypto/cmac/cmac.h" ; # unless $no_hmac; 32155714Skris 322111147Snectar$crypto.=" crypto/engine/engine.h"; # unless $no_engine; 323109998Smarkm$crypto.=" crypto/stack/stack.h" ; # unless $no_stack; 324109998Smarkm$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer; 325109998Smarkm$crypto.=" crypto/bio/bio.h" ; # unless $no_bio; 326109998Smarkm$crypto.=" crypto/dso/dso.h" ; # unless $no_dso; 327109998Smarkm$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash; 32855714Skris$crypto.=" crypto/conf/conf.h"; 32955714Skris$crypto.=" crypto/txt_db/txt_db.h"; 33055714Skris 331109998Smarkm$crypto.=" crypto/evp/evp.h" ; # unless $no_evp; 33255714Skris$crypto.=" crypto/objects/objects.h"; 33355714Skris$crypto.=" crypto/pem/pem.h"; 33455714Skris#$crypto.=" crypto/meth/meth.h"; 33555714Skris$crypto.=" crypto/asn1/asn1.h"; 336109998Smarkm$crypto.=" crypto/asn1/asn1t.h"; 33755714Skris$crypto.=" crypto/asn1/asn1_mac.h"; 338109998Smarkm$crypto.=" crypto/err/err.h" ; # unless $no_err; 33955714Skris$crypto.=" crypto/pkcs7/pkcs7.h"; 34055714Skris$crypto.=" crypto/pkcs12/pkcs12.h"; 34155714Skris$crypto.=" crypto/x509/x509.h"; 34255714Skris$crypto.=" crypto/x509/x509_vfy.h"; 34355714Skris$crypto.=" crypto/x509v3/x509v3.h"; 344238405Sjkim$crypto.=" crypto/ts/ts.h"; 34555714Skris$crypto.=" crypto/rand/rand.h"; 346109998Smarkm$crypto.=" crypto/comp/comp.h" ; # unless $no_comp; 347109998Smarkm$crypto.=" crypto/ocsp/ocsp.h"; 348109998Smarkm$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h"; 349109998Smarkm$crypto.=" crypto/krb5/krb5_asn.h"; 350238405Sjkim#$crypto.=" crypto/store/store.h"; 351160814Ssimon$crypto.=" crypto/pqueue/pqueue.h"; 352194206Ssimon$crypto.=" crypto/cms/cms.h"; 353194206Ssimon$crypto.=" crypto/jpake/jpake.h"; 354238405Sjkim$crypto.=" crypto/modes/modes.h"; 355238405Sjkim$crypto.=" crypto/srp/srp.h"; 35655714Skris 35768651Skrismy $symhacks="crypto/symhacks.h"; 35855714Skris 35968651Skrismy @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks); 36068651Skrismy @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks); 36155714Skris 36255714Skrisif ($do_update) { 36355714Skris 36455714Skrisif ($do_ssl == 1) { 36568651Skris 36668651Skris &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols); 36768651Skris if ($do_rewrite == 1) { 36868651Skris open(OUT, ">$ssl_num"); 36968651Skris &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols); 37068651Skris } else { 37168651Skris open(OUT, ">>$ssl_num"); 37268651Skris } 37368651Skris &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols); 37455714Skris close OUT; 37555714Skris} 37655714Skris 37755714Skrisif($do_crypto == 1) { 37868651Skris 37968651Skris &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols); 38068651Skris if ($do_rewrite == 1) { 38168651Skris open(OUT, ">$crypto_num"); 38268651Skris &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols); 38368651Skris } else { 38468651Skris open(OUT, ">>$crypto_num"); 38568651Skris } 38668651Skris &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols); 38755714Skris close OUT; 38859191Skris} 38955714Skris 390109998Smarkm} elsif ($do_checkexist) { 391109998Smarkm &check_existing(*ssl_list, @ssl_symbols) 392109998Smarkm if $do_ssl == 1; 393109998Smarkm &check_existing(*crypto_list, @crypto_symbols) 394109998Smarkm if $do_crypto == 1; 39568651Skris} elsif ($do_ctest || $do_ctestall) { 39659191Skris 39759191Skris print <<"EOF"; 39859191Skris 39959191Skris/* Test file to check all DEF file symbols are present by trying 40059191Skris * to link to all of them. This is *not* intended to be run! 40159191Skris */ 40259191Skris 40359191Skrisint main() 40459191Skris{ 40559191SkrisEOF 40668651Skris &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols) 40759191Skris if $do_ssl == 1; 40859191Skris 40968651Skris &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols) 41059191Skris if $do_crypto == 1; 41159191Skris 41259191Skris print "}\n"; 41359191Skris 41455714Skris} else { 41555714Skris 416109998Smarkm &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols) 41755714Skris if $do_ssl == 1; 41855714Skris 419109998Smarkm &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols) 42055714Skris if $do_crypto == 1; 42155714Skris 42255714Skris} 42355714Skris 42455714Skris 42555714Skrissub do_defs 42655714Skris{ 42768651Skris my($name,$files,$symhacksfile)=@_; 42859191Skris my $file; 42955714Skris my @ret; 43068651Skris my %syms; 43168651Skris my %platform; # For anything undefined, we assume "" 43268651Skris my %kind; # For anything undefined, we assume "FUNCTION" 43368651Skris my %algorithm; # For anything undefined, we assume "" 434109998Smarkm my %variant; 435109998Smarkm my %variant_cnt; # To be able to allocate "name{n}" if "name" 436109998Smarkm # is the same name as the original. 43759191Skris my $cpp; 438109998Smarkm my %unknown_algorithms = (); 43955714Skris 44068651Skris foreach $file (split(/\s+/,$symhacksfile." ".$files)) 44155714Skris { 442109998Smarkm print STDERR "DEBUG: starting on $file:\n" if $debug; 44355714Skris open(IN,"<$file") || die "unable to open $file:$!\n"; 44459191Skris my $line = "", my $def= ""; 44555714Skris my %tag = ( 44668651Skris (map { $_ => 0 } @known_platforms), 447109998Smarkm (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms), 448109998Smarkm (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms), 44955714Skris NOPROTO => 0, 45055714Skris PERL5 => 0, 45155714Skris _WINDLL => 0, 45255714Skris CONST_STRICT => 0, 45355714Skris TRUE => 1, 45455714Skris ); 45568651Skris my $symhacking = $file eq $symhacksfile; 456109998Smarkm my @current_platforms = (); 457109998Smarkm my @current_algorithms = (); 458109998Smarkm 459109998Smarkm # params: symbol, alias, platforms, kind 460109998Smarkm # The reason to put this subroutine in a variable is that 461109998Smarkm # it will otherwise create it's own, unshared, version of 462109998Smarkm # %tag and %variant... 463109998Smarkm my $make_variant = sub 464109998Smarkm { 465109998Smarkm my ($s, $a, $p, $k) = @_; 466109998Smarkm my ($a1, $a2); 467109998Smarkm 468109998Smarkm print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug; 469109998Smarkm if (defined($p)) 470109998Smarkm { 471109998Smarkm $a1 = join(",",$p, 472109998Smarkm grep(!/^$/, 473109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 474109998Smarkm @known_platforms)); 475109998Smarkm } 476109998Smarkm else 477109998Smarkm { 478109998Smarkm $a1 = join(",", 479109998Smarkm grep(!/^$/, 480109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 481109998Smarkm @known_platforms)); 482109998Smarkm } 483109998Smarkm $a2 = join(",", 484109998Smarkm grep(!/^$/, 485109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" } 486109998Smarkm @known_ossl_platforms)); 487109998Smarkm print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug; 488109998Smarkm if ($a1 eq "") { $a1 = $a2; } 489109998Smarkm elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; } 490109998Smarkm if ($a eq $s) 491109998Smarkm { 492109998Smarkm if (!defined($variant_cnt{$s})) 493109998Smarkm { 494109998Smarkm $variant_cnt{$s} = 0; 495109998Smarkm } 496109998Smarkm $variant_cnt{$s}++; 497109998Smarkm $a .= "{$variant_cnt{$s}}"; 498109998Smarkm } 499109998Smarkm my $toadd = $a.":".$a1.(defined($k)?":".$k:""); 500109998Smarkm my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:""); 501109998Smarkm if (!grep(/^$togrep$/, 502109998Smarkm split(/;/, defined($variant{$s})?$variant{$s}:""))) { 503109998Smarkm if (defined($variant{$s})) { $variant{$s} .= ";"; } 504109998Smarkm $variant{$s} .= $toadd; 505109998Smarkm } 506109998Smarkm print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug; 507109998Smarkm }; 508109998Smarkm 509109998Smarkm print STDERR "DEBUG: parsing ----------\n" if $debug; 51055714Skris while(<IN>) { 511160814Ssimon if (/\/\* Error codes for the \w+ functions\. \*\//) 512160814Ssimon { 513160814Ssimon undef @tag; 514160814Ssimon last; 515160814Ssimon } 51655714Skris if ($line ne '') { 51755714Skris $_ = $line . $_; 51855714Skris $line = ''; 51955714Skris } 52055714Skris 52155714Skris if (/\\$/) { 522109998Smarkm chomp; # remove eol 523109998Smarkm chop; # remove ending backslash 52455714Skris $line = $_; 52555714Skris next; 52655714Skris } 52755714Skris 528160814Ssimon if(/\/\*/) { 529160814Ssimon if (not /\*\//) { # multiline comment... 530160814Ssimon $line = $_; # ... just accumulate 531160814Ssimon next; 532160814Ssimon } else { 533160814Ssimon s/\/\*.*?\*\///gs;# wipe it 534160814Ssimon } 535160814Ssimon } 536160814Ssimon 53755714Skris if ($cpp) { 538160814Ssimon $cpp++ if /^#\s*if/; 539160814Ssimon $cpp-- if /^#\s*endif/; 54055714Skris next; 54155714Skris } 542160814Ssimon $cpp = 1 if /^#.*ifdef.*cplusplus/; 54355714Skris 54455714Skris s/{[^{}]*}//gs; # ignore {} blocks 545120631Snectar print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne ""; 546109998Smarkm print STDERR "DEBUG: \$_=\"$_\"\n" if $debug; 547109998Smarkm if (/^\#\s*ifndef\s+(.*)/) { 548109998Smarkm push(@tag,"-"); 54955714Skris push(@tag,$1); 55055714Skris $tag{$1}=-1; 551109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 552109998Smarkm } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) { 553109998Smarkm push(@tag,"-"); 554109998Smarkm if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) { 555109998Smarkm my $tmp_1 = $1; 556109998Smarkm my $tmp_; 557109998Smarkm foreach $tmp_ (split '\&\&',$tmp_1) { 558109998Smarkm $tmp_ =~ /!defined\(([^\)]+)\)/; 559109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 560109998Smarkm push(@tag,$1); 561109998Smarkm $tag{$1}=-1; 562109998Smarkm } 563109998Smarkm } else { 564109998Smarkm print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O... 565109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 566109998Smarkm push(@tag,$1); 567109998Smarkm $tag{$1}=-1; 568109998Smarkm } 569160814Ssimon } elsif (/^\#\s*ifdef\s+(\S*)/) { 570109998Smarkm push(@tag,"-"); 57155714Skris push(@tag,$1); 57255714Skris $tag{$1}=1; 573109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 574109998Smarkm } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) { 575109998Smarkm push(@tag,"-"); 576109998Smarkm if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) { 577109998Smarkm my $tmp_1 = $1; 578109998Smarkm my $tmp_; 579109998Smarkm foreach $tmp_ (split '\|\|',$tmp_1) { 580109998Smarkm $tmp_ =~ /defined\(([^\)]+)\)/; 581109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 582109998Smarkm push(@tag,$1); 583109998Smarkm $tag{$1}=1; 584109998Smarkm } 585109998Smarkm } else { 586109998Smarkm print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O... 587109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 588109998Smarkm push(@tag,$1); 589109998Smarkm $tag{$1}=1; 590109998Smarkm } 59168651Skris } elsif (/^\#\s*error\s+(\w+) is disabled\./) { 592109998Smarkm my $tag_i = $#tag; 593109998Smarkm while($tag[$tag_i] ne "-") { 594109998Smarkm if ($tag[$tag_i] eq "OPENSSL_NO_".$1) { 595109998Smarkm $tag{$tag[$tag_i]}=2; 596109998Smarkm print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug; 597109998Smarkm } 598109998Smarkm $tag_i--; 59968651Skris } 60055714Skris } elsif (/^\#\s*endif/) { 601109998Smarkm my $tag_i = $#tag; 602160814Ssimon while($tag_i > 0 && $tag[$tag_i] ne "-") { 603109998Smarkm my $t=$tag[$tag_i]; 604109998Smarkm print STDERR "DEBUG: \$t=\"$t\"\n" if $debug; 605109998Smarkm if ($tag{$t}==2) { 606109998Smarkm $tag{$t}=-1; 607109998Smarkm } else { 608109998Smarkm $tag{$t}=0; 609109998Smarkm } 610109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 611109998Smarkm pop(@tag); 612109998Smarkm if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) { 613109998Smarkm $t=$1; 614109998Smarkm } else { 615109998Smarkm $t=""; 616109998Smarkm } 617109998Smarkm if ($t ne "" 618109998Smarkm && !grep(/^$t$/, @known_algorithms)) { 619109998Smarkm $unknown_algorithms{$t} = 1; 620109998Smarkm #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug; 621109998Smarkm } 622109998Smarkm $tag_i--; 62368651Skris } 62455714Skris pop(@tag); 62555714Skris } elsif (/^\#\s*else/) { 626109998Smarkm my $tag_i = $#tag; 627109998Smarkm while($tag[$tag_i] ne "-") { 628109998Smarkm my $t=$tag[$tag_i]; 629109998Smarkm $tag{$t}= -$tag{$t}; 630109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 631109998Smarkm $tag_i--; 632109998Smarkm } 63355714Skris } elsif (/^\#\s*if\s+1/) { 634109998Smarkm push(@tag,"-"); 63555714Skris # Dummy tag 63655714Skris push(@tag,"TRUE"); 63755714Skris $tag{"TRUE"}=1; 638109998Smarkm print STDERR "DEBUG: $file: found 1\n" if $debug; 63959191Skris } elsif (/^\#\s*if\s+0/) { 640109998Smarkm push(@tag,"-"); 64159191Skris # Dummy tag 64259191Skris push(@tag,"TRUE"); 64359191Skris $tag{"TRUE"}=-1; 644109998Smarkm print STDERR "DEBUG: $file: found 0\n" if $debug; 64568651Skris } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/ 646109998Smarkm && $symhacking && $tag{'TRUE'} != -1) { 647109998Smarkm # This is for aliasing. When we find an alias, 648109998Smarkm # we have to invert 649109998Smarkm &$make_variant($1,$2); 650109998Smarkm print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug; 65168651Skris } 65268651Skris if (/^\#/) { 653109998Smarkm @current_platforms = 654109998Smarkm grep(!/^$/, 655109998Smarkm map { $tag{$_} == 1 ? $_ : 656109998Smarkm $tag{$_} == -1 ? "!".$_ : "" } 657109998Smarkm @known_platforms); 658109998Smarkm push @current_platforms 659109998Smarkm , grep(!/^$/, 660109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : 661109998Smarkm $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" } 662109998Smarkm @known_ossl_platforms); 663109998Smarkm @current_algorithms = 664109998Smarkm grep(!/^$/, 665109998Smarkm map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" } 666109998Smarkm @known_algorithms); 667109998Smarkm $def .= 668109998Smarkm "#INFO:" 669109998Smarkm .join(',',@current_platforms).":" 670109998Smarkm .join(',',@current_algorithms).";"; 67159191Skris next; 67268651Skris } 673109998Smarkm if ($tag{'TRUE'} != -1) { 674109998Smarkm if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { 675109998Smarkm next; 676109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 677109998Smarkm $def .= "int d2i_$3(void);"; 678109998Smarkm $def .= "int i2d_$3(void);"; 679109998Smarkm # Variant for platforms that do not 680109998Smarkm # have to access globale variables 681109998Smarkm # in shared libraries through functions 682109998Smarkm $def .= 683109998Smarkm "#INFO:" 684109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 685109998Smarkm .join(',',@current_algorithms).";"; 686109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 687109998Smarkm $def .= 688109998Smarkm "#INFO:" 689109998Smarkm .join(',',@current_platforms).":" 690109998Smarkm .join(',',@current_algorithms).";"; 691109998Smarkm # Variant for platforms that have to 692109998Smarkm # access globale variables in shared 693109998Smarkm # libraries through functions 694109998Smarkm &$make_variant("$2_it","$2_it", 695109998Smarkm "EXPORT_VAR_AS_FUNCTION", 696109998Smarkm "FUNCTION"); 697109998Smarkm next; 698109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 699109998Smarkm $def .= "int d2i_$3(void);"; 700109998Smarkm $def .= "int i2d_$3(void);"; 701109998Smarkm $def .= "int $3_free(void);"; 702109998Smarkm $def .= "int $3_new(void);"; 703109998Smarkm # Variant for platforms that do not 704109998Smarkm # have to access globale variables 705109998Smarkm # in shared libraries through functions 706109998Smarkm $def .= 707109998Smarkm "#INFO:" 708109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 709109998Smarkm .join(',',@current_algorithms).";"; 710109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 711109998Smarkm $def .= 712109998Smarkm "#INFO:" 713109998Smarkm .join(',',@current_platforms).":" 714109998Smarkm .join(',',@current_algorithms).";"; 715109998Smarkm # Variant for platforms that have to 716109998Smarkm # access globale variables in shared 717109998Smarkm # libraries through functions 718109998Smarkm &$make_variant("$2_it","$2_it", 719109998Smarkm "EXPORT_VAR_AS_FUNCTION", 720109998Smarkm "FUNCTION"); 721109998Smarkm next; 722109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ || 723109998Smarkm /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) { 724109998Smarkm $def .= "int d2i_$1(void);"; 725109998Smarkm $def .= "int i2d_$1(void);"; 726109998Smarkm $def .= "int $1_free(void);"; 727109998Smarkm $def .= "int $1_new(void);"; 728109998Smarkm # Variant for platforms that do not 729109998Smarkm # have to access globale variables 730109998Smarkm # in shared libraries through functions 731109998Smarkm $def .= 732109998Smarkm "#INFO:" 733109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 734109998Smarkm .join(',',@current_algorithms).";"; 735109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 736109998Smarkm $def .= 737109998Smarkm "#INFO:" 738109998Smarkm .join(',',@current_platforms).":" 739109998Smarkm .join(',',@current_algorithms).";"; 740109998Smarkm # Variant for platforms that have to 741109998Smarkm # access globale variables in shared 742109998Smarkm # libraries through functions 743109998Smarkm &$make_variant("$1_it","$1_it", 744109998Smarkm "EXPORT_VAR_AS_FUNCTION", 745109998Smarkm "FUNCTION"); 746109998Smarkm next; 747109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 748109998Smarkm $def .= "int d2i_$2(void);"; 749109998Smarkm $def .= "int i2d_$2(void);"; 750109998Smarkm # Variant for platforms that do not 751109998Smarkm # have to access globale variables 752109998Smarkm # in shared libraries through functions 753109998Smarkm $def .= 754109998Smarkm "#INFO:" 755109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 756109998Smarkm .join(',',@current_algorithms).";"; 757109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 758109998Smarkm $def .= 759109998Smarkm "#INFO:" 760109998Smarkm .join(',',@current_platforms).":" 761109998Smarkm .join(',',@current_algorithms).";"; 762109998Smarkm # Variant for platforms that have to 763109998Smarkm # access globale variables in shared 764109998Smarkm # libraries through functions 765109998Smarkm &$make_variant("$2_it","$2_it", 766109998Smarkm "EXPORT_VAR_AS_FUNCTION", 767109998Smarkm "FUNCTION"); 768109998Smarkm next; 769160814Ssimon } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) { 770160814Ssimon $def .= "int $1_free(void);"; 771160814Ssimon $def .= "int $1_new(void);"; 772160814Ssimon next; 773109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 774109998Smarkm $def .= "int d2i_$2(void);"; 775109998Smarkm $def .= "int i2d_$2(void);"; 776109998Smarkm $def .= "int $2_free(void);"; 777109998Smarkm $def .= "int $2_new(void);"; 778109998Smarkm # Variant for platforms that do not 779109998Smarkm # have to access globale variables 780109998Smarkm # in shared libraries through functions 781109998Smarkm $def .= 782109998Smarkm "#INFO:" 783109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 784109998Smarkm .join(',',@current_algorithms).";"; 785109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 786109998Smarkm $def .= 787109998Smarkm "#INFO:" 788109998Smarkm .join(',',@current_platforms).":" 789109998Smarkm .join(',',@current_algorithms).";"; 790109998Smarkm # Variant for platforms that have to 791109998Smarkm # access globale variables in shared 792109998Smarkm # libraries through functions 793109998Smarkm &$make_variant("$2_it","$2_it", 794109998Smarkm "EXPORT_VAR_AS_FUNCTION", 795109998Smarkm "FUNCTION"); 796109998Smarkm next; 797109998Smarkm } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) { 798109998Smarkm # Variant for platforms that do not 799109998Smarkm # have to access globale variables 800109998Smarkm # in shared libraries through functions 801109998Smarkm $def .= 802109998Smarkm "#INFO:" 803109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 804109998Smarkm .join(',',@current_algorithms).";"; 805109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 806109998Smarkm $def .= 807109998Smarkm "#INFO:" 808109998Smarkm .join(',',@current_platforms).":" 809109998Smarkm .join(',',@current_algorithms).";"; 810109998Smarkm # Variant for platforms that have to 811109998Smarkm # access globale variables in shared 812109998Smarkm # libraries through functions 813109998Smarkm &$make_variant("$1_it","$1_it", 814109998Smarkm "EXPORT_VAR_AS_FUNCTION", 815109998Smarkm "FUNCTION"); 816109998Smarkm next; 817160814Ssimon } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) { 818160814Ssimon $def .= "int i2d_$1_NDEF(void);"; 819109998Smarkm } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { 820109998Smarkm next; 821160814Ssimon } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) { 822160814Ssimon $def .= "int $1_print_ctx(void);"; 823160814Ssimon next; 824160814Ssimon } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 825160814Ssimon $def .= "int $2_print_ctx(void);"; 826160814Ssimon next; 827109998Smarkm } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) { 828109998Smarkm next; 829109998Smarkm } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || 830160814Ssimon /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ || 831160814Ssimon /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) { 832109998Smarkm # Things not in Win16 833109998Smarkm $def .= 834109998Smarkm "#INFO:" 835109998Smarkm .join(',',"!WIN16",@current_platforms).":" 836109998Smarkm .join(',',@current_algorithms).";"; 837109998Smarkm $def .= "int PEM_read_$1(void);"; 838109998Smarkm $def .= "int PEM_write_$1(void);"; 839109998Smarkm $def .= 840109998Smarkm "#INFO:" 841109998Smarkm .join(',',@current_platforms).":" 842109998Smarkm .join(',',@current_algorithms).";"; 843109998Smarkm # Things that are everywhere 844109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 845109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 846109998Smarkm next; 847109998Smarkm } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ || 848109998Smarkm /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) { 849109998Smarkm # Things not in Win16 850109998Smarkm $def .= 851109998Smarkm "#INFO:" 852109998Smarkm .join(',',"!WIN16",@current_platforms).":" 853109998Smarkm .join(',',@current_algorithms).";"; 854109998Smarkm $def .= "int PEM_write_$1(void);"; 855109998Smarkm $def .= 856109998Smarkm "#INFO:" 857109998Smarkm .join(',',@current_platforms).":" 858109998Smarkm .join(',',@current_algorithms).";"; 859109998Smarkm # Things that are everywhere 860109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 861109998Smarkm next; 862109998Smarkm } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ || 863109998Smarkm /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) { 864109998Smarkm # Things not in Win16 865109998Smarkm $def .= 866109998Smarkm "#INFO:" 867109998Smarkm .join(',',"!WIN16",@current_platforms).":" 868109998Smarkm .join(',',@current_algorithms).";"; 869109998Smarkm $def .= "int PEM_read_$1(void);"; 870109998Smarkm $def .= 871109998Smarkm "#INFO:" 872109998Smarkm .join(',',@current_platforms).":" 873109998Smarkm .join(',',@current_algorithms).";"; 874109998Smarkm # Things that are everywhere 875109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 876109998Smarkm next; 877109998Smarkm } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 878109998Smarkm # Variant for platforms that do not 879109998Smarkm # have to access globale variables 880109998Smarkm # in shared libraries through functions 881109998Smarkm $def .= 882109998Smarkm "#INFO:" 883109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 884109998Smarkm .join(',',@current_algorithms).";"; 885109998Smarkm $def .= "OPENSSL_EXTERN int _shadow_$2;"; 886109998Smarkm $def .= 887109998Smarkm "#INFO:" 888109998Smarkm .join(',',@current_platforms).":" 889109998Smarkm .join(',',@current_algorithms).";"; 890109998Smarkm # Variant for platforms that have to 891109998Smarkm # access globale variables in shared 892109998Smarkm # libraries through functions 893109998Smarkm &$make_variant("_shadow_$2","_shadow_$2", 894109998Smarkm "EXPORT_VAR_AS_FUNCTION", 895109998Smarkm "FUNCTION"); 896109998Smarkm } elsif ($tag{'CONST_STRICT'} != 1) { 89768651Skris if (/\{|\/\*|\([^\)]*$/) { 89855714Skris $line = $_; 89955714Skris } else { 90055714Skris $def .= $_; 90155714Skris } 90255714Skris } 90355714Skris } 904109998Smarkm } 90555714Skris close(IN); 90655714Skris 907160814Ssimon my $algs; 90868651Skris my $plays; 90968651Skris 910109998Smarkm print STDERR "DEBUG: postprocessing ----------\n" if $debug; 91155714Skris foreach (split /;/, $def) { 91268651Skris my $s; my $k = "FUNCTION"; my $p; my $a; 91355714Skris s/^[\n\s]*//g; 91455714Skris s/[\n\s]*$//g; 91568651Skris next if(/\#undef/); 91655714Skris next if(/typedef\W/); 91768651Skris next if(/\#define/); 91868651Skris 919160814Ssimon # Reduce argument lists to empty () 920160814Ssimon # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {} 921160814Ssimon while(/\(.*\)/s) { 922160814Ssimon s/\([^\(\)]+\)/\{\}/gs; 923160814Ssimon s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f 924160814Ssimon } 925160814Ssimon # pretend as we didn't use curly braces: {} -> () 926160814Ssimon s/\{\}/\(\)/gs; 927160814Ssimon 928160814Ssimon s/STACK_OF\(\)/void/gs; 929238405Sjkim s/LHASH_OF\(\)/void/gs; 930160814Ssimon 931109998Smarkm print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug; 93268651Skris if (/^\#INFO:([^:]*):(.*)$/) { 93368651Skris $plats = $1; 93468651Skris $algs = $2; 935109998Smarkm print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug; 93668651Skris next; 937109998Smarkm } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) { 93868651Skris $s = $1; 93968651Skris $k = "VARIABLE"; 940109998Smarkm print STDERR "DEBUG: found external variable $s\n" if $debug; 941160814Ssimon } elsif (/TYPEDEF_\w+_OF/s) { 94255714Skris next; 943160814Ssimon } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is 944160814Ssimon $s = $1; # a function name! 945109998Smarkm print STDERR "DEBUG: found function $s\n" if $debug; 94655714Skris } elsif (/\(/ and not (/=/)) { 94755714Skris print STDERR "File $file: cannot parse: $_;\n"; 94868651Skris next; 94968651Skris } else { 95068651Skris next; 95155714Skris } 95268651Skris 95368651Skris $syms{$s} = 1; 95468651Skris $kind{$s} = $k; 95568651Skris 95668651Skris $p = $plats; 95768651Skris $a = $algs; 95868651Skris $a .= ",BF" if($s =~ /EVP_bf/); 95968651Skris $a .= ",CAST" if($s =~ /EVP_cast/); 96068651Skris $a .= ",DES" if($s =~ /EVP_des/); 96168651Skris $a .= ",DSA" if($s =~ /EVP_dss/); 96268651Skris $a .= ",IDEA" if($s =~ /EVP_idea/); 96368651Skris $a .= ",MD2" if($s =~ /EVP_md2/); 96468651Skris $a .= ",MD4" if($s =~ /EVP_md4/); 96568651Skris $a .= ",MD5" if($s =~ /EVP_md5/); 96668651Skris $a .= ",RC2" if($s =~ /EVP_rc2/); 96768651Skris $a .= ",RC4" if($s =~ /EVP_rc4/); 96868651Skris $a .= ",RC5" if($s =~ /EVP_rc5/); 96968651Skris $a .= ",RIPEMD" if($s =~ /EVP_ripemd/); 97068651Skris $a .= ",SHA" if($s =~ /EVP_sha/); 97168651Skris $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/); 97268651Skris $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); 97368651Skris $a .= ",RSA" if($s =~ /RSAPrivateKey/); 97468651Skris $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); 97568651Skris 976109998Smarkm $platform{$s} = 977109998Smarkm &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p); 97868651Skris $algorithm{$s} .= ','.$a; 97968651Skris 980109998Smarkm if (defined($variant{$s})) { 981109998Smarkm foreach $v (split /;/,$variant{$s}) { 982109998Smarkm (my $r, my $p, my $k) = split(/:/,$v); 983109998Smarkm my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p); 984109998Smarkm $syms{$r} = 1; 985109998Smarkm if (!defined($k)) { $k = $kind{$s}; } 986109998Smarkm $kind{$r} = $k."(".$s.")"; 987109998Smarkm $algorithm{$r} = $algorithm{$s}; 988109998Smarkm $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p); 989109998Smarkm $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip); 990109998Smarkm print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug; 991109998Smarkm } 99268651Skris } 993109998Smarkm print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug; 99455714Skris } 99555714Skris } 99655714Skris 99768651Skris # Prune the returned symbols 99855714Skris 99968651Skris delete $syms{"bn_dump1"}; 100068651Skris $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh"; 100168651Skris 1002109998Smarkm $platform{"PEM_read_NS_CERT_SEQ"} = "VMS"; 1003109998Smarkm $platform{"PEM_write_NS_CERT_SEQ"} = "VMS"; 1004109998Smarkm $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS"; 1005109998Smarkm $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS"; 1006205128Ssimon $platform{"EVP_sha384"} = "!VMSVAX"; 1007205128Ssimon $platform{"EVP_sha512"} = "!VMSVAX"; 1008205128Ssimon $platform{"SHA384_Init"} = "!VMSVAX"; 1009205128Ssimon $platform{"SHA384_Transform"} = "!VMSVAX"; 1010205128Ssimon $platform{"SHA384_Update"} = "!VMSVAX"; 1011205128Ssimon $platform{"SHA384_Final"} = "!VMSVAX"; 1012205128Ssimon $platform{"SHA384"} = "!VMSVAX"; 1013205128Ssimon $platform{"SHA512_Init"} = "!VMSVAX"; 1014205128Ssimon $platform{"SHA512_Transform"} = "!VMSVAX"; 1015205128Ssimon $platform{"SHA512_Update"} = "!VMSVAX"; 1016205128Ssimon $platform{"SHA512_Final"} = "!VMSVAX"; 1017205128Ssimon $platform{"SHA512"} = "!VMSVAX"; 1018238405Sjkim $platform{"WHIRLPOOL_Init"} = "!VMSVAX"; 1019238405Sjkim $platform{"WHIRLPOOL"} = "!VMSVAX"; 1020238405Sjkim $platform{"WHIRLPOOL_BitUpdate"} = "!VMSVAX"; 1021238405Sjkim $platform{"EVP_whirlpool"} = "!VMSVAX"; 1022238405Sjkim $platform{"WHIRLPOOL_Final"} = "!VMSVAX"; 1023238405Sjkim $platform{"WHIRLPOOL_Update"} = "!VMSVAX"; 1024205128Ssimon 1025215697Ssimon 102668651Skris # Info we know about 102768651Skris 102868651Skris push @ret, map { $_."\\".&info_string($_,"EXIST", 102968651Skris $platform{$_}, 103068651Skris $kind{$_}, 103168651Skris $algorithm{$_}) } keys %syms; 103268651Skris 1033109998Smarkm if (keys %unknown_algorithms) { 1034109998Smarkm print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n"; 1035109998Smarkm print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n"; 1036109998Smarkm } 103768651Skris return(@ret); 103868651Skris} 103968651Skris 1040109998Smarkm# Param: string of comma-separated platform-specs. 1041109998Smarkmsub reduce_platforms 1042109998Smarkm{ 1043109998Smarkm my ($platforms) = @_; 104468651Skris my $pl = defined($platforms) ? $platforms : ""; 104568651Skris my %p = map { $_ => 0 } split /,/, $pl; 104668651Skris my $ret; 104768651Skris 1048109998Smarkm print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n" 1049109998Smarkm if $debug; 105068651Skris # We do this, because if there's code like the following, it really 105168651Skris # means the function exists in all cases and should therefore be 105268651Skris # everywhere. By increasing and decreasing, we may attain 0: 105368651Skris # 105468651Skris # ifndef WIN16 105568651Skris # int foo(); 105668651Skris # else 105768651Skris # int _fat foo(); 105868651Skris # endif 105968651Skris foreach $platform (split /,/, $pl) { 106068651Skris if ($platform =~ /^!(.*)$/) { 106168651Skris $p{$1}--; 106268651Skris } else { 106368651Skris $p{$platform}++; 106455714Skris } 106555714Skris } 106668651Skris foreach $platform (keys %p) { 106768651Skris if ($p{$platform} == 0) { delete $p{$platform}; } 106855714Skris } 106955714Skris 107068651Skris delete $p{""}; 1071109998Smarkm 1072109998Smarkm $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p)); 1073109998Smarkm print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n" 1074109998Smarkm if $debug; 1075109998Smarkm return $ret; 1076109998Smarkm} 1077109998Smarkm 1078109998Smarkmsub info_string { 1079109998Smarkm (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_; 1080109998Smarkm 1081109998Smarkm my %a = defined($algorithms) ? 1082109998Smarkm map { $_ => 1 } split /,/, $algorithms : (); 1083109998Smarkm my $k = defined($kind) ? $kind : "FUNCTION"; 1084109998Smarkm my $ret; 1085109998Smarkm my $p = &reduce_platforms($platforms); 1086109998Smarkm 108768651Skris delete $a{""}; 108855714Skris 108968651Skris $ret = $exist; 1090109998Smarkm $ret .= ":".$p; 109168651Skris $ret .= ":".$k; 1092109998Smarkm $ret .= ":".join(',',sort keys %a); 109368651Skris return $ret; 109455714Skris} 109555714Skris 109668651Skrissub maybe_add_info { 109768651Skris (my $name, *nums, my @symbols) = @_; 109868651Skris my $sym; 109968651Skris my $new_info = 0; 1100109998Smarkm my %syms=(); 110168651Skris 110268651Skris print STDERR "Updating $name info\n"; 110368651Skris foreach $sym (@symbols) { 110468651Skris (my $s, my $i) = split /\\/, $sym; 110568651Skris if (defined($nums{$s})) { 1106109998Smarkm $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/; 110768651Skris (my $n, my $dummy) = split /\\/, $nums{$s}; 110868651Skris if (!defined($dummy) || $i ne $dummy) { 110968651Skris $nums{$s} = $n."\\".$i; 111068651Skris $new_info++; 1111109998Smarkm print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug; 111268651Skris } 111368651Skris } 1114109998Smarkm $syms{$s} = 1; 111568651Skris } 1116109998Smarkm 1117109998Smarkm my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums; 1118109998Smarkm foreach $sym (@s) { 1119109998Smarkm (my $n, my $i) = split /\\/, $nums{$sym}; 1120109998Smarkm if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) { 1121109998Smarkm $new_info++; 1122109998Smarkm print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug; 1123109998Smarkm } 1124109998Smarkm } 112568651Skris if ($new_info) { 112668651Skris print STDERR "$new_info old symbols got an info update\n"; 112768651Skris if (!$do_rewrite) { 112868651Skris print STDERR "You should do a rewrite to fix this.\n"; 112968651Skris } 113068651Skris } else { 113168651Skris print STDERR "No old symbols needed info update\n"; 113268651Skris } 113368651Skris} 113468651Skris 1135109998Smarkm# Param: string of comma-separated keywords, each possibly prefixed with a "!" 1136109998Smarkmsub is_valid 1137109998Smarkm{ 1138109998Smarkm my ($keywords_txt,$platforms) = @_; 1139109998Smarkm my (@keywords) = split /,/,$keywords_txt; 1140160814Ssimon my ($falsesum, $truesum) = (0, 1); 1141109998Smarkm 1142109998Smarkm # Param: one keyword 1143109998Smarkm sub recognise 1144109998Smarkm { 1145109998Smarkm my ($keyword,$platforms) = @_; 1146109998Smarkm 1147109998Smarkm if ($platforms) { 1148109998Smarkm # platforms 1149205128Ssimon if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; } 1150205128Ssimon if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; } 1151238405Sjkim if ($keyword eq "VMS" && $VMS) { return 1; } 1152109998Smarkm if ($keyword eq "WIN32" && $W32) { return 1; } 1153109998Smarkm if ($keyword eq "WIN16" && $W16) { return 1; } 1154109998Smarkm if ($keyword eq "WINNT" && $NT) { return 1; } 1155109998Smarkm if ($keyword eq "OS2" && $OS2) { return 1; } 1156109998Smarkm # Special platforms: 1157109998Smarkm # EXPORT_VAR_AS_FUNCTION means that global variables 1158109998Smarkm # will be represented as functions. This currently 1159109998Smarkm # only happens on VMS-VAX. 1160109998Smarkm if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) { 1161109998Smarkm return 1; 1162109998Smarkm } 1163194206Ssimon if ($keyword eq "OPENSSL_FIPS" && $fips) { 1164194206Ssimon return 1; 1165194206Ssimon } 1166194206Ssimon if ($keyword eq "ZLIB" && $zlib) { return 1; } 1167109998Smarkm return 0; 1168109998Smarkm } else { 1169109998Smarkm # algorithms 1170109998Smarkm if ($keyword eq "RC2" && $no_rc2) { return 0; } 1171109998Smarkm if ($keyword eq "RC4" && $no_rc4) { return 0; } 1172109998Smarkm if ($keyword eq "RC5" && $no_rc5) { return 0; } 1173109998Smarkm if ($keyword eq "IDEA" && $no_idea) { return 0; } 1174109998Smarkm if ($keyword eq "DES" && $no_des) { return 0; } 1175109998Smarkm if ($keyword eq "BF" && $no_bf) { return 0; } 1176109998Smarkm if ($keyword eq "CAST" && $no_cast) { return 0; } 1177109998Smarkm if ($keyword eq "MD2" && $no_md2) { return 0; } 1178109998Smarkm if ($keyword eq "MD4" && $no_md4) { return 0; } 1179109998Smarkm if ($keyword eq "MD5" && $no_md5) { return 0; } 1180109998Smarkm if ($keyword eq "SHA" && $no_sha) { return 0; } 1181109998Smarkm if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; } 1182109998Smarkm if ($keyword eq "MDC2" && $no_mdc2) { return 0; } 1183238405Sjkim if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; } 1184109998Smarkm if ($keyword eq "RSA" && $no_rsa) { return 0; } 1185109998Smarkm if ($keyword eq "DSA" && $no_dsa) { return 0; } 1186109998Smarkm if ($keyword eq "DH" && $no_dh) { return 0; } 1187109998Smarkm if ($keyword eq "EC" && $no_ec) { return 0; } 1188160814Ssimon if ($keyword eq "ECDSA" && $no_ecdsa) { return 0; } 1189160814Ssimon if ($keyword eq "ECDH" && $no_ecdh) { return 0; } 1190109998Smarkm if ($keyword eq "HMAC" && $no_hmac) { return 0; } 1191109998Smarkm if ($keyword eq "AES" && $no_aes) { return 0; } 1192162911Ssimon if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; } 1193194206Ssimon if ($keyword eq "SEED" && $no_seed) { return 0; } 1194109998Smarkm if ($keyword eq "EVP" && $no_evp) { return 0; } 1195109998Smarkm if ($keyword eq "LHASH" && $no_lhash) { return 0; } 1196109998Smarkm if ($keyword eq "STACK" && $no_stack) { return 0; } 1197109998Smarkm if ($keyword eq "ERR" && $no_err) { return 0; } 1198109998Smarkm if ($keyword eq "BUFFER" && $no_buffer) { return 0; } 1199109998Smarkm if ($keyword eq "BIO" && $no_bio) { return 0; } 1200109998Smarkm if ($keyword eq "COMP" && $no_comp) { return 0; } 1201109998Smarkm if ($keyword eq "DSO" && $no_dso) { return 0; } 1202109998Smarkm if ($keyword eq "KRB5" && $no_krb5) { return 0; } 1203111147Snectar if ($keyword eq "ENGINE" && $no_engine) { return 0; } 1204111147Snectar if ($keyword eq "HW" && $no_hw) { return 0; } 1205109998Smarkm if ($keyword eq "FP_API" && $no_fp_api) { return 0; } 1206160814Ssimon if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; } 1207160814Ssimon if ($keyword eq "GMP" && $no_gmp) { return 0; } 1208167612Ssimon if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; } 1209194206Ssimon if ($keyword eq "TLSEXT" && $no_tlsext) { return 0; } 1210238405Sjkim if ($keyword eq "PSK" && $no_psk) { return 0; } 1211194206Ssimon if ($keyword eq "CMS" && $no_cms) { return 0; } 1212238405Sjkim if ($keyword eq "EC2M" && $no_ec2m) { return 0; } 1213238405Sjkim if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; } 1214238405Sjkim if ($keyword eq "EC_NISTP_64_GCC_128" && $no_nistp_gcc) 1215238405Sjkim { return 0; } 1216238405Sjkim if ($keyword eq "SSL2" && $no_ssl2) { return 0; } 1217298999Sjkim if ($keyword eq "SSL2_METHOD" && $no_ssl2_method) { return 0; } 1218276864Sjkim if ($keyword eq "SSL3_METHOD" && $no_ssl3_method) { return 0; } 1219194206Ssimon if ($keyword eq "CAPIENG" && $no_capieng) { return 0; } 1220194206Ssimon if ($keyword eq "JPAKE" && $no_jpake) { return 0; } 1221238405Sjkim if ($keyword eq "SRP" && $no_srp) { return 0; } 1222238405Sjkim if ($keyword eq "SCTP" && $no_sctp) { return 0; } 1223273149Sjkim if ($keyword eq "SRTP" && $no_srtp) { return 0; } 1224269686Sjkim if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; } 1225160814Ssimon if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; } 1226109998Smarkm 1227109998Smarkm # Nothing recognise as true 1228109998Smarkm return 1; 1229109998Smarkm } 1230109998Smarkm } 1231109998Smarkm 1232109998Smarkm foreach $k (@keywords) { 1233109998Smarkm if ($k =~ /^!(.*)$/) { 1234109998Smarkm $falsesum += &recognise($1,$platforms); 1235109998Smarkm } else { 1236160814Ssimon $truesum *= &recognise($k,$platforms); 1237109998Smarkm } 1238109998Smarkm } 1239109998Smarkm print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug; 1240109998Smarkm return (!$falsesum) && $truesum; 1241109998Smarkm} 1242109998Smarkm 124359191Skrissub print_test_file 124459191Skris{ 1245109998Smarkm (*OUT,my $name,*nums,my $testall,my @symbols)=@_; 124659191Skris my $n = 1; my @e; my @r; 124768651Skris my $sym; my $prev = ""; my $prefSSLeay; 124859191Skris 1249109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 1250109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 125168651Skris @symbols=((sort @e),(sort @r)); 125259191Skris 125368651Skris foreach $sym (@symbols) { 125468651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1255109998Smarkm my $v = 0; 1256109998Smarkm $v = 1 if $i=~ /^.*?:.*?:VARIABLE/; 1257109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1258109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1259109998Smarkm if (!defined($nums{$s})) { 1260109998Smarkm print STDERR "Warning: $s does not have a number assigned\n" 1261109998Smarkm if(!$do_update); 1262109998Smarkm } elsif (is_valid($p,1) && is_valid($a,0)) { 1263109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1264109998Smarkm if ($prev eq $s2) { 1265109998Smarkm print OUT "\t/* The following has already appeared previously */\n"; 1266109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1267109998Smarkm } 1268109998Smarkm $prev = $s2; # To warn about duplicates... 1269109998Smarkm 1270109998Smarkm ($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/); 1271109998Smarkm if ($v) { 1272109998Smarkm print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n"; 127368651Skris } else { 1274109998Smarkm print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n"; 127568651Skris } 127659191Skris } 127759191Skris } 127859191Skris} 127959191Skris 1280127128Snectarsub get_version { 1281127128Snectar local *MF; 1282127128Snectar my $v = '?'; 1283142425Snectar open MF, 'Makefile' or return $v; 1284127128Snectar while (<MF>) { 1285127128Snectar $v = $1, last if /^VERSION=(.*?)\s*$/; 1286127128Snectar } 1287127128Snectar close MF; 1288127128Snectar return $v; 1289127128Snectar} 1290127128Snectar 129155714Skrissub print_def_file 129255714Skris{ 129368651Skris (*OUT,my $name,*nums,my @symbols)=@_; 1294109998Smarkm my $n = 1; my @e; my @r; my @v; my $prev=""; 1295109998Smarkm my $liboptions=""; 1296127128Snectar my $libname = $name; 1297127128Snectar my $http_vendor = 'www.openssl.org/'; 1298127128Snectar my $version = get_version(); 1299127128Snectar my $what = "OpenSSL: implementation of Secure Socket Layer"; 1300127128Snectar my $description = "$what $version, $name - http://$http_vendor"; 130155714Skris 130255714Skris if ($W32) 1303127128Snectar { $libname.="32"; } 1304109998Smarkm elsif ($W16) 1305127128Snectar { $libname.="16"; } 1306109998Smarkm elsif ($OS2) 1307127128Snectar { # DLL names should not clash on the whole system. 1308127128Snectar # However, they should not have any particular relationship 1309127128Snectar # to the name of the static library. Chose descriptive names 1310127128Snectar # (must be at most 8 chars). 1311127128Snectar my %translate = (ssl => 'open_ssl', crypto => 'cryptssl'); 1312127128Snectar $libname = $translate{$name} || $name; 1313127128Snectar $liboptions = <<EOO; 1314127128SnectarINITINSTANCE 1315127128SnectarDATA MULTIPLE NONSHARED 1316127128SnectarEOO 1317127128Snectar # Vendor field can't contain colon, drat; so we omit http:// 1318127128Snectar $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd"; 1319127128Snectar } 132055714Skris 132155714Skris print OUT <<"EOF"; 132255714Skris; 132355714Skris; Definition file for the DLL version of the $name library from OpenSSL 132455714Skris; 132555714Skris 1326127128SnectarLIBRARY $libname $liboptions 132755714Skris 132855714SkrisEOF 132955714Skris 1330109998Smarkm if ($W16) { 133155714Skris print <<"EOF"; 133255714SkrisCODE PRELOAD MOVEABLE 133355714SkrisDATA PRELOAD MOVEABLE SINGLE 133455714Skris 133555714SkrisEXETYPE WINDOWS 133655714Skris 133755714SkrisHEAPSIZE 4096 133855714SkrisSTACKSIZE 8192 133955714Skris 134055714SkrisEOF 134155714Skris } 134255714Skris 134355714Skris print "EXPORTS\n"; 134455714Skris 1345109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1346109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1347109998Smarkm (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols); 1348109998Smarkm @symbols=((sort @e),(sort @r), (sort @v)); 134955714Skris 135055714Skris 135168651Skris foreach $sym (@symbols) { 135268651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1353109998Smarkm my $v = 0; 1354109998Smarkm $v = 1 if $i =~ /^.*?:.*?:VARIABLE/; 135568651Skris if (!defined($nums{$s})) { 135668651Skris printf STDERR "Warning: $s does not have a number assigned\n" 1357109998Smarkm if(!$do_update); 135855714Skris } else { 1359109998Smarkm (my $n, my $dummy) = split /\\/, $nums{$s}; 136068651Skris my %pf = (); 1361109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1362109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1363109998Smarkm if (is_valid($p,1) && is_valid($a,0)) { 1364109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1365109998Smarkm if ($prev eq $s2) { 1366109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1367109998Smarkm } 1368109998Smarkm $prev = $s2; # To warn about duplicates... 1369109998Smarkm if($v && !$OS2) { 1370109998Smarkm printf OUT " %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n; 1371109998Smarkm } else { 1372109998Smarkm printf OUT " %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n; 1373109998Smarkm } 137468651Skris } 137555714Skris } 137655714Skris } 137755714Skris printf OUT "\n"; 137855714Skris} 137955714Skris 138055714Skrissub load_numbers 138155714Skris{ 138255714Skris my($name)=@_; 138355714Skris my(@a,%ret); 138455714Skris 138555714Skris $max_num = 0; 138668651Skris $num_noinfo = 0; 138768651Skris $prev = ""; 1388109998Smarkm $prev_cnt = 0; 138955714Skris 139055714Skris open(IN,"<$name") || die "unable to open $name:$!\n"; 139155714Skris while (<IN>) { 139255714Skris chop; 139355714Skris s/#.*$//; 139455714Skris next if /^\s*$/; 139555714Skris @a=split; 139668651Skris if (defined $ret{$a[0]}) { 1397109998Smarkm # This is actually perfectly OK 1398109998Smarkm #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n"; 139968651Skris } 140068651Skris if ($max_num > $a[1]) { 140168651Skris print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n"; 140268651Skris } 1403109998Smarkm elsif ($max_num == $a[1]) { 140468651Skris # This is actually perfectly OK 140568651Skris #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n"; 1406109998Smarkm if ($a[0] eq $prev) { 1407109998Smarkm $prev_cnt++; 1408109998Smarkm $a[0] .= "{$prev_cnt}"; 1409109998Smarkm } 141068651Skris } 1411109998Smarkm else { 1412109998Smarkm $prev_cnt = 0; 1413109998Smarkm } 141468651Skris if ($#a < 2) { 141568651Skris # Existence will be proven later, in do_defs 141668651Skris $ret{$a[0]}=$a[1]; 141768651Skris $num_noinfo++; 141868651Skris } else { 141968651Skris $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker 142068651Skris } 142155714Skris $max_num = $a[1] if $a[1] > $max_num; 142268651Skris $prev=$a[0]; 142355714Skris } 142468651Skris if ($num_noinfo) { 142568651Skris print STDERR "Warning: $num_noinfo symbols were without info."; 142668651Skris if ($do_rewrite) { 142768651Skris printf STDERR " The rewrite will fix this.\n"; 142868651Skris } else { 142968651Skris printf STDERR " You should do a rewrite to fix this.\n"; 143068651Skris } 143168651Skris } 143255714Skris close(IN); 143355714Skris return(%ret); 143455714Skris} 143555714Skris 143668651Skrissub parse_number 143768651Skris{ 143868651Skris (my $str, my $what) = @_; 143968651Skris (my $n, my $i) = split(/\\/,$str); 144068651Skris if ($what eq "n") { 144168651Skris return $n; 144268651Skris } else { 144368651Skris return $i; 144468651Skris } 144568651Skris} 144668651Skris 144768651Skrissub rewrite_numbers 144868651Skris{ 144968651Skris (*OUT,$name,*nums,@symbols)=@_; 145068651Skris my $thing; 145168651Skris 145268651Skris print STDERR "Rewriting $name\n"; 145368651Skris 1454109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 145568651Skris my $r; my %r; my %rsyms; 145668651Skris foreach $r (@r) { 145768651Skris (my $s, my $i) = split /\\/, $r; 145868651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 145968651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 146068651Skris $r{$a} = $s."\\".$i; 146168651Skris $rsyms{$s} = 1; 146268651Skris } 146368651Skris 1464109998Smarkm my %syms = (); 1465109998Smarkm foreach $_ (@symbols) { 1466109998Smarkm (my $n, my $i) = split /\\/; 1467109998Smarkm $syms{$n} = 1; 1468109998Smarkm } 1469109998Smarkm 1470109998Smarkm my @s=sort { 1471109998Smarkm &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") 1472109998Smarkm || $a cmp $b 1473109998Smarkm } keys %nums; 147468651Skris foreach $sym (@s) { 147568651Skris (my $n, my $i) = split /\\/, $nums{$sym}; 147668651Skris next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/; 147768651Skris next if defined($rsyms{$sym}); 1478109998Smarkm print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug; 1479109998Smarkm $i="NOEXIST::FUNCTION:" 1480109998Smarkm if !defined($i) || $i eq "" || !defined($syms{$sym}); 1481109998Smarkm my $s2 = $sym; 1482109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1483109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 148468651Skris if (exists $r{$sym}) { 148568651Skris (my $s, $i) = split /\\/,$r{$sym}; 1486109998Smarkm my $s2 = $s; 1487109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1488109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 148968651Skris } 149068651Skris } 149168651Skris} 149268651Skris 149355714Skrissub update_numbers 149455714Skris{ 149568651Skris (*OUT,$name,*nums,my $start_num, my @symbols)=@_; 149668651Skris my $new_syms = 0; 149768651Skris 149868651Skris print STDERR "Updating $name numbers\n"; 149968651Skris 1500109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 150168651Skris my $r; my %r; my %rsyms; 150268651Skris foreach $r (@r) { 150368651Skris (my $s, my $i) = split /\\/, $r; 150468651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 150568651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 150668651Skris $r{$a} = $s."\\".$i; 150768651Skris $rsyms{$s} = 1; 150868651Skris } 150968651Skris 151068651Skris foreach $sym (@symbols) { 151168651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 151268651Skris next if $i =~ /^.*?:.*?:\w+\(\w+\)/; 151368651Skris next if defined($rsyms{$sym}); 151468651Skris die "ERROR: Symbol $sym had no info attached to it." 151568651Skris if $i eq ""; 151668651Skris if (!exists $nums{$s}) { 151768651Skris $new_syms++; 1518109998Smarkm my $s2 = $s; 1519109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1520109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i; 152168651Skris if (exists $r{$s}) { 152268651Skris ($s, $i) = split /\\/,$r{$s}; 1523109998Smarkm $s =~ s/\{[0-9]+\}$//; 1524109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i; 152568651Skris } 152655714Skris } 152755714Skris } 152868651Skris if($new_syms) { 152968651Skris print STDERR "$new_syms New symbols added\n"; 153055714Skris } else { 153168651Skris print STDERR "No New symbols Added\n"; 153255714Skris } 153355714Skris} 153468651Skris 153568651Skrissub check_existing 153668651Skris{ 153768651Skris (*nums, my @symbols)=@_; 153868651Skris my %existing; my @remaining; 153968651Skris @remaining=(); 154068651Skris foreach $sym (@symbols) { 154168651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 154268651Skris $existing{$s}=1; 154368651Skris } 154468651Skris foreach $sym (keys %nums) { 154568651Skris if (!exists $existing{$sym}) { 154668651Skris push @remaining, $sym; 154768651Skris } 154868651Skris } 154968651Skris if(@remaining) { 155068651Skris print STDERR "The following symbols do not seem to exist:\n"; 155168651Skris foreach $sym (@remaining) { 155268651Skris print STDERR "\t",$sym,"\n"; 155368651Skris } 155468651Skris } 155568651Skris} 155668651Skris 1557