Configure 129 KB

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