Configure 123 KB

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