Configure 114 KB

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