Configure 123 KB

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