Configure 139 KB

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