Configure 136 KB

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