mkdef.pl revision 269682
1215976Sjmallett#!/usr/local/bin/perl -w 2232812Sjmallett# 3215976Sjmallett# generate a .def file 4215976Sjmallett# 5215976Sjmallett# It does this by parsing the header files and looking for the 6215976Sjmallett# prototyped functions: it then prunes the output. 7215976Sjmallett# 8215976Sjmallett# Intermediary files are created, call libeay.num and ssleay.num,... 9215976Sjmallett# Previously, they had the following format: 10215976Sjmallett# 11215976Sjmallett# routine-name nnnn 12215976Sjmallett# 13215976Sjmallett# But that isn't enough for a number of reasons, the first on being that 14215976Sjmallett# this format is (needlessly) very Win32-centric, and even then... 15215976Sjmallett# One of the biggest problems is that there's no information about what 16215976Sjmallett# routines should actually be used, which varies with what crypto algorithms 17215976Sjmallett# are disabled. Also, some operating systems (for example VMS with VAX C) 18232812Sjmallett# need to keep track of the global variables as well as the functions. 19215976Sjmallett# 20215976Sjmallett# So, a remake of this script is done so as to include information on the 21215976Sjmallett# kind of symbol it is (function or variable) and what algorithms they're 22215976Sjmallett# part of. This will allow easy translating to .def files or the corresponding 23215976Sjmallett# file in other operating systems (a .opt file for VMS, possibly with a .mar 24215976Sjmallett# file). 25215976Sjmallett# 26215976Sjmallett# The format now becomes: 27215976Sjmallett# 28215976Sjmallett# routine-name nnnn info 29232812Sjmallett# 30215976Sjmallett# and the "info" part is actually a colon-separated string of fields with 31215976Sjmallett# the following meaning: 32215976Sjmallett# 33215976Sjmallett# existence:platform:kind:algorithms 34215976Sjmallett# 35215976Sjmallett# - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is 36215976Sjmallett# found somewhere in the source, 37215976Sjmallett# - "platforms" is empty if it exists on all platforms, otherwise it contains 38215976Sjmallett# comma-separated list of the platform, just as they are if the symbol exists 39215976Sjmallett# for those platforms, or prepended with a "!" if not. This helps resolve 40215976Sjmallett# symbol name variants for platforms where the names are too long for the 41215976Sjmallett# compiler or linker, or if the systems is case insensitive and there is a 42215976Sjmallett# clash, or the symbol is implemented differently (see 43215976Sjmallett# EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found 44215976Sjmallett# in the file crypto/symhacks.h. 45215976Sjmallett# The semantics for the platforms is that every item is checked against the 46215976Sjmallett# environment. For the negative items ("!FOO"), if any of them is false 47215976Sjmallett# (i.e. "FOO" is true) in the environment, the corresponding symbol can't be 48215976Sjmallett# used. For the positive itms, if all of them are false in the environment, 49215976Sjmallett# the corresponding symbol can't be used. Any combination of positive and 50215976Sjmallett# negative items are possible, and of course leave room for some redundancy. 51215976Sjmallett# - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious. 52232812Sjmallett# - "algorithms" is a comma-separated list of algorithm names. This helps 53232812Sjmallett# exclude symbols that are part of an algorithm that some user wants to 54215976Sjmallett# exclude. 55215976Sjmallett# 56215976Sjmallett 57215976Sjmallettmy $debug=0; 58215976Sjmallett 59215976Sjmallettmy $crypto_num= "util/libeay.num"; 60215976Sjmallettmy $ssl_num= "util/ssleay.num"; 61232812Sjmallettmy $libname; 62232812Sjmallett 63232812Sjmallettmy $do_update = 0; 64232812Sjmallettmy $do_rewrite = 1; 65232812Sjmallettmy $do_crypto = 0; 66215976Sjmallettmy $do_ssl = 0; 67215976Sjmallettmy $do_ctest = 0; 68215976Sjmallettmy $do_ctestall = 0; 69215976Sjmallettmy $do_checkexist = 0; 70215976Sjmallett 71215976Sjmallettmy $VMSVAX=0; 72215976Sjmallettmy $VMSNonVAX=0; 73215976Sjmallettmy $VMS=0; 74215976Sjmallettmy $W32=0; 75215976Sjmallettmy $W16=0; 76215976Sjmallettmy $NT=0; 77215976Sjmallettmy $OS2=0; 78232812Sjmallett# Set this to make typesafe STACK definitions appear in DEF 79232812Sjmallettmy $safe_stack_def = 0; 80232812Sjmallett 81232812Sjmallettmy @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT", 82232812Sjmallett "EXPORT_VAR_AS_FUNCTION", "ZLIB", "OPENSSL_FIPS" ); 83215976Sjmallettmy @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" ); 84215976Sjmallettmy @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF", 85215976Sjmallett "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1", 86215976Sjmallett "SHA256", "SHA512", "RIPEMD", 87215976Sjmallett "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "ECDH", "ECDSA", "EC2M", 88215976Sjmallett "HMAC", "AES", "CAMELLIA", "SEED", "GOST", 89215976Sjmallett # EC_NISTP_64_GCC_128 90215976Sjmallett "EC_NISTP_64_GCC_128", 91215976Sjmallett # Envelope "algorithms" 92215976Sjmallett "EVP", "X509", "ASN1_TYPEDEFS", 93215976Sjmallett # Helper "algorithms" 94215976Sjmallett "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR", 95232812Sjmallett "LOCKING", 96232812Sjmallett # External "algorithms" 97232812Sjmallett "FP_API", "STDIO", "SOCK", "KRB5", "DGRAM", 98232812Sjmallett # Engines 99232812Sjmallett "STATIC_ENGINE", "ENGINE", "HW", "GMP", 100215976Sjmallett # RFC3779 101215976Sjmallett "RFC3779", 102215976Sjmallett # TLS 103215976Sjmallett "TLSEXT", "PSK", "SRP", "HEARTBEATS", 104215976Sjmallett # CMS 105215976Sjmallett "CMS", 106215976Sjmallett # CryptoAPI Engine 107215976Sjmallett "CAPIENG", 108215976Sjmallett # SSL v2 109215976Sjmallett "SSL2", 110215976Sjmallett # JPAKE 111215976Sjmallett "JPAKE", 112232812Sjmallett # NEXTPROTONEG 113232812Sjmallett "NEXTPROTONEG", 114232812Sjmallett # Deprecated functions 115232812Sjmallett "DEPRECATED", 116232812Sjmallett # Hide SSL internals 117215976Sjmallett "SSL_INTERN", 118215976Sjmallett # SCTP 119215976Sjmallett "SCTP", 120215976Sjmallett # Unit testing 121215976Sjmallett "UNIT_TEST"); 122215976Sjmallett 123215976Sjmallettmy $options=""; 124215976Sjmallettopen(IN,"<Makefile") || die "unable to open Makefile!\n"; 125215976Sjmallettwhile(<IN>) { 126215976Sjmallett $options=$1 if (/^OPTIONS=(.*)$/); 127215976Sjmallett} 128215976Sjmallettclose(IN); 129232812Sjmallett 130232812Sjmallett# The following ciphers may be excluded (by Configure). This means functions 131232812Sjmallett# defined with ifndef(NO_XXX) are not included in the .def file, and everything 132232812Sjmallett# in directory xxx is ignored. 133232812Sjmallettmy $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf; 134215976Sjmallettmy $no_cast; my $no_whirlpool; my $no_camellia; my $no_seed; 135215976Sjmallettmy $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2; 136215976Sjmallettmy $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5; 137215976Sjmallettmy $no_ec; my $no_ecdsa; my $no_ecdh; my $no_engine; my $no_hw; 138215976Sjmallettmy $no_fp_api; my $no_static_engine=1; my $no_gmp; my $no_deprecated; 139215976Sjmallettmy $no_rfc3779; my $no_psk; my $no_tlsext; my $no_cms; my $no_capieng; 140215976Sjmallettmy $no_jpake; my $no_srp; my $no_ssl2; my $no_ec2m; my $no_nistp_gcc; 141215976Sjmallettmy $no_nextprotoneg; my $no_sctp; 142215976Sjmallettmy $no_unit_test; 143215976Sjmallett 144215976Sjmallettmy $fips; 145215976Sjmallett 146232812Sjmallettmy $zlib; 147232812Sjmallett 148232812Sjmallett 149232812Sjmallettforeach (@ARGV, split(/ /, $options)) 150232812Sjmallett { 151215976Sjmallett $debug=1 if $_ eq "debug"; 152215976Sjmallett $W32=1 if $_ eq "32"; 153215976Sjmallett $W16=1 if $_ eq "16"; 154215976Sjmallett if($_ eq "NT") { 155215976Sjmallett $W32 = 1; 156215976Sjmallett $NT = 1; 157215976Sjmallett } 158215976Sjmallett if ($_ eq "VMS-VAX") { 159215976Sjmallett $VMS=1; 160215976Sjmallett $VMSVAX=1; 161215976Sjmallett } 162215976Sjmallett if ($_ eq "VMS-NonVAX") { 163232812Sjmallett $VMS=1; 164232812Sjmallett $VMSNonVAX=1; 165232812Sjmallett } 166232812Sjmallett $VMS=1 if $_ eq "VMS"; 167232812Sjmallett $OS2=1 if $_ eq "OS2"; 168215976Sjmallett $fips=1 if /^fips/; 169215976Sjmallett if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic" 170215976Sjmallett || $_ eq "enable-zlib-dynamic") { 171215976Sjmallett $zlib = 1; 172215976Sjmallett } 173215976Sjmallett 174215976Sjmallett $do_ssl=1 if $_ eq "ssleay"; 175215976Sjmallett if ($_ eq "ssl") { 176215976Sjmallett $do_ssl=1; 177215976Sjmallett $libname=$_ 178215976Sjmallett } 179215976Sjmallett $do_crypto=1 if $_ eq "libeay"; 180232812Sjmallett if ($_ eq "crypto") { 181232812Sjmallett $do_crypto=1; 182232812Sjmallett $libname=$_; 183232812Sjmallett } 184232812Sjmallett $no_static_engine=1 if $_ eq "no-static-engine"; 185215976Sjmallett $no_static_engine=0 if $_ eq "enable-static-engine"; 186215976Sjmallett $do_update=1 if $_ eq "update"; 187215976Sjmallett $do_rewrite=1 if $_ eq "rewrite"; 188215976Sjmallett $do_ctest=1 if $_ eq "ctest"; 189215976Sjmallett $do_ctestall=1 if $_ eq "ctestall"; 190215976Sjmallett $do_checkexist=1 if $_ eq "exist"; 191215976Sjmallett #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK"; 192215976Sjmallett 193215976Sjmallett if (/^no-rc2$/) { $no_rc2=1; } 194215976Sjmallett elsif (/^no-rc4$/) { $no_rc4=1; } 195215976Sjmallett elsif (/^no-rc5$/) { $no_rc5=1; } 196215976Sjmallett elsif (/^no-idea$/) { $no_idea=1; } 197232812Sjmallett elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; } 198232812Sjmallett elsif (/^no-bf$/) { $no_bf=1; } 199232812Sjmallett elsif (/^no-cast$/) { $no_cast=1; } 200232812Sjmallett elsif (/^no-whirlpool$/) { $no_whirlpool=1; } 201232812Sjmallett elsif (/^no-md2$/) { $no_md2=1; } 202215976Sjmallett elsif (/^no-md4$/) { $no_md4=1; } 203215976Sjmallett elsif (/^no-md5$/) { $no_md5=1; } 204215976Sjmallett elsif (/^no-sha$/) { $no_sha=1; } 205215976Sjmallett elsif (/^no-ripemd$/) { $no_ripemd=1; } 206215976Sjmallett elsif (/^no-mdc2$/) { $no_mdc2=1; } 207215976Sjmallett elsif (/^no-rsa$/) { $no_rsa=1; } 208215976Sjmallett elsif (/^no-dsa$/) { $no_dsa=1; } 209215976Sjmallett elsif (/^no-dh$/) { $no_dh=1; } 210215976Sjmallett elsif (/^no-ec$/) { $no_ec=1; } 211215976Sjmallett elsif (/^no-ecdsa$/) { $no_ecdsa=1; } 212215976Sjmallett elsif (/^no-ecdh$/) { $no_ecdh=1; } 213215976Sjmallett elsif (/^no-hmac$/) { $no_hmac=1; } 214232812Sjmallett elsif (/^no-aes$/) { $no_aes=1; } 215232812Sjmallett elsif (/^no-camellia$/) { $no_camellia=1; } 216232812Sjmallett elsif (/^no-seed$/) { $no_seed=1; } 217232812Sjmallett elsif (/^no-evp$/) { $no_evp=1; } 218232812Sjmallett elsif (/^no-lhash$/) { $no_lhash=1; } 219215976Sjmallett elsif (/^no-stack$/) { $no_stack=1; } 220215976Sjmallett elsif (/^no-err$/) { $no_err=1; } 221215976Sjmallett elsif (/^no-buffer$/) { $no_buffer=1; } 222215976Sjmallett elsif (/^no-bio$/) { $no_bio=1; } 223215976Sjmallett #elsif (/^no-locking$/) { $no_locking=1; } 224215976Sjmallett elsif (/^no-comp$/) { $no_comp=1; } 225215976Sjmallett elsif (/^no-dso$/) { $no_dso=1; } 226215976Sjmallett elsif (/^no-krb5$/) { $no_krb5=1; } 227215976Sjmallett elsif (/^no-engine$/) { $no_engine=1; } 228215976Sjmallett elsif (/^no-hw$/) { $no_hw=1; } 229215976Sjmallett elsif (/^no-gmp$/) { $no_gmp=1; } 230215976Sjmallett elsif (/^no-rfc3779$/) { $no_rfc3779=1; } 231232812Sjmallett elsif (/^no-tlsext$/) { $no_tlsext=1; } 232232812Sjmallett elsif (/^no-cms$/) { $no_cms=1; } 233232812Sjmallett elsif (/^no-ec2m$/) { $no_ec2m=1; } 234232812Sjmallett elsif (/^no-ec_nistp_64_gcc_128$/) { $no_nistp_gcc=1; } 235232812Sjmallett elsif (/^no-nextprotoneg$/) { $no_nextprotoneg=1; } 236215976Sjmallett elsif (/^no-ssl2$/) { $no_ssl2=1; } 237215976Sjmallett elsif (/^no-capieng$/) { $no_capieng=1; } 238215976Sjmallett elsif (/^no-jpake$/) { $no_jpake=1; } 239215976Sjmallett elsif (/^no-srp$/) { $no_srp=1; } 240215976Sjmallett elsif (/^no-sctp$/) { $no_sctp=1; } 241215976Sjmallett elsif (/^no-unit-test$/){ $no_unit_test=1; } 242215976Sjmallett } 243215976Sjmallett 244215976Sjmallett 245215976Sjmallettif (!$libname) { 246215976Sjmallett if ($do_ssl) { 247215976Sjmallett $libname="SSLEAY"; 248232812Sjmallett } 249232812Sjmallett if ($do_crypto) { 250232812Sjmallett $libname="LIBEAY"; 251232812Sjmallett } 252232812Sjmallett} 253215976Sjmallett 254215976Sjmallett# If no platform is given, assume WIN32 255215976Sjmallettif ($W32 + $W16 + $VMS + $OS2 == 0) { 256215976Sjmallett $W32 = 1; 257215976Sjmallett} 258215976Sjmallett 259215976Sjmallett# Add extra knowledge 260215976Sjmallettif ($W16) { 261215976Sjmallett $no_fp_api=1; 262215976Sjmallett} 263215976Sjmallett 264215976Sjmallettif (!$do_ssl && !$do_crypto) 265232812Sjmallett { 266232812Sjmallett print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n"; 267232812Sjmallett exit(1); 268232812Sjmallett } 269232812Sjmallett 270215976Sjmallett%ssl_list=&load_numbers($ssl_num); 271215976Sjmallett$max_ssl = $max_num; 272215976Sjmallett%crypto_list=&load_numbers($crypto_num); 273215976Sjmallett$max_crypto = $max_num; 274215976Sjmallett 275215976Sjmallettmy $ssl="ssl/ssl.h"; 276215976Sjmallett$ssl.=" ssl/kssl.h"; 277215976Sjmallett$ssl.=" ssl/tls1.h"; 278215976Sjmallett$ssl.=" ssl/srtp.h"; 279215976Sjmallett 280215976Sjmallettmy $crypto ="crypto/crypto.h"; 281215976Sjmallett$crypto.=" crypto/cryptlib.h"; 282232812Sjmallett$crypto.=" crypto/o_dir.h"; 283232812Sjmallett$crypto.=" crypto/o_str.h"; 284232812Sjmallett$crypto.=" crypto/o_time.h"; 285232812Sjmallett$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des; 286232812Sjmallett$crypto.=" crypto/idea/idea.h" ; # unless $no_idea; 287215976Sjmallett$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4; 288215976Sjmallett$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5; 289215976Sjmallett$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2; 290215976Sjmallett$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf; 291215976Sjmallett$crypto.=" crypto/cast/cast.h" ; # unless $no_cast; 292215976Sjmallett$crypto.=" crypto/whrlpool/whrlpool.h" ; 293215976Sjmallett$crypto.=" crypto/md2/md2.h" ; # unless $no_md2; 294215976Sjmallett$crypto.=" crypto/md4/md4.h" ; # unless $no_md4; 295215976Sjmallett$crypto.=" crypto/md5/md5.h" ; # unless $no_md5; 296215976Sjmallett$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2; 297215976Sjmallett$crypto.=" crypto/sha/sha.h" ; # unless $no_sha; 298215976Sjmallett$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd; 299232812Sjmallett$crypto.=" crypto/aes/aes.h" ; # unless $no_aes; 300232812Sjmallett$crypto.=" crypto/camellia/camellia.h" ; # unless $no_camellia; 301232812Sjmallett$crypto.=" crypto/seed/seed.h"; # unless $no_seed; 302232812Sjmallett 303232812Sjmallett$crypto.=" crypto/bn/bn.h"; 304215976Sjmallett$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa; 305215976Sjmallett$crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa; 306215976Sjmallett$crypto.=" crypto/dh/dh.h" ; # unless $no_dh; 307215976Sjmallett$crypto.=" crypto/ec/ec.h" ; # unless $no_ec; 308215976Sjmallett$crypto.=" crypto/ecdsa/ecdsa.h" ; # unless $no_ecdsa; 309215976Sjmallett$crypto.=" crypto/ecdh/ecdh.h" ; # unless $no_ecdh; 310215976Sjmallett$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac; 311215976Sjmallett$crypto.=" crypto/cmac/cmac.h" ; # unless $no_hmac; 312215976Sjmallett 313215976Sjmallett$crypto.=" crypto/engine/engine.h"; # unless $no_engine; 314215976Sjmallett$crypto.=" crypto/stack/stack.h" ; # unless $no_stack; 315215976Sjmallett$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer; 316232812Sjmallett$crypto.=" crypto/bio/bio.h" ; # unless $no_bio; 317232812Sjmallett$crypto.=" crypto/dso/dso.h" ; # unless $no_dso; 318232812Sjmallett$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash; 319232812Sjmallett$crypto.=" crypto/conf/conf.h"; 320232812Sjmallett$crypto.=" crypto/txt_db/txt_db.h"; 321215976Sjmallett 322215976Sjmallett$crypto.=" crypto/evp/evp.h" ; # unless $no_evp; 323215976Sjmallett$crypto.=" crypto/objects/objects.h"; 324215976Sjmallett$crypto.=" crypto/pem/pem.h"; 325215976Sjmallett#$crypto.=" crypto/meth/meth.h"; 326215976Sjmallett$crypto.=" crypto/asn1/asn1.h"; 327215976Sjmallett$crypto.=" crypto/asn1/asn1t.h"; 328215976Sjmallett$crypto.=" crypto/asn1/asn1_mac.h"; 329215976Sjmallett$crypto.=" crypto/err/err.h" ; # unless $no_err; 330215976Sjmallett$crypto.=" crypto/pkcs7/pkcs7.h"; 331215976Sjmallett$crypto.=" crypto/pkcs12/pkcs12.h"; 332215976Sjmallett$crypto.=" crypto/x509/x509.h"; 333232812Sjmallett$crypto.=" crypto/x509/x509_vfy.h"; 334232812Sjmallett$crypto.=" crypto/x509v3/x509v3.h"; 335232812Sjmallett$crypto.=" crypto/ts/ts.h"; 336232812Sjmallett$crypto.=" crypto/rand/rand.h"; 337232812Sjmallett$crypto.=" crypto/comp/comp.h" ; # unless $no_comp; 338215976Sjmallett$crypto.=" crypto/ocsp/ocsp.h"; 339215976Sjmallett$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h"; 340215976Sjmallett$crypto.=" crypto/krb5/krb5_asn.h"; 341215976Sjmallett#$crypto.=" crypto/store/store.h"; 342215976Sjmallett$crypto.=" crypto/pqueue/pqueue.h"; 343215976Sjmallett$crypto.=" crypto/cms/cms.h"; 344215976Sjmallett$crypto.=" crypto/jpake/jpake.h"; 345215976Sjmallett$crypto.=" crypto/modes/modes.h"; 346215976Sjmallett$crypto.=" crypto/srp/srp.h"; 347215976Sjmallett 348215976Sjmallettmy $symhacks="crypto/symhacks.h"; 349215976Sjmallett 350232812Sjmallettmy @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks); 351232812Sjmallettmy @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks); 352232812Sjmallett 353232812Sjmallettif ($do_update) { 354232812Sjmallett 355215976Sjmallettif ($do_ssl == 1) { 356215976Sjmallett 357215976Sjmallett &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols); 358215976Sjmallett if ($do_rewrite == 1) { 359215976Sjmallett open(OUT, ">$ssl_num"); 360215976Sjmallett &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols); 361215976Sjmallett } else { 362215976Sjmallett open(OUT, ">>$ssl_num"); 363215976Sjmallett } 364215976Sjmallett &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols); 365215976Sjmallett close OUT; 366215976Sjmallett} 367232812Sjmallett 368232812Sjmallettif($do_crypto == 1) { 369232812Sjmallett 370232812Sjmallett &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols); 371232812Sjmallett if ($do_rewrite == 1) { 372215976Sjmallett open(OUT, ">$crypto_num"); 373215976Sjmallett &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols); 374215976Sjmallett } else { 375215976Sjmallett open(OUT, ">>$crypto_num"); 376215976Sjmallett } 377215976Sjmallett &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols); 378215976Sjmallett close OUT; 379215976Sjmallett} 380215976Sjmallett 381215976Sjmallett} elsif ($do_checkexist) { 382215976Sjmallett &check_existing(*ssl_list, @ssl_symbols) 383215976Sjmallett if $do_ssl == 1; 384232812Sjmallett &check_existing(*crypto_list, @crypto_symbols) 385232812Sjmallett if $do_crypto == 1; 386232812Sjmallett} elsif ($do_ctest || $do_ctestall) { 387232812Sjmallett 388232812Sjmallett print <<"EOF"; 389215976Sjmallett 390215976Sjmallett/* Test file to check all DEF file symbols are present by trying 391215976Sjmallett * to link to all of them. This is *not* intended to be run! 392215976Sjmallett */ 393215976Sjmallett 394215976Sjmallettint main() 395215976Sjmallett{ 396215976SjmallettEOF 397215976Sjmallett &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols) 398215976Sjmallett if $do_ssl == 1; 399215976Sjmallett 400215976Sjmallett &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols) 401232812Sjmallett if $do_crypto == 1; 402232812Sjmallett 403232812Sjmallett print "}\n"; 404232812Sjmallett 405232812Sjmallett} else { 406215976Sjmallett 407215976Sjmallett &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols) 408215976Sjmallett if $do_ssl == 1; 409215976Sjmallett 410215976Sjmallett &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols) 411215976Sjmallett if $do_crypto == 1; 412215976Sjmallett 413215976Sjmallett} 414215976Sjmallett 415215976Sjmallett 416215976Sjmallettsub do_defs 417215976Sjmallett{ 418232812Sjmallett my($name,$files,$symhacksfile)=@_; 419232812Sjmallett my $file; 420232812Sjmallett my @ret; 421232812Sjmallett my %syms; 422232812Sjmallett my %platform; # For anything undefined, we assume "" 423215976Sjmallett my %kind; # For anything undefined, we assume "FUNCTION" 424215976Sjmallett my %algorithm; # For anything undefined, we assume "" 425215976Sjmallett my %variant; 426215976Sjmallett my %variant_cnt; # To be able to allocate "name{n}" if "name" 427215976Sjmallett # is the same name as the original. 428215976Sjmallett my $cpp; 429215976Sjmallett my %unknown_algorithms = (); 430215976Sjmallett 431215976Sjmallett foreach $file (split(/\s+/,$symhacksfile." ".$files)) 432215976Sjmallett { 433215976Sjmallett print STDERR "DEBUG: starting on $file:\n" if $debug; 434215976Sjmallett open(IN,"<$file") || die "unable to open $file:$!\n"; 435232812Sjmallett my $line = "", my $def= ""; 436232812Sjmallett my %tag = ( 437232812Sjmallett (map { $_ => 0 } @known_platforms), 438232812Sjmallett (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms), 439232812Sjmallett (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms), 440215976Sjmallett NOPROTO => 0, 441215976Sjmallett PERL5 => 0, 442215976Sjmallett _WINDLL => 0, 443215976Sjmallett CONST_STRICT => 0, 444215976Sjmallett TRUE => 1, 445215976Sjmallett ); 446215976Sjmallett my $symhacking = $file eq $symhacksfile; 447215976Sjmallett my @current_platforms = (); 448215976Sjmallett my @current_algorithms = (); 449215976Sjmallett 450215976Sjmallett # params: symbol, alias, platforms, kind 451215976Sjmallett # The reason to put this subroutine in a variable is that 452232812Sjmallett # it will otherwise create it's own, unshared, version of 453232812Sjmallett # %tag and %variant... 454232812Sjmallett my $make_variant = sub 455232812Sjmallett { 456232812Sjmallett my ($s, $a, $p, $k) = @_; 457215976Sjmallett my ($a1, $a2); 458215976Sjmallett 459215976Sjmallett print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug; 460215976Sjmallett if (defined($p)) 461215976Sjmallett { 462215976Sjmallett $a1 = join(",",$p, 463215976Sjmallett grep(!/^$/, 464215976Sjmallett map { $tag{$_} == 1 ? $_ : "" } 465215976Sjmallett @known_platforms)); 466215976Sjmallett } 467215976Sjmallett else 468215976Sjmallett { 469232812Sjmallett $a1 = join(",", 470232812Sjmallett grep(!/^$/, 471232812Sjmallett map { $tag{$_} == 1 ? $_ : "" } 472232812Sjmallett @known_platforms)); 473232812Sjmallett } 474215976Sjmallett $a2 = join(",", 475215976Sjmallett grep(!/^$/, 476215976Sjmallett map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" } 477215976Sjmallett @known_ossl_platforms)); 478215976Sjmallett print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug; 479215976Sjmallett if ($a1 eq "") { $a1 = $a2; } 480215976Sjmallett elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; } 481215976Sjmallett if ($a eq $s) 482215976Sjmallett { 483215976Sjmallett if (!defined($variant_cnt{$s})) 484215976Sjmallett { 485215976Sjmallett $variant_cnt{$s} = 0; 486232812Sjmallett } 487232812Sjmallett $variant_cnt{$s}++; 488232812Sjmallett $a .= "{$variant_cnt{$s}}"; 489232812Sjmallett } 490232812Sjmallett my $toadd = $a.":".$a1.(defined($k)?":".$k:""); 491215976Sjmallett my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:""); 492215976Sjmallett if (!grep(/^$togrep$/, 493215976Sjmallett split(/;/, defined($variant{$s})?$variant{$s}:""))) { 494215976Sjmallett if (defined($variant{$s})) { $variant{$s} .= ";"; } 495215976Sjmallett $variant{$s} .= $toadd; 496215976Sjmallett } 497215976Sjmallett print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug; 498215976Sjmallett }; 499215976Sjmallett 500215976Sjmallett print STDERR "DEBUG: parsing ----------\n" if $debug; 501215976Sjmallett while(<IN>) { 502215976Sjmallett if (/\/\* Error codes for the \w+ functions\. \*\//) 503232812Sjmallett { 504232812Sjmallett undef @tag; 505232812Sjmallett last; 506232812Sjmallett } 507232812Sjmallett if ($line ne '') { 508215976Sjmallett $_ = $line . $_; 509215976Sjmallett $line = ''; 510215976Sjmallett } 511215976Sjmallett 512215976Sjmallett if (/\\$/) { 513215976Sjmallett chomp; # remove eol 514215976Sjmallett chop; # remove ending backslash 515215976Sjmallett $line = $_; 516215976Sjmallett next; 517215976Sjmallett } 518215976Sjmallett 519215976Sjmallett if(/\/\*/) { 520232812Sjmallett if (not /\*\//) { # multiline comment... 521232812Sjmallett $line = $_; # ... just accumulate 522232812Sjmallett next; 523232812Sjmallett } else { 524232812Sjmallett s/\/\*.*?\*\///gs;# wipe it 525215976Sjmallett } 526215976Sjmallett } 527215976Sjmallett 528215976Sjmallett if ($cpp) { 529215976Sjmallett $cpp++ if /^#\s*if/; 530215976Sjmallett $cpp-- if /^#\s*endif/; 531215976Sjmallett next; 532215976Sjmallett } 533215976Sjmallett $cpp = 1 if /^#.*ifdef.*cplusplus/; 534215976Sjmallett 535215976Sjmallett s/{[^{}]*}//gs; # ignore {} blocks 536215976Sjmallett print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne ""; 537232812Sjmallett print STDERR "DEBUG: \$_=\"$_\"\n" if $debug; 538232812Sjmallett if (/^\#\s*ifndef\s+(.*)/) { 539232812Sjmallett push(@tag,"-"); 540232812Sjmallett push(@tag,$1); 541232812Sjmallett $tag{$1}=-1; 542215976Sjmallett print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 543215976Sjmallett } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) { 544215976Sjmallett push(@tag,"-"); 545215976Sjmallett if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) { 546215976Sjmallett my $tmp_1 = $1; 547215976Sjmallett my $tmp_; 548215976Sjmallett foreach $tmp_ (split '\&\&',$tmp_1) { 549215976Sjmallett $tmp_ =~ /!defined\(([^\)]+)\)/; 550215976Sjmallett print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 551215976Sjmallett push(@tag,$1); 552215976Sjmallett $tag{$1}=-1; 553215976Sjmallett } 554232812Sjmallett } else { 555232812Sjmallett print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O... 556232812Sjmallett print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; 557232812Sjmallett push(@tag,$1); 558232812Sjmallett $tag{$1}=-1; 559215976Sjmallett } 560215976Sjmallett } elsif (/^\#\s*ifdef\s+(\S*)/) { 561215976Sjmallett push(@tag,"-"); 562215976Sjmallett push(@tag,$1); 563215976Sjmallett $tag{$1}=1; 564215976Sjmallett print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 565215976Sjmallett } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) { 566215976Sjmallett push(@tag,"-"); 567215976Sjmallett if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) { 568215976Sjmallett my $tmp_1 = $1; 569215976Sjmallett my $tmp_; 570215976Sjmallett foreach $tmp_ (split '\|\|',$tmp_1) { 571232812Sjmallett $tmp_ =~ /defined\(([^\)]+)\)/; 572232812Sjmallett print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 573232812Sjmallett push(@tag,$1); 574232812Sjmallett $tag{$1}=1; 575232812Sjmallett } 576215976Sjmallett } else { 577215976Sjmallett print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O... 578215976Sjmallett print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; 579215976Sjmallett push(@tag,$1); 580215976Sjmallett $tag{$1}=1; 581215976Sjmallett } 582215976Sjmallett } elsif (/^\#\s*error\s+(\w+) is disabled\./) { 583215976Sjmallett my $tag_i = $#tag; 584215976Sjmallett while($tag[$tag_i] ne "-") { 585215976Sjmallett if ($tag[$tag_i] eq "OPENSSL_NO_".$1) { 586215976Sjmallett $tag{$tag[$tag_i]}=2; 587215976Sjmallett print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug; 588232812Sjmallett } 589232812Sjmallett $tag_i--; 590232812Sjmallett } 591232812Sjmallett } elsif (/^\#\s*endif/) { 592232812Sjmallett my $tag_i = $#tag; 593215976Sjmallett while($tag_i > 0 && $tag[$tag_i] ne "-") { 594215976Sjmallett my $t=$tag[$tag_i]; 595215976Sjmallett print STDERR "DEBUG: \$t=\"$t\"\n" if $debug; 596215976Sjmallett if ($tag{$t}==2) { 597215976Sjmallett $tag{$t}=-1; 598215976Sjmallett } else { 599215976Sjmallett $tag{$t}=0; 600215976Sjmallett } 601215976Sjmallett print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 602215976Sjmallett pop(@tag); 603215976Sjmallett if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) { 604215976Sjmallett $t=$1; 605232812Sjmallett } else { 606232812Sjmallett $t=""; 607232812Sjmallett } 608232812Sjmallett if ($t ne "" 609232812Sjmallett && !grep(/^$t$/, @known_algorithms)) { 610215976Sjmallett $unknown_algorithms{$t} = 1; 611215976Sjmallett #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug; 612215976Sjmallett } 613215976Sjmallett $tag_i--; 614215976Sjmallett } 615215976Sjmallett pop(@tag); 616215976Sjmallett } elsif (/^\#\s*else/) { 617215976Sjmallett my $tag_i = $#tag; 618215976Sjmallett while($tag[$tag_i] ne "-") { 619215976Sjmallett my $t=$tag[$tag_i]; 620215976Sjmallett $tag{$t}= -$tag{$t}; 621215976Sjmallett print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; 622215976Sjmallett $tag_i--; 623215976Sjmallett } 624215976Sjmallett } elsif (/^\#\s*if\s+1/) { 625215976Sjmallett push(@tag,"-"); 626215976Sjmallett # Dummy tag 627215976Sjmallett push(@tag,"TRUE"); 628215976Sjmallett $tag{"TRUE"}=1; 629215976Sjmallett print STDERR "DEBUG: $file: found 1\n" if $debug; 630215976Sjmallett } elsif (/^\#\s*if\s+0/) { 631215976Sjmallett push(@tag,"-"); 632215976Sjmallett # Dummy tag 633215976Sjmallett push(@tag,"TRUE"); 634215976Sjmallett $tag{"TRUE"}=-1; 635215976Sjmallett print STDERR "DEBUG: $file: found 0\n" if $debug; 636215976Sjmallett } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/ 637215976Sjmallett && $symhacking && $tag{'TRUE'} != -1) { 638215976Sjmallett # This is for aliasing. When we find an alias, 639215976Sjmallett # we have to invert 640215976Sjmallett &$make_variant($1,$2); 641215976Sjmallett print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug; 642215976Sjmallett } 643215976Sjmallett if (/^\#/) { 644215976Sjmallett @current_platforms = 645215976Sjmallett grep(!/^$/, 646215976Sjmallett map { $tag{$_} == 1 ? $_ : 647215976Sjmallett $tag{$_} == -1 ? "!".$_ : "" } 648232812Sjmallett @known_platforms); 649232812Sjmallett push @current_platforms 650232812Sjmallett , grep(!/^$/, 651232812Sjmallett map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : 652232812Sjmallett $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" } 653215976Sjmallett @known_ossl_platforms); 654215976Sjmallett @current_algorithms = 655215976Sjmallett grep(!/^$/, 656215976Sjmallett map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" } 657215976Sjmallett @known_algorithms); 658215976Sjmallett $def .= 659215976Sjmallett "#INFO:" 660215976Sjmallett .join(',',@current_platforms).":" 661215976Sjmallett .join(',',@current_algorithms).";"; 662215976Sjmallett next; 663215976Sjmallett } 664215976Sjmallett if ($tag{'TRUE'} != -1) { 665232812Sjmallett if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { 666232812Sjmallett next; 667232812Sjmallett } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 668232812Sjmallett $def .= "int d2i_$3(void);"; 669232812Sjmallett $def .= "int i2d_$3(void);"; 670215976Sjmallett # Variant for platforms that do not 671215976Sjmallett # have to access globale variables 672215976Sjmallett # in shared libraries through functions 673215976Sjmallett $def .= 674215976Sjmallett "#INFO:" 675215976Sjmallett .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 676215976Sjmallett .join(',',@current_algorithms).";"; 677215976Sjmallett $def .= "OPENSSL_EXTERN int $2_it;"; 678215976Sjmallett $def .= 679215976Sjmallett "#INFO:" 680215976Sjmallett .join(',',@current_platforms).":" 681215976Sjmallett .join(',',@current_algorithms).";"; 682232812Sjmallett # Variant for platforms that have to 683232812Sjmallett # access globale variables in shared 684232812Sjmallett # libraries through functions 685232812Sjmallett &$make_variant("$2_it","$2_it", 686232812Sjmallett "EXPORT_VAR_AS_FUNCTION", 687215976Sjmallett "FUNCTION"); 688215976Sjmallett next; 689215976Sjmallett } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { 690215976Sjmallett $def .= "int d2i_$3(void);"; 691215976Sjmallett $def .= "int i2d_$3(void);"; 692215976Sjmallett $def .= "int $3_free(void);"; 693215976Sjmallett $def .= "int $3_new(void);"; 694215976Sjmallett # Variant for platforms that do not 695215976Sjmallett # have to access globale variables 696215976Sjmallett # in shared libraries through functions 697215976Sjmallett $def .= 698215976Sjmallett "#INFO:" 699232812Sjmallett .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 700232812Sjmallett .join(',',@current_algorithms).";"; 701232812Sjmallett $def .= "OPENSSL_EXTERN int $2_it;"; 702232812Sjmallett $def .= 703232812Sjmallett "#INFO:" 704215976Sjmallett .join(',',@current_platforms).":" 705215976Sjmallett .join(',',@current_algorithms).";"; 706215976Sjmallett # Variant for platforms that have to 707215976Sjmallett # access globale variables in shared 708215976Sjmallett # libraries through functions 709215976Sjmallett &$make_variant("$2_it","$2_it", 710215976Sjmallett "EXPORT_VAR_AS_FUNCTION", 711215976Sjmallett "FUNCTION"); 712215976Sjmallett next; 713215976Sjmallett } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ || 714215976Sjmallett /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) { 715215976Sjmallett $def .= "int d2i_$1(void);"; 716215976Sjmallett $def .= "int i2d_$1(void);"; 717215976Sjmallett $def .= "int $1_free(void);"; 718215976Sjmallett $def .= "int $1_new(void);"; 719215976Sjmallett # Variant for platforms that do not 720215976Sjmallett # have to access globale variables 721215976Sjmallett # in shared libraries through functions 722215976Sjmallett $def .= 723215976Sjmallett "#INFO:" 724215976Sjmallett .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 725215976Sjmallett .join(',',@current_algorithms).";"; 726215976Sjmallett $def .= "OPENSSL_EXTERN int $1_it;"; 727215976Sjmallett $def .= 728215976Sjmallett "#INFO:" 729215976Sjmallett .join(',',@current_platforms).":" 730215976Sjmallett .join(',',@current_algorithms).";"; 731215976Sjmallett # Variant for platforms that have to 732215976Sjmallett # access globale variables in shared 733215976Sjmallett # libraries through functions 734215976Sjmallett &$make_variant("$1_it","$1_it", 735215976Sjmallett "EXPORT_VAR_AS_FUNCTION", 736215976Sjmallett "FUNCTION"); 737215976Sjmallett next; 738215976Sjmallett } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 739215976Sjmallett $def .= "int d2i_$2(void);"; 740215976Sjmallett $def .= "int i2d_$2(void);"; 741215976Sjmallett # Variant for platforms that do not 742232812Sjmallett # have to access globale variables 743232812Sjmallett # in shared libraries through functions 744232812Sjmallett $def .= 745232812Sjmallett "#INFO:" 746232812Sjmallett .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 747215976Sjmallett .join(',',@current_algorithms).";"; 748215976Sjmallett $def .= "OPENSSL_EXTERN int $2_it;"; 749215976Sjmallett $def .= 750215976Sjmallett "#INFO:" 751215976Sjmallett .join(',',@current_platforms).":" 752215976Sjmallett .join(',',@current_algorithms).";"; 753215976Sjmallett # Variant for platforms that have to 754215976Sjmallett # access globale variables in shared 755215976Sjmallett # libraries through functions 756215976Sjmallett &$make_variant("$2_it","$2_it", 757215976Sjmallett "EXPORT_VAR_AS_FUNCTION", 758215976Sjmallett "FUNCTION"); 759232812Sjmallett next; 760232812Sjmallett } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) { 761232812Sjmallett $def .= "int $1_free(void);"; 762232812Sjmallett $def .= "int $1_new(void);"; 763232812Sjmallett next; 764215976Sjmallett } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 765215976Sjmallett $def .= "int d2i_$2(void);"; 766215976Sjmallett $def .= "int i2d_$2(void);"; 767215976Sjmallett $def .= "int $2_free(void);"; 768215976Sjmallett $def .= "int $2_new(void);"; 769215976Sjmallett # Variant for platforms that do not 770215976Sjmallett # have to access globale variables 771215976Sjmallett # in shared libraries through functions 772215976Sjmallett $def .= 773215976Sjmallett "#INFO:" 774215976Sjmallett .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 775215976Sjmallett .join(',',@current_algorithms).";"; 776232812Sjmallett $def .= "OPENSSL_EXTERN int $2_it;"; 777232812Sjmallett $def .= 778232812Sjmallett "#INFO:" 779232812Sjmallett .join(',',@current_platforms).":" 780232812Sjmallett .join(',',@current_algorithms).";"; 781215976Sjmallett # Variant for platforms that have to 782215976Sjmallett # access globale variables in shared 783215976Sjmallett # libraries through functions 784215976Sjmallett &$make_variant("$2_it","$2_it", 785215976Sjmallett "EXPORT_VAR_AS_FUNCTION", 786215976Sjmallett "FUNCTION"); 787215976Sjmallett next; 788215976Sjmallett } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) { 789215976Sjmallett # Variant for platforms that do not 790215976Sjmallett # have to access globale variables 791215976Sjmallett # in shared libraries through functions 792215976Sjmallett $def .= 793232812Sjmallett "#INFO:" 794232812Sjmallett .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 795232812Sjmallett .join(',',@current_algorithms).";"; 796232812Sjmallett $def .= "OPENSSL_EXTERN int $1_it;"; 797232812Sjmallett $def .= 798215976Sjmallett "#INFO:" 799215976Sjmallett .join(',',@current_platforms).":" 800215976Sjmallett .join(',',@current_algorithms).";"; 801215976Sjmallett # Variant for platforms that have to 802215976Sjmallett # access globale variables in shared 803215976Sjmallett # libraries through functions 804215976Sjmallett &$make_variant("$1_it","$1_it", 805215976Sjmallett "EXPORT_VAR_AS_FUNCTION", 806215976Sjmallett "FUNCTION"); 807215976Sjmallett next; 808215976Sjmallett } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) { 809215976Sjmallett $def .= "int i2d_$1_NDEF(void);"; 810232812Sjmallett } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { 811232812Sjmallett next; 812232812Sjmallett } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) { 813232812Sjmallett $def .= "int $1_print_ctx(void);"; 814232812Sjmallett next; 815215976Sjmallett } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 816215976Sjmallett $def .= "int $2_print_ctx(void);"; 817215976Sjmallett next; 818215976Sjmallett } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) { 819215976Sjmallett next; 820215976Sjmallett } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || 821215976Sjmallett /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ || 822215976Sjmallett /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) { 823215976Sjmallett # Things not in Win16 824215976Sjmallett $def .= 825215976Sjmallett "#INFO:" 826215976Sjmallett .join(',',"!WIN16",@current_platforms).":" 827232812Sjmallett .join(',',@current_algorithms).";"; 828232812Sjmallett $def .= "int PEM_read_$1(void);"; 829232812Sjmallett $def .= "int PEM_write_$1(void);"; 830232812Sjmallett $def .= 831232812Sjmallett "#INFO:" 832215976Sjmallett .join(',',@current_platforms).":" 833215976Sjmallett .join(',',@current_algorithms).";"; 834215976Sjmallett # Things that are everywhere 835215976Sjmallett $def .= "int PEM_read_bio_$1(void);"; 836215976Sjmallett $def .= "int PEM_write_bio_$1(void);"; 837215976Sjmallett next; 838215976Sjmallett } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ || 839215976Sjmallett /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) { 840215976Sjmallett # Things not in Win16 841215976Sjmallett $def .= 842215976Sjmallett "#INFO:" 843215976Sjmallett .join(',',"!WIN16",@current_platforms).":" 844232812Sjmallett .join(',',@current_algorithms).";"; 845232812Sjmallett $def .= "int PEM_write_$1(void);"; 846232812Sjmallett $def .= 847232812Sjmallett "#INFO:" 848232812Sjmallett .join(',',@current_platforms).":" 849215976Sjmallett .join(',',@current_algorithms).";"; 850215976Sjmallett # Things that are everywhere 851215976Sjmallett $def .= "int PEM_write_bio_$1(void);"; 852215976Sjmallett next; 853215976Sjmallett } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ || 854215976Sjmallett /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) { 855215976Sjmallett # Things not in Win16 856215976Sjmallett $def .= 857215976Sjmallett "#INFO:" 858215976Sjmallett .join(',',"!WIN16",@current_platforms).":" 859215976Sjmallett .join(',',@current_algorithms).";"; 860215976Sjmallett $def .= "int PEM_read_$1(void);"; 861232812Sjmallett $def .= 862232812Sjmallett "#INFO:" 863232812Sjmallett .join(',',@current_platforms).":" 864232812Sjmallett .join(',',@current_algorithms).";"; 865232812Sjmallett # Things that are everywhere 866215976Sjmallett $def .= "int PEM_read_bio_$1(void);"; 867215976Sjmallett next; 868215976Sjmallett } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { 869215976Sjmallett # Variant for platforms that do not 870215976Sjmallett # have to access globale variables 871215976Sjmallett # in shared libraries through functions 872215976Sjmallett $def .= 873215976Sjmallett "#INFO:" 874215976Sjmallett .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" 875215976Sjmallett .join(',',@current_algorithms).";"; 876215976Sjmallett $def .= "OPENSSL_EXTERN int _shadow_$2;"; 877215976Sjmallett $def .= 878232812Sjmallett "#INFO:" 879232812Sjmallett .join(',',@current_platforms).":" 880232812Sjmallett .join(',',@current_algorithms).";"; 881232812Sjmallett # Variant for platforms that have to 882232812Sjmallett # access globale variables in shared 883215976Sjmallett # libraries through functions 884215976Sjmallett &$make_variant("_shadow_$2","_shadow_$2", 885215976Sjmallett "EXPORT_VAR_AS_FUNCTION", 886215976Sjmallett "FUNCTION"); 887215976Sjmallett } elsif ($tag{'CONST_STRICT'} != 1) { 888215976Sjmallett if (/\{|\/\*|\([^\)]*$/) { 889215976Sjmallett $line = $_; 890215976Sjmallett } else { 891215976Sjmallett $def .= $_; 892215976Sjmallett } 893215976Sjmallett } 894215976Sjmallett } 895232812Sjmallett } 896232812Sjmallett close(IN); 897232812Sjmallett 898232812Sjmallett my $algs; 899232812Sjmallett my $plays; 900215976Sjmallett 901215976Sjmallett print STDERR "DEBUG: postprocessing ----------\n" if $debug; 902215976Sjmallett foreach (split /;/, $def) { 903215976Sjmallett my $s; my $k = "FUNCTION"; my $p; my $a; 904215976Sjmallett s/^[\n\s]*//g; 905215976Sjmallett s/[\n\s]*$//g; 906215976Sjmallett next if(/\#undef/); 907215976Sjmallett next if(/typedef\W/); 908215976Sjmallett next if(/\#define/); 909215976Sjmallett 910215976Sjmallett # Reduce argument lists to empty () 911215976Sjmallett # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {} 912232812Sjmallett while(/\(.*\)/s) { 913232812Sjmallett s/\([^\(\)]+\)/\{\}/gs; 914232812Sjmallett s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f 915232812Sjmallett } 916232812Sjmallett # pretend as we didn't use curly braces: {} -> () 917215976Sjmallett s/\{\}/\(\)/gs; 918215976Sjmallett 919215976Sjmallett s/STACK_OF\(\)/void/gs; 920215976Sjmallett s/LHASH_OF\(\)/void/gs; 921215976Sjmallett 922215976Sjmallett print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug; 923215976Sjmallett if (/^\#INFO:([^:]*):(.*)$/) { 924215976Sjmallett $plats = $1; 925215976Sjmallett $algs = $2; 926215976Sjmallett print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug; 927215976Sjmallett next; 928215976Sjmallett } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) { 929232812Sjmallett $s = $1; 930232812Sjmallett $k = "VARIABLE"; 931232812Sjmallett print STDERR "DEBUG: found external variable $s\n" if $debug; 932232812Sjmallett } elsif (/TYPEDEF_\w+_OF/s) { 933232812Sjmallett next; 934215976Sjmallett } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is 935215976Sjmallett $s = $1; # a function name! 936215976Sjmallett print STDERR "DEBUG: found function $s\n" if $debug; 937215976Sjmallett } elsif (/\(/ and not (/=/)) { 938215976Sjmallett print STDERR "File $file: cannot parse: $_;\n"; 939215976Sjmallett next; 940215976Sjmallett } else { 941215976Sjmallett next; 942215976Sjmallett } 943215976Sjmallett 944215976Sjmallett $syms{$s} = 1; 945215976Sjmallett $kind{$s} = $k; 946232812Sjmallett 947232812Sjmallett $p = $plats; 948232812Sjmallett $a = $algs; 949232812Sjmallett $a .= ",BF" if($s =~ /EVP_bf/); 950232812Sjmallett $a .= ",CAST" if($s =~ /EVP_cast/); 951215976Sjmallett $a .= ",DES" if($s =~ /EVP_des/); 952215976Sjmallett $a .= ",DSA" if($s =~ /EVP_dss/); 953215976Sjmallett $a .= ",IDEA" if($s =~ /EVP_idea/); 954215976Sjmallett $a .= ",MD2" if($s =~ /EVP_md2/); 955215976Sjmallett $a .= ",MD4" if($s =~ /EVP_md4/); 956215976Sjmallett $a .= ",MD5" if($s =~ /EVP_md5/); 957215976Sjmallett $a .= ",RC2" if($s =~ /EVP_rc2/); 958215976Sjmallett $a .= ",RC4" if($s =~ /EVP_rc4/); 959215976Sjmallett $a .= ",RC5" if($s =~ /EVP_rc5/); 960215976Sjmallett $a .= ",RIPEMD" if($s =~ /EVP_ripemd/); 961215976Sjmallett $a .= ",SHA" if($s =~ /EVP_sha/); 962215976Sjmallett $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/); 963232812Sjmallett $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); 964232812Sjmallett $a .= ",RSA" if($s =~ /RSAPrivateKey/); 965232812Sjmallett $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); 966232812Sjmallett 967232812Sjmallett $platform{$s} = 968215976Sjmallett &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p); 969215976Sjmallett $algorithm{$s} .= ','.$a; 970215976Sjmallett 971215976Sjmallett if (defined($variant{$s})) { 972215976Sjmallett foreach $v (split /;/,$variant{$s}) { 973215976Sjmallett (my $r, my $p, my $k) = split(/:/,$v); 974215976Sjmallett my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p); 975215976Sjmallett $syms{$r} = 1; 976215976Sjmallett if (!defined($k)) { $k = $kind{$s}; } 977215976Sjmallett $kind{$r} = $k."(".$s.")"; 978215976Sjmallett $algorithm{$r} = $algorithm{$s}; 979215976Sjmallett $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p); 980232812Sjmallett $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip); 981232812Sjmallett print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug; 982232812Sjmallett } 983232812Sjmallett } 984232812Sjmallett print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug; 985215976Sjmallett } 986215976Sjmallett } 987215976Sjmallett 988215976Sjmallett # Prune the returned symbols 989215976Sjmallett 990215976Sjmallett delete $syms{"bn_dump1"}; 991215976Sjmallett $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh"; 992215976Sjmallett 993215976Sjmallett $platform{"PEM_read_NS_CERT_SEQ"} = "VMS"; 994215976Sjmallett $platform{"PEM_write_NS_CERT_SEQ"} = "VMS"; 995215976Sjmallett $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS"; 996215976Sjmallett $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS"; 997232812Sjmallett $platform{"EVP_sha384"} = "!VMSVAX"; 998232812Sjmallett $platform{"EVP_sha512"} = "!VMSVAX"; 999232812Sjmallett $platform{"SHA384_Init"} = "!VMSVAX"; 1000232812Sjmallett $platform{"SHA384_Transform"} = "!VMSVAX"; 1001232812Sjmallett $platform{"SHA384_Update"} = "!VMSVAX"; 1002215976Sjmallett $platform{"SHA384_Final"} = "!VMSVAX"; 1003215976Sjmallett $platform{"SHA384"} = "!VMSVAX"; 1004215976Sjmallett $platform{"SHA512_Init"} = "!VMSVAX"; 1005215976Sjmallett $platform{"SHA512_Transform"} = "!VMSVAX"; 1006215976Sjmallett $platform{"SHA512_Update"} = "!VMSVAX"; 1007215976Sjmallett $platform{"SHA512_Final"} = "!VMSVAX"; 1008215976Sjmallett $platform{"SHA512"} = "!VMSVAX"; 1009215976Sjmallett $platform{"WHIRLPOOL_Init"} = "!VMSVAX"; 1010215976Sjmallett $platform{"WHIRLPOOL"} = "!VMSVAX"; 1011215976Sjmallett $platform{"WHIRLPOOL_BitUpdate"} = "!VMSVAX"; 1012215976Sjmallett $platform{"EVP_whirlpool"} = "!VMSVAX"; 1013215976Sjmallett $platform{"WHIRLPOOL_Final"} = "!VMSVAX"; 1014232812Sjmallett $platform{"WHIRLPOOL_Update"} = "!VMSVAX"; 1015232812Sjmallett 1016232812Sjmallett 1017232812Sjmallett # Info we know about 1018232812Sjmallett 1019215976Sjmallett push @ret, map { $_."\\".&info_string($_,"EXIST", 1020215976Sjmallett $platform{$_}, 1021215976Sjmallett $kind{$_}, 1022215976Sjmallett $algorithm{$_}) } keys %syms; 1023215976Sjmallett 1024215976Sjmallett if (keys %unknown_algorithms) { 1025215976Sjmallett print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n"; 1026215976Sjmallett print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n"; 1027215976Sjmallett } 1028215976Sjmallett return(@ret); 1029215976Sjmallett} 1030215976Sjmallett 1031232812Sjmallett# Param: string of comma-separated platform-specs. 1032232812Sjmallettsub reduce_platforms 1033232812Sjmallett{ 1034232812Sjmallett my ($platforms) = @_; 1035232812Sjmallett my $pl = defined($platforms) ? $platforms : ""; 1036215976Sjmallett my %p = map { $_ => 0 } split /,/, $pl; 1037215976Sjmallett my $ret; 1038215976Sjmallett 1039215976Sjmallett print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n" 1040215976Sjmallett if $debug; 1041215976Sjmallett # We do this, because if there's code like the following, it really 1042215976Sjmallett # means the function exists in all cases and should therefore be 1043215976Sjmallett # everywhere. By increasing and decreasing, we may attain 0: 1044215976Sjmallett # 1045215976Sjmallett # ifndef WIN16 1046215976Sjmallett # int foo(); 1047215976Sjmallett # else 1048232812Sjmallett # int _fat foo(); 1049232812Sjmallett # endif 1050232812Sjmallett foreach $platform (split /,/, $pl) { 1051232812Sjmallett if ($platform =~ /^!(.*)$/) { 1052232812Sjmallett $p{$1}--; 1053215976Sjmallett } else { 1054215976Sjmallett $p{$platform}++; 1055215976Sjmallett } 1056215976Sjmallett } 1057215976Sjmallett foreach $platform (keys %p) { 1058215976Sjmallett if ($p{$platform} == 0) { delete $p{$platform}; } 1059215976Sjmallett } 1060215976Sjmallett 1061215976Sjmallett delete $p{""}; 1062215976Sjmallett 1063215976Sjmallett $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p)); 1064215976Sjmallett print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n" 1065232812Sjmallett if $debug; 1066232812Sjmallett return $ret; 1067232812Sjmallett} 1068232812Sjmallett 1069232812Sjmallettsub info_string { 1070215976Sjmallett (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_; 1071215976Sjmallett 1072215976Sjmallett my %a = defined($algorithms) ? 1073215976Sjmallett map { $_ => 1 } split /,/, $algorithms : (); 1074215976Sjmallett my $k = defined($kind) ? $kind : "FUNCTION"; 1075215976Sjmallett my $ret; 1076215976Sjmallett my $p = &reduce_platforms($platforms); 1077215976Sjmallett 1078215976Sjmallett delete $a{""}; 1079215976Sjmallett 1080215976Sjmallett $ret = $exist; 1081215976Sjmallett $ret .= ":".$p; 1082232812Sjmallett $ret .= ":".$k; 1083232812Sjmallett $ret .= ":".join(',',sort keys %a); 1084232812Sjmallett return $ret; 1085232812Sjmallett} 1086232812Sjmallett 1087215976Sjmallettsub maybe_add_info { 1088215976Sjmallett (my $name, *nums, my @symbols) = @_; 1089215976Sjmallett my $sym; 1090215976Sjmallett my $new_info = 0; 1091215976Sjmallett my %syms=(); 1092215976Sjmallett 1093215976Sjmallett print STDERR "Updating $name info\n"; 1094215976Sjmallett foreach $sym (@symbols) { 1095215976Sjmallett (my $s, my $i) = split /\\/, $sym; 1096215976Sjmallett if (defined($nums{$s})) { 1097215976Sjmallett $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/; 1098215976Sjmallett (my $n, my $dummy) = split /\\/, $nums{$s}; 1099232812Sjmallett if (!defined($dummy) || $i ne $dummy) { 1100232812Sjmallett $nums{$s} = $n."\\".$i; 1101232812Sjmallett $new_info++; 1102232812Sjmallett print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug; 1103232812Sjmallett } 1104215976Sjmallett } 1105215976Sjmallett $syms{$s} = 1; 1106215976Sjmallett } 1107215976Sjmallett 1108215976Sjmallett my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums; 1109215976Sjmallett foreach $sym (@s) { 1110215976Sjmallett (my $n, my $i) = split /\\/, $nums{$sym}; 1111215976Sjmallett if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) { 1112215976Sjmallett $new_info++; 1113215976Sjmallett print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug; 1114215976Sjmallett } 1115215976Sjmallett } 1116232812Sjmallett if ($new_info) { 1117232812Sjmallett print STDERR "$new_info old symbols got an info update\n"; 1118232812Sjmallett if (!$do_rewrite) { 1119232812Sjmallett print STDERR "You should do a rewrite to fix this.\n"; 1120232812Sjmallett } 1121215976Sjmallett } else { 1122215976Sjmallett print STDERR "No old symbols needed info update\n"; 1123215976Sjmallett } 1124215976Sjmallett} 1125215976Sjmallett 1126215976Sjmallett# Param: string of comma-separated keywords, each possibly prefixed with a "!" 1127215976Sjmallettsub is_valid 1128215976Sjmallett{ 1129215976Sjmallett my ($keywords_txt,$platforms) = @_; 1130215976Sjmallett my (@keywords) = split /,/,$keywords_txt; 1131215976Sjmallett my ($falsesum, $truesum) = (0, 1); 1132215976Sjmallett 1133232812Sjmallett # Param: one keyword 1134232812Sjmallett sub recognise 1135232812Sjmallett { 1136232812Sjmallett my ($keyword,$platforms) = @_; 1137232812Sjmallett 1138215976Sjmallett if ($platforms) { 1139215976Sjmallett # platforms 1140215976Sjmallett if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; } 1141215976Sjmallett if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; } 1142215976Sjmallett if ($keyword eq "VMS" && $VMS) { return 1; } 1143215976Sjmallett if ($keyword eq "WIN32" && $W32) { return 1; } 1144215976Sjmallett if ($keyword eq "WIN16" && $W16) { return 1; } 1145215976Sjmallett if ($keyword eq "WINNT" && $NT) { return 1; } 1146215976Sjmallett if ($keyword eq "OS2" && $OS2) { return 1; } 1147215976Sjmallett # Special platforms: 1148215976Sjmallett # EXPORT_VAR_AS_FUNCTION means that global variables 1149215976Sjmallett # will be represented as functions. This currently 1150232812Sjmallett # only happens on VMS-VAX. 1151232812Sjmallett if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) { 1152232812Sjmallett return 1; 1153232812Sjmallett } 1154232812Sjmallett if ($keyword eq "OPENSSL_FIPS" && $fips) { 1155215976Sjmallett return 1; 1156215976Sjmallett } 1157215976Sjmallett if ($keyword eq "ZLIB" && $zlib) { return 1; } 1158215976Sjmallett return 0; 1159215976Sjmallett } else { 1160215976Sjmallett # algorithms 1161215976Sjmallett if ($keyword eq "RC2" && $no_rc2) { return 0; } 1162215976Sjmallett if ($keyword eq "RC4" && $no_rc4) { return 0; } 1163215976Sjmallett if ($keyword eq "RC5" && $no_rc5) { return 0; } 1164215976Sjmallett if ($keyword eq "IDEA" && $no_idea) { return 0; } 1165215976Sjmallett if ($keyword eq "DES" && $no_des) { return 0; } 1166215976Sjmallett if ($keyword eq "BF" && $no_bf) { return 0; } 1167232812Sjmallett if ($keyword eq "CAST" && $no_cast) { return 0; } 1168232812Sjmallett if ($keyword eq "MD2" && $no_md2) { return 0; } 1169232812Sjmallett if ($keyword eq "MD4" && $no_md4) { return 0; } 1170232812Sjmallett if ($keyword eq "MD5" && $no_md5) { return 0; } 1171232812Sjmallett if ($keyword eq "SHA" && $no_sha) { return 0; } 1172215976Sjmallett if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; } 1173215976Sjmallett if ($keyword eq "MDC2" && $no_mdc2) { return 0; } 1174215976Sjmallett if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; } 1175215976Sjmallett if ($keyword eq "RSA" && $no_rsa) { return 0; } 1176215976Sjmallett if ($keyword eq "DSA" && $no_dsa) { return 0; } 1177215976Sjmallett if ($keyword eq "DH" && $no_dh) { return 0; } 1178215976Sjmallett if ($keyword eq "EC" && $no_ec) { return 0; } 1179215976Sjmallett if ($keyword eq "ECDSA" && $no_ecdsa) { return 0; } 1180215976Sjmallett if ($keyword eq "ECDH" && $no_ecdh) { return 0; } 1181215976Sjmallett if ($keyword eq "HMAC" && $no_hmac) { return 0; } 1182215976Sjmallett if ($keyword eq "AES" && $no_aes) { return 0; } 1183215976Sjmallett if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; } 1184232812Sjmallett if ($keyword eq "SEED" && $no_seed) { return 0; } 1185232812Sjmallett if ($keyword eq "EVP" && $no_evp) { return 0; } 1186232812Sjmallett if ($keyword eq "LHASH" && $no_lhash) { return 0; } 1187232812Sjmallett if ($keyword eq "STACK" && $no_stack) { return 0; } 1188232812Sjmallett if ($keyword eq "ERR" && $no_err) { return 0; } 1189215976Sjmallett if ($keyword eq "BUFFER" && $no_buffer) { return 0; } 1190215976Sjmallett if ($keyword eq "BIO" && $no_bio) { return 0; } 1191215976Sjmallett if ($keyword eq "COMP" && $no_comp) { return 0; } 1192215976Sjmallett if ($keyword eq "DSO" && $no_dso) { return 0; } 1193215976Sjmallett if ($keyword eq "KRB5" && $no_krb5) { return 0; } 1194215976Sjmallett if ($keyword eq "ENGINE" && $no_engine) { return 0; } 1195215976Sjmallett if ($keyword eq "HW" && $no_hw) { return 0; } 1196215976Sjmallett if ($keyword eq "FP_API" && $no_fp_api) { return 0; } 1197215976Sjmallett if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; } 1198215976Sjmallett if ($keyword eq "GMP" && $no_gmp) { return 0; } 1199215976Sjmallett if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; } 1200215976Sjmallett if ($keyword eq "TLSEXT" && $no_tlsext) { return 0; } 1201232812Sjmallett if ($keyword eq "PSK" && $no_psk) { return 0; } 1202232812Sjmallett if ($keyword eq "CMS" && $no_cms) { return 0; } 1203232812Sjmallett if ($keyword eq "EC2M" && $no_ec2m) { return 0; } 1204232812Sjmallett if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; } 1205232812Sjmallett if ($keyword eq "EC_NISTP_64_GCC_128" && $no_nistp_gcc) 1206215976Sjmallett { return 0; } 1207215976Sjmallett if ($keyword eq "SSL2" && $no_ssl2) { return 0; } 1208215976Sjmallett if ($keyword eq "CAPIENG" && $no_capieng) { return 0; } 1209215976Sjmallett if ($keyword eq "JPAKE" && $no_jpake) { return 0; } 1210215976Sjmallett if ($keyword eq "SRP" && $no_srp) { return 0; } 1211215976Sjmallett if ($keyword eq "SCTP" && $no_sctp) { return 0; } 1212215976Sjmallett if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; } 1213215976Sjmallett if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; } 1214215976Sjmallett 1215215976Sjmallett # Nothing recognise as true 1216215976Sjmallett return 1; 1217215976Sjmallett } 1218232812Sjmallett } 1219232812Sjmallett 1220232812Sjmallett foreach $k (@keywords) { 1221232812Sjmallett if ($k =~ /^!(.*)$/) { 1222232812Sjmallett $falsesum += &recognise($1,$platforms); 1223215976Sjmallett } else { 1224215976Sjmallett $truesum *= &recognise($k,$platforms); 1225215976Sjmallett } 1226215976Sjmallett } 1227215976Sjmallett print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug; 1228215976Sjmallett return (!$falsesum) && $truesum; 1229215976Sjmallett} 1230215976Sjmallett 1231215976Sjmallettsub print_test_file 1232215976Sjmallett{ 1233215976Sjmallett (*OUT,my $name,*nums,my $testall,my @symbols)=@_; 1234215976Sjmallett my $n = 1; my @e; my @r; 1235232812Sjmallett my $sym; my $prev = ""; my $prefSSLeay; 1236232812Sjmallett 1237232812Sjmallett (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 1238232812Sjmallett (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols); 1239232812Sjmallett @symbols=((sort @e),(sort @r)); 1240215976Sjmallett 1241215976Sjmallett foreach $sym (@symbols) { 1242215976Sjmallett (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1243215976Sjmallett my $v = 0; 1244215976Sjmallett $v = 1 if $i=~ /^.*?:.*?:VARIABLE/; 1245215976Sjmallett my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1246215976Sjmallett my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1247215976Sjmallett if (!defined($nums{$s})) { 1248215976Sjmallett print STDERR "Warning: $s does not have a number assigned\n" 1249215976Sjmallett if(!$do_update); 1250215976Sjmallett } elsif (is_valid($p,1) && is_valid($a,0)) { 1251215976Sjmallett my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1252232812Sjmallett if ($prev eq $s2) { 1253232812Sjmallett print OUT "\t/* The following has already appeared previously */\n"; 1254232812Sjmallett print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1255232812Sjmallett } 1256232812Sjmallett $prev = $s2; # To warn about duplicates... 1257215976Sjmallett 1258215976Sjmallett ($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/); 1259215976Sjmallett if ($v) { 1260215976Sjmallett print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n"; 1261215976Sjmallett } else { 1262215976Sjmallett print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n"; 1263215976Sjmallett } 1264215976Sjmallett } 1265215976Sjmallett } 1266215976Sjmallett} 1267215976Sjmallett 1268215976Sjmallettsub get_version { 1269232812Sjmallett local *MF; 1270232812Sjmallett my $v = '?'; 1271232812Sjmallett open MF, 'Makefile' or return $v; 1272232812Sjmallett while (<MF>) { 1273232812Sjmallett $v = $1, last if /^VERSION=(.*?)\s*$/; 1274215976Sjmallett } 1275215976Sjmallett close MF; 1276215976Sjmallett return $v; 1277215976Sjmallett} 1278215976Sjmallett 1279215976Sjmallettsub print_def_file 1280215976Sjmallett{ 1281215976Sjmallett (*OUT,my $name,*nums,my @symbols)=@_; 1282215976Sjmallett my $n = 1; my @e; my @r; my @v; my $prev=""; 1283215976Sjmallett my $liboptions=""; 1284215976Sjmallett my $libname = $name; 1285215976Sjmallett my $http_vendor = 'www.openssl.org/'; 1286232812Sjmallett my $version = get_version(); 1287232812Sjmallett my $what = "OpenSSL: implementation of Secure Socket Layer"; 1288232812Sjmallett my $description = "$what $version, $name - http://$http_vendor"; 1289232812Sjmallett 1290232812Sjmallett if ($W32) 1291215976Sjmallett { $libname.="32"; } 1292215976Sjmallett elsif ($W16) 1293215976Sjmallett { $libname.="16"; } 1294215976Sjmallett elsif ($OS2) 1295215976Sjmallett { # DLL names should not clash on the whole system. 1296215976Sjmallett # However, they should not have any particular relationship 1297215976Sjmallett # to the name of the static library. Chose descriptive names 1298215976Sjmallett # (must be at most 8 chars). 1299215976Sjmallett my %translate = (ssl => 'open_ssl', crypto => 'cryptssl'); 1300215976Sjmallett $libname = $translate{$name} || $name; 1301215976Sjmallett $liboptions = <<EOO; 1302215976SjmallettINITINSTANCE 1303232812SjmallettDATA MULTIPLE NONSHARED 1304232812SjmallettEOO 1305232812Sjmallett # Vendor field can't contain colon, drat; so we omit http:// 1306232812Sjmallett $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd"; 1307232812Sjmallett } 1308215976Sjmallett 1309215976Sjmallett print OUT <<"EOF"; 1310215976Sjmallett; 1311215976Sjmallett; Definition file for the DLL version of the $name library from OpenSSL 1312215976Sjmallett; 1313215976Sjmallett 1314215976SjmallettLIBRARY $libname $liboptions 1315215976Sjmallett 1316215976SjmallettEOF 1317215976Sjmallett 1318232812Sjmallett if ($W16) { 1319232812Sjmallett print <<"EOF"; 1320232812SjmallettCODE PRELOAD MOVEABLE 1321232812SjmallettDATA PRELOAD MOVEABLE SINGLE 1322232812Sjmallett 1323215976SjmallettEXETYPE WINDOWS 1324215976Sjmallett 1325215976SjmallettHEAPSIZE 4096 1326215976SjmallettSTACKSIZE 8192 1327215976Sjmallett 1328215976SjmallettEOF 1329215976Sjmallett } 1330215976Sjmallett 1331215976Sjmallett print "EXPORTS\n"; 1332215976Sjmallett 1333215976Sjmallett (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1334215976Sjmallett (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols); 1335232812Sjmallett (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols); 1336232812Sjmallett @symbols=((sort @e),(sort @r), (sort @v)); 1337232812Sjmallett 1338232812Sjmallett 1339232812Sjmallett foreach $sym (@symbols) { 1340215976Sjmallett (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1341215976Sjmallett my $v = 0; 1342215976Sjmallett $v = 1 if $i =~ /^.*?:.*?:VARIABLE/; 1343215976Sjmallett if (!defined($nums{$s})) { 1344215976Sjmallett printf STDERR "Warning: $s does not have a number assigned\n" 1345215976Sjmallett if(!$do_update); 1346215976Sjmallett } else { 1347215976Sjmallett (my $n, my $dummy) = split /\\/, $nums{$s}; 1348215976Sjmallett my %pf = (); 1349215976Sjmallett my $p = ($i =~ /^[^:]*:([^:]*):/,$1); 1350215976Sjmallett my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1); 1351215976Sjmallett if (is_valid($p,1) && is_valid($a,0)) { 1352232812Sjmallett my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1); 1353232812Sjmallett if ($prev eq $s2) { 1354232812Sjmallett print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n"; 1355232812Sjmallett } 1356232812Sjmallett $prev = $s2; # To warn about duplicates... 1357215976Sjmallett if($v && !$OS2) { 1358215976Sjmallett printf OUT " %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n; 1359215976Sjmallett } else { 1360215976Sjmallett printf OUT " %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n; 1361215976Sjmallett } 1362215976Sjmallett } 1363215976Sjmallett } 1364215976Sjmallett } 1365215976Sjmallett printf OUT "\n"; 1366215976Sjmallett} 1367215976Sjmallett 1368215976Sjmallettsub load_numbers 1369215976Sjmallett{ 1370232812Sjmallett my($name)=@_; 1371215976Sjmallett my(@a,%ret); 1372232812Sjmallett 1373232812Sjmallett $max_num = 0; 1374215976Sjmallett $num_noinfo = 0; 1375215976Sjmallett $prev = ""; 1376215976Sjmallett $prev_cnt = 0; 1377215976Sjmallett 1378215976Sjmallett open(IN,"<$name") || die "unable to open $name:$!\n"; 1379215976Sjmallett while (<IN>) { 1380215976Sjmallett chop; 1381215976Sjmallett s/#.*$//; 1382215976Sjmallett next if /^\s*$/; 1383215976Sjmallett @a=split; 1384215976Sjmallett if (defined $ret{$a[0]}) { 1385215976Sjmallett # This is actually perfectly OK 1386215976Sjmallett #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n"; 1387215976Sjmallett } 1388215976Sjmallett if ($max_num > $a[1]) { 1389215976Sjmallett print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n"; 1390215976Sjmallett } 1391215976Sjmallett elsif ($max_num == $a[1]) { 1392215976Sjmallett # This is actually perfectly OK 1393232812Sjmallett #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n"; 1394215976Sjmallett if ($a[0] eq $prev) { 1395215976Sjmallett $prev_cnt++; 1396232812Sjmallett $a[0] .= "{$prev_cnt}"; 1397232812Sjmallett } 1398232812Sjmallett } 1399232812Sjmallett else { 1400215976Sjmallett $prev_cnt = 0; 1401215976Sjmallett } 1402215976Sjmallett if ($#a < 2) { 1403215976Sjmallett # Existence will be proven later, in do_defs 1404215976Sjmallett $ret{$a[0]}=$a[1]; 1405215976Sjmallett $num_noinfo++; 1406215976Sjmallett } else { 1407215976Sjmallett $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker 1408215976Sjmallett } 1409232812Sjmallett $max_num = $a[1] if $a[1] > $max_num; 1410215976Sjmallett $prev=$a[0]; 1411232812Sjmallett } 1412232812Sjmallett if ($num_noinfo) { 1413215976Sjmallett print STDERR "Warning: $num_noinfo symbols were without info."; 1414215976Sjmallett if ($do_rewrite) { 1415215976Sjmallett printf STDERR " The rewrite will fix this.\n"; 1416215976Sjmallett } else { 1417215976Sjmallett printf STDERR " You should do a rewrite to fix this.\n"; 1418215976Sjmallett } 1419215976Sjmallett } 1420215976Sjmallett close(IN); 1421215976Sjmallett return(%ret); 1422215976Sjmallett} 1423215976Sjmallett 1424215976Sjmallettsub parse_number 1425215976Sjmallett{ 1426215976Sjmallett (my $str, my $what) = @_; 1427215976Sjmallett (my $n, my $i) = split(/\\/,$str); 1428215976Sjmallett if ($what eq "n") { 1429215976Sjmallett return $n; 1430215976Sjmallett } else { 1431215976Sjmallett return $i; 1432215976Sjmallett } 1433215976Sjmallett} 1434215976Sjmallett 1435215976Sjmallettsub rewrite_numbers 1436215976Sjmallett{ 1437215976Sjmallett (*OUT,$name,*nums,@symbols)=@_; 1438215976Sjmallett my $thing; 1439215976Sjmallett 1440215976Sjmallett print STDERR "Rewriting $name\n"; 1441215976Sjmallett 1442215976Sjmallett my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 1443215976Sjmallett my $r; my %r; my %rsyms; 1444215976Sjmallett foreach $r (@r) { 1445215976Sjmallett (my $s, my $i) = split /\\/, $r; 1446215976Sjmallett my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 1447215976Sjmallett $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 1448215976Sjmallett $r{$a} = $s."\\".$i; 1449215976Sjmallett $rsyms{$s} = 1; 1450215976Sjmallett } 1451215976Sjmallett 1452215976Sjmallett my %syms = (); 1453215976Sjmallett foreach $_ (@symbols) { 1454215976Sjmallett (my $n, my $i) = split /\\/; 1455215976Sjmallett $syms{$n} = 1; 1456215976Sjmallett } 1457215976Sjmallett 1458215976Sjmallett my @s=sort { 1459215976Sjmallett &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") 1460215976Sjmallett || $a cmp $b 1461215976Sjmallett } keys %nums; 1462215976Sjmallett foreach $sym (@s) { 1463215976Sjmallett (my $n, my $i) = split /\\/, $nums{$sym}; 1464215976Sjmallett next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/; 1465215976Sjmallett next if defined($rsyms{$sym}); 1466215976Sjmallett print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug; 1467215976Sjmallett $i="NOEXIST::FUNCTION:" 1468215976Sjmallett if !defined($i) || $i eq "" || !defined($syms{$sym}); 1469215976Sjmallett my $s2 = $sym; 1470215976Sjmallett $s2 =~ s/\{[0-9]+\}$//; 1471215976Sjmallett printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 1472215976Sjmallett if (exists $r{$sym}) { 1473215976Sjmallett (my $s, $i) = split /\\/,$r{$sym}; 1474215976Sjmallett my $s2 = $s; 1475215976Sjmallett $s2 =~ s/\{[0-9]+\}$//; 1476215976Sjmallett printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i; 1477215976Sjmallett } 1478232812Sjmallett } 1479215976Sjmallett} 1480215976Sjmallett 1481232812Sjmallettsub update_numbers 1482232812Sjmallett{ 1483232812Sjmallett (*OUT,$name,*nums,my $start_num, my @symbols)=@_; 1484232812Sjmallett my $new_syms = 0; 1485215976Sjmallett 1486215976Sjmallett print STDERR "Updating $name numbers\n"; 1487215976Sjmallett 1488215976Sjmallett my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols); 1489215976Sjmallett my $r; my %r; my %rsyms; 1490215976Sjmallett foreach $r (@r) { 1491215976Sjmallett (my $s, my $i) = split /\\/, $r; 1492215976Sjmallett my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/; 1493215976Sjmallett $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/; 1494232812Sjmallett $r{$a} = $s."\\".$i; 1495215976Sjmallett $rsyms{$s} = 1; 1496232812Sjmallett } 1497232812Sjmallett 1498215976Sjmallett foreach $sym (@symbols) { 1499215976Sjmallett (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1500215976Sjmallett next if $i =~ /^.*?:.*?:\w+\(\w+\)/; 1501215976Sjmallett next if defined($rsyms{$sym}); 1502215976Sjmallett die "ERROR: Symbol $sym had no info attached to it." 1503215976Sjmallett if $i eq ""; 1504215976Sjmallett if (!exists $nums{$s}) { 1505215976Sjmallett $new_syms++; 1506215976Sjmallett my $s2 = $s; 1507215976Sjmallett $s2 =~ s/\{[0-9]+\}$//; 1508215976Sjmallett printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i; 1509215976Sjmallett if (exists $r{$s}) { 1510215976Sjmallett ($s, $i) = split /\\/,$r{$s}; 1511215976Sjmallett $s =~ s/\{[0-9]+\}$//; 1512215976Sjmallett printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i; 1513215976Sjmallett } 1514215976Sjmallett } 1515215976Sjmallett } 1516215976Sjmallett if($new_syms) { 1517232812Sjmallett print STDERR "$new_syms New symbols added\n"; 1518215976Sjmallett } else { 1519215976Sjmallett print STDERR "No New symbols Added\n"; 1520232812Sjmallett } 1521232812Sjmallett} 1522232812Sjmallett 1523232812Sjmallettsub check_existing 1524215976Sjmallett{ 1525215976Sjmallett (*nums, my @symbols)=@_; 1526215976Sjmallett my %existing; my @remaining; 1527215976Sjmallett @remaining=(); 1528215976Sjmallett foreach $sym (@symbols) { 1529215976Sjmallett (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/; 1530215976Sjmallett $existing{$s}=1; 1531215976Sjmallett } 1532215976Sjmallett foreach $sym (keys %nums) { 1533232812Sjmallett if (!exists $existing{$sym}) { 1534215976Sjmallett push @remaining, $sym; 1535232812Sjmallett } 1536232812Sjmallett } 1537215976Sjmallett if(@remaining) { 1538215976Sjmallett print STDERR "The following symbols do not seem to exist:\n"; 1539215976Sjmallett foreach $sym (@remaining) { 1540215976Sjmallett print STDERR "\t",$sym,"\n"; 1541215976Sjmallett } 1542215976Sjmallett } 1543215976Sjmallett} 1544215976Sjmallett 1545215976Sjmallett