Configure 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833
  1. #! /usr/bin/env perl
  2. # -*- mode: perl; -*-
  3. # Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
  4. #
  5. # Licensed under the OpenSSL license (the "License"). You may not use
  6. # this file except in compliance with the License. You can obtain a copy
  7. # in the file LICENSE in the source distribution or at
  8. # https://www.openssl.org/source/license.html
  9. ## Configure -- OpenSSL source tree configuration script
  10. use 5.10.0;
  11. use strict;
  12. use FindBin;
  13. use lib "$FindBin::Bin/util/perl";
  14. use File::Basename;
  15. use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
  16. use File::Path qw/mkpath/;
  17. use OpenSSL::Glob;
  18. # see INSTALL for instructions.
  19. my $orig_death_handler = $SIG{__DIE__};
  20. $SIG{__DIE__} = \&death_handler;
  21. my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";
  22. # Options:
  23. #
  24. # --config add the given configuration file, which will be read after
  25. # any "Configurations*" files that are found in the same
  26. # directory as this script.
  27. # --prefix prefix for the OpenSSL installation, which includes the
  28. # directories bin, lib, include, share/man, share/doc/openssl
  29. # This becomes the value of INSTALLTOP in Makefile
  30. # (Default: /usr/local)
  31. # --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys.
  32. # If it's a relative directory, it will be added on the directory
  33. # given with --prefix.
  34. # This becomes the value of OPENSSLDIR in Makefile and in C.
  35. # (Default: PREFIX/ssl)
  36. #
  37. # --cross-compile-prefix Add specified prefix to binutils components.
  38. #
  39. # --api One of 0.9.8, 1.0.0 or 1.1.0. Do not compile support for
  40. # interfaces deprecated as of the specified OpenSSL version.
  41. #
  42. # no-hw-xxx do not compile support for specific crypto hardware.
  43. # Generic OpenSSL-style methods relating to this support
  44. # are always compiled but return NULL if the hardware
  45. # support isn't compiled.
  46. # no-hw do not compile support for any crypto hardware.
  47. # [no-]threads [don't] try to create a library that is suitable for
  48. # multithreaded applications (default is "threads" if we
  49. # know how to do it)
  50. # [no-]shared [don't] try to create shared libraries when supported.
  51. # [no-]pic [don't] try to build position independent code when supported.
  52. # If disabled, it also disables shared and dynamic-engine.
  53. # no-asm do not use assembler
  54. # no-dso do not compile in any native shared-library methods. This
  55. # will ensure that all methods just return NULL.
  56. # no-egd do not compile support for the entropy-gathering daemon APIs
  57. # [no-]zlib [don't] compile support for zlib compression.
  58. # zlib-dynamic Like "zlib", but the zlib library is expected to be a shared
  59. # library and will be loaded in run-time by the OpenSSL library.
  60. # sctp include SCTP support
  61. # enable-weak-ssl-ciphers
  62. # Enable weak ciphers that are disabled by default.
  63. # 386 generate 80386 code in assembly modules
  64. # no-sse2 disables IA-32 SSE2 code in assembly modules, the above
  65. # mentioned '386' option implies this one
  66. # no-<cipher> build without specified algorithm (rsa, idea, rc5, ...)
  67. # -<xxx> +<xxx> compiler options are passed through
  68. # -static while -static is also a pass-through compiler option (and
  69. # as such is limited to environments where it's actually
  70. # meaningful), it triggers a number configuration options,
  71. # namely no-dso, no-pic, no-shared and no-threads. It is
  72. # argued that the only reason to produce statically linked
  73. # binaries (and in context it means executables linked with
  74. # -static flag, and not just executables linked with static
  75. # libcrypto.a) is to eliminate dependency on specific run-time,
  76. # a.k.a. libc version. The mentioned config options are meant
  77. # to achieve just that. Unfortunately on Linux it's impossible
  78. # to eliminate the dependency completely for openssl executable
  79. # because of getaddrinfo and gethostbyname calls, which can
  80. # invoke dynamically loadable library facility anyway to meet
  81. # the lookup requests. For this reason on Linux statically
  82. # linked openssl executable has rather debugging value than
  83. # production quality.
  84. #
  85. # DEBUG_SAFESTACK use type-safe stacks to enforce type-safety on stack items
  86. # provided to stack calls. Generates unique stack functions for
  87. # each possible stack type.
  88. # BN_LLONG use the type 'long long' in crypto/bn/bn.h
  89. # RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
  90. # Following are set automatically by this script
  91. #
  92. # MD5_ASM use some extra md5 assembler,
  93. # SHA1_ASM use some extra sha1 assembler, must define L_ENDIAN for x86
  94. # RMD160_ASM use some extra ripemd160 assembler,
  95. # SHA256_ASM sha256_block is implemented in assembler
  96. # SHA512_ASM sha512_block is implemented in assembler
  97. # AES_ASM AES_[en|de]crypt is implemented in assembler
  98. # Minimum warning options... any contributions to OpenSSL should at least get
  99. # past these.
  100. # DEBUG_UNUSED enables __owur (warn unused result) checks.
  101. my $gcc_devteam_warn = "-DDEBUG_UNUSED"
  102. # -DPEDANTIC complements -pedantic and is meant to mask code that
  103. # is not strictly standard-compliant and/or implementation-specific,
  104. # e.g. inline assembly, disregards to alignment requirements, such
  105. # that -pedantic would complain about. Incidentally -DPEDANTIC has
  106. # to be used even in sanitized builds, because sanitizer too is
  107. # supposed to and does take notice of non-standard behaviour. Then
  108. # -pedantic with pre-C9x compiler would also complain about 'long
  109. # long' not being supported. As 64-bit algorithms are common now,
  110. # it grew impossible to resolve this without sizeable additional
  111. # code, so we just tell compiler to be pedantic about everything
  112. # but 'long long' type.
  113. . " -DPEDANTIC -pedantic -Wno-long-long"
  114. . " -Wall"
  115. . " -Wextra"
  116. . " -Wno-unused-parameter"
  117. . " -Wno-missing-field-initializers"
  118. . " -Wsign-compare"
  119. . " -Wmissing-prototypes"
  120. . " -Wshadow"
  121. . " -Wformat"
  122. . " -Wtype-limits"
  123. . " -Wundef"
  124. . " -Werror"
  125. ;
  126. # These are used in addition to $gcc_devteam_warn when the compiler is clang.
  127. # TODO(openssl-team): fix problems and investigate if (at least) the
  128. # following warnings can also be enabled:
  129. # -Wswitch-enum
  130. # -Wcast-align
  131. # -Wunreachable-code
  132. # -Wlanguage-extension-token -- no, we use asm()
  133. # -Wunused-macros -- no, too tricky for BN and _XOPEN_SOURCE etc
  134. # -Wextended-offsetof -- no, needed in CMS ASN1 code
  135. my $clang_devteam_warn = ""
  136. . " -Wno-unknown-warning-option"
  137. . " -Qunused-arguments"
  138. . " -Wno-language-extension-token"
  139. . " -Wno-extended-offsetof"
  140. . " -Wconditional-uninitialized"
  141. . " -Wincompatible-pointer-types-discards-qualifiers"
  142. . " -Wmissing-variable-declarations"
  143. ;
  144. # This adds backtrace information to the memory leak info. Is only used
  145. # when crypto-mdebug-backtrace is enabled.
  146. my $memleak_devteam_backtrace = "-rdynamic";
  147. my $strict_warnings = 0;
  148. # As for $BSDthreads. Idea is to maintain "collective" set of flags,
  149. # which would cover all BSD flavors. -pthread applies to them all,
  150. # but is treated differently. OpenBSD expands is as -D_POSIX_THREAD
  151. # -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r,
  152. # which has to be accompanied by explicit -D_THREAD_SAFE and
  153. # sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which
  154. # seems to be sufficient?
  155. our $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT";
  156. #
  157. # API compatibility name to version number mapping.
  158. #
  159. my $maxapi = "1.1.0"; # API for "no-deprecated" builds
  160. my $apitable = {
  161. "1.1.0" => "0x10100000L",
  162. "1.0.0" => "0x10000000L",
  163. "0.9.8" => "0x00908000L",
  164. };
  165. our %table = ();
  166. our %config = ();
  167. our %withargs = ();
  168. # Forward declarations ###############################################
  169. # read_config(filename)
  170. #
  171. # Reads a configuration file and populates %table with the contents
  172. # (which the configuration file places in %targets).
  173. sub read_config;
  174. # resolve_config(target)
  175. #
  176. # Resolves all the late evaluations, inheritances and so on for the
  177. # chosen target and any target it inherits from.
  178. sub resolve_config;
  179. # Information collection #############################################
  180. # Unified build supports separate build dir
  181. my $srcdir = catdir(absolutedir(dirname($0))); # catdir ensures local syntax
  182. my $blddir = catdir(absolutedir(".")); # catdir ensures local syntax
  183. my $dofile = abs2rel(catfile($srcdir, "util/dofile.pl"));
  184. my $local_config_envname = 'OPENSSL_LOCAL_CONFIG_DIR';
  185. $config{sourcedir} = abs2rel($srcdir);
  186. $config{builddir} = abs2rel($blddir);
  187. # Collect reconfiguration information if needed
  188. my @argvcopy=@ARGV;
  189. if (grep /^reconf(igure)?$/, @argvcopy) {
  190. if (-f "./configdata.pm") {
  191. my $file = "./configdata.pm";
  192. unless (my $return = do $file) {
  193. die "couldn't parse $file: $@" if $@;
  194. die "couldn't do $file: $!" unless defined $return;
  195. die "couldn't run $file" unless $return;
  196. }
  197. @argvcopy = defined($configdata::config{perlargv}) ?
  198. @{$configdata::config{perlargv}} : ();
  199. die "Incorrect data to reconfigure, please do a normal configuration\n"
  200. if (grep(/^reconf/,@argvcopy));
  201. $ENV{CROSS_COMPILE} = $configdata::config{cross_compile_prefix}
  202. if defined($configdata::config{cross_compile_prefix});
  203. $ENV{CC} = $configdata::config{cc}
  204. if defined($configdata::config{cc});
  205. $ENV{BUILDFILE} = $configdata::config{build_file}
  206. if defined($configdata::config{build_file});
  207. $ENV{$local_config_envname} = $configdata::config{local_config_dir}
  208. if defined($configdata::config{local_config_dir});
  209. print "Reconfiguring with: ", join(" ",@argvcopy), "\n";
  210. print " CROSS_COMPILE = ",$ENV{CROSS_COMPILE},"\n"
  211. if $ENV{CROSS_COMPILE};
  212. print " CC = ",$ENV{CC},"\n" if $ENV{CC};
  213. print " BUILDFILE = ",$ENV{BUILDFILE},"\n" if $ENV{BUILDFILE};
  214. print " $local_config_envname = ",$ENV{$local_config_envname},"\n"
  215. if $ENV{$local_config_envname};
  216. } else {
  217. die "Insufficient data to reconfigure, please do a normal configuration\n";
  218. }
  219. }
  220. $config{perlargv} = [ @argvcopy ];
  221. # Collect version numbers
  222. $config{version} = "unknown";
  223. $config{version_num} = "unknown";
  224. $config{shlib_version_number} = "unknown";
  225. $config{shlib_version_history} = "unknown";
  226. collect_information(
  227. collect_from_file(catfile($srcdir,'include/openssl/opensslv.h')),
  228. qr/OPENSSL.VERSION.TEXT.*OpenSSL (\S+) / => sub { $config{version} = $1; },
  229. qr/OPENSSL.VERSION.NUMBER.*(0x\S+)/ => sub { $config{version_num}=$1 },
  230. qr/SHLIB_VERSION_NUMBER *"([^"]+)"/ => sub { $config{shlib_version_number}=$1 },
  231. qr/SHLIB_VERSION_HISTORY *"([^"]*)"/ => sub { $config{shlib_version_history}=$1 }
  232. );
  233. if ($config{shlib_version_history} ne "") { $config{shlib_version_history} .= ":"; }
  234. ($config{major}, $config{minor})
  235. = ($config{version} =~ /^([0-9]+)\.([0-9\.]+)/);
  236. ($config{shlib_major}, $config{shlib_minor})
  237. = ($config{shlib_version_number} =~ /^([0-9]+)\.([0-9\.]+)/);
  238. die "erroneous version information in opensslv.h: ",
  239. "$config{major}, $config{minor}, $config{shlib_major}, $config{shlib_minor}\n"
  240. if ($config{major} eq "" || $config{minor} eq ""
  241. || $config{shlib_major} eq "" || $config{shlib_minor} eq "");
  242. # Collect target configurations
  243. my $pattern = catfile(dirname($0), "Configurations", "*.conf");
  244. foreach (sort glob($pattern)) {
  245. &read_config($_);
  246. }
  247. if (defined $ENV{$local_config_envname}) {
  248. if ($^O eq 'VMS') {
  249. # VMS environment variables are logical names,
  250. # which can be used as is
  251. $pattern = $local_config_envname . ':' . '*.conf';
  252. } else {
  253. $pattern = catfile($ENV{$local_config_envname}, '*.conf');
  254. }
  255. foreach (sort glob($pattern)) {
  256. &read_config($_);
  257. }
  258. }
  259. print "Configuring OpenSSL version $config{version} ($config{version_num})\n";
  260. $config{prefix}="";
  261. $config{openssldir}="";
  262. $config{processor}="";
  263. $config{libdir}="";
  264. $config{cross_compile_prefix}="";
  265. $config{fipslibdir}="/usr/local/ssl/fips-2.0/lib/";
  266. my $nofipscanistercheck=0;
  267. $config{baseaddr}="0xFB00000";
  268. my $auto_threads=1; # enable threads automatically? true by default
  269. my $default_ranlib;
  270. $config{fips}=0;
  271. # Top level directories to build
  272. $config{dirs} = [ "crypto", "ssl", "engines", "apps", "test", "util", "tools", "fuzz" ];
  273. # crypto/ subdirectories to build
  274. $config{sdirs} = [
  275. "objects",
  276. "md2", "md4", "md5", "sha", "mdc2", "hmac", "ripemd", "whrlpool", "poly1305", "blake2",
  277. "des", "aes", "rc2", "rc4", "rc5", "idea", "bf", "cast", "camellia", "seed", "chacha", "modes",
  278. "bn", "ec", "rsa", "dsa", "dh", "dso", "engine",
  279. "buffer", "bio", "stack", "lhash", "rand", "err",
  280. "evp", "asn1", "pem", "x509", "x509v3", "conf", "txt_db", "pkcs7", "pkcs12", "comp", "ocsp", "ui",
  281. "cms", "ts", "srp", "cmac", "ct", "async", "kdf"
  282. ];
  283. # Known TLS and DTLS protocols
  284. my @tls = qw(ssl3 tls1 tls1_1 tls1_2);
  285. my @dtls = qw(dtls1 dtls1_2);
  286. # Explicitly known options that are possible to disable. They can
  287. # be regexps, and will be used like this: /^no-${option}$/
  288. # For developers: keep it sorted alphabetically
  289. my @disablables = (
  290. "afalgeng",
  291. "asan",
  292. "asm",
  293. "async",
  294. "autoalginit",
  295. "autoerrinit",
  296. "bf",
  297. "blake2",
  298. "camellia",
  299. "capieng",
  300. "cast",
  301. "chacha",
  302. "cmac",
  303. "cms",
  304. "comp",
  305. "crypto-mdebug",
  306. "crypto-mdebug-backtrace",
  307. "ct",
  308. "deprecated",
  309. "des",
  310. "dgram",
  311. "dh",
  312. "dsa",
  313. "dso",
  314. "dtls",
  315. "dynamic-engine",
  316. "ec",
  317. "ec2m",
  318. "ecdh",
  319. "ecdsa",
  320. "ec_nistp_64_gcc_128",
  321. "egd",
  322. "engine",
  323. "err",
  324. "filenames",
  325. "fuzz-libfuzzer",
  326. "fuzz-afl",
  327. "gost",
  328. "heartbeats",
  329. "hw(-.+)?",
  330. "idea",
  331. "makedepend",
  332. "md2",
  333. "md4",
  334. "mdc2",
  335. "msan",
  336. "multiblock",
  337. "nextprotoneg",
  338. "ocb",
  339. "ocsp",
  340. "pic",
  341. "poly1305",
  342. "posix-io",
  343. "psk",
  344. "rc2",
  345. "rc4",
  346. "rc5",
  347. "rdrand",
  348. "rfc3779",
  349. "rmd160",
  350. "scrypt",
  351. "sctp",
  352. "seed",
  353. "shared",
  354. "sock",
  355. "srp",
  356. "srtp",
  357. "sse2",
  358. "ssl",
  359. "ssl-trace",
  360. "static-engine",
  361. "stdio",
  362. "threads",
  363. "tls",
  364. "ts",
  365. "ubsan",
  366. "ui",
  367. "unit-test",
  368. "whirlpool",
  369. "weak-ssl-ciphers",
  370. "zlib",
  371. "zlib-dynamic",
  372. );
  373. foreach my $proto ((@tls, @dtls))
  374. {
  375. push(@disablables, $proto);
  376. push(@disablables, "$proto-method");
  377. }
  378. my %deprecated_disablables = (
  379. "ssl2" => undef,
  380. "buf-freelists" => undef,
  381. "ripemd" => "rmd160"
  382. );
  383. # All of the following is disabled by default (RC5 was enabled before 0.9.8):
  384. our %disabled = ( # "what" => "comment"
  385. "asan" => "default",
  386. "crypto-mdebug" => "default",
  387. "crypto-mdebug-backtrace" => "default",
  388. "ec_nistp_64_gcc_128" => "default",
  389. "egd" => "default",
  390. "fuzz-libfuzzer" => "default",
  391. "fuzz-afl" => "default",
  392. "heartbeats" => "default",
  393. "md2" => "default",
  394. "msan" => "default",
  395. "rc5" => "default",
  396. "sctp" => "default",
  397. "ssl-trace" => "default",
  398. "ssl3" => "default",
  399. "ssl3-method" => "default",
  400. "ubsan" => "default",
  401. "unit-test" => "default",
  402. "weak-ssl-ciphers" => "default",
  403. "zlib" => "default",
  404. "zlib-dynamic" => "default",
  405. );
  406. # Note: => pair form used for aesthetics, not to truly make a hash table
  407. my @disable_cascades = (
  408. # "what" => [ "cascade", ... ]
  409. sub { $config{processor} eq "386" }
  410. => [ "sse2" ],
  411. "ssl" => [ "ssl3" ],
  412. "ssl3-method" => [ "ssl3" ],
  413. "zlib" => [ "zlib-dynamic" ],
  414. "des" => [ "mdc2" ],
  415. "ec" => [ "ecdsa", "ecdh" ],
  416. "dgram" => [ "dtls", "sctp" ],
  417. "sock" => [ "dgram" ],
  418. "dtls" => [ @dtls ],
  419. sub { 0 == scalar grep { !$disabled{$_} } @dtls }
  420. => [ "dtls" ],
  421. "tls" => [ @tls ],
  422. sub { 0 == scalar grep { !$disabled{$_} } @tls }
  423. => [ "tls" ],
  424. "crypto-mdebug" => [ "crypto-mdebug-backtrace" ],
  425. # Without DSO, we can't load dynamic engines, so don't build them dynamic
  426. "dso" => [ "dynamic-engine" ],
  427. # Without position independent code, there can be no shared libraries or DSOs
  428. "pic" => [ "shared" ],
  429. "shared" => [ "dynamic-engine" ],
  430. "engine" => [ "afalgeng" ],
  431. # no-autoalginit is only useful when building non-shared
  432. "autoalginit" => [ "shared", "apps" ],
  433. "stdio" => [ "apps", "capieng", "egd" ],
  434. "apps" => [ "tests" ],
  435. "comp" => [ "zlib" ],
  436. sub { !$disabled{"unit-test"} } => [ "heartbeats" ],
  437. sub { !$disabled{"msan"} } => [ "asm" ],
  438. );
  439. # Avoid protocol support holes. Also disable all versions below N, if version
  440. # N is disabled while N+1 is enabled.
  441. #
  442. my @list = (reverse @tls);
  443. while ((my $first, my $second) = (shift @list, shift @list)) {
  444. last unless @list;
  445. push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
  446. => [ @list ] );
  447. unshift @list, $second;
  448. }
  449. my @list = (reverse @dtls);
  450. while ((my $first, my $second) = (shift @list, shift @list)) {
  451. last unless @list;
  452. push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
  453. => [ @list ] );
  454. unshift @list, $second;
  455. }
  456. # Explicit "no-..." options will be collected in %disabled along with the defaults.
  457. # To remove something from %disabled, use "enable-foo".
  458. # For symmetry, "disable-foo" is a synonym for "no-foo".
  459. &usage if ($#ARGV < 0);
  460. my $user_cflags="";
  461. my @user_defines=();
  462. $config{openssl_api_defines}=[];
  463. $config{openssl_algorithm_defines}=[];
  464. $config{openssl_thread_defines}=[];
  465. $config{openssl_sys_defines}=[];
  466. $config{openssl_other_defines}=[];
  467. my $libs="";
  468. my $target="";
  469. $config{options}="";
  470. $config{build_type} = "release";
  471. my %unsupported_options = ();
  472. my %deprecated_options = ();
  473. while (@argvcopy)
  474. {
  475. $_ = shift @argvcopy;
  476. # VMS is a case insensitive environment, and depending on settings
  477. # out of our control, we may receive options uppercased. Let's
  478. # downcase at least the part before any equal sign.
  479. if ($^O eq "VMS")
  480. {
  481. s/^([^=]*)/lc($1)/e;
  482. }
  483. s /^-no-/no-/; # some people just can't read the instructions
  484. # rewrite some options in "enable-..." form
  485. s /^-?-?shared$/enable-shared/;
  486. s /^sctp$/enable-sctp/;
  487. s /^threads$/enable-threads/;
  488. s /^zlib$/enable-zlib/;
  489. s /^zlib-dynamic$/enable-zlib-dynamic/;
  490. if (/^(no|disable|enable)-(.+)$/)
  491. {
  492. my $word = $2;
  493. if (!exists $deprecated_disablables{$word}
  494. && !grep { $word =~ /^${_}$/ } @disablables)
  495. {
  496. $unsupported_options{$_} = 1;
  497. next;
  498. }
  499. }
  500. if (/^no-(.+)$/ || /^disable-(.+)$/)
  501. {
  502. foreach my $proto ((@tls, @dtls))
  503. {
  504. if ($1 eq "$proto-method")
  505. {
  506. $disabled{"$proto"} = "option($proto-method)";
  507. last;
  508. }
  509. }
  510. if ($1 eq "dtls")
  511. {
  512. foreach my $proto (@dtls)
  513. {
  514. $disabled{$proto} = "option(dtls)";
  515. }
  516. $disabled{"dtls"} = "option(dtls)";
  517. }
  518. elsif ($1 eq "ssl")
  519. {
  520. # Last one of its kind
  521. $disabled{"ssl3"} = "option(ssl)";
  522. }
  523. elsif ($1 eq "tls")
  524. {
  525. # XXX: Tests will fail if all SSL/TLS
  526. # protocols are disabled.
  527. foreach my $proto (@tls)
  528. {
  529. $disabled{$proto} = "option(tls)";
  530. }
  531. }
  532. elsif ($1 eq "static-engine")
  533. {
  534. delete $disabled{"dynamic-engine"};
  535. }
  536. elsif ($1 eq "dynamic-engine")
  537. {
  538. $disabled{"dynamic-engine"} = "option";
  539. }
  540. elsif (exists $deprecated_disablables{$1})
  541. {
  542. $deprecated_options{$_} = 1;
  543. if (defined $deprecated_disablables{$1})
  544. {
  545. $disabled{$deprecated_disablables{$1}} = "option";
  546. }
  547. }
  548. else
  549. {
  550. $disabled{$1} = "option";
  551. }
  552. # No longer an automatic choice
  553. $auto_threads = 0 if ($1 eq "threads");
  554. }
  555. elsif (/^enable-(.+)$/)
  556. {
  557. if ($1 eq "static-engine")
  558. {
  559. $disabled{"dynamic-engine"} = "option";
  560. }
  561. elsif ($1 eq "dynamic-engine")
  562. {
  563. delete $disabled{"dynamic-engine"};
  564. }
  565. elsif ($1 eq "zlib-dynamic")
  566. {
  567. delete $disabled{"zlib"};
  568. }
  569. my $algo = $1;
  570. delete $disabled{$algo};
  571. # No longer an automatic choice
  572. $auto_threads = 0 if ($1 eq "threads");
  573. }
  574. elsif (/^--strict-warnings$/)
  575. {
  576. $strict_warnings = 1;
  577. }
  578. elsif (/^--debug$/)
  579. {
  580. $config{build_type} = "debug";
  581. }
  582. elsif (/^--release$/)
  583. {
  584. $config{build_type} = "release";
  585. }
  586. elsif (/^386$/)
  587. { $config{processor}=386; }
  588. elsif (/^fips$/)
  589. {
  590. $config{fips}=1;
  591. }
  592. elsif (/^rsaref$/)
  593. {
  594. # No RSAref support any more since it's not needed.
  595. # The check for the option is there so scripts aren't
  596. # broken
  597. }
  598. elsif (/^nofipscanistercheck$/)
  599. {
  600. $config{fips} = 1;
  601. $nofipscanistercheck = 1;
  602. }
  603. elsif (/^[-+]/)
  604. {
  605. if (/^--prefix=(.*)$/)
  606. {
  607. $config{prefix}=$1;
  608. die "Directory given with --prefix MUST be absolute\n"
  609. unless file_name_is_absolute($config{prefix});
  610. }
  611. elsif (/^--api=(.*)$/)
  612. {
  613. $config{api}=$1;
  614. }
  615. elsif (/^--libdir=(.*)$/)
  616. {
  617. $config{libdir}=$1;
  618. }
  619. elsif (/^--openssldir=(.*)$/)
  620. {
  621. $config{openssldir}=$1;
  622. }
  623. elsif (/^--with-zlib-lib=(.*)$/)
  624. {
  625. $withargs{zlib_lib}=$1;
  626. }
  627. elsif (/^--with-zlib-include=(.*)$/)
  628. {
  629. $withargs{zlib_include}=$1;
  630. }
  631. elsif (/^--with-fuzzer-lib=(.*)$/)
  632. {
  633. $withargs{fuzzer_lib}=$1;
  634. }
  635. elsif (/^--with-fuzzer-include=(.*)$/)
  636. {
  637. $withargs{fuzzer_include}=$1;
  638. }
  639. elsif (/^--with-fipslibdir=(.*)$/)
  640. {
  641. $config{fipslibdir}="$1/";
  642. }
  643. elsif (/^--with-baseaddr=(.*)$/)
  644. {
  645. $config{baseaddr}="$1";
  646. }
  647. elsif (/^--cross-compile-prefix=(.*)$/)
  648. {
  649. $config{cross_compile_prefix}=$1;
  650. }
  651. elsif (/^--config=(.*)$/)
  652. {
  653. read_config $1;
  654. }
  655. elsif (/^-[lL](.*)$/ or /^-Wl,/)
  656. {
  657. $libs.=$_." ";
  658. }
  659. elsif (/^-rpath$/ or /^-R$/)
  660. # -rpath is the OSF1 rpath flag
  661. # -R is the old Solaris rpath flag
  662. {
  663. my $rpath = shift(@argvcopy) || "";
  664. $rpath .= " " if $rpath ne "";
  665. $libs.=$_." ".$rpath;
  666. }
  667. elsif (/^-static$/)
  668. {
  669. $libs.=$_." ";
  670. $disabled{"dso"} = "forced";
  671. $disabled{"pic"} = "forced";
  672. $disabled{"shared"} = "forced";
  673. $disabled{"threads"} = "forced";
  674. }
  675. elsif (/^-D(.*)$/)
  676. {
  677. push @user_defines, $1;
  678. }
  679. else # common if (/^[-+]/), just pass down...
  680. {
  681. $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
  682. $user_cflags.=" ".$_;
  683. }
  684. }
  685. else
  686. {
  687. die "target already defined - $target (offending arg: $_)\n" if ($target ne "");
  688. $target=$_;
  689. }
  690. unless ($_ eq $target || /^no-/ || /^disable-/)
  691. {
  692. # "no-..." follows later after implied disactivations
  693. # have been derived. (Don't take this too seriously,
  694. # we really only write OPTIONS to the Makefile out of
  695. # nostalgia.)
  696. if ($config{options} eq "")
  697. { $config{options} = $_; }
  698. else
  699. { $config{options} .= " ".$_; }
  700. }
  701. }
  702. if (defined($config{api}) && !exists $apitable->{$config{api}}) {
  703. die "***** Unsupported api compatibility level: $config{api}\n",
  704. }
  705. if (keys %deprecated_options)
  706. {
  707. warn "***** Deprecated options: ",
  708. join(", ", keys %deprecated_options), "\n";
  709. }
  710. if (keys %unsupported_options)
  711. {
  712. die "***** Unsupported options: ",
  713. join(", ", keys %unsupported_options), "\n";
  714. }
  715. if ($libs =~ /(^|\s)-Wl,-rpath,/
  716. && !$disabled{shared}
  717. && !($disabled{asan} && $disabled{msan} && $disabled{ubsan})) {
  718. die "***** Cannot simultaneously use -rpath, shared libraries, and\n",
  719. "***** any of asan, msan or ubsan\n";
  720. }
  721. if ($config{fips})
  722. {
  723. delete $disabled{"shared"} if ($disabled{"shared"} =~ /^default/);
  724. }
  725. else
  726. {
  727. @{$config{dirs}} = grep !/^fips$/, @{$config{dirs}};
  728. }
  729. my @tocheckfor = (keys %disabled);
  730. while (@tocheckfor) {
  731. my %new_tocheckfor = ();
  732. my @cascade_copy = (@disable_cascades);
  733. while (@cascade_copy) {
  734. my ($test, $descendents) = (shift @cascade_copy, shift @cascade_copy);
  735. if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) {
  736. foreach(grep { !defined($disabled{$_}) } @$descendents) {
  737. $new_tocheckfor{$_} = 1; $disabled{$_} = "forced";
  738. }
  739. }
  740. }
  741. @tocheckfor = (keys %new_tocheckfor);
  742. }
  743. our $die = sub { die @_; };
  744. if ($target eq "TABLE") {
  745. local $die = sub { warn @_; };
  746. foreach (sort keys %table) {
  747. print_table_entry($_, "TABLE");
  748. }
  749. exit 0;
  750. }
  751. if ($target eq "LIST") {
  752. foreach (sort keys %table) {
  753. print $_,"\n" unless $table{$_}->{template};
  754. }
  755. exit 0;
  756. }
  757. if ($target eq "HASH") {
  758. local $die = sub { warn @_; };
  759. print "%table = (\n";
  760. foreach (sort keys %table) {
  761. print_table_entry($_, "HASH");
  762. }
  763. exit 0;
  764. }
  765. # Backward compatibility?
  766. if ($target =~ m/^CygWin32(-.*)$/) {
  767. $target = "Cygwin".$1;
  768. }
  769. foreach (sort (keys %disabled))
  770. {
  771. $config{options} .= " no-$_";
  772. printf " no-%-12s %-10s", $_, "[$disabled{$_}]";
  773. if (/^dso$/)
  774. { }
  775. elsif (/^threads$/)
  776. { }
  777. elsif (/^shared$/)
  778. { }
  779. elsif (/^pic$/)
  780. { }
  781. elsif (/^zlib$/)
  782. { }
  783. elsif (/^dynamic-engine$/)
  784. { }
  785. elsif (/^makedepend$/)
  786. { }
  787. elsif (/^zlib-dynamic$/)
  788. { }
  789. elsif (/^sse2$/)
  790. { }
  791. elsif (/^engine$/)
  792. {
  793. @{$config{dirs}} = grep !/^engines$/, @{$config{dirs}};
  794. @{$config{sdirs}} = grep !/^engine$/, @{$config{sdirs}};
  795. push @{$config{openssl_other_defines}}, "OPENSSL_NO_ENGINE";
  796. print " OPENSSL_NO_ENGINE (skip engines)";
  797. }
  798. else
  799. {
  800. my ($WHAT, $what);
  801. ($WHAT = $what = $_) =~ tr/[\-a-z]/[_A-Z]/;
  802. # Fix up C macro end names
  803. $WHAT = "RMD160" if $what eq "ripemd";
  804. # fix-up crypto/directory name(s)
  805. $what = "ripemd" if $what eq "rmd160";
  806. $what = "whrlpool" if $what eq "whirlpool";
  807. if ($what ne "async" && $what ne "err"
  808. && grep { $_ eq $what } @{$config{sdirs}})
  809. {
  810. push @{$config{openssl_algorithm_defines}}, "OPENSSL_NO_$WHAT";
  811. @{$config{sdirs}} = grep { $_ ne $what} @{$config{sdirs}};
  812. print " OPENSSL_NO_$WHAT (skip dir)";
  813. }
  814. else
  815. {
  816. push @{$config{openssl_other_defines}}, "OPENSSL_NO_$WHAT";
  817. print " OPENSSL_NO_$WHAT";
  818. }
  819. }
  820. print "\n";
  821. }
  822. print "Configuring for $target\n";
  823. # Support for legacy targets having a name starting with 'debug-'
  824. my ($d, $t) = $target =~ m/^(debug-)?(.*)$/;
  825. if ($d) {
  826. $config{build_type} = "debug";
  827. # If we do not find debug-foo in the table, the target is set to foo.
  828. if (!$table{$target}) {
  829. $target = $t;
  830. }
  831. }
  832. &usage if !$table{$target} || $table{$target}->{template};
  833. $config{target} = $target;
  834. my %target = resolve_config($target);
  835. my %conf_files = map { $_ => 1 } (@{$target{_conf_fname_int}});
  836. $config{conf_files} = [ sort keys %conf_files ];
  837. %target = ( %{$table{DEFAULTS}}, %target );
  838. $target{exe_extension}="";
  839. $target{exe_extension}=".exe" if ($config{target} eq "DJGPP"
  840. || $config{target} =~ /^(?:Cygwin|mingw)/);
  841. $target{exe_extension}=".pm" if ($config{target} =~ /vos/);
  842. ($target{shared_extension_simple}=$target{shared_extension})
  843. =~ s|\.\$\(SHLIB_MAJOR\)\.\$\(SHLIB_MINOR\)||;
  844. $target{dso_extension}=$target{shared_extension_simple};
  845. ($target{shared_import_extension}=$target{shared_extension_simple}.".a")
  846. if ($config{target} =~ /^(?:Cygwin|mingw)/);
  847. $config{cross_compile_prefix} = $ENV{'CROSS_COMPILE'}
  848. if $config{cross_compile_prefix} eq "";
  849. # Allow overriding the names of some tools. USE WITH CARE
  850. # Note: only Unix cares about HASHBANGPERL... that explains
  851. # the default string.
  852. $config{perl} = $ENV{'PERL'} || ($^O ne "VMS" ? $^X : "perl");
  853. $config{hashbangperl} =
  854. $ENV{'HASHBANGPERL'} || $ENV{'PERL'} || "/usr/bin/env perl";
  855. $target{cc} = $ENV{'CC'} || $target{cc} || "cc";
  856. $target{ranlib} = $ENV{'RANLIB'} || $target{ranlib} ||
  857. (which("$config{cross_compile_prefix}ranlib") ?
  858. "\$(CROSS_COMPILE)ranlib" : "true");
  859. $target{ar} = $ENV{'AR'} || $target{ar} || "ar";
  860. $target{nm} = $ENV{'NM'} || $target{nm} || "nm";
  861. $target{rc} =
  862. $ENV{'RC'} || $ENV{'WINDRES'} || $target{rc} || "windres";
  863. # Allow overriding the build file name
  864. $target{build_file} = $ENV{BUILDFILE} || $target{build_file} || "Makefile";
  865. # Cache information necessary for reconfiguration
  866. $config{cc} = $target{cc};
  867. $config{build_file} = $target{build_file};
  868. # For cflags, lflags, plib_lflags, ex_libs and defines, add the debug_
  869. # or release_ attributes.
  870. # Do it in such a way that no spurious space is appended (hence the grep).
  871. $config{defines} = [];
  872. $config{cflags} = "";
  873. $config{ex_libs} = "";
  874. $config{shared_ldflag} = "";
  875. # Make sure build_scheme is consistent.
  876. $target{build_scheme} = [ $target{build_scheme} ]
  877. if ref($target{build_scheme}) ne "ARRAY";
  878. my ($builder, $builder_platform, @builder_opts) =
  879. @{$target{build_scheme}};
  880. foreach my $checker (($builder_platform."-".$target{build_file}."-checker.pm",
  881. $builder_platform."-checker.pm")) {
  882. my $checker_path = catfile($srcdir, "Configurations", $checker);
  883. if (-f $checker_path) {
  884. my $fn = $ENV{CONFIGURE_CHECKER_WARN}
  885. ? sub { warn $@; } : sub { die $@; };
  886. if (! do $checker_path) {
  887. if ($@) {
  888. $fn->($@);
  889. } elsif ($!) {
  890. $fn->($!);
  891. } else {
  892. $fn->("The detected tools didn't match the platform\n");
  893. }
  894. }
  895. last;
  896. }
  897. }
  898. push @{$config{defines}}, "NDEBUG" if $config{build_type} eq "release";
  899. if ($target =~ /^mingw/ && `$target{cc} --target-help 2>&1` =~ m/-mno-cygwin/m)
  900. {
  901. $config{cflags} .= " -mno-cygwin";
  902. $config{shared_ldflag} .= " -mno-cygwin";
  903. }
  904. if ($target =~ /linux.*-mips/ && !$disabled{asm} && $user_cflags !~ /-m(ips|arch=)/) {
  905. # minimally required architecture flags for assembly modules
  906. $config{cflags}="-mips2 $config{cflags}" if ($target =~ /mips32/);
  907. $config{cflags}="-mips3 $config{cflags}" if ($target =~ /mips64/);
  908. }
  909. my $no_shared_warn=0;
  910. my $no_user_cflags=0;
  911. my $no_user_defines=0;
  912. # The DSO code currently always implements all functions so that no
  913. # applications will have to worry about that from a compilation point
  914. # of view. However, the "method"s may return zero unless that platform
  915. # has support compiled in for them. Currently each method is enabled
  916. # by a define "DSO_<name>" ... we translate the "dso_scheme" config
  917. # string entry into using the following logic;
  918. if (!$disabled{dso} && $target{dso_scheme} ne "")
  919. {
  920. $target{dso_scheme} =~ tr/[a-z]/[A-Z]/;
  921. if ($target{dso_scheme} eq "DLFCN")
  922. {
  923. unshift @{$config{defines}}, "DSO_DLFCN", "HAVE_DLFCN_H";
  924. }
  925. elsif ($target{dso_scheme} eq "DLFCN_NO_H")
  926. {
  927. unshift @{$config{defines}}, "DSO_DLFCN";
  928. }
  929. else
  930. {
  931. unshift @{$config{defines}}, "DSO_$target{dso_scheme}";
  932. }
  933. }
  934. $config{ex_libs}="$libs$config{ex_libs}" if ($libs ne "");
  935. if ($disabled{asm})
  936. {
  937. if ($config{fips})
  938. {
  939. @{$config{defines}} = grep !/^[BL]_ENDIAN$/, @{$config{defines}};
  940. @{$target{defines}} = grep !/^[BL]_ENDIAN$/, @{$target{defines}};
  941. }
  942. }
  943. # If threads aren't disabled, check how possible they are
  944. unless ($disabled{threads}) {
  945. if ($auto_threads) {
  946. # Enabled by default, disable it forcibly if unavailable
  947. if ($target{thread_scheme} eq "(unknown)") {
  948. $disabled{threads} = "unavailable";
  949. }
  950. } else {
  951. # The user chose to enable threads explicitly, let's see
  952. # if there's a chance that's possible
  953. if ($target{thread_scheme} eq "(unknown)") {
  954. # If the user asked for "threads" and we don't have internal
  955. # knowledge how to do it, [s]he is expected to provide any
  956. # system-dependent compiler options that are necessary. We
  957. # can't truly check that the given options are correct, but
  958. # we expect the user to know what [s]He is doing.
  959. if ($no_user_cflags && $no_user_defines) {
  960. die "You asked for multi-threading support, but didn't\n"
  961. ,"provide any system-specific compiler options\n";
  962. }
  963. }
  964. }
  965. }
  966. # If threads still aren't disabled, add a C macro to ensure the source
  967. # code knows about it. Any other flag is taken care of by the configs.
  968. unless($disabled{threads}) {
  969. foreach (("defines", "openssl_thread_defines")) {
  970. push @{$config{$_}}, "OPENSSL_THREADS";
  971. }
  972. }
  973. # With "deprecated" disable all deprecated features.
  974. if (defined($disabled{"deprecated"})) {
  975. $config{api} = $maxapi;
  976. }
  977. if ($target{shared_target} eq "")
  978. {
  979. $no_shared_warn = 1
  980. if ((!$disabled{shared} || !$disabled{"dynamic-engine"})
  981. && !$config{fips});
  982. $disabled{shared} = "no-shared-target";
  983. $disabled{pic} = $disabled{shared} = $disabled{"dynamic-engine"} =
  984. "no-shared-target";
  985. }
  986. if ($disabled{"dynamic-engine"}) {
  987. push @{$config{defines}}, "OPENSSL_NO_DYNAMIC_ENGINE";
  988. $config{dynamic_engines} = 0;
  989. } else {
  990. push @{$config{defines}}, "OPENSSL_NO_STATIC_ENGINE";
  991. $config{dynamic_engines} = 1;
  992. }
  993. unless ($disabled{"fuzz-libfuzzer"}) {
  994. $config{cflags} .= "-fsanitize-coverage=edge,indirect-calls ";
  995. }
  996. unless ($disabled{asan}) {
  997. $config{cflags} .= "-fsanitize=address ";
  998. }
  999. unless ($disabled{ubsan}) {
  1000. # -DPEDANTIC or -fnosanitize=alignment may also be required on some
  1001. # platforms.
  1002. $config{cflags} .= "-fsanitize=undefined -fno-sanitize-recover=all ";
  1003. }
  1004. unless ($disabled{msan}) {
  1005. $config{cflags} .= "-fsanitize=memory ";
  1006. }
  1007. unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
  1008. && $disabled{asan} && $disabled{ubsan} && $disabled{msan}) {
  1009. $config{cflags} .= "-fno-omit-frame-pointer -g ";
  1010. }
  1011. #
  1012. # Platform fix-ups
  1013. #
  1014. # This saves the build files from having to check
  1015. if ($disabled{pic})
  1016. {
  1017. $target{shared_cflag} = $target{shared_ldflag} =
  1018. $target{shared_rcflag} = "";
  1019. }
  1020. else
  1021. {
  1022. push @{$config{defines}}, "OPENSSL_PIC";
  1023. }
  1024. if ($target{sys_id} ne "")
  1025. {
  1026. push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}";
  1027. }
  1028. unless ($disabled{asm}) {
  1029. $target{cpuid_asm_src}=$table{DEFAULTS}->{cpuid_asm_src} if ($config{processor} eq "386");
  1030. $target{bn_asm_src} =~ s/\w+-gf2m.c// if (defined($disabled{ec2m}));
  1031. # bn-586 is the only one implementing bn_*_part_words
  1032. push @{$config{defines}}, "OPENSSL_BN_ASM_PART_WORDS" if ($target{bn_asm_src} =~ /bn-586/);
  1033. push @{$config{defines}}, "OPENSSL_IA32_SSE2" if (!$disabled{sse2} && $target{bn_asm_src} =~ /86/);
  1034. push @{$config{defines}}, "OPENSSL_BN_ASM_MONT" if ($target{bn_asm_src} =~ /-mont/);
  1035. push @{$config{defines}}, "OPENSSL_BN_ASM_MONT5" if ($target{bn_asm_src} =~ /-mont5/);
  1036. push @{$config{defines}}, "OPENSSL_BN_ASM_GF2m" if ($target{bn_asm_src} =~ /-gf2m/);
  1037. if ($config{fips}) {
  1038. push @{$config{openssl_other_defines}}, "OPENSSL_FIPS";
  1039. }
  1040. if ($target{sha1_asm_src}) {
  1041. push @{$config{defines}}, "SHA1_ASM" if ($target{sha1_asm_src} =~ /sx86/ || $target{sha1_asm_src} =~ /sha1/);
  1042. push @{$config{defines}}, "SHA256_ASM" if ($target{sha1_asm_src} =~ /sha256/);
  1043. push @{$config{defines}}, "SHA512_ASM" if ($target{sha1_asm_src} =~ /sha512/);
  1044. }
  1045. if ($target{rc4_asm_src} ne $table{DEFAULTS}->{rc4_asm_src}) {
  1046. push @{$config{defines}}, "RC4_ASM";
  1047. }
  1048. if ($target{md5_asm_src}) {
  1049. push @{$config{defines}}, "MD5_ASM";
  1050. }
  1051. $target{cast_asm_src}=$table{DEFAULTS}->{cast_asm_src} unless $disabled{pic}; # CAST assembler is not PIC
  1052. if ($target{rmd160_asm_src}) {
  1053. push @{$config{defines}}, "RMD160_ASM";
  1054. }
  1055. if ($target{aes_asm_src}) {
  1056. push @{$config{defines}}, "AES_ASM" if ($target{aes_asm_src} =~ m/\baes-/);;
  1057. # aes-ctr.fake is not a real file, only indication that assembler
  1058. # module implements AES_ctr32_encrypt...
  1059. push @{$config{defines}}, "AES_CTR_ASM" if ($target{aes_asm_src} =~ s/\s*aes-ctr\.fake//);
  1060. # aes-xts.fake indicates presence of AES_xts_[en|de]crypt...
  1061. push @{$config{defines}}, "AES_XTS_ASM" if ($target{aes_asm_src} =~ s/\s*aes-xts\.fake//);
  1062. $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($disabled{sse2});
  1063. push @{$config{defines}}, "VPAES_ASM" if ($target{aes_asm_src} =~ m/vpaes/);
  1064. push @{$config{defines}}, "BSAES_ASM" if ($target{aes_asm_src} =~ m/bsaes/);
  1065. }
  1066. if ($target{wp_asm_src} =~ /mmx/) {
  1067. if ($config{processor} eq "386") {
  1068. $target{wp_asm_src}=$table{DEFAULTS}->{wp_asm_src};
  1069. } elsif (!$disabled{"whirlpool"}) {
  1070. push @{$config{defines}}, "WHIRLPOOL_ASM";
  1071. }
  1072. }
  1073. if ($target{modes_asm_src} =~ /ghash-/) {
  1074. push @{$config{defines}}, "GHASH_ASM";
  1075. }
  1076. if ($target{ec_asm_src} =~ /ecp_nistz256/) {
  1077. push @{$config{defines}}, "ECP_NISTZ256_ASM";
  1078. }
  1079. if ($target{padlock_asm_src} ne $table{DEFAULTS}->{padlock_asm_src}) {
  1080. push @{$config{defines}}, "PADLOCK_ASM";
  1081. }
  1082. if ($target{poly1305_asm_src} ne "") {
  1083. push @{$config{defines}}, "POLY1305_ASM";
  1084. }
  1085. }
  1086. my %predefined;
  1087. if ($^O ne "VMS") {
  1088. my $cc = "$config{cross_compile_prefix}$target{cc}";
  1089. # collect compiler pre-defines from gcc or gcc-alike...
  1090. open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |");
  1091. while (<PIPE>) {
  1092. m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last;
  1093. $predefined{$1} = $2 // "";
  1094. }
  1095. close(PIPE);
  1096. if (!$disabled{makedepend}) {
  1097. # We know that GNU C version 3 and up as well as all clang
  1098. # versions support dependency generation, but Xcode did not
  1099. # handle $cc -M before clang support (but claims __GNUC__ = 3)
  1100. if (($predefined{__GNUC__} // -1) >= 3
  1101. && !($predefined{__APPLE_CC__} && !$predefined{__clang__})) {
  1102. $config{makedepprog} = $cc;
  1103. } else {
  1104. $config{makedepprog} = which('makedepend');
  1105. $disabled{makedepend} = "unavailable" unless $config{makedepprog};
  1106. }
  1107. }
  1108. }
  1109. # Deal with bn_ops ###################################################
  1110. $config{bn_ll} =0;
  1111. $config{export_var_as_fn} =0;
  1112. my $def_int="unsigned int";
  1113. $config{rc4_int} =$def_int;
  1114. ($config{b64l},$config{b64},$config{b32})=(0,0,1);
  1115. my $count = 0;
  1116. foreach (sort split(/\s+/,$target{bn_ops})) {
  1117. $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/;
  1118. $config{export_var_as_fn}=1 if $_ eq 'EXPORT_VAR_AS_FN';
  1119. $config{bn_ll}=1 if $_ eq 'BN_LLONG';
  1120. $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR';
  1121. ($config{b64l},$config{b64},$config{b32})
  1122. =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT';
  1123. ($config{b64l},$config{b64},$config{b32})
  1124. =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG';
  1125. ($config{b64l},$config{b64},$config{b32})
  1126. =(0,0,1) if $_ eq 'THIRTY_TWO_BIT';
  1127. }
  1128. die "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n"
  1129. if $count > 1;
  1130. # Hack cflags for better warnings (dev option) #######################
  1131. # "Stringify" the C flags string. This permits it to be made part of a string
  1132. # and works as well on command lines.
  1133. $config{cflags} =~ s/([\\\"])/\\$1/g;
  1134. if (defined($config{api})) {
  1135. $config{openssl_api_defines} = [ "OPENSSL_MIN_API=".$apitable->{$config{api}} ];
  1136. my $apiflag = sprintf("OPENSSL_API_COMPAT=%s", $apitable->{$config{api}});
  1137. push @{$config{defines}}, $apiflag;
  1138. }
  1139. if ($strict_warnings)
  1140. {
  1141. my $wopt;
  1142. die "ERROR --strict-warnings requires gcc or gcc-alike"
  1143. unless defined($predefined{__GNUC__});
  1144. foreach $wopt (split /\s+/, $gcc_devteam_warn)
  1145. {
  1146. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(?:^|\s)$wopt(?:\s|$)/)
  1147. }
  1148. if (defined($predefined{__clang__}))
  1149. {
  1150. foreach $wopt (split /\s+/, $clang_devteam_warn)
  1151. {
  1152. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(?:^|\s)$wopt(?:\s|$)/)
  1153. }
  1154. }
  1155. }
  1156. unless ($disabled{"crypto-mdebug-backtrace"})
  1157. {
  1158. foreach my $wopt (split /\s+/, $memleak_devteam_backtrace)
  1159. {
  1160. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(?:^|\s)$wopt(?:\s|$)/)
  1161. }
  1162. if ($target =~ /^BSD-/)
  1163. {
  1164. $config{ex_libs} .= " -lexecinfo";
  1165. }
  1166. }
  1167. if ($user_cflags ne "") { $config{cflags}="$config{cflags}$user_cflags"; }
  1168. else { $no_user_cflags=1; }
  1169. if (@user_defines) { $config{defines}=[ @{$config{defines}}, @user_defines ]; }
  1170. else { $no_user_defines=1; }
  1171. # ALL MODIFICATIONS TO %config and %target MUST BE DONE FROM HERE ON
  1172. unless ($disabled{afalgeng}) {
  1173. $config{afalgeng}="";
  1174. if ($target =~ m/^linux/) {
  1175. my $minver = 4*10000 + 1*100 + 0;
  1176. if ($config{cross_compile_prefix} eq "") {
  1177. my $verstr = `uname -r`;
  1178. my ($ma, $mi1, $mi2) = split("\\.", $verstr);
  1179. ($mi2) = $mi2 =~ /(\d+)/;
  1180. my $ver = $ma*10000 + $mi1*100 + $mi2;
  1181. if ($ver < $minver) {
  1182. $disabled{afalgeng} = "too-old-kernel";
  1183. } else {
  1184. push @{$config{engdirs}}, "afalg";
  1185. }
  1186. } else {
  1187. $disabled{afalgeng} = "cross-compiling";
  1188. }
  1189. } else {
  1190. $disabled{afalgeng} = "not-linux";
  1191. }
  1192. }
  1193. push @{$config{openssl_other_defines}}, "OPENSSL_NO_AFALGENG" if ($disabled{afalgeng});
  1194. # If we use the unified build, collect information from build.info files
  1195. my %unified_info = ();
  1196. my $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO});
  1197. if ($builder eq "unified") {
  1198. use with_fallback qw(Text::Template);
  1199. sub cleandir {
  1200. my $base = shift;
  1201. my $dir = shift;
  1202. my $relativeto = shift || ".";
  1203. $dir = catdir($base,$dir) unless isabsolute($dir);
  1204. # Make sure the directories we're building in exists
  1205. mkpath($dir);
  1206. my $res = abs2rel(absolutedir($dir), rel2abs($relativeto));
  1207. #print STDERR "DEBUG[cleandir]: $dir , $base => $res\n";
  1208. return $res;
  1209. }
  1210. sub cleanfile {
  1211. my $base = shift;
  1212. my $file = shift;
  1213. my $relativeto = shift || ".";
  1214. $file = catfile($base,$file) unless isabsolute($file);
  1215. my $d = dirname($file);
  1216. my $f = basename($file);
  1217. # Make sure the directories we're building in exists
  1218. mkpath($d);
  1219. my $res = abs2rel(catfile(absolutedir($d), $f), rel2abs($relativeto));
  1220. #print STDERR "DEBUG[cleanfile]: $d , $f => $res\n";
  1221. return $res;
  1222. }
  1223. # Store the name of the template file we will build the build file from
  1224. # in %config. This may be useful for the build file itself.
  1225. my @build_file_template_names =
  1226. ( $builder_platform."-".$target{build_file}.".tmpl",
  1227. $target{build_file}.".tmpl" );
  1228. my @build_file_templates = ();
  1229. # First, look in the user provided directory, if given
  1230. if (defined $ENV{$local_config_envname}) {
  1231. @build_file_templates =
  1232. map {
  1233. if ($^O eq 'VMS') {
  1234. # VMS environment variables are logical names,
  1235. # which can be used as is
  1236. $local_config_envname . ':' . $_;
  1237. } else {
  1238. catfile($ENV{$local_config_envname}, $_);
  1239. }
  1240. }
  1241. @build_file_template_names;
  1242. }
  1243. # Then, look in our standard directory
  1244. push @build_file_templates,
  1245. ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir) }
  1246. @build_file_template_names );
  1247. my $build_file_template;
  1248. for $_ (@build_file_templates) {
  1249. $build_file_template = $_;
  1250. last if -f $build_file_template;
  1251. $build_file_template = undef;
  1252. }
  1253. if (!defined $build_file_template) {
  1254. die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n";
  1255. }
  1256. $config{build_file_templates}
  1257. = [ $build_file_template,
  1258. cleanfile($srcdir, catfile("Configurations", "common.tmpl"),
  1259. $blddir) ];
  1260. my @build_infos = ( [ ".", "build.info" ] );
  1261. foreach (@{$config{dirs}}) {
  1262. push @build_infos, [ $_, "build.info" ]
  1263. if (-f catfile($srcdir, $_, "build.info"));
  1264. }
  1265. foreach (@{$config{sdirs}}) {
  1266. push @build_infos, [ catdir("crypto", $_), "build.info" ]
  1267. if (-f catfile($srcdir, "crypto", $_, "build.info"));
  1268. }
  1269. foreach (@{$config{engdirs}}) {
  1270. push @build_infos, [ catdir("engines", $_), "build.info" ]
  1271. if (-f catfile($srcdir, "engines", $_, "build.info"));
  1272. }
  1273. $config{build_infos} = [ ];
  1274. foreach (@build_infos) {
  1275. my $sourced = catdir($srcdir, $_->[0]);
  1276. my $buildd = catdir($blddir, $_->[0]);
  1277. mkpath($buildd);
  1278. my $f = $_->[1];
  1279. # The basic things we're trying to build
  1280. my @programs = ();
  1281. my @programs_install = ();
  1282. my @libraries = ();
  1283. my @libraries_install = ();
  1284. my @engines = ();
  1285. my @engines_install = ();
  1286. my @scripts = ();
  1287. my @scripts_install = ();
  1288. my @extra = ();
  1289. my @overrides = ();
  1290. my @intermediates = ();
  1291. my @rawlines = ();
  1292. my %ordinals = ();
  1293. my %sources = ();
  1294. my %shared_sources = ();
  1295. my %includes = ();
  1296. my %depends = ();
  1297. my %renames = ();
  1298. my %sharednames = ();
  1299. my %generate = ();
  1300. # We want to detect configdata.pm in the source tree, so we
  1301. # don't use it if the build tree is different.
  1302. my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir);
  1303. push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f);
  1304. my $template =
  1305. Text::Template->new(TYPE => 'FILE',
  1306. SOURCE => catfile($sourced, $f),
  1307. PREPEND => qq{use lib "$FindBin::Bin/util/perl";});
  1308. die "Something went wrong with $sourced/$f: $!\n" unless $template;
  1309. my @text =
  1310. split /^/m,
  1311. $template->fill_in(HASH => { config => \%config,
  1312. target => \%target,
  1313. disabled => \%disabled,
  1314. withargs => \%withargs,
  1315. builddir => abs2rel($buildd, $blddir),
  1316. sourcedir => abs2rel($sourced, $blddir),
  1317. buildtop => abs2rel($blddir, $blddir),
  1318. sourcetop => abs2rel($srcdir, $blddir) },
  1319. DELIMITERS => [ "{-", "-}" ]);
  1320. # The top item of this stack has the following values
  1321. # -2 positive already run and we found ELSE (following ELSIF should fail)
  1322. # -1 positive already run (skip until ENDIF)
  1323. # 0 negatives so far (if we're at a condition, check it)
  1324. # 1 last was positive (don't skip lines until next ELSE, ELSIF or ENDIF)
  1325. # 2 positive ELSE (following ELSIF should fail)
  1326. my @skip = ();
  1327. collect_information(
  1328. collect_from_array([ @text ],
  1329. qr/\\$/ => sub { my $l1 = shift; my $l2 = shift;
  1330. $l1 =~ s/\\$//; $l1.$l2 }),
  1331. # Info we're looking for
  1332. qr/^\s*IF\[((?:\\.|[^\\\]])*)\]\s*$/
  1333. => sub {
  1334. if (! @skip || $skip[$#skip] > 0) {
  1335. push @skip, !! $1;
  1336. } else {
  1337. push @skip, -1;
  1338. }
  1339. },
  1340. qr/^\s*ELSIF\[((?:\\.|[^\\\]])*)\]\s*$/
  1341. => sub { die "ELSIF out of scope" if ! @skip;
  1342. die "ELSIF following ELSE" if abs($skip[$#skip]) == 2;
  1343. $skip[$#skip] = -1 if $skip[$#skip] != 0;
  1344. $skip[$#skip] = !! $1
  1345. if $skip[$#skip] == 0; },
  1346. qr/^\s*ELSE\s*$/
  1347. => sub { die "ELSE out of scope" if ! @skip;
  1348. $skip[$#skip] = -2 if $skip[$#skip] != 0;
  1349. $skip[$#skip] = 2 if $skip[$#skip] == 0; },
  1350. qr/^\s*ENDIF\s*$/
  1351. => sub { die "ENDIF out of scope" if ! @skip;
  1352. pop @skip; },
  1353. qr/^\s*PROGRAMS(_NO_INST)?\s*=\s*(.*)\s*$/
  1354. => sub {
  1355. if (!@skip || $skip[$#skip] > 0) {
  1356. my $install = $1;
  1357. my @x = tokenize($2);
  1358. push @programs, @x;
  1359. push @programs_install, @x unless $install;
  1360. }
  1361. },
  1362. qr/^\s*LIBS(_NO_INST)?\s*=\s*(.*)\s*$/
  1363. => sub {
  1364. if (!@skip || $skip[$#skip] > 0) {
  1365. my $install = $1;
  1366. my @x = tokenize($2);
  1367. push @libraries, @x;
  1368. push @libraries_install, @x unless $install;
  1369. }
  1370. },
  1371. qr/^\s*ENGINES(_NO_INST)?\s*=\s*(.*)\s*$/
  1372. => sub {
  1373. if (!@skip || $skip[$#skip] > 0) {
  1374. my $install = $1;
  1375. my @x = tokenize($2);
  1376. push @engines, @x;
  1377. push @engines_install, @x unless $install;
  1378. }
  1379. },
  1380. qr/^\s*SCRIPTS(_NO_INST)?\s*=\s*(.*)\s*$/
  1381. => sub {
  1382. if (!@skip || $skip[$#skip] > 0) {
  1383. my $install = $1;
  1384. my @x = tokenize($2);
  1385. push @scripts, @x;
  1386. push @scripts_install, @x unless $install;
  1387. }
  1388. },
  1389. qr/^\s*EXTRA\s*=\s*(.*)\s*$/
  1390. => sub { push @extra, tokenize($1)
  1391. if !@skip || $skip[$#skip] > 0 },
  1392. qr/^\s*OVERRIDES\s*=\s*(.*)\s*$/
  1393. => sub { push @overrides, tokenize($1)
  1394. if !@skip || $skip[$#skip] > 0 },
  1395. qr/^\s*ORDINALS\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/,
  1396. => sub { push @{$ordinals{$1}}, tokenize($2)
  1397. if !@skip || $skip[$#skip] > 0 },
  1398. qr/^\s*SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1399. => sub { push @{$sources{$1}}, tokenize($2)
  1400. if !@skip || $skip[$#skip] > 0 },
  1401. qr/^\s*SHARED_SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1402. => sub { push @{$shared_sources{$1}}, tokenize($2)
  1403. if !@skip || $skip[$#skip] > 0 },
  1404. qr/^\s*INCLUDE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1405. => sub { push @{$includes{$1}}, tokenize($2)
  1406. if !@skip || $skip[$#skip] > 0 },
  1407. qr/^\s*DEPEND\[((?:\\.|[^\\\]])*)\]\s*=\s*(.*)\s*$/
  1408. => sub { push @{$depends{$1}}, tokenize($2)
  1409. if !@skip || $skip[$#skip] > 0 },
  1410. qr/^\s*GENERATE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1411. => sub { push @{$generate{$1}}, $2
  1412. if !@skip || $skip[$#skip] > 0 },
  1413. qr/^\s*RENAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1414. => sub { push @{$renames{$1}}, tokenize($2)
  1415. if !@skip || $skip[$#skip] > 0 },
  1416. qr/^\s*SHARED_NAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1417. => sub { push @{$sharednames{$1}}, tokenize($2)
  1418. if !@skip || $skip[$#skip] > 0 },
  1419. qr/^\s*BEGINRAW\[((?:\\.|[^\\\]])+)\]\s*$/
  1420. => sub {
  1421. my $lineiterator = shift;
  1422. my $target_kind = $1;
  1423. while (defined $lineiterator->()) {
  1424. s|\R$||;
  1425. if (/^\s*ENDRAW\[((?:\\.|[^\\\]])+)\]\s*$/) {
  1426. die "ENDRAW doesn't match BEGINRAW"
  1427. if $1 ne $target_kind;
  1428. last;
  1429. }
  1430. next if @skip && $skip[$#skip] <= 0;
  1431. push @rawlines, $_
  1432. if ($target_kind eq $target{build_file}
  1433. || $target_kind eq $target{build_file}."(".$builder_platform.")");
  1434. }
  1435. },
  1436. qr/^(?:#.*|\s*)$/ => sub { },
  1437. "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" },
  1438. "BEFORE" => sub {
  1439. if ($buildinfo_debug) {
  1440. print STDERR "DEBUG: Parsing ",join(" ", @_),"\n";
  1441. print STDERR "DEBUG: ... before parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1442. }
  1443. },
  1444. "AFTER" => sub {
  1445. if ($buildinfo_debug) {
  1446. print STDERR "DEBUG: .... after parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1447. }
  1448. },
  1449. );
  1450. die "runaway IF?" if (@skip);
  1451. foreach (keys %renames) {
  1452. die "$_ renamed to more than one thing: "
  1453. ,join(" ", @{$renames{$_}}),"\n"
  1454. if scalar @{$renames{$_}} > 1;
  1455. my $dest = cleanfile($buildd, $_, $blddir);
  1456. my $to = cleanfile($buildd, $renames{$_}->[0], $blddir);
  1457. die "$dest renamed to more than one thing: "
  1458. ,$unified_info{rename}->{$dest}, $to
  1459. unless !defined($unified_info{rename}->{$dest})
  1460. or $unified_info{rename}->{$dest} eq $to;
  1461. $unified_info{rename}->{$dest} = $to;
  1462. }
  1463. foreach (@programs) {
  1464. my $program = cleanfile($buildd, $_, $blddir);
  1465. if ($unified_info{rename}->{$program}) {
  1466. $program = $unified_info{rename}->{$program};
  1467. }
  1468. $unified_info{programs}->{$program} = 1;
  1469. }
  1470. foreach (@programs_install) {
  1471. my $program = cleanfile($buildd, $_, $blddir);
  1472. if ($unified_info{rename}->{$program}) {
  1473. $program = $unified_info{rename}->{$program};
  1474. }
  1475. $unified_info{install}->{programs}->{$program} = 1;
  1476. }
  1477. foreach (@libraries) {
  1478. my $library = cleanfile($buildd, $_, $blddir);
  1479. if ($unified_info{rename}->{$library}) {
  1480. $library = $unified_info{rename}->{$library};
  1481. }
  1482. $unified_info{libraries}->{$library} = 1;
  1483. }
  1484. foreach (@libraries_install) {
  1485. my $library = cleanfile($buildd, $_, $blddir);
  1486. if ($unified_info{rename}->{$library}) {
  1487. $library = $unified_info{rename}->{$library};
  1488. }
  1489. $unified_info{install}->{libraries}->{$library} = 1;
  1490. }
  1491. die <<"EOF" if scalar @engines and !$config{dynamic_engines};
  1492. ENGINES can only be used if configured with 'dynamic-engine'.
  1493. This is usually a fault in a build.info file.
  1494. EOF
  1495. foreach (@engines) {
  1496. my $library = cleanfile($buildd, $_, $blddir);
  1497. if ($unified_info{rename}->{$library}) {
  1498. $library = $unified_info{rename}->{$library};
  1499. }
  1500. $unified_info{engines}->{$library} = 1;
  1501. }
  1502. foreach (@engines_install) {
  1503. my $library = cleanfile($buildd, $_, $blddir);
  1504. if ($unified_info{rename}->{$library}) {
  1505. $library = $unified_info{rename}->{$library};
  1506. }
  1507. $unified_info{install}->{engines}->{$library} = 1;
  1508. }
  1509. foreach (@scripts) {
  1510. my $script = cleanfile($buildd, $_, $blddir);
  1511. if ($unified_info{rename}->{$script}) {
  1512. $script = $unified_info{rename}->{$script};
  1513. }
  1514. $unified_info{scripts}->{$script} = 1;
  1515. }
  1516. foreach (@scripts_install) {
  1517. my $script = cleanfile($buildd, $_, $blddir);
  1518. if ($unified_info{rename}->{$script}) {
  1519. $script = $unified_info{rename}->{$script};
  1520. }
  1521. $unified_info{install}->{scripts}->{$script} = 1;
  1522. }
  1523. foreach (@extra) {
  1524. my $extra = cleanfile($buildd, $_, $blddir);
  1525. $unified_info{extra}->{$extra} = 1;
  1526. }
  1527. foreach (@overrides) {
  1528. my $override = cleanfile($buildd, $_, $blddir);
  1529. $unified_info{overrides}->{$override} = 1;
  1530. }
  1531. push @{$unified_info{rawlines}}, @rawlines;
  1532. unless ($disabled{shared}) {
  1533. # Check sharednames.
  1534. foreach (keys %sharednames) {
  1535. my $dest = cleanfile($buildd, $_, $blddir);
  1536. if ($unified_info{rename}->{$dest}) {
  1537. $dest = $unified_info{rename}->{$dest};
  1538. }
  1539. die "shared_name for $dest with multiple values: "
  1540. ,join(" ", @{$sharednames{$_}}),"\n"
  1541. if scalar @{$sharednames{$_}} > 1;
  1542. my $to = cleanfile($buildd, $sharednames{$_}->[0], $blddir);
  1543. die "shared_name found for a library $dest that isn't defined\n"
  1544. unless $unified_info{libraries}->{$dest};
  1545. die "shared_name for $dest with multiple values: "
  1546. ,$unified_info{sharednames}->{$dest}, ", ", $to
  1547. unless !defined($unified_info{sharednames}->{$dest})
  1548. or $unified_info{sharednames}->{$dest} eq $to;
  1549. $unified_info{sharednames}->{$dest} = $to;
  1550. }
  1551. # Additionally, we set up sharednames for libraries that don't
  1552. # have any, as themselves.
  1553. foreach (keys %{$unified_info{libraries}}) {
  1554. if (!defined $unified_info{sharednames}->{$_}) {
  1555. $unified_info{sharednames}->{$_} = $_
  1556. }
  1557. }
  1558. }
  1559. foreach (keys %ordinals) {
  1560. my $dest = $_;
  1561. my $ddest = cleanfile($buildd, $_, $blddir);
  1562. if ($unified_info{rename}->{$ddest}) {
  1563. $ddest = $unified_info{rename}->{$ddest};
  1564. }
  1565. foreach (@{$ordinals{$dest}}) {
  1566. my %known_ordinals =
  1567. (
  1568. crypto =>
  1569. cleanfile($sourced, catfile("util", "libcrypto.num"), $blddir),
  1570. ssl =>
  1571. cleanfile($sourced, catfile("util", "libssl.num"), $blddir)
  1572. );
  1573. my $o = $known_ordinals{$_};
  1574. die "Ordinals for $ddest defined more than once\n"
  1575. if $unified_info{ordinals}->{$ddest};
  1576. $unified_info{ordinals}->{$ddest} = [ $_, $o ];
  1577. }
  1578. }
  1579. foreach (keys %sources) {
  1580. my $dest = $_;
  1581. my $ddest = cleanfile($buildd, $_, $blddir);
  1582. if ($unified_info{rename}->{$ddest}) {
  1583. $ddest = $unified_info{rename}->{$ddest};
  1584. }
  1585. foreach (@{$sources{$dest}}) {
  1586. my $s = cleanfile($sourced, $_, $blddir);
  1587. # If it isn't in the source tree, we assume it's generated
  1588. # in the build tree
  1589. if ($s eq $src_configdata || ! -f $s || $generate{$_}) {
  1590. $s = cleanfile($buildd, $_, $blddir);
  1591. }
  1592. # We recognise C and asm files
  1593. if ($s =~ /\.[csS]\b$/) {
  1594. (my $o = $_) =~ s/\.[csS]\b$/.o/;
  1595. $o = cleanfile($buildd, $o, $blddir);
  1596. $unified_info{sources}->{$ddest}->{$o} = 1;
  1597. $unified_info{sources}->{$o}->{$s} = 1;
  1598. } else {
  1599. $unified_info{sources}->{$ddest}->{$s} = 1;
  1600. }
  1601. }
  1602. }
  1603. foreach (keys %shared_sources) {
  1604. my $dest = $_;
  1605. my $ddest = cleanfile($buildd, $_, $blddir);
  1606. if ($unified_info{rename}->{$ddest}) {
  1607. $ddest = $unified_info{rename}->{$ddest};
  1608. }
  1609. foreach (@{$shared_sources{$dest}}) {
  1610. my $s = cleanfile($sourced, $_, $blddir);
  1611. # If it isn't in the source tree, we assume it's generated
  1612. # in the build tree
  1613. if ($s eq $src_configdata || ! -f $s || $generate{$_}) {
  1614. $s = cleanfile($buildd, $_, $blddir);
  1615. }
  1616. # We recognise C and asm files
  1617. if ($s =~ /\.[csS]\b$/) {
  1618. (my $o = $_) =~ s/\.[csS]\b$/.o/;
  1619. $o = cleanfile($buildd, $o, $blddir);
  1620. $unified_info{shared_sources}->{$ddest}->{$o} = 1;
  1621. $unified_info{sources}->{$o}->{$s} = 1;
  1622. } else {
  1623. die "unrecognised source file type for shared library: $s\n";
  1624. }
  1625. }
  1626. }
  1627. foreach (keys %generate) {
  1628. my $dest = $_;
  1629. my $ddest = cleanfile($buildd, $_, $blddir);
  1630. if ($unified_info{rename}->{$ddest}) {
  1631. $ddest = $unified_info{rename}->{$ddest};
  1632. }
  1633. die "more than one generator for $dest: "
  1634. ,join(" ", @{$generate{$_}}),"\n"
  1635. if scalar @{$generate{$_}} > 1;
  1636. my @generator = split /\s+/, $generate{$dest}->[0];
  1637. $generator[0] = cleanfile($sourced, $generator[0], $blddir),
  1638. $unified_info{generate}->{$ddest} = [ @generator ];
  1639. }
  1640. foreach (keys %depends) {
  1641. my $dest = $_;
  1642. my $ddest = $dest eq "" ? "" : cleanfile($sourced, $_, $blddir);
  1643. # If the destination doesn't exist in source, it can only be
  1644. # a generated file in the build tree.
  1645. if ($ddest ne "" && ($ddest eq $src_configdata || ! -f $ddest)) {
  1646. $ddest = cleanfile($buildd, $_, $blddir);
  1647. if ($unified_info{rename}->{$ddest}) {
  1648. $ddest = $unified_info{rename}->{$ddest};
  1649. }
  1650. }
  1651. foreach (@{$depends{$dest}}) {
  1652. my $d = cleanfile($sourced, $_, $blddir);
  1653. # If we know it's generated, or assume it is because we can't
  1654. # find it in the source tree, we set file we depend on to be
  1655. # in the build tree rather than the source tree, and assume
  1656. # and that there are lines to build it in a BEGINRAW..ENDRAW
  1657. # section or in the Makefile template.
  1658. if ($d eq $src_configdata
  1659. || ! -f $d
  1660. || (grep { $d eq $_ }
  1661. map { cleanfile($srcdir, $_, $blddir) }
  1662. grep { /\.h$/ } keys %{$unified_info{generate}})) {
  1663. $d = cleanfile($buildd, $_, $blddir);
  1664. }
  1665. # Take note if the file to depend on is being renamed
  1666. if ($unified_info{rename}->{$d}) {
  1667. $d = $unified_info{rename}->{$d};
  1668. }
  1669. $unified_info{depends}->{$ddest}->{$d} = 1;
  1670. }
  1671. }
  1672. foreach (keys %includes) {
  1673. my $dest = $_;
  1674. my $ddest = cleanfile($sourced, $_, $blddir);
  1675. # If the destination doesn't exist in source, it can only be
  1676. # a generated file in the build tree.
  1677. if ($ddest eq $src_configdata || ! -f $ddest) {
  1678. $ddest = cleanfile($buildd, $_, $blddir);
  1679. if ($unified_info{rename}->{$ddest}) {
  1680. $ddest = $unified_info{rename}->{$ddest};
  1681. }
  1682. }
  1683. foreach (@{$includes{$dest}}) {
  1684. my $is = cleandir($sourced, $_, $blddir);
  1685. my $ib = cleandir($buildd, $_, $blddir);
  1686. push @{$unified_info{includes}->{$ddest}->{source}}, $is
  1687. unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}};
  1688. push @{$unified_info{includes}->{$ddest}->{build}}, $ib
  1689. unless grep { $_ eq $ib } @{$unified_info{includes}->{$ddest}->{build}};
  1690. }
  1691. }
  1692. }
  1693. # Massage the result
  1694. # If we depend on a header file or a perl module, add an inclusion of
  1695. # its directory to allow smoothe inclusion
  1696. foreach my $dest (keys %{$unified_info{depends}}) {
  1697. next if $dest eq "";
  1698. foreach my $d (keys %{$unified_info{depends}->{$dest}}) {
  1699. next unless $d =~ /\.(h|pm)$/;
  1700. my $i = dirname($d);
  1701. my $spot =
  1702. $d eq "configdata.pm" || defined($unified_info{generate}->{$d})
  1703. ? 'build' : 'source';
  1704. push @{$unified_info{includes}->{$dest}->{$spot}}, $i
  1705. unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{$spot}};
  1706. }
  1707. }
  1708. # Trickle down includes placed on libraries, engines and programs to
  1709. # their sources (i.e. object files)
  1710. foreach my $dest (keys %{$unified_info{engines}},
  1711. keys %{$unified_info{libraries}},
  1712. keys %{$unified_info{programs}}) {
  1713. foreach my $k (("source", "build")) {
  1714. next unless defined($unified_info{includes}->{$dest}->{$k});
  1715. my @incs = reverse @{$unified_info{includes}->{$dest}->{$k}};
  1716. foreach my $obj (grep /\.o$/,
  1717. (keys %{$unified_info{sources}->{$dest} // {}},
  1718. keys %{$unified_info{shared_sources}->{$dest} // {}})) {
  1719. foreach my $inc (@incs) {
  1720. unshift @{$unified_info{includes}->{$obj}->{$k}}, $inc
  1721. unless grep { $_ eq $inc } @{$unified_info{includes}->{$obj}->{$k}};
  1722. }
  1723. }
  1724. }
  1725. delete $unified_info{includes}->{$dest};
  1726. }
  1727. ### Make unified_info a bit more efficient
  1728. # One level structures
  1729. foreach (("programs", "libraries", "engines", "scripts", "extra", "overrides")) {
  1730. $unified_info{$_} = [ sort keys %{$unified_info{$_}} ];
  1731. }
  1732. # Two level structures
  1733. foreach my $l1 (("install", "sources", "shared_sources", "ldadd", "depends")) {
  1734. foreach my $l2 (sort keys %{$unified_info{$l1}}) {
  1735. $unified_info{$l1}->{$l2} =
  1736. [ sort keys %{$unified_info{$l1}->{$l2}} ];
  1737. }
  1738. }
  1739. # Includes
  1740. foreach my $dest (sort keys %{$unified_info{includes}}) {
  1741. if (defined($unified_info{includes}->{$dest}->{build})) {
  1742. my @source_includes = ();
  1743. @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} )
  1744. if defined($unified_info{includes}->{$dest}->{source});
  1745. $unified_info{includes}->{$dest} =
  1746. [ @{$unified_info{includes}->{$dest}->{build}} ];
  1747. foreach my $inc (@source_includes) {
  1748. push @{$unified_info{includes}->{$dest}}, $inc
  1749. unless grep { $_ eq $inc } @{$unified_info{includes}->{$dest}};
  1750. }
  1751. } else {
  1752. $unified_info{includes}->{$dest} =
  1753. [ @{$unified_info{includes}->{$dest}->{source}} ];
  1754. }
  1755. }
  1756. }
  1757. # For the schemes that need it, we provide the old *_obj configs
  1758. # from the *_asm_obj ones
  1759. foreach (grep /_(asm|aux)_src$/, keys %target) {
  1760. my $src = $_;
  1761. (my $obj = $_) =~ s/_(asm|aux)_src$/_obj/;
  1762. ($target{$obj} = $target{$src}) =~ s/\.[csS]\b/.o/g;
  1763. }
  1764. # Write down our configuration where it fits #########################
  1765. open(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n";
  1766. print OUT <<"EOF";
  1767. package configdata;
  1768. use strict;
  1769. use warnings;
  1770. use Exporter;
  1771. #use vars qw(\@ISA \@EXPORT);
  1772. our \@ISA = qw(Exporter);
  1773. our \@EXPORT = qw(\%config \%target \%disabled \%withargs \%unified_info \@disablables);
  1774. EOF
  1775. print OUT "our %config = (\n";
  1776. foreach (sort keys %config) {
  1777. if (ref($config{$_}) eq "ARRAY") {
  1778. print OUT " ", $_, " => [ ", join(", ",
  1779. map { quotify("perl", $_) }
  1780. @{$config{$_}}), " ],\n";
  1781. } else {
  1782. print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n"
  1783. }
  1784. }
  1785. print OUT <<"EOF";
  1786. );
  1787. EOF
  1788. print OUT "our %target = (\n";
  1789. foreach (sort keys %target) {
  1790. if (ref($target{$_}) eq "ARRAY") {
  1791. print OUT " ", $_, " => [ ", join(", ",
  1792. map { quotify("perl", $_) }
  1793. @{$target{$_}}), " ],\n";
  1794. } else {
  1795. print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n"
  1796. }
  1797. }
  1798. print OUT <<"EOF";
  1799. );
  1800. EOF
  1801. print OUT "our \%available_protocols = (\n";
  1802. print OUT " tls => [ ", join(", ", map { quotify("perl", $_) } @tls), " ],\n";
  1803. print OUT " dtls => [ ", join(", ", map { quotify("perl", $_) } @dtls), " ],\n";
  1804. print OUT <<"EOF";
  1805. );
  1806. EOF
  1807. print OUT "our \@disablables = (\n";
  1808. foreach (@disablables) {
  1809. print OUT " ", quotify("perl", $_), ",\n";
  1810. }
  1811. print OUT <<"EOF";
  1812. );
  1813. EOF
  1814. print OUT "our \%disabled = (\n";
  1815. foreach (sort keys %disabled) {
  1816. print OUT " ", quotify("perl", $_), " => ", quotify("perl", $disabled{$_}), ",\n";
  1817. }
  1818. print OUT <<"EOF";
  1819. );
  1820. EOF
  1821. print OUT "our %withargs = (\n";
  1822. foreach (sort keys %withargs) {
  1823. if (ref($withargs{$_}) eq "ARRAY") {
  1824. print OUT " ", $_, " => [ ", join(", ",
  1825. map { quotify("perl", $_) }
  1826. @{$withargs{$_}}), " ],\n";
  1827. } else {
  1828. print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n"
  1829. }
  1830. }
  1831. print OUT <<"EOF";
  1832. );
  1833. EOF
  1834. if ($builder eq "unified") {
  1835. my $recurse;
  1836. $recurse = sub {
  1837. my $indent = shift;
  1838. foreach (@_) {
  1839. if (ref $_ eq "ARRAY") {
  1840. print OUT " "x$indent, "[\n";
  1841. foreach (@$_) {
  1842. $recurse->($indent + 4, $_);
  1843. }
  1844. print OUT " "x$indent, "],\n";
  1845. } elsif (ref $_ eq "HASH") {
  1846. my %h = %$_;
  1847. print OUT " "x$indent, "{\n";
  1848. foreach (sort keys %h) {
  1849. if (ref $h{$_} eq "") {
  1850. print OUT " "x($indent + 4), quotify("perl", $_), " => ", quotify("perl", $h{$_}), ",\n";
  1851. } else {
  1852. print OUT " "x($indent + 4), quotify("perl", $_), " =>\n";
  1853. $recurse->($indent + 8, $h{$_});
  1854. }
  1855. }
  1856. print OUT " "x$indent, "},\n";
  1857. } else {
  1858. print OUT " "x$indent, quotify("perl", $_), ",\n";
  1859. }
  1860. }
  1861. };
  1862. print OUT "our %unified_info = (\n";
  1863. foreach (sort keys %unified_info) {
  1864. if (ref $unified_info{$_} eq "") {
  1865. print OUT " "x4, quotify("perl", $_), " => ", quotify("perl", $unified_info{$_}), ",\n";
  1866. } else {
  1867. print OUT " "x4, quotify("perl", $_), " =>\n";
  1868. $recurse->(8, $unified_info{$_});
  1869. }
  1870. }
  1871. print OUT <<"EOF";
  1872. );
  1873. EOF
  1874. }
  1875. print OUT "1;\n";
  1876. close(OUT);
  1877. print "CC =$config{cross_compile_prefix}$target{cc}\n";
  1878. print "CFLAG =$target{cflags} $config{cflags}\n";
  1879. print "SHARED_CFLAG =$target{shared_cflag}\n";
  1880. print "DEFINES =",join(" ", @{$target{defines}}, @{$config{defines}}),"\n";
  1881. print "LFLAG =$target{lflags}\n";
  1882. print "PLIB_LFLAG =$target{plib_lflags}\n";
  1883. print "EX_LIBS =$target{ex_libs} $config{ex_libs}\n";
  1884. print "APPS_OBJ =$target{apps_obj}\n";
  1885. print "CPUID_OBJ =$target{cpuid_obj}\n";
  1886. print "UPLINK_OBJ =$target{uplink_obj}\n";
  1887. print "BN_ASM =$target{bn_obj}\n";
  1888. print "EC_ASM =$target{ec_obj}\n";
  1889. print "DES_ENC =$target{des_obj}\n";
  1890. print "AES_ENC =$target{aes_obj}\n";
  1891. print "BF_ENC =$target{bf_obj}\n";
  1892. print "CAST_ENC =$target{cast_obj}\n";
  1893. print "RC4_ENC =$target{rc4_obj}\n";
  1894. print "RC5_ENC =$target{rc5_obj}\n";
  1895. print "MD5_OBJ_ASM =$target{md5_obj}\n";
  1896. print "SHA1_OBJ_ASM =$target{sha1_obj}\n";
  1897. print "RMD160_OBJ_ASM=$target{rmd160_obj}\n";
  1898. print "CMLL_ENC =$target{cmll_obj}\n";
  1899. print "MODES_OBJ =$target{modes_obj}\n";
  1900. print "PADLOCK_OBJ =$target{padlock_obj}\n";
  1901. print "CHACHA_ENC =$target{chacha_obj}\n";
  1902. print "POLY1305_OBJ =$target{poly1305_obj}\n";
  1903. print "BLAKE2_OBJ =$target{blake2_obj}\n";
  1904. print "PROCESSOR =$config{processor}\n";
  1905. print "RANLIB =", $target{ranlib} eq '$(CROSS_COMPILE)ranlib' ?
  1906. "$config{cross_compile_prefix}ranlib" :
  1907. "$target{ranlib}", "\n";
  1908. print "ARFLAGS =$target{arflags}\n";
  1909. print "PERL =$config{perl}\n";
  1910. print "\n";
  1911. print "SIXTY_FOUR_BIT_LONG mode\n" if $config{b64l};
  1912. print "SIXTY_FOUR_BIT mode\n" if $config{b64};
  1913. print "THIRTY_TWO_BIT mode\n" if $config{b32};
  1914. print "BN_LLONG mode\n" if $config{bn_ll};
  1915. print "RC4 uses $config{rc4_int}\n" if $config{rc4_int} ne $def_int;
  1916. my %builders = (
  1917. unified => sub {
  1918. run_dofile(catfile($blddir, $target{build_file}),
  1919. @{$config{build_file_templates}});
  1920. },
  1921. );
  1922. $builders{$builder}->($builder_platform, @builder_opts);
  1923. $SIG{__DIE__} = $orig_death_handler;
  1924. print <<"EOF";
  1925. Configured for $target.
  1926. EOF
  1927. print <<"EOF" if ($disabled{threads} eq "unavailable");
  1928. The library could not be configured for supporting multi-threaded
  1929. applications as the compiler options required on this system are not known.
  1930. See file INSTALL for details if you need multi-threading.
  1931. EOF
  1932. print <<"EOF" if ($no_shared_warn);
  1933. The options 'shared', 'pic' and 'dynamic-engine' aren't supported on this
  1934. platform, so we will pretend you gave the option 'no-pic', which also disables
  1935. 'shared' and 'dynamic-engine'. If you know how to implement shared libraries
  1936. or position independent code, please let us know (but please first make sure
  1937. you have tried with a current version of OpenSSL).
  1938. EOF
  1939. exit(0);
  1940. ######################################################################
  1941. #
  1942. # Helpers and utility functions
  1943. #
  1944. # Death handler, to print a helpful message in case of failure #######
  1945. #
  1946. sub death_handler {
  1947. die @_ if $^S; # To prevent the added message in eval blocks
  1948. my $build_file = $target{build_file} // "build file";
  1949. my @message = ( <<"_____", @_ );
  1950. Failure! $build_file wasn't produced.
  1951. Please read INSTALL and associated NOTES files. You may also have to look over
  1952. your available compiler tool chain or change your configuration.
  1953. _____
  1954. # Dying is terminal, so it's ok to reset the signal handler here.
  1955. $SIG{__DIE__} = $orig_death_handler;
  1956. die @message;
  1957. }
  1958. # Configuration file reading #########################################
  1959. # Note: All of the helper functions are for lazy evaluation. They all
  1960. # return a CODE ref, which will return the intended value when evaluated.
  1961. # Thus, whenever there's mention of a returned value, it's about that
  1962. # intended value.
  1963. # Helper function to implement conditional inheritance depending on the
  1964. # value of $disabled{asm}. Used in inherit_from values as follows:
  1965. #
  1966. # inherit_from => [ "template", asm("asm_tmpl") ]
  1967. #
  1968. sub asm {
  1969. my @x = @_;
  1970. sub {
  1971. $disabled{asm} ? () : @x;
  1972. }
  1973. }
  1974. # Helper function to implement conditional value variants, with a default
  1975. # plus additional values based on the value of $config{build_type}.
  1976. # Arguments are given in hash table form:
  1977. #
  1978. # picker(default => "Basic string: ",
  1979. # debug => "debug",
  1980. # release => "release")
  1981. #
  1982. # When configuring with --debug, the resulting string will be
  1983. # "Basic string: debug", and when not, it will be "Basic string: release"
  1984. #
  1985. # This can be used to create variants of sets of flags according to the
  1986. # build type:
  1987. #
  1988. # cflags => picker(default => "-Wall",
  1989. # debug => "-g -O0",
  1990. # release => "-O3")
  1991. #
  1992. sub picker {
  1993. my %opts = @_;
  1994. return sub { add($opts{default} || (),
  1995. $opts{$config{build_type}} || ())->(); }
  1996. }
  1997. # Helper function to combine several values of different types into one.
  1998. # This is useful if you want to combine a string with the result of a
  1999. # lazy function, such as:
  2000. #
  2001. # cflags => combine("-Wall", sub { $disabled{zlib} ? () : "-DZLIB" })
  2002. #
  2003. sub combine {
  2004. my @stuff = @_;
  2005. return sub { add(@stuff)->(); }
  2006. }
  2007. # Helper function to implement conditional values depending on the value
  2008. # of $disabled{threads}. Can be used as follows:
  2009. #
  2010. # cflags => combine("-Wall", threads("-pthread"))
  2011. #
  2012. sub threads {
  2013. my @flags = @_;
  2014. return sub { add($disabled{threads} ? () : @flags)->(); }
  2015. }
  2016. our $add_called = 0;
  2017. # Helper function to implement adding values to already existing configuration
  2018. # values. It handles elements that are ARRAYs, CODEs and scalars
  2019. sub _add {
  2020. my $separator = shift;
  2021. # If there's any ARRAY in the collection of values OR the separator
  2022. # is undef, we will return an ARRAY of combined values, otherwise a
  2023. # string of joined values with $separator as the separator.
  2024. my $found_array = !defined($separator);
  2025. my @values =
  2026. map {
  2027. my $res = $_;
  2028. while (ref($res) eq "CODE") {
  2029. $res = $res->();
  2030. }
  2031. if (defined($res)) {
  2032. if (ref($res) eq "ARRAY") {
  2033. $found_array = 1;
  2034. @$res;
  2035. } else {
  2036. $res;
  2037. }
  2038. } else {
  2039. ();
  2040. }
  2041. } (@_);
  2042. $add_called = 1;
  2043. if ($found_array) {
  2044. [ @values ];
  2045. } else {
  2046. join($separator, grep { defined($_) && $_ ne "" } @values);
  2047. }
  2048. }
  2049. sub add_before {
  2050. my $separator = " ";
  2051. if (ref($_[$#_]) eq "HASH") {
  2052. my $opts = pop;
  2053. $separator = $opts->{separator};
  2054. }
  2055. my @x = @_;
  2056. sub { _add($separator, @x, @_) };
  2057. }
  2058. sub add {
  2059. my $separator = " ";
  2060. if (ref($_[$#_]) eq "HASH") {
  2061. my $opts = pop;
  2062. $separator = $opts->{separator};
  2063. }
  2064. my @x = @_;
  2065. sub { _add($separator, @_, @x) };
  2066. }
  2067. # configuration reader, evaluates the input file as a perl script and expects
  2068. # it to fill %targets with target configurations. Those are then added to
  2069. # %table.
  2070. sub read_config {
  2071. my $fname = shift;
  2072. open(CONFFILE, "< $fname")
  2073. or die "Can't open configuration file '$fname'!\n";
  2074. my $x = $/;
  2075. undef $/;
  2076. my $content = <CONFFILE>;
  2077. $/ = $x;
  2078. close(CONFFILE);
  2079. my %targets = ();
  2080. {
  2081. # Protect certain tables from tampering
  2082. local %table = %::table;
  2083. eval $content;
  2084. warn $@ if $@;
  2085. }
  2086. my %preexisting = ();
  2087. foreach (sort keys %targets) {
  2088. $preexisting{$_} = 1 if $table{$_};
  2089. }
  2090. die <<"EOF",
  2091. The following config targets from $fname
  2092. shadow pre-existing config targets with the same name:
  2093. EOF
  2094. map { " $_\n" } sort keys %preexisting
  2095. if %preexisting;
  2096. # For each target, check that it's configured with a hash table.
  2097. foreach (keys %targets) {
  2098. if (ref($targets{$_}) ne "HASH") {
  2099. if (ref($targets{$_}) eq "") {
  2100. warn "Deprecated target configuration for $_, ignoring...\n";
  2101. } else {
  2102. warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
  2103. }
  2104. delete $targets{$_};
  2105. } else {
  2106. $targets{$_}->{_conf_fname_int} = add([ $fname ]);
  2107. }
  2108. }
  2109. %table = (%table, %targets);
  2110. }
  2111. # configuration resolver. Will only resolve all the lazy evaluation
  2112. # codeblocks for the chosen target and all those it inherits from,
  2113. # recursively
  2114. sub resolve_config {
  2115. my $target = shift;
  2116. my @breadcrumbs = @_;
  2117. # my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS});
  2118. if (grep { $_ eq $target } @breadcrumbs) {
  2119. die "inherit_from loop! target backtrace:\n "
  2120. ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
  2121. }
  2122. if (!defined($table{$target})) {
  2123. warn "Warning! target $target doesn't exist!\n";
  2124. return ();
  2125. }
  2126. # Recurse through all inheritances. They will be resolved on the
  2127. # fly, so when this operation is done, they will all just be a
  2128. # bunch of attributes with string values.
  2129. # What we get here, though, are keys with references to lists of
  2130. # the combined values of them all. We will deal with lists after
  2131. # this stage is done.
  2132. my %combined_inheritance = ();
  2133. if ($table{$target}->{inherit_from}) {
  2134. my @inherit_from =
  2135. map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
  2136. foreach (@inherit_from) {
  2137. my %inherited_config = resolve_config($_, $target, @breadcrumbs);
  2138. # 'template' is a marker that's considered private to
  2139. # the config that had it.
  2140. delete $inherited_config{template};
  2141. foreach (keys %inherited_config) {
  2142. if (!$combined_inheritance{$_}) {
  2143. $combined_inheritance{$_} = [];
  2144. }
  2145. push @{$combined_inheritance{$_}}, $inherited_config{$_};
  2146. }
  2147. }
  2148. }
  2149. # We won't need inherit_from in this target any more, since we've
  2150. # resolved all the inheritances that lead to this
  2151. delete $table{$target}->{inherit_from};
  2152. # Now is the time to deal with those lists. Here's the place to
  2153. # decide what shall be done with those lists, all based on the
  2154. # values of the target we're currently dealing with.
  2155. # - If a value is a coderef, it will be executed with the list of
  2156. # inherited values as arguments.
  2157. # - If the corresponding key doesn't have a value at all or is the
  2158. # empty string, the inherited value list will be run through the
  2159. # default combiner (below), and the result becomes this target's
  2160. # value.
  2161. # - Otherwise, this target's value is assumed to be a string that
  2162. # will simply override the inherited list of values.
  2163. my $default_combiner = add();
  2164. my %all_keys =
  2165. map { $_ => 1 } (keys %combined_inheritance,
  2166. keys %{$table{$target}});
  2167. sub process_values {
  2168. my $object = shift;
  2169. my $inherited = shift; # Always a [ list ]
  2170. my $target = shift;
  2171. my $entry = shift;
  2172. $add_called = 0;
  2173. while(ref($object) eq "CODE") {
  2174. $object = $object->(@$inherited);
  2175. }
  2176. if (!defined($object)) {
  2177. return ();
  2178. }
  2179. elsif (ref($object) eq "ARRAY") {
  2180. local $add_called; # To make sure recursive calls don't affect it
  2181. return [ map { process_values($_, $inherited, $target, $entry) }
  2182. @$object ];
  2183. } elsif (ref($object) eq "") {
  2184. return $object;
  2185. } else {
  2186. die "cannot handle reference type ",ref($object)
  2187. ," found in target ",$target," -> ",$entry,"\n";
  2188. }
  2189. }
  2190. foreach (sort keys %all_keys) {
  2191. my $previous = $combined_inheritance{$_};
  2192. # Current target doesn't have a value for the current key?
  2193. # Assign it the default combiner, the rest of this loop body
  2194. # will handle it just like any other coderef.
  2195. if (!exists $table{$target}->{$_}) {
  2196. $table{$target}->{$_} = $default_combiner;
  2197. }
  2198. $table{$target}->{$_} = process_values($table{$target}->{$_},
  2199. $combined_inheritance{$_},
  2200. $target, $_);
  2201. unless(defined($table{$target}->{$_})) {
  2202. delete $table{$target}->{$_};
  2203. }
  2204. # if ($extra_checks &&
  2205. # $previous && !($add_called || $previous ~~ $table{$target}->{$_})) {
  2206. # warn "$_ got replaced in $target\n";
  2207. # }
  2208. }
  2209. # Finally done, return the result.
  2210. return %{$table{$target}};
  2211. }
  2212. sub usage
  2213. {
  2214. print STDERR $usage;
  2215. print STDERR "\npick os/compiler from:\n";
  2216. my $j=0;
  2217. my $i;
  2218. my $k=0;
  2219. foreach $i (sort keys %table)
  2220. {
  2221. next if $table{$i}->{template};
  2222. next if $i =~ /^debug/;
  2223. $k += length($i) + 1;
  2224. if ($k > 78)
  2225. {
  2226. print STDERR "\n";
  2227. $k=length($i);
  2228. }
  2229. print STDERR $i . " ";
  2230. }
  2231. foreach $i (sort keys %table)
  2232. {
  2233. next if $table{$i}->{template};
  2234. next if $i !~ /^debug/;
  2235. $k += length($i) + 1;
  2236. if ($k > 78)
  2237. {
  2238. print STDERR "\n";
  2239. $k=length($i);
  2240. }
  2241. print STDERR $i . " ";
  2242. }
  2243. print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n";
  2244. exit(1);
  2245. }
  2246. sub run_dofile
  2247. {
  2248. my $out = shift;
  2249. my @templates = @_;
  2250. unlink $out || warn "Can't remove $out, $!"
  2251. if -f $out;
  2252. foreach (@templates) {
  2253. die "Can't open $_, $!" unless -f $_;
  2254. }
  2255. my $perlcmd = (quotify("maybeshell", $config{perl}))[0];
  2256. my $cmd = "$perlcmd \"-I.\" \"-Mconfigdata\" \"$dofile\" -o\"Configure\" \"".join("\" \"",@templates)."\" > \"$out.new\"";
  2257. #print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
  2258. system($cmd);
  2259. exit 1 if $? != 0;
  2260. rename("$out.new", $out) || die "Can't rename $out.new, $!";
  2261. }
  2262. sub which
  2263. {
  2264. my ($name)=@_;
  2265. if (eval { require IPC::Cmd; 1; }) {
  2266. IPC::Cmd->import();
  2267. return scalar IPC::Cmd::can_run($name);
  2268. } else {
  2269. # if there is $directories component in splitpath,
  2270. # then it's not something to test with $PATH...
  2271. return $name if (File::Spec->splitpath($name))[1];
  2272. foreach (File::Spec->path()) {
  2273. my $fullpath = catfile($_, "$name$target{exe_extension}");
  2274. if (-f $fullpath and -x $fullpath) {
  2275. return $fullpath;
  2276. }
  2277. }
  2278. }
  2279. }
  2280. # Configuration printer ##############################################
  2281. sub print_table_entry
  2282. {
  2283. my $target = shift;
  2284. my %target = resolve_config($target);
  2285. my $type = shift;
  2286. # Don't print the templates
  2287. return if $target{template};
  2288. my @sequence = (
  2289. "sys_id",
  2290. "cc",
  2291. "cflags",
  2292. "defines",
  2293. "unistd",
  2294. "ld",
  2295. "lflags",
  2296. "loutflag",
  2297. "plib_lflags",
  2298. "ex_libs",
  2299. "bn_ops",
  2300. "apps_aux_src",
  2301. "cpuid_asm_src",
  2302. "uplink_aux_src",
  2303. "bn_asm_src",
  2304. "ec_asm_src",
  2305. "des_asm_src",
  2306. "aes_asm_src",
  2307. "bf_asm_src",
  2308. "md5_asm_src",
  2309. "cast_asm_src",
  2310. "sha1_asm_src",
  2311. "rc4_asm_src",
  2312. "rmd160_asm_src",
  2313. "rc5_asm_src",
  2314. "wp_asm_src",
  2315. "cmll_asm_src",
  2316. "modes_asm_src",
  2317. "padlock_asm_src",
  2318. "chacha_asm_src",
  2319. "poly1035_asm_src",
  2320. "thread_scheme",
  2321. "perlasm_scheme",
  2322. "dso_scheme",
  2323. "shared_target",
  2324. "shared_cflag",
  2325. "shared_defines",
  2326. "shared_ldflag",
  2327. "shared_rcflag",
  2328. "shared_extension",
  2329. "dso_extension",
  2330. "obj_extension",
  2331. "exe_extension",
  2332. "ranlib",
  2333. "ar",
  2334. "arflags",
  2335. "aroutflag",
  2336. "rc",
  2337. "rcflags",
  2338. "rcoutflag",
  2339. "mt",
  2340. "mtflags",
  2341. "mtinflag",
  2342. "mtoutflag",
  2343. "multilib",
  2344. "build_scheme",
  2345. );
  2346. if ($type eq "TABLE") {
  2347. print "\n";
  2348. print "*** $target\n";
  2349. foreach (@sequence) {
  2350. if (ref($target{$_}) eq "ARRAY") {
  2351. printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}});
  2352. } else {
  2353. printf "\$%-12s = %s\n", $_, $target{$_};
  2354. }
  2355. }
  2356. } elsif ($type eq "HASH") {
  2357. my $largest =
  2358. length((sort { length($a) <=> length($b) } @sequence)[-1]);
  2359. print " '$target' => {\n";
  2360. foreach (@sequence) {
  2361. if ($target{$_}) {
  2362. if (ref($target{$_}) eq "ARRAY") {
  2363. print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n";
  2364. } else {
  2365. print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
  2366. }
  2367. }
  2368. }
  2369. print " },\n";
  2370. }
  2371. }
  2372. # Utility routines ###################################################
  2373. # On VMS, if the given file is a logical name, File::Spec::Functions
  2374. # will consider it an absolute path. There are cases when we want a
  2375. # purely syntactic check without checking the environment.
  2376. sub isabsolute {
  2377. my $file = shift;
  2378. # On non-platforms, we just use file_name_is_absolute().
  2379. return file_name_is_absolute($file) unless $^O eq "VMS";
  2380. # If the file spec includes a device or a directory spec,
  2381. # file_name_is_absolute() is perfectly safe.
  2382. return file_name_is_absolute($file) if $file =~ m|[:\[]|;
  2383. # Here, we know the given file spec isn't absolute
  2384. return 0;
  2385. }
  2386. # Makes a directory absolute and cleans out /../ in paths like foo/../bar
  2387. # On some platforms, this uses rel2abs(), while on others, realpath() is used.
  2388. # realpath() requires that at least all path components except the last is an
  2389. # existing directory. On VMS, the last component of the directory spec must
  2390. # exist.
  2391. sub absolutedir {
  2392. my $dir = shift;
  2393. # realpath() is quite buggy on VMS. It uses LIB$FID_TO_NAME, which
  2394. # will return the volume name for the device, no matter what. Also,
  2395. # it will return an incorrect directory spec if the argument is a
  2396. # directory that doesn't exist.
  2397. if ($^O eq "VMS") {
  2398. return rel2abs($dir);
  2399. }
  2400. # We use realpath() on Unix, since no other will properly clean out
  2401. # a directory spec.
  2402. use Cwd qw/realpath/;
  2403. return realpath($dir);
  2404. }
  2405. sub quotify {
  2406. my %processors = (
  2407. perl => sub { my $x = shift;
  2408. $x =~ s/([\\\$\@"])/\\$1/g;
  2409. return '"'.$x.'"'; },
  2410. maybeshell => sub { my $x = shift;
  2411. (my $y = $x) =~ s/([\\\"])/\\$1/g;
  2412. if ($x ne $y || $x =~ m|\s|) {
  2413. return '"'.$y.'"';
  2414. } else {
  2415. return $x;
  2416. }
  2417. },
  2418. );
  2419. my $for = shift;
  2420. my $processor =
  2421. defined($processors{$for}) ? $processors{$for} : sub { shift; };
  2422. return map { $processor->($_); } @_;
  2423. }
  2424. # collect_from_file($filename, $line_concat_cond_re, $line_concat)
  2425. # $filename is a file name to read from
  2426. # $line_concat_cond_re is a regexp detecting a line continuation ending
  2427. # $line_concat is a CODEref that takes care of concatenating two lines
  2428. sub collect_from_file {
  2429. my $filename = shift;
  2430. my $line_concat_cond_re = shift;
  2431. my $line_concat = shift;
  2432. open my $fh, $filename || die "unable to read $filename: $!\n";
  2433. return sub {
  2434. my $saved_line = "";
  2435. $_ = "";
  2436. while (<$fh>) {
  2437. s|\R$||;
  2438. if (defined $line_concat) {
  2439. $_ = $line_concat->($saved_line, $_);
  2440. $saved_line = "";
  2441. }
  2442. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  2443. $saved_line = $_;
  2444. next;
  2445. }
  2446. return $_;
  2447. }
  2448. die "$filename ending with continuation line\n" if $_;
  2449. close $fh;
  2450. return undef;
  2451. }
  2452. }
  2453. # collect_from_array($array, $line_concat_cond_re, $line_concat)
  2454. # $array is an ARRAYref of lines
  2455. # $line_concat_cond_re is a regexp detecting a line continuation ending
  2456. # $line_concat is a CODEref that takes care of concatenating two lines
  2457. sub collect_from_array {
  2458. my $array = shift;
  2459. my $line_concat_cond_re = shift;
  2460. my $line_concat = shift;
  2461. my @array = (@$array);
  2462. return sub {
  2463. my $saved_line = "";
  2464. $_ = "";
  2465. while (defined($_ = shift @array)) {
  2466. s|\R$||;
  2467. if (defined $line_concat) {
  2468. $_ = $line_concat->($saved_line, $_);
  2469. $saved_line = "";
  2470. }
  2471. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  2472. $saved_line = $_;
  2473. next;
  2474. }
  2475. return $_;
  2476. }
  2477. die "input text ending with continuation line\n" if $_;
  2478. return undef;
  2479. }
  2480. }
  2481. # collect_information($lineiterator, $line_continue, $regexp => $CODEref, ...)
  2482. # $lineiterator is a CODEref that delivers one line at a time.
  2483. # All following arguments are regex/CODEref pairs, where the regexp detects a
  2484. # line and the CODEref does something with the result of the regexp.
  2485. sub collect_information {
  2486. my $lineiterator = shift;
  2487. my %collectors = @_;
  2488. while(defined($_ = $lineiterator->())) {
  2489. s|\R$||;
  2490. my $found = 0;
  2491. if ($collectors{"BEFORE"}) {
  2492. $collectors{"BEFORE"}->($_);
  2493. }
  2494. foreach my $re (keys %collectors) {
  2495. if ($re !~ /^OTHERWISE|BEFORE|AFTER$/ && /$re/) {
  2496. $collectors{$re}->($lineiterator);
  2497. $found = 1;
  2498. };
  2499. }
  2500. if ($collectors{"OTHERWISE"}) {
  2501. $collectors{"OTHERWISE"}->($lineiterator, $_)
  2502. unless $found || !defined $collectors{"OTHERWISE"};
  2503. }
  2504. if ($collectors{"AFTER"}) {
  2505. $collectors{"AFTER"}->($_);
  2506. }
  2507. }
  2508. }
  2509. # tokenize($line)
  2510. # $line is a line of text to split up into tokens
  2511. # returns a list of tokens
  2512. #
  2513. # Tokens are divided by spaces. If the tokens include spaces, they
  2514. # have to be quoted with single or double quotes. Double quotes
  2515. # inside a double quoted token must be escaped. Escaping is done
  2516. # with backslash.
  2517. # Basically, the same quoting rules apply for " and ' as in any
  2518. # Unix shell.
  2519. sub tokenize {
  2520. my $line = my $debug_line = shift;
  2521. my @result = ();
  2522. while ($line =~ s|^\s+||, $line ne "") {
  2523. my $token = "";
  2524. while ($line ne "" && $line !~ m|^\s|) {
  2525. if ($line =~ m/^"((?:[^"\\]+|\\.)*)"/) {
  2526. $token .= $1;
  2527. $line = $';
  2528. } elsif ($line =~ m/^'([^']*)'/) {
  2529. $token .= $1;
  2530. $line = $';
  2531. } elsif ($line =~ m/^(\S+)/) {
  2532. $token .= $1;
  2533. $line = $';
  2534. }
  2535. }
  2536. push @result, $token;
  2537. }
  2538. if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) {
  2539. print STDERR "DEBUG[tokenize]: Parsed '$debug_line' into:\n";
  2540. print STDERR "DEBUG[tokenize]: ('", join("', '", @result), "')\n";
  2541. }
  2542. return @result;
  2543. }