Configure 137 KB

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