Configure 134 KB

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