Configure 118 KB

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