Configure 137 KB

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