Configure 136 KB

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