Configure 124 KB

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