Configure 114 KB

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