Configure 129 KB

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