Configure 133 KB

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