Configure 133 KB

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