Configure 132 KB

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