Configure 132 KB

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