Configure 129 KB

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