2
0

mkdef.pl 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  1. #! /usr/bin/env perl
  2. # Copyright 1995-2018 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. # Set this to make typesafe STACK definitions appear in DEF
  123. my $safe_stack_def = 0;
  124. my @known_platforms = ( "__FreeBSD__", "PERL5",
  125. "EXPORT_VAR_AS_FUNCTION", "ZLIB", "_WIN32"
  126. );
  127. my @known_ossl_platforms = ( "UNIX", "VMS", "WIN32", "WINNT", "OS2" );
  128. my @known_algorithms = ( # These are algorithms we know are guarded in relevant
  129. # header files, but aren't actually disablable.
  130. # Without these, this script will warn a lot.
  131. "RSA", "MD5",
  132. # @disablables comes from configdata.pm
  133. map { (my $x = uc $_) =~ s|-|_|g; $x; } @disablables,
  134. # Deprecated functions. Not really algorithmss, but
  135. # treated as such here for the sake of simplicity
  136. "DEPRECATEDIN_0_9_8",
  137. "DEPRECATEDIN_1_0_0",
  138. "DEPRECATEDIN_1_1_0",
  139. "DEPRECATEDIN_1_2_0",
  140. );
  141. # %disabled comes from configdata.pm
  142. my %disabled_algorithms =
  143. map { (my $x = uc $_) =~ s|-|_|g; $x => 1; } keys %disabled;
  144. my $apiv = sprintf "%x%02x%02x", split(/\./, $config{api});
  145. foreach (@known_algorithms) {
  146. if (/^DEPRECATEDIN_(\d+)_(\d+)_(\d+)$/) {
  147. my $depv = sprintf "%x%02x%02x", $1, $2, $3;
  148. $disabled_algorithms{$_} = 1 if $apiv ge $depv;
  149. }
  150. }
  151. my $zlib;
  152. foreach (@ARGV, split(/ /, $config{options}))
  153. {
  154. $debug=1 if $_ eq "debug";
  155. $trace=1 if $_ eq "trace";
  156. $verbose=1 if $_ eq "verbose";
  157. $W32=1 if $_ eq "32";
  158. die "win16 not supported" if $_ eq "16";
  159. if($_ eq "NT") {
  160. $W32 = 1;
  161. $NT = 1;
  162. }
  163. if ($_ eq "linux") {
  164. $linux=1;
  165. $UNIX=1;
  166. }
  167. $VMS=1 if $_ eq "VMS";
  168. if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
  169. || $_ eq "enable-zlib-dynamic") {
  170. $zlib = 1;
  171. }
  172. $do_crypto=1 if $_ eq "libcrypto" || $_ eq "crypto";
  173. $do_ssl=1 if $_ eq "libssl" || $_ eq "ssl";
  174. $do_update=1 if $_ eq "update";
  175. $do_rewrite=1 if $_ eq "rewrite";
  176. $do_ctest=1 if $_ eq "ctest";
  177. $do_ctestall=1 if $_ eq "ctestall";
  178. $do_checkexist=1 if $_ eq "exist";
  179. }
  180. $libname = $unified_info{sharednames}->{libcrypto} if $do_crypto;
  181. $libname = $unified_info{sharednames}->{libssl} if $do_ssl;
  182. if (!$libname) {
  183. if ($do_ssl) {
  184. $libname="LIBSSL";
  185. }
  186. if ($do_crypto) {
  187. $libname="LIBCRYPTO";
  188. }
  189. }
  190. # If no platform is given, assume WIN32
  191. if ($W32 + $VMS + $linux == 0) {
  192. $W32 = 1;
  193. }
  194. die "Please, only one platform at a time"
  195. if ($W32 + $VMS + $linux > 1);
  196. if (!$do_ssl && !$do_crypto)
  197. {
  198. print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 | linux | VMS ]\n";
  199. exit(1);
  200. }
  201. %ssl_list=&load_numbers($ssl_num);
  202. $max_ssl = $max_num;
  203. %crypto_list=&load_numbers($crypto_num);
  204. $max_crypto = $max_num;
  205. my $ssl="include/openssl/ssl.h";
  206. $ssl.=" include/openssl/sslerr.h";
  207. $ssl.=" include/openssl/tls1.h";
  208. $ssl.=" include/openssl/srtp.h";
  209. # When scanning include/openssl, skip all SSL files and some internal ones.
  210. my %skipthese;
  211. foreach my $f ( split(/\s+/, $ssl) ) {
  212. $skipthese{$f} = 1;
  213. }
  214. $skipthese{'include/openssl/conf_api.h'} = 1;
  215. $skipthese{'include/openssl/ebcdic.h'} = 1;
  216. $skipthese{'include/openssl/opensslconf.h'} = 1;
  217. # We use headers found in include/openssl and include/internal only.
  218. # The latter is needed so libssl.so/.dll/.exe can link properly.
  219. my $crypto ="include/internal/dso.h";
  220. $crypto.=" include/internal/o_dir.h";
  221. $crypto.=" include/internal/o_str.h";
  222. $crypto.=" include/internal/err.h";
  223. foreach my $f ( glob(catfile($config{sourcedir},'include/openssl/*.h')) ) {
  224. my $fn = "include/openssl/" . lc(basename($f));
  225. $crypto .= " $fn" if !defined $skipthese{$fn};
  226. }
  227. my $symhacks="include/openssl/symhacks.h";
  228. my @ssl_symbols = &do_defs("LIBSSL", $ssl, $symhacks);
  229. my @crypto_symbols = &do_defs("LIBCRYPTO", $crypto, $symhacks);
  230. if ($do_update) {
  231. if ($do_ssl == 1) {
  232. &maybe_add_info("LIBSSL",*ssl_list,@ssl_symbols);
  233. if ($do_rewrite == 1) {
  234. open(OUT, ">$ssl_num");
  235. &rewrite_numbers(*OUT,"LIBSSL",*ssl_list,@ssl_symbols);
  236. } else {
  237. open(OUT, ">>$ssl_num");
  238. }
  239. &update_numbers(*OUT,"LIBSSL",*ssl_list,$max_ssl,@ssl_symbols);
  240. close OUT;
  241. }
  242. if($do_crypto == 1) {
  243. &maybe_add_info("LIBCRYPTO",*crypto_list,@crypto_symbols);
  244. if ($do_rewrite == 1) {
  245. open(OUT, ">$crypto_num");
  246. &rewrite_numbers(*OUT,"LIBCRYPTO",*crypto_list,@crypto_symbols);
  247. } else {
  248. open(OUT, ">>$crypto_num");
  249. }
  250. &update_numbers(*OUT,"LIBCRYPTO",*crypto_list,$max_crypto,@crypto_symbols);
  251. close OUT;
  252. }
  253. } elsif ($do_checkexist) {
  254. &check_existing(*ssl_list, @ssl_symbols)
  255. if $do_ssl == 1;
  256. &check_existing(*crypto_list, @crypto_symbols)
  257. if $do_crypto == 1;
  258. } elsif ($do_ctest || $do_ctestall) {
  259. print <<"EOF";
  260. /* Test file to check all DEF file symbols are present by trying
  261. * to link to all of them. This is *not* intended to be run!
  262. */
  263. int main()
  264. {
  265. EOF
  266. &print_test_file(*STDOUT,"LIBSSL",*ssl_list,$do_ctestall,@ssl_symbols)
  267. if $do_ssl == 1;
  268. &print_test_file(*STDOUT,"LIBCRYPTO",*crypto_list,$do_ctestall,@crypto_symbols)
  269. if $do_crypto == 1;
  270. print "}\n";
  271. } else {
  272. &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
  273. if $do_ssl == 1;
  274. &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
  275. if $do_crypto == 1;
  276. }
  277. sub do_defs
  278. {
  279. my($name,$files,$symhacksfile)=@_;
  280. my $file;
  281. my @ret;
  282. my %syms;
  283. my %platform; # For anything undefined, we assume ""
  284. my %kind; # For anything undefined, we assume "FUNCTION"
  285. my %algorithm; # For anything undefined, we assume ""
  286. my %variant;
  287. my %variant_cnt; # To be able to allocate "name{n}" if "name"
  288. # is the same name as the original.
  289. my $cpp;
  290. my %unknown_algorithms = ();
  291. my $parens = 0;
  292. foreach $file (split(/\s+/,$symhacksfile." ".$files))
  293. {
  294. my $fn = catfile($config{sourcedir},$file);
  295. print STDERR "DEBUG: starting on $fn:\n" if $debug;
  296. print STDERR "TRACE: start reading $fn\n" if $trace;
  297. open(IN,"<$fn") || die "Can't open $fn, $!,";
  298. my $line = "", my $def= "";
  299. my %tag = (
  300. (map { $_ => 0 } @known_platforms),
  301. (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
  302. (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
  303. (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
  304. (grep /^DEPRECATED_/, @known_algorithms),
  305. NOPROTO => 0,
  306. PERL5 => 0,
  307. _WINDLL => 0,
  308. CONST_STRICT => 0,
  309. TRUE => 1,
  310. );
  311. my $symhacking = $file eq $symhacksfile;
  312. my @current_platforms = ();
  313. my @current_algorithms = ();
  314. # params: symbol, alias, platforms, kind
  315. # The reason to put this subroutine in a variable is that
  316. # it will otherwise create it's own, unshared, version of
  317. # %tag and %variant...
  318. my $make_variant = sub
  319. {
  320. my ($s, $a, $p, $k) = @_;
  321. my ($a1, $a2);
  322. print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
  323. if (defined($p))
  324. {
  325. $a1 = join(",",$p,
  326. grep(!/^$/,
  327. map { $tag{$_} == 1 ? $_ : "" }
  328. @known_platforms));
  329. }
  330. else
  331. {
  332. $a1 = join(",",
  333. grep(!/^$/,
  334. map { $tag{$_} == 1 ? $_ : "" }
  335. @known_platforms));
  336. }
  337. $a2 = join(",",
  338. grep(!/^$/,
  339. map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
  340. @known_ossl_platforms));
  341. print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
  342. if ($a1 eq "") { $a1 = $a2; }
  343. elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
  344. if ($a eq $s)
  345. {
  346. if (!defined($variant_cnt{$s}))
  347. {
  348. $variant_cnt{$s} = 0;
  349. }
  350. $variant_cnt{$s}++;
  351. $a .= "{$variant_cnt{$s}}";
  352. }
  353. my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
  354. my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
  355. if (!grep(/^$togrep$/,
  356. split(/;/, defined($variant{$s})?$variant{$s}:""))) {
  357. if (defined($variant{$s})) { $variant{$s} .= ";"; }
  358. $variant{$s} .= $toadd;
  359. }
  360. print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
  361. };
  362. print STDERR "DEBUG: parsing ----------\n" if $debug;
  363. while(<IN>) {
  364. s|\R$||; # Better chomp
  365. if($parens > 0) {
  366. #Inside a DEPRECATEDIN
  367. $stored_multiline .= $_;
  368. print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug;
  369. $parens = count_parens($stored_multiline);
  370. if ($parens == 0) {
  371. $def .= do_deprecated($stored_multiline,
  372. \@current_platforms,
  373. \@current_algorithms);
  374. }
  375. next;
  376. }
  377. if (/\/\* Error codes for the \w+ functions\. \*\//)
  378. {
  379. undef @tag;
  380. last;
  381. }
  382. if ($line ne '') {
  383. $_ = $line . $_;
  384. $line = '';
  385. }
  386. if (/\\$/) {
  387. $line = $`; # keep what was before the backslash
  388. next;
  389. }
  390. if(/\/\*/) {
  391. if (not /\*\//) { # multi-line comment...
  392. $line = $_; # ... just accumulate
  393. next;
  394. } else {
  395. s/\/\*.*?\*\///gs;# wipe it
  396. }
  397. }
  398. if ($cpp) {
  399. $cpp++ if /^#\s*if/;
  400. $cpp-- if /^#\s*endif/;
  401. next;
  402. }
  403. if (/^#.*ifdef.*cplusplus/) {
  404. $cpp = 1;
  405. next;
  406. }
  407. s/{[^{}]*}//gs; # ignore {} blocks
  408. print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
  409. print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
  410. if (/^\#\s*if\s+OPENSSL_API_COMPAT\s*(\S)\s*(0x[0-9a-fA-F]{8})L\s*$/) {
  411. my $op = $1;
  412. my $v = hex($2);
  413. if ($op ne '<' && $op ne '>=') {
  414. die "$file unacceptable operator $op: $_\n";
  415. }
  416. my ($one, $major, $minor) =
  417. ( ($v >> 28) & 0xf,
  418. ($v >> 20) & 0xff,
  419. ($v >> 12) & 0xff );
  420. my $t = "DEPRECATEDIN_${one}_${major}_${minor}";
  421. push(@tag,"-");
  422. push(@tag,$t);
  423. $tag{$t}=($op eq '<' ? 1 : -1);
  424. print STDERR "DEBUG: $file: found tag $t = $tag{$t}\n" if $debug;
  425. } elsif (/^\#\s*ifndef\s+(.*)/) {
  426. push(@tag,"-");
  427. push(@tag,$1);
  428. $tag{$1}=-1;
  429. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  430. } elsif (/^\#\s*if\s+!defined\s*\(([^\)]+)\)/) {
  431. push(@tag,"-");
  432. if (/^\#\s*if\s+(!defined\s*\(([^\)]+)\)(\s+\&\&\s+!defined\s*\(([^\)]+)\))*)$/) {
  433. my $tmp_1 = $1;
  434. my $tmp_;
  435. foreach $tmp_ (split '\&\&',$tmp_1) {
  436. $tmp_ =~ /!defined\s*\(([^\)]+)\)/;
  437. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  438. push(@tag,$1);
  439. $tag{$1}=-1;
  440. }
  441. } else {
  442. print STDERR "Warning: $file: taking only '!defined($1)' of complicated expression: $_" if $verbose; # because it is O...
  443. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  444. push(@tag,$1);
  445. $tag{$1}=-1;
  446. }
  447. } elsif (/^\#\s*ifdef\s+(\S*)/) {
  448. push(@tag,"-");
  449. push(@tag,$1);
  450. $tag{$1}=1;
  451. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  452. } elsif (/^\#\s*if\s+defined\s*\(([^\)]+)\)/) {
  453. push(@tag,"-");
  454. if (/^\#\s*if\s+(defined\s*\(([^\)]+)\)(\s+\|\|\s+defined\s*\(([^\)]+)\))*)$/) {
  455. my $tmp_1 = $1;
  456. my $tmp_;
  457. foreach $tmp_ (split '\|\|',$tmp_1) {
  458. $tmp_ =~ /defined\s*\(([^\)]+)\)/;
  459. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  460. push(@tag,$1);
  461. $tag{$1}=1;
  462. }
  463. } else {
  464. print STDERR "Warning: $file: taking only 'defined($1)' of complicated expression: $_\n" if $verbose; # because it is O...
  465. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  466. push(@tag,$1);
  467. $tag{$1}=1;
  468. }
  469. } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
  470. my $tag_i = $#tag;
  471. while($tag[$tag_i] ne "-") {
  472. if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
  473. $tag{$tag[$tag_i]}=2;
  474. print STDERR "DEBUG: $file: changed tag $1 = 2\n" if $debug;
  475. }
  476. $tag_i--;
  477. }
  478. } elsif (/^\#\s*endif/) {
  479. my $tag_i = $#tag;
  480. while($tag_i > 0 && $tag[$tag_i] ne "-") {
  481. my $t=$tag[$tag_i];
  482. print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
  483. if ($tag{$t}==2) {
  484. $tag{$t}=-1;
  485. } else {
  486. $tag{$t}=0;
  487. }
  488. print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
  489. pop(@tag);
  490. if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
  491. $t=$1;
  492. } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
  493. $t=$1;
  494. } else {
  495. $t="";
  496. }
  497. if ($t ne ""
  498. && !grep(/^$t$/, @known_algorithms)) {
  499. $unknown_algorithms{$t} = 1;
  500. #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
  501. }
  502. $tag_i--;
  503. }
  504. pop(@tag);
  505. } elsif (/^\#\s*else/) {
  506. my $tag_i = $#tag;
  507. die "$file unmatched else\n" if $tag_i < 0;
  508. while($tag[$tag_i] ne "-") {
  509. my $t=$tag[$tag_i];
  510. $tag{$t}= -$tag{$t};
  511. print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
  512. $tag_i--;
  513. }
  514. } elsif (/^\#\s*if\s+1/) {
  515. push(@tag,"-");
  516. # Dummy tag
  517. push(@tag,"TRUE");
  518. $tag{"TRUE"}=1;
  519. print STDERR "DEBUG: $file: found 1\n" if $debug;
  520. } elsif (/^\#\s*if\s+0/) {
  521. push(@tag,"-");
  522. # Dummy tag
  523. push(@tag,"TRUE");
  524. $tag{"TRUE"}=-1;
  525. print STDERR "DEBUG: $file: found 0\n" if $debug;
  526. } elsif (/^\#\s*if\s+/) {
  527. #Some other unrecognized "if" style
  528. push(@tag,"-");
  529. print STDERR "Warning: $file: ignoring unrecognized expression: $_\n" if $verbose; # because it is O...
  530. } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
  531. && $symhacking && $tag{'TRUE'} != -1) {
  532. # This is for aliasing. When we find an alias,
  533. # we have to invert
  534. &$make_variant($1,$2);
  535. print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
  536. }
  537. if (/^\#/) {
  538. @current_platforms =
  539. grep(!/^$/,
  540. map { $tag{$_} == 1 ? $_ :
  541. $tag{$_} == -1 ? "!".$_ : "" }
  542. @known_platforms);
  543. push @current_platforms
  544. , grep(!/^$/,
  545. map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
  546. $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
  547. @known_ossl_platforms);
  548. @current_algorithms = ();
  549. @current_algorithms =
  550. grep(!/^$/,
  551. map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
  552. @known_algorithms);
  553. push @current_algorithms
  554. , grep(!/^$/,
  555. map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
  556. @known_algorithms);
  557. push @current_algorithms,
  558. grep { /^DEPRECATEDIN_/ && $tag{$_} == 1 }
  559. @known_algorithms;
  560. $def .=
  561. "#INFO:"
  562. .join(',',@current_platforms).":"
  563. .join(',',@current_algorithms).";";
  564. next;
  565. }
  566. if ($tag{'TRUE'} != -1) {
  567. if (/^\s*DEFINE_STACK_OF\s*\(\s*(\w*)\s*\)/
  568. || /^\s*DEFINE_STACK_OF_CONST\s*\(\s*(\w*)\s*\)/) {
  569. next;
  570. } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  571. $def .= "int d2i_$3(void);";
  572. $def .= "int i2d_$3(void);";
  573. # Variant for platforms that do not
  574. # have to access global variables
  575. # in shared libraries through functions
  576. $def .=
  577. "#INFO:"
  578. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  579. .join(',',@current_algorithms).";";
  580. $def .= "OPENSSL_EXTERN int $2_it;";
  581. $def .=
  582. "#INFO:"
  583. .join(',',@current_platforms).":"
  584. .join(',',@current_algorithms).";";
  585. # Variant for platforms that have to
  586. # access global variables in shared
  587. # libraries through functions
  588. &$make_variant("$2_it","$2_it",
  589. "EXPORT_VAR_AS_FUNCTION",
  590. "FUNCTION");
  591. next;
  592. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  593. $def .= "int d2i_$3(void);";
  594. $def .= "int i2d_$3(void);";
  595. $def .= "int $3_free(void);";
  596. $def .= "int $3_new(void);";
  597. # Variant for platforms that do not
  598. # have to access global variables
  599. # in shared libraries through functions
  600. $def .=
  601. "#INFO:"
  602. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  603. .join(',',@current_algorithms).";";
  604. $def .= "OPENSSL_EXTERN int $2_it;";
  605. $def .=
  606. "#INFO:"
  607. .join(',',@current_platforms).":"
  608. .join(',',@current_algorithms).";";
  609. # Variant for platforms that have to
  610. # access global variables in shared
  611. # libraries through functions
  612. &$make_variant("$2_it","$2_it",
  613. "EXPORT_VAR_AS_FUNCTION",
  614. "FUNCTION");
  615. next;
  616. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
  617. /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
  618. $def .= "int d2i_$1(void);";
  619. $def .= "int i2d_$1(void);";
  620. $def .= "int $1_free(void);";
  621. $def .= "int $1_new(void);";
  622. # Variant for platforms that do not
  623. # have to access global variables
  624. # in shared libraries through functions
  625. $def .=
  626. "#INFO:"
  627. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  628. .join(',',@current_algorithms).";";
  629. $def .= "OPENSSL_EXTERN int $1_it;";
  630. $def .=
  631. "#INFO:"
  632. .join(',',@current_platforms).":"
  633. .join(',',@current_algorithms).";";
  634. # Variant for platforms that have to
  635. # access global variables in shared
  636. # libraries through functions
  637. &$make_variant("$1_it","$1_it",
  638. "EXPORT_VAR_AS_FUNCTION",
  639. "FUNCTION");
  640. next;
  641. } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  642. $def .= "int d2i_$2(void);";
  643. $def .= "int i2d_$2(void);";
  644. # Variant for platforms that do not
  645. # have to access global variables
  646. # in shared libraries through functions
  647. $def .=
  648. "#INFO:"
  649. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  650. .join(',',@current_algorithms).";";
  651. $def .= "OPENSSL_EXTERN int $2_it;";
  652. $def .=
  653. "#INFO:"
  654. .join(',',@current_platforms).":"
  655. .join(',',@current_algorithms).";";
  656. # Variant for platforms that have to
  657. # access global variables in shared
  658. # libraries through functions
  659. &$make_variant("$2_it","$2_it",
  660. "EXPORT_VAR_AS_FUNCTION",
  661. "FUNCTION");
  662. next;
  663. } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
  664. $def .= "int $1_free(void);";
  665. $def .= "int $1_new(void);";
  666. next;
  667. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  668. $def .= "int d2i_$2(void);";
  669. $def .= "int i2d_$2(void);";
  670. $def .= "int $2_free(void);";
  671. $def .= "int $2_new(void);";
  672. # Variant for platforms that do not
  673. # have to access global variables
  674. # in shared libraries through functions
  675. $def .=
  676. "#INFO:"
  677. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  678. .join(',',@current_algorithms).";";
  679. $def .= "OPENSSL_EXTERN int $2_it;";
  680. $def .=
  681. "#INFO:"
  682. .join(',',@current_platforms).":"
  683. .join(',',@current_algorithms).";";
  684. # Variant for platforms that have to
  685. # access global variables in shared
  686. # libraries through functions
  687. &$make_variant("$2_it","$2_it",
  688. "EXPORT_VAR_AS_FUNCTION",
  689. "FUNCTION");
  690. next;
  691. } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
  692. # Variant for platforms that do not
  693. # have to access global variables
  694. # in shared libraries through functions
  695. $def .=
  696. "#INFO:"
  697. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  698. .join(',',@current_algorithms).";";
  699. $def .= "OPENSSL_EXTERN int $1_it;";
  700. $def .=
  701. "#INFO:"
  702. .join(',',@current_platforms).":"
  703. .join(',',@current_algorithms).";";
  704. # Variant for platforms that have to
  705. # access global variables in shared
  706. # libraries through functions
  707. &$make_variant("$1_it","$1_it",
  708. "EXPORT_VAR_AS_FUNCTION",
  709. "FUNCTION");
  710. next;
  711. } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
  712. $def .= "int i2d_$1_NDEF(void);";
  713. } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
  714. next;
  715. } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
  716. $def .= "int $1_print_ctx(void);";
  717. next;
  718. } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  719. $def .= "int $2_print_ctx(void);";
  720. next;
  721. } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
  722. next;
  723. } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
  724. /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
  725. /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
  726. $def .=
  727. "#INFO:"
  728. .join(',',@current_platforms).":"
  729. .join(',',"STDIO",@current_algorithms).";";
  730. $def .= "int PEM_read_$1(void);";
  731. $def .= "int PEM_write_$1(void);";
  732. $def .=
  733. "#INFO:"
  734. .join(',',@current_platforms).":"
  735. .join(',',@current_algorithms).";";
  736. # Things that are everywhere
  737. $def .= "int PEM_read_bio_$1(void);";
  738. $def .= "int PEM_write_bio_$1(void);";
  739. next;
  740. } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
  741. /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
  742. /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
  743. $def .=
  744. "#INFO:"
  745. .join(',',@current_platforms).":"
  746. .join(',',"STDIO",@current_algorithms).";";
  747. $def .= "int PEM_write_$1(void);";
  748. $def .=
  749. "#INFO:"
  750. .join(',',@current_platforms).":"
  751. .join(',',@current_algorithms).";";
  752. # Things that are everywhere
  753. $def .= "int PEM_write_bio_$1(void);";
  754. next;
  755. } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
  756. /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
  757. $def .=
  758. "#INFO:"
  759. .join(',',@current_platforms).":"
  760. .join(',',"STDIO",@current_algorithms).";";
  761. $def .= "int PEM_read_$1(void);";
  762. $def .=
  763. "#INFO:"
  764. .join(',',@current_platforms).":"
  765. .join(',',"STDIO",@current_algorithms).";";
  766. # Things that are everywhere
  767. $def .= "int PEM_read_bio_$1(void);";
  768. next;
  769. } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  770. # Variant for platforms that do not
  771. # have to access global variables
  772. # in shared libraries through functions
  773. $def .=
  774. "#INFO:"
  775. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  776. .join(',',@current_algorithms).";";
  777. $def .= "OPENSSL_EXTERN int _shadow_$2;";
  778. $def .=
  779. "#INFO:"
  780. .join(',',@current_platforms).":"
  781. .join(',',@current_algorithms).";";
  782. # Variant for platforms that have to
  783. # access global variables in shared
  784. # libraries through functions
  785. &$make_variant("_shadow_$2","_shadow_$2",
  786. "EXPORT_VAR_AS_FUNCTION",
  787. "FUNCTION");
  788. } elsif (/^\s*DEPRECATEDIN/) {
  789. $parens = count_parens($_);
  790. if ($parens == 0) {
  791. $def .= do_deprecated($_,
  792. \@current_platforms,
  793. \@current_algorithms);
  794. } else {
  795. $stored_multiline = $_;
  796. print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug;
  797. next;
  798. }
  799. } elsif ($tag{'CONST_STRICT'} != 1) {
  800. if (/\{|\/\*|\([^\)]*$/) {
  801. $line = $_;
  802. } else {
  803. $def .= $_;
  804. }
  805. }
  806. }
  807. }
  808. close(IN);
  809. die "$file: Unmatched tags\n" if $#tag >= 0;
  810. my $algs;
  811. my $plays;
  812. print STDERR "DEBUG: postprocessing ----------\n" if $debug;
  813. foreach (split /;/, $def) {
  814. my $s; my $k = "FUNCTION"; my $p; my $a;
  815. s/^[\n\s]*//g;
  816. s/[\n\s]*$//g;
  817. next if(/\#undef/);
  818. next if(/typedef\W/);
  819. next if(/\#define/);
  820. print STDERR "TRACE: processing $_\n" if $trace && !/^\#INFO:/;
  821. # Reduce argument lists to empty ()
  822. # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
  823. my $nsubst = 1; # prevent infinite loop, e.g., on int fn()
  824. while($nsubst && /\(.*\)/s) {
  825. $nsubst = s/\([^\(\)]+\)/\{\}/gs;
  826. $nsubst+= s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
  827. }
  828. # pretend as we didn't use curly braces: {} -> ()
  829. s/\{\}/\(\)/gs;
  830. s/STACK_OF\(\)/void/gs;
  831. s/LHASH_OF\(\)/void/gs;
  832. print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
  833. if (/^\#INFO:([^:]*):(.*)$/) {
  834. $plats = $1;
  835. $algs = $2;
  836. print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
  837. next;
  838. } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
  839. $s = $1;
  840. $k = "VARIABLE";
  841. print STDERR "DEBUG: found external variable $s\n" if $debug;
  842. } elsif (/TYPEDEF_\w+_OF/s) {
  843. next;
  844. } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
  845. $s = $1; # a function name!
  846. print STDERR "DEBUG: found function $s\n" if $debug;
  847. } elsif (/\(/ and not (/=/)) {
  848. print STDERR "File $file: cannot parse: $_;\n";
  849. next;
  850. } else {
  851. next;
  852. }
  853. $syms{$s} = 1;
  854. $kind{$s} = $k;
  855. $p = $plats;
  856. $a = $algs;
  857. $platform{$s} =
  858. &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
  859. $algorithm{$s} .= ','.$a;
  860. if (defined($variant{$s})) {
  861. foreach $v (split /;/,$variant{$s}) {
  862. (my $r, my $p, my $k) = split(/:/,$v);
  863. my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
  864. $syms{$r} = 1;
  865. if (!defined($k)) { $k = $kind{$s}; }
  866. $kind{$r} = $k."(".$s.")";
  867. $algorithm{$r} = $algorithm{$s};
  868. $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
  869. $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
  870. print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
  871. }
  872. }
  873. print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
  874. }
  875. }
  876. # Prune the returned symbols
  877. delete $syms{"bn_dump1"};
  878. $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
  879. $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
  880. $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
  881. $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
  882. $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
  883. # Info we know about
  884. push @ret, map { $_."\\".&info_string($_,"EXIST",
  885. $platform{$_},
  886. $kind{$_},
  887. $algorithm{$_}) } keys %syms;
  888. if (keys %unknown_algorithms) {
  889. print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
  890. print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
  891. }
  892. return(@ret);
  893. }
  894. # Param: string of comma-separated platform-specs.
  895. sub reduce_platforms
  896. {
  897. my ($platforms) = @_;
  898. my $pl = defined($platforms) ? $platforms : "";
  899. my %p = map { $_ => 0 } split /,/, $pl;
  900. my $ret;
  901. print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
  902. if $debug;
  903. # We do this, because if there's code like the following, it really
  904. # means the function exists in all cases and should therefore be
  905. # everywhere. By increasing and decreasing, we may attain 0:
  906. #
  907. # ifndef WIN16
  908. # int foo();
  909. # else
  910. # int _fat foo();
  911. # endif
  912. foreach $platform (split /,/, $pl) {
  913. if ($platform =~ /^!(.*)$/) {
  914. $p{$1}--;
  915. } else {
  916. $p{$platform}++;
  917. }
  918. }
  919. foreach $platform (keys %p) {
  920. if ($p{$platform} == 0) { delete $p{$platform}; }
  921. }
  922. delete $p{""};
  923. $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
  924. print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
  925. if $debug;
  926. return $ret;
  927. }
  928. sub info_string
  929. {
  930. (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
  931. my %a = defined($algorithms) ?
  932. map { $_ => 1 } split /,/, $algorithms : ();
  933. my $k = defined($kind) ? $kind : "FUNCTION";
  934. my $ret;
  935. my $p = &reduce_platforms($platforms);
  936. delete $a{""};
  937. $ret = $exist;
  938. $ret .= ":".$p;
  939. $ret .= ":".$k;
  940. $ret .= ":".join(',',sort keys %a);
  941. return $ret;
  942. }
  943. sub maybe_add_info
  944. {
  945. (my $name, *nums, my @symbols) = @_;
  946. my $sym;
  947. my $new_info = 0;
  948. my %syms=();
  949. foreach $sym (@symbols) {
  950. (my $s, my $i) = split /\\/, $sym;
  951. if (defined($nums{$s})) {
  952. $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
  953. (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
  954. if (!defined($dummy) || $i ne $dummy) {
  955. $nums{$s} = $n."\\".$vers."\\".$i;
  956. $new_info++;
  957. print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
  958. }
  959. }
  960. $syms{$s} = 1;
  961. }
  962. my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
  963. foreach $sym (@s) {
  964. (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
  965. if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
  966. $new_info++;
  967. print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
  968. }
  969. }
  970. if ($new_info) {
  971. print STDERR "$name: $new_info old symbols have updated info\n";
  972. if (!$do_rewrite) {
  973. print STDERR "You should do a rewrite to fix this.\n";
  974. }
  975. } else {
  976. }
  977. }
  978. # Param: string of comma-separated keywords, each possibly prefixed with a "!"
  979. sub is_valid
  980. {
  981. my ($keywords_txt,$platforms) = @_;
  982. my (@keywords) = split /,/,$keywords_txt;
  983. my ($falsesum, $truesum) = (0, 1);
  984. # Param: one keyword
  985. sub recognise
  986. {
  987. my ($keyword,$platforms) = @_;
  988. if ($platforms) {
  989. # platforms
  990. if ($keyword eq "UNIX" && $UNIX) { return 1; }
  991. if ($keyword eq "VMS" && $VMS) { return 1; }
  992. if ($keyword eq "WIN32" && $W32) { return 1; }
  993. if ($keyword eq "_WIN32" && $W32) { return 1; }
  994. if ($keyword eq "WINNT" && $NT) { return 1; }
  995. # Special platforms:
  996. # EXPORT_VAR_AS_FUNCTION means that global variables
  997. # will be represented as functions.
  998. if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && $W32) {
  999. return 1;
  1000. }
  1001. if ($keyword eq "ZLIB" && $zlib) { return 1; }
  1002. return 0;
  1003. } else {
  1004. # algorithms
  1005. if ($disabled_algorithms{$keyword}) { return 0;}
  1006. # Nothing recognise as true
  1007. return 1;
  1008. }
  1009. }
  1010. foreach $k (@keywords) {
  1011. if ($k =~ /^!(.*)$/) {
  1012. $falsesum += &recognise($1,$platforms);
  1013. } else {
  1014. $truesum *= &recognise($k,$platforms);
  1015. }
  1016. }
  1017. print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
  1018. return (!$falsesum) && $truesum;
  1019. }
  1020. sub print_test_file
  1021. {
  1022. (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
  1023. my $n = 1; my @e; my @r;
  1024. my $sym; my $prev = ""; my $prefSSLeay;
  1025. (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
  1026. (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
  1027. @symbols=((sort @e),(sort @r));
  1028. foreach $sym (@symbols) {
  1029. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1030. my $v = 0;
  1031. $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
  1032. my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
  1033. my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
  1034. if (!defined($nums{$s})) {
  1035. print STDERR "Warning: $s does not have a number assigned\n"
  1036. if(!$do_update);
  1037. } elsif (is_valid($p,1) && is_valid($a,0)) {
  1038. my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
  1039. if ($prev eq $s2) {
  1040. print OUT "\t/* The following has already appeared previously */\n";
  1041. print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
  1042. }
  1043. $prev = $s2; # To warn about duplicates...
  1044. (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
  1045. if ($v) {
  1046. print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
  1047. } else {
  1048. print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
  1049. }
  1050. }
  1051. }
  1052. }
  1053. sub get_version
  1054. {
  1055. return $config{version};
  1056. }
  1057. sub print_def_file
  1058. {
  1059. (*OUT,my $name,*nums,my @symbols)=@_;
  1060. my $n = 1; my @e; my @r; my @v; my $prev="";
  1061. my $liboptions="";
  1062. my $libname = $name;
  1063. my $http_vendor = 'www.openssl.org/';
  1064. my $version = get_version();
  1065. my $what = "OpenSSL: implementation of Secure Socket Layer";
  1066. my $description = "$what $version, $name - http://$http_vendor";
  1067. my $prevsymversion = "", $prevprevsymversion = "";
  1068. # For VMS
  1069. my $prevnum = 0;
  1070. my $symvtextcount = 0;
  1071. if ($W32)
  1072. {
  1073. print OUT <<"EOF";
  1074. ;
  1075. ; Definition file for the DLL version of the $name library from OpenSSL
  1076. ;
  1077. LIBRARY $libname $liboptions
  1078. EOF
  1079. print "EXPORTS\n";
  1080. }
  1081. elsif ($VMS)
  1082. {
  1083. print OUT <<"EOF";
  1084. IDENTIFICATION=$version
  1085. CASE_SENSITIVE=YES
  1086. SYMBOL_VECTOR=(-
  1087. EOF
  1088. $symvtextcount = 16; # length of "SYMBOL_VECTOR=(-"
  1089. }
  1090. (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
  1091. (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
  1092. if ($VMS) {
  1093. # VMS needs to have the symbols on slot number order
  1094. @symbols=(map { $_->[1] }
  1095. sort { $a->[0] <=> $b->[0] }
  1096. map { (my $s, my $i) = $_ =~ /^(.*?)\\(.*)$/;
  1097. die "Error: $s doesn't have a number assigned\n"
  1098. if !defined($nums{$s});
  1099. (my $n, my @rest) = split /\\/, $nums{$s};
  1100. [ $n, $_ ] } (@e, @r, @v));
  1101. } else {
  1102. @symbols=((sort @e),(sort @r), (sort @v));
  1103. }
  1104. my ($baseversion, $currversion) = get_openssl_version();
  1105. my $thisversion;
  1106. do {
  1107. if (!defined($thisversion)) {
  1108. $thisversion = $baseversion;
  1109. } else {
  1110. $thisversion = get_next_version($thisversion);
  1111. }
  1112. foreach $sym (@symbols) {
  1113. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1114. my $v = 0;
  1115. $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
  1116. if (!defined($nums{$s})) {
  1117. die "Error: $s does not have a number assigned\n"
  1118. if(!$do_update);
  1119. } else {
  1120. (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
  1121. my %pf = ();
  1122. my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
  1123. my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
  1124. if (is_valid($p,1) && is_valid($a,0)) {
  1125. my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
  1126. if ($prev eq $s2) {
  1127. print STDERR "Warning: Symbol '",$s2,
  1128. "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
  1129. ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
  1130. }
  1131. $prev = $s2; # To warn about duplicates...
  1132. if($linux) {
  1133. next if $symversion ne $thisversion;
  1134. if ($symversion ne $prevsymversion) {
  1135. if ($prevsymversion ne "") {
  1136. if ($prevprevsymversion ne "") {
  1137. print OUT "} OPENSSL${SO_VARIANT}_"
  1138. ."$prevprevsymversion;\n\n";
  1139. } else {
  1140. print OUT "};\n\n";
  1141. }
  1142. }
  1143. print OUT "OPENSSL${SO_VARIANT}_$symversion {\n global:\n";
  1144. $prevprevsymversion = $prevsymversion;
  1145. $prevsymversion = $symversion;
  1146. }
  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+)$/;
  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. }