mkdef.pl 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  1. #! /usr/bin/env perl
  2. # Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. #
  9. # generate a .def file
  10. #
  11. # It does this by parsing the header files and looking for the
  12. # prototyped functions: it then prunes the output.
  13. #
  14. # Intermediary files are created, call libcrypto.num and libssl.num,
  15. # The format of these files is:
  16. #
  17. # routine-name nnnn vers info
  18. #
  19. # The "nnnn" and "vers" fields are the numeric id and version for the symbol
  20. # respectively. The "info" part is actually a colon-separated string of fields
  21. # with the following meaning:
  22. #
  23. # existence:platform:kind:algorithms
  24. #
  25. # - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
  26. # found somewhere in the source,
  27. # - "platforms" is empty if it exists on all platforms, otherwise it contains
  28. # comma-separated list of the platform, just as they are if the symbol exists
  29. # for those platforms, or prepended with a "!" if not. This helps resolve
  30. # symbol name variants for platforms where the names are too long for the
  31. # compiler or linker, or if the systems is case insensitive and there is a
  32. # clash, or the symbol is implemented differently (see
  33. # EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found
  34. # in the file crypto/symhacks.h.
  35. # The semantics for the platforms is that every item is checked against the
  36. # environment. For the negative items ("!FOO"), if any of them is false
  37. # (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
  38. # used. For the positive items, if all of them are false in the environment,
  39. # the corresponding symbol can't be used. Any combination of positive and
  40. # negative items are possible, and of course leave room for some redundancy.
  41. # - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious.
  42. # - "algorithms" is a comma-separated list of algorithm names. This helps
  43. # exclude symbols that are part of an algorithm that some user wants to
  44. # exclude.
  45. #
  46. use lib ".";
  47. use configdata;
  48. use File::Spec::Functions;
  49. use File::Basename;
  50. use FindBin;
  51. use lib "$FindBin::Bin/perl";
  52. use OpenSSL::Glob;
  53. # When building a "variant" shared library, with a custom SONAME, also customize
  54. # all the symbol versions. This produces a shared object that can coexist
  55. # without conflict in the same address space as a default build, or an object
  56. # with a different variant tag.
  57. #
  58. # For example, with a target definition that includes:
  59. #
  60. # shlib_variant => "-opt",
  61. #
  62. # we build the following objects:
  63. #
  64. # $ perl -le '
  65. # for (@ARGV) {
  66. # if ($l = readlink) {
  67. # printf "%s -> %s\n", $_, $l
  68. # } else {
  69. # print
  70. # }
  71. # }' *.so*
  72. # libcrypto-opt.so.1.1
  73. # libcrypto.so -> libcrypto-opt.so.1.1
  74. # libssl-opt.so.1.1
  75. # libssl.so -> libssl-opt.so.1.1
  76. #
  77. # whose SONAMEs and dependencies are:
  78. #
  79. # $ for l in *.so; do
  80. # echo $l
  81. # readelf -d $l | egrep 'SONAME|NEEDED.*(ssl|crypto)'
  82. # done
  83. # libcrypto.so
  84. # 0x000000000000000e (SONAME) Library soname: [libcrypto-opt.so.1.1]
  85. # libssl.so
  86. # 0x0000000000000001 (NEEDED) Shared library: [libcrypto-opt.so.1.1]
  87. # 0x000000000000000e (SONAME) Library soname: [libssl-opt.so.1.1]
  88. #
  89. # We case-fold the variant tag to upper case and replace all non-alnum
  90. # characters with "_". This yields the following symbol versions:
  91. #
  92. # $ nm libcrypto.so | grep -w A
  93. # 0000000000000000 A OPENSSL_OPT_1_1_0
  94. # 0000000000000000 A OPENSSL_OPT_1_1_0a
  95. # 0000000000000000 A OPENSSL_OPT_1_1_0c
  96. # 0000000000000000 A OPENSSL_OPT_1_1_0d
  97. # 0000000000000000 A OPENSSL_OPT_1_1_0f
  98. # 0000000000000000 A OPENSSL_OPT_1_1_0g
  99. # $ nm libssl.so | grep -w A
  100. # 0000000000000000 A OPENSSL_OPT_1_1_0
  101. # 0000000000000000 A OPENSSL_OPT_1_1_0d
  102. #
  103. (my $SO_VARIANT = qq{\U$target{"shlib_variant"}}) =~ s/\W/_/g;
  104. my $debug=0;
  105. my $trace=0;
  106. my $verbose=0;
  107. my $crypto_num= catfile($config{sourcedir},"util","libcrypto.num");
  108. my $ssl_num= catfile($config{sourcedir},"util","libssl.num");
  109. my $libname;
  110. my $do_update = 0;
  111. my $do_rewrite = 1;
  112. my $do_crypto = 0;
  113. my $do_ssl = 0;
  114. my $do_ctest = 0;
  115. my $do_ctestall = 0;
  116. my $do_checkexist = 0;
  117. my $VMS=0;
  118. my $W32=0;
  119. my $NT=0;
  120. my $UNIX=0;
  121. my $linux=0;
  122. my $aix=0;
  123. # Set this to make typesafe STACK definitions appear in DEF
  124. my $safe_stack_def = 0;
  125. my @known_platforms = ( "__FreeBSD__", "PERL5",
  126. "EXPORT_VAR_AS_FUNCTION", "ZLIB", "_WIN32"
  127. );
  128. my @known_ossl_platforms = ( "UNIX", "VMS", "WIN32", "WINNT", "OS2" );
  129. my @known_algorithms = ( # These are algorithms we know are guarded in relevant
  130. # header files, but aren't actually disablable.
  131. # Without these, this script will warn a lot.
  132. "RSA", "MD5",
  133. # @disablables comes from configdata.pm
  134. map { (my $x = uc $_) =~ s|-|_|g; $x; } @disablables,
  135. # Deprecated functions. Not really algorithmss, but
  136. # treated as such here for the sake of simplicity
  137. "DEPRECATEDIN_0_9_8",
  138. "DEPRECATEDIN_1_0_0",
  139. "DEPRECATEDIN_1_1_0",
  140. "DEPRECATEDIN_1_2_0",
  141. );
  142. # %disabled comes from configdata.pm
  143. my %disabled_algorithms =
  144. map { (my $x = uc $_) =~ s|-|_|g; $x => 1; } keys %disabled;
  145. my $apiv = sprintf "%x%02x%02x", split(/\./, $config{api});
  146. foreach (@known_algorithms) {
  147. if (/^DEPRECATEDIN_(\d+)_(\d+)_(\d+)$/) {
  148. my $depv = sprintf "%x%02x%02x", $1, $2, $3;
  149. $disabled_algorithms{$_} = 1 if $apiv ge $depv;
  150. }
  151. }
  152. my $zlib;
  153. foreach (@ARGV, split(/ /, $config{options}))
  154. {
  155. $debug=1 if $_ eq "debug";
  156. $trace=1 if $_ eq "trace";
  157. $verbose=1 if $_ eq "verbose";
  158. $W32=1 if $_ eq "32";
  159. die "win16 not supported" if $_ eq "16";
  160. if($_ eq "NT") {
  161. $W32 = 1;
  162. $NT = 1;
  163. } elsif ($_ eq "linux") {
  164. $linux=1;
  165. $UNIX=1;
  166. } elsif ($_ eq "aix") {
  167. $aix=1;
  168. $UNIX=1;
  169. } elsif ($_ eq "VMS") {
  170. $VMS=1;
  171. }
  172. if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
  173. || $_ eq "enable-zlib-dynamic") {
  174. $zlib = 1;
  175. }
  176. $do_crypto=1 if $_ eq "libcrypto" || $_ eq "crypto";
  177. $do_ssl=1 if $_ eq "libssl" || $_ eq "ssl";
  178. $do_update=1 if $_ eq "update";
  179. $do_rewrite=1 if $_ eq "rewrite";
  180. $do_ctest=1 if $_ eq "ctest";
  181. $do_ctestall=1 if $_ eq "ctestall";
  182. $do_checkexist=1 if $_ eq "exist";
  183. }
  184. $libname = $unified_info{sharednames}->{libcrypto} if $do_crypto;
  185. $libname = $unified_info{sharednames}->{libssl} if $do_ssl;
  186. if (!$libname) {
  187. if ($do_ssl) {
  188. $libname="LIBSSL";
  189. }
  190. if ($do_crypto) {
  191. $libname="LIBCRYPTO";
  192. }
  193. }
  194. # If no platform is given, assume WIN32
  195. if ($W32 + $VMS + $linux + $aix == 0) {
  196. $W32 = 1;
  197. }
  198. die "Please, only one platform at a time"
  199. if ($W32 + $VMS + $linux + $aix > 1);
  200. if (!$do_ssl && !$do_crypto)
  201. {
  202. print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 | linux | VMS ]\n";
  203. exit(1);
  204. }
  205. %ssl_list=&load_numbers($ssl_num);
  206. $max_ssl = $max_num;
  207. %crypto_list=&load_numbers($crypto_num);
  208. $max_crypto = $max_num;
  209. my $ssl="include/openssl/ssl.h";
  210. $ssl.=" include/openssl/sslerr.h";
  211. $ssl.=" include/openssl/tls1.h";
  212. $ssl.=" include/openssl/srtp.h";
  213. # When scanning include/openssl, skip all SSL files and some internal ones.
  214. my %skipthese;
  215. foreach my $f ( split(/\s+/, $ssl) ) {
  216. $skipthese{$f} = 1;
  217. }
  218. $skipthese{'include/openssl/conf_api.h'} = 1;
  219. $skipthese{'include/openssl/ebcdic.h'} = 1;
  220. $skipthese{'include/openssl/opensslconf.h'} = 1;
  221. # We use headers found in include/openssl and include/internal only.
  222. # The latter is needed so libssl.so/.dll/.exe can link properly.
  223. my $crypto ="include/internal/dso.h";
  224. $crypto.=" include/internal/o_dir.h";
  225. $crypto.=" include/internal/o_str.h";
  226. $crypto.=" include/internal/err.h";
  227. $crypto.=" include/internal/sslconf.h";
  228. foreach my $f ( glob(catfile($config{sourcedir},'include/openssl/*.h')) ) {
  229. my $fn = "include/openssl/" . basename($f);
  230. $crypto .= " $fn" if !defined $skipthese{$fn};
  231. }
  232. my $symhacks="include/openssl/symhacks.h";
  233. my @ssl_symbols = &do_defs("LIBSSL", $ssl, $symhacks);
  234. my @crypto_symbols = &do_defs("LIBCRYPTO", $crypto, $symhacks);
  235. if ($do_update) {
  236. if ($do_ssl == 1) {
  237. &maybe_add_info("LIBSSL",*ssl_list,@ssl_symbols);
  238. if ($do_rewrite == 1) {
  239. open(OUT, ">$ssl_num");
  240. &rewrite_numbers(*OUT,"LIBSSL",*ssl_list,@ssl_symbols);
  241. } else {
  242. open(OUT, ">>$ssl_num");
  243. }
  244. &update_numbers(*OUT,"LIBSSL",*ssl_list,$max_ssl,@ssl_symbols);
  245. close OUT;
  246. }
  247. if($do_crypto == 1) {
  248. &maybe_add_info("LIBCRYPTO",*crypto_list,@crypto_symbols);
  249. if ($do_rewrite == 1) {
  250. open(OUT, ">$crypto_num");
  251. &rewrite_numbers(*OUT,"LIBCRYPTO",*crypto_list,@crypto_symbols);
  252. } else {
  253. open(OUT, ">>$crypto_num");
  254. }
  255. &update_numbers(*OUT,"LIBCRYPTO",*crypto_list,$max_crypto,@crypto_symbols);
  256. close OUT;
  257. }
  258. } elsif ($do_checkexist) {
  259. &check_existing(*ssl_list, @ssl_symbols)
  260. if $do_ssl == 1;
  261. &check_existing(*crypto_list, @crypto_symbols)
  262. if $do_crypto == 1;
  263. } elsif ($do_ctest || $do_ctestall) {
  264. print <<"EOF";
  265. /* Test file to check all DEF file symbols are present by trying
  266. * to link to all of them. This is *not* intended to be run!
  267. */
  268. int main()
  269. {
  270. EOF
  271. &print_test_file(*STDOUT,"LIBSSL",*ssl_list,$do_ctestall,@ssl_symbols)
  272. if $do_ssl == 1;
  273. &print_test_file(*STDOUT,"LIBCRYPTO",*crypto_list,$do_ctestall,@crypto_symbols)
  274. if $do_crypto == 1;
  275. print "}\n";
  276. } else {
  277. &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
  278. if $do_ssl == 1;
  279. &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
  280. if $do_crypto == 1;
  281. }
  282. sub do_defs
  283. {
  284. my($name,$files,$symhacksfile)=@_;
  285. my $file;
  286. my @ret;
  287. my %syms;
  288. my %platform; # For anything undefined, we assume ""
  289. my %kind; # For anything undefined, we assume "FUNCTION"
  290. my %algorithm; # For anything undefined, we assume ""
  291. my %variant;
  292. my %variant_cnt; # To be able to allocate "name{n}" if "name"
  293. # is the same name as the original.
  294. my $cpp;
  295. my %unknown_algorithms = ();
  296. my $parens = 0;
  297. foreach $file (split(/\s+/,$symhacksfile." ".$files))
  298. {
  299. my $fn = catfile($config{sourcedir},$file);
  300. print STDERR "DEBUG: starting on $fn:\n" if $debug;
  301. print STDERR "TRACE: start reading $fn\n" if $trace;
  302. open(IN,"<$fn") || die "Can't open $fn, $!,";
  303. my $line = "", my $def= "";
  304. my %tag = (
  305. (map { $_ => 0 } @known_platforms),
  306. (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
  307. (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
  308. (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
  309. (grep /^DEPRECATED_/, @known_algorithms),
  310. NOPROTO => 0,
  311. PERL5 => 0,
  312. _WINDLL => 0,
  313. CONST_STRICT => 0,
  314. TRUE => 1,
  315. );
  316. my $symhacking = $file eq $symhacksfile;
  317. my @current_platforms = ();
  318. my @current_algorithms = ();
  319. # params: symbol, alias, platforms, kind
  320. # The reason to put this subroutine in a variable is that
  321. # it will otherwise create its own, unshared, version of
  322. # %tag and %variant...
  323. my $make_variant = sub
  324. {
  325. my ($s, $a, $p, $k) = @_;
  326. my ($a1, $a2);
  327. print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
  328. if (defined($p))
  329. {
  330. $a1 = join(",",$p,
  331. grep(!/^$/,
  332. map { $tag{$_} == 1 ? $_ : "" }
  333. @known_platforms));
  334. }
  335. else
  336. {
  337. $a1 = join(",",
  338. grep(!/^$/,
  339. map { $tag{$_} == 1 ? $_ : "" }
  340. @known_platforms));
  341. }
  342. $a2 = join(",",
  343. grep(!/^$/,
  344. map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
  345. @known_ossl_platforms));
  346. print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
  347. if ($a1 eq "") { $a1 = $a2; }
  348. elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
  349. if ($a eq $s)
  350. {
  351. if (!defined($variant_cnt{$s}))
  352. {
  353. $variant_cnt{$s} = 0;
  354. }
  355. $variant_cnt{$s}++;
  356. $a .= "{$variant_cnt{$s}}";
  357. }
  358. my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
  359. my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
  360. if (!grep(/^$togrep$/,
  361. split(/;/, defined($variant{$s})?$variant{$s}:""))) {
  362. if (defined($variant{$s})) { $variant{$s} .= ";"; }
  363. $variant{$s} .= $toadd;
  364. }
  365. print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
  366. };
  367. print STDERR "DEBUG: parsing ----------\n" if $debug;
  368. while(<IN>) {
  369. s|\R$||; # Better chomp
  370. if($parens > 0) {
  371. #Inside a DEPRECATEDIN
  372. $stored_multiline .= $_;
  373. print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug;
  374. $parens = count_parens($stored_multiline);
  375. if ($parens == 0) {
  376. $def .= do_deprecated($stored_multiline,
  377. \@current_platforms,
  378. \@current_algorithms);
  379. }
  380. next;
  381. }
  382. if (/\/\* Error codes for the \w+ functions\. \*\//)
  383. {
  384. undef @tag;
  385. last;
  386. }
  387. if ($line ne '') {
  388. $_ = $line . $_;
  389. $line = '';
  390. }
  391. if (/\\$/) {
  392. $line = $`; # keep what was before the backslash
  393. next;
  394. }
  395. if(/\/\*/) {
  396. if (not /\*\//) { # multi-line comment...
  397. $line = $_; # ... just accumulate
  398. next;
  399. } else {
  400. s/\/\*.*?\*\///gs;# wipe it
  401. }
  402. }
  403. if ($cpp) {
  404. $cpp++ if /^#\s*if/;
  405. $cpp-- if /^#\s*endif/;
  406. next;
  407. }
  408. if (/^#.*ifdef.*cplusplus/) {
  409. $cpp = 1;
  410. next;
  411. }
  412. s/{[^{}]*}//gs; # ignore {} blocks
  413. print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
  414. print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
  415. if (/^\#\s*if\s+OPENSSL_API_COMPAT\s*(\S)\s*(0x[0-9a-fA-F]{8})L\s*$/) {
  416. my $op = $1;
  417. my $v = hex($2);
  418. if ($op ne '<' && $op ne '>=') {
  419. die "$file unacceptable operator $op: $_\n";
  420. }
  421. my ($one, $major, $minor) =
  422. ( ($v >> 28) & 0xf,
  423. ($v >> 20) & 0xff,
  424. ($v >> 12) & 0xff );
  425. my $t = "DEPRECATEDIN_${one}_${major}_${minor}";
  426. push(@tag,"-");
  427. push(@tag,$t);
  428. $tag{$t}=($op eq '<' ? 1 : -1);
  429. print STDERR "DEBUG: $file: found tag $t = $tag{$t}\n" if $debug;
  430. } elsif (/^\#\s*ifndef\s+(.*)/) {
  431. push(@tag,"-");
  432. push(@tag,$1);
  433. $tag{$1}=-1;
  434. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  435. } elsif (/^\#\s*if\s+!defined\s*\(([^\)]+)\)/) {
  436. push(@tag,"-");
  437. if (/^\#\s*if\s+(!defined\s*\(([^\)]+)\)(\s+\&\&\s+!defined\s*\(([^\)]+)\))*)$/) {
  438. my $tmp_1 = $1;
  439. my $tmp_;
  440. foreach $tmp_ (split '\&\&',$tmp_1) {
  441. $tmp_ =~ /!defined\s*\(([^\)]+)\)/;
  442. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  443. push(@tag,$1);
  444. $tag{$1}=-1;
  445. }
  446. } else {
  447. print STDERR "Warning: $file: taking only '!defined($1)' of complicated expression: $_" if $verbose; # because it is O...
  448. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  449. push(@tag,$1);
  450. $tag{$1}=-1;
  451. }
  452. } elsif (/^\#\s*ifdef\s+(\S*)/) {
  453. push(@tag,"-");
  454. push(@tag,$1);
  455. $tag{$1}=1;
  456. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  457. } elsif (/^\#\s*if\s+defined\s*\(([^\)]+)\)/) {
  458. push(@tag,"-");
  459. if (/^\#\s*if\s+(defined\s*\(([^\)]+)\)(\s+\|\|\s+defined\s*\(([^\)]+)\))*)$/) {
  460. my $tmp_1 = $1;
  461. my $tmp_;
  462. foreach $tmp_ (split '\|\|',$tmp_1) {
  463. $tmp_ =~ /defined\s*\(([^\)]+)\)/;
  464. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  465. push(@tag,$1);
  466. $tag{$1}=1;
  467. }
  468. } else {
  469. print STDERR "Warning: $file: taking only 'defined($1)' of complicated expression: $_\n" if $verbose; # because it is O...
  470. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  471. push(@tag,$1);
  472. $tag{$1}=1;
  473. }
  474. } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
  475. my $tag_i = $#tag;
  476. while($tag[$tag_i] ne "-") {
  477. if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
  478. $tag{$tag[$tag_i]}=2;
  479. print STDERR "DEBUG: $file: changed tag $1 = 2\n" if $debug;
  480. }
  481. $tag_i--;
  482. }
  483. } elsif (/^\#\s*endif/) {
  484. my $tag_i = $#tag;
  485. while($tag_i > 0 && $tag[$tag_i] ne "-") {
  486. my $t=$tag[$tag_i];
  487. print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
  488. if ($tag{$t}==2) {
  489. $tag{$t}=-1;
  490. } else {
  491. $tag{$t}=0;
  492. }
  493. print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
  494. pop(@tag);
  495. if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
  496. $t=$1;
  497. } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
  498. $t=$1;
  499. } else {
  500. $t="";
  501. }
  502. if ($t ne ""
  503. && !grep(/^$t$/, @known_algorithms)) {
  504. $unknown_algorithms{$t} = 1;
  505. #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
  506. }
  507. $tag_i--;
  508. }
  509. pop(@tag);
  510. } elsif (/^\#\s*else/) {
  511. my $tag_i = $#tag;
  512. die "$file unmatched else\n" if $tag_i < 0;
  513. while($tag[$tag_i] ne "-") {
  514. my $t=$tag[$tag_i];
  515. $tag{$t}= -$tag{$t};
  516. print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
  517. $tag_i--;
  518. }
  519. } elsif (/^\#\s*if\s+1/) {
  520. push(@tag,"-");
  521. # Dummy tag
  522. push(@tag,"TRUE");
  523. $tag{"TRUE"}=1;
  524. print STDERR "DEBUG: $file: found 1\n" if $debug;
  525. } elsif (/^\#\s*if\s+0/) {
  526. push(@tag,"-");
  527. # Dummy tag
  528. push(@tag,"TRUE");
  529. $tag{"TRUE"}=-1;
  530. print STDERR "DEBUG: $file: found 0\n" if $debug;
  531. } elsif (/^\#\s*if\s+/) {
  532. #Some other unrecognized "if" style
  533. push(@tag,"-");
  534. print STDERR "Warning: $file: ignoring unrecognized expression: $_\n" if $verbose; # because it is O...
  535. } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
  536. && $symhacking && $tag{'TRUE'} != -1) {
  537. # This is for aliasing. When we find an alias,
  538. # we have to invert
  539. &$make_variant($1,$2);
  540. print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
  541. }
  542. if (/^\#/) {
  543. @current_platforms =
  544. grep(!/^$/,
  545. map { $tag{$_} == 1 ? $_ :
  546. $tag{$_} == -1 ? "!".$_ : "" }
  547. @known_platforms);
  548. push @current_platforms
  549. , grep(!/^$/,
  550. map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
  551. $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
  552. @known_ossl_platforms);
  553. @current_algorithms = ();
  554. @current_algorithms =
  555. grep(!/^$/,
  556. map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
  557. @known_algorithms);
  558. push @current_algorithms
  559. , grep(!/^$/,
  560. map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
  561. @known_algorithms);
  562. push @current_algorithms,
  563. grep { /^DEPRECATEDIN_/ && $tag{$_} == 1 }
  564. @known_algorithms;
  565. $def .=
  566. "#INFO:"
  567. .join(',',@current_platforms).":"
  568. .join(',',@current_algorithms).";";
  569. next;
  570. }
  571. if ($tag{'TRUE'} != -1) {
  572. if (/^\s*DEFINE_STACK_OF\s*\(\s*(\w*)\s*\)/
  573. || /^\s*DEFINE_STACK_OF_CONST\s*\(\s*(\w*)\s*\)/) {
  574. next;
  575. } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  576. $def .= "int d2i_$3(void);";
  577. $def .= "int i2d_$3(void);";
  578. # Variant for platforms that do not
  579. # have to access global variables
  580. # in shared libraries through functions
  581. $def .=
  582. "#INFO:"
  583. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  584. .join(',',@current_algorithms).";";
  585. $def .= "OPENSSL_EXTERN int $2_it;";
  586. $def .=
  587. "#INFO:"
  588. .join(',',@current_platforms).":"
  589. .join(',',@current_algorithms).";";
  590. # Variant for platforms that have to
  591. # access global variables in shared
  592. # libraries through functions
  593. &$make_variant("$2_it","$2_it",
  594. "EXPORT_VAR_AS_FUNCTION",
  595. "FUNCTION");
  596. next;
  597. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  598. $def .= "int d2i_$3(void);";
  599. $def .= "int i2d_$3(void);";
  600. $def .= "int $3_free(void);";
  601. $def .= "int $3_new(void);";
  602. # Variant for platforms that do not
  603. # have to access global variables
  604. # in shared libraries through functions
  605. $def .=
  606. "#INFO:"
  607. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  608. .join(',',@current_algorithms).";";
  609. $def .= "OPENSSL_EXTERN int $2_it;";
  610. $def .=
  611. "#INFO:"
  612. .join(',',@current_platforms).":"
  613. .join(',',@current_algorithms).";";
  614. # Variant for platforms that have to
  615. # access global variables in shared
  616. # libraries through functions
  617. &$make_variant("$2_it","$2_it",
  618. "EXPORT_VAR_AS_FUNCTION",
  619. "FUNCTION");
  620. next;
  621. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
  622. /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
  623. $def .= "int d2i_$1(void);";
  624. $def .= "int i2d_$1(void);";
  625. $def .= "int $1_free(void);";
  626. $def .= "int $1_new(void);";
  627. # Variant for platforms that do not
  628. # have to access global variables
  629. # in shared libraries through functions
  630. $def .=
  631. "#INFO:"
  632. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  633. .join(',',@current_algorithms).";";
  634. $def .= "OPENSSL_EXTERN int $1_it;";
  635. $def .=
  636. "#INFO:"
  637. .join(',',@current_platforms).":"
  638. .join(',',@current_algorithms).";";
  639. # Variant for platforms that have to
  640. # access global variables in shared
  641. # libraries through functions
  642. &$make_variant("$1_it","$1_it",
  643. "EXPORT_VAR_AS_FUNCTION",
  644. "FUNCTION");
  645. next;
  646. } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  647. $def .= "int d2i_$2(void);";
  648. $def .= "int i2d_$2(void);";
  649. # Variant for platforms that do not
  650. # have to access global variables
  651. # in shared libraries through functions
  652. $def .=
  653. "#INFO:"
  654. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  655. .join(',',@current_algorithms).";";
  656. $def .= "OPENSSL_EXTERN int $2_it;";
  657. $def .=
  658. "#INFO:"
  659. .join(',',@current_platforms).":"
  660. .join(',',@current_algorithms).";";
  661. # Variant for platforms that have to
  662. # access global variables in shared
  663. # libraries through functions
  664. &$make_variant("$2_it","$2_it",
  665. "EXPORT_VAR_AS_FUNCTION",
  666. "FUNCTION");
  667. next;
  668. } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
  669. $def .= "int $1_free(void);";
  670. $def .= "int $1_new(void);";
  671. next;
  672. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  673. $def .= "int d2i_$2(void);";
  674. $def .= "int i2d_$2(void);";
  675. $def .= "int $2_free(void);";
  676. $def .= "int $2_new(void);";
  677. # Variant for platforms that do not
  678. # have to access global variables
  679. # in shared libraries through functions
  680. $def .=
  681. "#INFO:"
  682. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  683. .join(',',@current_algorithms).";";
  684. $def .= "OPENSSL_EXTERN int $2_it;";
  685. $def .=
  686. "#INFO:"
  687. .join(',',@current_platforms).":"
  688. .join(',',@current_algorithms).";";
  689. # Variant for platforms that have to
  690. # access global variables in shared
  691. # libraries through functions
  692. &$make_variant("$2_it","$2_it",
  693. "EXPORT_VAR_AS_FUNCTION",
  694. "FUNCTION");
  695. next;
  696. } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
  697. # Variant for platforms that do not
  698. # have to access global variables
  699. # in shared libraries through functions
  700. $def .=
  701. "#INFO:"
  702. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  703. .join(',',@current_algorithms).";";
  704. $def .= "OPENSSL_EXTERN int $1_it;";
  705. $def .=
  706. "#INFO:"
  707. .join(',',@current_platforms).":"
  708. .join(',',@current_algorithms).";";
  709. # Variant for platforms that have to
  710. # access global variables in shared
  711. # libraries through functions
  712. &$make_variant("$1_it","$1_it",
  713. "EXPORT_VAR_AS_FUNCTION",
  714. "FUNCTION");
  715. next;
  716. } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
  717. $def .= "int i2d_$1_NDEF(void);";
  718. } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
  719. next;
  720. } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
  721. $def .= "int $1_print_ctx(void);";
  722. next;
  723. } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  724. $def .= "int $2_print_ctx(void);";
  725. next;
  726. } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
  727. next;
  728. } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
  729. /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
  730. /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
  731. $def .=
  732. "#INFO:"
  733. .join(',',@current_platforms).":"
  734. .join(',',"STDIO",@current_algorithms).";";
  735. $def .= "int PEM_read_$1(void);";
  736. $def .= "int PEM_write_$1(void);";
  737. $def .=
  738. "#INFO:"
  739. .join(',',@current_platforms).":"
  740. .join(',',@current_algorithms).";";
  741. # Things that are everywhere
  742. $def .= "int PEM_read_bio_$1(void);";
  743. $def .= "int PEM_write_bio_$1(void);";
  744. next;
  745. } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
  746. /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
  747. /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
  748. $def .=
  749. "#INFO:"
  750. .join(',',@current_platforms).":"
  751. .join(',',"STDIO",@current_algorithms).";";
  752. $def .= "int PEM_write_$1(void);";
  753. $def .=
  754. "#INFO:"
  755. .join(',',@current_platforms).":"
  756. .join(',',@current_algorithms).";";
  757. # Things that are everywhere
  758. $def .= "int PEM_write_bio_$1(void);";
  759. next;
  760. } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
  761. /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
  762. $def .=
  763. "#INFO:"
  764. .join(',',@current_platforms).":"
  765. .join(',',"STDIO",@current_algorithms).";";
  766. $def .= "int PEM_read_$1(void);";
  767. $def .=
  768. "#INFO:"
  769. .join(',',@current_platforms).":"
  770. .join(',',"STDIO",@current_algorithms).";";
  771. # Things that are everywhere
  772. $def .= "int PEM_read_bio_$1(void);";
  773. next;
  774. } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  775. # Variant for platforms that do not
  776. # have to access global variables
  777. # in shared libraries through functions
  778. $def .=
  779. "#INFO:"
  780. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  781. .join(',',@current_algorithms).";";
  782. $def .= "OPENSSL_EXTERN int _shadow_$2;";
  783. $def .=
  784. "#INFO:"
  785. .join(',',@current_platforms).":"
  786. .join(',',@current_algorithms).";";
  787. # Variant for platforms that have to
  788. # access global variables in shared
  789. # libraries through functions
  790. &$make_variant("_shadow_$2","_shadow_$2",
  791. "EXPORT_VAR_AS_FUNCTION",
  792. "FUNCTION");
  793. } elsif (/^\s*DEPRECATEDIN/) {
  794. $parens = count_parens($_);
  795. if ($parens == 0) {
  796. $def .= do_deprecated($_,
  797. \@current_platforms,
  798. \@current_algorithms);
  799. } else {
  800. $stored_multiline = $_;
  801. print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug;
  802. next;
  803. }
  804. } elsif ($tag{'CONST_STRICT'} != 1) {
  805. if (/\{|\/\*|\([^\)]*$/) {
  806. $line = $_;
  807. } else {
  808. $def .= $_;
  809. }
  810. }
  811. }
  812. }
  813. close(IN);
  814. die "$file: Unmatched tags\n" if $#tag >= 0;
  815. my $algs;
  816. my $plays;
  817. print STDERR "DEBUG: postprocessing ----------\n" if $debug;
  818. foreach (split /;/, $def) {
  819. my $s; my $k = "FUNCTION"; my $p; my $a;
  820. s/^[\n\s]*//g;
  821. s/[\n\s]*$//g;
  822. next if(/\#undef/);
  823. next if(/typedef\W/);
  824. next if(/\#define/);
  825. print STDERR "TRACE: processing $_\n" if $trace && !/^\#INFO:/;
  826. # Reduce argument lists to empty ()
  827. # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
  828. my $nsubst = 1; # prevent infinite loop, e.g., on int fn()
  829. while($nsubst && /\(.*\)/s) {
  830. $nsubst = s/\([^\(\)]+\)/\{\}/gs;
  831. $nsubst+= s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
  832. }
  833. # pretend as we didn't use curly braces: {} -> ()
  834. s/\{\}/\(\)/gs;
  835. s/STACK_OF\(\)/void/gs;
  836. s/LHASH_OF\(\)/void/gs;
  837. print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
  838. if (/^\#INFO:([^:]*):(.*)$/) {
  839. $plats = $1;
  840. $algs = $2;
  841. print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
  842. next;
  843. } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
  844. $s = $1;
  845. $k = "VARIABLE";
  846. print STDERR "DEBUG: found external variable $s\n" if $debug;
  847. } elsif (/TYPEDEF_\w+_OF/s) {
  848. next;
  849. } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
  850. $s = $1; # a function name!
  851. print STDERR "DEBUG: found function $s\n" if $debug;
  852. } elsif (/\(/ and not (/=/)) {
  853. print STDERR "File $file: cannot parse: $_;\n";
  854. next;
  855. } else {
  856. next;
  857. }
  858. $syms{$s} = 1;
  859. $kind{$s} = $k;
  860. $p = $plats;
  861. $a = $algs;
  862. $platform{$s} =
  863. &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
  864. $algorithm{$s} .= ','.$a;
  865. if (defined($variant{$s})) {
  866. foreach $v (split /;/,$variant{$s}) {
  867. (my $r, my $p, my $k) = split(/:/,$v);
  868. my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
  869. $syms{$r} = 1;
  870. if (!defined($k)) { $k = $kind{$s}; }
  871. $kind{$r} = $k."(".$s.")";
  872. $algorithm{$r} = $algorithm{$s};
  873. $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
  874. $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
  875. print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
  876. }
  877. }
  878. print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
  879. }
  880. }
  881. # Info we know about
  882. push @ret, map { $_."\\".&info_string($_,"EXIST",
  883. $platform{$_},
  884. $kind{$_},
  885. $algorithm{$_}) } keys %syms;
  886. if (keys %unknown_algorithms) {
  887. print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
  888. print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
  889. }
  890. return(@ret);
  891. }
  892. # Param: string of comma-separated platform-specs.
  893. sub reduce_platforms
  894. {
  895. my ($platforms) = @_;
  896. my $pl = defined($platforms) ? $platforms : "";
  897. my %p = map { $_ => 0 } split /,/, $pl;
  898. my $ret;
  899. print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
  900. if $debug;
  901. # We do this, because if there's code like the following, it really
  902. # means the function exists in all cases and should therefore be
  903. # everywhere. By increasing and decreasing, we may attain 0:
  904. #
  905. # ifndef WIN16
  906. # int foo();
  907. # else
  908. # int _fat foo();
  909. # endif
  910. foreach $platform (split /,/, $pl) {
  911. if ($platform =~ /^!(.*)$/) {
  912. $p{$1}--;
  913. } else {
  914. $p{$platform}++;
  915. }
  916. }
  917. foreach $platform (keys %p) {
  918. if ($p{$platform} == 0) { delete $p{$platform}; }
  919. }
  920. delete $p{""};
  921. $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
  922. print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
  923. if $debug;
  924. return $ret;
  925. }
  926. sub info_string
  927. {
  928. (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
  929. my %a = defined($algorithms) ?
  930. map { $_ => 1 } split /,/, $algorithms : ();
  931. my $k = defined($kind) ? $kind : "FUNCTION";
  932. my $ret;
  933. my $p = &reduce_platforms($platforms);
  934. delete $a{""};
  935. $ret = $exist;
  936. $ret .= ":".$p;
  937. $ret .= ":".$k;
  938. $ret .= ":".join(',',sort keys %a);
  939. return $ret;
  940. }
  941. sub maybe_add_info
  942. {
  943. (my $name, *nums, my @symbols) = @_;
  944. my $sym;
  945. my $new_info = 0;
  946. my %syms=();
  947. foreach $sym (@symbols) {
  948. (my $s, my $i) = split /\\/, $sym;
  949. if (defined($nums{$s})) {
  950. $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
  951. (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
  952. if (!defined($dummy) || $i ne $dummy) {
  953. $nums{$s} = $n."\\".$vers."\\".$i;
  954. $new_info++;
  955. print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
  956. }
  957. }
  958. $syms{$s} = 1;
  959. }
  960. my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
  961. foreach $sym (@s) {
  962. (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
  963. if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
  964. $new_info++;
  965. print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
  966. }
  967. }
  968. if ($new_info) {
  969. print STDERR "$name: $new_info old symbols have updated info\n";
  970. if (!$do_rewrite) {
  971. print STDERR "You should do a rewrite to fix this.\n";
  972. }
  973. } else {
  974. }
  975. }
  976. # Param: string of comma-separated keywords, each possibly prefixed with a "!"
  977. sub is_valid
  978. {
  979. my ($keywords_txt,$platforms) = @_;
  980. my (@keywords) = split /,/,$keywords_txt;
  981. my ($falsesum, $truesum) = (0, 1);
  982. # Param: one keyword
  983. sub recognise
  984. {
  985. my ($keyword,$platforms) = @_;
  986. if ($platforms) {
  987. # platforms
  988. if ($keyword eq "UNIX" && $UNIX) { return 1; }
  989. if ($keyword eq "VMS" && $VMS) { return 1; }
  990. if ($keyword eq "WIN32" && $W32) { return 1; }
  991. if ($keyword eq "_WIN32" && $W32) { return 1; }
  992. if ($keyword eq "WINNT" && $NT) { return 1; }
  993. # Special platforms:
  994. # EXPORT_VAR_AS_FUNCTION means that global variables
  995. # will be represented as functions.
  996. if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && $W32) {
  997. return 1;
  998. }
  999. if ($keyword eq "ZLIB" && $zlib) { return 1; }
  1000. return 0;
  1001. } else {
  1002. # algorithms
  1003. if ($disabled_algorithms{$keyword}) { return 0;}
  1004. # Nothing recognise as true
  1005. return 1;
  1006. }
  1007. }
  1008. foreach $k (@keywords) {
  1009. if ($k =~ /^!(.*)$/) {
  1010. $falsesum += &recognise($1,$platforms);
  1011. } else {
  1012. $truesum *= &recognise($k,$platforms);
  1013. }
  1014. }
  1015. print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
  1016. return (!$falsesum) && $truesum;
  1017. }
  1018. sub print_test_file
  1019. {
  1020. (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
  1021. my $n = 1; my @e; my @r;
  1022. my $sym; my $prev = ""; my $prefSSLeay;
  1023. (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
  1024. (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
  1025. @symbols=((sort @e),(sort @r));
  1026. foreach $sym (@symbols) {
  1027. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1028. my $v = 0;
  1029. $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
  1030. my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
  1031. my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
  1032. if (!defined($nums{$s})) {
  1033. print STDERR "Warning: $s does not have a number assigned\n"
  1034. if(!$do_update);
  1035. } elsif (is_valid($p,1) && is_valid($a,0)) {
  1036. my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
  1037. if ($prev eq $s2) {
  1038. print OUT "\t/* The following has already appeared previously */\n";
  1039. print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
  1040. }
  1041. $prev = $s2; # To warn about duplicates...
  1042. (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
  1043. if ($v) {
  1044. print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
  1045. } else {
  1046. print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
  1047. }
  1048. }
  1049. }
  1050. }
  1051. sub get_version
  1052. {
  1053. return $config{version};
  1054. }
  1055. sub print_def_file
  1056. {
  1057. (*OUT,my $name,*nums,my @symbols)=@_;
  1058. my $n = 1; my @e; my @r; my @v; my $prev="";
  1059. my $liboptions="";
  1060. my $libname = $name;
  1061. my $http_vendor = 'www.openssl.org/';
  1062. my $version = get_version();
  1063. my $what = "OpenSSL: implementation of Secure Socket Layer";
  1064. my $description = "$what $version, $name - http://$http_vendor";
  1065. my $prevsymversion = "", $prevprevsymversion = "";
  1066. # For VMS
  1067. my $prevnum = 0;
  1068. my $symvtextcount = 0;
  1069. if ($W32)
  1070. {
  1071. print OUT <<"EOF";
  1072. ;
  1073. ; Definition file for the DLL version of the $name library from OpenSSL
  1074. ;
  1075. LIBRARY $libname $liboptions
  1076. EOF
  1077. print "EXPORTS\n";
  1078. }
  1079. elsif ($VMS)
  1080. {
  1081. print OUT <<"EOF";
  1082. IDENTIFICATION=$version
  1083. CASE_SENSITIVE=YES
  1084. SYMBOL_VECTOR=(-
  1085. EOF
  1086. $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
  1087. }
  1088. (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
  1089. (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
  1090. if ($VMS) {
  1091. # VMS needs to have the symbols on slot number order
  1092. @symbols=(map { $_->[1] }
  1093. sort { $a->[0] <=> $b->[0] }
  1094. map { (my $s, my $i) = $_ =~ /^(.*?)\\(.*)$/;
  1095. die "Error: $s doesn't have a number assigned\n"
  1096. if !defined($nums{$s});
  1097. (my $n, my @rest) = split /\\/, $nums{$s};
  1098. [ $n, $_ ] } (@e, @r, @v));
  1099. } else {
  1100. @symbols=((sort @e),(sort @r), (sort @v));
  1101. }
  1102. my ($baseversion, $currversion) = get_openssl_version();
  1103. my $thisversion;
  1104. do {
  1105. if (!defined($thisversion)) {
  1106. $thisversion = $baseversion;
  1107. } else {
  1108. $thisversion = get_next_version($thisversion);
  1109. }
  1110. foreach $sym (@symbols) {
  1111. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1112. my $v = 0;
  1113. $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
  1114. if (!defined($nums{$s})) {
  1115. die "Error: $s does not have a number assigned\n"
  1116. if(!$do_update);
  1117. } else {
  1118. (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
  1119. my %pf = ();
  1120. my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
  1121. my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
  1122. if (is_valid($p,1) && is_valid($a,0)) {
  1123. my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
  1124. if ($prev eq $s2) {
  1125. print STDERR "Warning: Symbol '",$s2,
  1126. "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
  1127. ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
  1128. }
  1129. $prev = $s2; # To warn about duplicates...
  1130. if($linux) {
  1131. next if $symversion ne $thisversion;
  1132. if ($symversion ne $prevsymversion) {
  1133. if ($prevsymversion ne "") {
  1134. if ($prevprevsymversion ne "") {
  1135. print OUT "} OPENSSL${SO_VARIANT}_"
  1136. ."$prevprevsymversion;\n\n";
  1137. } else {
  1138. print OUT "};\n\n";
  1139. }
  1140. }
  1141. print OUT "OPENSSL${SO_VARIANT}_$symversion {\n global:\n";
  1142. $prevprevsymversion = $prevsymversion;
  1143. $prevsymversion = $symversion;
  1144. }
  1145. print OUT " $s2;\n";
  1146. } elsif ($aix) {
  1147. print OUT "$s2\n";
  1148. } elsif ($VMS) {
  1149. while(++$prevnum < $n) {
  1150. my $symline=" ,SPARE -\n ,SPARE -\n";
  1151. if ($symvtextcount + length($symline) - 2 > 1024) {
  1152. print OUT ")\nSYMBOL_VECTOR=(-\n";
  1153. $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
  1154. }
  1155. if ($symvtextcount == 16) {
  1156. # Take away first comma
  1157. $symline =~ s/,//;
  1158. }
  1159. print OUT $symline;
  1160. $symvtextcount += length($symline) - 2;
  1161. }
  1162. (my $s_uc = $s) =~ tr/a-z/A-Z/;
  1163. my $symtype=
  1164. $v ? "DATA" : "PROCEDURE";
  1165. my $symline=
  1166. ($s_uc ne $s
  1167. ? " ,$s_uc/$s=$symtype -\n ,$s=$symtype -\n"
  1168. : " ,$s=$symtype -\n ,SPARE -\n");
  1169. if ($symvtextcount + length($symline) - 2 > 1024) {
  1170. print OUT ")\nSYMBOL_VECTOR=(-\n";
  1171. $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
  1172. }
  1173. if ($symvtextcount == 16) {
  1174. # Take away first comma
  1175. $symline =~ s/,//;
  1176. }
  1177. print OUT $symline;
  1178. $symvtextcount += length($symline) - 2;
  1179. } elsif($v) {
  1180. printf OUT " %s%-39s DATA\n",
  1181. ($W32)?"":"_",$s2;
  1182. } else {
  1183. printf OUT " %s%s\n",
  1184. ($W32)?"":"_",$s2;
  1185. }
  1186. }
  1187. }
  1188. }
  1189. } while ($linux && $thisversion ne $currversion);
  1190. if ($linux) {
  1191. if ($prevprevsymversion ne "") {
  1192. print OUT " local: *;\n} OPENSSL${SO_VARIANT}_$prevprevsymversion;\n\n";
  1193. } else {
  1194. print OUT " local: *;\n};\n\n";
  1195. }
  1196. } elsif ($VMS) {
  1197. print OUT ")\n";
  1198. (my $libvmaj, my $libvmin, my $libvedit) =
  1199. $currversion =~ /^(\d+)_(\d+)_(\d+)[a-z]{0,2}$/;
  1200. # The reason to multiply the edit number with 100 is to make space
  1201. # for the possibility that we want to encode the patch letters
  1202. print OUT "GSMATCH=LEQUAL,",($libvmaj * 100 + $libvmin),",",($libvedit * 100),"\n";
  1203. }
  1204. printf OUT "\n";
  1205. }
  1206. sub load_numbers
  1207. {
  1208. my($name)=@_;
  1209. my(@a,%ret);
  1210. my $prevversion;
  1211. $max_num = 0;
  1212. $num_noinfo = 0;
  1213. $prev = "";
  1214. $prev_cnt = 0;
  1215. my ($baseversion, $currversion) = get_openssl_version();
  1216. open(IN,"<$name") || die "unable to open $name:$!\n";
  1217. while (<IN>) {
  1218. s|\R$||; # Better chomp
  1219. s/#.*$//;
  1220. next if /^\s*$/;
  1221. @a=split;
  1222. if (defined $ret{$a[0]}) {
  1223. # This is actually perfectly OK
  1224. #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
  1225. }
  1226. if ($max_num > $a[1]) {
  1227. print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
  1228. }
  1229. elsif ($max_num == $a[1]) {
  1230. # This is actually perfectly OK
  1231. #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
  1232. if ($a[0] eq $prev) {
  1233. $prev_cnt++;
  1234. $a[0] .= "{$prev_cnt}";
  1235. }
  1236. }
  1237. else {
  1238. $prev_cnt = 0;
  1239. }
  1240. if ($#a < 2) {
  1241. # Existence will be proven later, in do_defs
  1242. $ret{$a[0]}=$a[1];
  1243. $num_noinfo++;
  1244. } else {
  1245. #Sanity check the version number
  1246. if (defined $prevversion) {
  1247. check_version_lte($prevversion, $a[2]);
  1248. }
  1249. check_version_lte($a[2], $currversion);
  1250. $prevversion = $a[2];
  1251. $ret{$a[0]}=$a[1]."\\".$a[2]."\\".$a[3]; # \\ is a special marker
  1252. }
  1253. $max_num = $a[1] if $a[1] > $max_num;
  1254. $prev=$a[0];
  1255. }
  1256. if ($num_noinfo) {
  1257. print STDERR "Warning: $num_noinfo symbols were without info." if $verbose || !$do_rewrite;
  1258. if ($do_rewrite) {
  1259. printf STDERR " The rewrite will fix this.\n" if $verbose;
  1260. } else {
  1261. printf STDERR " You should do a rewrite to fix this.\n";
  1262. }
  1263. }
  1264. close(IN);
  1265. return(%ret);
  1266. }
  1267. sub parse_number
  1268. {
  1269. (my $str, my $what) = @_;
  1270. (my $n, my $v, my $i) = split(/\\/,$str);
  1271. if ($what eq "n") {
  1272. return $n;
  1273. } else {
  1274. return $i;
  1275. }
  1276. }
  1277. sub rewrite_numbers
  1278. {
  1279. (*OUT,$name,*nums,@symbols)=@_;
  1280. my $thing;
  1281. my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
  1282. my $r; my %r; my %rsyms;
  1283. foreach $r (@r) {
  1284. (my $s, my $i) = split /\\/, $r;
  1285. my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
  1286. $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
  1287. $r{$a} = $s."\\".$i;
  1288. $rsyms{$s} = 1;
  1289. }
  1290. my %syms = ();
  1291. foreach $_ (@symbols) {
  1292. (my $n, my $i) = split /\\/;
  1293. $syms{$n} = 1;
  1294. }
  1295. my @s=sort {
  1296. &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
  1297. || $a cmp $b
  1298. } keys %nums;
  1299. foreach $sym (@s) {
  1300. (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
  1301. next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
  1302. next if defined($rsyms{$sym});
  1303. print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
  1304. $i="NOEXIST::FUNCTION:"
  1305. if !defined($i) || $i eq "" || !defined($syms{$sym});
  1306. my $s2 = $sym;
  1307. $s2 =~ s/\{[0-9]+\}$//;
  1308. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
  1309. if (exists $r{$sym}) {
  1310. (my $s, $i) = split /\\/,$r{$sym};
  1311. my $s2 = $s;
  1312. $s2 =~ s/\{[0-9]+\}$//;
  1313. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
  1314. }
  1315. }
  1316. }
  1317. sub update_numbers
  1318. {
  1319. (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
  1320. my $new_syms = 0;
  1321. my $basevers;
  1322. my $vers;
  1323. ($basevers, $vers) = get_openssl_version();
  1324. my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
  1325. my $r; my %r; my %rsyms;
  1326. foreach $r (@r) {
  1327. (my $s, my $i) = split /\\/, $r;
  1328. my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
  1329. $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
  1330. $r{$a} = $s."\\".$i;
  1331. $rsyms{$s} = 1;
  1332. }
  1333. foreach $sym (@symbols) {
  1334. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1335. next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
  1336. next if defined($rsyms{$sym});
  1337. die "ERROR: Symbol $sym had no info attached to it."
  1338. if $i eq "";
  1339. if (!exists $nums{$s}) {
  1340. $new_syms++;
  1341. my $s2 = $s;
  1342. $s2 =~ s/\{[0-9]+\}$//;
  1343. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2, ++$start_num,$vers,$i;
  1344. if (exists $r{$s}) {
  1345. ($s, $i) = split /\\/,$r{$s};
  1346. $s =~ s/\{[0-9]+\}$//;
  1347. printf OUT "%s%-39s %d\t%s\t%s\n","",$s, $start_num,$vers,$i;
  1348. }
  1349. }
  1350. }
  1351. if($new_syms) {
  1352. print STDERR "$name: Added $new_syms new symbols\n";
  1353. } else {
  1354. print STDERR "$name: No new symbols added\n";
  1355. }
  1356. }
  1357. sub check_existing
  1358. {
  1359. (*nums, my @symbols)=@_;
  1360. my %existing; my @remaining;
  1361. @remaining=();
  1362. foreach $sym (@symbols) {
  1363. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1364. $existing{$s}=1;
  1365. }
  1366. foreach $sym (keys %nums) {
  1367. if (!exists $existing{$sym}) {
  1368. push @remaining, $sym;
  1369. }
  1370. }
  1371. if(@remaining) {
  1372. print STDERR "The following symbols do not seem to exist:\n";
  1373. foreach $sym (@remaining) {
  1374. print STDERR "\t",$sym,"\n";
  1375. }
  1376. }
  1377. }
  1378. sub count_parens
  1379. {
  1380. my $line = shift(@_);
  1381. my $open = $line =~ tr/\(//;
  1382. my $close = $line =~ tr/\)//;
  1383. return $open - $close;
  1384. }
  1385. #Parse opensslv.h to get the current version number. Also work out the base
  1386. #version, i.e. the lowest version number that is binary compatible with this
  1387. #version
  1388. sub get_openssl_version()
  1389. {
  1390. my $fn = catfile($config{sourcedir},"include","openssl","opensslv.h");
  1391. open (IN, "$fn") || die "Can't open opensslv.h";
  1392. while(<IN>) {
  1393. if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
  1394. my $suffix = $2;
  1395. (my $baseversion = $1) =~ s/\./_/g;
  1396. close IN;
  1397. return ($baseversion."0", $baseversion.$suffix);
  1398. }
  1399. }
  1400. die "Can't find OpenSSL version number\n";
  1401. }
  1402. #Given an OpenSSL version number, calculate the next version number. If the
  1403. #version number gets to a.b.czz then we go to a.b.(c+1)
  1404. sub get_next_version()
  1405. {
  1406. my $thisversion = shift;
  1407. my ($base, $letter) = $thisversion =~ /^(\d_\d_\d)([a-z]{0,2})$/;
  1408. if ($letter eq "zz") {
  1409. my $lastnum = substr($base, -1);
  1410. return substr($base, 0, length($base)-1).(++$lastnum);
  1411. }
  1412. return $base.get_next_letter($letter);
  1413. }
  1414. #Given the letters off the end of an OpenSSL version string, calculate what
  1415. #the letters for the next release would be.
  1416. sub get_next_letter()
  1417. {
  1418. my $thisletter = shift;
  1419. my $baseletter = "";
  1420. my $endletter;
  1421. if ($thisletter eq "") {
  1422. return "a";
  1423. }
  1424. if ((length $thisletter) > 1) {
  1425. ($baseletter, $endletter) = $thisletter =~ /([a-z]+)([a-z])/;
  1426. } else {
  1427. $endletter = $thisletter;
  1428. }
  1429. if ($endletter eq "z") {
  1430. return $thisletter."a";
  1431. } else {
  1432. return $baseletter.(++$endletter);
  1433. }
  1434. }
  1435. #Check if a version is less than or equal to the current version. Its a fatal
  1436. #error if not. They must also only differ in letters, or the last number (i.e.
  1437. #the first two numbers must be the same)
  1438. sub check_version_lte()
  1439. {
  1440. my ($testversion, $currversion) = @_;
  1441. my $lentv;
  1442. my $lencv;
  1443. my $cvbase;
  1444. my ($cvnums) = $currversion =~ /^(\d_\d_\d)[a-z]*$/;
  1445. my ($tvnums) = $testversion =~ /^(\d_\d_\d)[a-z]*$/;
  1446. #Die if we can't parse the version numbers or they don't look sane
  1447. die "Invalid version number: $testversion and $currversion\n"
  1448. if (!defined($cvnums) || !defined($tvnums)
  1449. || length($cvnums) != 5
  1450. || length($tvnums) != 5);
  1451. #If the base versions (without letters) don't match check they only differ
  1452. #in the last number
  1453. if ($cvnums ne $tvnums) {
  1454. die "Invalid version number: $testversion "
  1455. ."for current version $currversion\n"
  1456. if (substr($cvnums, 0, 4) ne substr($tvnums, 0, 4));
  1457. return;
  1458. }
  1459. #If we get here then the base version (i.e. the numbers) are the same - they
  1460. #only differ in the letters
  1461. $lentv = length $testversion;
  1462. $lencv = length $currversion;
  1463. #If the testversion has more letters than the current version then it must
  1464. #be later (or malformed)
  1465. if ($lentv > $lencv) {
  1466. die "Invalid version number: $testversion "
  1467. ."is greater than $currversion\n";
  1468. }
  1469. #Get the last letter from the current version
  1470. my ($cvletter) = $currversion =~ /([a-z])$/;
  1471. if (defined $cvletter) {
  1472. ($cvbase) = $currversion =~ /(\d_\d_\d[a-z]*)$cvletter$/;
  1473. } else {
  1474. $cvbase = $currversion;
  1475. }
  1476. die "Unable to parse version number $currversion" if (!defined $cvbase);
  1477. my $tvbase;
  1478. my ($tvletter) = $testversion =~ /([a-z])$/;
  1479. if (defined $tvletter) {
  1480. ($tvbase) = $testversion =~ /(\d_\d_\d[a-z]*)$tvletter$/;
  1481. } else {
  1482. $tvbase = $testversion;
  1483. }
  1484. die "Unable to parse version number $testversion" if (!defined $tvbase);
  1485. if ($lencv > $lentv) {
  1486. #If current version has more letters than testversion then testversion
  1487. #minus the final letter must be a substring of the current version
  1488. die "Invalid version number $testversion "
  1489. ."is greater than $currversion or is invalid\n"
  1490. if (index($cvbase, $tvbase) != 0);
  1491. } else {
  1492. #If both versions have the same number of letters then they must be
  1493. #equal up to the last letter, and the last letter in testversion must
  1494. #be less than or equal to the last letter in current version.
  1495. die "Invalid version number $testversion "
  1496. ."is greater than $currversion\n"
  1497. if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));
  1498. }
  1499. }
  1500. sub do_deprecated()
  1501. {
  1502. my ($decl, $plats, $algs) = @_;
  1503. $decl =~ /^\s*(DEPRECATEDIN_\d+_\d+_\d+)\s*\((.*)\)\s*$/
  1504. or die "Bad DEPRECATEDIN: $decl\n";
  1505. my $info1 .= "#INFO:";
  1506. $info1 .= join(',', @{$plats}) . ":";
  1507. my $info2 = $info1;
  1508. $info1 .= join(',',@{$algs}, $1) . ";";
  1509. $info2 .= join(',',@{$algs}) . ";";
  1510. return $info1 . $2 . ";" . $info2;
  1511. }