Configure 122 KB

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