Configure 126 KB

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