mkdef.pl revision 276861
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", 110276861Sjkim # SSL v3 method 111276861Sjkim "SSL3_METHOD", 112194206Ssimon # JPAKE 113194206Ssimon "JPAKE", 114238405Sjkim # NEXTPROTONEG 115238405Sjkim "NEXTPROTONEG", 116160814Ssimon # Deprecated functions 117238405Sjkim "DEPRECATED", 118238405Sjkim # Hide SSL internals 119238405Sjkim "SSL_INTERN", 120238405Sjkim # SCTP 121269682Sjkim "SCTP", 122273144Sjkim # SRTP 123273144Sjkim "SRTP", 124269682Sjkim # Unit testing 125269682Sjkim "UNIT_TEST"); 12668651Skris 12759191Skrismy $options=""; 128142425Snectaropen(IN,"<Makefile") || die "unable to open Makefile!\n"; 12955714Skriswhile(<IN>) { 13055714Skris $options=$1 if (/^OPTIONS=(.*)$/); 13155714Skris} 13255714Skrisclose(IN); 13355714Skris 13459191Skris# The following ciphers may be excluded (by Configure). This means functions 13559191Skris# defined with ifndef(NO_XXX) are not included in the .def file, and everything 13659191Skris# in directory xxx is ignored. 13759191Skrismy $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf; 138238405Sjkimmy $no_cast; my $no_whirlpool; my $no_camellia; my $no_seed; 13968651Skrismy $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2; 140109998Smarkmmy $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5; 141238405Sjkimmy $no_ec; my $no_ecdsa; my $no_ecdh; my $no_engine; my $no_hw; 142238405Sjkimmy $no_fp_api; my $no_static_engine=1; my $no_gmp; my $no_deprecated; 143238405Sjkimmy $no_rfc3779; my $no_psk; my $no_tlsext; my $no_cms; my $no_capieng; 144238405Sjkimmy $no_jpake; my $no_srp; my $no_ssl2; my $no_ec2m; my $no_nistp_gcc; 145273144Sjkimmy $no_nextprotoneg; my $no_sctp; my $no_srtp; 146276861Sjkimmy $no_unit_test; my $no_ssl3_method; 147238405Sjkim 148194206Ssimonmy $fips; 14959191Skris 150238405Sjkimmy $zlib; 151160814Ssimon 152238405Sjkim 15355714Skrisforeach (@ARGV, split(/ /, $options)) 15455714Skris { 155109998Smarkm $debug=1 if $_ eq "debug"; 15655714Skris $W32=1 if $_ eq "32"; 15768651Skris $W16=1 if $_ eq "16"; 15855714Skris if($_ eq "NT") { 15955714Skris $W32 = 1; 16055714Skris $NT = 1; 16155714Skris } 162109998Smarkm if ($_ eq "VMS-VAX") { 163109998Smarkm $VMS=1; 164109998Smarkm $VMSVAX=1; 165109998Smarkm } 166205128Ssimon if ($_ eq "VMS-NonVAX") { 167109998Smarkm $VMS=1; 168205128Ssimon $VMSNonVAX=1; 169109998Smarkm } 17068651Skris $VMS=1 if $_ eq "VMS"; 171109998Smarkm $OS2=1 if $_ eq "OS2"; 172194206Ssimon $fips=1 if /^fips/; 173238405Sjkim if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic" 174238405Sjkim || $_ eq "enable-zlib-dynamic") { 175238405Sjkim $zlib = 1; 176194206Ssimon } 177194206Ssimon 17855714Skris $do_ssl=1 if $_ eq "ssleay"; 179109998Smarkm if ($_ eq "ssl") { 180109998Smarkm $do_ssl=1; 181109998Smarkm $libname=$_ 182109998Smarkm } 18355714Skris $do_crypto=1 if $_ eq "libeay"; 184109998Smarkm if ($_ eq "crypto") { 185109998Smarkm $do_crypto=1; 186109998Smarkm $libname=$_; 187109998Smarkm } 188160814Ssimon $no_static_engine=1 if $_ eq "no-static-engine"; 189160814Ssimon $no_static_engine=0 if $_ eq "enable-static-engine"; 19055714Skris $do_update=1 if $_ eq "update"; 19168651Skris $do_rewrite=1 if $_ eq "rewrite"; 19259191Skris $do_ctest=1 if $_ eq "ctest"; 19368651Skris $do_ctestall=1 if $_ eq "ctestall"; 194109998Smarkm $do_checkexist=1 if $_ eq "exist"; 19568651Skris #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK"; 19655714Skris 19755714Skris if (/^no-rc2$/) { $no_rc2=1; } 19855714Skris elsif (/^no-rc4$/) { $no_rc4=1; } 19955714Skris elsif (/^no-rc5$/) { $no_rc5=1; } 20055714Skris elsif (/^no-idea$/) { $no_idea=1; } 20172613Skris elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; } 20255714Skris elsif (/^no-bf$/) { $no_bf=1; } 20355714Skris elsif (/^no-cast$/) { $no_cast=1; } 204238405Sjkim elsif (/^no-whirlpool$/) { $no_whirlpool=1; } 20555714Skris elsif (/^no-md2$/) { $no_md2=1; } 20668651Skris elsif (/^no-md4$/) { $no_md4=1; } 20755714Skris elsif (/^no-md5$/) { $no_md5=1; } 20855714Skris elsif (/^no-sha$/) { $no_sha=1; } 20955714Skris elsif (/^no-ripemd$/) { $no_ripemd=1; } 21055714Skris elsif (/^no-mdc2$/) { $no_mdc2=1; } 21155714Skris elsif (/^no-rsa$/) { $no_rsa=1; } 21255714Skris elsif (/^no-dsa$/) { $no_dsa=1; } 21355714Skris elsif (/^no-dh$/) { $no_dh=1; } 214109998Smarkm elsif (/^no-ec$/) { $no_ec=1; } 215160814Ssimon elsif (/^no-ecdsa$/) { $no_ecdsa=1; } 216160814Ssimon elsif (/^no-ecdh$/) { $no_ecdh=1; } 21755714Skris elsif (/^no-hmac$/) { $no_hmac=1; } 218109998Smarkm elsif (/^no-aes$/) { $no_aes=1; } 219162911Ssimon elsif (/^no-camellia$/) { $no_camellia=1; } 220194206Ssimon elsif (/^no-seed$/) { $no_seed=1; } 221109998Smarkm elsif (/^no-evp$/) { $no_evp=1; } 222109998Smarkm elsif (/^no-lhash$/) { $no_lhash=1; } 223109998Smarkm elsif (/^no-stack$/) { $no_stack=1; } 224109998Smarkm elsif (/^no-err$/) { $no_err=1; } 225109998Smarkm elsif (/^no-buffer$/) { $no_buffer=1; } 226109998Smarkm elsif (/^no-bio$/) { $no_bio=1; } 227109998Smarkm #elsif (/^no-locking$/) { $no_locking=1; } 228109998Smarkm elsif (/^no-comp$/) { $no_comp=1; } 229109998Smarkm elsif (/^no-dso$/) { $no_dso=1; } 230109998Smarkm elsif (/^no-krb5$/) { $no_krb5=1; } 231111147Snectar elsif (/^no-engine$/) { $no_engine=1; } 232111147Snectar elsif (/^no-hw$/) { $no_hw=1; } 233160814Ssimon elsif (/^no-gmp$/) { $no_gmp=1; } 234167612Ssimon elsif (/^no-rfc3779$/) { $no_rfc3779=1; } 235194206Ssimon elsif (/^no-tlsext$/) { $no_tlsext=1; } 236194206Ssimon elsif (/^no-cms$/) { $no_cms=1; } 237238405Sjkim elsif (/^no-ec2m$/) { $no_ec2m=1; } 238238405Sjkim elsif (/^no-ec_nistp_64_gcc_128$/) { $no_nistp_gcc=1; } 239238405Sjkim elsif (/^no-nextprotoneg$/) { $no_nextprotoneg=1; } 240238405Sjkim elsif (/^no-ssl2$/) { $no_ssl2=1; } 241276861Sjkim elsif (/^no-ssl3-method$/) { $no_ssl3_method=1; } 242194206Ssimon elsif (/^no-capieng$/) { $no_capieng=1; } 243194206Ssimon elsif (/^no-jpake$/) { $no_jpake=1; } 244238405Sjkim elsif (/^no-srp$/) { $no_srp=1; } 245238405Sjkim elsif (/^no-sctp$/) { $no_sctp=1; } 246273144Sjkim elsif (/^no-srtp$/) { $no_srtp=1; } 247269682Sjkim elsif (/^no-unit-test$/){ $no_unit_test=1; } 24855714Skris } 24955714Skris 25059191Skris 251109998Smarkmif (!$libname) { 252109998Smarkm if ($do_ssl) { 253109998Smarkm $libname="SSLEAY"; 254109998Smarkm } 255109998Smarkm if ($do_crypto) { 256109998Smarkm $libname="LIBEAY"; 257109998Smarkm } 258109998Smarkm} 259109998Smarkm 26068651Skris# If no platform is given, assume WIN32 261109998Smarkmif ($W32 + $W16 + $VMS + $OS2 == 0) { 26268651Skris $W32 = 1; 26368651Skris} 26468651Skris 26568651Skris# Add extra knowledge 26668651Skrisif ($W16) { 26768651Skris $no_fp_api=1; 26868651Skris} 26968651Skris 27055714Skrisif (!$do_ssl && !$do_crypto) 27155714Skris { 272109998Smarkm print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n"; 27355714Skris exit(1); 27455714Skris } 27555714Skris 27655714Skris%ssl_list=&load_numbers($ssl_num); 27755714Skris$max_ssl = $max_num; 27855714Skris%crypto_list=&load_numbers($crypto_num); 27955714Skris$max_crypto = $max_num; 28055714Skris 28159191Skrismy $ssl="ssl/ssl.h"; 282109998Smarkm$ssl.=" ssl/kssl.h"; 283194206Ssimon$ssl.=" ssl/tls1.h"; 284238405Sjkim$ssl.=" ssl/srtp.h"; 28555714Skris 28659191Skrismy $crypto ="crypto/crypto.h"; 287238405Sjkim$crypto.=" crypto/cryptlib.h"; 288160814Ssimon$crypto.=" crypto/o_dir.h"; 289238405Sjkim$crypto.=" crypto/o_str.h"; 290238405Sjkim$crypto.=" crypto/o_time.h"; 291109998Smarkm$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des; 292109998Smarkm$crypto.=" crypto/idea/idea.h" ; # unless $no_idea; 293109998Smarkm$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4; 294109998Smarkm$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5; 295109998Smarkm$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2; 296109998Smarkm$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf; 297109998Smarkm$crypto.=" crypto/cast/cast.h" ; # unless $no_cast; 298238405Sjkim$crypto.=" crypto/whrlpool/whrlpool.h" ; 299109998Smarkm$crypto.=" crypto/md2/md2.h" ; # unless $no_md2; 300109998Smarkm$crypto.=" crypto/md4/md4.h" ; # unless $no_md4; 301109998Smarkm$crypto.=" crypto/md5/md5.h" ; # unless $no_md5; 302109998Smarkm$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2; 303109998Smarkm$crypto.=" crypto/sha/sha.h" ; # unless $no_sha; 304109998Smarkm$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd; 305109998Smarkm$crypto.=" crypto/aes/aes.h" ; # unless $no_aes; 306162911Ssimon$crypto.=" crypto/camellia/camellia.h" ; # unless $no_camellia; 307194206Ssimon$crypto.=" crypto/seed/seed.h"; # unless $no_seed; 30855714Skris 30955714Skris$crypto.=" crypto/bn/bn.h"; 310109998Smarkm$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa; 311109998Smarkm$crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa; 312109998Smarkm$crypto.=" crypto/dh/dh.h" ; # unless $no_dh; 313109998Smarkm$crypto.=" crypto/ec/ec.h" ; # unless $no_ec; 314160814Ssimon$crypto.=" crypto/ecdsa/ecdsa.h" ; # unless $no_ecdsa; 315160814Ssimon$crypto.=" crypto/ecdh/ecdh.h" ; # unless $no_ecdh; 316109998Smarkm$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac; 317238405Sjkim$crypto.=" crypto/cmac/cmac.h" ; # unless $no_hmac; 31855714Skris 319111147Snectar$crypto.=" crypto/engine/engine.h"; # unless $no_engine; 320109998Smarkm$crypto.=" crypto/stack/stack.h" ; # unless $no_stack; 321109998Smarkm$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer; 322109998Smarkm$crypto.=" crypto/bio/bio.h" ; # unless $no_bio; 323109998Smarkm$crypto.=" crypto/dso/dso.h" ; # unless $no_dso; 324109998Smarkm$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash; 32555714Skris$crypto.=" crypto/conf/conf.h"; 32655714Skris$crypto.=" crypto/txt_db/txt_db.h"; 32755714Skris 328109998Smarkm$crypto.=" crypto/evp/evp.h" ; # unless $no_evp; 32955714Skris$crypto.=" crypto/objects/objects.h"; 33055714Skris$crypto.=" crypto/pem/pem.h"; 33155714Skris#$crypto.=" crypto/meth/meth.h"; 33255714Skris$crypto.=" crypto/asn1/asn1.h"; 333109998Smarkm$crypto.=" crypto/asn1/asn1t.h"; 33455714Skris$crypto.=" crypto/asn1/asn1_mac.h"; 335109998Smarkm$crypto.=" crypto/err/err.h" ; # unless $no_err; 33655714Skris$crypto.=" crypto/pkcs7/pkcs7.h"; 33755714Skris$crypto.=" crypto/pkcs12/pkcs12.h"; 33855714Skris$crypto.=" crypto/x509/x509.h"; 33955714Skris$crypto.=" crypto/x509/x509_vfy.h"; 34055714Skris$crypto.=" crypto/x509v3/x509v3.h"; 341238405Sjkim$crypto.=" crypto/ts/ts.h"; 34255714Skris$crypto.=" crypto/rand/rand.h"; 343109998Smarkm$crypto.=" crypto/comp/comp.h" ; # unless $no_comp; 344109998Smarkm$crypto.=" crypto/ocsp/ocsp.h"; 345109998Smarkm$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h"; 346109998Smarkm$crypto.=" crypto/krb5/krb5_asn.h"; 347238405Sjkim#$crypto.=" crypto/store/store.h"; 348160814Ssimon$crypto.=" crypto/pqueue/pqueue.h"; 349194206Ssimon$crypto.=" crypto/cms/cms.h"; 350194206Ssimon$crypto.=" crypto/jpake/jpake.h"; 351238405Sjkim$crypto.=" crypto/modes/modes.h"; 352238405Sjkim$crypto.=" crypto/srp/srp.h"; 35355714Skris 35468651Skrismy $symhacks="crypto/symhacks.h"; 35555714Skris 35668651Skrismy @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks); 35768651Skrismy @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks); 35855714Skris 35955714Skrisif ($do_update) { 36055714Skris 36155714Skrisif ($do_ssl == 1) { 36268651Skris 36368651Skris &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols); 36468651Skris if ($do_rewrite == 1) { 36568651Skris open(OUT, ">$ssl_num"); 36668651Skris &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols); 36768651Skris } else { 36868651Skris open(OUT, ">>$ssl_num"); 36968651Skris } 37068651Skris &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols); 37155714Skris close OUT; 37255714Skris} 37355714Skris 37455714Skrisif($do_crypto == 1) { 37568651Skris 37668651Skris &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols); 37768651Skris if ($do_rewrite == 1) { 37868651Skris open(OUT, ">$crypto_num"); 37968651Skris &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols); 38068651Skris } else { 38168651Skris open(OUT, ">>$crypto_num"); 38268651Skris } 38368651Skris &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols); 38455714Skris close OUT; 38559191Skris} 38655714Skris 387109998Smarkm} elsif ($do_checkexist) { 388109998Smarkm &check_existing(*ssl_list, @ssl_symbols) 389109998Smarkm if $do_ssl == 1; 390109998Smarkm &check_existing(*crypto_list, @crypto_symbols) 391109998Smarkm if $do_crypto == 1; 39268651Skris} elsif ($do_ctest || $do_ctestall) { 39359191Skris 39459191Skris print <<"EOF"; 39559191Skris 39659191Skris/* Test file to check all DEF file symbols are present by trying 39759191Skris * to link to all of them. This is *not* intended to be run! 39859191Skris */ 39959191Skris 40059191Skrisint main() 40159191Skris{ 40259191SkrisEOF 40368651Skris &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols) 40459191Skris if $do_ssl == 1; 40559191Skris 40668651Skris &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols) 40759191Skris if $do_crypto == 1; 40859191Skris 40959191Skris print "}\n"; 41059191Skris 41155714Skris} else { 41255714Skris 413109998Smarkm &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols) 41455714Skris if $do_ssl == 1; 41555714Skris 416109998Smarkm &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols) 41755714Skris if $do_crypto == 1; 41855714Skris 41955714Skris} 42055714Skris 42155714Skris 42255714Skrissub do_defs 42355714Skris{ 42468651Skris my($name,$files,$symhacksfile)=@_; 42559191Skris my $file; 42655714Skris my @ret; 42768651Skris my %syms; 42868651Skris my %platform; # For anything undefined, we assume "" 42968651Skris my %kind; # For anything undefined, we assume "FUNCTION" 43068651Skris my %algorithm; # For anything undefined, we assume "" 431109998Smarkm my %variant; 432109998Smarkm my %variant_cnt; # To be able to allocate "name{n}" if "name" 433109998Smarkm # is the same name as the original. 43459191Skris my $cpp; 435109998Smarkm my %unknown_algorithms = (); 43655714Skris 43768651Skris foreach $file (split(/\s+/,$symhacksfile." ".$files)) 43855714Skris { 439109998Smarkm print STDERR "DEBUG: starting on $file:\n" if $debug; 44055714Skris open(IN,"<$file") || die "unable to open $file:$!\n"; 44159191Skris my $line = "", my $def= ""; 44255714Skris my %tag = ( 44368651Skris (map { $_ => 0 } @known_platforms), 444109998Smarkm (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms), 445109998Smarkm (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms), 44655714Skris NOPROTO => 0, 44755714Skris PERL5 => 0, 44855714Skris _WINDLL => 0, 44955714Skris CONST_STRICT => 0, 45055714Skris TRUE => 1, 45155714Skris ); 45268651Skris my $symhacking = $file eq $symhacksfile; 453109998Smarkm my @current_platforms = (); 454109998Smarkm my @current_algorithms = (); 455109998Smarkm 456109998Smarkm # params: symbol, alias, platforms, kind 457109998Smarkm # The reason to put this subroutine in a variable is that 458109998Smarkm # it will otherwise create it's own, unshared, version of 459109998Smarkm # %tag and %variant... 460109998Smarkm my $make_variant = sub 461109998Smarkm { 462109998Smarkm my ($s, $a, $p, $k) = @_; 463109998Smarkm my ($a1, $a2); 464109998Smarkm 465109998Smarkm print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug; 466109998Smarkm if (defined($p)) 467109998Smarkm { 468109998Smarkm $a1 = join(",",$p, 469109998Smarkm grep(!/^$/, 470109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 471109998Smarkm @known_platforms)); 472109998Smarkm } 473109998Smarkm else 474109998Smarkm { 475109998Smarkm $a1 = join(",", 476109998Smarkm grep(!/^$/, 477109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 478109998Smarkm @known_platforms)); 479109998Smarkm } 480109998Smarkm $a2 = join(",", 481109998Smarkm grep(!/^$/, 482109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" } 483109998Smarkm @known_ossl_platforms)); 484109998Smarkm print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug; 485109998Smarkm if ($a1 eq "") { $a1 = $a2; } 486109998Smarkm elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; } 487109998Smarkm if ($a eq $s) 488109998Smarkm { 489109998Smarkm if (!defined($variant_cnt{$s})) 490109998Smarkm { 491109998Smarkm $variant_cnt{$s} = 0; 492109998Smarkm } 493109998Smarkm $variant_cnt{$s}++; 494109998Smarkm $a .= "{$variant_cnt{$s}}"; 495109998Smarkm } 496109998Smarkm my $toadd = $a.":".$a1.(defined($k)?":".$k:""); 497109998Smarkm my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:""); 498109998Smarkm if (!grep(/^$togrep$/, 499109998Smarkm split(/;/, defined($variant{$s})?$variant{$s}:""))) { 500109998Smarkm if (defined($variant{$s})) { $variant{$s} .= ";"; } 501109998Smarkm $variant{$s} .= $toadd; 502109998Smarkm } 503109998Smarkm print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug; 504109998Smarkm }; 505109998Smarkm 506109998Smarkm print STDERR "DEBUG: parsing ----------\n" if $debug; 50755714Skris while(<IN>) { 508160814Ssimon if (/\/\* Error codes for the \w+ functions\. \*\//) 509160814Ssimon { 510160814Ssimon undef @tag; 511160814Ssimon last; 512160814Ssimon } 51355714Skris if ($line ne '') { 51455714Skris $_ = $line . $_; 51555714Skris $line = ''; 51655714Skris } 51755714Skris 51855714Skris if (/\\$/) { 519109998Smarkm chomp; # remove eol 520109998Smarkm chop; # remove ending backslash 52155714Skris $line = $_; 52255714Skris next; 52355714Skris } 52455714Skris 525160814Ssimon if(/\/\*/) { 526160814Ssimon if (not /\*\//) { # multiline comment... 527160814Ssimon $line = $_; # ... just accumulate 528160814Ssimon next; 529160814Ssimon } else { 530160814Ssimon s/\/\*.*?\*\///gs;# wipe it 531160814Ssimon } 532160814Ssimon } 533160814Ssimon 53455714Skris if ($cpp) { 535160814Ssimon $cpp++ if /^#\s*if/; 536160814Ssimon $cpp-- if /^#\s*endif/; 53755714Skris next; 53855714Skris } 539160814Ssimon $cpp = 1 if /^#.*ifdef.*cplusplus/; 54055714Skris 54155714Skris s/{[^{}]*}//gs; # ignore {} blocks 542120631Snectar print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne ""; 543109998Smarkm print STDERR "DEBUG: \$_=\"$_\"\n" if $debug; 544109998Smarkm if (/^\#\s*ifndef\s+(.*)/) { 545109998Smarkm push(@tag,"-"); 54655714Skris push(@tag,$1); 54755714Skris $tag{$1}=-1; 548109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 549109998Smarkm } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) { 550109998Smarkm push(@tag,"-"); 551109998Smarkm if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) { 552109998Smarkm my $tmp_1 = $1; 553109998Smarkm my $tmp_; 554109998Smarkm foreach $tmp_ (split '\&\&',$tmp_1) { 555109998Smarkm $tmp_ =~ /!defined\(([^\)]+)\)/; 556109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 557109998Smarkm push(@tag,$1); 558109998Smarkm $tag{$1}=-1; 559109998Smarkm } 560109998Smarkm } else { 561109998Smarkm print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O... 562109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 563109998Smarkm push(@tag,$1); 564109998Smarkm $tag{$1}=-1; 565109998Smarkm } 566160814Ssimon } elsif (/^\#\s*ifdef\s+(\S*)/) { 567109998Smarkm push(@tag,"-"); 56855714Skris push(@tag,$1); 56955714Skris $tag{$1}=1; 570109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 571109998Smarkm } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) { 572109998Smarkm push(@tag,"-"); 573109998Smarkm if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) { 574109998Smarkm my $tmp_1 = $1; 575109998Smarkm my $tmp_; 576109998Smarkm foreach $tmp_ (split '\|\|',$tmp_1) { 577109998Smarkm $tmp_ =~ /defined\(([^\)]+)\)/; 578109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 579109998Smarkm push(@tag,$1); 580109998Smarkm $tag{$1}=1; 581109998Smarkm } 582109998Smarkm } else { 583109998Smarkm print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O... 584109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 585109998Smarkm push(@tag,$1); 586109998Smarkm $tag{$1}=1; 587109998Smarkm } 58868651Skris } elsif (/^\#\s*error\s+(\w+) is disabled\./) { 589109998Smarkm my $tag_i = $#tag; 590109998Smarkm while($tag[$tag_i] ne "-") { 591109998Smarkm if ($tag[$tag_i] eq "OPENSSL_NO_".$1) { 592109998Smarkm $tag{$tag[$tag_i]}=2; 593109998Smarkm print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug; 594109998Smarkm } 595109998Smarkm $tag_i--; 59668651Skris } 59755714Skris } elsif (/^\#\s*endif/) { 598109998Smarkm my $tag_i = $#tag; 599160814Ssimon while($tag_i > 0 && $tag[$tag_i] ne "-") { 600109998Smarkm my $t=$tag[$tag_i]; 601109998Smarkm print STDERR "DEBUG: \$t=\"$t\"\n" if $debug; 602109998Smarkm if ($tag{$t}==2) { 603109998Smarkm $tag{$t}=-1; 604109998Smarkm } else { 605109998Smarkm $tag{$t}=0; 606109998Smarkm } 607109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 608109998Smarkm pop(@tag); 609109998Smarkm if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) { 610109998Smarkm $t=$1; 611109998Smarkm } else { 612109998Smarkm $t=""; 613109998Smarkm } 614109998Smarkm if ($t ne "" 615109998Smarkm && !grep(/^$t$/, @known_algorithms)) { 616109998Smarkm $unknown_algorithms{$t} = 1; 617109998Smarkm #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug; 618109998Smarkm } 619109998Smarkm $tag_i--; 62068651Skris } 62155714Skris pop(@tag); 62255714Skris } elsif (/^\#\s*else/) { 623109998Smarkm my $tag_i = $#tag; 624109998Smarkm while($tag[$tag_i] ne "-") { 625109998Smarkm my $t=$tag[$tag_i]; 626109998Smarkm $tag{$t}= -$tag{$t}; 627109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 628109998Smarkm $tag_i--; 629109998Smarkm } 63055714Skris } elsif (/^\#\s*if\s+1/) { 631109998Smarkm push(@tag,"-"); 63255714Skris # Dummy tag 63355714Skris push(@tag,"TRUE"); 63455714Skris $tag{"TRUE"}=1; 635109998Smarkm print STDERR "DEBUG: $file: found 1\n" if $debug; 63659191Skris } elsif (/^\#\s*if\s+0/) { 637109998Smarkm push(@tag,"-"); 63859191Skris # Dummy tag 63959191Skris push(@tag,"TRUE"); 64059191Skris $tag{"TRUE"}=-1; 641109998Smarkm print STDERR "DEBUG: $file: found 0\n" if $debug; 64268651Skris } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/ 643109998Smarkm && $symhacking && $tag{'TRUE'} != -1) { 644109998Smarkm # This is for aliasing. When we find an alias, 645109998Smarkm # we have to invert 646109998Smarkm &$make_variant($1,$2); 647109998Smarkm print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug; 64868651Skris } 64968651Skris if (/^\#/) { 650109998Smarkm @current_platforms = 651109998Smarkm grep(!/^$/, 652109998Smarkm map { $tag{$_} == 1 ? $_ : 653109998Smarkm $tag{$_} == -1 ? "!".$_ : "" } 654109998Smarkm @known_platforms); 655109998Smarkm push @current_platforms 656109998Smarkm , grep(!/^$/, 657109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : 658109998Smarkm $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" } 659109998Smarkm @known_ossl_platforms); 660109998Smarkm @current_algorithms = 661109998Smarkm grep(!/^$/, 662109998Smarkm map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" } 663109998Smarkm @known_algorithms); 664109998Smarkm $def .= 665109998Smarkm "#INFO:" 666109998Smarkm .join(',',@current_platforms).":" 667109998Smarkm .join(',',@current_algorithms).";"; 66859191Skris next; 66968651Skris } 670109998Smarkm if ($tag{'TRUE'} != -1) { 671109998Smarkm if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { 672109998Smarkm next; 673109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 674109998Smarkm $def .= "int d2i_$3(void);"; 675109998Smarkm $def .= "int i2d_$3(void);"; 676109998Smarkm # Variant for platforms that do not 677109998Smarkm # have to access globale variables 678109998Smarkm # in shared libraries through functions 679109998Smarkm $def .= 680109998Smarkm "#INFO:" 681109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 682109998Smarkm .join(',',@current_algorithms).";"; 683109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 684109998Smarkm $def .= 685109998Smarkm "#INFO:" 686109998Smarkm .join(',',@current_platforms).":" 687109998Smarkm .join(',',@current_algorithms).";"; 688109998Smarkm # Variant for platforms that have to 689109998Smarkm # access globale variables in shared 690109998Smarkm # libraries through functions 691109998Smarkm &$make_variant("$2_it","$2_it", 692109998Smarkm "EXPORT_VAR_AS_FUNCTION", 693109998Smarkm "FUNCTION"); 694109998Smarkm next; 695109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 696109998Smarkm $def .= "int d2i_$3(void);"; 697109998Smarkm $def .= "int i2d_$3(void);"; 698109998Smarkm $def .= "int $3_free(void);"; 699109998Smarkm $def .= "int $3_new(void);"; 700109998Smarkm # Variant for platforms that do not 701109998Smarkm # have to access globale variables 702109998Smarkm # in shared libraries through functions 703109998Smarkm $def .= 704109998Smarkm "#INFO:" 705109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 706109998Smarkm .join(',',@current_algorithms).";"; 707109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 708109998Smarkm $def .= 709109998Smarkm "#INFO:" 710109998Smarkm .join(',',@current_platforms).":" 711109998Smarkm .join(',',@current_algorithms).";"; 712109998Smarkm # Variant for platforms that have to 713109998Smarkm # access globale variables in shared 714109998Smarkm # libraries through functions 715109998Smarkm &$make_variant("$2_it","$2_it", 716109998Smarkm "EXPORT_VAR_AS_FUNCTION", 717109998Smarkm "FUNCTION"); 718109998Smarkm next; 719109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ || 720109998Smarkm /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) { 721109998Smarkm $def .= "int d2i_$1(void);"; 722109998Smarkm $def .= "int i2d_$1(void);"; 723109998Smarkm $def .= "int $1_free(void);"; 724109998Smarkm $def .= "int $1_new(void);"; 725109998Smarkm # Variant for platforms that do not 726109998Smarkm # have to access globale variables 727109998Smarkm # in shared libraries through functions 728109998Smarkm $def .= 729109998Smarkm "#INFO:" 730109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 731109998Smarkm .join(',',@current_algorithms).";"; 732109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 733109998Smarkm $def .= 734109998Smarkm "#INFO:" 735109998Smarkm .join(',',@current_platforms).":" 736109998Smarkm .join(',',@current_algorithms).";"; 737109998Smarkm # Variant for platforms that have to 738109998Smarkm # access globale variables in shared 739109998Smarkm # libraries through functions 740109998Smarkm &$make_variant("$1_it","$1_it", 741109998Smarkm "EXPORT_VAR_AS_FUNCTION", 742109998Smarkm "FUNCTION"); 743109998Smarkm next; 744109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 745109998Smarkm $def .= "int d2i_$2(void);"; 746109998Smarkm $def .= "int i2d_$2(void);"; 747109998Smarkm # Variant for platforms that do not 748109998Smarkm # have to access globale variables 749109998Smarkm # in shared libraries through functions 750109998Smarkm $def .= 751109998Smarkm "#INFO:" 752109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 753109998Smarkm .join(',',@current_algorithms).";"; 754109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 755109998Smarkm $def .= 756109998Smarkm "#INFO:" 757109998Smarkm .join(',',@current_platforms).":" 758109998Smarkm .join(',',@current_algorithms).";"; 759109998Smarkm # Variant for platforms that have to 760109998Smarkm # access globale variables in shared 761109998Smarkm # libraries through functions 762109998Smarkm &$make_variant("$2_it","$2_it", 763109998Smarkm "EXPORT_VAR_AS_FUNCTION", 764109998Smarkm "FUNCTION"); 765109998Smarkm next; 766160814Ssimon } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) { 767160814Ssimon $def .= "int $1_free(void);"; 768160814Ssimon $def .= "int $1_new(void);"; 769160814Ssimon next; 770109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 771109998Smarkm $def .= "int d2i_$2(void);"; 772109998Smarkm $def .= "int i2d_$2(void);"; 773109998Smarkm $def .= "int $2_free(void);"; 774109998Smarkm $def .= "int $2_new(void);"; 775109998Smarkm # Variant for platforms that do not 776109998Smarkm # have to access globale variables 777109998Smarkm # in shared libraries through functions 778109998Smarkm $def .= 779109998Smarkm "#INFO:" 780109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 781109998Smarkm .join(',',@current_algorithms).";"; 782109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 783109998Smarkm $def .= 784109998Smarkm "#INFO:" 785109998Smarkm .join(',',@current_platforms).":" 786109998Smarkm .join(',',@current_algorithms).";"; 787109998Smarkm # Variant for platforms that have to 788109998Smarkm # access globale variables in shared 789109998Smarkm # libraries through functions 790109998Smarkm &$make_variant("$2_it","$2_it", 791109998Smarkm "EXPORT_VAR_AS_FUNCTION", 792109998Smarkm "FUNCTION"); 793109998Smarkm next; 794109998Smarkm } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) { 795109998Smarkm # Variant for platforms that do not 796109998Smarkm # have to access globale variables 797109998Smarkm # in shared libraries through functions 798109998Smarkm $def .= 799109998Smarkm "#INFO:" 800109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 801109998Smarkm .join(',',@current_algorithms).";"; 802109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 803109998Smarkm $def .= 804109998Smarkm "#INFO:" 805109998Smarkm .join(',',@current_platforms).":" 806109998Smarkm .join(',',@current_algorithms).";"; 807109998Smarkm # Variant for platforms that have to 808109998Smarkm # access globale variables in shared 809109998Smarkm # libraries through functions 810109998Smarkm &$make_variant("$1_it","$1_it", 811109998Smarkm "EXPORT_VAR_AS_FUNCTION", 812109998Smarkm "FUNCTION"); 813109998Smarkm next; 814160814Ssimon } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) { 815160814Ssimon $def .= "int i2d_$1_NDEF(void);"; 816109998Smarkm } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { 817109998Smarkm next; 818160814Ssimon } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) { 819160814Ssimon $def .= "int $1_print_ctx(void);"; 820160814Ssimon next; 821160814Ssimon } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 822160814Ssimon $def .= "int $2_print_ctx(void);"; 823160814Ssimon next; 824109998Smarkm } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) { 825109998Smarkm next; 826109998Smarkm } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || 827160814Ssimon /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ || 828160814Ssimon /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) { 829109998Smarkm # Things not in Win16 830109998Smarkm $def .= 831109998Smarkm "#INFO:" 832109998Smarkm .join(',',"!WIN16",@current_platforms).":" 833109998Smarkm .join(',',@current_algorithms).";"; 834109998Smarkm $def .= "int PEM_read_$1(void);"; 835109998Smarkm $def .= "int PEM_write_$1(void);"; 836109998Smarkm $def .= 837109998Smarkm "#INFO:" 838109998Smarkm .join(',',@current_platforms).":" 839109998Smarkm .join(',',@current_algorithms).";"; 840109998Smarkm # Things that are everywhere 841109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 842109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 843109998Smarkm next; 844109998Smarkm } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ || 845109998Smarkm /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) { 846109998Smarkm # Things not in Win16 847109998Smarkm $def .= 848109998Smarkm "#INFO:" 849109998Smarkm .join(',',"!WIN16",@current_platforms).":" 850109998Smarkm .join(',',@current_algorithms).";"; 851109998Smarkm $def .= "int PEM_write_$1(void);"; 852109998Smarkm $def .= 853109998Smarkm "#INFO:" 854109998Smarkm .join(',',@current_platforms).":" 855109998Smarkm .join(',',@current_algorithms).";"; 856109998Smarkm # Things that are everywhere 857109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 858109998Smarkm next; 859109998Smarkm } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ || 860109998Smarkm /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) { 861109998Smarkm # Things not in Win16 862109998Smarkm $def .= 863109998Smarkm "#INFO:" 864109998Smarkm .join(',',"!WIN16",@current_platforms).":" 865109998Smarkm .join(',',@current_algorithms).";"; 866109998Smarkm $def .= "int PEM_read_$1(void);"; 867109998Smarkm $def .= 868109998Smarkm "#INFO:" 869109998Smarkm .join(',',@current_platforms).":" 870109998Smarkm .join(',',@current_algorithms).";"; 871109998Smarkm # Things that are everywhere 872109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 873109998Smarkm next; 874109998Smarkm } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 875109998Smarkm # Variant for platforms that do not 876109998Smarkm # have to access globale variables 877109998Smarkm # in shared libraries through functions 878109998Smarkm $def .= 879109998Smarkm "#INFO:" 880109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 881109998Smarkm .join(',',@current_algorithms).";"; 882109998Smarkm $def .= "OPENSSL_EXTERN int _shadow_$2;"; 883109998Smarkm $def .= 884109998Smarkm "#INFO:" 885109998Smarkm .join(',',@current_platforms).":" 886109998Smarkm .join(',',@current_algorithms).";"; 887109998Smarkm # Variant for platforms that have to 888109998Smarkm # access globale variables in shared 889109998Smarkm # libraries through functions 890109998Smarkm &$make_variant("_shadow_$2","_shadow_$2", 891109998Smarkm "EXPORT_VAR_AS_FUNCTION", 892109998Smarkm "FUNCTION"); 893109998Smarkm } elsif ($tag{'CONST_STRICT'} != 1) { 89468651Skris if (/\{|\/\*|\([^\)]*$/) { 89555714Skris $line = $_; 89655714Skris } else { 89755714Skris $def .= $_; 89855714Skris } 89955714Skris } 90055714Skris } 901109998Smarkm } 90255714Skris close(IN); 90355714Skris 904160814Ssimon my $algs; 90568651Skris my $plays; 90668651Skris 907109998Smarkm print STDERR "DEBUG: postprocessing ----------\n" if $debug; 90855714Skris foreach (split /;/, $def) { 90968651Skris my $s; my $k = "FUNCTION"; my $p; my $a; 91055714Skris s/^[\n\s]*//g; 91155714Skris s/[\n\s]*$//g; 91268651Skris next if(/\#undef/); 91355714Skris next if(/typedef\W/); 91468651Skris next if(/\#define/); 91568651Skris 916160814Ssimon # Reduce argument lists to empty () 917160814Ssimon # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {} 918160814Ssimon while(/\(.*\)/s) { 919160814Ssimon s/\([^\(\)]+\)/\{\}/gs; 920160814Ssimon s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f 921160814Ssimon } 922160814Ssimon # pretend as we didn't use curly braces: {} -> () 923160814Ssimon s/\{\}/\(\)/gs; 924160814Ssimon 925160814Ssimon s/STACK_OF\(\)/void/gs; 926238405Sjkim s/LHASH_OF\(\)/void/gs; 927160814Ssimon 928109998Smarkm print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug; 92968651Skris if (/^\#INFO:([^:]*):(.*)$/) { 93068651Skris $plats = $1; 93168651Skris $algs = $2; 932109998Smarkm print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug; 93368651Skris next; 934109998Smarkm } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) { 93568651Skris $s = $1; 93668651Skris $k = "VARIABLE"; 937109998Smarkm print STDERR "DEBUG: found external variable $s\n" if $debug; 938160814Ssimon } elsif (/TYPEDEF_\w+_OF/s) { 93955714Skris next; 940160814Ssimon } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is 941160814Ssimon $s = $1; # a function name! 942109998Smarkm print STDERR "DEBUG: found function $s\n" if $debug; 94355714Skris } elsif (/\(/ and not (/=/)) { 94455714Skris print STDERR "File $file: cannot parse: $_;\n"; 94568651Skris next; 94668651Skris } else { 94768651Skris next; 94855714Skris } 94968651Skris 95068651Skris $syms{$s} = 1; 95168651Skris $kind{$s} = $k; 95268651Skris 95368651Skris $p = $plats; 95468651Skris $a = $algs; 95568651Skris $a .= ",BF" if($s =~ /EVP_bf/); 95668651Skris $a .= ",CAST" if($s =~ /EVP_cast/); 95768651Skris $a .= ",DES" if($s =~ /EVP_des/); 95868651Skris $a .= ",DSA" if($s =~ /EVP_dss/); 95968651Skris $a .= ",IDEA" if($s =~ /EVP_idea/); 96068651Skris $a .= ",MD2" if($s =~ /EVP_md2/); 96168651Skris $a .= ",MD4" if($s =~ /EVP_md4/); 96268651Skris $a .= ",MD5" if($s =~ /EVP_md5/); 96368651Skris $a .= ",RC2" if($s =~ /EVP_rc2/); 96468651Skris $a .= ",RC4" if($s =~ /EVP_rc4/); 96568651Skris $a .= ",RC5" if($s =~ /EVP_rc5/); 96668651Skris $a .= ",RIPEMD" if($s =~ /EVP_ripemd/); 96768651Skris $a .= ",SHA" if($s =~ /EVP_sha/); 96868651Skris $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/); 96968651Skris $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); 97068651Skris $a .= ",RSA" if($s =~ /RSAPrivateKey/); 97168651Skris $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); 97268651Skris 973109998Smarkm $platform{$s} = 974109998Smarkm &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p); 97568651Skris $algorithm{$s} .= ','.$a; 97668651Skris 977109998Smarkm if (defined($variant{$s})) { 978109998Smarkm foreach $v (split /;/,$variant{$s}) { 979109998Smarkm (my $r, my $p, my $k) = split(/:/,$v); 980109998Smarkm my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p); 981109998Smarkm $syms{$r} = 1; 982109998Smarkm if (!defined($k)) { $k = $kind{$s}; } 983109998Smarkm $kind{$r} = $k."(".$s.")"; 984109998Smarkm $algorithm{$r} = $algorithm{$s}; 985109998Smarkm $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p); 986109998Smarkm $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip); 987109998Smarkm print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug; 988109998Smarkm } 98968651Skris } 990109998Smarkm print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug; 99155714Skris } 99255714Skris } 99355714Skris 99468651Skris # Prune the returned symbols 99555714Skris 99668651Skris delete $syms{"bn_dump1"}; 99768651Skris $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh"; 99868651Skris 999109998Smarkm $platform{"PEM_read_NS_CERT_SEQ"} = "VMS"; 1000109998Smarkm $platform{"PEM_write_NS_CERT_SEQ"} = "VMS"; 1001109998Smarkm $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS"; 1002109998Smarkm $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS"; 1003205128Ssimon $platform{"EVP_sha384"} = "!VMSVAX"; 1004205128Ssimon $platform{"EVP_sha512"} = "!VMSVAX"; 1005205128Ssimon $platform{"SHA384_Init"} = "!VMSVAX"; 1006205128Ssimon $platform{"SHA384_Transform"} = "!VMSVAX"; 1007205128Ssimon $platform{"SHA384_Update"} = "!VMSVAX"; 1008205128Ssimon $platform{"SHA384_Final"} = "!VMSVAX"; 1009205128Ssimon $platform{"SHA384"} = "!VMSVAX"; 1010205128Ssimon $platform{"SHA512_Init"} = "!VMSVAX"; 1011205128Ssimon $platform{"SHA512_Transform"} = "!VMSVAX"; 1012205128Ssimon $platform{"SHA512_Update"} = "!VMSVAX"; 1013205128Ssimon $platform{"SHA512_Final"} = "!VMSVAX"; 1014205128Ssimon $platform{"SHA512"} = "!VMSVAX"; 1015238405Sjkim $platform{"WHIRLPOOL_Init"} = "!VMSVAX"; 1016238405Sjkim $platform{"WHIRLPOOL"} = "!VMSVAX"; 1017238405Sjkim $platform{"WHIRLPOOL_BitUpdate"} = "!VMSVAX"; 1018238405Sjkim $platform{"EVP_whirlpool"} = "!VMSVAX"; 1019238405Sjkim $platform{"WHIRLPOOL_Final"} = "!VMSVAX"; 1020238405Sjkim $platform{"WHIRLPOOL_Update"} = "!VMSVAX"; 1021205128Ssimon 1022215697Ssimon 102368651Skris # Info we know about 102468651Skris 102568651Skris push @ret, map { $_."\\".&info_string($_,"EXIST", 102668651Skris $platform{$_}, 102768651Skris $kind{$_}, 102868651Skris $algorithm{$_}) } keys %syms; 102968651Skris 1030109998Smarkm if (keys %unknown_algorithms) { 1031109998Smarkm print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n"; 1032109998Smarkm print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n"; 1033109998Smarkm } 103468651Skris return(@ret); 103568651Skris} 103668651Skris 1037109998Smarkm# Param: string of comma-separated platform-specs. 1038109998Smarkmsub reduce_platforms 1039109998Smarkm{ 1040109998Smarkm my ($platforms) = @_; 104168651Skris my $pl = defined($platforms) ? $platforms : ""; 104268651Skris my %p = map { $_ => 0 } split /,/, $pl; 104368651Skris my $ret; 104468651Skris 1045109998Smarkm print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n" 1046109998Smarkm if $debug; 104768651Skris # We do this, because if there's code like the following, it really 104868651Skris # means the function exists in all cases and should therefore be 104968651Skris # everywhere. By increasing and decreasing, we may attain 0: 105068651Skris # 105168651Skris # ifndef WIN16 105268651Skris # int foo(); 105368651Skris # else 105468651Skris # int _fat foo(); 105568651Skris # endif 105668651Skris foreach $platform (split /,/, $pl) { 105768651Skris if ($platform =~ /^!(.*)$/) { 105868651Skris $p{$1}--; 105968651Skris } else { 106068651Skris $p{$platform}++; 106155714Skris } 106255714Skris } 106368651Skris foreach $platform (keys %p) { 106468651Skris if ($p{$platform} == 0) { delete $p{$platform}; } 106555714Skris } 106655714Skris 106768651Skris delete $p{""}; 1068109998Smarkm 1069109998Smarkm $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p)); 1070109998Smarkm print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n" 1071109998Smarkm if $debug; 1072109998Smarkm return $ret; 1073109998Smarkm} 1074109998Smarkm 1075109998Smarkmsub info_string { 1076109998Smarkm (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_; 1077109998Smarkm 1078109998Smarkm my %a = defined($algorithms) ? 1079109998Smarkm map { $_ => 1 } split /,/, $algorithms : (); 1080109998Smarkm my $k = defined($kind) ? $kind : "FUNCTION"; 1081109998Smarkm my $ret; 1082109998Smarkm my $p = &reduce_platforms($platforms); 1083109998Smarkm 108468651Skris delete $a{""}; 108555714Skris 108668651Skris $ret = $exist; 1087109998Smarkm $ret .= ":".$p; 108868651Skris $ret .= ":".$k; 1089109998Smarkm $ret .= ":".join(',',sort keys %a); 109068651Skris return $ret; 109155714Skris} 109255714Skris 109368651Skrissub maybe_add_info { 109468651Skris (my $name, *nums, my @symbols) = @_; 109568651Skris my $sym; 109668651Skris my $new_info = 0; 1097109998Smarkm my %syms=(); 109868651Skris 109968651Skris print STDERR "Updating $name info\n"; 110068651Skris foreach $sym (@symbols) { 110168651Skris (my $s, my $i) = split /\\/, $sym; 110268651Skris if (defined($nums{$s})) { 1103109998Smarkm $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/; 110468651Skris (my $n, my $dummy) = split /\\/, $nums{$s}; 110568651Skris if (!defined($dummy) || $i ne $dummy) { 110668651Skris $nums{$s} = $n."\\".$i; 110768651Skris $new_info++; 1108109998Smarkm print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug; 110968651Skris } 111068651Skris } 1111109998Smarkm $syms{$s} = 1; 111268651Skris } 1113109998Smarkm 1114109998Smarkm my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums; 1115109998Smarkm foreach $sym (@s) { 1116109998Smarkm (my $n, my $i) = split /\\/, $nums{$sym}; 1117109998Smarkm if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) { 1118109998Smarkm $new_info++; 1119109998Smarkm print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug; 1120109998Smarkm } 1121109998Smarkm } 112268651Skris if ($new_info) { 112368651Skris print STDERR "$new_info old symbols got an info update\n"; 112468651Skris if (!$do_rewrite) { 112568651Skris print STDERR "You should do a rewrite to fix this.\n"; 112668651Skris } 112768651Skris } else { 112868651Skris print STDERR "No old symbols needed info update\n"; 112968651Skris } 113068651Skris} 113168651Skris 1132109998Smarkm# Param: string of comma-separated keywords, each possibly prefixed with a "!" 1133109998Smarkmsub is_valid 1134109998Smarkm{ 1135109998Smarkm my ($keywords_txt,$platforms) = @_; 1136109998Smarkm my (@keywords) = split /,/,$keywords_txt; 1137160814Ssimon my ($falsesum, $truesum) = (0, 1); 1138109998Smarkm 1139109998Smarkm # Param: one keyword 1140109998Smarkm sub recognise 1141109998Smarkm { 1142109998Smarkm my ($keyword,$platforms) = @_; 1143109998Smarkm 1144109998Smarkm if ($platforms) { 1145109998Smarkm # platforms 1146205128Ssimon if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; } 1147205128Ssimon if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; } 1148238405Sjkim if ($keyword eq "VMS" && $VMS) { return 1; } 1149109998Smarkm if ($keyword eq "WIN32" && $W32) { return 1; } 1150109998Smarkm if ($keyword eq "WIN16" && $W16) { return 1; } 1151109998Smarkm if ($keyword eq "WINNT" && $NT) { return 1; } 1152109998Smarkm if ($keyword eq "OS2" && $OS2) { return 1; } 1153109998Smarkm # Special platforms: 1154109998Smarkm # EXPORT_VAR_AS_FUNCTION means that global variables 1155109998Smarkm # will be represented as functions. This currently 1156109998Smarkm # only happens on VMS-VAX. 1157109998Smarkm if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) { 1158109998Smarkm return 1; 1159109998Smarkm } 1160194206Ssimon if ($keyword eq "OPENSSL_FIPS" && $fips) { 1161194206Ssimon return 1; 1162194206Ssimon } 1163194206Ssimon if ($keyword eq "ZLIB" && $zlib) { return 1; } 1164109998Smarkm return 0; 1165109998Smarkm } else { 1166109998Smarkm # algorithms 1167109998Smarkm if ($keyword eq "RC2" && $no_rc2) { return 0; } 1168109998Smarkm if ($keyword eq "RC4" && $no_rc4) { return 0; } 1169109998Smarkm if ($keyword eq "RC5" && $no_rc5) { return 0; } 1170109998Smarkm if ($keyword eq "IDEA" && $no_idea) { return 0; } 1171109998Smarkm if ($keyword eq "DES" && $no_des) { return 0; } 1172109998Smarkm if ($keyword eq "BF" && $no_bf) { return 0; } 1173109998Smarkm if ($keyword eq "CAST" && $no_cast) { return 0; } 1174109998Smarkm if ($keyword eq "MD2" && $no_md2) { return 0; } 1175109998Smarkm if ($keyword eq "MD4" && $no_md4) { return 0; } 1176109998Smarkm if ($keyword eq "MD5" && $no_md5) { return 0; } 1177109998Smarkm if ($keyword eq "SHA" && $no_sha) { return 0; } 1178109998Smarkm if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; } 1179109998Smarkm if ($keyword eq "MDC2" && $no_mdc2) { return 0; } 1180238405Sjkim if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; } 1181109998Smarkm if ($keyword eq "RSA" && $no_rsa) { return 0; } 1182109998Smarkm if ($keyword eq "DSA" && $no_dsa) { return 0; } 1183109998Smarkm if ($keyword eq "DH" && $no_dh) { return 0; } 1184109998Smarkm if ($keyword eq "EC" && $no_ec) { return 0; } 1185160814Ssimon if ($keyword eq "ECDSA" && $no_ecdsa) { return 0; } 1186160814Ssimon if ($keyword eq "ECDH" && $no_ecdh) { return 0; } 1187109998Smarkm if ($keyword eq "HMAC" && $no_hmac) { return 0; } 1188109998Smarkm if ($keyword eq "AES" && $no_aes) { return 0; } 1189162911Ssimon if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; } 1190194206Ssimon if ($keyword eq "SEED" && $no_seed) { return 0; } 1191109998Smarkm if ($keyword eq "EVP" && $no_evp) { return 0; } 1192109998Smarkm if ($keyword eq "LHASH" && $no_lhash) { return 0; } 1193109998Smarkm if ($keyword eq "STACK" && $no_stack) { return 0; } 1194109998Smarkm if ($keyword eq "ERR" && $no_err) { return 0; } 1195109998Smarkm if ($keyword eq "BUFFER" && $no_buffer) { return 0; } 1196109998Smarkm if ($keyword eq "BIO" && $no_bio) { return 0; } 1197109998Smarkm if ($keyword eq "COMP" && $no_comp) { return 0; } 1198109998Smarkm if ($keyword eq "DSO" && $no_dso) { return 0; } 1199109998Smarkm if ($keyword eq "KRB5" && $no_krb5) { return 0; } 1200111147Snectar if ($keyword eq "ENGINE" && $no_engine) { return 0; } 1201111147Snectar if ($keyword eq "HW" && $no_hw) { return 0; } 1202109998Smarkm if ($keyword eq "FP_API" && $no_fp_api) { return 0; } 1203160814Ssimon if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; } 1204160814Ssimon if ($keyword eq "GMP" && $no_gmp) { return 0; } 1205167612Ssimon if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; } 1206194206Ssimon if ($keyword eq "TLSEXT" && $no_tlsext) { return 0; } 1207238405Sjkim if ($keyword eq "PSK" && $no_psk) { return 0; } 1208194206Ssimon if ($keyword eq "CMS" && $no_cms) { return 0; } 1209238405Sjkim if ($keyword eq "EC2M" && $no_ec2m) { return 0; } 1210238405Sjkim if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; } 1211238405Sjkim if ($keyword eq "EC_NISTP_64_GCC_128" && $no_nistp_gcc) 1212238405Sjkim { return 0; } 1213238405Sjkim if ($keyword eq "SSL2" && $no_ssl2) { return 0; } 1214276861Sjkim if ($keyword eq "SSL3_METHOD" && $no_ssl3_method) { return 0; } 1215194206Ssimon if ($keyword eq "CAPIENG" && $no_capieng) { return 0; } 1216194206Ssimon if ($keyword eq "JPAKE" && $no_jpake) { return 0; } 1217238405Sjkim if ($keyword eq "SRP" && $no_srp) { return 0; } 1218238405Sjkim if ($keyword eq "SCTP" && $no_sctp) { return 0; } 1219273144Sjkim if ($keyword eq "SRTP" && $no_srtp) { return 0; } 1220269682Sjkim if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; } 1221160814Ssimon if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; } 1222109998Smarkm 1223109998Smarkm # Nothing recognise as true 1224109998Smarkm return 1; 1225109998Smarkm } 1226109998Smarkm } 1227109998Smarkm 1228109998Smarkm foreach $k (@keywords) { 1229109998Smarkm if ($k =~ /^!(.*)$/) { 1230109998Smarkm $falsesum += &recognise($1,$platforms); 1231109998Smarkm } else { 1232160814Ssimon $truesum *= &recognise($k,$platforms); 1233109998Smarkm } 1234109998Smarkm } 1235109998Smarkm print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug; 1236109998Smarkm return (!$falsesum) && $truesum; 1237109998Smarkm} 1238109998Smarkm 123959191Skrissub print_test_file 124059191Skris{ 1241109998Smarkm (*OUT,my $name,*nums,my $testall,my @symbols)=@_; 124259191Skris my $n = 1; my @e; my @r; 124368651Skris my $sym; my $prev = ""; my $prefSSLeay; 124459191Skris 1245109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 1246109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 124768651Skris @symbols=((sort @e),(sort @r)); 124859191Skris 124968651Skris foreach $sym (@symbols) { 125068651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1251109998Smarkm my $v = 0; 1252109998Smarkm $v = 1 if $i=~ /^.*?:.*?:VARIABLE/; 1253109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1254109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1255109998Smarkm if (!defined($nums{$s})) { 1256109998Smarkm print STDERR "Warning: $s does not have a number assigned\n" 1257109998Smarkm if(!$do_update); 1258109998Smarkm } elsif (is_valid($p,1) && is_valid($a,0)) { 1259109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1260109998Smarkm if ($prev eq $s2) { 1261109998Smarkm print OUT "\t/* The following has already appeared previously */\n"; 1262109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1263109998Smarkm } 1264109998Smarkm $prev = $s2; # To warn about duplicates... 1265109998Smarkm 1266109998Smarkm ($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/); 1267109998Smarkm if ($v) { 1268109998Smarkm print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n"; 126968651Skris } else { 1270109998Smarkm print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n"; 127168651Skris } 127259191Skris } 127359191Skris } 127459191Skris} 127559191Skris 1276127128Snectarsub get_version { 1277127128Snectar local *MF; 1278127128Snectar my $v = '?'; 1279142425Snectar open MF, 'Makefile' or return $v; 1280127128Snectar while (<MF>) { 1281127128Snectar $v = $1, last if /^VERSION=(.*?)\s*$/; 1282127128Snectar } 1283127128Snectar close MF; 1284127128Snectar return $v; 1285127128Snectar} 1286127128Snectar 128755714Skrissub print_def_file 128855714Skris{ 128968651Skris (*OUT,my $name,*nums,my @symbols)=@_; 1290109998Smarkm my $n = 1; my @e; my @r; my @v; my $prev=""; 1291109998Smarkm my $liboptions=""; 1292127128Snectar my $libname = $name; 1293127128Snectar my $http_vendor = 'www.openssl.org/'; 1294127128Snectar my $version = get_version(); 1295127128Snectar my $what = "OpenSSL: implementation of Secure Socket Layer"; 1296127128Snectar my $description = "$what $version, $name - http://$http_vendor"; 129755714Skris 129855714Skris if ($W32) 1299127128Snectar { $libname.="32"; } 1300109998Smarkm elsif ($W16) 1301127128Snectar { $libname.="16"; } 1302109998Smarkm elsif ($OS2) 1303127128Snectar { # DLL names should not clash on the whole system. 1304127128Snectar # However, they should not have any particular relationship 1305127128Snectar # to the name of the static library. Chose descriptive names 1306127128Snectar # (must be at most 8 chars). 1307127128Snectar my %translate = (ssl => 'open_ssl', crypto => 'cryptssl'); 1308127128Snectar $libname = $translate{$name} || $name; 1309127128Snectar $liboptions = <<EOO; 1310127128SnectarINITINSTANCE 1311127128SnectarDATA MULTIPLE NONSHARED 1312127128SnectarEOO 1313127128Snectar # Vendor field can't contain colon, drat; so we omit http:// 1314127128Snectar $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd"; 1315127128Snectar } 131655714Skris 131755714Skris print OUT <<"EOF"; 131855714Skris; 131955714Skris; Definition file for the DLL version of the $name library from OpenSSL 132055714Skris; 132155714Skris 1322127128SnectarLIBRARY $libname $liboptions 132355714Skris 132455714SkrisEOF 132555714Skris 1326109998Smarkm if ($W16) { 132755714Skris print <<"EOF"; 132855714SkrisCODE PRELOAD MOVEABLE 132955714SkrisDATA PRELOAD MOVEABLE SINGLE 133055714Skris 133155714SkrisEXETYPE WINDOWS 133255714Skris 133355714SkrisHEAPSIZE 4096 133455714SkrisSTACKSIZE 8192 133555714Skris 133655714SkrisEOF 133755714Skris } 133855714Skris 133955714Skris print "EXPORTS\n"; 134055714Skris 1341109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1342109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1343109998Smarkm (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols); 1344109998Smarkm @symbols=((sort @e),(sort @r), (sort @v)); 134555714Skris 134655714Skris 134768651Skris foreach $sym (@symbols) { 134868651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1349109998Smarkm my $v = 0; 1350109998Smarkm $v = 1 if $i =~ /^.*?:.*?:VARIABLE/; 135168651Skris if (!defined($nums{$s})) { 135268651Skris printf STDERR "Warning: $s does not have a number assigned\n" 1353109998Smarkm if(!$do_update); 135455714Skris } else { 1355109998Smarkm (my $n, my $dummy) = split /\\/, $nums{$s}; 135668651Skris my %pf = (); 1357109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1358109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1359109998Smarkm if (is_valid($p,1) && is_valid($a,0)) { 1360109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1361109998Smarkm if ($prev eq $s2) { 1362109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1363109998Smarkm } 1364109998Smarkm $prev = $s2; # To warn about duplicates... 1365109998Smarkm if($v && !$OS2) { 1366109998Smarkm printf OUT " %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n; 1367109998Smarkm } else { 1368109998Smarkm printf OUT " %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n; 1369109998Smarkm } 137068651Skris } 137155714Skris } 137255714Skris } 137355714Skris printf OUT "\n"; 137455714Skris} 137555714Skris 137655714Skrissub load_numbers 137755714Skris{ 137855714Skris my($name)=@_; 137955714Skris my(@a,%ret); 138055714Skris 138155714Skris $max_num = 0; 138268651Skris $num_noinfo = 0; 138368651Skris $prev = ""; 1384109998Smarkm $prev_cnt = 0; 138555714Skris 138655714Skris open(IN,"<$name") || die "unable to open $name:$!\n"; 138755714Skris while (<IN>) { 138855714Skris chop; 138955714Skris s/#.*$//; 139055714Skris next if /^\s*$/; 139155714Skris @a=split; 139268651Skris if (defined $ret{$a[0]}) { 1393109998Smarkm # This is actually perfectly OK 1394109998Smarkm #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n"; 139568651Skris } 139668651Skris if ($max_num > $a[1]) { 139768651Skris print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n"; 139868651Skris } 1399109998Smarkm elsif ($max_num == $a[1]) { 140068651Skris # This is actually perfectly OK 140168651Skris #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n"; 1402109998Smarkm if ($a[0] eq $prev) { 1403109998Smarkm $prev_cnt++; 1404109998Smarkm $a[0] .= "{$prev_cnt}"; 1405109998Smarkm } 140668651Skris } 1407109998Smarkm else { 1408109998Smarkm $prev_cnt = 0; 1409109998Smarkm } 141068651Skris if ($#a < 2) { 141168651Skris # Existence will be proven later, in do_defs 141268651Skris $ret{$a[0]}=$a[1]; 141368651Skris $num_noinfo++; 141468651Skris } else { 141568651Skris $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker 141668651Skris } 141755714Skris $max_num = $a[1] if $a[1] > $max_num; 141868651Skris $prev=$a[0]; 141955714Skris } 142068651Skris if ($num_noinfo) { 142168651Skris print STDERR "Warning: $num_noinfo symbols were without info."; 142268651Skris if ($do_rewrite) { 142368651Skris printf STDERR " The rewrite will fix this.\n"; 142468651Skris } else { 142568651Skris printf STDERR " You should do a rewrite to fix this.\n"; 142668651Skris } 142768651Skris } 142855714Skris close(IN); 142955714Skris return(%ret); 143055714Skris} 143155714Skris 143268651Skrissub parse_number 143368651Skris{ 143468651Skris (my $str, my $what) = @_; 143568651Skris (my $n, my $i) = split(/\\/,$str); 143668651Skris if ($what eq "n") { 143768651Skris return $n; 143868651Skris } else { 143968651Skris return $i; 144068651Skris } 144168651Skris} 144268651Skris 144368651Skrissub rewrite_numbers 144468651Skris{ 144568651Skris (*OUT,$name,*nums,@symbols)=@_; 144668651Skris my $thing; 144768651Skris 144868651Skris print STDERR "Rewriting $name\n"; 144968651Skris 1450109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 145168651Skris my $r; my %r; my %rsyms; 145268651Skris foreach $r (@r) { 145368651Skris (my $s, my $i) = split /\\/, $r; 145468651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 145568651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 145668651Skris $r{$a} = $s."\\".$i; 145768651Skris $rsyms{$s} = 1; 145868651Skris } 145968651Skris 1460109998Smarkm my %syms = (); 1461109998Smarkm foreach $_ (@symbols) { 1462109998Smarkm (my $n, my $i) = split /\\/; 1463109998Smarkm $syms{$n} = 1; 1464109998Smarkm } 1465109998Smarkm 1466109998Smarkm my @s=sort { 1467109998Smarkm &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") 1468109998Smarkm || $a cmp $b 1469109998Smarkm } keys %nums; 147068651Skris foreach $sym (@s) { 147168651Skris (my $n, my $i) = split /\\/, $nums{$sym}; 147268651Skris next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/; 147368651Skris next if defined($rsyms{$sym}); 1474109998Smarkm print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug; 1475109998Smarkm $i="NOEXIST::FUNCTION:" 1476109998Smarkm if !defined($i) || $i eq "" || !defined($syms{$sym}); 1477109998Smarkm my $s2 = $sym; 1478109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1479109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 148068651Skris if (exists $r{$sym}) { 148168651Skris (my $s, $i) = split /\\/,$r{$sym}; 1482109998Smarkm my $s2 = $s; 1483109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1484109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 148568651Skris } 148668651Skris } 148768651Skris} 148868651Skris 148955714Skrissub update_numbers 149055714Skris{ 149168651Skris (*OUT,$name,*nums,my $start_num, my @symbols)=@_; 149268651Skris my $new_syms = 0; 149368651Skris 149468651Skris print STDERR "Updating $name numbers\n"; 149568651Skris 1496109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 149768651Skris my $r; my %r; my %rsyms; 149868651Skris foreach $r (@r) { 149968651Skris (my $s, my $i) = split /\\/, $r; 150068651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 150168651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 150268651Skris $r{$a} = $s."\\".$i; 150368651Skris $rsyms{$s} = 1; 150468651Skris } 150568651Skris 150668651Skris foreach $sym (@symbols) { 150768651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 150868651Skris next if $i =~ /^.*?:.*?:\w+\(\w+\)/; 150968651Skris next if defined($rsyms{$sym}); 151068651Skris die "ERROR: Symbol $sym had no info attached to it." 151168651Skris if $i eq ""; 151268651Skris if (!exists $nums{$s}) { 151368651Skris $new_syms++; 1514109998Smarkm my $s2 = $s; 1515109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1516109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i; 151768651Skris if (exists $r{$s}) { 151868651Skris ($s, $i) = split /\\/,$r{$s}; 1519109998Smarkm $s =~ s/\{[0-9]+\}$//; 1520109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i; 152168651Skris } 152255714Skris } 152355714Skris } 152468651Skris if($new_syms) { 152568651Skris print STDERR "$new_syms New symbols added\n"; 152655714Skris } else { 152768651Skris print STDERR "No New symbols Added\n"; 152855714Skris } 152955714Skris} 153068651Skris 153168651Skrissub check_existing 153268651Skris{ 153368651Skris (*nums, my @symbols)=@_; 153468651Skris my %existing; my @remaining; 153568651Skris @remaining=(); 153668651Skris foreach $sym (@symbols) { 153768651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 153868651Skris $existing{$s}=1; 153968651Skris } 154068651Skris foreach $sym (keys %nums) { 154168651Skris if (!exists $existing{$sym}) { 154268651Skris push @remaining, $sym; 154368651Skris } 154468651Skris } 154568651Skris if(@remaining) { 154668651Skris print STDERR "The following symbols do not seem to exist:\n"; 154768651Skris foreach $sym (@remaining) { 154868651Skris print STDERR "\t",$sym,"\n"; 154968651Skris } 155068651Skris } 155168651Skris} 155268651Skris 1553