Configure 136 KB

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