Configure 132 KB

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