2
0

Configure 127 KB

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