Configure 116 KB

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