mkdef.pl revision 269682
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", 110194206Ssimon # JPAKE 111194206Ssimon "JPAKE", 112238405Sjkim # NEXTPROTONEG 113238405Sjkim "NEXTPROTONEG", 114160814Ssimon # Deprecated functions 115238405Sjkim "DEPRECATED", 116238405Sjkim # Hide SSL internals 117238405Sjkim "SSL_INTERN", 118238405Sjkim # SCTP 119269682Sjkim "SCTP", 120269682Sjkim # Unit testing 121269682Sjkim "UNIT_TEST"); 12268651Skris 12359191Skrismy $options=""; 124142425Snectaropen(IN,"<Makefile") || die "unable to open Makefile!\n"; 12555714Skriswhile(<IN>) { 12655714Skris $options=$1 if (/^OPTIONS=(.*)$/); 12755714Skris} 12855714Skrisclose(IN); 12955714Skris 13059191Skris# The following ciphers may be excluded (by Configure). This means functions 13159191Skris# defined with ifndef(NO_XXX) are not included in the .def file, and everything 13259191Skris# in directory xxx is ignored. 13359191Skrismy $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf; 134238405Sjkimmy $no_cast; my $no_whirlpool; my $no_camellia; my $no_seed; 13568651Skrismy $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2; 136109998Smarkmmy $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5; 137238405Sjkimmy $no_ec; my $no_ecdsa; my $no_ecdh; my $no_engine; my $no_hw; 138238405Sjkimmy $no_fp_api; my $no_static_engine=1; my $no_gmp; my $no_deprecated; 139238405Sjkimmy $no_rfc3779; my $no_psk; my $no_tlsext; my $no_cms; my $no_capieng; 140238405Sjkimmy $no_jpake; my $no_srp; my $no_ssl2; my $no_ec2m; my $no_nistp_gcc; 141238405Sjkimmy $no_nextprotoneg; my $no_sctp; 142269682Sjkimmy $no_unit_test; 143238405Sjkim 144194206Ssimonmy $fips; 14559191Skris 146238405Sjkimmy $zlib; 147160814Ssimon 148238405Sjkim 14955714Skrisforeach (@ARGV, split(/ /, $options)) 15055714Skris { 151109998Smarkm $debug=1 if $_ eq "debug"; 15255714Skris $W32=1 if $_ eq "32"; 15368651Skris $W16=1 if $_ eq "16"; 15455714Skris if($_ eq "NT") { 15555714Skris $W32 = 1; 15655714Skris $NT = 1; 15755714Skris } 158109998Smarkm if ($_ eq "VMS-VAX") { 159109998Smarkm $VMS=1; 160109998Smarkm $VMSVAX=1; 161109998Smarkm } 162205128Ssimon if ($_ eq "VMS-NonVAX") { 163109998Smarkm $VMS=1; 164205128Ssimon $VMSNonVAX=1; 165109998Smarkm } 16668651Skris $VMS=1 if $_ eq "VMS"; 167109998Smarkm $OS2=1 if $_ eq "OS2"; 168194206Ssimon $fips=1 if /^fips/; 169238405Sjkim if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic" 170238405Sjkim || $_ eq "enable-zlib-dynamic") { 171238405Sjkim $zlib = 1; 172194206Ssimon } 173194206Ssimon 17455714Skris $do_ssl=1 if $_ eq "ssleay"; 175109998Smarkm if ($_ eq "ssl") { 176109998Smarkm $do_ssl=1; 177109998Smarkm $libname=$_ 178109998Smarkm } 17955714Skris $do_crypto=1 if $_ eq "libeay"; 180109998Smarkm if ($_ eq "crypto") { 181109998Smarkm $do_crypto=1; 182109998Smarkm $libname=$_; 183109998Smarkm } 184160814Ssimon $no_static_engine=1 if $_ eq "no-static-engine"; 185160814Ssimon $no_static_engine=0 if $_ eq "enable-static-engine"; 18655714Skris $do_update=1 if $_ eq "update"; 18768651Skris $do_rewrite=1 if $_ eq "rewrite"; 18859191Skris $do_ctest=1 if $_ eq "ctest"; 18968651Skris $do_ctestall=1 if $_ eq "ctestall"; 190109998Smarkm $do_checkexist=1 if $_ eq "exist"; 19168651Skris #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK"; 19255714Skris 19355714Skris if (/^no-rc2$/) { $no_rc2=1; } 19455714Skris elsif (/^no-rc4$/) { $no_rc4=1; } 19555714Skris elsif (/^no-rc5$/) { $no_rc5=1; } 19655714Skris elsif (/^no-idea$/) { $no_idea=1; } 19772613Skris elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; } 19855714Skris elsif (/^no-bf$/) { $no_bf=1; } 19955714Skris elsif (/^no-cast$/) { $no_cast=1; } 200238405Sjkim elsif (/^no-whirlpool$/) { $no_whirlpool=1; } 20155714Skris elsif (/^no-md2$/) { $no_md2=1; } 20268651Skris elsif (/^no-md4$/) { $no_md4=1; } 20355714Skris elsif (/^no-md5$/) { $no_md5=1; } 20455714Skris elsif (/^no-sha$/) { $no_sha=1; } 20555714Skris elsif (/^no-ripemd$/) { $no_ripemd=1; } 20655714Skris elsif (/^no-mdc2$/) { $no_mdc2=1; } 20755714Skris elsif (/^no-rsa$/) { $no_rsa=1; } 20855714Skris elsif (/^no-dsa$/) { $no_dsa=1; } 20955714Skris elsif (/^no-dh$/) { $no_dh=1; } 210109998Smarkm elsif (/^no-ec$/) { $no_ec=1; } 211160814Ssimon elsif (/^no-ecdsa$/) { $no_ecdsa=1; } 212160814Ssimon elsif (/^no-ecdh$/) { $no_ecdh=1; } 21355714Skris elsif (/^no-hmac$/) { $no_hmac=1; } 214109998Smarkm elsif (/^no-aes$/) { $no_aes=1; } 215162911Ssimon elsif (/^no-camellia$/) { $no_camellia=1; } 216194206Ssimon elsif (/^no-seed$/) { $no_seed=1; } 217109998Smarkm elsif (/^no-evp$/) { $no_evp=1; } 218109998Smarkm elsif (/^no-lhash$/) { $no_lhash=1; } 219109998Smarkm elsif (/^no-stack$/) { $no_stack=1; } 220109998Smarkm elsif (/^no-err$/) { $no_err=1; } 221109998Smarkm elsif (/^no-buffer$/) { $no_buffer=1; } 222109998Smarkm elsif (/^no-bio$/) { $no_bio=1; } 223109998Smarkm #elsif (/^no-locking$/) { $no_locking=1; } 224109998Smarkm elsif (/^no-comp$/) { $no_comp=1; } 225109998Smarkm elsif (/^no-dso$/) { $no_dso=1; } 226109998Smarkm elsif (/^no-krb5$/) { $no_krb5=1; } 227111147Snectar elsif (/^no-engine$/) { $no_engine=1; } 228111147Snectar elsif (/^no-hw$/) { $no_hw=1; } 229160814Ssimon elsif (/^no-gmp$/) { $no_gmp=1; } 230167612Ssimon elsif (/^no-rfc3779$/) { $no_rfc3779=1; } 231194206Ssimon elsif (/^no-tlsext$/) { $no_tlsext=1; } 232194206Ssimon elsif (/^no-cms$/) { $no_cms=1; } 233238405Sjkim elsif (/^no-ec2m$/) { $no_ec2m=1; } 234238405Sjkim elsif (/^no-ec_nistp_64_gcc_128$/) { $no_nistp_gcc=1; } 235238405Sjkim elsif (/^no-nextprotoneg$/) { $no_nextprotoneg=1; } 236238405Sjkim elsif (/^no-ssl2$/) { $no_ssl2=1; } 237194206Ssimon elsif (/^no-capieng$/) { $no_capieng=1; } 238194206Ssimon elsif (/^no-jpake$/) { $no_jpake=1; } 239238405Sjkim elsif (/^no-srp$/) { $no_srp=1; } 240238405Sjkim elsif (/^no-sctp$/) { $no_sctp=1; } 241269682Sjkim elsif (/^no-unit-test$/){ $no_unit_test=1; } 24255714Skris } 24355714Skris 24459191Skris 245109998Smarkmif (!$libname) { 246109998Smarkm if ($do_ssl) { 247109998Smarkm $libname="SSLEAY"; 248109998Smarkm } 249109998Smarkm if ($do_crypto) { 250109998Smarkm $libname="LIBEAY"; 251109998Smarkm } 252109998Smarkm} 253109998Smarkm 25468651Skris# If no platform is given, assume WIN32 255109998Smarkmif ($W32 + $W16 + $VMS + $OS2 == 0) { 25668651Skris $W32 = 1; 25768651Skris} 25868651Skris 25968651Skris# Add extra knowledge 26068651Skrisif ($W16) { 26168651Skris $no_fp_api=1; 26268651Skris} 26368651Skris 26455714Skrisif (!$do_ssl && !$do_crypto) 26555714Skris { 266109998Smarkm print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n"; 26755714Skris exit(1); 26855714Skris } 26955714Skris 27055714Skris%ssl_list=&load_numbers($ssl_num); 27155714Skris$max_ssl = $max_num; 27255714Skris%crypto_list=&load_numbers($crypto_num); 27355714Skris$max_crypto = $max_num; 27455714Skris 27559191Skrismy $ssl="ssl/ssl.h"; 276109998Smarkm$ssl.=" ssl/kssl.h"; 277194206Ssimon$ssl.=" ssl/tls1.h"; 278238405Sjkim$ssl.=" ssl/srtp.h"; 27955714Skris 28059191Skrismy $crypto ="crypto/crypto.h"; 281238405Sjkim$crypto.=" crypto/cryptlib.h"; 282160814Ssimon$crypto.=" crypto/o_dir.h"; 283238405Sjkim$crypto.=" crypto/o_str.h"; 284238405Sjkim$crypto.=" crypto/o_time.h"; 285109998Smarkm$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des; 286109998Smarkm$crypto.=" crypto/idea/idea.h" ; # unless $no_idea; 287109998Smarkm$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4; 288109998Smarkm$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5; 289109998Smarkm$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2; 290109998Smarkm$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf; 291109998Smarkm$crypto.=" crypto/cast/cast.h" ; # unless $no_cast; 292238405Sjkim$crypto.=" crypto/whrlpool/whrlpool.h" ; 293109998Smarkm$crypto.=" crypto/md2/md2.h" ; # unless $no_md2; 294109998Smarkm$crypto.=" crypto/md4/md4.h" ; # unless $no_md4; 295109998Smarkm$crypto.=" crypto/md5/md5.h" ; # unless $no_md5; 296109998Smarkm$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2; 297109998Smarkm$crypto.=" crypto/sha/sha.h" ; # unless $no_sha; 298109998Smarkm$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd; 299109998Smarkm$crypto.=" crypto/aes/aes.h" ; # unless $no_aes; 300162911Ssimon$crypto.=" crypto/camellia/camellia.h" ; # unless $no_camellia; 301194206Ssimon$crypto.=" crypto/seed/seed.h"; # unless $no_seed; 30255714Skris 30355714Skris$crypto.=" crypto/bn/bn.h"; 304109998Smarkm$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa; 305109998Smarkm$crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa; 306109998Smarkm$crypto.=" crypto/dh/dh.h" ; # unless $no_dh; 307109998Smarkm$crypto.=" crypto/ec/ec.h" ; # unless $no_ec; 308160814Ssimon$crypto.=" crypto/ecdsa/ecdsa.h" ; # unless $no_ecdsa; 309160814Ssimon$crypto.=" crypto/ecdh/ecdh.h" ; # unless $no_ecdh; 310109998Smarkm$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac; 311238405Sjkim$crypto.=" crypto/cmac/cmac.h" ; # unless $no_hmac; 31255714Skris 313111147Snectar$crypto.=" crypto/engine/engine.h"; # unless $no_engine; 314109998Smarkm$crypto.=" crypto/stack/stack.h" ; # unless $no_stack; 315109998Smarkm$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer; 316109998Smarkm$crypto.=" crypto/bio/bio.h" ; # unless $no_bio; 317109998Smarkm$crypto.=" crypto/dso/dso.h" ; # unless $no_dso; 318109998Smarkm$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash; 31955714Skris$crypto.=" crypto/conf/conf.h"; 32055714Skris$crypto.=" crypto/txt_db/txt_db.h"; 32155714Skris 322109998Smarkm$crypto.=" crypto/evp/evp.h" ; # unless $no_evp; 32355714Skris$crypto.=" crypto/objects/objects.h"; 32455714Skris$crypto.=" crypto/pem/pem.h"; 32555714Skris#$crypto.=" crypto/meth/meth.h"; 32655714Skris$crypto.=" crypto/asn1/asn1.h"; 327109998Smarkm$crypto.=" crypto/asn1/asn1t.h"; 32855714Skris$crypto.=" crypto/asn1/asn1_mac.h"; 329109998Smarkm$crypto.=" crypto/err/err.h" ; # unless $no_err; 33055714Skris$crypto.=" crypto/pkcs7/pkcs7.h"; 33155714Skris$crypto.=" crypto/pkcs12/pkcs12.h"; 33255714Skris$crypto.=" crypto/x509/x509.h"; 33355714Skris$crypto.=" crypto/x509/x509_vfy.h"; 33455714Skris$crypto.=" crypto/x509v3/x509v3.h"; 335238405Sjkim$crypto.=" crypto/ts/ts.h"; 33655714Skris$crypto.=" crypto/rand/rand.h"; 337109998Smarkm$crypto.=" crypto/comp/comp.h" ; # unless $no_comp; 338109998Smarkm$crypto.=" crypto/ocsp/ocsp.h"; 339109998Smarkm$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h"; 340109998Smarkm$crypto.=" crypto/krb5/krb5_asn.h"; 341238405Sjkim#$crypto.=" crypto/store/store.h"; 342160814Ssimon$crypto.=" crypto/pqueue/pqueue.h"; 343194206Ssimon$crypto.=" crypto/cms/cms.h"; 344194206Ssimon$crypto.=" crypto/jpake/jpake.h"; 345238405Sjkim$crypto.=" crypto/modes/modes.h"; 346238405Sjkim$crypto.=" crypto/srp/srp.h"; 34755714Skris 34868651Skrismy $symhacks="crypto/symhacks.h"; 34955714Skris 35068651Skrismy @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks); 35168651Skrismy @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks); 35255714Skris 35355714Skrisif ($do_update) { 35455714Skris 35555714Skrisif ($do_ssl == 1) { 35668651Skris 35768651Skris &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols); 35868651Skris if ($do_rewrite == 1) { 35968651Skris open(OUT, ">$ssl_num"); 36068651Skris &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols); 36168651Skris } else { 36268651Skris open(OUT, ">>$ssl_num"); 36368651Skris } 36468651Skris &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols); 36555714Skris close OUT; 36655714Skris} 36755714Skris 36855714Skrisif($do_crypto == 1) { 36968651Skris 37068651Skris &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols); 37168651Skris if ($do_rewrite == 1) { 37268651Skris open(OUT, ">$crypto_num"); 37368651Skris &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols); 37468651Skris } else { 37568651Skris open(OUT, ">>$crypto_num"); 37668651Skris } 37768651Skris &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols); 37855714Skris close OUT; 37959191Skris} 38055714Skris 381109998Smarkm} elsif ($do_checkexist) { 382109998Smarkm &check_existing(*ssl_list, @ssl_symbols) 383109998Smarkm if $do_ssl == 1; 384109998Smarkm &check_existing(*crypto_list, @crypto_symbols) 385109998Smarkm if $do_crypto == 1; 38668651Skris} elsif ($do_ctest || $do_ctestall) { 38759191Skris 38859191Skris print <<"EOF"; 38959191Skris 39059191Skris/* Test file to check all DEF file symbols are present by trying 39159191Skris * to link to all of them. This is *not* intended to be run! 39259191Skris */ 39359191Skris 39459191Skrisint main() 39559191Skris{ 39659191SkrisEOF 39768651Skris &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols) 39859191Skris if $do_ssl == 1; 39959191Skris 40068651Skris &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols) 40159191Skris if $do_crypto == 1; 40259191Skris 40359191Skris print "}\n"; 40459191Skris 40555714Skris} else { 40655714Skris 407109998Smarkm &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols) 40855714Skris if $do_ssl == 1; 40955714Skris 410109998Smarkm &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols) 41155714Skris if $do_crypto == 1; 41255714Skris 41355714Skris} 41455714Skris 41555714Skris 41655714Skrissub do_defs 41755714Skris{ 41868651Skris my($name,$files,$symhacksfile)=@_; 41959191Skris my $file; 42055714Skris my @ret; 42168651Skris my %syms; 42268651Skris my %platform; # For anything undefined, we assume "" 42368651Skris my %kind; # For anything undefined, we assume "FUNCTION" 42468651Skris my %algorithm; # For anything undefined, we assume "" 425109998Smarkm my %variant; 426109998Smarkm my %variant_cnt; # To be able to allocate "name{n}" if "name" 427109998Smarkm # is the same name as the original. 42859191Skris my $cpp; 429109998Smarkm my %unknown_algorithms = (); 43055714Skris 43168651Skris foreach $file (split(/\s+/,$symhacksfile." ".$files)) 43255714Skris { 433109998Smarkm print STDERR "DEBUG: starting on $file:\n" if $debug; 43455714Skris open(IN,"<$file") || die "unable to open $file:$!\n"; 43559191Skris my $line = "", my $def= ""; 43655714Skris my %tag = ( 43768651Skris (map { $_ => 0 } @known_platforms), 438109998Smarkm (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms), 439109998Smarkm (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms), 44055714Skris NOPROTO => 0, 44155714Skris PERL5 => 0, 44255714Skris _WINDLL => 0, 44355714Skris CONST_STRICT => 0, 44455714Skris TRUE => 1, 44555714Skris ); 44668651Skris my $symhacking = $file eq $symhacksfile; 447109998Smarkm my @current_platforms = (); 448109998Smarkm my @current_algorithms = (); 449109998Smarkm 450109998Smarkm # params: symbol, alias, platforms, kind 451109998Smarkm # The reason to put this subroutine in a variable is that 452109998Smarkm # it will otherwise create it's own, unshared, version of 453109998Smarkm # %tag and %variant... 454109998Smarkm my $make_variant = sub 455109998Smarkm { 456109998Smarkm my ($s, $a, $p, $k) = @_; 457109998Smarkm my ($a1, $a2); 458109998Smarkm 459109998Smarkm print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug; 460109998Smarkm if (defined($p)) 461109998Smarkm { 462109998Smarkm $a1 = join(",",$p, 463109998Smarkm grep(!/^$/, 464109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 465109998Smarkm @known_platforms)); 466109998Smarkm } 467109998Smarkm else 468109998Smarkm { 469109998Smarkm $a1 = join(",", 470109998Smarkm grep(!/^$/, 471109998Smarkm map { $tag{$_} == 1 ? $_ : "" } 472109998Smarkm @known_platforms)); 473109998Smarkm } 474109998Smarkm $a2 = join(",", 475109998Smarkm grep(!/^$/, 476109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" } 477109998Smarkm @known_ossl_platforms)); 478109998Smarkm print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug; 479109998Smarkm if ($a1 eq "") { $a1 = $a2; } 480109998Smarkm elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; } 481109998Smarkm if ($a eq $s) 482109998Smarkm { 483109998Smarkm if (!defined($variant_cnt{$s})) 484109998Smarkm { 485109998Smarkm $variant_cnt{$s} = 0; 486109998Smarkm } 487109998Smarkm $variant_cnt{$s}++; 488109998Smarkm $a .= "{$variant_cnt{$s}}"; 489109998Smarkm } 490109998Smarkm my $toadd = $a.":".$a1.(defined($k)?":".$k:""); 491109998Smarkm my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:""); 492109998Smarkm if (!grep(/^$togrep$/, 493109998Smarkm split(/;/, defined($variant{$s})?$variant{$s}:""))) { 494109998Smarkm if (defined($variant{$s})) { $variant{$s} .= ";"; } 495109998Smarkm $variant{$s} .= $toadd; 496109998Smarkm } 497109998Smarkm print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug; 498109998Smarkm }; 499109998Smarkm 500109998Smarkm print STDERR "DEBUG: parsing ----------\n" if $debug; 50155714Skris while(<IN>) { 502160814Ssimon if (/\/\* Error codes for the \w+ functions\. \*\//) 503160814Ssimon { 504160814Ssimon undef @tag; 505160814Ssimon last; 506160814Ssimon } 50755714Skris if ($line ne '') { 50855714Skris $_ = $line . $_; 50955714Skris $line = ''; 51055714Skris } 51155714Skris 51255714Skris if (/\\$/) { 513109998Smarkm chomp; # remove eol 514109998Smarkm chop; # remove ending backslash 51555714Skris $line = $_; 51655714Skris next; 51755714Skris } 51855714Skris 519160814Ssimon if(/\/\*/) { 520160814Ssimon if (not /\*\//) { # multiline comment... 521160814Ssimon $line = $_; # ... just accumulate 522160814Ssimon next; 523160814Ssimon } else { 524160814Ssimon s/\/\*.*?\*\///gs;# wipe it 525160814Ssimon } 526160814Ssimon } 527160814Ssimon 52855714Skris if ($cpp) { 529160814Ssimon $cpp++ if /^#\s*if/; 530160814Ssimon $cpp-- if /^#\s*endif/; 53155714Skris next; 53255714Skris } 533160814Ssimon $cpp = 1 if /^#.*ifdef.*cplusplus/; 53455714Skris 53555714Skris s/{[^{}]*}//gs; # ignore {} blocks 536120631Snectar print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne ""; 537109998Smarkm print STDERR "DEBUG: \$_=\"$_\"\n" if $debug; 538109998Smarkm if (/^\#\s*ifndef\s+(.*)/) { 539109998Smarkm push(@tag,"-"); 54055714Skris push(@tag,$1); 54155714Skris $tag{$1}=-1; 542109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 543109998Smarkm } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) { 544109998Smarkm push(@tag,"-"); 545109998Smarkm if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) { 546109998Smarkm my $tmp_1 = $1; 547109998Smarkm my $tmp_; 548109998Smarkm foreach $tmp_ (split '\&\&',$tmp_1) { 549109998Smarkm $tmp_ =~ /!defined\(([^\)]+)\)/; 550109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 551109998Smarkm push(@tag,$1); 552109998Smarkm $tag{$1}=-1; 553109998Smarkm } 554109998Smarkm } else { 555109998Smarkm print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O... 556109998Smarkm print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 557109998Smarkm push(@tag,$1); 558109998Smarkm $tag{$1}=-1; 559109998Smarkm } 560160814Ssimon } elsif (/^\#\s*ifdef\s+(\S*)/) { 561109998Smarkm push(@tag,"-"); 56255714Skris push(@tag,$1); 56355714Skris $tag{$1}=1; 564109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 565109998Smarkm } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) { 566109998Smarkm push(@tag,"-"); 567109998Smarkm if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) { 568109998Smarkm my $tmp_1 = $1; 569109998Smarkm my $tmp_; 570109998Smarkm foreach $tmp_ (split '\|\|',$tmp_1) { 571109998Smarkm $tmp_ =~ /defined\(([^\)]+)\)/; 572109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 573109998Smarkm push(@tag,$1); 574109998Smarkm $tag{$1}=1; 575109998Smarkm } 576109998Smarkm } else { 577109998Smarkm print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O... 578109998Smarkm print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 579109998Smarkm push(@tag,$1); 580109998Smarkm $tag{$1}=1; 581109998Smarkm } 58268651Skris } elsif (/^\#\s*error\s+(\w+) is disabled\./) { 583109998Smarkm my $tag_i = $#tag; 584109998Smarkm while($tag[$tag_i] ne "-") { 585109998Smarkm if ($tag[$tag_i] eq "OPENSSL_NO_".$1) { 586109998Smarkm $tag{$tag[$tag_i]}=2; 587109998Smarkm print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug; 588109998Smarkm } 589109998Smarkm $tag_i--; 59068651Skris } 59155714Skris } elsif (/^\#\s*endif/) { 592109998Smarkm my $tag_i = $#tag; 593160814Ssimon while($tag_i > 0 && $tag[$tag_i] ne "-") { 594109998Smarkm my $t=$tag[$tag_i]; 595109998Smarkm print STDERR "DEBUG: \$t=\"$t\"\n" if $debug; 596109998Smarkm if ($tag{$t}==2) { 597109998Smarkm $tag{$t}=-1; 598109998Smarkm } else { 599109998Smarkm $tag{$t}=0; 600109998Smarkm } 601109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 602109998Smarkm pop(@tag); 603109998Smarkm if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) { 604109998Smarkm $t=$1; 605109998Smarkm } else { 606109998Smarkm $t=""; 607109998Smarkm } 608109998Smarkm if ($t ne "" 609109998Smarkm && !grep(/^$t$/, @known_algorithms)) { 610109998Smarkm $unknown_algorithms{$t} = 1; 611109998Smarkm #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug; 612109998Smarkm } 613109998Smarkm $tag_i--; 61468651Skris } 61555714Skris pop(@tag); 61655714Skris } elsif (/^\#\s*else/) { 617109998Smarkm my $tag_i = $#tag; 618109998Smarkm while($tag[$tag_i] ne "-") { 619109998Smarkm my $t=$tag[$tag_i]; 620109998Smarkm $tag{$t}= -$tag{$t}; 621109998Smarkm print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 622109998Smarkm $tag_i--; 623109998Smarkm } 62455714Skris } elsif (/^\#\s*if\s+1/) { 625109998Smarkm push(@tag,"-"); 62655714Skris # Dummy tag 62755714Skris push(@tag,"TRUE"); 62855714Skris $tag{"TRUE"}=1; 629109998Smarkm print STDERR "DEBUG: $file: found 1\n" if $debug; 63059191Skris } elsif (/^\#\s*if\s+0/) { 631109998Smarkm push(@tag,"-"); 63259191Skris # Dummy tag 63359191Skris push(@tag,"TRUE"); 63459191Skris $tag{"TRUE"}=-1; 635109998Smarkm print STDERR "DEBUG: $file: found 0\n" if $debug; 63668651Skris } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/ 637109998Smarkm && $symhacking && $tag{'TRUE'} != -1) { 638109998Smarkm # This is for aliasing. When we find an alias, 639109998Smarkm # we have to invert 640109998Smarkm &$make_variant($1,$2); 641109998Smarkm print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug; 64268651Skris } 64368651Skris if (/^\#/) { 644109998Smarkm @current_platforms = 645109998Smarkm grep(!/^$/, 646109998Smarkm map { $tag{$_} == 1 ? $_ : 647109998Smarkm $tag{$_} == -1 ? "!".$_ : "" } 648109998Smarkm @known_platforms); 649109998Smarkm push @current_platforms 650109998Smarkm , grep(!/^$/, 651109998Smarkm map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : 652109998Smarkm $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" } 653109998Smarkm @known_ossl_platforms); 654109998Smarkm @current_algorithms = 655109998Smarkm grep(!/^$/, 656109998Smarkm map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" } 657109998Smarkm @known_algorithms); 658109998Smarkm $def .= 659109998Smarkm "#INFO:" 660109998Smarkm .join(',',@current_platforms).":" 661109998Smarkm .join(',',@current_algorithms).";"; 66259191Skris next; 66368651Skris } 664109998Smarkm if ($tag{'TRUE'} != -1) { 665109998Smarkm if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { 666109998Smarkm next; 667109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 668109998Smarkm $def .= "int d2i_$3(void);"; 669109998Smarkm $def .= "int i2d_$3(void);"; 670109998Smarkm # Variant for platforms that do not 671109998Smarkm # have to access globale variables 672109998Smarkm # in shared libraries through functions 673109998Smarkm $def .= 674109998Smarkm "#INFO:" 675109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 676109998Smarkm .join(',',@current_algorithms).";"; 677109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 678109998Smarkm $def .= 679109998Smarkm "#INFO:" 680109998Smarkm .join(',',@current_platforms).":" 681109998Smarkm .join(',',@current_algorithms).";"; 682109998Smarkm # Variant for platforms that have to 683109998Smarkm # access globale variables in shared 684109998Smarkm # libraries through functions 685109998Smarkm &$make_variant("$2_it","$2_it", 686109998Smarkm "EXPORT_VAR_AS_FUNCTION", 687109998Smarkm "FUNCTION"); 688109998Smarkm next; 689109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 690109998Smarkm $def .= "int d2i_$3(void);"; 691109998Smarkm $def .= "int i2d_$3(void);"; 692109998Smarkm $def .= "int $3_free(void);"; 693109998Smarkm $def .= "int $3_new(void);"; 694109998Smarkm # Variant for platforms that do not 695109998Smarkm # have to access globale variables 696109998Smarkm # in shared libraries through functions 697109998Smarkm $def .= 698109998Smarkm "#INFO:" 699109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 700109998Smarkm .join(',',@current_algorithms).";"; 701109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 702109998Smarkm $def .= 703109998Smarkm "#INFO:" 704109998Smarkm .join(',',@current_platforms).":" 705109998Smarkm .join(',',@current_algorithms).";"; 706109998Smarkm # Variant for platforms that have to 707109998Smarkm # access globale variables in shared 708109998Smarkm # libraries through functions 709109998Smarkm &$make_variant("$2_it","$2_it", 710109998Smarkm "EXPORT_VAR_AS_FUNCTION", 711109998Smarkm "FUNCTION"); 712109998Smarkm next; 713109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ || 714109998Smarkm /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) { 715109998Smarkm $def .= "int d2i_$1(void);"; 716109998Smarkm $def .= "int i2d_$1(void);"; 717109998Smarkm $def .= "int $1_free(void);"; 718109998Smarkm $def .= "int $1_new(void);"; 719109998Smarkm # Variant for platforms that do not 720109998Smarkm # have to access globale variables 721109998Smarkm # in shared libraries through functions 722109998Smarkm $def .= 723109998Smarkm "#INFO:" 724109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 725109998Smarkm .join(',',@current_algorithms).";"; 726109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 727109998Smarkm $def .= 728109998Smarkm "#INFO:" 729109998Smarkm .join(',',@current_platforms).":" 730109998Smarkm .join(',',@current_algorithms).";"; 731109998Smarkm # Variant for platforms that have to 732109998Smarkm # access globale variables in shared 733109998Smarkm # libraries through functions 734109998Smarkm &$make_variant("$1_it","$1_it", 735109998Smarkm "EXPORT_VAR_AS_FUNCTION", 736109998Smarkm "FUNCTION"); 737109998Smarkm next; 738109998Smarkm } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 739109998Smarkm $def .= "int d2i_$2(void);"; 740109998Smarkm $def .= "int i2d_$2(void);"; 741109998Smarkm # Variant for platforms that do not 742109998Smarkm # have to access globale variables 743109998Smarkm # in shared libraries through functions 744109998Smarkm $def .= 745109998Smarkm "#INFO:" 746109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 747109998Smarkm .join(',',@current_algorithms).";"; 748109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 749109998Smarkm $def .= 750109998Smarkm "#INFO:" 751109998Smarkm .join(',',@current_platforms).":" 752109998Smarkm .join(',',@current_algorithms).";"; 753109998Smarkm # Variant for platforms that have to 754109998Smarkm # access globale variables in shared 755109998Smarkm # libraries through functions 756109998Smarkm &$make_variant("$2_it","$2_it", 757109998Smarkm "EXPORT_VAR_AS_FUNCTION", 758109998Smarkm "FUNCTION"); 759109998Smarkm next; 760160814Ssimon } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) { 761160814Ssimon $def .= "int $1_free(void);"; 762160814Ssimon $def .= "int $1_new(void);"; 763160814Ssimon next; 764109998Smarkm } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 765109998Smarkm $def .= "int d2i_$2(void);"; 766109998Smarkm $def .= "int i2d_$2(void);"; 767109998Smarkm $def .= "int $2_free(void);"; 768109998Smarkm $def .= "int $2_new(void);"; 769109998Smarkm # Variant for platforms that do not 770109998Smarkm # have to access globale variables 771109998Smarkm # in shared libraries through functions 772109998Smarkm $def .= 773109998Smarkm "#INFO:" 774109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 775109998Smarkm .join(',',@current_algorithms).";"; 776109998Smarkm $def .= "OPENSSL_EXTERN int $2_it;"; 777109998Smarkm $def .= 778109998Smarkm "#INFO:" 779109998Smarkm .join(',',@current_platforms).":" 780109998Smarkm .join(',',@current_algorithms).";"; 781109998Smarkm # Variant for platforms that have to 782109998Smarkm # access globale variables in shared 783109998Smarkm # libraries through functions 784109998Smarkm &$make_variant("$2_it","$2_it", 785109998Smarkm "EXPORT_VAR_AS_FUNCTION", 786109998Smarkm "FUNCTION"); 787109998Smarkm next; 788109998Smarkm } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) { 789109998Smarkm # Variant for platforms that do not 790109998Smarkm # have to access globale variables 791109998Smarkm # in shared libraries through functions 792109998Smarkm $def .= 793109998Smarkm "#INFO:" 794109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 795109998Smarkm .join(',',@current_algorithms).";"; 796109998Smarkm $def .= "OPENSSL_EXTERN int $1_it;"; 797109998Smarkm $def .= 798109998Smarkm "#INFO:" 799109998Smarkm .join(',',@current_platforms).":" 800109998Smarkm .join(',',@current_algorithms).";"; 801109998Smarkm # Variant for platforms that have to 802109998Smarkm # access globale variables in shared 803109998Smarkm # libraries through functions 804109998Smarkm &$make_variant("$1_it","$1_it", 805109998Smarkm "EXPORT_VAR_AS_FUNCTION", 806109998Smarkm "FUNCTION"); 807109998Smarkm next; 808160814Ssimon } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) { 809160814Ssimon $def .= "int i2d_$1_NDEF(void);"; 810109998Smarkm } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { 811109998Smarkm next; 812160814Ssimon } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) { 813160814Ssimon $def .= "int $1_print_ctx(void);"; 814160814Ssimon next; 815160814Ssimon } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 816160814Ssimon $def .= "int $2_print_ctx(void);"; 817160814Ssimon next; 818109998Smarkm } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) { 819109998Smarkm next; 820109998Smarkm } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || 821160814Ssimon /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ || 822160814Ssimon /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) { 823109998Smarkm # Things not in Win16 824109998Smarkm $def .= 825109998Smarkm "#INFO:" 826109998Smarkm .join(',',"!WIN16",@current_platforms).":" 827109998Smarkm .join(',',@current_algorithms).";"; 828109998Smarkm $def .= "int PEM_read_$1(void);"; 829109998Smarkm $def .= "int PEM_write_$1(void);"; 830109998Smarkm $def .= 831109998Smarkm "#INFO:" 832109998Smarkm .join(',',@current_platforms).":" 833109998Smarkm .join(',',@current_algorithms).";"; 834109998Smarkm # Things that are everywhere 835109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 836109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 837109998Smarkm next; 838109998Smarkm } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ || 839109998Smarkm /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) { 840109998Smarkm # Things not in Win16 841109998Smarkm $def .= 842109998Smarkm "#INFO:" 843109998Smarkm .join(',',"!WIN16",@current_platforms).":" 844109998Smarkm .join(',',@current_algorithms).";"; 845109998Smarkm $def .= "int PEM_write_$1(void);"; 846109998Smarkm $def .= 847109998Smarkm "#INFO:" 848109998Smarkm .join(',',@current_platforms).":" 849109998Smarkm .join(',',@current_algorithms).";"; 850109998Smarkm # Things that are everywhere 851109998Smarkm $def .= "int PEM_write_bio_$1(void);"; 852109998Smarkm next; 853109998Smarkm } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ || 854109998Smarkm /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) { 855109998Smarkm # Things not in Win16 856109998Smarkm $def .= 857109998Smarkm "#INFO:" 858109998Smarkm .join(',',"!WIN16",@current_platforms).":" 859109998Smarkm .join(',',@current_algorithms).";"; 860109998Smarkm $def .= "int PEM_read_$1(void);"; 861109998Smarkm $def .= 862109998Smarkm "#INFO:" 863109998Smarkm .join(',',@current_platforms).":" 864109998Smarkm .join(',',@current_algorithms).";"; 865109998Smarkm # Things that are everywhere 866109998Smarkm $def .= "int PEM_read_bio_$1(void);"; 867109998Smarkm next; 868109998Smarkm } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 869109998Smarkm # Variant for platforms that do not 870109998Smarkm # have to access globale variables 871109998Smarkm # in shared libraries through functions 872109998Smarkm $def .= 873109998Smarkm "#INFO:" 874109998Smarkm .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 875109998Smarkm .join(',',@current_algorithms).";"; 876109998Smarkm $def .= "OPENSSL_EXTERN int _shadow_$2;"; 877109998Smarkm $def .= 878109998Smarkm "#INFO:" 879109998Smarkm .join(',',@current_platforms).":" 880109998Smarkm .join(',',@current_algorithms).";"; 881109998Smarkm # Variant for platforms that have to 882109998Smarkm # access globale variables in shared 883109998Smarkm # libraries through functions 884109998Smarkm &$make_variant("_shadow_$2","_shadow_$2", 885109998Smarkm "EXPORT_VAR_AS_FUNCTION", 886109998Smarkm "FUNCTION"); 887109998Smarkm } elsif ($tag{'CONST_STRICT'} != 1) { 88868651Skris if (/\{|\/\*|\([^\)]*$/) { 88955714Skris $line = $_; 89055714Skris } else { 89155714Skris $def .= $_; 89255714Skris } 89355714Skris } 89455714Skris } 895109998Smarkm } 89655714Skris close(IN); 89755714Skris 898160814Ssimon my $algs; 89968651Skris my $plays; 90068651Skris 901109998Smarkm print STDERR "DEBUG: postprocessing ----------\n" if $debug; 90255714Skris foreach (split /;/, $def) { 90368651Skris my $s; my $k = "FUNCTION"; my $p; my $a; 90455714Skris s/^[\n\s]*//g; 90555714Skris s/[\n\s]*$//g; 90668651Skris next if(/\#undef/); 90755714Skris next if(/typedef\W/); 90868651Skris next if(/\#define/); 90968651Skris 910160814Ssimon # Reduce argument lists to empty () 911160814Ssimon # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {} 912160814Ssimon while(/\(.*\)/s) { 913160814Ssimon s/\([^\(\)]+\)/\{\}/gs; 914160814Ssimon s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f 915160814Ssimon } 916160814Ssimon # pretend as we didn't use curly braces: {} -> () 917160814Ssimon s/\{\}/\(\)/gs; 918160814Ssimon 919160814Ssimon s/STACK_OF\(\)/void/gs; 920238405Sjkim s/LHASH_OF\(\)/void/gs; 921160814Ssimon 922109998Smarkm print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug; 92368651Skris if (/^\#INFO:([^:]*):(.*)$/) { 92468651Skris $plats = $1; 92568651Skris $algs = $2; 926109998Smarkm print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug; 92768651Skris next; 928109998Smarkm } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) { 92968651Skris $s = $1; 93068651Skris $k = "VARIABLE"; 931109998Smarkm print STDERR "DEBUG: found external variable $s\n" if $debug; 932160814Ssimon } elsif (/TYPEDEF_\w+_OF/s) { 93355714Skris next; 934160814Ssimon } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is 935160814Ssimon $s = $1; # a function name! 936109998Smarkm print STDERR "DEBUG: found function $s\n" if $debug; 93755714Skris } elsif (/\(/ and not (/=/)) { 93855714Skris print STDERR "File $file: cannot parse: $_;\n"; 93968651Skris next; 94068651Skris } else { 94168651Skris next; 94255714Skris } 94368651Skris 94468651Skris $syms{$s} = 1; 94568651Skris $kind{$s} = $k; 94668651Skris 94768651Skris $p = $plats; 94868651Skris $a = $algs; 94968651Skris $a .= ",BF" if($s =~ /EVP_bf/); 95068651Skris $a .= ",CAST" if($s =~ /EVP_cast/); 95168651Skris $a .= ",DES" if($s =~ /EVP_des/); 95268651Skris $a .= ",DSA" if($s =~ /EVP_dss/); 95368651Skris $a .= ",IDEA" if($s =~ /EVP_idea/); 95468651Skris $a .= ",MD2" if($s =~ /EVP_md2/); 95568651Skris $a .= ",MD4" if($s =~ /EVP_md4/); 95668651Skris $a .= ",MD5" if($s =~ /EVP_md5/); 95768651Skris $a .= ",RC2" if($s =~ /EVP_rc2/); 95868651Skris $a .= ",RC4" if($s =~ /EVP_rc4/); 95968651Skris $a .= ",RC5" if($s =~ /EVP_rc5/); 96068651Skris $a .= ",RIPEMD" if($s =~ /EVP_ripemd/); 96168651Skris $a .= ",SHA" if($s =~ /EVP_sha/); 96268651Skris $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/); 96368651Skris $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); 96468651Skris $a .= ",RSA" if($s =~ /RSAPrivateKey/); 96568651Skris $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); 96668651Skris 967109998Smarkm $platform{$s} = 968109998Smarkm &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p); 96968651Skris $algorithm{$s} .= ','.$a; 97068651Skris 971109998Smarkm if (defined($variant{$s})) { 972109998Smarkm foreach $v (split /;/,$variant{$s}) { 973109998Smarkm (my $r, my $p, my $k) = split(/:/,$v); 974109998Smarkm my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p); 975109998Smarkm $syms{$r} = 1; 976109998Smarkm if (!defined($k)) { $k = $kind{$s}; } 977109998Smarkm $kind{$r} = $k."(".$s.")"; 978109998Smarkm $algorithm{$r} = $algorithm{$s}; 979109998Smarkm $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p); 980109998Smarkm $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip); 981109998Smarkm print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug; 982109998Smarkm } 98368651Skris } 984109998Smarkm print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug; 98555714Skris } 98655714Skris } 98755714Skris 98868651Skris # Prune the returned symbols 98955714Skris 99068651Skris delete $syms{"bn_dump1"}; 99168651Skris $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh"; 99268651Skris 993109998Smarkm $platform{"PEM_read_NS_CERT_SEQ"} = "VMS"; 994109998Smarkm $platform{"PEM_write_NS_CERT_SEQ"} = "VMS"; 995109998Smarkm $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS"; 996109998Smarkm $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS"; 997205128Ssimon $platform{"EVP_sha384"} = "!VMSVAX"; 998205128Ssimon $platform{"EVP_sha512"} = "!VMSVAX"; 999205128Ssimon $platform{"SHA384_Init"} = "!VMSVAX"; 1000205128Ssimon $platform{"SHA384_Transform"} = "!VMSVAX"; 1001205128Ssimon $platform{"SHA384_Update"} = "!VMSVAX"; 1002205128Ssimon $platform{"SHA384_Final"} = "!VMSVAX"; 1003205128Ssimon $platform{"SHA384"} = "!VMSVAX"; 1004205128Ssimon $platform{"SHA512_Init"} = "!VMSVAX"; 1005205128Ssimon $platform{"SHA512_Transform"} = "!VMSVAX"; 1006205128Ssimon $platform{"SHA512_Update"} = "!VMSVAX"; 1007205128Ssimon $platform{"SHA512_Final"} = "!VMSVAX"; 1008205128Ssimon $platform{"SHA512"} = "!VMSVAX"; 1009238405Sjkim $platform{"WHIRLPOOL_Init"} = "!VMSVAX"; 1010238405Sjkim $platform{"WHIRLPOOL"} = "!VMSVAX"; 1011238405Sjkim $platform{"WHIRLPOOL_BitUpdate"} = "!VMSVAX"; 1012238405Sjkim $platform{"EVP_whirlpool"} = "!VMSVAX"; 1013238405Sjkim $platform{"WHIRLPOOL_Final"} = "!VMSVAX"; 1014238405Sjkim $platform{"WHIRLPOOL_Update"} = "!VMSVAX"; 1015205128Ssimon 1016215697Ssimon 101768651Skris # Info we know about 101868651Skris 101968651Skris push @ret, map { $_."\\".&info_string($_,"EXIST", 102068651Skris $platform{$_}, 102168651Skris $kind{$_}, 102268651Skris $algorithm{$_}) } keys %syms; 102368651Skris 1024109998Smarkm if (keys %unknown_algorithms) { 1025109998Smarkm print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n"; 1026109998Smarkm print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n"; 1027109998Smarkm } 102868651Skris return(@ret); 102968651Skris} 103068651Skris 1031109998Smarkm# Param: string of comma-separated platform-specs. 1032109998Smarkmsub reduce_platforms 1033109998Smarkm{ 1034109998Smarkm my ($platforms) = @_; 103568651Skris my $pl = defined($platforms) ? $platforms : ""; 103668651Skris my %p = map { $_ => 0 } split /,/, $pl; 103768651Skris my $ret; 103868651Skris 1039109998Smarkm print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n" 1040109998Smarkm if $debug; 104168651Skris # We do this, because if there's code like the following, it really 104268651Skris # means the function exists in all cases and should therefore be 104368651Skris # everywhere. By increasing and decreasing, we may attain 0: 104468651Skris # 104568651Skris # ifndef WIN16 104668651Skris # int foo(); 104768651Skris # else 104868651Skris # int _fat foo(); 104968651Skris # endif 105068651Skris foreach $platform (split /,/, $pl) { 105168651Skris if ($platform =~ /^!(.*)$/) { 105268651Skris $p{$1}--; 105368651Skris } else { 105468651Skris $p{$platform}++; 105555714Skris } 105655714Skris } 105768651Skris foreach $platform (keys %p) { 105868651Skris if ($p{$platform} == 0) { delete $p{$platform}; } 105955714Skris } 106055714Skris 106168651Skris delete $p{""}; 1062109998Smarkm 1063109998Smarkm $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p)); 1064109998Smarkm print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n" 1065109998Smarkm if $debug; 1066109998Smarkm return $ret; 1067109998Smarkm} 1068109998Smarkm 1069109998Smarkmsub info_string { 1070109998Smarkm (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_; 1071109998Smarkm 1072109998Smarkm my %a = defined($algorithms) ? 1073109998Smarkm map { $_ => 1 } split /,/, $algorithms : (); 1074109998Smarkm my $k = defined($kind) ? $kind : "FUNCTION"; 1075109998Smarkm my $ret; 1076109998Smarkm my $p = &reduce_platforms($platforms); 1077109998Smarkm 107868651Skris delete $a{""}; 107955714Skris 108068651Skris $ret = $exist; 1081109998Smarkm $ret .= ":".$p; 108268651Skris $ret .= ":".$k; 1083109998Smarkm $ret .= ":".join(',',sort keys %a); 108468651Skris return $ret; 108555714Skris} 108655714Skris 108768651Skrissub maybe_add_info { 108868651Skris (my $name, *nums, my @symbols) = @_; 108968651Skris my $sym; 109068651Skris my $new_info = 0; 1091109998Smarkm my %syms=(); 109268651Skris 109368651Skris print STDERR "Updating $name info\n"; 109468651Skris foreach $sym (@symbols) { 109568651Skris (my $s, my $i) = split /\\/, $sym; 109668651Skris if (defined($nums{$s})) { 1097109998Smarkm $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/; 109868651Skris (my $n, my $dummy) = split /\\/, $nums{$s}; 109968651Skris if (!defined($dummy) || $i ne $dummy) { 110068651Skris $nums{$s} = $n."\\".$i; 110168651Skris $new_info++; 1102109998Smarkm print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug; 110368651Skris } 110468651Skris } 1105109998Smarkm $syms{$s} = 1; 110668651Skris } 1107109998Smarkm 1108109998Smarkm my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums; 1109109998Smarkm foreach $sym (@s) { 1110109998Smarkm (my $n, my $i) = split /\\/, $nums{$sym}; 1111109998Smarkm if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) { 1112109998Smarkm $new_info++; 1113109998Smarkm print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug; 1114109998Smarkm } 1115109998Smarkm } 111668651Skris if ($new_info) { 111768651Skris print STDERR "$new_info old symbols got an info update\n"; 111868651Skris if (!$do_rewrite) { 111968651Skris print STDERR "You should do a rewrite to fix this.\n"; 112068651Skris } 112168651Skris } else { 112268651Skris print STDERR "No old symbols needed info update\n"; 112368651Skris } 112468651Skris} 112568651Skris 1126109998Smarkm# Param: string of comma-separated keywords, each possibly prefixed with a "!" 1127109998Smarkmsub is_valid 1128109998Smarkm{ 1129109998Smarkm my ($keywords_txt,$platforms) = @_; 1130109998Smarkm my (@keywords) = split /,/,$keywords_txt; 1131160814Ssimon my ($falsesum, $truesum) = (0, 1); 1132109998Smarkm 1133109998Smarkm # Param: one keyword 1134109998Smarkm sub recognise 1135109998Smarkm { 1136109998Smarkm my ($keyword,$platforms) = @_; 1137109998Smarkm 1138109998Smarkm if ($platforms) { 1139109998Smarkm # platforms 1140205128Ssimon if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; } 1141205128Ssimon if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; } 1142238405Sjkim if ($keyword eq "VMS" && $VMS) { return 1; } 1143109998Smarkm if ($keyword eq "WIN32" && $W32) { return 1; } 1144109998Smarkm if ($keyword eq "WIN16" && $W16) { return 1; } 1145109998Smarkm if ($keyword eq "WINNT" && $NT) { return 1; } 1146109998Smarkm if ($keyword eq "OS2" && $OS2) { return 1; } 1147109998Smarkm # Special platforms: 1148109998Smarkm # EXPORT_VAR_AS_FUNCTION means that global variables 1149109998Smarkm # will be represented as functions. This currently 1150109998Smarkm # only happens on VMS-VAX. 1151109998Smarkm if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) { 1152109998Smarkm return 1; 1153109998Smarkm } 1154194206Ssimon if ($keyword eq "OPENSSL_FIPS" && $fips) { 1155194206Ssimon return 1; 1156194206Ssimon } 1157194206Ssimon if ($keyword eq "ZLIB" && $zlib) { return 1; } 1158109998Smarkm return 0; 1159109998Smarkm } else { 1160109998Smarkm # algorithms 1161109998Smarkm if ($keyword eq "RC2" && $no_rc2) { return 0; } 1162109998Smarkm if ($keyword eq "RC4" && $no_rc4) { return 0; } 1163109998Smarkm if ($keyword eq "RC5" && $no_rc5) { return 0; } 1164109998Smarkm if ($keyword eq "IDEA" && $no_idea) { return 0; } 1165109998Smarkm if ($keyword eq "DES" && $no_des) { return 0; } 1166109998Smarkm if ($keyword eq "BF" && $no_bf) { return 0; } 1167109998Smarkm if ($keyword eq "CAST" && $no_cast) { return 0; } 1168109998Smarkm if ($keyword eq "MD2" && $no_md2) { return 0; } 1169109998Smarkm if ($keyword eq "MD4" && $no_md4) { return 0; } 1170109998Smarkm if ($keyword eq "MD5" && $no_md5) { return 0; } 1171109998Smarkm if ($keyword eq "SHA" && $no_sha) { return 0; } 1172109998Smarkm if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; } 1173109998Smarkm if ($keyword eq "MDC2" && $no_mdc2) { return 0; } 1174238405Sjkim if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; } 1175109998Smarkm if ($keyword eq "RSA" && $no_rsa) { return 0; } 1176109998Smarkm if ($keyword eq "DSA" && $no_dsa) { return 0; } 1177109998Smarkm if ($keyword eq "DH" && $no_dh) { return 0; } 1178109998Smarkm if ($keyword eq "EC" && $no_ec) { return 0; } 1179160814Ssimon if ($keyword eq "ECDSA" && $no_ecdsa) { return 0; } 1180160814Ssimon if ($keyword eq "ECDH" && $no_ecdh) { return 0; } 1181109998Smarkm if ($keyword eq "HMAC" && $no_hmac) { return 0; } 1182109998Smarkm if ($keyword eq "AES" && $no_aes) { return 0; } 1183162911Ssimon if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; } 1184194206Ssimon if ($keyword eq "SEED" && $no_seed) { return 0; } 1185109998Smarkm if ($keyword eq "EVP" && $no_evp) { return 0; } 1186109998Smarkm if ($keyword eq "LHASH" && $no_lhash) { return 0; } 1187109998Smarkm if ($keyword eq "STACK" && $no_stack) { return 0; } 1188109998Smarkm if ($keyword eq "ERR" && $no_err) { return 0; } 1189109998Smarkm if ($keyword eq "BUFFER" && $no_buffer) { return 0; } 1190109998Smarkm if ($keyword eq "BIO" && $no_bio) { return 0; } 1191109998Smarkm if ($keyword eq "COMP" && $no_comp) { return 0; } 1192109998Smarkm if ($keyword eq "DSO" && $no_dso) { return 0; } 1193109998Smarkm if ($keyword eq "KRB5" && $no_krb5) { return 0; } 1194111147Snectar if ($keyword eq "ENGINE" && $no_engine) { return 0; } 1195111147Snectar if ($keyword eq "HW" && $no_hw) { return 0; } 1196109998Smarkm if ($keyword eq "FP_API" && $no_fp_api) { return 0; } 1197160814Ssimon if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; } 1198160814Ssimon if ($keyword eq "GMP" && $no_gmp) { return 0; } 1199167612Ssimon if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; } 1200194206Ssimon if ($keyword eq "TLSEXT" && $no_tlsext) { return 0; } 1201238405Sjkim if ($keyword eq "PSK" && $no_psk) { return 0; } 1202194206Ssimon if ($keyword eq "CMS" && $no_cms) { return 0; } 1203238405Sjkim if ($keyword eq "EC2M" && $no_ec2m) { return 0; } 1204238405Sjkim if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; } 1205238405Sjkim if ($keyword eq "EC_NISTP_64_GCC_128" && $no_nistp_gcc) 1206238405Sjkim { return 0; } 1207238405Sjkim if ($keyword eq "SSL2" && $no_ssl2) { return 0; } 1208194206Ssimon if ($keyword eq "CAPIENG" && $no_capieng) { return 0; } 1209194206Ssimon if ($keyword eq "JPAKE" && $no_jpake) { return 0; } 1210238405Sjkim if ($keyword eq "SRP" && $no_srp) { return 0; } 1211238405Sjkim if ($keyword eq "SCTP" && $no_sctp) { return 0; } 1212269682Sjkim if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; } 1213160814Ssimon if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; } 1214109998Smarkm 1215109998Smarkm # Nothing recognise as true 1216109998Smarkm return 1; 1217109998Smarkm } 1218109998Smarkm } 1219109998Smarkm 1220109998Smarkm foreach $k (@keywords) { 1221109998Smarkm if ($k =~ /^!(.*)$/) { 1222109998Smarkm $falsesum += &recognise($1,$platforms); 1223109998Smarkm } else { 1224160814Ssimon $truesum *= &recognise($k,$platforms); 1225109998Smarkm } 1226109998Smarkm } 1227109998Smarkm print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug; 1228109998Smarkm return (!$falsesum) && $truesum; 1229109998Smarkm} 1230109998Smarkm 123159191Skrissub print_test_file 123259191Skris{ 1233109998Smarkm (*OUT,my $name,*nums,my $testall,my @symbols)=@_; 123459191Skris my $n = 1; my @e; my @r; 123568651Skris my $sym; my $prev = ""; my $prefSSLeay; 123659191Skris 1237109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 1238109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 123968651Skris @symbols=((sort @e),(sort @r)); 124059191Skris 124168651Skris foreach $sym (@symbols) { 124268651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1243109998Smarkm my $v = 0; 1244109998Smarkm $v = 1 if $i=~ /^.*?:.*?:VARIABLE/; 1245109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1246109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1247109998Smarkm if (!defined($nums{$s})) { 1248109998Smarkm print STDERR "Warning: $s does not have a number assigned\n" 1249109998Smarkm if(!$do_update); 1250109998Smarkm } elsif (is_valid($p,1) && is_valid($a,0)) { 1251109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1252109998Smarkm if ($prev eq $s2) { 1253109998Smarkm print OUT "\t/* The following has already appeared previously */\n"; 1254109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1255109998Smarkm } 1256109998Smarkm $prev = $s2; # To warn about duplicates... 1257109998Smarkm 1258109998Smarkm ($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/); 1259109998Smarkm if ($v) { 1260109998Smarkm print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n"; 126168651Skris } else { 1262109998Smarkm print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n"; 126368651Skris } 126459191Skris } 126559191Skris } 126659191Skris} 126759191Skris 1268127128Snectarsub get_version { 1269127128Snectar local *MF; 1270127128Snectar my $v = '?'; 1271142425Snectar open MF, 'Makefile' or return $v; 1272127128Snectar while (<MF>) { 1273127128Snectar $v = $1, last if /^VERSION=(.*?)\s*$/; 1274127128Snectar } 1275127128Snectar close MF; 1276127128Snectar return $v; 1277127128Snectar} 1278127128Snectar 127955714Skrissub print_def_file 128055714Skris{ 128168651Skris (*OUT,my $name,*nums,my @symbols)=@_; 1282109998Smarkm my $n = 1; my @e; my @r; my @v; my $prev=""; 1283109998Smarkm my $liboptions=""; 1284127128Snectar my $libname = $name; 1285127128Snectar my $http_vendor = 'www.openssl.org/'; 1286127128Snectar my $version = get_version(); 1287127128Snectar my $what = "OpenSSL: implementation of Secure Socket Layer"; 1288127128Snectar my $description = "$what $version, $name - http://$http_vendor"; 128955714Skris 129055714Skris if ($W32) 1291127128Snectar { $libname.="32"; } 1292109998Smarkm elsif ($W16) 1293127128Snectar { $libname.="16"; } 1294109998Smarkm elsif ($OS2) 1295127128Snectar { # DLL names should not clash on the whole system. 1296127128Snectar # However, they should not have any particular relationship 1297127128Snectar # to the name of the static library. Chose descriptive names 1298127128Snectar # (must be at most 8 chars). 1299127128Snectar my %translate = (ssl => 'open_ssl', crypto => 'cryptssl'); 1300127128Snectar $libname = $translate{$name} || $name; 1301127128Snectar $liboptions = <<EOO; 1302127128SnectarINITINSTANCE 1303127128SnectarDATA MULTIPLE NONSHARED 1304127128SnectarEOO 1305127128Snectar # Vendor field can't contain colon, drat; so we omit http:// 1306127128Snectar $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd"; 1307127128Snectar } 130855714Skris 130955714Skris print OUT <<"EOF"; 131055714Skris; 131155714Skris; Definition file for the DLL version of the $name library from OpenSSL 131255714Skris; 131355714Skris 1314127128SnectarLIBRARY $libname $liboptions 131555714Skris 131655714SkrisEOF 131755714Skris 1318109998Smarkm if ($W16) { 131955714Skris print <<"EOF"; 132055714SkrisCODE PRELOAD MOVEABLE 132155714SkrisDATA PRELOAD MOVEABLE SINGLE 132255714Skris 132355714SkrisEXETYPE WINDOWS 132455714Skris 132555714SkrisHEAPSIZE 4096 132655714SkrisSTACKSIZE 8192 132755714Skris 132855714SkrisEOF 132955714Skris } 133055714Skris 133155714Skris print "EXPORTS\n"; 133255714Skris 1333109998Smarkm (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1334109998Smarkm (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1335109998Smarkm (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols); 1336109998Smarkm @symbols=((sort @e),(sort @r), (sort @v)); 133755714Skris 133855714Skris 133968651Skris foreach $sym (@symbols) { 134068651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1341109998Smarkm my $v = 0; 1342109998Smarkm $v = 1 if $i =~ /^.*?:.*?:VARIABLE/; 134368651Skris if (!defined($nums{$s})) { 134468651Skris printf STDERR "Warning: $s does not have a number assigned\n" 1345109998Smarkm if(!$do_update); 134655714Skris } else { 1347109998Smarkm (my $n, my $dummy) = split /\\/, $nums{$s}; 134868651Skris my %pf = (); 1349109998Smarkm my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1350109998Smarkm my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1351109998Smarkm if (is_valid($p,1) && is_valid($a,0)) { 1352109998Smarkm my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1353109998Smarkm if ($prev eq $s2) { 1354109998Smarkm print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1355109998Smarkm } 1356109998Smarkm $prev = $s2; # To warn about duplicates... 1357109998Smarkm if($v && !$OS2) { 1358109998Smarkm printf OUT " %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n; 1359109998Smarkm } else { 1360109998Smarkm printf OUT " %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n; 1361109998Smarkm } 136268651Skris } 136355714Skris } 136455714Skris } 136555714Skris printf OUT "\n"; 136655714Skris} 136755714Skris 136855714Skrissub load_numbers 136955714Skris{ 137055714Skris my($name)=@_; 137155714Skris my(@a,%ret); 137255714Skris 137355714Skris $max_num = 0; 137468651Skris $num_noinfo = 0; 137568651Skris $prev = ""; 1376109998Smarkm $prev_cnt = 0; 137755714Skris 137855714Skris open(IN,"<$name") || die "unable to open $name:$!\n"; 137955714Skris while (<IN>) { 138055714Skris chop; 138155714Skris s/#.*$//; 138255714Skris next if /^\s*$/; 138355714Skris @a=split; 138468651Skris if (defined $ret{$a[0]}) { 1385109998Smarkm # This is actually perfectly OK 1386109998Smarkm #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n"; 138768651Skris } 138868651Skris if ($max_num > $a[1]) { 138968651Skris print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n"; 139068651Skris } 1391109998Smarkm elsif ($max_num == $a[1]) { 139268651Skris # This is actually perfectly OK 139368651Skris #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n"; 1394109998Smarkm if ($a[0] eq $prev) { 1395109998Smarkm $prev_cnt++; 1396109998Smarkm $a[0] .= "{$prev_cnt}"; 1397109998Smarkm } 139868651Skris } 1399109998Smarkm else { 1400109998Smarkm $prev_cnt = 0; 1401109998Smarkm } 140268651Skris if ($#a < 2) { 140368651Skris # Existence will be proven later, in do_defs 140468651Skris $ret{$a[0]}=$a[1]; 140568651Skris $num_noinfo++; 140668651Skris } else { 140768651Skris $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker 140868651Skris } 140955714Skris $max_num = $a[1] if $a[1] > $max_num; 141068651Skris $prev=$a[0]; 141155714Skris } 141268651Skris if ($num_noinfo) { 141368651Skris print STDERR "Warning: $num_noinfo symbols were without info."; 141468651Skris if ($do_rewrite) { 141568651Skris printf STDERR " The rewrite will fix this.\n"; 141668651Skris } else { 141768651Skris printf STDERR " You should do a rewrite to fix this.\n"; 141868651Skris } 141968651Skris } 142055714Skris close(IN); 142155714Skris return(%ret); 142255714Skris} 142355714Skris 142468651Skrissub parse_number 142568651Skris{ 142668651Skris (my $str, my $what) = @_; 142768651Skris (my $n, my $i) = split(/\\/,$str); 142868651Skris if ($what eq "n") { 142968651Skris return $n; 143068651Skris } else { 143168651Skris return $i; 143268651Skris } 143368651Skris} 143468651Skris 143568651Skrissub rewrite_numbers 143668651Skris{ 143768651Skris (*OUT,$name,*nums,@symbols)=@_; 143868651Skris my $thing; 143968651Skris 144068651Skris print STDERR "Rewriting $name\n"; 144168651Skris 1442109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 144368651Skris my $r; my %r; my %rsyms; 144468651Skris foreach $r (@r) { 144568651Skris (my $s, my $i) = split /\\/, $r; 144668651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 144768651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 144868651Skris $r{$a} = $s."\\".$i; 144968651Skris $rsyms{$s} = 1; 145068651Skris } 145168651Skris 1452109998Smarkm my %syms = (); 1453109998Smarkm foreach $_ (@symbols) { 1454109998Smarkm (my $n, my $i) = split /\\/; 1455109998Smarkm $syms{$n} = 1; 1456109998Smarkm } 1457109998Smarkm 1458109998Smarkm my @s=sort { 1459109998Smarkm &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") 1460109998Smarkm || $a cmp $b 1461109998Smarkm } keys %nums; 146268651Skris foreach $sym (@s) { 146368651Skris (my $n, my $i) = split /\\/, $nums{$sym}; 146468651Skris next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/; 146568651Skris next if defined($rsyms{$sym}); 1466109998Smarkm print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug; 1467109998Smarkm $i="NOEXIST::FUNCTION:" 1468109998Smarkm if !defined($i) || $i eq "" || !defined($syms{$sym}); 1469109998Smarkm my $s2 = $sym; 1470109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1471109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 147268651Skris if (exists $r{$sym}) { 147368651Skris (my $s, $i) = split /\\/,$r{$sym}; 1474109998Smarkm my $s2 = $s; 1475109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1476109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 147768651Skris } 147868651Skris } 147968651Skris} 148068651Skris 148155714Skrissub update_numbers 148255714Skris{ 148368651Skris (*OUT,$name,*nums,my $start_num, my @symbols)=@_; 148468651Skris my $new_syms = 0; 148568651Skris 148668651Skris print STDERR "Updating $name numbers\n"; 148768651Skris 1488109998Smarkm my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 148968651Skris my $r; my %r; my %rsyms; 149068651Skris foreach $r (@r) { 149168651Skris (my $s, my $i) = split /\\/, $r; 149268651Skris my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 149368651Skris $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 149468651Skris $r{$a} = $s."\\".$i; 149568651Skris $rsyms{$s} = 1; 149668651Skris } 149768651Skris 149868651Skris foreach $sym (@symbols) { 149968651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 150068651Skris next if $i =~ /^.*?:.*?:\w+\(\w+\)/; 150168651Skris next if defined($rsyms{$sym}); 150268651Skris die "ERROR: Symbol $sym had no info attached to it." 150368651Skris if $i eq ""; 150468651Skris if (!exists $nums{$s}) { 150568651Skris $new_syms++; 1506109998Smarkm my $s2 = $s; 1507109998Smarkm $s2 =~ s/\{[0-9]+\}$//; 1508109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i; 150968651Skris if (exists $r{$s}) { 151068651Skris ($s, $i) = split /\\/,$r{$s}; 1511109998Smarkm $s =~ s/\{[0-9]+\}$//; 1512109998Smarkm printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i; 151368651Skris } 151455714Skris } 151555714Skris } 151668651Skris if($new_syms) { 151768651Skris print STDERR "$new_syms New symbols added\n"; 151855714Skris } else { 151968651Skris print STDERR "No New symbols Added\n"; 152055714Skris } 152155714Skris} 152268651Skris 152368651Skrissub check_existing 152468651Skris{ 152568651Skris (*nums, my @symbols)=@_; 152668651Skris my %existing; my @remaining; 152768651Skris @remaining=(); 152868651Skris foreach $sym (@symbols) { 152968651Skris (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 153068651Skris $existing{$s}=1; 153168651Skris } 153268651Skris foreach $sym (keys %nums) { 153368651Skris if (!exists $existing{$sym}) { 153468651Skris push @remaining, $sym; 153568651Skris } 153668651Skris } 153768651Skris if(@remaining) { 153868651Skris print STDERR "The following symbols do not seem to exist:\n"; 153968651Skris foreach $sym (@remaining) { 154068651Skris print STDERR "\t",$sym,"\n"; 154168651Skris } 154268651Skris } 154368651Skris} 154468651Skris 1545