Configure 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546
  1. #! /usr/bin/env perl
  2. # -*- mode: perl; -*-
  3. # Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License 2.0 (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 Config;
  13. use FindBin;
  14. use lib "$FindBin::Bin/util/perl";
  15. use File::Basename;
  16. use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs splitdir/;
  17. use File::Path qw/mkpath/;
  18. use OpenSSL::Glob;
  19. # see INSTALL for instructions.
  20. my $orig_death_handler = $SIG{__DIE__};
  21. $SIG{__DIE__} = \&death_handler;
  22. 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";
  23. # Options:
  24. #
  25. # --config add the given configuration file, which will be read after
  26. # any "Configurations*" files that are found in the same
  27. # directory as this script.
  28. # --prefix prefix for the OpenSSL installation, which includes the
  29. # directories bin, lib, include, share/man, share/doc/openssl
  30. # This becomes the value of INSTALLTOP in Makefile
  31. # (Default: /usr/local)
  32. # --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys.
  33. # If it's a relative directory, it will be added on the directory
  34. # given with --prefix.
  35. # This becomes the value of OPENSSLDIR in Makefile and in C.
  36. # (Default: PREFIX/ssl)
  37. #
  38. # --cross-compile-prefix Add specified prefix to binutils components.
  39. #
  40. # --api One of 0.9.8, 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.1, or 3.0.0 / 3.
  41. # Do not compile support for interfaces deprecated as of the
  42. # specified OpenSSL version.
  43. #
  44. # no-hw-xxx do not compile support for specific crypto hardware.
  45. # Generic OpenSSL-style methods relating to this support
  46. # are always compiled but return NULL if the hardware
  47. # support isn't compiled.
  48. # no-hw do not compile support for any crypto hardware.
  49. # [no-]threads [don't] try to create a library that is suitable for
  50. # multithreaded applications (default is "threads" if we
  51. # know how to do it)
  52. # [no-]shared [don't] try to create shared libraries when supported.
  53. # [no-]pic [don't] try to build position independent code when supported.
  54. # If disabled, it also disables shared and dynamic-engine.
  55. # no-asm do not use assembler
  56. # no-dso do not compile in any native shared-library methods. This
  57. # will ensure that all methods just return NULL.
  58. # no-egd do not compile support for the entropy-gathering daemon APIs
  59. # [no-]zlib [don't] compile support for zlib compression.
  60. # zlib-dynamic Like "zlib", but the zlib library is expected to be a shared
  61. # library and will be loaded in run-time by the OpenSSL library.
  62. # sctp include SCTP support
  63. # enable-weak-ssl-ciphers
  64. # Enable weak ciphers that are disabled by default.
  65. # 386 generate 80386 code in assembly modules
  66. # no-sse2 disables IA-32 SSE2 code in assembly modules, the above
  67. # mentioned '386' option implies this one
  68. # no-<cipher> build without specified algorithm (rsa, idea, rc5, ...)
  69. # -<xxx> +<xxx> compiler options are passed through
  70. # -static while -static is also a pass-through compiler option (and
  71. # as such is limited to environments where it's actually
  72. # meaningful), it triggers a number configuration options,
  73. # namely no-dso, no-pic, no-shared and no-threads. It is
  74. # argued that the only reason to produce statically linked
  75. # binaries (and in context it means executables linked with
  76. # -static flag, and not just executables linked with static
  77. # libcrypto.a) is to eliminate dependency on specific run-time,
  78. # a.k.a. libc version. The mentioned config options are meant
  79. # to achieve just that. Unfortunately on Linux it's impossible
  80. # to eliminate the dependency completely for openssl executable
  81. # because of getaddrinfo and gethostbyname calls, which can
  82. # invoke dynamically loadable library facility anyway to meet
  83. # the lookup requests. For this reason on Linux statically
  84. # linked openssl executable has rather debugging value than
  85. # production quality.
  86. #
  87. # DEBUG_SAFESTACK use type-safe stacks to enforce type-safety on stack items
  88. # provided to stack calls. Generates unique stack functions for
  89. # each possible stack type.
  90. # BN_LLONG use the type 'long long' in crypto/bn/bn.h
  91. # RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
  92. # Following are set automatically by this script
  93. #
  94. # MD5_ASM use some extra md5 assembler,
  95. # SHA1_ASM use some extra sha1 assembler, must define L_ENDIAN for x86
  96. # RMD160_ASM use some extra ripemd160 assembler,
  97. # SHA256_ASM sha256_block is implemented in assembler
  98. # SHA512_ASM sha512_block is implemented in assembler
  99. # AES_ASM AES_[en|de]crypt is implemented in assembler
  100. # Minimum warning options... any contributions to OpenSSL should at least get
  101. # past these.
  102. # DEBUG_UNUSED enables __owur (warn unused result) checks.
  103. # -DPEDANTIC complements -pedantic and is meant to mask code that
  104. # is not strictly standard-compliant and/or implementation-specific,
  105. # e.g. inline assembly, disregards to alignment requirements, such
  106. # that -pedantic would complain about. Incidentally -DPEDANTIC has
  107. # to be used even in sanitized builds, because sanitizer too is
  108. # supposed to and does take notice of non-standard behaviour. Then
  109. # -pedantic with pre-C9x compiler would also complain about 'long
  110. # long' not being supported. As 64-bit algorithms are common now,
  111. # it grew impossible to resolve this without sizeable additional
  112. # code, so we just tell compiler to be pedantic about everything
  113. # but 'long long' type.
  114. my $gcc_devteam_warn = "-DDEBUG_UNUSED"
  115. . " -DPEDANTIC -pedantic -Wno-long-long"
  116. . " -Wall"
  117. . " -Wextra"
  118. . " -Wno-unused-parameter"
  119. . " -Wno-missing-field-initializers"
  120. . " -Wswitch"
  121. . " -Wsign-compare"
  122. . " -Wmissing-prototypes"
  123. . " -Wstrict-prototypes"
  124. . " -Wshadow"
  125. . " -Wformat"
  126. . " -Wtype-limits"
  127. . " -Wundef"
  128. . " -Werror"
  129. ;
  130. # These are used in addition to $gcc_devteam_warn when the compiler is clang.
  131. # TODO(openssl-team): fix problems and investigate if (at least) the
  132. # following warnings can also be enabled:
  133. # -Wcast-align
  134. # -Wunreachable-code -- no, too ugly/compiler-specific
  135. # -Wlanguage-extension-token -- no, we use asm()
  136. # -Wunused-macros -- no, too tricky for BN and _XOPEN_SOURCE etc
  137. # -Wextended-offsetof -- no, needed in CMS ASN1 code
  138. my $clang_devteam_warn = ""
  139. . " -Wswitch-default"
  140. . " -Wno-parentheses-equality"
  141. . " -Wno-language-extension-token"
  142. . " -Wno-extended-offsetof"
  143. . " -Wconditional-uninitialized"
  144. . " -Wincompatible-pointer-types-discards-qualifiers"
  145. . " -Wmissing-variable-declarations"
  146. . " -Wno-unknown-warning-option"
  147. ;
  148. # This adds backtrace information to the memory leak info. Is only used
  149. # when crypto-mdebug-backtrace is enabled.
  150. my $memleak_devteam_backtrace = "-rdynamic";
  151. my $strict_warnings = 0;
  152. # As for $BSDthreads. Idea is to maintain "collective" set of flags,
  153. # which would cover all BSD flavors. -pthread applies to them all,
  154. # but is treated differently. OpenBSD expands is as -D_POSIX_THREAD
  155. # -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r,
  156. # which has to be accompanied by explicit -D_THREAD_SAFE and
  157. # sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which
  158. # seems to be sufficient?
  159. our $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT";
  160. #
  161. # API compatibility name to version number mapping.
  162. #
  163. my $maxapi = "3.0.0"; # API for "no-deprecated" builds
  164. my $apitable = {
  165. "3.0.0" => 3,
  166. "1.1.1" => 2,
  167. "1.1.0" => 2,
  168. "1.0.2" => 1,
  169. "1.0.1" => 1,
  170. "1.0.0" => 1,
  171. "0.9.8" => 0,
  172. };
  173. our %table = ();
  174. our %config = ();
  175. our %withargs = ();
  176. our $now_printing; # set to current entry's name in print_table_entry
  177. # (todo: right thing would be to encapsulate name
  178. # into %target [class] and make print_table_entry
  179. # a method)
  180. # Forward declarations ###############################################
  181. # read_config(filename)
  182. #
  183. # Reads a configuration file and populates %table with the contents
  184. # (which the configuration file places in %targets).
  185. sub read_config;
  186. # resolve_config(target)
  187. #
  188. # Resolves all the late evaluations, inheritances and so on for the
  189. # chosen target and any target it inherits from.
  190. sub resolve_config;
  191. # Information collection #############################################
  192. # Unified build supports separate build dir
  193. my $srcdir = catdir(absolutedir(dirname($0))); # catdir ensures local syntax
  194. my $blddir = catdir(absolutedir(".")); # catdir ensures local syntax
  195. my $dofile = abs2rel(catfile($srcdir, "util/dofile.pl"));
  196. my $local_config_envname = 'OPENSSL_LOCAL_CONFIG_DIR';
  197. $config{sourcedir} = abs2rel($srcdir);
  198. $config{builddir} = abs2rel($blddir);
  199. # Collect reconfiguration information if needed
  200. my @argvcopy=@ARGV;
  201. if (grep /^reconf(igure)?$/, @argvcopy) {
  202. die "reconfiguring with other arguments present isn't supported"
  203. if scalar @argvcopy > 1;
  204. if (-f "./configdata.pm") {
  205. my $file = "./configdata.pm";
  206. unless (my $return = do $file) {
  207. die "couldn't parse $file: $@" if $@;
  208. die "couldn't do $file: $!" unless defined $return;
  209. die "couldn't run $file" unless $return;
  210. }
  211. @argvcopy = defined($configdata::config{perlargv}) ?
  212. @{$configdata::config{perlargv}} : ();
  213. die "Incorrect data to reconfigure, please do a normal configuration\n"
  214. if (grep(/^reconf/,@argvcopy));
  215. $config{perlenv} = $configdata::config{perlenv} // {};
  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{major} = "unknown";
  223. $config{minor} = "unknown";
  224. $config{patch} = "unknown";
  225. $config{prerelease} = "";
  226. $config{build_metadata} = "";
  227. $config{shlib_version} = "unknown";
  228. collect_information(
  229. collect_from_file(catfile($srcdir,'include/openssl/opensslv.h')),
  230. qr/#\s+define\s+OPENSSL_VERSION_MAJOR\s+(\d+)/ =>
  231. sub { $config{major} = $1; },
  232. qr/#\s+define\s+OPENSSL_VERSION_MINOR\s+(\d+)/ =>
  233. sub { $config{minor} = $1; },
  234. qr/#\s+define\s+OPENSSL_VERSION_PATCH\s+(\d+)/ =>
  235. sub { $config{patch} = $1; },
  236. qr/#\s+define\s+OPENSSL_VERSION_PRE_RELEASE\s+"((?:\\.|[^"])*)"/ =>
  237. sub { $config{prerelease} = $1; },
  238. qr/#\s+define\s+OPENSSL_VERSION_BUILD_METADATA\s+"((?:\\.|[^"])*)"/ =>
  239. sub { $config{build_metadata} = $1; },
  240. qr/#\s+define\s+OPENSSL_SHLIB_VERSION\s+([\d\.]+)/ =>
  241. sub { $config{shlib_version} = $1; },
  242. );
  243. die "erroneous version information in opensslv.h: ",
  244. "$config{major}.$config{minor}.$config{patch}, $config{shlib_version}\n"
  245. if ($config{major} eq "unknown"
  246. || $config{minor} eq "unknown"
  247. || $config{patch} eq "unknown"
  248. || $config{shlib_version} eq "unknown");
  249. $config{version} = "$config{major}.$config{minor}.$config{patch}";
  250. $config{full_version} = "$config{version}$config{prerelease}$config{build_metadata}";
  251. # Collect target configurations
  252. my $pattern = catfile(dirname($0), "Configurations", "*.conf");
  253. foreach (sort glob($pattern)) {
  254. &read_config($_);
  255. }
  256. if (defined env($local_config_envname)) {
  257. if ($^O eq 'VMS') {
  258. # VMS environment variables are logical names,
  259. # which can be used as is
  260. $pattern = $local_config_envname . ':' . '*.conf';
  261. } else {
  262. $pattern = catfile(env($local_config_envname), '*.conf');
  263. }
  264. foreach (sort glob($pattern)) {
  265. &read_config($_);
  266. }
  267. }
  268. # Save away perl command information
  269. $config{perl_cmd} = $^X;
  270. $config{perl_version} = $Config{version};
  271. $config{perl_archname} = $Config{archname};
  272. $config{prefix}="";
  273. $config{openssldir}="";
  274. $config{processor}="";
  275. $config{libdir}="";
  276. my $auto_threads=1; # enable threads automatically? true by default
  277. my $default_ranlib;
  278. # Known TLS and DTLS protocols
  279. my @tls = qw(ssl3 tls1 tls1_1 tls1_2 tls1_3);
  280. my @dtls = qw(dtls1 dtls1_2);
  281. # Explicitly known options that are possible to disable. They can
  282. # be regexps, and will be used like this: /^no-${option}$/
  283. # For developers: keep it sorted alphabetically
  284. my @disablables = (
  285. "ktls",
  286. "afalgeng",
  287. "aria",
  288. "asan",
  289. "asm",
  290. "async",
  291. "autoalginit",
  292. "autoerrinit",
  293. "autoload-config",
  294. "bf",
  295. "blake2",
  296. "camellia",
  297. "capieng",
  298. "cast",
  299. "chacha",
  300. "cmac",
  301. "cms",
  302. "comp",
  303. "crypto-mdebug",
  304. "crypto-mdebug-backtrace",
  305. "ct",
  306. "deprecated",
  307. "des",
  308. "devcryptoeng",
  309. "dgram",
  310. "dh",
  311. "dsa",
  312. "dso",
  313. "dtls",
  314. "dynamic-engine",
  315. "ec",
  316. "ec2m",
  317. "ecdh",
  318. "ecdsa",
  319. "ec_nistp_64_gcc_128",
  320. "egd",
  321. "engine",
  322. "err",
  323. "external-tests",
  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. "pinshared",
  339. "ocb",
  340. "ocsp",
  341. "pic",
  342. "poly1305",
  343. "posix-io",
  344. "psk",
  345. "rc2",
  346. "rc4",
  347. "rc5",
  348. "rdrand",
  349. "rfc3779",
  350. "rmd160",
  351. "scrypt",
  352. "sctp",
  353. "seed",
  354. "shared",
  355. "siphash",
  356. "siv",
  357. "sm2",
  358. "sm3",
  359. "sm4",
  360. "sock",
  361. "srp",
  362. "srtp",
  363. "sse2",
  364. "ssl",
  365. "ssl-trace",
  366. "static-engine",
  367. "stdio",
  368. "tests",
  369. "threads",
  370. "tls",
  371. "ts",
  372. "ubsan",
  373. "ui-console",
  374. "unit-test",
  375. "whirlpool",
  376. "weak-ssl-ciphers",
  377. "zlib",
  378. "zlib-dynamic",
  379. );
  380. foreach my $proto ((@tls, @dtls))
  381. {
  382. push(@disablables, $proto);
  383. push(@disablables, "$proto-method") unless $proto eq "tls1_3";
  384. }
  385. my %deprecated_disablables = (
  386. "ssl2" => undef,
  387. "buf-freelists" => undef,
  388. "ripemd" => "rmd160",
  389. "ui" => "ui-console",
  390. );
  391. # All of the following are disabled by default:
  392. our %disabled = ( # "what" => "comment"
  393. "asan" => "default",
  394. "crypto-mdebug" => "default",
  395. "crypto-mdebug-backtrace" => "default",
  396. "devcryptoeng" => "default",
  397. "ec_nistp_64_gcc_128" => "default",
  398. "egd" => "default",
  399. "external-tests" => "default",
  400. "fuzz-libfuzzer" => "default",
  401. "fuzz-afl" => "default",
  402. "heartbeats" => "default",
  403. "md2" => "default",
  404. "msan" => "default",
  405. "rc5" => "default",
  406. "sctp" => "default",
  407. "ssl-trace" => "default",
  408. "ssl3" => "default",
  409. "ssl3-method" => "default",
  410. "ubsan" => "default",
  411. "unit-test" => "default",
  412. "weak-ssl-ciphers" => "default",
  413. "zlib" => "default",
  414. "zlib-dynamic" => "default",
  415. "ktls" => "default",
  416. );
  417. # Note: => pair form used for aesthetics, not to truly make a hash table
  418. my @disable_cascades = (
  419. # "what" => [ "cascade", ... ]
  420. sub { $config{processor} eq "386" }
  421. => [ "sse2" ],
  422. "ssl" => [ "ssl3" ],
  423. "ssl3-method" => [ "ssl3" ],
  424. "zlib" => [ "zlib-dynamic" ],
  425. "des" => [ "mdc2" ],
  426. "ec" => [ "ecdsa", "ecdh" ],
  427. "dgram" => [ "dtls", "sctp" ],
  428. "sock" => [ "dgram" ],
  429. "dtls" => [ @dtls ],
  430. sub { 0 == scalar grep { !$disabled{$_} } @dtls }
  431. => [ "dtls" ],
  432. "tls" => [ @tls ],
  433. sub { 0 == scalar grep { !$disabled{$_} } @tls }
  434. => [ "tls" ],
  435. "crypto-mdebug" => [ "crypto-mdebug-backtrace" ],
  436. # Without DSO, we can't load dynamic engines, so don't build them dynamic
  437. "dso" => [ "dynamic-engine" ],
  438. # Without position independent code, there can be no shared libraries or DSOs
  439. "pic" => [ "shared" ],
  440. "shared" => [ "dynamic-engine" ],
  441. "engine" => [ "afalgeng", "devcryptoeng" ],
  442. # no-autoalginit is only useful when building non-shared
  443. "autoalginit" => [ "shared", "apps" ],
  444. "stdio" => [ "apps", "capieng", "egd" ],
  445. "apps" => [ "tests" ],
  446. "tests" => [ "external-tests" ],
  447. "comp" => [ "zlib" ],
  448. "ec" => [ "tls1_3", "sm2" ],
  449. "sm3" => [ "sm2" ],
  450. sub { !$disabled{"unit-test"} } => [ "heartbeats" ],
  451. sub { !$disabled{"msan"} } => [ "asm" ],
  452. sub { $disabled{cmac}; } => [ "siv" ],
  453. );
  454. # Avoid protocol support holes. Also disable all versions below N, if version
  455. # N is disabled while N+1 is enabled.
  456. #
  457. my @list = (reverse @tls);
  458. while ((my $first, my $second) = (shift @list, shift @list)) {
  459. last unless @list;
  460. push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
  461. => [ @list ] );
  462. unshift @list, $second;
  463. }
  464. my @list = (reverse @dtls);
  465. while ((my $first, my $second) = (shift @list, shift @list)) {
  466. last unless @list;
  467. push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
  468. => [ @list ] );
  469. unshift @list, $second;
  470. }
  471. # Explicit "no-..." options will be collected in %disabled along with the defaults.
  472. # To remove something from %disabled, use "enable-foo".
  473. # For symmetry, "disable-foo" is a synonym for "no-foo".
  474. &usage if ($#ARGV < 0);
  475. # For the "make variables" CINCLUDES and CDEFINES, we support lists with
  476. # platform specific list separators. Users from those platforms should
  477. # recognise those separators from how you set up the PATH to find executables.
  478. # The default is the Unix like separator, :, but as an exception, we also
  479. # support the space as separator.
  480. my $list_separator_re =
  481. { VMS => qr/(?<!\^),/,
  482. MSWin32 => qr/(?<!\\);/ } -> {$^O} // qr/(?<!\\)[:\s]/;
  483. # All the "make variables" we support
  484. # Some get pre-populated for the sake of backward compatibility
  485. # (we supported those before the change to "make variable" support.
  486. my %user = (
  487. AR => env('AR'),
  488. ARFLAGS => [],
  489. AS => undef,
  490. ASFLAGS => [],
  491. CC => env('CC'),
  492. CFLAGS => [],
  493. CXX => env('CXX'),
  494. CXXFLAGS => [],
  495. CPP => undef,
  496. CPPFLAGS => [], # -D, -I, -Wp,
  497. CPPDEFINES => [], # Alternative for -D
  498. CPPINCLUDES => [], # Alternative for -I
  499. CROSS_COMPILE => env('CROSS_COMPILE'),
  500. HASHBANGPERL=> env('HASHBANGPERL') || env('PERL'),
  501. LD => undef,
  502. LDFLAGS => [], # -L, -Wl,
  503. LDLIBS => [], # -l
  504. MT => undef,
  505. MTFLAGS => [],
  506. PERL => env('PERL') || ($^O ne "VMS" ? $^X : "perl"),
  507. RANLIB => env('RANLIB'),
  508. RC => env('RC') || env('WINDRES'),
  509. RCFLAGS => [],
  510. RM => undef,
  511. );
  512. # Info about what "make variables" may be prefixed with the cross compiler
  513. # prefix. This should NEVER mention any such variable with a list for value.
  514. my @user_crossable = qw ( AR AS CC CXX CPP LD MT RANLIB RC );
  515. # The same but for flags given as Configure options. These are *additional*
  516. # input, as opposed to the VAR=string option that override the corresponding
  517. # config target attributes
  518. my %useradd = (
  519. CPPDEFINES => [],
  520. CPPINCLUDES => [],
  521. CPPFLAGS => [],
  522. CFLAGS => [],
  523. CXXFLAGS => [],
  524. LDFLAGS => [],
  525. LDLIBS => [],
  526. );
  527. my %user_synonyms = (
  528. HASHBANGPERL=> 'PERL',
  529. RC => 'WINDRES',
  530. );
  531. # Some target attributes have been renamed, this is the translation table
  532. my %target_attr_translate =(
  533. ar => 'AR',
  534. as => 'AS',
  535. cc => 'CC',
  536. cxx => 'CXX',
  537. cpp => 'CPP',
  538. hashbangperl => 'HASHBANGPERL',
  539. ld => 'LD',
  540. mt => 'MT',
  541. ranlib => 'RANLIB',
  542. rc => 'RC',
  543. rm => 'RM',
  544. );
  545. # Initialisers coming from 'config' scripts
  546. $config{defines} = [ split(/$list_separator_re/, env('__CNF_CPPDEFINES')) ];
  547. $config{includes} = [ split(/$list_separator_re/, env('__CNF_CPPINCLUDES')) ];
  548. $config{cppflags} = [ env('__CNF_CPPFLAGS') || () ];
  549. $config{cflags} = [ env('__CNF_CFLAGS') || () ];
  550. $config{cxxflags} = [ env('__CNF_CXXFLAGS') || () ];
  551. $config{lflags} = [ env('__CNF_LDFLAGS') || () ];
  552. $config{ex_libs} = [ env('__CNF_LDLIBS') || () ];
  553. $config{openssl_api_defines}=[];
  554. $config{openssl_sys_defines}=[];
  555. $config{openssl_feature_defines}=[];
  556. $config{options}="";
  557. $config{build_type} = "release";
  558. my $target="";
  559. my %cmdvars = (); # Stores FOO='blah' type arguments
  560. my %unsupported_options = ();
  561. my %deprecated_options = ();
  562. # If you change this, update apps/version.c
  563. my @known_seed_sources = qw(getrandom devrandom os egd none rdcpu librandom);
  564. my @seed_sources = ();
  565. while (@argvcopy)
  566. {
  567. $_ = shift @argvcopy;
  568. # Support env variable assignments among the options
  569. if (m|^(\w+)=(.+)?$|)
  570. {
  571. $cmdvars{$1} = $2;
  572. # Every time a variable is given as a configuration argument,
  573. # it acts as a reset if the variable.
  574. if (exists $user{$1})
  575. {
  576. $user{$1} = ref $user{$1} eq "ARRAY" ? [] : undef;
  577. }
  578. #if (exists $useradd{$1})
  579. # {
  580. # $useradd{$1} = [];
  581. # }
  582. next;
  583. }
  584. # VMS is a case insensitive environment, and depending on settings
  585. # out of our control, we may receive options uppercased. Let's
  586. # downcase at least the part before any equal sign.
  587. if ($^O eq "VMS")
  588. {
  589. s/^([^=]*)/lc($1)/e;
  590. }
  591. # some people just can't read the instructions, clang people have to...
  592. s/^-no-(?!integrated-as)/no-/;
  593. # rewrite some options in "enable-..." form
  594. s /^-?-?shared$/enable-shared/;
  595. s /^sctp$/enable-sctp/;
  596. s /^threads$/enable-threads/;
  597. s /^zlib$/enable-zlib/;
  598. s /^zlib-dynamic$/enable-zlib-dynamic/;
  599. if (/^(no|disable|enable)-(.+)$/)
  600. {
  601. my $word = $2;
  602. if (!exists $deprecated_disablables{$word}
  603. && !grep { $word =~ /^${_}$/ } @disablables)
  604. {
  605. $unsupported_options{$_} = 1;
  606. next;
  607. }
  608. }
  609. if (/^no-(.+)$/ || /^disable-(.+)$/)
  610. {
  611. foreach my $proto ((@tls, @dtls))
  612. {
  613. if ($1 eq "$proto-method")
  614. {
  615. $disabled{"$proto"} = "option($proto-method)";
  616. last;
  617. }
  618. }
  619. if ($1 eq "dtls")
  620. {
  621. foreach my $proto (@dtls)
  622. {
  623. $disabled{$proto} = "option(dtls)";
  624. }
  625. $disabled{"dtls"} = "option(dtls)";
  626. }
  627. elsif ($1 eq "ssl")
  628. {
  629. # Last one of its kind
  630. $disabled{"ssl3"} = "option(ssl)";
  631. }
  632. elsif ($1 eq "tls")
  633. {
  634. # XXX: Tests will fail if all SSL/TLS
  635. # protocols are disabled.
  636. foreach my $proto (@tls)
  637. {
  638. $disabled{$proto} = "option(tls)";
  639. }
  640. }
  641. elsif ($1 eq "static-engine")
  642. {
  643. delete $disabled{"dynamic-engine"};
  644. }
  645. elsif ($1 eq "dynamic-engine")
  646. {
  647. $disabled{"dynamic-engine"} = "option";
  648. }
  649. elsif (exists $deprecated_disablables{$1})
  650. {
  651. $deprecated_options{$_} = 1;
  652. if (defined $deprecated_disablables{$1})
  653. {
  654. $disabled{$deprecated_disablables{$1}} = "option";
  655. }
  656. }
  657. else
  658. {
  659. $disabled{$1} = "option";
  660. }
  661. # No longer an automatic choice
  662. $auto_threads = 0 if ($1 eq "threads");
  663. }
  664. elsif (/^enable-(.+)$/)
  665. {
  666. if ($1 eq "static-engine")
  667. {
  668. $disabled{"dynamic-engine"} = "option";
  669. }
  670. elsif ($1 eq "dynamic-engine")
  671. {
  672. delete $disabled{"dynamic-engine"};
  673. }
  674. elsif ($1 eq "zlib-dynamic")
  675. {
  676. delete $disabled{"zlib"};
  677. }
  678. my $algo = $1;
  679. delete $disabled{$algo};
  680. # No longer an automatic choice
  681. $auto_threads = 0 if ($1 eq "threads");
  682. }
  683. elsif (/^--strict-warnings$/)
  684. {
  685. $strict_warnings = 1;
  686. }
  687. elsif (/^--debug$/)
  688. {
  689. $config{build_type} = "debug";
  690. }
  691. elsif (/^--release$/)
  692. {
  693. $config{build_type} = "release";
  694. }
  695. elsif (/^386$/)
  696. { $config{processor}=386; }
  697. elsif (/^fips$/)
  698. {
  699. die "FIPS mode not supported\n";
  700. }
  701. elsif (/^rsaref$/)
  702. {
  703. # No RSAref support any more since it's not needed.
  704. # The check for the option is there so scripts aren't
  705. # broken
  706. }
  707. elsif (/^nofipscanistercheck$/)
  708. {
  709. die "FIPS mode not supported\n";
  710. }
  711. elsif (/^[-+]/)
  712. {
  713. if (/^--prefix=(.*)$/)
  714. {
  715. $config{prefix}=$1;
  716. die "Directory given with --prefix MUST be absolute\n"
  717. unless file_name_is_absolute($config{prefix});
  718. }
  719. elsif (/^--api=(.*)$/)
  720. {
  721. $config{api}=$1;
  722. }
  723. elsif (/^--libdir=(.*)$/)
  724. {
  725. $config{libdir}=$1;
  726. }
  727. elsif (/^--openssldir=(.*)$/)
  728. {
  729. $config{openssldir}=$1;
  730. }
  731. elsif (/^--with-zlib-lib=(.*)$/)
  732. {
  733. $withargs{zlib_lib}=$1;
  734. }
  735. elsif (/^--with-zlib-include=(.*)$/)
  736. {
  737. $withargs{zlib_include}=$1;
  738. }
  739. elsif (/^--with-fuzzer-lib=(.*)$/)
  740. {
  741. $withargs{fuzzer_lib}=$1;
  742. }
  743. elsif (/^--with-fuzzer-include=(.*)$/)
  744. {
  745. $withargs{fuzzer_include}=$1;
  746. }
  747. elsif (/^--with-rand-seed=(.*)$/)
  748. {
  749. foreach my $x (split(m|,|, $1))
  750. {
  751. die "Unknown --with-rand-seed choice $x\n"
  752. if ! grep { $x eq $_ } @known_seed_sources;
  753. push @seed_sources, $x;
  754. }
  755. }
  756. elsif (/^--cross-compile-prefix=(.*)$/)
  757. {
  758. $user{CROSS_COMPILE}=$1;
  759. }
  760. elsif (/^--config=(.*)$/)
  761. {
  762. read_config $1;
  763. }
  764. elsif (/^-l(.*)$/)
  765. {
  766. push @{$useradd{LDLIBS}}, $_;
  767. }
  768. elsif (/^-framework$/)
  769. {
  770. push @{$useradd{LDLIBS}}, $_, shift(@argvcopy);
  771. }
  772. elsif (/^-L(.*)$/ or /^-Wl,/)
  773. {
  774. push @{$useradd{LDFLAGS}}, $_;
  775. }
  776. elsif (/^-rpath$/ or /^-R$/)
  777. # -rpath is the OSF1 rpath flag
  778. # -R is the old Solaris rpath flag
  779. {
  780. my $rpath = shift(@argvcopy) || "";
  781. $rpath .= " " if $rpath ne "";
  782. push @{$useradd{LDFLAGS}}, $_, $rpath;
  783. }
  784. elsif (/^-static$/)
  785. {
  786. push @{$useradd{LDFLAGS}}, $_;
  787. $disabled{"dso"} = "forced";
  788. $disabled{"pic"} = "forced";
  789. $disabled{"shared"} = "forced";
  790. $disabled{"threads"} = "forced";
  791. }
  792. elsif (/^-D(.*)$/)
  793. {
  794. push @{$useradd{CPPDEFINES}}, $1;
  795. }
  796. elsif (/^-I(.*)$/)
  797. {
  798. push @{$useradd{CPPINCLUDES}}, $1;
  799. }
  800. elsif (/^-Wp,$/)
  801. {
  802. push @{$useradd{CPPFLAGS}}, $1;
  803. }
  804. else # common if (/^[-+]/), just pass down...
  805. {
  806. $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
  807. push @{$useradd{CFLAGS}}, $_;
  808. push @{$useradd{CXXFLAGS}}, $_;
  809. }
  810. }
  811. else
  812. {
  813. die "target already defined - $target (offending arg: $_)\n" if ($target ne "");
  814. $target=$_;
  815. }
  816. unless ($_ eq $target || /^no-/ || /^disable-/)
  817. {
  818. # "no-..." follows later after implied deactivations
  819. # have been derived. (Don't take this too seriously,
  820. # we really only write OPTIONS to the Makefile out of
  821. # nostalgia.)
  822. if ($config{options} eq "")
  823. { $config{options} = $_; }
  824. else
  825. { $config{options} .= " ".$_; }
  826. }
  827. }
  828. if (defined($config{api}) && !exists $apitable->{$config{api}}) {
  829. die "***** Unsupported api compatibility level: $config{api}\n",
  830. }
  831. if (keys %deprecated_options)
  832. {
  833. warn "***** Deprecated options: ",
  834. join(", ", keys %deprecated_options), "\n";
  835. }
  836. if (keys %unsupported_options)
  837. {
  838. die "***** Unsupported options: ",
  839. join(", ", keys %unsupported_options), "\n";
  840. }
  841. # If any %useradd entry has been set, we must check that the "make
  842. # variables" haven't been set. We start by checking of any %useradd entry
  843. # is set.
  844. if (grep { scalar @$_ > 0 } values %useradd) {
  845. # Hash of env / make variables names. The possible values are:
  846. # 1 - "make vars"
  847. # 2 - %useradd entry set
  848. # 3 - both set
  849. my %detected_vars =
  850. map { my $v = 0;
  851. $v += 1 if $cmdvars{$_};
  852. $v += 2 if @{$useradd{$_}};
  853. $_ => $v }
  854. keys %useradd;
  855. # If any of the corresponding "make variables" is set, we error
  856. if (grep { $_ & 1 } values %detected_vars) {
  857. my $names = join(', ', grep { $detected_vars{$_} > 0 }
  858. sort keys %detected_vars);
  859. die <<"_____";
  860. ***** Mixing make variables and additional compiler/linker flags as
  861. ***** configure command line option is not permitted.
  862. ***** Affected make variables: $names
  863. _____
  864. }
  865. }
  866. # Check through all supported command line variables to see if any of them
  867. # were set, and canonicalise the values we got. If no compiler or linker
  868. # flag or anything else that affects %useradd was set, we also check the
  869. # environment for values.
  870. my $anyuseradd =
  871. grep { defined $_ && (ref $_ ne 'ARRAY' || @$_) } values %useradd;
  872. foreach (keys %user) {
  873. my $value = $cmdvars{$_};
  874. $value //= env($_) unless $anyuseradd;
  875. $value //=
  876. defined $user_synonyms{$_} ? $cmdvars{$user_synonyms{$_}} : undef;
  877. $value //= defined $user_synonyms{$_} ? env($user_synonyms{$_}) : undef
  878. unless $anyuseradd;
  879. if (defined $value) {
  880. if (ref $user{$_} eq 'ARRAY') {
  881. $user{$_} = [ split /$list_separator_re/, $value ];
  882. } elsif (!defined $user{$_}) {
  883. $user{$_} = $value;
  884. }
  885. }
  886. }
  887. if (grep { /-rpath\b/ } ($user{LDFLAGS} ? @{$user{LDFLAGS}} : ())
  888. && !$disabled{shared}
  889. && !($disabled{asan} && $disabled{msan} && $disabled{ubsan})) {
  890. die "***** Cannot simultaneously use -rpath, shared libraries, and\n",
  891. "***** any of asan, msan or ubsan\n";
  892. }
  893. my @tocheckfor = (keys %disabled);
  894. while (@tocheckfor) {
  895. my %new_tocheckfor = ();
  896. my @cascade_copy = (@disable_cascades);
  897. while (@cascade_copy) {
  898. my ($test, $descendents) = (shift @cascade_copy, shift @cascade_copy);
  899. if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) {
  900. foreach(grep { !defined($disabled{$_}) } @$descendents) {
  901. $new_tocheckfor{$_} = 1; $disabled{$_} = "forced";
  902. }
  903. }
  904. }
  905. @tocheckfor = (keys %new_tocheckfor);
  906. }
  907. our $die = sub { die @_; };
  908. if ($target eq "TABLE") {
  909. local $die = sub { warn @_; };
  910. foreach (sort keys %table) {
  911. print_table_entry($_, "TABLE");
  912. }
  913. exit 0;
  914. }
  915. if ($target eq "LIST") {
  916. foreach (sort keys %table) {
  917. print $_,"\n" unless $table{$_}->{template};
  918. }
  919. exit 0;
  920. }
  921. if ($target eq "HASH") {
  922. local $die = sub { warn @_; };
  923. print "%table = (\n";
  924. foreach (sort keys %table) {
  925. print_table_entry($_, "HASH");
  926. }
  927. exit 0;
  928. }
  929. print "Configuring OpenSSL version $config{full_version} ";
  930. print "for target $target\n";
  931. if (scalar(@seed_sources) == 0) {
  932. print "Using os-specific seed configuration\n";
  933. push @seed_sources, 'os';
  934. }
  935. if (scalar(grep { $_ eq 'none' } @seed_sources) > 0) {
  936. die "Cannot seed with none and anything else" if scalar(@seed_sources) > 1;
  937. warn <<_____ if scalar(@seed_sources) == 1;
  938. ============================== WARNING ===============================
  939. You have selected the --with-rand-seed=none option, which effectively
  940. disables automatic reseeding of the OpenSSL random generator.
  941. All operations depending on the random generator such as creating keys
  942. will not work unless the random generator is seeded manually by the
  943. application.
  944. Please read the 'Note on random number generation' section in the
  945. INSTALL instructions and the RAND_DRBG(7) manual page for more details.
  946. ============================== WARNING ===============================
  947. _____
  948. }
  949. push @{$config{openssl_feature_defines}},
  950. map { (my $x = $_) =~ tr|[\-a-z]|[_A-Z]|; "OPENSSL_RAND_SEED_$x" }
  951. @seed_sources;
  952. # Backward compatibility?
  953. if ($target =~ m/^CygWin32(-.*)$/) {
  954. $target = "Cygwin".$1;
  955. }
  956. # Support for legacy targets having a name starting with 'debug-'
  957. my ($d, $t) = $target =~ m/^(debug-)?(.*)$/;
  958. if ($d) {
  959. $config{build_type} = "debug";
  960. # If we do not find debug-foo in the table, the target is set to foo.
  961. if (!$table{$target}) {
  962. $target = $t;
  963. }
  964. }
  965. &usage if !$table{$target} || $table{$target}->{template};
  966. $config{target} = $target;
  967. my %target = resolve_config($target);
  968. foreach (keys %target_attr_translate) {
  969. $target{$target_attr_translate{$_}} = $target{$_}
  970. if $target{$_};
  971. delete $target{$_};
  972. }
  973. %target = ( %{$table{DEFAULTS}}, %target );
  974. # Make the flags to build DSOs the same as for shared libraries unless they
  975. # are already defined
  976. $target{module_cflags} = $target{shared_cflag} unless defined $target{module_cflags};
  977. $target{module_cxxflags} = $target{shared_cxxflag} unless defined $target{module_cxxflags};
  978. $target{module_ldflags} = $target{shared_ldflag} unless defined $target{module_ldflags};
  979. {
  980. my $shared_info_pl =
  981. catfile(dirname($0), "Configurations", "shared-info.pl");
  982. my %shared_info = read_eval_file($shared_info_pl);
  983. push @{$target{_conf_fname_int}}, $shared_info_pl;
  984. my $si = $target{shared_target};
  985. while (ref $si ne "HASH") {
  986. last if ! defined $si;
  987. if (ref $si eq "CODE") {
  988. $si = $si->();
  989. } else {
  990. $si = $shared_info{$si};
  991. }
  992. }
  993. # Some of the 'shared_target' values don't have any entried in
  994. # %shared_info. That's perfectly fine, AS LONG AS the build file
  995. # template knows how to handle this. That is currently the case for
  996. # Windows and VMS.
  997. if (defined $si) {
  998. # Just as above, copy certain shared_* attributes to the corresponding
  999. # module_ attribute unless the latter is already defined
  1000. $si->{module_cflags} = $si->{shared_cflag} unless defined $si->{module_cflags};
  1001. $si->{module_cxxflags} = $si->{shared_cxxflag} unless defined $si->{module_cxxflags};
  1002. $si->{module_ldflags} = $si->{shared_ldflag} unless defined $si->{module_ldflags};
  1003. foreach (sort keys %$si) {
  1004. $target{$_} = defined $target{$_}
  1005. ? add($si->{$_})->($target{$_})
  1006. : $si->{$_};
  1007. }
  1008. }
  1009. }
  1010. my %conf_files = map { $_ => 1 } (@{$target{_conf_fname_int}});
  1011. $config{conf_files} = [ sort keys %conf_files ];
  1012. foreach my $feature (@{$target{disable}}) {
  1013. if (exists $deprecated_disablables{$feature}) {
  1014. warn "***** config $target disables deprecated feature $feature\n";
  1015. } elsif (!grep { $feature eq $_ } @disablables) {
  1016. die "***** config $target disables unknown feature $feature\n";
  1017. }
  1018. $disabled{$feature} = 'config';
  1019. }
  1020. foreach my $feature (@{$target{enable}}) {
  1021. if ("default" eq ($disabled{$feature} // "")) {
  1022. if (exists $deprecated_disablables{$feature}) {
  1023. warn "***** config $target enables deprecated feature $feature\n";
  1024. } elsif (!grep { $feature eq $_ } @disablables) {
  1025. die "***** config $target enables unknown feature $feature\n";
  1026. }
  1027. delete $disabled{$feature};
  1028. }
  1029. }
  1030. $target{CXXFLAGS}//=$target{CFLAGS} if $target{CXX};
  1031. $target{cxxflags}//=$target{cflags} if $target{CXX};
  1032. $target{exe_extension}=".exe" if ($config{target} eq "DJGPP");
  1033. $target{exe_extension}=".pm" if ($config{target} =~ /vos/);
  1034. # Fill %config with values from %user, and in case those are undefined or
  1035. # empty, use values from %target (acting as a default).
  1036. foreach (keys %user) {
  1037. my $ref_type = ref $user{$_};
  1038. # Temporary function. Takes an intended ref type (empty string or "ARRAY")
  1039. # and a value that's to be coerced into that type.
  1040. my $mkvalue = sub {
  1041. my $type = shift;
  1042. my $value = shift;
  1043. my $undef_p = shift;
  1044. die "Too many arguments for \$mkvalue" if @_;
  1045. while (ref $value eq 'CODE') {
  1046. $value = $value->();
  1047. }
  1048. if ($type eq 'ARRAY') {
  1049. return undef unless defined $value;
  1050. return undef if ref $value ne 'ARRAY' && !$value;
  1051. return undef if ref $value eq 'ARRAY' && !@$value;
  1052. return [ $value ] unless ref $value eq 'ARRAY';
  1053. }
  1054. return undef unless $value;
  1055. return $value;
  1056. };
  1057. $config{$_} =
  1058. $mkvalue->($ref_type, $user{$_})
  1059. || $mkvalue->($ref_type, $target{$_});
  1060. delete $config{$_} unless defined $config{$_};
  1061. }
  1062. # Allow overriding the build file name
  1063. $config{build_file} = env('BUILDFILE') || $target{build_file} || "Makefile";
  1064. ######################################################################
  1065. # Build up information for skipping certain directories depending on disabled
  1066. # features, as well as setting up macros for disabled features.
  1067. # This is a tentative database of directories to skip. Some entries may not
  1068. # correspond to anything real, but that's ok, they will simply be ignored.
  1069. # The actual processing of these entries is done in the build.info lookup
  1070. # loop further down.
  1071. #
  1072. # The key is a Unix formated path in the source tree, the value is an index
  1073. # into %disabled_info, so any existing path gets added to a corresponding
  1074. # 'skipped' entry in there with the list of skipped directories.
  1075. my %skipdir = ();
  1076. my %disabled_info = (); # For configdata.pm
  1077. foreach my $what (sort keys %disabled) {
  1078. $config{options} .= " no-$what";
  1079. if (!grep { $what eq $_ } ( 'dso', 'threads', 'shared', 'pic',
  1080. 'dynamic-engine', 'makedepend',
  1081. 'zlib-dynamic', 'zlib', 'sse2' )) {
  1082. (my $WHAT = uc $what) =~ s|-|_|g;
  1083. my $skipdir = $what;
  1084. # fix-up crypto/directory name(s)
  1085. $skipdir = "ripemd" if $what eq "rmd160";
  1086. $skipdir = "whrlpool" if $what eq "whirlpool";
  1087. my $macro = $disabled_info{$what}->{macro} = "OPENSSL_NO_$WHAT";
  1088. push @{$config{openssl_feature_defines}}, $macro;
  1089. $skipdir{engines} = $what if $what eq 'engine';
  1090. $skipdir{"crypto/$skipdir"} = $what
  1091. unless $what eq 'async' || $what eq 'err';
  1092. }
  1093. }
  1094. # Make sure build_scheme is consistent.
  1095. $target{build_scheme} = [ $target{build_scheme} ]
  1096. if ref($target{build_scheme}) ne "ARRAY";
  1097. my ($builder, $builder_platform, @builder_opts) =
  1098. @{$target{build_scheme}};
  1099. foreach my $checker (($builder_platform."-".$target{build_file}."-checker.pm",
  1100. $builder_platform."-checker.pm")) {
  1101. my $checker_path = catfile($srcdir, "Configurations", $checker);
  1102. if (-f $checker_path) {
  1103. my $fn = $ENV{CONFIGURE_CHECKER_WARN}
  1104. ? sub { warn $@; } : sub { die $@; };
  1105. if (! do $checker_path) {
  1106. if ($@) {
  1107. $fn->($@);
  1108. } elsif ($!) {
  1109. $fn->($!);
  1110. } else {
  1111. $fn->("The detected tools didn't match the platform\n");
  1112. }
  1113. }
  1114. last;
  1115. }
  1116. }
  1117. push @{$config{defines}}, "NDEBUG" if $config{build_type} eq "release";
  1118. if ($target =~ /^mingw/ && `$config{CC} --target-help 2>&1` =~ m/-mno-cygwin/m)
  1119. {
  1120. push @{$config{cflags}}, "-mno-cygwin";
  1121. push @{$config{cxxflags}}, "-mno-cygwin" if $config{CXX};
  1122. push @{$config{shared_ldflag}}, "-mno-cygwin";
  1123. }
  1124. if ($target =~ /linux.*-mips/ && !$disabled{asm}
  1125. && !grep { $_ !~ /-m(ips|arch=)/ } (@{$user{CFLAGS}},
  1126. @{$useradd{CFLAGS}})) {
  1127. # minimally required architecture flags for assembly modules
  1128. my $value;
  1129. $value = '-mips2' if ($target =~ /mips32/);
  1130. $value = '-mips3' if ($target =~ /mips64/);
  1131. unshift @{$config{cflags}}, $value;
  1132. unshift @{$config{cxxflags}}, $value if $config{CXX};
  1133. }
  1134. # If threads aren't disabled, check how possible they are
  1135. unless ($disabled{threads}) {
  1136. if ($auto_threads) {
  1137. # Enabled by default, disable it forcibly if unavailable
  1138. if ($target{thread_scheme} eq "(unknown)") {
  1139. $disabled{threads} = "unavailable";
  1140. }
  1141. } else {
  1142. # The user chose to enable threads explicitly, let's see
  1143. # if there's a chance that's possible
  1144. if ($target{thread_scheme} eq "(unknown)") {
  1145. # If the user asked for "threads" and we don't have internal
  1146. # knowledge how to do it, [s]he is expected to provide any
  1147. # system-dependent compiler options that are necessary. We
  1148. # can't truly check that the given options are correct, but
  1149. # we expect the user to know what [s]He is doing.
  1150. if (!@{$user{CFLAGS}} && !@{$useradd{CFLAGS}}
  1151. && !@{$user{CPPDEFINES}} && !@{$useradd{CPPDEFINES}}) {
  1152. die "You asked for multi-threading support, but didn't\n"
  1153. ,"provide any system-specific compiler options\n";
  1154. }
  1155. }
  1156. }
  1157. }
  1158. # If threads still aren't disabled, add a C macro to ensure the source
  1159. # code knows about it. Any other flag is taken care of by the configs.
  1160. unless($disabled{threads}) {
  1161. push @{$config{openssl_feature_defines}}, "OPENSSL_THREADS";
  1162. }
  1163. # With "deprecated" disable all deprecated features.
  1164. if (defined($disabled{"deprecated"})) {
  1165. $config{api} = $maxapi;
  1166. }
  1167. my $no_shared_warn=0;
  1168. if ($target{shared_target} eq "")
  1169. {
  1170. $no_shared_warn = 1
  1171. if (!$disabled{shared} || !$disabled{"dynamic-engine"});
  1172. $disabled{shared} = "no-shared-target";
  1173. $disabled{pic} = $disabled{shared} = $disabled{"dynamic-engine"} =
  1174. "no-shared-target";
  1175. }
  1176. if ($disabled{"dynamic-engine"}) {
  1177. push @{$config{openssl_feature_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE";
  1178. $config{dynamic_engines} = 0;
  1179. } else {
  1180. push @{$config{openssl_feature_defines}}, "OPENSSL_NO_STATIC_ENGINE";
  1181. $config{dynamic_engines} = 1;
  1182. }
  1183. unless ($disabled{asan}) {
  1184. push @{$config{cflags}}, "-fsanitize=address";
  1185. push @{$config{cxxflags}}, "-fsanitize=address" if $config{CXX};
  1186. }
  1187. unless ($disabled{ubsan}) {
  1188. # -DPEDANTIC or -fnosanitize=alignment may also be required on some
  1189. # platforms.
  1190. push @{$config{cflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all";
  1191. push @{$config{cxxflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all"
  1192. if $config{CXX};
  1193. }
  1194. unless ($disabled{msan}) {
  1195. push @{$config{cflags}}, "-fsanitize=memory";
  1196. push @{$config{cxxflags}}, "-fsanitize=memory" if $config{CXX};
  1197. }
  1198. unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
  1199. && $disabled{asan} && $disabled{ubsan} && $disabled{msan}) {
  1200. push @{$config{cflags}}, "-fno-omit-frame-pointer", "-g";
  1201. push @{$config{cxxflags}}, "-fno-omit-frame-pointer", "-g" if $config{CXX};
  1202. }
  1203. #
  1204. # Platform fix-ups
  1205. #
  1206. # This saves the build files from having to check
  1207. if ($disabled{pic})
  1208. {
  1209. foreach (qw(shared_cflag shared_cxxflag shared_cppflag
  1210. shared_defines shared_includes shared_ldflag
  1211. module_cflags module_cxxflags module_cppflags
  1212. module_defines module_includes module_lflags))
  1213. {
  1214. delete $config{$_};
  1215. $target{$_} = "";
  1216. }
  1217. }
  1218. else
  1219. {
  1220. push @{$config{lib_defines}}, "OPENSSL_PIC";
  1221. }
  1222. if ($target{sys_id} ne "")
  1223. {
  1224. push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}";
  1225. }
  1226. unless ($disabled{asm}) {
  1227. $target{cpuid_asm_src}=$table{DEFAULTS}->{cpuid_asm_src} if ($config{processor} eq "386");
  1228. push @{$config{lib_defines}}, "OPENSSL_CPUID_OBJ" if ($target{cpuid_asm_src} ne "mem_clr.c");
  1229. $target{bn_asm_src} =~ s/\w+-gf2m.c// if (defined($disabled{ec2m}));
  1230. # bn-586 is the only one implementing bn_*_part_words
  1231. push @{$config{lib_defines}}, "OPENSSL_BN_ASM_PART_WORDS" if ($target{bn_asm_src} =~ /bn-586/);
  1232. push @{$config{lib_defines}}, "OPENSSL_IA32_SSE2" if (!$disabled{sse2} && $target{bn_asm_src} =~ /86/);
  1233. push @{$config{lib_defines}}, "OPENSSL_BN_ASM_MONT" if ($target{bn_asm_src} =~ /-mont/);
  1234. push @{$config{lib_defines}}, "OPENSSL_BN_ASM_MONT5" if ($target{bn_asm_src} =~ /-mont5/);
  1235. push @{$config{lib_defines}}, "OPENSSL_BN_ASM_GF2m" if ($target{bn_asm_src} =~ /-gf2m/);
  1236. push @{$config{lib_defines}}, "BN_DIV3W" if ($target{bn_asm_src} =~ /-div3w/);
  1237. if ($target{sha1_asm_src}) {
  1238. push @{$config{lib_defines}}, "SHA1_ASM" if ($target{sha1_asm_src} =~ /sx86/ || $target{sha1_asm_src} =~ /sha1/);
  1239. push @{$config{lib_defines}}, "SHA256_ASM" if ($target{sha1_asm_src} =~ /sha256/);
  1240. push @{$config{lib_defines}}, "SHA512_ASM" if ($target{sha1_asm_src} =~ /sha512/);
  1241. }
  1242. if ($target{keccak1600_asm_src} ne $table{DEFAULTS}->{keccak1600_asm_src}) {
  1243. push @{$config{lib_defines}}, "KECCAK1600_ASM";
  1244. }
  1245. if ($target{rc4_asm_src} ne $table{DEFAULTS}->{rc4_asm_src}) {
  1246. push @{$config{lib_defines}}, "RC4_ASM";
  1247. }
  1248. if ($target{md5_asm_src}) {
  1249. push @{$config{lib_defines}}, "MD5_ASM";
  1250. }
  1251. $target{cast_asm_src}=$table{DEFAULTS}->{cast_asm_src} unless $disabled{pic}; # CAST assembler is not PIC
  1252. if ($target{rmd160_asm_src}) {
  1253. push @{$config{lib_defines}}, "RMD160_ASM";
  1254. }
  1255. if ($target{aes_asm_src}) {
  1256. push @{$config{lib_defines}}, "AES_ASM" if ($target{aes_asm_src} =~ m/\baes-/);;
  1257. # aes-ctr.fake is not a real file, only indication that assembler
  1258. # module implements AES_ctr32_encrypt...
  1259. push @{$config{lib_defines}}, "AES_CTR_ASM" if ($target{aes_asm_src} =~ s/\s*aes-ctr\.fake//);
  1260. # aes-xts.fake indicates presence of AES_xts_[en|de]crypt...
  1261. push @{$config{lib_defines}}, "AES_XTS_ASM" if ($target{aes_asm_src} =~ s/\s*aes-xts\.fake//);
  1262. $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($disabled{sse2});
  1263. push @{$config{lib_defines}}, "VPAES_ASM" if ($target{aes_asm_src} =~ m/vpaes/);
  1264. push @{$config{lib_defines}}, "BSAES_ASM" if ($target{aes_asm_src} =~ m/bsaes/);
  1265. }
  1266. if ($target{wp_asm_src} =~ /mmx/) {
  1267. if ($config{processor} eq "386") {
  1268. $target{wp_asm_src}=$table{DEFAULTS}->{wp_asm_src};
  1269. } elsif (!$disabled{"whirlpool"}) {
  1270. push @{$config{lib_defines}}, "WHIRLPOOL_ASM";
  1271. }
  1272. }
  1273. if ($target{modes_asm_src} =~ /ghash-/) {
  1274. push @{$config{lib_defines}}, "GHASH_ASM";
  1275. }
  1276. if ($target{ec_asm_src} =~ /ecp_nistz256/) {
  1277. push @{$config{lib_defines}}, "ECP_NISTZ256_ASM";
  1278. }
  1279. if ($target{ec_asm_src} =~ /x25519/) {
  1280. push @{$config{lib_defines}}, "X25519_ASM";
  1281. }
  1282. if ($target{padlock_asm_src} ne $table{DEFAULTS}->{padlock_asm_src}) {
  1283. push @{$config{lib_defines}}, "PADLOCK_ASM";
  1284. }
  1285. if ($target{poly1305_asm_src} ne "") {
  1286. push @{$config{lib_defines}}, "POLY1305_ASM";
  1287. }
  1288. }
  1289. my %predefined = compiler_predefined($config{CROSS_COMPILE}.$config{CC});
  1290. # Check for makedepend capabilities.
  1291. if (!$disabled{makedepend}) {
  1292. if ($config{target} =~ /^(VC|vms)-/) {
  1293. # For VC- and vms- targets, there's nothing more to do here. The
  1294. # functionality is hard coded in the corresponding build files for
  1295. # cl (Windows) and CC/DECC (VMS).
  1296. } elsif (($predefined{__GNUC__} // -1) >= 3
  1297. && !($predefined{__APPLE_CC__} && !$predefined{__clang__})) {
  1298. # We know that GNU C version 3 and up as well as all clang
  1299. # versions support dependency generation, but Xcode did not
  1300. # handle $cc -M before clang support (but claims __GNUC__ = 3)
  1301. $config{makedepprog} = "\$(CROSS_COMPILE)$config{CC}";
  1302. } else {
  1303. # In all other cases, we look for 'makedepend', and disable the
  1304. # capability if not found.
  1305. $config{makedepprog} = which('makedepend');
  1306. $disabled{makedepend} = "unavailable" unless $config{makedepprog};
  1307. }
  1308. }
  1309. if (!$disabled{asm} && !$predefined{__MACH__} && $^O ne 'VMS') {
  1310. # probe for -Wa,--noexecstack option...
  1311. if ($predefined{__clang__}) {
  1312. # clang has builtin assembler, which doesn't recognize --help,
  1313. # but it apparently recognizes the option in question on all
  1314. # supported platforms even when it's meaningless. In other words
  1315. # probe would fail, but probed option always accepted...
  1316. push @{$config{cflags}}, "-Wa,--noexecstack", "-Qunused-arguments";
  1317. } else {
  1318. my $cc = $config{CROSS_COMPILE}.$config{CC};
  1319. open(PIPE, "$cc -Wa,--help -c -o null.$$.o -x assembler /dev/null 2>&1 |");
  1320. while(<PIPE>) {
  1321. if (m/--noexecstack/) {
  1322. push @{$config{cflags}}, "-Wa,--noexecstack";
  1323. last;
  1324. }
  1325. }
  1326. close(PIPE);
  1327. unlink("null.$$.o");
  1328. }
  1329. }
  1330. # Deal with bn_ops ###################################################
  1331. $config{bn_ll} =0;
  1332. $config{export_var_as_fn} =0;
  1333. my $def_int="unsigned int";
  1334. $config{rc4_int} =$def_int;
  1335. ($config{b64l},$config{b64},$config{b32})=(0,0,1);
  1336. my $count = 0;
  1337. foreach (sort split(/\s+/,$target{bn_ops})) {
  1338. $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/;
  1339. $config{export_var_as_fn}=1 if $_ eq 'EXPORT_VAR_AS_FN';
  1340. $config{bn_ll}=1 if $_ eq 'BN_LLONG';
  1341. $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR';
  1342. ($config{b64l},$config{b64},$config{b32})
  1343. =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT';
  1344. ($config{b64l},$config{b64},$config{b32})
  1345. =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG';
  1346. ($config{b64l},$config{b64},$config{b32})
  1347. =(0,0,1) if $_ eq 'THIRTY_TWO_BIT';
  1348. }
  1349. die "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n"
  1350. if $count > 1;
  1351. # Hack cflags for better warnings (dev option) #######################
  1352. # "Stringify" the C and C++ flags string. This permits it to be made part of
  1353. # a string and works as well on command lines.
  1354. $config{cflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x }
  1355. @{$config{cflags}} ];
  1356. $config{cxxflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x }
  1357. @{$config{cxxflags}} ] if $config{CXX};
  1358. $config{openssl_api_defines} = [
  1359. "OPENSSL_MIN_API=".($apitable->{$config{api} // ""} // -1)
  1360. ];
  1361. if ($strict_warnings)
  1362. {
  1363. my $wopt;
  1364. my $gccver = $predefined{__GNUC__} // -1;
  1365. die "ERROR --strict-warnings requires gcc[>=4] or gcc-alike"
  1366. unless $gccver >= 4;
  1367. foreach $wopt (split /\s+/, $gcc_devteam_warn)
  1368. {
  1369. push @{$config{cflags}}, $wopt
  1370. unless grep { $_ eq $wopt } @{$config{cflags}};
  1371. push @{$config{cxxflags}}, $wopt
  1372. if ($config{CXX}
  1373. && !grep { $_ eq $wopt } @{$config{cxxflags}});
  1374. }
  1375. if (defined($predefined{__clang__}))
  1376. {
  1377. foreach $wopt (split /\s+/, $clang_devteam_warn)
  1378. {
  1379. push @{$config{cflags}}, $wopt
  1380. unless grep { $_ eq $wopt } @{$config{cflags}};
  1381. push @{$config{cxxflags}}, $wopt
  1382. if ($config{CXX}
  1383. && !grep { $_ eq $wopt } @{$config{cxxflags}});
  1384. }
  1385. }
  1386. }
  1387. unless ($disabled{"crypto-mdebug-backtrace"})
  1388. {
  1389. foreach my $wopt (split /\s+/, $memleak_devteam_backtrace)
  1390. {
  1391. push @{$config{cflags}}, $wopt
  1392. unless grep { $_ eq $wopt } @{$config{cflags}};
  1393. push @{$config{cxxflags}}, $wopt
  1394. if ($config{CXX}
  1395. && !grep { $_ eq $wopt } @{$config{cxxflags}});
  1396. }
  1397. if ($target =~ /^BSD-/)
  1398. {
  1399. push @{$config{ex_libs}}, "-lexecinfo";
  1400. }
  1401. }
  1402. unless ($disabled{afalgeng}) {
  1403. $config{afalgeng}="";
  1404. if (grep { $_ eq 'afalgeng' } @{$target{enable}}) {
  1405. my $minver = 4*10000 + 1*100 + 0;
  1406. if ($config{CROSS_COMPILE} eq "") {
  1407. my $verstr = `uname -r`;
  1408. my ($ma, $mi1, $mi2) = split("\\.", $verstr);
  1409. ($mi2) = $mi2 =~ /(\d+)/;
  1410. my $ver = $ma*10000 + $mi1*100 + $mi2;
  1411. if ($ver < $minver) {
  1412. $disabled{afalgeng} = "too-old-kernel";
  1413. } else {
  1414. push @{$config{engdirs}}, "afalg";
  1415. }
  1416. } else {
  1417. $disabled{afalgeng} = "cross-compiling";
  1418. }
  1419. } else {
  1420. $disabled{afalgeng} = "not-linux";
  1421. }
  1422. }
  1423. push @{$config{openssl_feature_defines}}, "OPENSSL_NO_AFALGENG" if ($disabled{afalgeng});
  1424. unless ($disabled{ktls}) {
  1425. $config{ktls}="";
  1426. if ($target =~ m/^linux/) {
  1427. my $usr = "/usr/$config{cross_compile_prefix}";
  1428. chop($usr);
  1429. if ($config{cross_compile_prefix} eq "") {
  1430. $usr = "/usr";
  1431. }
  1432. my $minver = (4 << 16) + (13 << 8) + 0;
  1433. my @verstr = split(" ",`cat $usr/include/linux/version.h | grep LINUX_VERSION_CODE`);
  1434. if ($verstr[2] < $minver) {
  1435. $disabled{ktls} = "too-old-kernel";
  1436. }
  1437. } else {
  1438. $disabled{ktls} = "not-linux";
  1439. }
  1440. }
  1441. push @{$config{openssl_other_defines}}, "OPENSSL_NO_KTLS" if ($disabled{ktls});
  1442. # Finish up %config by appending things the user gave us on the command line
  1443. # apart from "make variables"
  1444. foreach (keys %useradd) {
  1445. # The must all be lists, so we assert that here
  1446. die "internal error: \$useradd{$_} isn't an ARRAY\n"
  1447. unless ref $useradd{$_} eq 'ARRAY';
  1448. if (defined $config{$_}) {
  1449. push @{$config{$_}}, @{$useradd{$_}};
  1450. } else {
  1451. $config{$_} = [ @{$useradd{$_}} ];
  1452. }
  1453. }
  1454. # ALL MODIFICATIONS TO %config and %target MUST BE DONE FROM HERE ON
  1455. # If we use the unified build, collect information from build.info files
  1456. my %unified_info = ();
  1457. my $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO});
  1458. if ($builder eq "unified") {
  1459. use with_fallback qw(Text::Template);
  1460. sub cleandir {
  1461. my $base = shift;
  1462. my $dir = shift;
  1463. my $relativeto = shift || ".";
  1464. $dir = catdir($base,$dir) unless isabsolute($dir);
  1465. # Make sure the directories we're building in exists
  1466. mkpath($dir);
  1467. my $res = abs2rel(absolutedir($dir), rel2abs($relativeto));
  1468. #print STDERR "DEBUG[cleandir]: $dir , $base => $res\n";
  1469. return $res;
  1470. }
  1471. sub cleanfile {
  1472. my $base = shift;
  1473. my $file = shift;
  1474. my $relativeto = shift || ".";
  1475. $file = catfile($base,$file) unless isabsolute($file);
  1476. my $d = dirname($file);
  1477. my $f = basename($file);
  1478. # Make sure the directories we're building in exists
  1479. mkpath($d);
  1480. my $res = abs2rel(catfile(absolutedir($d), $f), rel2abs($relativeto));
  1481. #print STDERR "DEBUG[cleanfile]: $d , $f => $res\n";
  1482. return $res;
  1483. }
  1484. # Store the name of the template file we will build the build file from
  1485. # in %config. This may be useful for the build file itself.
  1486. my @build_file_template_names =
  1487. ( $builder_platform."-".$target{build_file}.".tmpl",
  1488. $target{build_file}.".tmpl" );
  1489. my @build_file_templates = ();
  1490. # First, look in the user provided directory, if given
  1491. if (defined env($local_config_envname)) {
  1492. @build_file_templates =
  1493. map {
  1494. if ($^O eq 'VMS') {
  1495. # VMS environment variables are logical names,
  1496. # which can be used as is
  1497. $local_config_envname . ':' . $_;
  1498. } else {
  1499. catfile(env($local_config_envname), $_);
  1500. }
  1501. }
  1502. @build_file_template_names;
  1503. }
  1504. # Then, look in our standard directory
  1505. push @build_file_templates,
  1506. ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir) }
  1507. @build_file_template_names );
  1508. my $build_file_template;
  1509. for $_ (@build_file_templates) {
  1510. $build_file_template = $_;
  1511. last if -f $build_file_template;
  1512. $build_file_template = undef;
  1513. }
  1514. if (!defined $build_file_template) {
  1515. die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n";
  1516. }
  1517. $config{build_file_templates}
  1518. = [ cleanfile($srcdir, catfile("Configurations", "common0.tmpl"),
  1519. $blddir),
  1520. $build_file_template,
  1521. cleanfile($srcdir, catfile("Configurations", "common.tmpl"),
  1522. $blddir) ];
  1523. my @build_dirs = ( [ ] ); # current directory
  1524. $config{build_infos} = [ ];
  1525. my %ordinals = ();
  1526. while (@build_dirs) {
  1527. my @curd = @{shift @build_dirs};
  1528. my $sourced = catdir($srcdir, @curd);
  1529. my $buildd = catdir($blddir, @curd);
  1530. my $unixdir = join('/', @curd);
  1531. if (exists $skipdir{$unixdir}) {
  1532. my $what = $skipdir{$unixdir};
  1533. push @{$disabled_info{$what}->{skipped}}, catdir(@curd);
  1534. next;
  1535. }
  1536. mkpath($buildd);
  1537. my $f = 'build.info';
  1538. # The basic things we're trying to build
  1539. my @programs = ();
  1540. my @programs_install = ();
  1541. my @libraries = ();
  1542. my @libraries_install = ();
  1543. my @engines = ();
  1544. my @engines_install = ();
  1545. my @scripts = ();
  1546. my @scripts_install = ();
  1547. my @extra = ();
  1548. my @overrides = ();
  1549. my @intermediates = ();
  1550. my @rawlines = ();
  1551. my %sources = ();
  1552. my %shared_sources = ();
  1553. my %includes = ();
  1554. my %defines = ();
  1555. my %depends = ();
  1556. my %generate = ();
  1557. # We want to detect configdata.pm in the source tree, so we
  1558. # don't use it if the build tree is different.
  1559. my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir);
  1560. push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f);
  1561. my $template =
  1562. Text::Template->new(TYPE => 'FILE',
  1563. SOURCE => catfile($sourced, $f),
  1564. PREPEND => qq{use lib "$FindBin::Bin/util/perl";});
  1565. die "Something went wrong with $sourced/$f: $!\n" unless $template;
  1566. my @text =
  1567. split /^/m,
  1568. $template->fill_in(HASH => { config => \%config,
  1569. target => \%target,
  1570. disabled => \%disabled,
  1571. withargs => \%withargs,
  1572. builddir => abs2rel($buildd, $blddir),
  1573. sourcedir => abs2rel($sourced, $blddir),
  1574. buildtop => abs2rel($blddir, $blddir),
  1575. sourcetop => abs2rel($srcdir, $blddir) },
  1576. DELIMITERS => [ "{-", "-}" ]);
  1577. # The top item of this stack has the following values
  1578. # -2 positive already run and we found ELSE (following ELSIF should fail)
  1579. # -1 positive already run (skip until ENDIF)
  1580. # 0 negatives so far (if we're at a condition, check it)
  1581. # 1 last was positive (don't skip lines until next ELSE, ELSIF or ENDIF)
  1582. # 2 positive ELSE (following ELSIF should fail)
  1583. my @skip = ();
  1584. collect_information(
  1585. collect_from_array([ @text ],
  1586. qr/\\$/ => sub { my $l1 = shift; my $l2 = shift;
  1587. $l1 =~ s/\\$//; $l1.$l2 }),
  1588. # Info we're looking for
  1589. qr/^\s*IF\[((?:\\.|[^\\\]])*)\]\s*$/
  1590. => sub {
  1591. if (! @skip || $skip[$#skip] > 0) {
  1592. push @skip, !! $1;
  1593. } else {
  1594. push @skip, -1;
  1595. }
  1596. },
  1597. qr/^\s*ELSIF\[((?:\\.|[^\\\]])*)\]\s*$/
  1598. => sub { die "ELSIF out of scope" if ! @skip;
  1599. die "ELSIF following ELSE" if abs($skip[$#skip]) == 2;
  1600. $skip[$#skip] = -1 if $skip[$#skip] != 0;
  1601. $skip[$#skip] = !! $1
  1602. if $skip[$#skip] == 0; },
  1603. qr/^\s*ELSE\s*$/
  1604. => sub { die "ELSE out of scope" if ! @skip;
  1605. $skip[$#skip] = -2 if $skip[$#skip] != 0;
  1606. $skip[$#skip] = 2 if $skip[$#skip] == 0; },
  1607. qr/^\s*ENDIF\s*$/
  1608. => sub { die "ENDIF out of scope" if ! @skip;
  1609. pop @skip; },
  1610. qr/^\s*SUBDIRS\s*=\s*(.*)\s*$/
  1611. => sub {
  1612. if (!@skip || $skip[$#skip] > 0) {
  1613. foreach (tokenize($1)) {
  1614. push @build_dirs, [ @curd, splitdir($_, 1) ];
  1615. }
  1616. }
  1617. },
  1618. qr/^\s*PROGRAMS(_NO_INST)?\s*=\s*(.*)\s*$/
  1619. => sub {
  1620. if (!@skip || $skip[$#skip] > 0) {
  1621. my $install = $1;
  1622. my @x = tokenize($2);
  1623. push @programs, @x;
  1624. push @programs_install, @x unless $install;
  1625. }
  1626. },
  1627. qr/^\s*LIBS(_NO_INST)?\s*=\s*(.*)\s*$/
  1628. => sub {
  1629. if (!@skip || $skip[$#skip] > 0) {
  1630. my $install = $1;
  1631. my @x = tokenize($2);
  1632. push @libraries, @x;
  1633. push @libraries_install, @x unless $install;
  1634. }
  1635. },
  1636. qr/^\s*ENGINES(_NO_INST)?\s*=\s*(.*)\s*$/
  1637. => sub {
  1638. if (!@skip || $skip[$#skip] > 0) {
  1639. my $install = $1;
  1640. my @x = tokenize($2);
  1641. push @engines, @x;
  1642. push @engines_install, @x unless $install;
  1643. }
  1644. },
  1645. qr/^\s*SCRIPTS(_NO_INST)?\s*=\s*(.*)\s*$/
  1646. => sub {
  1647. if (!@skip || $skip[$#skip] > 0) {
  1648. my $install = $1;
  1649. my @x = tokenize($2);
  1650. push @scripts, @x;
  1651. push @scripts_install, @x unless $install;
  1652. }
  1653. },
  1654. qr/^\s*EXTRA\s*=\s*(.*)\s*$/
  1655. => sub { push @extra, tokenize($1)
  1656. if !@skip || $skip[$#skip] > 0 },
  1657. qr/^\s*OVERRIDES\s*=\s*(.*)\s*$/
  1658. => sub { push @overrides, tokenize($1)
  1659. if !@skip || $skip[$#skip] > 0 },
  1660. qr/^\s*ORDINALS\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/,
  1661. => sub { push @{$ordinals{$1}}, tokenize($2)
  1662. if !@skip || $skip[$#skip] > 0 },
  1663. qr/^\s*SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1664. => sub { push @{$sources{$1}}, tokenize($2)
  1665. if !@skip || $skip[$#skip] > 0 },
  1666. qr/^\s*SHARED_SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1667. => sub { push @{$shared_sources{$1}}, tokenize($2)
  1668. if !@skip || $skip[$#skip] > 0 },
  1669. qr/^\s*INCLUDE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1670. => sub { push @{$includes{$1}}, tokenize($2)
  1671. if !@skip || $skip[$#skip] > 0 },
  1672. qr/^\s*DEFINE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1673. => sub { push @{$defines{$1}}, tokenize($2)
  1674. if !@skip || $skip[$#skip] > 0 },
  1675. qr/^\s*DEPEND\[((?:\\.|[^\\\]])*)\]\s*=\s*(.*)\s*$/
  1676. => sub { push @{$depends{$1}}, tokenize($2)
  1677. if !@skip || $skip[$#skip] > 0 },
  1678. qr/^\s*GENERATE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1679. => sub { push @{$generate{$1}}, $2
  1680. if !@skip || $skip[$#skip] > 0 },
  1681. qr/^\s*RENAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1682. => sub { warn "RENAME is no longer supported\n" },
  1683. qr/^\s*SHARED_NAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1684. => sub { warn "SHARED_NAME is no longer supported\n" },
  1685. qr/^\s*BEGINRAW\[((?:\\.|[^\\\]])+)\]\s*$/
  1686. => sub {
  1687. my $lineiterator = shift;
  1688. my $target_kind = $1;
  1689. while (defined $lineiterator->()) {
  1690. s|\R$||;
  1691. if (/^\s*ENDRAW\[((?:\\.|[^\\\]])+)\]\s*$/) {
  1692. die "ENDRAW doesn't match BEGINRAW"
  1693. if $1 ne $target_kind;
  1694. last;
  1695. }
  1696. next if @skip && $skip[$#skip] <= 0;
  1697. push @rawlines, $_
  1698. if ($target_kind eq $target{build_file}
  1699. || $target_kind eq $target{build_file}."(".$builder_platform.")");
  1700. }
  1701. },
  1702. qr/^\s*(?:#.*)?$/ => sub { },
  1703. "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" },
  1704. "BEFORE" => sub {
  1705. if ($buildinfo_debug) {
  1706. print STDERR "DEBUG: Parsing ",join(" ", @_),"\n";
  1707. print STDERR "DEBUG: ... before parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1708. }
  1709. },
  1710. "AFTER" => sub {
  1711. if ($buildinfo_debug) {
  1712. print STDERR "DEBUG: .... after parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1713. }
  1714. },
  1715. );
  1716. die "runaway IF?" if (@skip);
  1717. foreach (@programs) {
  1718. my $program = cleanfile($buildd, $_, $blddir);
  1719. $unified_info{programs}->{$program} = 1;
  1720. }
  1721. foreach (@programs_install) {
  1722. my $program = cleanfile($buildd, $_, $blddir);
  1723. $unified_info{install}->{programs}->{$program} = 1;
  1724. }
  1725. foreach (@libraries) {
  1726. my $library = cleanfile($buildd, $_, $blddir);
  1727. $unified_info{libraries}->{$library} = 1;
  1728. }
  1729. foreach (@libraries_install) {
  1730. my $library = cleanfile($buildd, $_, $blddir);
  1731. $unified_info{install}->{libraries}->{$library} = 1;
  1732. }
  1733. die <<"EOF" if scalar @engines and !$config{dynamic_engines};
  1734. ENGINES can only be used if configured with 'dynamic-engine'.
  1735. This is usually a fault in a build.info file.
  1736. EOF
  1737. foreach (@engines) {
  1738. my $library = cleanfile($buildd, $_, $blddir);
  1739. $unified_info{engines}->{$library} = 1;
  1740. }
  1741. foreach (@engines_install) {
  1742. my $library = cleanfile($buildd, $_, $blddir);
  1743. $unified_info{install}->{engines}->{$library} = 1;
  1744. }
  1745. foreach (@scripts) {
  1746. my $script = cleanfile($buildd, $_, $blddir);
  1747. $unified_info{scripts}->{$script} = 1;
  1748. }
  1749. foreach (@scripts_install) {
  1750. my $script = cleanfile($buildd, $_, $blddir);
  1751. $unified_info{install}->{scripts}->{$script} = 1;
  1752. }
  1753. foreach (@extra) {
  1754. my $extra = cleanfile($buildd, $_, $blddir);
  1755. $unified_info{extra}->{$extra} = 1;
  1756. }
  1757. foreach (@overrides) {
  1758. my $override = cleanfile($buildd, $_, $blddir);
  1759. $unified_info{overrides}->{$override} = 1;
  1760. }
  1761. push @{$unified_info{rawlines}}, @rawlines;
  1762. # Check that we haven't defined any library as both shared and
  1763. # explicitly static. That is forbidden.
  1764. my @doubles = ();
  1765. foreach (grep /\.a$/, keys %{$unified_info{libraries}}) {
  1766. (my $l = $_) =~ s/\.a$//;
  1767. push @doubles, $l if defined $unified_info{libraries}->{$l};
  1768. }
  1769. die "these libraries are both explicitly static and shared:\n ",
  1770. join(" ", @doubles), "\n"
  1771. if @doubles;
  1772. foreach (keys %sources) {
  1773. my $dest = $_;
  1774. my $ddest = cleanfile($buildd, $_, $blddir);
  1775. foreach (@{$sources{$dest}}) {
  1776. my $s = cleanfile($sourced, $_, $blddir);
  1777. # If it isn't in the source tree, we assume it's generated
  1778. # in the build tree
  1779. if ($s eq $src_configdata || ! -f $s || $generate{$_}) {
  1780. $s = cleanfile($buildd, $_, $blddir);
  1781. }
  1782. # We recognise C++, C and asm files
  1783. if ($s =~ /\.(cc|cpp|c|s|S)$/) {
  1784. my $o = $_;
  1785. $o =~ s/\.[csS]$/.o/; # C and assembler
  1786. $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
  1787. $o = cleanfile($buildd, $o, $blddir);
  1788. $unified_info{sources}->{$ddest}->{$o} = -1;
  1789. $unified_info{sources}->{$o}->{$s} = -1;
  1790. } elsif ($s =~ /\.rc$/) {
  1791. # We also recognise resource files
  1792. my $o = $_;
  1793. $o =~ s/\.rc$/.res/; # Resource configuration
  1794. my $o = cleanfile($buildd, $o, $blddir);
  1795. $unified_info{sources}->{$ddest}->{$o} = -1;
  1796. $unified_info{sources}->{$o}->{$s} = -1;
  1797. } else {
  1798. $unified_info{sources}->{$ddest}->{$s} = 1;
  1799. }
  1800. }
  1801. }
  1802. foreach (keys %shared_sources) {
  1803. my $dest = $_;
  1804. my $ddest = cleanfile($buildd, $_, $blddir);
  1805. foreach (@{$shared_sources{$dest}}) {
  1806. my $s = cleanfile($sourced, $_, $blddir);
  1807. # If it isn't in the source tree, we assume it's generated
  1808. # in the build tree
  1809. if ($s eq $src_configdata || ! -f $s || $generate{$_}) {
  1810. $s = cleanfile($buildd, $_, $blddir);
  1811. }
  1812. if ($s =~ /\.(cc|cpp|c|s|S)$/) {
  1813. # We recognise C++, C and asm files
  1814. my $o = $_;
  1815. $o =~ s/\.[csS]$/.o/; # C and assembler
  1816. $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
  1817. $o = cleanfile($buildd, $o, $blddir);
  1818. $unified_info{shared_sources}->{$ddest}->{$o} = -1;
  1819. $unified_info{sources}->{$o}->{$s} = -1;
  1820. } elsif ($s =~ /\.rc$/) {
  1821. # We also recognise resource files
  1822. my $o = $_;
  1823. $o =~ s/\.rc$/.res/; # Resource configuration
  1824. my $o = cleanfile($buildd, $o, $blddir);
  1825. $unified_info{shared_sources}->{$ddest}->{$o} = -1;
  1826. $unified_info{sources}->{$o}->{$s} = -1;
  1827. } elsif ($s =~ /\.ld$/) {
  1828. # We also recognise linker scripts (or corresponding)
  1829. # We know they are generated files
  1830. my $ld = cleanfile($buildd, $_, $blddir);
  1831. $unified_info{shared_sources}->{$ddest}->{$ld} = 1;
  1832. } else {
  1833. die "unrecognised source file type for shared library: $s\n";
  1834. }
  1835. }
  1836. }
  1837. foreach (keys %generate) {
  1838. my $dest = $_;
  1839. my $ddest = cleanfile($buildd, $_, $blddir);
  1840. die "more than one generator for $dest: "
  1841. ,join(" ", @{$generate{$_}}),"\n"
  1842. if scalar @{$generate{$_}} > 1;
  1843. my @generator = split /\s+/, $generate{$dest}->[0];
  1844. $generator[0] = cleanfile($sourced, $generator[0], $blddir),
  1845. $unified_info{generate}->{$ddest} = [ @generator ];
  1846. }
  1847. foreach (keys %depends) {
  1848. my $dest = $_;
  1849. my $ddest = $dest eq "" ? "" : cleanfile($sourced, $_, $blddir);
  1850. # If the destination doesn't exist in source, it can only be
  1851. # a generated file in the build tree.
  1852. if ($ddest ne "" && ($ddest eq $src_configdata || ! -f $ddest)) {
  1853. $ddest = cleanfile($buildd, $_, $blddir);
  1854. }
  1855. foreach (@{$depends{$dest}}) {
  1856. my $d = cleanfile($sourced, $_, $blddir);
  1857. # If we know it's generated, or assume it is because we can't
  1858. # find it in the source tree, we set file we depend on to be
  1859. # in the build tree rather than the source tree, and assume
  1860. # and that there are lines to build it in a BEGINRAW..ENDRAW
  1861. # section or in the Makefile template.
  1862. if ($d eq $src_configdata
  1863. || ! -f $d
  1864. || (grep { $d eq $_ }
  1865. map { cleanfile($srcdir, $_, $blddir) }
  1866. grep { /\.h$/ } keys %{$unified_info{generate}})) {
  1867. $d = cleanfile($buildd, $_, $blddir);
  1868. }
  1869. # Take note if the file to depend on is being renamed
  1870. # Take extra care with files ending with .a, they should
  1871. # be treated without that extension, and the extension
  1872. # should be added back after treatment.
  1873. $d =~ /(\.a)?$/;
  1874. my $e = $1 // "";
  1875. $d = $`.$e;
  1876. $unified_info{depends}->{$ddest}->{$d} = 1;
  1877. }
  1878. }
  1879. foreach (keys %includes) {
  1880. my $dest = $_;
  1881. my $ddest = cleanfile($sourced, $_, $blddir);
  1882. # If the destination doesn't exist in source, it can only be
  1883. # a generated file in the build tree.
  1884. if ($ddest eq $src_configdata || ! -f $ddest) {
  1885. $ddest = cleanfile($buildd, $_, $blddir);
  1886. }
  1887. foreach (@{$includes{$dest}}) {
  1888. my $is = cleandir($sourced, $_, $blddir);
  1889. my $ib = cleandir($buildd, $_, $blddir);
  1890. push @{$unified_info{includes}->{$ddest}->{source}}, $is
  1891. unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}};
  1892. push @{$unified_info{includes}->{$ddest}->{build}}, $ib
  1893. unless grep { $_ eq $ib } @{$unified_info{includes}->{$ddest}->{build}};
  1894. }
  1895. }
  1896. foreach (keys %defines) {
  1897. my $dest = $_;
  1898. my $ddest = cleanfile($sourced, $_, $blddir);
  1899. # If the destination doesn't exist in source, it can only be
  1900. # a generated file in the build tree.
  1901. if (! -f $ddest) {
  1902. $ddest = cleanfile($buildd, $_, $blddir);
  1903. if ($unified_info{rename}->{$ddest}) {
  1904. $ddest = $unified_info{rename}->{$ddest};
  1905. }
  1906. }
  1907. foreach (@{$defines{$dest}}) {
  1908. m|^([^=]*)(=.*)?$|;
  1909. die "0 length macro name not permitted\n" if $1 eq "";
  1910. die "$1 defined more than once\n"
  1911. if defined $unified_info{defines}->{$ddest}->{$1};
  1912. $unified_info{defines}->{$ddest}->{$1} = $2;
  1913. }
  1914. }
  1915. }
  1916. my $ordinals_text = join(', ', sort keys %ordinals);
  1917. warn <<"EOF" if $ordinals_text;
  1918. WARNING: ORDINALS were specified for $ordinals_text
  1919. They are ignored and should be replaced with a combination of GENERATE,
  1920. DEPEND and SHARED_SOURCE.
  1921. EOF
  1922. # Massage the result
  1923. # If we depend on a header file or a perl module, add an inclusion of
  1924. # its directory to allow smoothe inclusion
  1925. foreach my $dest (keys %{$unified_info{depends}}) {
  1926. next if $dest eq "";
  1927. foreach my $d (keys %{$unified_info{depends}->{$dest}}) {
  1928. next unless $d =~ /\.(h|pm)$/;
  1929. my $i = dirname($d);
  1930. my $spot =
  1931. $d eq "configdata.pm" || defined($unified_info{generate}->{$d})
  1932. ? 'build' : 'source';
  1933. push @{$unified_info{includes}->{$dest}->{$spot}}, $i
  1934. unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{$spot}};
  1935. }
  1936. }
  1937. # Go through all intermediary files and change their names to something that
  1938. # reflects what they will be built for. Note that for some source files,
  1939. # this leads to duplicate object files because they are used multiple times.
  1940. # the goal is to rename all object files according to this scheme:
  1941. # {productname}-{midfix}-{origobjname}.[o|res]
  1942. # the {midfix} is a keyword indicating the type of product, which is mostly
  1943. # valuable for libraries since they come in two forms.
  1944. #
  1945. # This also reorganises the {sources} and {shared_sources} so that the
  1946. # former only contains ALL object files that are supposed to end up in
  1947. # static libraries and programs, while the latter contains ALL object files
  1948. # that are supposed to end up in shared libraries and DSOs.
  1949. # The main reason for having two different source structures is to allow
  1950. # the same name to be used for the static and the shared variants of a
  1951. # library.
  1952. {
  1953. # Take copies so we don't get interference from added stuff
  1954. my %unified_copy = ();
  1955. foreach (('sources', 'shared_sources')) {
  1956. $unified_copy{$_} = { %{$unified_info{$_}} }
  1957. if defined($unified_info{$_});
  1958. delete $unified_info{$_};
  1959. }
  1960. foreach my $prodtype (('programs', 'libraries', 'engines', 'scripts')) {
  1961. # $intent serves multi purposes:
  1962. # - give a prefix for the new object files names
  1963. # - in the case of libraries, rearrange the object files so static
  1964. # libraries use the 'sources' structure exclusively, while shared
  1965. # libraries use the 'shared_sources' structure exclusively.
  1966. my $intent = {
  1967. programs => { bin => { src => [ 'sources' ],
  1968. dst => 'sources' } },
  1969. libraries => { lib => { src => [ 'sources' ],
  1970. dst => 'sources' },
  1971. shlib => { prodselect =>
  1972. sub { grep !/\.a$/, @_ },
  1973. src => [ 'sources',
  1974. 'shared_sources' ],
  1975. dst => 'shared_sources' } },
  1976. engines => { dso => { src => [ 'sources',
  1977. 'shared_sources' ],
  1978. dst => 'shared_sources' } },
  1979. scripts => { script => { src => [ 'sources' ],
  1980. dst => 'sources' } }
  1981. } -> {$prodtype};
  1982. foreach my $kind (keys %$intent) {
  1983. next if ($intent->{$kind}->{dst} eq 'shared_sources'
  1984. && $disabled{shared});
  1985. my @src = @{$intent->{$kind}->{src}};
  1986. my $dst = $intent->{$kind}->{dst};
  1987. my $prodselect = $intent->{$kind}->{prodselect} // sub { @_ };
  1988. foreach my $prod ($prodselect->(keys %{$unified_info{$prodtype}})) {
  1989. # %prod_sources has all applicable objects as keys, and
  1990. # their corresponding sources as values
  1991. my %prod_sources =
  1992. map { $_ => [ keys %{$unified_copy{sources}->{$_}} ] }
  1993. map { keys %{$unified_copy{$_}->{$prod}} }
  1994. @src;
  1995. foreach (keys %prod_sources) {
  1996. # Only affect object files and resource files,
  1997. # the others simply get a new value
  1998. # (+1 instead of -1)
  1999. if ($_ =~ /\.(o|res)$/) {
  2000. (my $prodname = $prod) =~ s|\.a$||;
  2001. my $newobj =
  2002. catfile(dirname($_),
  2003. basename($prodname)
  2004. . '-' . $kind
  2005. . '-' . basename($_));
  2006. $unified_info{$dst}->{$prod}->{$newobj} = 1;
  2007. foreach my $src (@{$prod_sources{$_}}) {
  2008. $unified_info{sources}->{$newobj}->{$src} = 1;
  2009. }
  2010. # Adjust dependencies
  2011. foreach my $deps (keys %{$unified_info{depends}->{$_}}) {
  2012. $unified_info{depends}->{$_}->{$deps} = -1;
  2013. $unified_info{depends}->{$newobj}->{$deps} = 1;
  2014. }
  2015. # Adjust includes
  2016. foreach my $k (('source', 'build')) {
  2017. next unless
  2018. defined($unified_info{includes}->{$_}->{$k});
  2019. my @incs = @{$unified_info{includes}->{$_}->{$k}};
  2020. $unified_info{includes}->{$newobj}->{$k} = [ @incs ];
  2021. }
  2022. } else {
  2023. $unified_info{$dst}->{$prod}->{$_} = 1;
  2024. }
  2025. }
  2026. }
  2027. }
  2028. }
  2029. }
  2030. # At this point, we have a number of sources with the value -1. They
  2031. # aren't part of the local build and are probably meant for a different
  2032. # platform, and can therefore be cleaned away. That happens when making
  2033. # %unified_info more efficient below.
  2034. ### Make unified_info a bit more efficient
  2035. # One level structures
  2036. foreach (("programs", "libraries", "engines", "scripts", "extra", "overrides")) {
  2037. $unified_info{$_} = [ sort keys %{$unified_info{$_}} ];
  2038. }
  2039. # Two level structures
  2040. foreach my $l1 (("install", "sources", "shared_sources", "ldadd", "depends")) {
  2041. foreach my $l2 (sort keys %{$unified_info{$l1}}) {
  2042. my @items =
  2043. sort
  2044. grep { $unified_info{$l1}->{$l2}->{$_} > 0 }
  2045. keys %{$unified_info{$l1}->{$l2}};
  2046. if (@items) {
  2047. $unified_info{$l1}->{$l2} = [ @items ];
  2048. } else {
  2049. delete $unified_info{$l1}->{$l2};
  2050. }
  2051. }
  2052. }
  2053. # Defines
  2054. foreach my $dest (sort keys %{$unified_info{defines}}) {
  2055. $unified_info{defines}->{$dest}
  2056. = [ map { $_.$unified_info{defines}->{$dest}->{$_} }
  2057. sort keys %{$unified_info{defines}->{$dest}} ];
  2058. }
  2059. # Includes
  2060. foreach my $dest (sort keys %{$unified_info{includes}}) {
  2061. if (defined($unified_info{includes}->{$dest}->{build})) {
  2062. my @source_includes = ();
  2063. @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} )
  2064. if defined($unified_info{includes}->{$dest}->{source});
  2065. $unified_info{includes}->{$dest} =
  2066. [ @{$unified_info{includes}->{$dest}->{build}} ];
  2067. foreach my $inc (@source_includes) {
  2068. push @{$unified_info{includes}->{$dest}}, $inc
  2069. unless grep { $_ eq $inc } @{$unified_info{includes}->{$dest}};
  2070. }
  2071. } elsif (defined($unified_info{includes}->{$dest}->{source})) {
  2072. $unified_info{includes}->{$dest} =
  2073. [ @{$unified_info{includes}->{$dest}->{source}} ];
  2074. } else {
  2075. delete $unified_info{includes}->{$dest};
  2076. }
  2077. }
  2078. # For convenience collect information regarding directories where
  2079. # files are generated, those generated files and the end product
  2080. # they end up in where applicable. Then, add build rules for those
  2081. # directories
  2082. my %loopinfo = ( "lib" => [ @{$unified_info{libraries}} ],
  2083. "dso" => [ @{$unified_info{engines}} ],
  2084. "bin" => [ @{$unified_info{programs}} ],
  2085. "script" => [ @{$unified_info{scripts}} ] );
  2086. foreach my $type (keys %loopinfo) {
  2087. foreach my $product (@{$loopinfo{$type}}) {
  2088. my %dirs = ();
  2089. my $pd = dirname($product);
  2090. foreach (@{$unified_info{sources}->{$product} // []},
  2091. @{$unified_info{shared_sources}->{$product} // []}) {
  2092. my $d = dirname($_);
  2093. # We don't want to create targets for source directories
  2094. # when building out of source
  2095. next if ($config{sourcedir} ne $config{builddir}
  2096. && $d =~ m|^\Q$config{sourcedir}\E|);
  2097. # We already have a "test" target, and the current directory
  2098. # is just silly to make a target for
  2099. next if $d eq "test" || $d eq ".";
  2100. $dirs{$d} = 1;
  2101. push @{$unified_info{dirinfo}->{$d}->{deps}}, $_
  2102. if $d ne $pd;
  2103. }
  2104. foreach (keys %dirs) {
  2105. push @{$unified_info{dirinfo}->{$_}->{products}->{$type}},
  2106. $product;
  2107. }
  2108. }
  2109. }
  2110. }
  2111. # For the schemes that need it, we provide the old *_obj configs
  2112. # from the *_asm_obj ones
  2113. foreach (grep /_(asm|aux)_src$/, keys %target) {
  2114. my $src = $_;
  2115. (my $obj = $_) =~ s/_(asm|aux)_src$/_obj/;
  2116. $target{$obj} = $target{$src};
  2117. $target{$obj} =~ s/\.[csS]\b/.o/g; # C and assembler
  2118. $target{$obj} =~ s/\.(cc|cpp)\b/_cc.o/g; # C++
  2119. }
  2120. # Write down our configuration where it fits #########################
  2121. print "Creating configdata.pm\n";
  2122. open(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n";
  2123. print OUT <<"EOF";
  2124. #! $config{HASHBANGPERL}
  2125. package configdata;
  2126. use strict;
  2127. use warnings;
  2128. use Exporter;
  2129. #use vars qw(\@ISA \@EXPORT);
  2130. our \@ISA = qw(Exporter);
  2131. our \@EXPORT = qw(\%config \%target \%disabled \%withargs \%unified_info \@disablables);
  2132. EOF
  2133. print OUT "our %config = (\n";
  2134. foreach (sort keys %config) {
  2135. if (ref($config{$_}) eq "ARRAY") {
  2136. print OUT " ", $_, " => [ ", join(", ",
  2137. map { quotify("perl", $_) }
  2138. @{$config{$_}}), " ],\n";
  2139. } elsif (ref($config{$_}) eq "HASH") {
  2140. print OUT " ", $_, " => {";
  2141. if (scalar keys %{$config{$_}} > 0) {
  2142. print OUT "\n";
  2143. foreach my $key (sort keys %{$config{$_}}) {
  2144. print OUT " ",
  2145. join(" => ",
  2146. quotify("perl", $key),
  2147. defined $config{$_}->{$key}
  2148. ? quotify("perl", $config{$_}->{$key})
  2149. : "undef");
  2150. print OUT ",\n";
  2151. }
  2152. print OUT " ";
  2153. }
  2154. print OUT "},\n";
  2155. } else {
  2156. print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n"
  2157. }
  2158. }
  2159. print OUT <<"EOF";
  2160. );
  2161. EOF
  2162. print OUT "our %target = (\n";
  2163. foreach (sort keys %target) {
  2164. if (ref($target{$_}) eq "ARRAY") {
  2165. print OUT " ", $_, " => [ ", join(", ",
  2166. map { quotify("perl", $_) }
  2167. @{$target{$_}}), " ],\n";
  2168. } else {
  2169. print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n"
  2170. }
  2171. }
  2172. print OUT <<"EOF";
  2173. );
  2174. EOF
  2175. print OUT "our \%available_protocols = (\n";
  2176. print OUT " tls => [ ", join(", ", map { quotify("perl", $_) } @tls), " ],\n";
  2177. print OUT " dtls => [ ", join(", ", map { quotify("perl", $_) } @dtls), " ],\n";
  2178. print OUT <<"EOF";
  2179. );
  2180. EOF
  2181. print OUT "our \@disablables = (\n";
  2182. foreach (@disablables) {
  2183. print OUT " ", quotify("perl", $_), ",\n";
  2184. }
  2185. print OUT <<"EOF";
  2186. );
  2187. EOF
  2188. print OUT "our \%disabled = (\n";
  2189. foreach (sort keys %disabled) {
  2190. print OUT " ", quotify("perl", $_), " => ", quotify("perl", $disabled{$_}), ",\n";
  2191. }
  2192. print OUT <<"EOF";
  2193. );
  2194. EOF
  2195. print OUT "our %withargs = (\n";
  2196. foreach (sort keys %withargs) {
  2197. if (ref($withargs{$_}) eq "ARRAY") {
  2198. print OUT " ", $_, " => [ ", join(", ",
  2199. map { quotify("perl", $_) }
  2200. @{$withargs{$_}}), " ],\n";
  2201. } else {
  2202. print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n"
  2203. }
  2204. }
  2205. print OUT <<"EOF";
  2206. );
  2207. EOF
  2208. if ($builder eq "unified") {
  2209. my $recurse;
  2210. $recurse = sub {
  2211. my $indent = shift;
  2212. foreach (@_) {
  2213. if (ref $_ eq "ARRAY") {
  2214. print OUT " "x$indent, "[\n";
  2215. foreach (@$_) {
  2216. $recurse->($indent + 4, $_);
  2217. }
  2218. print OUT " "x$indent, "],\n";
  2219. } elsif (ref $_ eq "HASH") {
  2220. my %h = %$_;
  2221. print OUT " "x$indent, "{\n";
  2222. foreach (sort keys %h) {
  2223. if (ref $h{$_} eq "") {
  2224. print OUT " "x($indent + 4), quotify("perl", $_), " => ", quotify("perl", $h{$_}), ",\n";
  2225. } else {
  2226. print OUT " "x($indent + 4), quotify("perl", $_), " =>\n";
  2227. $recurse->($indent + 8, $h{$_});
  2228. }
  2229. }
  2230. print OUT " "x$indent, "},\n";
  2231. } else {
  2232. print OUT " "x$indent, quotify("perl", $_), ",\n";
  2233. }
  2234. }
  2235. };
  2236. print OUT "our %unified_info = (\n";
  2237. foreach (sort keys %unified_info) {
  2238. if (ref $unified_info{$_} eq "") {
  2239. print OUT " "x4, quotify("perl", $_), " => ", quotify("perl", $unified_info{$_}), ",\n";
  2240. } else {
  2241. print OUT " "x4, quotify("perl", $_), " =>\n";
  2242. $recurse->(8, $unified_info{$_});
  2243. }
  2244. }
  2245. print OUT <<"EOF";
  2246. );
  2247. EOF
  2248. }
  2249. print OUT
  2250. "# The following data is only used when this files is use as a script\n";
  2251. print OUT "my \@makevars = (\n";
  2252. foreach (sort keys %user) {
  2253. print OUT " '",$_,"',\n";
  2254. }
  2255. print OUT ");\n";
  2256. print OUT "my \%disabled_info = (\n";
  2257. foreach my $what (sort keys %disabled_info) {
  2258. print OUT " '$what' => {\n";
  2259. foreach my $info (sort keys %{$disabled_info{$what}}) {
  2260. if (ref $disabled_info{$what}->{$info} eq 'ARRAY') {
  2261. print OUT " $info => [ ",
  2262. join(', ', map { "'$_'" } @{$disabled_info{$what}->{$info}}),
  2263. " ],\n";
  2264. } else {
  2265. print OUT " $info => '", $disabled_info{$what}->{$info},
  2266. "',\n";
  2267. }
  2268. }
  2269. print OUT " },\n";
  2270. }
  2271. print OUT ");\n";
  2272. print OUT 'my @user_crossable = qw( ', join (' ', @user_crossable), " );\n";
  2273. print OUT << 'EOF';
  2274. # If run directly, we can give some answers, and even reconfigure
  2275. unless (caller) {
  2276. use Getopt::Long;
  2277. use File::Spec::Functions;
  2278. use File::Basename;
  2279. use Pod::Usage;
  2280. my $here = dirname($0);
  2281. my $dump = undef;
  2282. my $cmdline = undef;
  2283. my $options = undef;
  2284. my $target = undef;
  2285. my $envvars = undef;
  2286. my $makevars = undef;
  2287. my $buildparams = undef;
  2288. my $reconf = undef;
  2289. my $verbose = undef;
  2290. my $help = undef;
  2291. my $man = undef;
  2292. GetOptions('dump|d' => \$dump,
  2293. 'command-line|c' => \$cmdline,
  2294. 'options|o' => \$options,
  2295. 'target|t' => \$target,
  2296. 'environment|e' => \$envvars,
  2297. 'make-variables|m' => \$makevars,
  2298. 'build-parameters|b' => \$buildparams,
  2299. 'reconfigure|reconf|r' => \$reconf,
  2300. 'verbose|v' => \$verbose,
  2301. 'help' => \$help,
  2302. 'man' => \$man)
  2303. or die "Errors in command line arguments\n";
  2304. unless ($dump || $cmdline || $options || $target || $envvars || $makevars
  2305. || $buildparams || $reconf || $verbose || $help || $man) {
  2306. print STDERR <<"_____";
  2307. You must give at least one option.
  2308. For more information, do '$0 --help'
  2309. _____
  2310. exit(2);
  2311. }
  2312. if ($help) {
  2313. pod2usage(-exitval => 0,
  2314. -verbose => 1);
  2315. }
  2316. if ($man) {
  2317. pod2usage(-exitval => 0,
  2318. -verbose => 2);
  2319. }
  2320. if ($dump || $cmdline) {
  2321. print "\nCommand line (with current working directory = $here):\n\n";
  2322. print ' ',join(' ',
  2323. $config{PERL},
  2324. catfile($config{sourcedir}, 'Configure'),
  2325. @{$config{perlargv}}), "\n";
  2326. print "\nPerl information:\n\n";
  2327. print ' ',$config{perl_cmd},"\n";
  2328. print ' ',$config{perl_version},' for ',$config{perl_archname},"\n";
  2329. }
  2330. if ($dump || $options) {
  2331. my $longest = 0;
  2332. my $longest2 = 0;
  2333. foreach my $what (@disablables) {
  2334. $longest = length($what) if $longest < length($what);
  2335. $longest2 = length($disabled{$what})
  2336. if $disabled{$what} && $longest2 < length($disabled{$what});
  2337. }
  2338. print "\nEnabled features:\n\n";
  2339. foreach my $what (@disablables) {
  2340. print " $what\n" unless $disabled{$what};
  2341. }
  2342. print "\nDisabled features:\n\n";
  2343. foreach my $what (@disablables) {
  2344. if ($disabled{$what}) {
  2345. print " $what", ' ' x ($longest - length($what) + 1),
  2346. "[$disabled{$what}]", ' ' x ($longest2 - length($disabled{$what}) + 1);
  2347. print $disabled_info{$what}->{macro}
  2348. if $disabled_info{$what}->{macro};
  2349. print ' (skip ',
  2350. join(', ', @{$disabled_info{$what}->{skipped}}),
  2351. ')'
  2352. if $disabled_info{$what}->{skipped};
  2353. print "\n";
  2354. }
  2355. }
  2356. }
  2357. if ($dump || $target) {
  2358. print "\nConfig target attributes:\n\n";
  2359. foreach (sort keys %target) {
  2360. next if $_ =~ m|^_| || $_ eq 'template';
  2361. my $quotify = sub {
  2362. map { (my $x = $_) =~ s|([\\\$\@"])|\\$1|g; "\"$x\""} @_;
  2363. };
  2364. print ' ', $_, ' => ';
  2365. if (ref($target{$_}) eq "ARRAY") {
  2366. print '[ ', join(', ', $quotify->(@{$target{$_}})), " ],\n";
  2367. } else {
  2368. print $quotify->($target{$_}), ",\n"
  2369. }
  2370. }
  2371. }
  2372. if ($dump || $envvars) {
  2373. print "\nRecorded environment:\n\n";
  2374. foreach (sort keys %{$config{perlenv}}) {
  2375. print ' ',$_,' = ',($config{perlenv}->{$_} || ''),"\n";
  2376. }
  2377. }
  2378. if ($dump || $makevars) {
  2379. print "\nMakevars:\n\n";
  2380. foreach my $var (@makevars) {
  2381. my $prefix = '';
  2382. $prefix = $config{CROSS_COMPILE}
  2383. if grep { $var eq $_ } @user_crossable;
  2384. $prefix //= '';
  2385. print ' ',$var,' ' x (16 - length $var),'= ',
  2386. (ref $config{$var} eq 'ARRAY'
  2387. ? join(' ', @{$config{$var}})
  2388. : $prefix.$config{$var}),
  2389. "\n"
  2390. if defined $config{$var};
  2391. }
  2392. my @buildfile = ($config{builddir}, $config{build_file});
  2393. unshift @buildfile, $here
  2394. unless file_name_is_absolute($config{builddir});
  2395. my $buildfile = canonpath(catdir(@buildfile));
  2396. print <<"_____";
  2397. NOTE: These variables only represent the configuration view. The build file
  2398. template may have processed these variables further, please have a look at the
  2399. build file for more exact data:
  2400. $buildfile
  2401. _____
  2402. }
  2403. if ($dump || $buildparams) {
  2404. my @buildfile = ($config{builddir}, $config{build_file});
  2405. unshift @buildfile, $here
  2406. unless file_name_is_absolute($config{builddir});
  2407. print "\nbuild file:\n\n";
  2408. print " ", canonpath(catfile(@buildfile)),"\n";
  2409. print "\nbuild file templates:\n\n";
  2410. foreach (@{$config{build_file_templates}}) {
  2411. my @tmpl = ($_);
  2412. unshift @tmpl, $here
  2413. unless file_name_is_absolute($config{sourcedir});
  2414. print ' ',canonpath(catfile(@tmpl)),"\n";
  2415. }
  2416. }
  2417. if ($reconf) {
  2418. if ($verbose) {
  2419. print 'Reconfiguring with: ', join(' ',@{$config{perlargv}}), "\n";
  2420. foreach (sort keys %{$config{perlenv}}) {
  2421. print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n";
  2422. }
  2423. }
  2424. chdir $here;
  2425. exec $^X,catfile($config{sourcedir}, 'Configure'),'reconf';
  2426. }
  2427. }
  2428. 1;
  2429. __END__
  2430. =head1 NAME
  2431. configdata.pm - configuration data for OpenSSL builds
  2432. =head1 SYNOPSIS
  2433. Interactive:
  2434. perl configdata.pm [options]
  2435. As data bank module:
  2436. use configdata;
  2437. =head1 DESCRIPTION
  2438. This module can be used in two modes, interactively and as a module containing
  2439. all the data recorded by OpenSSL's Configure script.
  2440. When used interactively, simply run it as any perl script, with at least one
  2441. option, and you will get the information you ask for. See L</OPTIONS> below.
  2442. When loaded as a module, you get a few databanks with useful information to
  2443. perform build related tasks. The databanks are:
  2444. %config Configured things.
  2445. %target The OpenSSL config target with all inheritances
  2446. resolved.
  2447. %disabled The features that are disabled.
  2448. @disablables The list of features that can be disabled.
  2449. %withargs All data given through --with-THING options.
  2450. %unified_info All information that was computed from the build.info
  2451. files.
  2452. =head1 OPTIONS
  2453. =over 4
  2454. =item B<--help>
  2455. Print a brief help message and exit.
  2456. =item B<--man>
  2457. Print the manual page and exit.
  2458. =item B<--dump> | B<-d>
  2459. Print all relevant configuration data. This is equivalent to B<--command-line>
  2460. B<--options> B<--target> B<--environment> B<--make-variables>
  2461. B<--build-parameters>.
  2462. =item B<--command-line> | B<-c>
  2463. Print the current configuration command line.
  2464. =item B<--options> | B<-o>
  2465. Print the features, both enabled and disabled, and display defined macro and
  2466. skipped directories where applicable.
  2467. =item B<--target> | B<-t>
  2468. Print the config attributes for this config target.
  2469. =item B<--environment> | B<-e>
  2470. Print the environment variables and their values at the time of configuration.
  2471. =item B<--make-variables> | B<-m>
  2472. Print the main make variables generated in the current configuration
  2473. =item B<--build-parameters> | B<-b>
  2474. Print the build parameters, i.e. build file and build file templates.
  2475. =item B<--reconfigure> | B<--reconf> | B<-r>
  2476. Redo the configuration.
  2477. =item B<--verbose> | B<-v>
  2478. Verbose output.
  2479. =back
  2480. =cut
  2481. EOF
  2482. close(OUT);
  2483. if ($builder_platform eq 'unix') {
  2484. my $mode = (0755 & ~umask);
  2485. chmod $mode, 'configdata.pm'
  2486. or warn sprintf("WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s\n",$mode,$!);
  2487. }
  2488. my %builders = (
  2489. unified => sub {
  2490. print 'Creating ',$target{build_file},"\n";
  2491. run_dofile(catfile($blddir, $target{build_file}),
  2492. @{$config{build_file_templates}});
  2493. },
  2494. );
  2495. $builders{$builder}->($builder_platform, @builder_opts);
  2496. $SIG{__DIE__} = $orig_death_handler;
  2497. print <<"EOF" if ($disabled{threads} eq "unavailable");
  2498. The library could not be configured for supporting multi-threaded
  2499. applications as the compiler options required on this system are not known.
  2500. See file INSTALL for details if you need multi-threading.
  2501. EOF
  2502. print <<"EOF" if ($no_shared_warn);
  2503. The options 'shared', 'pic' and 'dynamic-engine' aren't supported on this
  2504. platform, so we will pretend you gave the option 'no-pic', which also disables
  2505. 'shared' and 'dynamic-engine'. If you know how to implement shared libraries
  2506. or position independent code, please let us know (but please first make sure
  2507. you have tried with a current version of OpenSSL).
  2508. EOF
  2509. print <<"EOF";
  2510. **********************************************************************
  2511. *** ***
  2512. *** OpenSSL has been successfully configured ***
  2513. *** ***
  2514. *** If you encounter a problem while building, please open an ***
  2515. *** issue on GitHub <https://github.com/openssl/openssl/issues> ***
  2516. *** and include the output from the following command: ***
  2517. *** ***
  2518. *** perl configdata.pm --dump ***
  2519. *** ***
  2520. *** (If you are new to OpenSSL, you might want to consult the ***
  2521. *** 'Troubleshooting' section in the INSTALL file first) ***
  2522. *** ***
  2523. **********************************************************************
  2524. EOF
  2525. exit(0);
  2526. ######################################################################
  2527. #
  2528. # Helpers and utility functions
  2529. #
  2530. # Death handler, to print a helpful message in case of failure #######
  2531. #
  2532. sub death_handler {
  2533. die @_ if $^S; # To prevent the added message in eval blocks
  2534. my $build_file = $target{build_file} // "build file";
  2535. my @message = ( <<"_____", @_ );
  2536. Failure! $build_file wasn't produced.
  2537. Please read INSTALL and associated NOTES files. You may also have to look over
  2538. your available compiler tool chain or change your configuration.
  2539. _____
  2540. # Dying is terminal, so it's ok to reset the signal handler here.
  2541. $SIG{__DIE__} = $orig_death_handler;
  2542. die @message;
  2543. }
  2544. # Configuration file reading #########################################
  2545. # Note: All of the helper functions are for lazy evaluation. They all
  2546. # return a CODE ref, which will return the intended value when evaluated.
  2547. # Thus, whenever there's mention of a returned value, it's about that
  2548. # intended value.
  2549. # Helper function to implement conditional inheritance depending on the
  2550. # value of $disabled{asm}. Used in inherit_from values as follows:
  2551. #
  2552. # inherit_from => [ "template", asm("asm_tmpl") ]
  2553. #
  2554. sub asm {
  2555. my @x = @_;
  2556. sub {
  2557. $disabled{asm} ? () : @x;
  2558. }
  2559. }
  2560. # Helper function to implement conditional value variants, with a default
  2561. # plus additional values based on the value of $config{build_type}.
  2562. # Arguments are given in hash table form:
  2563. #
  2564. # picker(default => "Basic string: ",
  2565. # debug => "debug",
  2566. # release => "release")
  2567. #
  2568. # When configuring with --debug, the resulting string will be
  2569. # "Basic string: debug", and when not, it will be "Basic string: release"
  2570. #
  2571. # This can be used to create variants of sets of flags according to the
  2572. # build type:
  2573. #
  2574. # cflags => picker(default => "-Wall",
  2575. # debug => "-g -O0",
  2576. # release => "-O3")
  2577. #
  2578. sub picker {
  2579. my %opts = @_;
  2580. return sub { add($opts{default} || (),
  2581. $opts{$config{build_type}} || ())->(); }
  2582. }
  2583. # Helper function to combine several values of different types into one.
  2584. # This is useful if you want to combine a string with the result of a
  2585. # lazy function, such as:
  2586. #
  2587. # cflags => combine("-Wall", sub { $disabled{zlib} ? () : "-DZLIB" })
  2588. #
  2589. sub combine {
  2590. my @stuff = @_;
  2591. return sub { add(@stuff)->(); }
  2592. }
  2593. # Helper function to implement conditional values depending on the value
  2594. # of $disabled{threads}. Can be used as follows:
  2595. #
  2596. # cflags => combine("-Wall", threads("-pthread"))
  2597. #
  2598. sub threads {
  2599. my @flags = @_;
  2600. return sub { add($disabled{threads} ? () : @flags)->(); }
  2601. }
  2602. sub shared {
  2603. my @flags = @_;
  2604. return sub { add($disabled{shared} ? () : @flags)->(); }
  2605. }
  2606. our $add_called = 0;
  2607. # Helper function to implement adding values to already existing configuration
  2608. # values. It handles elements that are ARRAYs, CODEs and scalars
  2609. sub _add {
  2610. my $separator = shift;
  2611. # If there's any ARRAY in the collection of values OR the separator
  2612. # is undef, we will return an ARRAY of combined values, otherwise a
  2613. # string of joined values with $separator as the separator.
  2614. my $found_array = !defined($separator);
  2615. my @values =
  2616. map {
  2617. my $res = $_;
  2618. while (ref($res) eq "CODE") {
  2619. $res = $res->();
  2620. }
  2621. if (defined($res)) {
  2622. if (ref($res) eq "ARRAY") {
  2623. $found_array = 1;
  2624. @$res;
  2625. } else {
  2626. $res;
  2627. }
  2628. } else {
  2629. ();
  2630. }
  2631. } (@_);
  2632. $add_called = 1;
  2633. if ($found_array) {
  2634. [ @values ];
  2635. } else {
  2636. join($separator, grep { defined($_) && $_ ne "" } @values);
  2637. }
  2638. }
  2639. sub add_before {
  2640. my $separator = " ";
  2641. if (ref($_[$#_]) eq "HASH") {
  2642. my $opts = pop;
  2643. $separator = $opts->{separator};
  2644. }
  2645. my @x = @_;
  2646. sub { _add($separator, @x, @_) };
  2647. }
  2648. sub add {
  2649. my $separator = " ";
  2650. if (ref($_[$#_]) eq "HASH") {
  2651. my $opts = pop;
  2652. $separator = $opts->{separator};
  2653. }
  2654. my @x = @_;
  2655. sub { _add($separator, @_, @x) };
  2656. }
  2657. sub read_eval_file {
  2658. my $fname = shift;
  2659. my $content;
  2660. my @result;
  2661. open F, "< $fname" or die "Can't open '$fname': $!\n";
  2662. {
  2663. undef local $/;
  2664. $content = <F>;
  2665. }
  2666. close F;
  2667. {
  2668. local $@;
  2669. @result = ( eval $content );
  2670. warn $@ if $@;
  2671. }
  2672. return wantarray ? @result : $result[0];
  2673. }
  2674. # configuration reader, evaluates the input file as a perl script and expects
  2675. # it to fill %targets with target configurations. Those are then added to
  2676. # %table.
  2677. sub read_config {
  2678. my $fname = shift;
  2679. my %targets;
  2680. {
  2681. # Protect certain tables from tampering
  2682. local %table = ();
  2683. %targets = read_eval_file($fname);
  2684. }
  2685. my %preexisting = ();
  2686. foreach (sort keys %targets) {
  2687. $preexisting{$_} = 1 if $table{$_};
  2688. }
  2689. die <<"EOF",
  2690. The following config targets from $fname
  2691. shadow pre-existing config targets with the same name:
  2692. EOF
  2693. map { " $_\n" } sort keys %preexisting
  2694. if %preexisting;
  2695. # For each target, check that it's configured with a hash table.
  2696. foreach (keys %targets) {
  2697. if (ref($targets{$_}) ne "HASH") {
  2698. if (ref($targets{$_}) eq "") {
  2699. warn "Deprecated target configuration for $_, ignoring...\n";
  2700. } else {
  2701. warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
  2702. }
  2703. delete $targets{$_};
  2704. } else {
  2705. $targets{$_}->{_conf_fname_int} = add([ $fname ]);
  2706. }
  2707. }
  2708. %table = (%table, %targets);
  2709. }
  2710. # configuration resolver. Will only resolve all the lazy evaluation
  2711. # codeblocks for the chosen target and all those it inherits from,
  2712. # recursively
  2713. sub resolve_config {
  2714. my $target = shift;
  2715. my @breadcrumbs = @_;
  2716. # my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS});
  2717. if (grep { $_ eq $target } @breadcrumbs) {
  2718. die "inherit_from loop! target backtrace:\n "
  2719. ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
  2720. }
  2721. if (!defined($table{$target})) {
  2722. warn "Warning! target $target doesn't exist!\n";
  2723. return ();
  2724. }
  2725. # Recurse through all inheritances. They will be resolved on the
  2726. # fly, so when this operation is done, they will all just be a
  2727. # bunch of attributes with string values.
  2728. # What we get here, though, are keys with references to lists of
  2729. # the combined values of them all. We will deal with lists after
  2730. # this stage is done.
  2731. my %combined_inheritance = ();
  2732. if ($table{$target}->{inherit_from}) {
  2733. my @inherit_from =
  2734. map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
  2735. foreach (@inherit_from) {
  2736. my %inherited_config = resolve_config($_, $target, @breadcrumbs);
  2737. # 'template' is a marker that's considered private to
  2738. # the config that had it.
  2739. delete $inherited_config{template};
  2740. foreach (keys %inherited_config) {
  2741. if (!$combined_inheritance{$_}) {
  2742. $combined_inheritance{$_} = [];
  2743. }
  2744. push @{$combined_inheritance{$_}}, $inherited_config{$_};
  2745. }
  2746. }
  2747. }
  2748. # We won't need inherit_from in this target any more, since we've
  2749. # resolved all the inheritances that lead to this
  2750. delete $table{$target}->{inherit_from};
  2751. # Now is the time to deal with those lists. Here's the place to
  2752. # decide what shall be done with those lists, all based on the
  2753. # values of the target we're currently dealing with.
  2754. # - If a value is a coderef, it will be executed with the list of
  2755. # inherited values as arguments.
  2756. # - If the corresponding key doesn't have a value at all or is the
  2757. # empty string, the inherited value list will be run through the
  2758. # default combiner (below), and the result becomes this target's
  2759. # value.
  2760. # - Otherwise, this target's value is assumed to be a string that
  2761. # will simply override the inherited list of values.
  2762. my $default_combiner = add();
  2763. my %all_keys =
  2764. map { $_ => 1 } (keys %combined_inheritance,
  2765. keys %{$table{$target}});
  2766. sub process_values {
  2767. my $object = shift;
  2768. my $inherited = shift; # Always a [ list ]
  2769. my $target = shift;
  2770. my $entry = shift;
  2771. $add_called = 0;
  2772. while(ref($object) eq "CODE") {
  2773. $object = $object->(@$inherited);
  2774. }
  2775. if (!defined($object)) {
  2776. return ();
  2777. }
  2778. elsif (ref($object) eq "ARRAY") {
  2779. local $add_called; # To make sure recursive calls don't affect it
  2780. return [ map { process_values($_, $inherited, $target, $entry) }
  2781. @$object ];
  2782. } elsif (ref($object) eq "") {
  2783. return $object;
  2784. } else {
  2785. die "cannot handle reference type ",ref($object)
  2786. ," found in target ",$target," -> ",$entry,"\n";
  2787. }
  2788. }
  2789. foreach (sort keys %all_keys) {
  2790. my $previous = $combined_inheritance{$_};
  2791. # Current target doesn't have a value for the current key?
  2792. # Assign it the default combiner, the rest of this loop body
  2793. # will handle it just like any other coderef.
  2794. if (!exists $table{$target}->{$_}) {
  2795. $table{$target}->{$_} = $default_combiner;
  2796. }
  2797. $table{$target}->{$_} = process_values($table{$target}->{$_},
  2798. $combined_inheritance{$_},
  2799. $target, $_);
  2800. unless(defined($table{$target}->{$_})) {
  2801. delete $table{$target}->{$_};
  2802. }
  2803. # if ($extra_checks &&
  2804. # $previous && !($add_called || $previous ~~ $table{$target}->{$_})) {
  2805. # warn "$_ got replaced in $target\n";
  2806. # }
  2807. }
  2808. # Finally done, return the result.
  2809. return %{$table{$target}};
  2810. }
  2811. sub usage
  2812. {
  2813. print STDERR $usage;
  2814. print STDERR "\npick os/compiler from:\n";
  2815. my $j=0;
  2816. my $i;
  2817. my $k=0;
  2818. foreach $i (sort keys %table)
  2819. {
  2820. next if $table{$i}->{template};
  2821. next if $i =~ /^debug/;
  2822. $k += length($i) + 1;
  2823. if ($k > 78)
  2824. {
  2825. print STDERR "\n";
  2826. $k=length($i);
  2827. }
  2828. print STDERR $i . " ";
  2829. }
  2830. foreach $i (sort keys %table)
  2831. {
  2832. next if $table{$i}->{template};
  2833. next if $i !~ /^debug/;
  2834. $k += length($i) + 1;
  2835. if ($k > 78)
  2836. {
  2837. print STDERR "\n";
  2838. $k=length($i);
  2839. }
  2840. print STDERR $i . " ";
  2841. }
  2842. print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n";
  2843. exit(1);
  2844. }
  2845. sub run_dofile
  2846. {
  2847. my $out = shift;
  2848. my @templates = @_;
  2849. unlink $out || warn "Can't remove $out, $!"
  2850. if -f $out;
  2851. foreach (@templates) {
  2852. die "Can't open $_, $!" unless -f $_;
  2853. }
  2854. my $perlcmd = (quotify("maybeshell", $config{PERL}))[0];
  2855. my $cmd = "$perlcmd \"-I.\" \"-Mconfigdata\" \"$dofile\" -o\"Configure\" \"".join("\" \"",@templates)."\" > \"$out.new\"";
  2856. #print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
  2857. system($cmd);
  2858. exit 1 if $? != 0;
  2859. rename("$out.new", $out) || die "Can't rename $out.new, $!";
  2860. }
  2861. sub compiler_predefined {
  2862. state %predefined;
  2863. my $cc = shift;
  2864. return () if $^O eq 'VMS';
  2865. die 'compiler_predefined called without a compiler command'
  2866. unless $cc;
  2867. if (! $predefined{$cc}) {
  2868. $predefined{$cc} = {};
  2869. # collect compiler pre-defines from gcc or gcc-alike...
  2870. open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |");
  2871. while (my $l = <PIPE>) {
  2872. $l =~ m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last;
  2873. $predefined{$cc}->{$1} = $2 // '';
  2874. }
  2875. close(PIPE);
  2876. }
  2877. return %{$predefined{$cc}};
  2878. }
  2879. sub which
  2880. {
  2881. my ($name)=@_;
  2882. if (eval { require IPC::Cmd; 1; }) {
  2883. IPC::Cmd->import();
  2884. return scalar IPC::Cmd::can_run($name);
  2885. } else {
  2886. # if there is $directories component in splitpath,
  2887. # then it's not something to test with $PATH...
  2888. return $name if (File::Spec->splitpath($name))[1];
  2889. foreach (File::Spec->path()) {
  2890. my $fullpath = catfile($_, "$name$target{exe_extension}");
  2891. if (-f $fullpath and -x $fullpath) {
  2892. return $fullpath;
  2893. }
  2894. }
  2895. }
  2896. }
  2897. sub env
  2898. {
  2899. my $name = shift;
  2900. my %opts = @_;
  2901. unless ($opts{cacheonly}) {
  2902. # Note that if $ENV{$name} doesn't exist or is undefined,
  2903. # $config{perlenv}->{$name} will be created with the value
  2904. # undef. This is intentional.
  2905. $config{perlenv}->{$name} = $ENV{$name}
  2906. if ! exists $config{perlenv}->{$name};
  2907. }
  2908. return $config{perlenv}->{$name};
  2909. }
  2910. # Configuration printer ##############################################
  2911. sub print_table_entry
  2912. {
  2913. local $now_printing = shift;
  2914. my %target = resolve_config($now_printing);
  2915. my $type = shift;
  2916. # Don't print the templates
  2917. return if $target{template};
  2918. my @sequence = (
  2919. "sys_id",
  2920. "cpp",
  2921. "cppflags",
  2922. "defines",
  2923. "includes",
  2924. "cc",
  2925. "cflags",
  2926. "unistd",
  2927. "ld",
  2928. "lflags",
  2929. "loutflag",
  2930. "ex_libs",
  2931. "bn_ops",
  2932. "apps_aux_src",
  2933. "cpuid_asm_src",
  2934. "uplink_aux_src",
  2935. "bn_asm_src",
  2936. "ec_asm_src",
  2937. "des_asm_src",
  2938. "aes_asm_src",
  2939. "bf_asm_src",
  2940. "md5_asm_src",
  2941. "cast_asm_src",
  2942. "sha1_asm_src",
  2943. "rc4_asm_src",
  2944. "rmd160_asm_src",
  2945. "rc5_asm_src",
  2946. "wp_asm_src",
  2947. "cmll_asm_src",
  2948. "modes_asm_src",
  2949. "padlock_asm_src",
  2950. "chacha_asm_src",
  2951. "poly1035_asm_src",
  2952. "thread_scheme",
  2953. "perlasm_scheme",
  2954. "dso_scheme",
  2955. "shared_target",
  2956. "shared_cflag",
  2957. "shared_defines",
  2958. "shared_ldflag",
  2959. "shared_rcflag",
  2960. "shared_extension",
  2961. "dso_extension",
  2962. "obj_extension",
  2963. "exe_extension",
  2964. "ranlib",
  2965. "ar",
  2966. "arflags",
  2967. "aroutflag",
  2968. "rc",
  2969. "rcflags",
  2970. "rcoutflag",
  2971. "mt",
  2972. "mtflags",
  2973. "mtinflag",
  2974. "mtoutflag",
  2975. "multilib",
  2976. "build_scheme",
  2977. );
  2978. if ($type eq "TABLE") {
  2979. print "\n";
  2980. print "*** $now_printing\n";
  2981. foreach (@sequence) {
  2982. if (ref($target{$_}) eq "ARRAY") {
  2983. printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}});
  2984. } else {
  2985. printf "\$%-12s = %s\n", $_, $target{$_};
  2986. }
  2987. }
  2988. } elsif ($type eq "HASH") {
  2989. my $largest =
  2990. length((sort { length($a) <=> length($b) } @sequence)[-1]);
  2991. print " '$now_printing' => {\n";
  2992. foreach (@sequence) {
  2993. if ($target{$_}) {
  2994. if (ref($target{$_}) eq "ARRAY") {
  2995. print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n";
  2996. } else {
  2997. print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
  2998. }
  2999. }
  3000. }
  3001. print " },\n";
  3002. }
  3003. }
  3004. # Utility routines ###################################################
  3005. # On VMS, if the given file is a logical name, File::Spec::Functions
  3006. # will consider it an absolute path. There are cases when we want a
  3007. # purely syntactic check without checking the environment.
  3008. sub isabsolute {
  3009. my $file = shift;
  3010. # On non-platforms, we just use file_name_is_absolute().
  3011. return file_name_is_absolute($file) unless $^O eq "VMS";
  3012. # If the file spec includes a device or a directory spec,
  3013. # file_name_is_absolute() is perfectly safe.
  3014. return file_name_is_absolute($file) if $file =~ m|[:\[]|;
  3015. # Here, we know the given file spec isn't absolute
  3016. return 0;
  3017. }
  3018. # Makes a directory absolute and cleans out /../ in paths like foo/../bar
  3019. # On some platforms, this uses rel2abs(), while on others, realpath() is used.
  3020. # realpath() requires that at least all path components except the last is an
  3021. # existing directory. On VMS, the last component of the directory spec must
  3022. # exist.
  3023. sub absolutedir {
  3024. my $dir = shift;
  3025. # realpath() is quite buggy on VMS. It uses LIB$FID_TO_NAME, which
  3026. # will return the volume name for the device, no matter what. Also,
  3027. # it will return an incorrect directory spec if the argument is a
  3028. # directory that doesn't exist.
  3029. if ($^O eq "VMS") {
  3030. return rel2abs($dir);
  3031. }
  3032. # We use realpath() on Unix, since no other will properly clean out
  3033. # a directory spec.
  3034. use Cwd qw/realpath/;
  3035. return realpath($dir);
  3036. }
  3037. sub quotify {
  3038. my %processors = (
  3039. perl => sub { my $x = shift;
  3040. $x =~ s/([\\\$\@"])/\\$1/g;
  3041. return '"'.$x.'"'; },
  3042. maybeshell => sub { my $x = shift;
  3043. (my $y = $x) =~ s/([\\\"])/\\$1/g;
  3044. if ($x ne $y || $x =~ m|\s|) {
  3045. return '"'.$y.'"';
  3046. } else {
  3047. return $x;
  3048. }
  3049. },
  3050. );
  3051. my $for = shift;
  3052. my $processor =
  3053. defined($processors{$for}) ? $processors{$for} : sub { shift; };
  3054. return map { $processor->($_); } @_;
  3055. }
  3056. # collect_from_file($filename, $line_concat_cond_re, $line_concat)
  3057. # $filename is a file name to read from
  3058. # $line_concat_cond_re is a regexp detecting a line continuation ending
  3059. # $line_concat is a CODEref that takes care of concatenating two lines
  3060. sub collect_from_file {
  3061. my $filename = shift;
  3062. my $line_concat_cond_re = shift;
  3063. my $line_concat = shift;
  3064. open my $fh, $filename || die "unable to read $filename: $!\n";
  3065. return sub {
  3066. my $saved_line = "";
  3067. $_ = "";
  3068. while (<$fh>) {
  3069. s|\R$||;
  3070. if (defined $line_concat) {
  3071. $_ = $line_concat->($saved_line, $_);
  3072. $saved_line = "";
  3073. }
  3074. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  3075. $saved_line = $_;
  3076. next;
  3077. }
  3078. return $_;
  3079. }
  3080. die "$filename ending with continuation line\n" if $_;
  3081. close $fh;
  3082. return undef;
  3083. }
  3084. }
  3085. # collect_from_array($array, $line_concat_cond_re, $line_concat)
  3086. # $array is an ARRAYref of lines
  3087. # $line_concat_cond_re is a regexp detecting a line continuation ending
  3088. # $line_concat is a CODEref that takes care of concatenating two lines
  3089. sub collect_from_array {
  3090. my $array = shift;
  3091. my $line_concat_cond_re = shift;
  3092. my $line_concat = shift;
  3093. my @array = (@$array);
  3094. return sub {
  3095. my $saved_line = "";
  3096. $_ = "";
  3097. while (defined($_ = shift @array)) {
  3098. s|\R$||;
  3099. if (defined $line_concat) {
  3100. $_ = $line_concat->($saved_line, $_);
  3101. $saved_line = "";
  3102. }
  3103. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  3104. $saved_line = $_;
  3105. next;
  3106. }
  3107. return $_;
  3108. }
  3109. die "input text ending with continuation line\n" if $_;
  3110. return undef;
  3111. }
  3112. }
  3113. # collect_information($lineiterator, $line_continue, $regexp => $CODEref, ...)
  3114. # $lineiterator is a CODEref that delivers one line at a time.
  3115. # All following arguments are regex/CODEref pairs, where the regexp detects a
  3116. # line and the CODEref does something with the result of the regexp.
  3117. sub collect_information {
  3118. my $lineiterator = shift;
  3119. my %collectors = @_;
  3120. while(defined($_ = $lineiterator->())) {
  3121. s|\R$||;
  3122. my $found = 0;
  3123. if ($collectors{"BEFORE"}) {
  3124. $collectors{"BEFORE"}->($_);
  3125. }
  3126. foreach my $re (keys %collectors) {
  3127. if ($re !~ /^OTHERWISE|BEFORE|AFTER$/ && /$re/) {
  3128. $collectors{$re}->($lineiterator);
  3129. $found = 1;
  3130. };
  3131. }
  3132. if ($collectors{"OTHERWISE"}) {
  3133. $collectors{"OTHERWISE"}->($lineiterator, $_)
  3134. unless $found || !defined $collectors{"OTHERWISE"};
  3135. }
  3136. if ($collectors{"AFTER"}) {
  3137. $collectors{"AFTER"}->($_);
  3138. }
  3139. }
  3140. }
  3141. # tokenize($line)
  3142. # $line is a line of text to split up into tokens
  3143. # returns a list of tokens
  3144. #
  3145. # Tokens are divided by spaces. If the tokens include spaces, they
  3146. # have to be quoted with single or double quotes. Double quotes
  3147. # inside a double quoted token must be escaped. Escaping is done
  3148. # with backslash.
  3149. # Basically, the same quoting rules apply for " and ' as in any
  3150. # Unix shell.
  3151. sub tokenize {
  3152. my $line = my $debug_line = shift;
  3153. my @result = ();
  3154. while ($line =~ s|^\s+||, $line ne "") {
  3155. my $token = "";
  3156. while ($line ne "" && $line !~ m|^\s|) {
  3157. if ($line =~ m/^"((?:[^"\\]+|\\.)*)"/) {
  3158. $token .= $1;
  3159. $line = $';
  3160. } elsif ($line =~ m/^'([^']*)'/) {
  3161. $token .= $1;
  3162. $line = $';
  3163. } elsif ($line =~ m/^(\S+)/) {
  3164. $token .= $1;
  3165. $line = $';
  3166. }
  3167. }
  3168. push @result, $token;
  3169. }
  3170. if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) {
  3171. print STDERR "DEBUG[tokenize]: Parsed '$debug_line' into:\n";
  3172. print STDERR "DEBUG[tokenize]: ('", join("', '", @result), "')\n";
  3173. }
  3174. return @result;
  3175. }