Configure 134 KB

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