Configure 137 KB

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