Configure 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612
  1. #! /usr/bin/env perl
  2. # -*- mode: perl; -*-
  3. # Copyright 2016-2021 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."-".$target{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. }
  1187. unless ($disabled{ubsan}) {
  1188. # -DPEDANTIC or -fnosanitize=alignment may also be required on some
  1189. # platforms.
  1190. push @{$config{cflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all";
  1191. }
  1192. unless ($disabled{msan}) {
  1193. push @{$config{cflags}}, "-fsanitize=memory";
  1194. }
  1195. unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
  1196. && $disabled{asan} && $disabled{ubsan} && $disabled{msan}) {
  1197. push @{$config{cflags}}, "-fno-omit-frame-pointer", "-g";
  1198. push @{$config{cxxflags}}, "-fno-omit-frame-pointer", "-g" if $config{CXX};
  1199. }
  1200. #
  1201. # Platform fix-ups
  1202. #
  1203. # This saves the build files from having to check
  1204. if ($disabled{pic})
  1205. {
  1206. foreach (qw(shared_cflag shared_cxxflag shared_cppflag
  1207. shared_defines shared_includes shared_ldflag
  1208. module_cflags module_cxxflags module_cppflags
  1209. module_defines module_includes module_lflags))
  1210. {
  1211. delete $config{$_};
  1212. $target{$_} = "";
  1213. }
  1214. }
  1215. else
  1216. {
  1217. push @{$config{lib_defines}}, "OPENSSL_PIC";
  1218. }
  1219. if ($target{sys_id} ne "")
  1220. {
  1221. push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}";
  1222. }
  1223. unless ($disabled{asm}) {
  1224. $target{cpuid_asm_src}=$table{DEFAULTS}->{cpuid_asm_src} if ($config{processor} eq "386");
  1225. push @{$config{lib_defines}}, "OPENSSL_CPUID_OBJ" if ($target{cpuid_asm_src} ne "mem_clr.c");
  1226. $target{bn_asm_src} =~ s/\w+-gf2m.c// if (defined($disabled{ec2m}));
  1227. # bn-586 is the only one implementing bn_*_part_words
  1228. push @{$config{lib_defines}}, "OPENSSL_BN_ASM_PART_WORDS" if ($target{bn_asm_src} =~ /bn-586/);
  1229. push @{$config{lib_defines}}, "OPENSSL_IA32_SSE2" if (!$disabled{sse2} && $target{bn_asm_src} =~ /86/);
  1230. push @{$config{lib_defines}}, "OPENSSL_BN_ASM_MONT" if ($target{bn_asm_src} =~ /-mont/);
  1231. push @{$config{lib_defines}}, "OPENSSL_BN_ASM_MONT5" if ($target{bn_asm_src} =~ /-mont5/);
  1232. push @{$config{lib_defines}}, "OPENSSL_BN_ASM_GF2m" if ($target{bn_asm_src} =~ /-gf2m/);
  1233. push @{$config{lib_defines}}, "BN_DIV3W" if ($target{bn_asm_src} =~ /-div3w/);
  1234. if ($target{sha1_asm_src}) {
  1235. push @{$config{lib_defines}}, "SHA1_ASM" if ($target{sha1_asm_src} =~ /sx86/ || $target{sha1_asm_src} =~ /sha1/);
  1236. push @{$config{lib_defines}}, "SHA256_ASM" if ($target{sha1_asm_src} =~ /sha256/);
  1237. push @{$config{lib_defines}}, "SHA512_ASM" if ($target{sha1_asm_src} =~ /sha512/);
  1238. }
  1239. if ($target{keccak1600_asm_src} ne $table{DEFAULTS}->{keccak1600_asm_src}) {
  1240. push @{$config{lib_defines}}, "KECCAK1600_ASM";
  1241. }
  1242. if ($target{rc4_asm_src} ne $table{DEFAULTS}->{rc4_asm_src}) {
  1243. push @{$config{lib_defines}}, "RC4_ASM";
  1244. }
  1245. if ($target{md5_asm_src}) {
  1246. push @{$config{lib_defines}}, "MD5_ASM";
  1247. }
  1248. $target{cast_asm_src}=$table{DEFAULTS}->{cast_asm_src} unless $disabled{pic}; # CAST assembler is not PIC
  1249. if ($target{rmd160_asm_src}) {
  1250. push @{$config{lib_defines}}, "RMD160_ASM";
  1251. }
  1252. if ($target{aes_asm_src}) {
  1253. push @{$config{lib_defines}}, "AES_ASM" if ($target{aes_asm_src} =~ m/\baes-/);;
  1254. push @{$config{lib_defines}}, "AESNI_ASM" if ($target{aes_asm_src} =~ m/\baesni-/);;
  1255. # aes-ctr.fake is not a real file, only indication that assembler
  1256. # module implements AES_ctr32_encrypt...
  1257. push @{$config{lib_defines}}, "AES_CTR_ASM" if ($target{aes_asm_src} =~ s/\s*aes-ctr\.fake//);
  1258. # aes-xts.fake indicates presence of AES_xts_[en|de]crypt...
  1259. push @{$config{lib_defines}}, "AES_XTS_ASM" if ($target{aes_asm_src} =~ s/\s*aes-xts\.fake//);
  1260. $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($disabled{sse2});
  1261. push @{$config{lib_defines}}, "VPAES_ASM" if ($target{aes_asm_src} =~ m/vpaes/);
  1262. push @{$config{lib_defines}}, "BSAES_ASM" if ($target{aes_asm_src} =~ m/bsaes/);
  1263. }
  1264. if ($target{wp_asm_src} =~ /mmx/) {
  1265. if ($config{processor} eq "386") {
  1266. $target{wp_asm_src}=$table{DEFAULTS}->{wp_asm_src};
  1267. } elsif (!$disabled{"whirlpool"}) {
  1268. push @{$config{lib_defines}}, "WHIRLPOOL_ASM";
  1269. }
  1270. }
  1271. if ($target{modes_asm_src} =~ /ghash-/) {
  1272. push @{$config{lib_defines}}, "GHASH_ASM";
  1273. }
  1274. if ($target{ec_asm_src} =~ /ecp_nistz256/) {
  1275. push @{$config{lib_defines}}, "ECP_NISTZ256_ASM";
  1276. }
  1277. if ($target{ec_asm_src} =~ /x25519/) {
  1278. push @{$config{lib_defines}}, "X25519_ASM";
  1279. }
  1280. if ($target{padlock_asm_src} ne $table{DEFAULTS}->{padlock_asm_src}) {
  1281. push @{$config{dso_defines}}, "PADLOCK_ASM";
  1282. }
  1283. if ($target{poly1305_asm_src} ne "") {
  1284. push @{$config{lib_defines}}, "POLY1305_ASM";
  1285. }
  1286. }
  1287. my %predefined_C = compiler_predefined($config{CROSS_COMPILE}.$config{CC});
  1288. my %predefined_CXX = $config{CXX}
  1289. ? compiler_predefined($config{CROSS_COMPILE}.$config{CXX})
  1290. : ();
  1291. # Check for makedepend capabilities.
  1292. if (!$disabled{makedepend}) {
  1293. if ($config{target} =~ /^(VC|vms)-/) {
  1294. # For VC- and vms- targets, there's nothing more to do here. The
  1295. # functionality is hard coded in the corresponding build files for
  1296. # cl (Windows) and CC/DECC (VMS).
  1297. } elsif (($predefined_C{__GNUC__} // -1) >= 3
  1298. && !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) {
  1299. # We know that GNU C version 3 and up as well as all clang
  1300. # versions support dependency generation, but Xcode did not
  1301. # handle $cc -M before clang support (but claims __GNUC__ = 3)
  1302. $config{makedepprog} = "\$(CROSS_COMPILE)$config{CC}";
  1303. } else {
  1304. # In all other cases, we look for 'makedepend', and disable the
  1305. # capability if not found.
  1306. $config{makedepprog} = which('makedepend');
  1307. disable('unavailable', 'makedepend') unless $config{makedepprog};
  1308. }
  1309. }
  1310. if (!$disabled{asm} && !$predefined_C{__MACH__} && $^O ne 'VMS') {
  1311. # probe for -Wa,--noexecstack option...
  1312. if ($predefined_C{__clang__}) {
  1313. # clang has builtin assembler, which doesn't recognize --help,
  1314. # but it apparently recognizes the option in question on all
  1315. # supported platforms even when it's meaningless. In other words
  1316. # probe would fail, but probed option always accepted...
  1317. push @{$config{cflags}}, "-Wa,--noexecstack", "-Qunused-arguments";
  1318. } else {
  1319. my $cc = $config{CROSS_COMPILE}.$config{CC};
  1320. open(PIPE, "$cc -Wa,--help -c -o null.$$.o -x assembler /dev/null 2>&1 |");
  1321. while(<PIPE>) {
  1322. if (m/--noexecstack/) {
  1323. push @{$config{cflags}}, "-Wa,--noexecstack";
  1324. last;
  1325. }
  1326. }
  1327. close(PIPE);
  1328. unlink("null.$$.o");
  1329. }
  1330. }
  1331. # Deal with bn_ops ###################################################
  1332. $config{bn_ll} =0;
  1333. $config{export_var_as_fn} =0;
  1334. my $def_int="unsigned int";
  1335. $config{rc4_int} =$def_int;
  1336. ($config{b64l},$config{b64},$config{b32})=(0,0,1);
  1337. my $count = 0;
  1338. foreach (sort split(/\s+/,$target{bn_ops})) {
  1339. $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/;
  1340. $config{export_var_as_fn}=1 if $_ eq 'EXPORT_VAR_AS_FN';
  1341. $config{bn_ll}=1 if $_ eq 'BN_LLONG';
  1342. $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR';
  1343. ($config{b64l},$config{b64},$config{b32})
  1344. =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT';
  1345. ($config{b64l},$config{b64},$config{b32})
  1346. =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG';
  1347. ($config{b64l},$config{b64},$config{b32})
  1348. =(0,0,1) if $_ eq 'THIRTY_TWO_BIT';
  1349. }
  1350. die "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n"
  1351. if $count > 1;
  1352. # Hack cflags for better warnings (dev option) #######################
  1353. # "Stringify" the C and C++ flags string. This permits it to be made part of
  1354. # a string and works as well on command lines.
  1355. $config{cflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x }
  1356. @{$config{cflags}} ];
  1357. $config{cxxflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x }
  1358. @{$config{cxxflags}} ] if $config{CXX};
  1359. if (defined($config{api})) {
  1360. $config{openssl_api_defines} = [ "OPENSSL_MIN_API=".$apitable->{$config{api}} ];
  1361. my $apiflag = sprintf("OPENSSL_API_COMPAT=%s", $apitable->{$config{api}});
  1362. push @{$config{defines}}, $apiflag;
  1363. }
  1364. my @strict_warnings_collection=();
  1365. if ($strict_warnings)
  1366. {
  1367. my $wopt;
  1368. my $gccver = $predefined_C{__GNUC__} // -1;
  1369. if ($gccver >= 4)
  1370. {
  1371. push @strict_warnings_collection, @gcc_devteam_warn;
  1372. push @strict_warnings_collection, @clang_devteam_warn
  1373. if (defined($predefined_C{__clang__}));
  1374. }
  1375. elsif ($config{target} =~ /^VC-/)
  1376. {
  1377. push @strict_warnings_collection, @cl_devteam_warn;
  1378. }
  1379. else
  1380. {
  1381. warn "WARNING --strict-warnings requires gcc[>=4] or gcc-alike, or MSVC"
  1382. }
  1383. }
  1384. $config{CFLAGS} = [ map { $_ eq '--ossl-strict-warnings'
  1385. ? @strict_warnings_collection
  1386. : ( $_ ) }
  1387. @{$config{CFLAGS}} ];
  1388. unless ($disabled{"crypto-mdebug-backtrace"})
  1389. {
  1390. foreach my $wopt (split /\s+/, $memleak_devteam_backtrace)
  1391. {
  1392. push @{$config{cflags}}, $wopt
  1393. unless grep { $_ eq $wopt } @{$config{cflags}};
  1394. }
  1395. if ($target =~ /^BSD-/)
  1396. {
  1397. push @{$config{ex_libs}}, "-lexecinfo";
  1398. }
  1399. }
  1400. unless ($disabled{afalgeng}) {
  1401. $config{afalgeng}="";
  1402. if (grep { $_ eq 'afalgeng' } @{$target{enable}}) {
  1403. my $minver = 4*10000 + 1*100 + 0;
  1404. if ($config{CROSS_COMPILE} eq "") {
  1405. my $verstr = `uname -r`;
  1406. my ($ma, $mi1, $mi2) = split("\\.", $verstr);
  1407. ($mi2) = $mi2 =~ /(\d+)/;
  1408. my $ver = $ma*10000 + $mi1*100 + $mi2;
  1409. if ($ver < $minver) {
  1410. disable('too-old-kernel', 'afalgeng');
  1411. } else {
  1412. push @{$config{engdirs}}, "afalg";
  1413. }
  1414. } else {
  1415. disable('cross-compiling', 'afalgeng');
  1416. }
  1417. } else {
  1418. disable('not-linux', 'afalgeng');
  1419. }
  1420. }
  1421. unless ($disabled{devcryptoeng}) {
  1422. if ($target =~ m/^BSD/) {
  1423. my $maxver = 5*100 + 7;
  1424. my $sysstr = `uname -s`;
  1425. my $verstr = `uname -r`;
  1426. $sysstr =~ s|\R$||;
  1427. $verstr =~ s|\R$||;
  1428. my ($ma, $mi, @rest) = split m|\.|, $verstr;
  1429. my $ver = $ma*100 + $mi;
  1430. if ($sysstr eq 'OpenBSD' && $ver >= $maxver) {
  1431. disable('too-new-kernel', 'devcryptoeng');
  1432. }
  1433. }
  1434. }
  1435. # Get the extra flags used when building shared libraries and modules. We
  1436. # do this late because some of them depend on %disabled.
  1437. # Make the flags to build DSOs the same as for shared libraries unless they
  1438. # are already defined
  1439. $target{module_cflags} = $target{shared_cflag} unless defined $target{module_cflags};
  1440. $target{module_cxxflags} = $target{shared_cxxflag} unless defined $target{module_cxxflags};
  1441. $target{module_ldflags} = $target{shared_ldflag} unless defined $target{module_ldflags};
  1442. {
  1443. my $shared_info_pl =
  1444. catfile(dirname($0), "Configurations", "shared-info.pl");
  1445. my %shared_info = read_eval_file($shared_info_pl);
  1446. push @{$target{_conf_fname_int}}, $shared_info_pl;
  1447. my $si = $target{shared_target};
  1448. while (ref $si ne "HASH") {
  1449. last if ! defined $si;
  1450. if (ref $si eq "CODE") {
  1451. $si = $si->();
  1452. } else {
  1453. $si = $shared_info{$si};
  1454. }
  1455. }
  1456. # Some of the 'shared_target' values don't have any entries in
  1457. # %shared_info. That's perfectly fine, AS LONG AS the build file
  1458. # template knows how to handle this. That is currently the case for
  1459. # Windows and VMS.
  1460. if (defined $si) {
  1461. # Just as above, copy certain shared_* attributes to the corresponding
  1462. # module_ attribute unless the latter is already defined
  1463. $si->{module_cflags} = $si->{shared_cflag} unless defined $si->{module_cflags};
  1464. $si->{module_cxxflags} = $si->{shared_cxxflag} unless defined $si->{module_cxxflags};
  1465. $si->{module_ldflags} = $si->{shared_ldflag} unless defined $si->{module_ldflags};
  1466. foreach (sort keys %$si) {
  1467. $target{$_} = defined $target{$_}
  1468. ? add($si->{$_})->($target{$_})
  1469. : $si->{$_};
  1470. }
  1471. }
  1472. }
  1473. # ALL MODIFICATIONS TO %disabled, %config and %target MUST BE DONE FROM HERE ON
  1474. my %disabled_info = (); # For configdata.pm
  1475. foreach my $what (sort keys %disabled) {
  1476. $config{options} .= " no-$what";
  1477. if (!grep { $what eq $_ } ( 'buildtest-c++', 'threads', 'shared', 'pic',
  1478. 'dynamic-engine', 'makedepend',
  1479. 'zlib-dynamic', 'zlib', 'sse2' )) {
  1480. (my $WHAT = uc $what) =~ s|-|_|g;
  1481. # Fix up C macro end names
  1482. $WHAT = "RMD160" if $what eq "ripemd";
  1483. # fix-up crypto/directory name(s)
  1484. $what = "ripemd" if $what eq "rmd160";
  1485. $what = "whrlpool" if $what eq "whirlpool";
  1486. my $macro = $disabled_info{$what}->{macro} = "OPENSSL_NO_$WHAT";
  1487. if ((grep { $what eq $_ } @{$config{sdirs}})
  1488. && $what ne 'async' && $what ne 'err' && $what ne 'dso') {
  1489. @{$config{sdirs}} = grep { $what ne $_} @{$config{sdirs}};
  1490. $disabled_info{$what}->{skipped} = [ catdir('crypto', $what) ];
  1491. if ($what ne 'engine') {
  1492. push @{$config{openssl_algorithm_defines}}, $macro;
  1493. } else {
  1494. @{$config{dirs}} = grep !/^engines$/, @{$config{dirs}};
  1495. push @{$disabled_info{engine}->{skipped}}, catdir('engines');
  1496. push @{$config{openssl_other_defines}}, $macro;
  1497. }
  1498. } else {
  1499. push @{$config{openssl_other_defines}}, $macro;
  1500. }
  1501. }
  1502. }
  1503. if ($disabled{"dynamic-engine"}) {
  1504. push @{$config{openssl_other_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE";
  1505. } else {
  1506. push @{$config{openssl_other_defines}}, "OPENSSL_NO_STATIC_ENGINE";
  1507. }
  1508. # If we use the unified build, collect information from build.info files
  1509. my %unified_info = ();
  1510. my $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO});
  1511. if ($builder eq "unified") {
  1512. use with_fallback qw(Text::Template);
  1513. sub cleandir {
  1514. my $base = shift;
  1515. my $dir = shift;
  1516. my $relativeto = shift || ".";
  1517. $dir = catdir($base,$dir) unless isabsolute($dir);
  1518. # Make sure the directories we're building in exists
  1519. mkpath($dir);
  1520. my $res = abs2rel(absolutedir($dir), rel2abs($relativeto));
  1521. #print STDERR "DEBUG[cleandir]: $dir , $base => $res\n";
  1522. return $res;
  1523. }
  1524. sub cleanfile {
  1525. my $base = shift;
  1526. my $file = shift;
  1527. my $relativeto = shift || ".";
  1528. $file = catfile($base,$file) unless isabsolute($file);
  1529. my $d = dirname($file);
  1530. my $f = basename($file);
  1531. # Make sure the directories we're building in exists
  1532. mkpath($d);
  1533. my $res = abs2rel(catfile(absolutedir($d), $f), rel2abs($relativeto));
  1534. #print STDERR "DEBUG[cleanfile]: $d , $f => $res\n";
  1535. return $res;
  1536. }
  1537. # Store the name of the template file we will build the build file from
  1538. # in %config. This may be useful for the build file itself.
  1539. my @build_file_template_names =
  1540. ( $builder_platform."-".$target{build_file}.".tmpl",
  1541. $target{build_file}.".tmpl" );
  1542. my @build_file_templates = ();
  1543. # First, look in the user provided directory, if given
  1544. if (defined env($local_config_envname)) {
  1545. @build_file_templates =
  1546. map {
  1547. if ($^O eq 'VMS') {
  1548. # VMS environment variables are logical names,
  1549. # which can be used as is
  1550. $local_config_envname . ':' . $_;
  1551. } else {
  1552. catfile(env($local_config_envname), $_);
  1553. }
  1554. }
  1555. @build_file_template_names;
  1556. }
  1557. # Then, look in our standard directory
  1558. push @build_file_templates,
  1559. ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir) }
  1560. @build_file_template_names );
  1561. my $build_file_template;
  1562. for $_ (@build_file_templates) {
  1563. $build_file_template = $_;
  1564. last if -f $build_file_template;
  1565. $build_file_template = undef;
  1566. }
  1567. if (!defined $build_file_template) {
  1568. die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n";
  1569. }
  1570. $config{build_file_templates}
  1571. = [ cleanfile($srcdir, catfile("Configurations", "common0.tmpl"),
  1572. $blddir),
  1573. $build_file_template,
  1574. cleanfile($srcdir, catfile("Configurations", "common.tmpl"),
  1575. $blddir) ];
  1576. my @build_infos = ( [ ".", "build.info" ] );
  1577. foreach (@{$config{dirs}}) {
  1578. push @build_infos, [ $_, "build.info" ]
  1579. if (-f catfile($srcdir, $_, "build.info"));
  1580. }
  1581. foreach (@{$config{sdirs}}) {
  1582. push @build_infos, [ catdir("crypto", $_), "build.info" ]
  1583. if (-f catfile($srcdir, "crypto", $_, "build.info"));
  1584. }
  1585. foreach (@{$config{engdirs}}) {
  1586. push @build_infos, [ catdir("engines", $_), "build.info" ]
  1587. if (-f catfile($srcdir, "engines", $_, "build.info"));
  1588. }
  1589. foreach (@{$config{tdirs}}) {
  1590. push @build_infos, [ catdir("test", $_), "build.info" ]
  1591. if (-f catfile($srcdir, "test", $_, "build.info"));
  1592. }
  1593. $config{build_infos} = [ ];
  1594. my %ordinals = ();
  1595. foreach (@build_infos) {
  1596. my $sourced = catdir($srcdir, $_->[0]);
  1597. my $buildd = catdir($blddir, $_->[0]);
  1598. mkpath($buildd);
  1599. my $f = $_->[1];
  1600. # The basic things we're trying to build
  1601. my @programs = ();
  1602. my @programs_install = ();
  1603. my @libraries = ();
  1604. my @libraries_install = ();
  1605. my @engines = ();
  1606. my @engines_install = ();
  1607. my @scripts = ();
  1608. my @scripts_install = ();
  1609. my @extra = ();
  1610. my @overrides = ();
  1611. my @intermediates = ();
  1612. my @rawlines = ();
  1613. my %sources = ();
  1614. my %shared_sources = ();
  1615. my %includes = ();
  1616. my %depends = ();
  1617. my %renames = ();
  1618. my %sharednames = ();
  1619. my %generate = ();
  1620. # We want to detect configdata.pm in the source tree, so we
  1621. # don't use it if the build tree is different.
  1622. my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir);
  1623. push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f);
  1624. my $template =
  1625. Text::Template->new(TYPE => 'FILE',
  1626. SOURCE => catfile($sourced, $f),
  1627. PREPEND => qq{use lib "$FindBin::Bin/util/perl";});
  1628. die "Something went wrong with $sourced/$f: $!\n" unless $template;
  1629. my @text =
  1630. split /^/m,
  1631. $template->fill_in(HASH => { config => \%config,
  1632. target => \%target,
  1633. disabled => \%disabled,
  1634. withargs => \%withargs,
  1635. builddir => abs2rel($buildd, $blddir),
  1636. sourcedir => abs2rel($sourced, $blddir),
  1637. buildtop => abs2rel($blddir, $blddir),
  1638. sourcetop => abs2rel($srcdir, $blddir) },
  1639. DELIMITERS => [ "{-", "-}" ]);
  1640. # The top item of this stack has the following values
  1641. # -2 positive already run and we found ELSE (following ELSIF should fail)
  1642. # -1 positive already run (skip until ENDIF)
  1643. # 0 negatives so far (if we're at a condition, check it)
  1644. # 1 last was positive (don't skip lines until next ELSE, ELSIF or ENDIF)
  1645. # 2 positive ELSE (following ELSIF should fail)
  1646. my @skip = ();
  1647. collect_information(
  1648. collect_from_array([ @text ],
  1649. qr/\\$/ => sub { my $l1 = shift; my $l2 = shift;
  1650. $l1 =~ s/\\$//; $l1.$l2 }),
  1651. # Info we're looking for
  1652. qr/^\s*IF\[((?:\\.|[^\\\]])*)\]\s*$/
  1653. => sub {
  1654. if (! @skip || $skip[$#skip] > 0) {
  1655. push @skip, !! $1;
  1656. } else {
  1657. push @skip, -1;
  1658. }
  1659. },
  1660. qr/^\s*ELSIF\[((?:\\.|[^\\\]])*)\]\s*$/
  1661. => sub { die "ELSIF out of scope" if ! @skip;
  1662. die "ELSIF following ELSE" if abs($skip[$#skip]) == 2;
  1663. $skip[$#skip] = -1 if $skip[$#skip] != 0;
  1664. $skip[$#skip] = !! $1
  1665. if $skip[$#skip] == 0; },
  1666. qr/^\s*ELSE\s*$/
  1667. => sub { die "ELSE out of scope" if ! @skip;
  1668. $skip[$#skip] = -2 if $skip[$#skip] != 0;
  1669. $skip[$#skip] = 2 if $skip[$#skip] == 0; },
  1670. qr/^\s*ENDIF\s*$/
  1671. => sub { die "ENDIF out of scope" if ! @skip;
  1672. pop @skip; },
  1673. qr/^\s*PROGRAMS(_NO_INST)?\s*=\s*(.*)\s*$/
  1674. => sub {
  1675. if (!@skip || $skip[$#skip] > 0) {
  1676. my $install = $1;
  1677. my @x = tokenize($2);
  1678. push @programs, @x;
  1679. push @programs_install, @x unless $install;
  1680. }
  1681. },
  1682. qr/^\s*LIBS(_NO_INST)?\s*=\s*(.*)\s*$/
  1683. => sub {
  1684. if (!@skip || $skip[$#skip] > 0) {
  1685. my $install = $1;
  1686. my @x = tokenize($2);
  1687. push @libraries, @x;
  1688. push @libraries_install, @x unless $install;
  1689. }
  1690. },
  1691. qr/^\s*ENGINES(_NO_INST)?\s*=\s*(.*)\s*$/
  1692. => sub {
  1693. if (!@skip || $skip[$#skip] > 0) {
  1694. my $install = $1;
  1695. my @x = tokenize($2);
  1696. push @engines, @x;
  1697. push @engines_install, @x unless $install;
  1698. }
  1699. },
  1700. qr/^\s*SCRIPTS(_NO_INST)?\s*=\s*(.*)\s*$/
  1701. => sub {
  1702. if (!@skip || $skip[$#skip] > 0) {
  1703. my $install = $1;
  1704. my @x = tokenize($2);
  1705. push @scripts, @x;
  1706. push @scripts_install, @x unless $install;
  1707. }
  1708. },
  1709. qr/^\s*EXTRA\s*=\s*(.*)\s*$/
  1710. => sub { push @extra, tokenize($1)
  1711. if !@skip || $skip[$#skip] > 0 },
  1712. qr/^\s*OVERRIDES\s*=\s*(.*)\s*$/
  1713. => sub { push @overrides, tokenize($1)
  1714. if !@skip || $skip[$#skip] > 0 },
  1715. qr/^\s*ORDINALS\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/,
  1716. => sub { push @{$ordinals{$1}}, tokenize($2)
  1717. if !@skip || $skip[$#skip] > 0 },
  1718. qr/^\s*SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1719. => sub { push @{$sources{$1}}, tokenize($2)
  1720. if !@skip || $skip[$#skip] > 0 },
  1721. qr/^\s*SHARED_SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1722. => sub { push @{$shared_sources{$1}}, tokenize($2)
  1723. if !@skip || $skip[$#skip] > 0 },
  1724. qr/^\s*INCLUDE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1725. => sub { push @{$includes{$1}}, tokenize($2)
  1726. if !@skip || $skip[$#skip] > 0 },
  1727. qr/^\s*DEPEND\[((?:\\.|[^\\\]])*)\]\s*=\s*(.*)\s*$/
  1728. => sub { push @{$depends{$1}}, tokenize($2)
  1729. if !@skip || $skip[$#skip] > 0 },
  1730. qr/^\s*GENERATE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1731. => sub { push @{$generate{$1}}, $2
  1732. if !@skip || $skip[$#skip] > 0 },
  1733. qr/^\s*RENAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1734. => sub { push @{$renames{$1}}, tokenize($2)
  1735. if !@skip || $skip[$#skip] > 0 },
  1736. qr/^\s*SHARED_NAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1737. => sub { push @{$sharednames{$1}}, tokenize($2)
  1738. if !@skip || $skip[$#skip] > 0 },
  1739. qr/^\s*BEGINRAW\[((?:\\.|[^\\\]])+)\]\s*$/
  1740. => sub {
  1741. my $lineiterator = shift;
  1742. my $target_kind = $1;
  1743. while (defined $lineiterator->()) {
  1744. s|\R$||;
  1745. if (/^\s*ENDRAW\[((?:\\.|[^\\\]])+)\]\s*$/) {
  1746. die "ENDRAW doesn't match BEGINRAW"
  1747. if $1 ne $target_kind;
  1748. last;
  1749. }
  1750. next if @skip && $skip[$#skip] <= 0;
  1751. push @rawlines, $_
  1752. if ($target_kind eq $target{build_file}
  1753. || $target_kind eq $target{build_file}."(".$builder_platform.")");
  1754. }
  1755. },
  1756. qr/^\s*(?:#.*)?$/ => sub { },
  1757. "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" },
  1758. "BEFORE" => sub {
  1759. if ($buildinfo_debug) {
  1760. print STDERR "DEBUG: Parsing ",join(" ", @_),"\n";
  1761. print STDERR "DEBUG: ... before parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1762. }
  1763. },
  1764. "AFTER" => sub {
  1765. if ($buildinfo_debug) {
  1766. print STDERR "DEBUG: .... after parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1767. }
  1768. },
  1769. );
  1770. die "runaway IF?" if (@skip);
  1771. foreach (keys %renames) {
  1772. die "$_ renamed to more than one thing: "
  1773. ,join(" ", @{$renames{$_}}),"\n"
  1774. if scalar @{$renames{$_}} > 1;
  1775. my $dest = cleanfile($buildd, $_, $blddir);
  1776. my $to = cleanfile($buildd, $renames{$_}->[0], $blddir);
  1777. die "$dest renamed to more than one thing: "
  1778. ,$unified_info{rename}->{$dest}, $to
  1779. unless !defined($unified_info{rename}->{$dest})
  1780. or $unified_info{rename}->{$dest} eq $to;
  1781. $unified_info{rename}->{$dest} = $to;
  1782. }
  1783. foreach (@programs) {
  1784. my $program = cleanfile($buildd, $_, $blddir);
  1785. if ($unified_info{rename}->{$program}) {
  1786. $program = $unified_info{rename}->{$program};
  1787. }
  1788. $unified_info{programs}->{$program} = 1;
  1789. }
  1790. foreach (@programs_install) {
  1791. my $program = cleanfile($buildd, $_, $blddir);
  1792. if ($unified_info{rename}->{$program}) {
  1793. $program = $unified_info{rename}->{$program};
  1794. }
  1795. $unified_info{install}->{programs}->{$program} = 1;
  1796. }
  1797. foreach (@libraries) {
  1798. my $library = cleanfile($buildd, $_, $blddir);
  1799. if ($unified_info{rename}->{$library}) {
  1800. $library = $unified_info{rename}->{$library};
  1801. }
  1802. $unified_info{libraries}->{$library} = 1;
  1803. }
  1804. foreach (@libraries_install) {
  1805. my $library = cleanfile($buildd, $_, $blddir);
  1806. if ($unified_info{rename}->{$library}) {
  1807. $library = $unified_info{rename}->{$library};
  1808. }
  1809. $unified_info{install}->{libraries}->{$library} = 1;
  1810. }
  1811. die <<"EOF" if scalar @engines and !$config{dynamic_engines};
  1812. ENGINES can only be used if configured with 'dynamic-engine'.
  1813. This is usually a fault in a build.info file.
  1814. EOF
  1815. foreach (@engines) {
  1816. my $library = cleanfile($buildd, $_, $blddir);
  1817. if ($unified_info{rename}->{$library}) {
  1818. $library = $unified_info{rename}->{$library};
  1819. }
  1820. $unified_info{engines}->{$library} = 1;
  1821. }
  1822. foreach (@engines_install) {
  1823. my $library = cleanfile($buildd, $_, $blddir);
  1824. if ($unified_info{rename}->{$library}) {
  1825. $library = $unified_info{rename}->{$library};
  1826. }
  1827. $unified_info{install}->{engines}->{$library} = 1;
  1828. }
  1829. foreach (@scripts) {
  1830. my $script = cleanfile($buildd, $_, $blddir);
  1831. if ($unified_info{rename}->{$script}) {
  1832. $script = $unified_info{rename}->{$script};
  1833. }
  1834. $unified_info{scripts}->{$script} = 1;
  1835. }
  1836. foreach (@scripts_install) {
  1837. my $script = cleanfile($buildd, $_, $blddir);
  1838. if ($unified_info{rename}->{$script}) {
  1839. $script = $unified_info{rename}->{$script};
  1840. }
  1841. $unified_info{install}->{scripts}->{$script} = 1;
  1842. }
  1843. foreach (@extra) {
  1844. my $extra = cleanfile($buildd, $_, $blddir);
  1845. $unified_info{extra}->{$extra} = 1;
  1846. }
  1847. foreach (@overrides) {
  1848. my $override = cleanfile($buildd, $_, $blddir);
  1849. $unified_info{overrides}->{$override} = 1;
  1850. }
  1851. push @{$unified_info{rawlines}}, @rawlines;
  1852. unless ($disabled{shared}) {
  1853. # Check sharednames.
  1854. foreach (keys %sharednames) {
  1855. my $dest = cleanfile($buildd, $_, $blddir);
  1856. if ($unified_info{rename}->{$dest}) {
  1857. $dest = $unified_info{rename}->{$dest};
  1858. }
  1859. die "shared_name for $dest with multiple values: "
  1860. ,join(" ", @{$sharednames{$_}}),"\n"
  1861. if scalar @{$sharednames{$_}} > 1;
  1862. my $to = cleanfile($buildd, $sharednames{$_}->[0], $blddir);
  1863. die "shared_name found for a library $dest that isn't defined\n"
  1864. unless $unified_info{libraries}->{$dest};
  1865. die "shared_name for $dest with multiple values: "
  1866. ,$unified_info{sharednames}->{$dest}, ", ", $to
  1867. unless !defined($unified_info{sharednames}->{$dest})
  1868. or $unified_info{sharednames}->{$dest} eq $to;
  1869. $unified_info{sharednames}->{$dest} = $to;
  1870. }
  1871. # Additionally, we set up sharednames for libraries that don't
  1872. # have any, as themselves. Only for libraries that aren't
  1873. # explicitly static.
  1874. foreach (grep !/\.a$/, keys %{$unified_info{libraries}}) {
  1875. if (!defined $unified_info{sharednames}->{$_}) {
  1876. $unified_info{sharednames}->{$_} = $_
  1877. }
  1878. }
  1879. # Check that we haven't defined any library as both shared and
  1880. # explicitly static. That is forbidden.
  1881. my @doubles = ();
  1882. foreach (grep /\.a$/, keys %{$unified_info{libraries}}) {
  1883. (my $l = $_) =~ s/\.a$//;
  1884. push @doubles, $l if defined $unified_info{sharednames}->{$l};
  1885. }
  1886. die "these libraries are both explicitly static and shared:\n ",
  1887. join(" ", @doubles), "\n"
  1888. if @doubles;
  1889. }
  1890. foreach (keys %sources) {
  1891. my $dest = $_;
  1892. my $ddest = cleanfile($buildd, $_, $blddir);
  1893. if ($unified_info{rename}->{$ddest}) {
  1894. $ddest = $unified_info{rename}->{$ddest};
  1895. }
  1896. foreach (@{$sources{$dest}}) {
  1897. my $s = cleanfile($sourced, $_, $blddir);
  1898. # If it isn't in the source tree, we assume it's generated
  1899. # in the build tree
  1900. if ($s eq $src_configdata || ! -f $s || $generate{$_}) {
  1901. $s = cleanfile($buildd, $_, $blddir);
  1902. }
  1903. # We recognise C++, C and asm files
  1904. if ($s =~ /\.(cc|cpp|c|s|S)$/) {
  1905. my $o = $_;
  1906. $o =~ s/\.[csS]$/.o/; # C and assembler
  1907. $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
  1908. $o = cleanfile($buildd, $o, $blddir);
  1909. $unified_info{sources}->{$ddest}->{$o} = 1;
  1910. $unified_info{sources}->{$o}->{$s} = 1;
  1911. } elsif ($s =~ /\.rc$/) {
  1912. # We also recognise resource files
  1913. my $o = $_;
  1914. $o =~ s/\.rc$/.res/; # Resource configuration
  1915. my $o = cleanfile($buildd, $o, $blddir);
  1916. $unified_info{sources}->{$ddest}->{$o} = 1;
  1917. $unified_info{sources}->{$o}->{$s} = 1;
  1918. } else {
  1919. $unified_info{sources}->{$ddest}->{$s} = 1;
  1920. }
  1921. }
  1922. }
  1923. foreach (keys %shared_sources) {
  1924. my $dest = $_;
  1925. my $ddest = cleanfile($buildd, $_, $blddir);
  1926. if ($unified_info{rename}->{$ddest}) {
  1927. $ddest = $unified_info{rename}->{$ddest};
  1928. }
  1929. foreach (@{$shared_sources{$dest}}) {
  1930. my $s = cleanfile($sourced, $_, $blddir);
  1931. # If it isn't in the source tree, we assume it's generated
  1932. # in the build tree
  1933. if ($s eq $src_configdata || ! -f $s || $generate{$_}) {
  1934. $s = cleanfile($buildd, $_, $blddir);
  1935. }
  1936. if ($s =~ /\.(cc|cpp|c|s|S)$/) {
  1937. # We recognise C++, C and asm files
  1938. my $o = $_;
  1939. $o =~ s/\.[csS]$/.o/; # C and assembler
  1940. $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
  1941. $o = cleanfile($buildd, $o, $blddir);
  1942. $unified_info{shared_sources}->{$ddest}->{$o} = 1;
  1943. $unified_info{sources}->{$o}->{$s} = 1;
  1944. } elsif ($s =~ /\.rc$/) {
  1945. # We also recognise resource files
  1946. my $o = $_;
  1947. $o =~ s/\.rc$/.res/; # Resource configuration
  1948. my $o = cleanfile($buildd, $o, $blddir);
  1949. $unified_info{shared_sources}->{$ddest}->{$o} = 1;
  1950. $unified_info{sources}->{$o}->{$s} = 1;
  1951. } elsif ($s =~ /\.(def|map|opt)$/) {
  1952. # We also recognise .def / .map / .opt files
  1953. # We know they are generated files
  1954. my $def = cleanfile($buildd, $s, $blddir);
  1955. $unified_info{shared_sources}->{$ddest}->{$def} = 1;
  1956. } else {
  1957. die "unrecognised source file type for shared library: $s\n";
  1958. }
  1959. }
  1960. }
  1961. foreach (keys %generate) {
  1962. my $dest = $_;
  1963. my $ddest = cleanfile($buildd, $_, $blddir);
  1964. if ($unified_info{rename}->{$ddest}) {
  1965. $ddest = $unified_info{rename}->{$ddest};
  1966. }
  1967. die "more than one generator for $dest: "
  1968. ,join(" ", @{$generate{$_}}),"\n"
  1969. if scalar @{$generate{$_}} > 1;
  1970. my @generator = split /\s+/, $generate{$dest}->[0];
  1971. $generator[0] = cleanfile($sourced, $generator[0], $blddir),
  1972. $unified_info{generate}->{$ddest} = [ @generator ];
  1973. }
  1974. foreach (keys %depends) {
  1975. my $dest = $_;
  1976. my $ddest = $dest eq "" ? "" : cleanfile($sourced, $_, $blddir);
  1977. # If the destination doesn't exist in source, it can only be
  1978. # a generated file in the build tree.
  1979. if ($ddest ne "" && ($ddest eq $src_configdata || ! -f $ddest)) {
  1980. $ddest = cleanfile($buildd, $_, $blddir);
  1981. if ($unified_info{rename}->{$ddest}) {
  1982. $ddest = $unified_info{rename}->{$ddest};
  1983. }
  1984. }
  1985. foreach (@{$depends{$dest}}) {
  1986. my $d = cleanfile($sourced, $_, $blddir);
  1987. # If we know it's generated, or assume it is because we can't
  1988. # find it in the source tree, we set file we depend on to be
  1989. # in the build tree rather than the source tree, and assume
  1990. # and that there are lines to build it in a BEGINRAW..ENDRAW
  1991. # section or in the Makefile template.
  1992. if ($d eq $src_configdata
  1993. || ! -f $d
  1994. || (grep { $d eq $_ }
  1995. map { cleanfile($srcdir, $_, $blddir) }
  1996. grep { /\.h$/ } keys %{$unified_info{generate}})) {
  1997. $d = cleanfile($buildd, $_, $blddir);
  1998. }
  1999. # Take note if the file to depend on is being renamed
  2000. # Take extra care with files ending with .a, they should
  2001. # be treated without that extension, and the extension
  2002. # should be added back after treatment.
  2003. $d =~ /(\.a)?$/;
  2004. my $e = $1 // "";
  2005. $d = $`;
  2006. if ($unified_info{rename}->{$d}) {
  2007. $d = $unified_info{rename}->{$d};
  2008. }
  2009. $d .= $e;
  2010. $unified_info{depends}->{$ddest}->{$d} = 1;
  2011. }
  2012. }
  2013. foreach (keys %includes) {
  2014. my $dest = $_;
  2015. my $ddest = cleanfile($sourced, $_, $blddir);
  2016. # If the destination doesn't exist in source, it can only be
  2017. # a generated file in the build tree.
  2018. if ($ddest eq $src_configdata || ! -f $ddest) {
  2019. $ddest = cleanfile($buildd, $_, $blddir);
  2020. if ($unified_info{rename}->{$ddest}) {
  2021. $ddest = $unified_info{rename}->{$ddest};
  2022. }
  2023. }
  2024. foreach (@{$includes{$dest}}) {
  2025. my $is = cleandir($sourced, $_, $blddir);
  2026. my $ib = cleandir($buildd, $_, $blddir);
  2027. push @{$unified_info{includes}->{$ddest}->{source}}, $is
  2028. unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}};
  2029. push @{$unified_info{includes}->{$ddest}->{build}}, $ib
  2030. unless grep { $_ eq $ib } @{$unified_info{includes}->{$ddest}->{build}};
  2031. }
  2032. }
  2033. }
  2034. my $ordinals_text = join(', ', sort keys %ordinals);
  2035. warn <<"EOF" if $ordinals_text;
  2036. WARNING: ORDINALS were specified for $ordinals_text
  2037. They are ignored and should be replaced with a combination of GENERATE,
  2038. DEPEND and SHARED_SOURCE.
  2039. EOF
  2040. # Massage the result
  2041. # If the user configured no-shared, we allow no shared sources
  2042. if ($disabled{shared}) {
  2043. foreach (keys %{$unified_info{shared_sources}}) {
  2044. foreach (keys %{$unified_info{shared_sources}->{$_}}) {
  2045. delete $unified_info{sources}->{$_};
  2046. }
  2047. }
  2048. $unified_info{shared_sources} = {};
  2049. }
  2050. # If we depend on a header file or a perl module, add an inclusion of
  2051. # its directory to allow smoothe inclusion
  2052. foreach my $dest (keys %{$unified_info{depends}}) {
  2053. next if $dest eq "";
  2054. foreach my $d (keys %{$unified_info{depends}->{$dest}}) {
  2055. next unless $d =~ /\.(h|pm)$/;
  2056. my $i = dirname($d);
  2057. my $spot =
  2058. $d eq "configdata.pm" || defined($unified_info{generate}->{$d})
  2059. ? 'build' : 'source';
  2060. push @{$unified_info{includes}->{$dest}->{$spot}}, $i
  2061. unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{$spot}};
  2062. }
  2063. }
  2064. # Trickle down includes placed on libraries, engines and programs to
  2065. # their sources (i.e. object files)
  2066. foreach my $dest (keys %{$unified_info{engines}},
  2067. keys %{$unified_info{libraries}},
  2068. keys %{$unified_info{programs}}) {
  2069. foreach my $k (("source", "build")) {
  2070. next unless defined($unified_info{includes}->{$dest}->{$k});
  2071. my @incs = reverse @{$unified_info{includes}->{$dest}->{$k}};
  2072. foreach my $obj (grep /\.o$/,
  2073. (keys %{$unified_info{sources}->{$dest} // {}},
  2074. keys %{$unified_info{shared_sources}->{$dest} // {}})) {
  2075. foreach my $inc (@incs) {
  2076. unshift @{$unified_info{includes}->{$obj}->{$k}}, $inc
  2077. unless grep { $_ eq $inc } @{$unified_info{includes}->{$obj}->{$k}};
  2078. }
  2079. }
  2080. }
  2081. delete $unified_info{includes}->{$dest};
  2082. }
  2083. ### Make unified_info a bit more efficient
  2084. # One level structures
  2085. foreach (("programs", "libraries", "engines", "scripts", "extra", "overrides")) {
  2086. $unified_info{$_} = [ sort keys %{$unified_info{$_}} ];
  2087. }
  2088. # Two level structures
  2089. foreach my $l1 (("install", "sources", "shared_sources", "ldadd", "depends")) {
  2090. foreach my $l2 (sort keys %{$unified_info{$l1}}) {
  2091. $unified_info{$l1}->{$l2} =
  2092. [ sort keys %{$unified_info{$l1}->{$l2}} ];
  2093. }
  2094. }
  2095. # Includes
  2096. foreach my $dest (sort keys %{$unified_info{includes}}) {
  2097. if (defined($unified_info{includes}->{$dest}->{build})) {
  2098. my @source_includes = ();
  2099. @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} )
  2100. if defined($unified_info{includes}->{$dest}->{source});
  2101. $unified_info{includes}->{$dest} =
  2102. [ @{$unified_info{includes}->{$dest}->{build}} ];
  2103. foreach my $inc (@source_includes) {
  2104. push @{$unified_info{includes}->{$dest}}, $inc
  2105. unless grep { $_ eq $inc } @{$unified_info{includes}->{$dest}};
  2106. }
  2107. } else {
  2108. $unified_info{includes}->{$dest} =
  2109. [ @{$unified_info{includes}->{$dest}->{source}} ];
  2110. }
  2111. }
  2112. # For convenience collect information regarding directories where
  2113. # files are generated, those generated files and the end product
  2114. # they end up in where applicable. Then, add build rules for those
  2115. # directories
  2116. my %loopinfo = ( "lib" => [ @{$unified_info{libraries}} ],
  2117. "dso" => [ @{$unified_info{engines}} ],
  2118. "bin" => [ @{$unified_info{programs}} ],
  2119. "script" => [ @{$unified_info{scripts}} ] );
  2120. foreach my $type (keys %loopinfo) {
  2121. foreach my $product (@{$loopinfo{$type}}) {
  2122. my %dirs = ();
  2123. my $pd = dirname($product);
  2124. foreach (@{$unified_info{sources}->{$product} // []},
  2125. @{$unified_info{shared_sources}->{$product} // []}) {
  2126. my $d = dirname($_);
  2127. # We don't want to create targets for source directories
  2128. # when building out of source
  2129. next if ($config{sourcedir} ne $config{builddir}
  2130. && $d =~ m|^\Q$config{sourcedir}\E|);
  2131. # We already have a "test" target, and the current directory
  2132. # is just silly to make a target for
  2133. next if $d eq "test" || $d eq ".";
  2134. $dirs{$d} = 1;
  2135. push @{$unified_info{dirinfo}->{$d}->{deps}}, $_
  2136. if $d ne $pd;
  2137. }
  2138. foreach (keys %dirs) {
  2139. push @{$unified_info{dirinfo}->{$_}->{products}->{$type}},
  2140. $product;
  2141. }
  2142. }
  2143. }
  2144. }
  2145. # For the schemes that need it, we provide the old *_obj configs
  2146. # from the *_asm_obj ones
  2147. foreach (grep /_(asm|aux)_src$/, keys %target) {
  2148. my $src = $_;
  2149. (my $obj = $_) =~ s/_(asm|aux)_src$/_obj/;
  2150. $target{$obj} = $target{$src};
  2151. $target{$obj} =~ s/\.[csS]\b/.o/g; # C and assembler
  2152. $target{$obj} =~ s/\.(cc|cpp)\b/_cc.o/g; # C++
  2153. }
  2154. # Write down our configuration where it fits #########################
  2155. print "Creating configdata.pm\n";
  2156. open(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n";
  2157. print OUT <<"EOF";
  2158. #! $config{HASHBANGPERL}
  2159. package configdata;
  2160. use strict;
  2161. use warnings;
  2162. use Exporter;
  2163. #use vars qw(\@ISA \@EXPORT);
  2164. our \@ISA = qw(Exporter);
  2165. our \@EXPORT = qw(\%config \%target \%disabled \%withargs \%unified_info \@disablables);
  2166. EOF
  2167. print OUT "our %config = (\n";
  2168. foreach (sort keys %config) {
  2169. if (ref($config{$_}) eq "ARRAY") {
  2170. print OUT " ", $_, " => [ ", join(", ",
  2171. map { quotify("perl", $_) }
  2172. @{$config{$_}}), " ],\n";
  2173. } elsif (ref($config{$_}) eq "HASH") {
  2174. print OUT " ", $_, " => {";
  2175. if (scalar keys %{$config{$_}} > 0) {
  2176. print OUT "\n";
  2177. foreach my $key (sort keys %{$config{$_}}) {
  2178. print OUT " ",
  2179. join(" => ",
  2180. quotify("perl", $key),
  2181. defined $config{$_}->{$key}
  2182. ? quotify("perl", $config{$_}->{$key})
  2183. : "undef");
  2184. print OUT ",\n";
  2185. }
  2186. print OUT " ";
  2187. }
  2188. print OUT "},\n";
  2189. } else {
  2190. print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n"
  2191. }
  2192. }
  2193. print OUT <<"EOF";
  2194. );
  2195. EOF
  2196. print OUT "our %target = (\n";
  2197. foreach (sort keys %target) {
  2198. if (ref($target{$_}) eq "ARRAY") {
  2199. print OUT " ", $_, " => [ ", join(", ",
  2200. map { quotify("perl", $_) }
  2201. @{$target{$_}}), " ],\n";
  2202. } else {
  2203. print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n"
  2204. }
  2205. }
  2206. print OUT <<"EOF";
  2207. );
  2208. EOF
  2209. print OUT "our \%available_protocols = (\n";
  2210. print OUT " tls => [ ", join(", ", map { quotify("perl", $_) } @tls), " ],\n";
  2211. print OUT " dtls => [ ", join(", ", map { quotify("perl", $_) } @dtls), " ],\n";
  2212. print OUT <<"EOF";
  2213. );
  2214. EOF
  2215. print OUT "our \@disablables = (\n";
  2216. foreach (@disablables) {
  2217. print OUT " ", quotify("perl", $_), ",\n";
  2218. }
  2219. print OUT <<"EOF";
  2220. );
  2221. EOF
  2222. print OUT "our \%disabled = (\n";
  2223. foreach (sort keys %disabled) {
  2224. print OUT " ", quotify("perl", $_), " => ", quotify("perl", $disabled{$_}), ",\n";
  2225. }
  2226. print OUT <<"EOF";
  2227. );
  2228. EOF
  2229. print OUT "our %withargs = (\n";
  2230. foreach (sort keys %withargs) {
  2231. if (ref($withargs{$_}) eq "ARRAY") {
  2232. print OUT " ", $_, " => [ ", join(", ",
  2233. map { quotify("perl", $_) }
  2234. @{$withargs{$_}}), " ],\n";
  2235. } else {
  2236. print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n"
  2237. }
  2238. }
  2239. print OUT <<"EOF";
  2240. );
  2241. EOF
  2242. if ($builder eq "unified") {
  2243. my $recurse;
  2244. $recurse = sub {
  2245. my $indent = shift;
  2246. foreach (@_) {
  2247. if (ref $_ eq "ARRAY") {
  2248. print OUT " "x$indent, "[\n";
  2249. foreach (@$_) {
  2250. $recurse->($indent + 4, $_);
  2251. }
  2252. print OUT " "x$indent, "],\n";
  2253. } elsif (ref $_ eq "HASH") {
  2254. my %h = %$_;
  2255. print OUT " "x$indent, "{\n";
  2256. foreach (sort keys %h) {
  2257. if (ref $h{$_} eq "") {
  2258. print OUT " "x($indent + 4), quotify("perl", $_), " => ", quotify("perl", $h{$_}), ",\n";
  2259. } else {
  2260. print OUT " "x($indent + 4), quotify("perl", $_), " =>\n";
  2261. $recurse->($indent + 8, $h{$_});
  2262. }
  2263. }
  2264. print OUT " "x$indent, "},\n";
  2265. } else {
  2266. print OUT " "x$indent, quotify("perl", $_), ",\n";
  2267. }
  2268. }
  2269. };
  2270. print OUT "our %unified_info = (\n";
  2271. foreach (sort keys %unified_info) {
  2272. if (ref $unified_info{$_} eq "") {
  2273. print OUT " "x4, quotify("perl", $_), " => ", quotify("perl", $unified_info{$_}), ",\n";
  2274. } else {
  2275. print OUT " "x4, quotify("perl", $_), " =>\n";
  2276. $recurse->(8, $unified_info{$_});
  2277. }
  2278. }
  2279. print OUT <<"EOF";
  2280. );
  2281. EOF
  2282. }
  2283. print OUT
  2284. "# The following data is only used when this files is use as a script\n";
  2285. print OUT "my \@makevars = (\n";
  2286. foreach (sort keys %user) {
  2287. print OUT " '",$_,"',\n";
  2288. }
  2289. print OUT ");\n";
  2290. print OUT "my \%disabled_info = (\n";
  2291. foreach my $what (sort keys %disabled_info) {
  2292. print OUT " '$what' => {\n";
  2293. foreach my $info (sort keys %{$disabled_info{$what}}) {
  2294. if (ref $disabled_info{$what}->{$info} eq 'ARRAY') {
  2295. print OUT " $info => [ ",
  2296. join(', ', map { "'$_'" } @{$disabled_info{$what}->{$info}}),
  2297. " ],\n";
  2298. } else {
  2299. print OUT " $info => '", $disabled_info{$what}->{$info},
  2300. "',\n";
  2301. }
  2302. }
  2303. print OUT " },\n";
  2304. }
  2305. print OUT ");\n";
  2306. print OUT 'my @user_crossable = qw( ', join (' ', @user_crossable), " );\n";
  2307. print OUT << 'EOF';
  2308. # If run directly, we can give some answers, and even reconfigure
  2309. unless (caller) {
  2310. use Getopt::Long;
  2311. use File::Spec::Functions;
  2312. use File::Basename;
  2313. use Pod::Usage;
  2314. my $here = dirname($0);
  2315. my $dump = undef;
  2316. my $cmdline = undef;
  2317. my $options = undef;
  2318. my $target = undef;
  2319. my $envvars = undef;
  2320. my $makevars = undef;
  2321. my $buildparams = undef;
  2322. my $reconf = undef;
  2323. my $verbose = undef;
  2324. my $help = undef;
  2325. my $man = undef;
  2326. GetOptions('dump|d' => \$dump,
  2327. 'command-line|c' => \$cmdline,
  2328. 'options|o' => \$options,
  2329. 'target|t' => \$target,
  2330. 'environment|e' => \$envvars,
  2331. 'make-variables|m' => \$makevars,
  2332. 'build-parameters|b' => \$buildparams,
  2333. 'reconfigure|reconf|r' => \$reconf,
  2334. 'verbose|v' => \$verbose,
  2335. 'help' => \$help,
  2336. 'man' => \$man)
  2337. or die "Errors in command line arguments\n";
  2338. unless ($dump || $cmdline || $options || $target || $envvars || $makevars
  2339. || $buildparams || $reconf || $verbose || $help || $man) {
  2340. print STDERR <<"_____";
  2341. You must give at least one option.
  2342. For more information, do '$0 --help'
  2343. _____
  2344. exit(2);
  2345. }
  2346. if ($help) {
  2347. pod2usage(-exitval => 0,
  2348. -verbose => 1);
  2349. }
  2350. if ($man) {
  2351. pod2usage(-exitval => 0,
  2352. -verbose => 2);
  2353. }
  2354. if ($dump || $cmdline) {
  2355. print "\nCommand line (with current working directory = $here):\n\n";
  2356. print ' ',join(' ',
  2357. $config{PERL},
  2358. catfile($config{sourcedir}, 'Configure'),
  2359. @{$config{perlargv}}), "\n";
  2360. print "\nPerl information:\n\n";
  2361. print ' ',$config{perl_cmd},"\n";
  2362. print ' ',$config{perl_version},' for ',$config{perl_archname},"\n";
  2363. }
  2364. if ($dump || $options) {
  2365. my $longest = 0;
  2366. my $longest2 = 0;
  2367. foreach my $what (@disablables) {
  2368. $longest = length($what) if $longest < length($what);
  2369. $longest2 = length($disabled{$what})
  2370. if $disabled{$what} && $longest2 < length($disabled{$what});
  2371. }
  2372. print "\nEnabled features:\n\n";
  2373. foreach my $what (@disablables) {
  2374. print " $what\n"
  2375. unless grep { $_ =~ /^${what}$/ } keys %disabled;
  2376. }
  2377. print "\nDisabled features:\n\n";
  2378. foreach my $what (@disablables) {
  2379. my @what2 = grep { $_ =~ /^${what}$/ } keys %disabled;
  2380. my $what3 = $what2[0];
  2381. if ($what3) {
  2382. print " $what3", ' ' x ($longest - length($what3) + 1),
  2383. "[$disabled{$what3}]", ' ' x ($longest2 - length($disabled{$what3}) + 1);
  2384. print $disabled_info{$what3}->{macro}
  2385. if $disabled_info{$what3}->{macro};
  2386. print ' (skip ',
  2387. join(', ', @{$disabled_info{$what3}->{skipped}}),
  2388. ')'
  2389. if $disabled_info{$what3}->{skipped};
  2390. print "\n";
  2391. }
  2392. }
  2393. }
  2394. if ($dump || $target) {
  2395. print "\nConfig target attributes:\n\n";
  2396. foreach (sort keys %target) {
  2397. next if $_ =~ m|^_| || $_ eq 'template';
  2398. my $quotify = sub {
  2399. map { (my $x = $_) =~ s|([\\\$\@"])|\\$1|g; "\"$x\""} @_;
  2400. };
  2401. print ' ', $_, ' => ';
  2402. if (ref($target{$_}) eq "ARRAY") {
  2403. print '[ ', join(', ', $quotify->(@{$target{$_}})), " ],\n";
  2404. } else {
  2405. print $quotify->($target{$_}), ",\n"
  2406. }
  2407. }
  2408. }
  2409. if ($dump || $envvars) {
  2410. print "\nRecorded environment:\n\n";
  2411. foreach (sort keys %{$config{perlenv}}) {
  2412. print ' ',$_,' = ',($config{perlenv}->{$_} || ''),"\n";
  2413. }
  2414. }
  2415. if ($dump || $makevars) {
  2416. print "\nMakevars:\n\n";
  2417. foreach my $var (@makevars) {
  2418. my $prefix = '';
  2419. $prefix = $config{CROSS_COMPILE}
  2420. if grep { $var eq $_ } @user_crossable;
  2421. $prefix //= '';
  2422. print ' ',$var,' ' x (16 - length $var),'= ',
  2423. (ref $config{$var} eq 'ARRAY'
  2424. ? join(' ', @{$config{$var}})
  2425. : $prefix.$config{$var}),
  2426. "\n"
  2427. if defined $config{$var};
  2428. }
  2429. my @buildfile = ($config{builddir}, $config{build_file});
  2430. unshift @buildfile, $here
  2431. unless file_name_is_absolute($config{builddir});
  2432. my $buildfile = canonpath(catdir(@buildfile));
  2433. print <<"_____";
  2434. NOTE: These variables only represent the configuration view. The build file
  2435. template may have processed these variables further, please have a look at the
  2436. build file for more exact data:
  2437. $buildfile
  2438. _____
  2439. }
  2440. if ($dump || $buildparams) {
  2441. my @buildfile = ($config{builddir}, $config{build_file});
  2442. unshift @buildfile, $here
  2443. unless file_name_is_absolute($config{builddir});
  2444. print "\nbuild file:\n\n";
  2445. print " ", canonpath(catfile(@buildfile)),"\n";
  2446. print "\nbuild file templates:\n\n";
  2447. foreach (@{$config{build_file_templates}}) {
  2448. my @tmpl = ($_);
  2449. unshift @tmpl, $here
  2450. unless file_name_is_absolute($config{sourcedir});
  2451. print ' ',canonpath(catfile(@tmpl)),"\n";
  2452. }
  2453. }
  2454. if ($reconf) {
  2455. if ($verbose) {
  2456. print 'Reconfiguring with: ', join(' ',@{$config{perlargv}}), "\n";
  2457. foreach (sort keys %{$config{perlenv}}) {
  2458. print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n";
  2459. }
  2460. }
  2461. chdir $here;
  2462. exec $^X,catfile($config{sourcedir}, 'Configure'),'reconf';
  2463. }
  2464. }
  2465. 1;
  2466. __END__
  2467. =head1 NAME
  2468. configdata.pm - configuration data for OpenSSL builds
  2469. =head1 SYNOPSIS
  2470. Interactive:
  2471. perl configdata.pm [options]
  2472. As data bank module:
  2473. use configdata;
  2474. =head1 DESCRIPTION
  2475. This module can be used in two modes, interactively and as a module containing
  2476. all the data recorded by OpenSSL's Configure script.
  2477. When used interactively, simply run it as any perl script, with at least one
  2478. option, and you will get the information you ask for. See L</OPTIONS> below.
  2479. When loaded as a module, you get a few databanks with useful information to
  2480. perform build related tasks. The databanks are:
  2481. %config Configured things.
  2482. %target The OpenSSL config target with all inheritances
  2483. resolved.
  2484. %disabled The features that are disabled.
  2485. @disablables The list of features that can be disabled.
  2486. %withargs All data given through --with-THING options.
  2487. %unified_info All information that was computed from the build.info
  2488. files.
  2489. =head1 OPTIONS
  2490. =over 4
  2491. =item B<--help>
  2492. Print a brief help message and exit.
  2493. =item B<--man>
  2494. Print the manual page and exit.
  2495. =item B<--dump> | B<-d>
  2496. Print all relevant configuration data. This is equivalent to B<--command-line>
  2497. B<--options> B<--target> B<--environment> B<--make-variables>
  2498. B<--build-parameters>.
  2499. =item B<--command-line> | B<-c>
  2500. Print the current configuration command line.
  2501. =item B<--options> | B<-o>
  2502. Print the features, both enabled and disabled, and display defined macro and
  2503. skipped directories where applicable.
  2504. =item B<--target> | B<-t>
  2505. Print the config attributes for this config target.
  2506. =item B<--environment> | B<-e>
  2507. Print the environment variables and their values at the time of configuration.
  2508. =item B<--make-variables> | B<-m>
  2509. Print the main make variables generated in the current configuration
  2510. =item B<--build-parameters> | B<-b>
  2511. Print the build parameters, i.e. build file and build file templates.
  2512. =item B<--reconfigure> | B<--reconf> | B<-r>
  2513. Redo the configuration.
  2514. =item B<--verbose> | B<-v>
  2515. Verbose output.
  2516. =back
  2517. =cut
  2518. EOF
  2519. close(OUT);
  2520. if ($builder_platform eq 'unix') {
  2521. my $mode = (0755 & ~umask);
  2522. chmod $mode, 'configdata.pm'
  2523. or warn sprintf("WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s\n",$mode,$!);
  2524. }
  2525. my %builders = (
  2526. unified => sub {
  2527. print 'Creating ',$target{build_file},"\n";
  2528. run_dofile(catfile($blddir, $target{build_file}),
  2529. @{$config{build_file_templates}});
  2530. },
  2531. );
  2532. $builders{$builder}->($builder_platform, @builder_opts);
  2533. $SIG{__DIE__} = $orig_death_handler;
  2534. print <<"EOF" if ($disabled{threads} eq "unavailable");
  2535. The library could not be configured for supporting multi-threaded
  2536. applications as the compiler options required on this system are not known.
  2537. See file INSTALL for details if you need multi-threading.
  2538. EOF
  2539. print <<"EOF" if ($no_shared_warn);
  2540. The options 'shared', 'pic' and 'dynamic-engine' aren't supported on this
  2541. platform, so we will pretend you gave the option 'no-pic', which also disables
  2542. 'shared' and 'dynamic-engine'. If you know how to implement shared libraries
  2543. or position independent code, please let us know (but please first make sure
  2544. you have tried with a current version of OpenSSL).
  2545. EOF
  2546. print <<"EOF";
  2547. **********************************************************************
  2548. *** ***
  2549. *** OpenSSL has been successfully configured ***
  2550. *** ***
  2551. *** If you encounter a problem while building, please open an ***
  2552. *** issue on GitHub <https://github.com/openssl/openssl/issues> ***
  2553. *** and include the output from the following command: ***
  2554. *** ***
  2555. *** perl configdata.pm --dump ***
  2556. *** ***
  2557. *** (If you are new to OpenSSL, you might want to consult the ***
  2558. *** 'Troubleshooting' section in the INSTALL file first) ***
  2559. *** ***
  2560. **********************************************************************
  2561. EOF
  2562. exit(0);
  2563. ######################################################################
  2564. #
  2565. # Helpers and utility functions
  2566. #
  2567. # Death handler, to print a helpful message in case of failure #######
  2568. #
  2569. sub death_handler {
  2570. die @_ if $^S; # To prevent the added message in eval blocks
  2571. my $build_file = $target{build_file} // "build file";
  2572. my @message = ( <<"_____", @_ );
  2573. Failure! $build_file wasn't produced.
  2574. Please read INSTALL and associated NOTES files. You may also have to look over
  2575. your available compiler tool chain or change your configuration.
  2576. _____
  2577. # Dying is terminal, so it's ok to reset the signal handler here.
  2578. $SIG{__DIE__} = $orig_death_handler;
  2579. die @message;
  2580. }
  2581. # Configuration file reading #########################################
  2582. # Note: All of the helper functions are for lazy evaluation. They all
  2583. # return a CODE ref, which will return the intended value when evaluated.
  2584. # Thus, whenever there's mention of a returned value, it's about that
  2585. # intended value.
  2586. # Helper function to implement conditional inheritance depending on the
  2587. # value of $disabled{asm}. Used in inherit_from values as follows:
  2588. #
  2589. # inherit_from => [ "template", asm("asm_tmpl") ]
  2590. #
  2591. sub asm {
  2592. my @x = @_;
  2593. sub {
  2594. $disabled{asm} ? () : @x;
  2595. }
  2596. }
  2597. # Helper function to implement conditional value variants, with a default
  2598. # plus additional values based on the value of $config{build_type}.
  2599. # Arguments are given in hash table form:
  2600. #
  2601. # picker(default => "Basic string: ",
  2602. # debug => "debug",
  2603. # release => "release")
  2604. #
  2605. # When configuring with --debug, the resulting string will be
  2606. # "Basic string: debug", and when not, it will be "Basic string: release"
  2607. #
  2608. # This can be used to create variants of sets of flags according to the
  2609. # build type:
  2610. #
  2611. # cflags => picker(default => "-Wall",
  2612. # debug => "-g -O0",
  2613. # release => "-O3")
  2614. #
  2615. sub picker {
  2616. my %opts = @_;
  2617. return sub { add($opts{default} || (),
  2618. $opts{$config{build_type}} || ())->(); }
  2619. }
  2620. # Helper function to combine several values of different types into one.
  2621. # This is useful if you want to combine a string with the result of a
  2622. # lazy function, such as:
  2623. #
  2624. # cflags => combine("-Wall", sub { $disabled{zlib} ? () : "-DZLIB" })
  2625. #
  2626. sub combine {
  2627. my @stuff = @_;
  2628. return sub { add(@stuff)->(); }
  2629. }
  2630. # Helper function to implement conditional values depending on the value
  2631. # of $disabled{threads}. Can be used as follows:
  2632. #
  2633. # cflags => combine("-Wall", threads("-pthread"))
  2634. #
  2635. sub threads {
  2636. my @flags = @_;
  2637. return sub { add($disabled{threads} ? () : @flags)->(); }
  2638. }
  2639. sub shared {
  2640. my @flags = @_;
  2641. return sub { add($disabled{shared} ? () : @flags)->(); }
  2642. }
  2643. our $add_called = 0;
  2644. # Helper function to implement adding values to already existing configuration
  2645. # values. It handles elements that are ARRAYs, CODEs and scalars
  2646. sub _add {
  2647. my $separator = shift;
  2648. # If there's any ARRAY in the collection of values OR the separator
  2649. # is undef, we will return an ARRAY of combined values, otherwise a
  2650. # string of joined values with $separator as the separator.
  2651. my $found_array = !defined($separator);
  2652. my @values =
  2653. map {
  2654. my $res = $_;
  2655. while (ref($res) eq "CODE") {
  2656. $res = $res->();
  2657. }
  2658. if (defined($res)) {
  2659. if (ref($res) eq "ARRAY") {
  2660. $found_array = 1;
  2661. @$res;
  2662. } else {
  2663. $res;
  2664. }
  2665. } else {
  2666. ();
  2667. }
  2668. } (@_);
  2669. $add_called = 1;
  2670. if ($found_array) {
  2671. [ @values ];
  2672. } else {
  2673. join($separator, grep { defined($_) && $_ ne "" } @values);
  2674. }
  2675. }
  2676. sub add_before {
  2677. my $separator = " ";
  2678. if (ref($_[$#_]) eq "HASH") {
  2679. my $opts = pop;
  2680. $separator = $opts->{separator};
  2681. }
  2682. my @x = @_;
  2683. sub { _add($separator, @x, @_) };
  2684. }
  2685. sub add {
  2686. my $separator = " ";
  2687. if (ref($_[$#_]) eq "HASH") {
  2688. my $opts = pop;
  2689. $separator = $opts->{separator};
  2690. }
  2691. my @x = @_;
  2692. sub { _add($separator, @_, @x) };
  2693. }
  2694. sub read_eval_file {
  2695. my $fname = shift;
  2696. my $content;
  2697. my @result;
  2698. open F, "< $fname" or die "Can't open '$fname': $!\n";
  2699. {
  2700. undef local $/;
  2701. $content = <F>;
  2702. }
  2703. close F;
  2704. {
  2705. local $@;
  2706. @result = ( eval $content );
  2707. warn $@ if $@;
  2708. }
  2709. return wantarray ? @result : $result[0];
  2710. }
  2711. # configuration reader, evaluates the input file as a perl script and expects
  2712. # it to fill %targets with target configurations. Those are then added to
  2713. # %table.
  2714. sub read_config {
  2715. my $fname = shift;
  2716. my %targets;
  2717. {
  2718. # Protect certain tables from tampering
  2719. local %table = ();
  2720. %targets = read_eval_file($fname);
  2721. }
  2722. my %preexisting = ();
  2723. foreach (sort keys %targets) {
  2724. $preexisting{$_} = 1 if $table{$_};
  2725. }
  2726. die <<"EOF",
  2727. The following config targets from $fname
  2728. shadow pre-existing config targets with the same name:
  2729. EOF
  2730. map { " $_\n" } sort keys %preexisting
  2731. if %preexisting;
  2732. # For each target, check that it's configured with a hash table.
  2733. foreach (keys %targets) {
  2734. if (ref($targets{$_}) ne "HASH") {
  2735. if (ref($targets{$_}) eq "") {
  2736. warn "Deprecated target configuration for $_, ignoring...\n";
  2737. } else {
  2738. warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
  2739. }
  2740. delete $targets{$_};
  2741. } else {
  2742. $targets{$_}->{_conf_fname_int} = add([ $fname ]);
  2743. }
  2744. }
  2745. %table = (%table, %targets);
  2746. }
  2747. # configuration resolver. Will only resolve all the lazy evaluation
  2748. # codeblocks for the chosen target and all those it inherits from,
  2749. # recursively
  2750. sub resolve_config {
  2751. my $target = shift;
  2752. my @breadcrumbs = @_;
  2753. # my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS});
  2754. if (grep { $_ eq $target } @breadcrumbs) {
  2755. die "inherit_from loop! target backtrace:\n "
  2756. ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
  2757. }
  2758. if (!defined($table{$target})) {
  2759. warn "Warning! target $target doesn't exist!\n";
  2760. return ();
  2761. }
  2762. # Recurse through all inheritances. They will be resolved on the
  2763. # fly, so when this operation is done, they will all just be a
  2764. # bunch of attributes with string values.
  2765. # What we get here, though, are keys with references to lists of
  2766. # the combined values of them all. We will deal with lists after
  2767. # this stage is done.
  2768. my %combined_inheritance = ();
  2769. if ($table{$target}->{inherit_from}) {
  2770. my @inherit_from =
  2771. map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
  2772. foreach (@inherit_from) {
  2773. my %inherited_config = resolve_config($_, $target, @breadcrumbs);
  2774. # 'template' is a marker that's considered private to
  2775. # the config that had it.
  2776. delete $inherited_config{template};
  2777. foreach (keys %inherited_config) {
  2778. if (!$combined_inheritance{$_}) {
  2779. $combined_inheritance{$_} = [];
  2780. }
  2781. push @{$combined_inheritance{$_}}, $inherited_config{$_};
  2782. }
  2783. }
  2784. }
  2785. # We won't need inherit_from in this target any more, since we've
  2786. # resolved all the inheritances that lead to this
  2787. delete $table{$target}->{inherit_from};
  2788. # Now is the time to deal with those lists. Here's the place to
  2789. # decide what shall be done with those lists, all based on the
  2790. # values of the target we're currently dealing with.
  2791. # - If a value is a coderef, it will be executed with the list of
  2792. # inherited values as arguments.
  2793. # - If the corresponding key doesn't have a value at all or is the
  2794. # empty string, the inherited value list will be run through the
  2795. # default combiner (below), and the result becomes this target's
  2796. # value.
  2797. # - Otherwise, this target's value is assumed to be a string that
  2798. # will simply override the inherited list of values.
  2799. my $default_combiner = add();
  2800. my %all_keys =
  2801. map { $_ => 1 } (keys %combined_inheritance,
  2802. keys %{$table{$target}});
  2803. sub process_values {
  2804. my $object = shift;
  2805. my $inherited = shift; # Always a [ list ]
  2806. my $target = shift;
  2807. my $entry = shift;
  2808. $add_called = 0;
  2809. while(ref($object) eq "CODE") {
  2810. $object = $object->(@$inherited);
  2811. }
  2812. if (!defined($object)) {
  2813. return ();
  2814. }
  2815. elsif (ref($object) eq "ARRAY") {
  2816. local $add_called; # To make sure recursive calls don't affect it
  2817. return [ map { process_values($_, $inherited, $target, $entry) }
  2818. @$object ];
  2819. } elsif (ref($object) eq "") {
  2820. return $object;
  2821. } else {
  2822. die "cannot handle reference type ",ref($object)
  2823. ," found in target ",$target," -> ",$entry,"\n";
  2824. }
  2825. }
  2826. foreach (sort keys %all_keys) {
  2827. my $previous = $combined_inheritance{$_};
  2828. # Current target doesn't have a value for the current key?
  2829. # Assign it the default combiner, the rest of this loop body
  2830. # will handle it just like any other coderef.
  2831. if (!exists $table{$target}->{$_}) {
  2832. $table{$target}->{$_} = $default_combiner;
  2833. }
  2834. $table{$target}->{$_} = process_values($table{$target}->{$_},
  2835. $combined_inheritance{$_},
  2836. $target, $_);
  2837. unless(defined($table{$target}->{$_})) {
  2838. delete $table{$target}->{$_};
  2839. }
  2840. # if ($extra_checks &&
  2841. # $previous && !($add_called || $previous ~~ $table{$target}->{$_})) {
  2842. # warn "$_ got replaced in $target\n";
  2843. # }
  2844. }
  2845. # Finally done, return the result.
  2846. return %{$table{$target}};
  2847. }
  2848. sub usage
  2849. {
  2850. print STDERR $usage;
  2851. print STDERR "\npick os/compiler from:\n";
  2852. my $j=0;
  2853. my $i;
  2854. my $k=0;
  2855. foreach $i (sort keys %table)
  2856. {
  2857. next if $table{$i}->{template};
  2858. next if $i =~ /^debug/;
  2859. $k += length($i) + 1;
  2860. if ($k > 78)
  2861. {
  2862. print STDERR "\n";
  2863. $k=length($i);
  2864. }
  2865. print STDERR $i . " ";
  2866. }
  2867. foreach $i (sort keys %table)
  2868. {
  2869. next if $table{$i}->{template};
  2870. next if $i !~ /^debug/;
  2871. $k += length($i) + 1;
  2872. if ($k > 78)
  2873. {
  2874. print STDERR "\n";
  2875. $k=length($i);
  2876. }
  2877. print STDERR $i . " ";
  2878. }
  2879. print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n";
  2880. exit(1);
  2881. }
  2882. sub run_dofile
  2883. {
  2884. my $out = shift;
  2885. my @templates = @_;
  2886. unlink $out || warn "Can't remove $out, $!"
  2887. if -f $out;
  2888. foreach (@templates) {
  2889. die "Can't open $_, $!" unless -f $_;
  2890. }
  2891. my $perlcmd = (quotify("maybeshell", $config{PERL}))[0];
  2892. my $cmd = "$perlcmd \"-I.\" \"-Mconfigdata\" \"$dofile\" -o\"Configure\" \"".join("\" \"",@templates)."\" > \"$out.new\"";
  2893. #print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
  2894. system($cmd);
  2895. exit 1 if $? != 0;
  2896. rename("$out.new", $out) || die "Can't rename $out.new, $!";
  2897. }
  2898. sub compiler_predefined {
  2899. state %predefined;
  2900. my $cc = shift;
  2901. return () if $^O eq 'VMS';
  2902. die 'compiler_predefined called without a compiler command'
  2903. unless $cc;
  2904. if (! $predefined{$cc}) {
  2905. $predefined{$cc} = {};
  2906. # collect compiler pre-defines from gcc or gcc-alike...
  2907. open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |");
  2908. while (my $l = <PIPE>) {
  2909. $l =~ m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last;
  2910. $predefined{$cc}->{$1} = $2 // '';
  2911. }
  2912. close(PIPE);
  2913. }
  2914. return %{$predefined{$cc}};
  2915. }
  2916. sub which
  2917. {
  2918. my ($name)=@_;
  2919. if (eval { require IPC::Cmd; 1; }) {
  2920. IPC::Cmd->import();
  2921. return scalar IPC::Cmd::can_run($name);
  2922. } else {
  2923. # if there is $directories component in splitpath,
  2924. # then it's not something to test with $PATH...
  2925. return $name if (File::Spec->splitpath($name))[1];
  2926. foreach (File::Spec->path()) {
  2927. my $fullpath = catfile($_, "$name$target{exe_extension}");
  2928. if (-f $fullpath and -x $fullpath) {
  2929. return $fullpath;
  2930. }
  2931. }
  2932. }
  2933. }
  2934. sub env
  2935. {
  2936. my $name = shift;
  2937. my %opts = @_;
  2938. unless ($opts{cacheonly}) {
  2939. # Note that if $ENV{$name} doesn't exist or is undefined,
  2940. # $config{perlenv}->{$name} will be created with the value
  2941. # undef. This is intentional.
  2942. $config{perlenv}->{$name} = $ENV{$name}
  2943. if ! exists $config{perlenv}->{$name};
  2944. }
  2945. return $config{perlenv}->{$name};
  2946. }
  2947. # Configuration printer ##############################################
  2948. sub print_table_entry
  2949. {
  2950. local $now_printing = shift;
  2951. my %target = resolve_config($now_printing);
  2952. my $type = shift;
  2953. # Don't print the templates
  2954. return if $target{template};
  2955. my @sequence = (
  2956. "sys_id",
  2957. "cpp",
  2958. "cppflags",
  2959. "defines",
  2960. "includes",
  2961. "cc",
  2962. "cflags",
  2963. "unistd",
  2964. "ld",
  2965. "lflags",
  2966. "loutflag",
  2967. "ex_libs",
  2968. "bn_ops",
  2969. "apps_aux_src",
  2970. "cpuid_asm_src",
  2971. "uplink_aux_src",
  2972. "bn_asm_src",
  2973. "ec_asm_src",
  2974. "des_asm_src",
  2975. "aes_asm_src",
  2976. "bf_asm_src",
  2977. "md5_asm_src",
  2978. "cast_asm_src",
  2979. "sha1_asm_src",
  2980. "rc4_asm_src",
  2981. "rmd160_asm_src",
  2982. "rc5_asm_src",
  2983. "wp_asm_src",
  2984. "cmll_asm_src",
  2985. "modes_asm_src",
  2986. "padlock_asm_src",
  2987. "chacha_asm_src",
  2988. "poly1035_asm_src",
  2989. "thread_scheme",
  2990. "perlasm_scheme",
  2991. "dso_scheme",
  2992. "shared_target",
  2993. "shared_cflag",
  2994. "shared_defines",
  2995. "shared_ldflag",
  2996. "shared_rcflag",
  2997. "shared_extension",
  2998. "dso_extension",
  2999. "obj_extension",
  3000. "exe_extension",
  3001. "ranlib",
  3002. "ar",
  3003. "arflags",
  3004. "aroutflag",
  3005. "rc",
  3006. "rcflags",
  3007. "rcoutflag",
  3008. "mt",
  3009. "mtflags",
  3010. "mtinflag",
  3011. "mtoutflag",
  3012. "multilib",
  3013. "build_scheme",
  3014. );
  3015. if ($type eq "TABLE") {
  3016. print "\n";
  3017. print "*** $now_printing\n";
  3018. foreach (@sequence) {
  3019. if (ref($target{$_}) eq "ARRAY") {
  3020. printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}});
  3021. } else {
  3022. printf "\$%-12s = %s\n", $_, $target{$_};
  3023. }
  3024. }
  3025. } elsif ($type eq "HASH") {
  3026. my $largest =
  3027. length((sort { length($a) <=> length($b) } @sequence)[-1]);
  3028. print " '$now_printing' => {\n";
  3029. foreach (@sequence) {
  3030. if ($target{$_}) {
  3031. if (ref($target{$_}) eq "ARRAY") {
  3032. print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n";
  3033. } else {
  3034. print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
  3035. }
  3036. }
  3037. }
  3038. print " },\n";
  3039. }
  3040. }
  3041. # Utility routines ###################################################
  3042. # On VMS, if the given file is a logical name, File::Spec::Functions
  3043. # will consider it an absolute path. There are cases when we want a
  3044. # purely syntactic check without checking the environment.
  3045. sub isabsolute {
  3046. my $file = shift;
  3047. # On non-platforms, we just use file_name_is_absolute().
  3048. return file_name_is_absolute($file) unless $^O eq "VMS";
  3049. # If the file spec includes a device or a directory spec,
  3050. # file_name_is_absolute() is perfectly safe.
  3051. return file_name_is_absolute($file) if $file =~ m|[:\[]|;
  3052. # Here, we know the given file spec isn't absolute
  3053. return 0;
  3054. }
  3055. # Makes a directory absolute and cleans out /../ in paths like foo/../bar
  3056. # On some platforms, this uses rel2abs(), while on others, realpath() is used.
  3057. # realpath() requires that at least all path components except the last is an
  3058. # existing directory. On VMS, the last component of the directory spec must
  3059. # exist.
  3060. sub absolutedir {
  3061. my $dir = shift;
  3062. # realpath() is quite buggy on VMS. It uses LIB$FID_TO_NAME, which
  3063. # will return the volume name for the device, no matter what. Also,
  3064. # it will return an incorrect directory spec if the argument is a
  3065. # directory that doesn't exist.
  3066. if ($^O eq "VMS") {
  3067. return rel2abs($dir);
  3068. }
  3069. # We use realpath() on Unix, since no other will properly clean out
  3070. # a directory spec.
  3071. use Cwd qw/realpath/;
  3072. return realpath($dir);
  3073. }
  3074. # Check if all paths are one and the same, using stat. They must both exist
  3075. # We need this for the cases when File::Spec doesn't detect case insensitivity
  3076. # (File::Spec::Unix assumes case sensitivity)
  3077. sub samedir {
  3078. die "samedir expects two arguments\n" unless scalar @_ == 2;
  3079. my @stat0 = stat($_[0]); # First argument
  3080. my @stat1 = stat($_[1]); # Second argument
  3081. die "Couldn't stat $_[0]" unless @stat0;
  3082. die "Couldn't stat $_[1]" unless @stat1;
  3083. # Compare device number
  3084. return 0 unless ($stat0[0] == $stat1[0]);
  3085. # Compare "inode". The perl manual recommends comparing as
  3086. # string rather than as number.
  3087. return 0 unless ($stat0[1] eq $stat1[1]);
  3088. return 1; # All the same
  3089. }
  3090. sub quotify {
  3091. my %processors = (
  3092. perl => sub { my $x = shift;
  3093. $x =~ s/([\\\$\@"])/\\$1/g;
  3094. return '"'.$x.'"'; },
  3095. maybeshell => sub { my $x = shift;
  3096. (my $y = $x) =~ s/([\\\"])/\\$1/g;
  3097. if ($x ne $y || $x =~ m|\s|) {
  3098. return '"'.$y.'"';
  3099. } else {
  3100. return $x;
  3101. }
  3102. },
  3103. );
  3104. my $for = shift;
  3105. my $processor =
  3106. defined($processors{$for}) ? $processors{$for} : sub { shift; };
  3107. return map { $processor->($_); } @_;
  3108. }
  3109. # collect_from_file($filename, $line_concat_cond_re, $line_concat)
  3110. # $filename is a file name to read from
  3111. # $line_concat_cond_re is a regexp detecting a line continuation ending
  3112. # $line_concat is a CODEref that takes care of concatenating two lines
  3113. sub collect_from_file {
  3114. my $filename = shift;
  3115. my $line_concat_cond_re = shift;
  3116. my $line_concat = shift;
  3117. open my $fh, $filename || die "unable to read $filename: $!\n";
  3118. return sub {
  3119. my $saved_line = "";
  3120. $_ = "";
  3121. while (<$fh>) {
  3122. s|\R$||;
  3123. if (defined $line_concat) {
  3124. $_ = $line_concat->($saved_line, $_);
  3125. $saved_line = "";
  3126. }
  3127. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  3128. $saved_line = $_;
  3129. next;
  3130. }
  3131. return $_;
  3132. }
  3133. die "$filename ending with continuation line\n" if $_;
  3134. close $fh;
  3135. return undef;
  3136. }
  3137. }
  3138. # collect_from_array($array, $line_concat_cond_re, $line_concat)
  3139. # $array is an ARRAYref of lines
  3140. # $line_concat_cond_re is a regexp detecting a line continuation ending
  3141. # $line_concat is a CODEref that takes care of concatenating two lines
  3142. sub collect_from_array {
  3143. my $array = shift;
  3144. my $line_concat_cond_re = shift;
  3145. my $line_concat = shift;
  3146. my @array = (@$array);
  3147. return sub {
  3148. my $saved_line = "";
  3149. $_ = "";
  3150. while (defined($_ = shift @array)) {
  3151. s|\R$||;
  3152. if (defined $line_concat) {
  3153. $_ = $line_concat->($saved_line, $_);
  3154. $saved_line = "";
  3155. }
  3156. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  3157. $saved_line = $_;
  3158. next;
  3159. }
  3160. return $_;
  3161. }
  3162. die "input text ending with continuation line\n" if $_;
  3163. return undef;
  3164. }
  3165. }
  3166. # collect_information($lineiterator, $line_continue, $regexp => $CODEref, ...)
  3167. # $lineiterator is a CODEref that delivers one line at a time.
  3168. # All following arguments are regex/CODEref pairs, where the regexp detects a
  3169. # line and the CODEref does something with the result of the regexp.
  3170. sub collect_information {
  3171. my $lineiterator = shift;
  3172. my %collectors = @_;
  3173. while(defined($_ = $lineiterator->())) {
  3174. s|\R$||;
  3175. my $found = 0;
  3176. if ($collectors{"BEFORE"}) {
  3177. $collectors{"BEFORE"}->($_);
  3178. }
  3179. foreach my $re (keys %collectors) {
  3180. if ($re !~ /^OTHERWISE|BEFORE|AFTER$/ && /$re/) {
  3181. $collectors{$re}->($lineiterator);
  3182. $found = 1;
  3183. };
  3184. }
  3185. if ($collectors{"OTHERWISE"}) {
  3186. $collectors{"OTHERWISE"}->($lineiterator, $_)
  3187. unless $found || !defined $collectors{"OTHERWISE"};
  3188. }
  3189. if ($collectors{"AFTER"}) {
  3190. $collectors{"AFTER"}->($_);
  3191. }
  3192. }
  3193. }
  3194. # tokenize($line)
  3195. # $line is a line of text to split up into tokens
  3196. # returns a list of tokens
  3197. #
  3198. # Tokens are divided by spaces. If the tokens include spaces, they
  3199. # have to be quoted with single or double quotes. Double quotes
  3200. # inside a double quoted token must be escaped. Escaping is done
  3201. # with backslash.
  3202. # Basically, the same quoting rules apply for " and ' as in any
  3203. # Unix shell.
  3204. sub tokenize {
  3205. my $line = my $debug_line = shift;
  3206. my @result = ();
  3207. while ($line =~ s|^\s+||, $line ne "") {
  3208. my $token = "";
  3209. while ($line ne "" && $line !~ m|^\s|) {
  3210. if ($line =~ m/^"((?:[^"\\]+|\\.)*)"/) {
  3211. $token .= $1;
  3212. $line = $';
  3213. } elsif ($line =~ m/^'([^']*)'/) {
  3214. $token .= $1;
  3215. $line = $';
  3216. } elsif ($line =~ m/^(\S+)/) {
  3217. $token .= $1;
  3218. $line = $';
  3219. }
  3220. }
  3221. push @result, $token;
  3222. }
  3223. if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) {
  3224. print STDERR "DEBUG[tokenize]: Parsed '$debug_line' into:\n";
  3225. print STDERR "DEBUG[tokenize]: ('", join("', '", @result), "')\n";
  3226. }
  3227. return @result;
  3228. }