Configure 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168
  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", "legacy" ],
  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. while ($value_rest =~ /(?<!\\)${variable_re}/) {
  1560. $value .= $`;
  1561. $value .= $variables{$1};
  1562. $value_rest = $';
  1563. }
  1564. return $value . $value_rest;
  1565. };
  1566. # We want to detect configdata.pm in the source tree, so we
  1567. # don't use it if the build tree is different.
  1568. my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir);
  1569. push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f);
  1570. my $template =
  1571. Text::Template->new(TYPE => 'FILE',
  1572. SOURCE => catfile($sourced, $f),
  1573. PREPEND => qq{use lib "$FindBin::Bin/util/perl";});
  1574. die "Something went wrong with $sourced/$f: $!\n" unless $template;
  1575. my @text =
  1576. split /^/m,
  1577. $template->fill_in(HASH => { config => \%config,
  1578. target => \%target,
  1579. disabled => \%disabled,
  1580. withargs => \%withargs,
  1581. builddir => abs2rel($buildd, $blddir),
  1582. sourcedir => abs2rel($sourced, $blddir),
  1583. buildtop => abs2rel($blddir, $blddir),
  1584. sourcetop => abs2rel($srcdir, $blddir) },
  1585. DELIMITERS => [ "{-", "-}" ]);
  1586. # The top item of this stack has the following values
  1587. # -2 positive already run and we found ELSE (following ELSIF should fail)
  1588. # -1 positive already run (skip until ENDIF)
  1589. # 0 negatives so far (if we're at a condition, check it)
  1590. # 1 last was positive (don't skip lines until next ELSE, ELSIF or ENDIF)
  1591. # 2 positive ELSE (following ELSIF should fail)
  1592. my @skip = ();
  1593. collect_information(
  1594. collect_from_array([ @text ],
  1595. qr/\\$/ => sub { my $l1 = shift; my $l2 = shift;
  1596. $l1 =~ s/\\$//; $l1.$l2 }),
  1597. # Info we're looking for
  1598. qr/^\s*IF\[((?:\\.|[^\\\]])*)\]\s*$/
  1599. => sub {
  1600. if (! @skip || $skip[$#skip] > 0) {
  1601. push @skip, !! $expand_variables->($1);
  1602. } else {
  1603. push @skip, -1;
  1604. }
  1605. },
  1606. qr/^\s*ELSIF\[((?:\\.|[^\\\]])*)\]\s*$/
  1607. => sub { die "ELSIF out of scope" if ! @skip;
  1608. die "ELSIF following ELSE" if abs($skip[$#skip]) == 2;
  1609. $skip[$#skip] = -1 if $skip[$#skip] != 0;
  1610. $skip[$#skip] = !! $expand_variables->($1)
  1611. if $skip[$#skip] == 0; },
  1612. qr/^\s*ELSE\s*$/
  1613. => sub { die "ELSE out of scope" if ! @skip;
  1614. $skip[$#skip] = -2 if $skip[$#skip] != 0;
  1615. $skip[$#skip] = 2 if $skip[$#skip] == 0; },
  1616. qr/^\s*ENDIF\s*$/
  1617. => sub { die "ENDIF out of scope" if ! @skip;
  1618. pop @skip; },
  1619. qr/^\s*${variable_re}\s*=\s*(.*?)\s*$/
  1620. => sub {
  1621. if (!@skip || $skip[$#skip] > 0) {
  1622. my $n = $1;
  1623. my $v = $2;
  1624. $variables{$n} = $expand_variables->($v);
  1625. }
  1626. },
  1627. qr/^\s*SUBDIRS\s*=\s*(.*)\s*$/
  1628. => sub {
  1629. if (!@skip || $skip[$#skip] > 0) {
  1630. foreach (tokenize($expand_variables->($1))) {
  1631. push @build_dirs, [ @curd, splitdir($_, 1) ];
  1632. }
  1633. }
  1634. },
  1635. qr/^\s*PROGRAMS(?:{([\w=]+(?:\s*,\s*[\w=]+)*)})?\s*=\s*(.*)\s*$/
  1636. => sub {
  1637. if (!@skip || $skip[$#skip] > 0) {
  1638. my @a = tokenize($1, qr|\s*,\s*|);
  1639. my @p = tokenize($expand_variables->($2));
  1640. push @programs, @p;
  1641. foreach my $a (@a) {
  1642. my $ak = $a;
  1643. my $av = 1;
  1644. if ($a =~ m|^(.*?)\s*=\s*(.*?)$|) {
  1645. $ak = $1;
  1646. $av = $2;
  1647. }
  1648. foreach my $p (@p) {
  1649. $attributes{$p}->{$ak} = $av;
  1650. }
  1651. }
  1652. }
  1653. },
  1654. qr/^\s*LIBS(?:{([\w=]+(?:\s*,\s*[\w=]+)*)})?\s*=\s*(.*)\s*$/
  1655. => sub {
  1656. if (!@skip || $skip[$#skip] > 0) {
  1657. my @a = tokenize($1, qr|\s*,\s*|);
  1658. my @l = tokenize($expand_variables->($2));
  1659. push @libraries, @l;
  1660. foreach my $a (@a) {
  1661. my $ak = $a;
  1662. my $av = 1;
  1663. if ($a =~ m|^(.*?)\s*=\s*(.*?)$|) {
  1664. $ak = $1;
  1665. $av = $2;
  1666. }
  1667. foreach my $l (@l) {
  1668. $attributes{$l}->{$ak} = $av;
  1669. }
  1670. }
  1671. }
  1672. },
  1673. qr/^\s*MODULES(?:{([\w=]+(?:\s*,\s*[\w=]+)*)})?\s*=\s*(.*)\s*$/
  1674. => sub {
  1675. if (!@skip || $skip[$#skip] > 0) {
  1676. my @a = tokenize($1, qr|\s*,\s*|);
  1677. my @m = tokenize($expand_variables->($2));
  1678. push @modules, @m;
  1679. foreach my $a (@a) {
  1680. my $ak = $a;
  1681. my $av = 1;
  1682. if ($a =~ m|^(.*?)\s*=\s*(.*?)$|) {
  1683. $ak = $1;
  1684. $av = $2;
  1685. }
  1686. foreach my $m (@m) {
  1687. $attributes{$m}->{$ak} = $av;
  1688. }
  1689. }
  1690. }
  1691. },
  1692. qr/^\s*SCRIPTS(?:{([\w=]+(?:\s*,\s*[\w=]+)*)})?\s*=\s*(.*)\s*$/
  1693. => sub {
  1694. if (!@skip || $skip[$#skip] > 0) {
  1695. my @a = tokenize($1, qr|\s*,\s*|);
  1696. my @s = tokenize($expand_variables->($2));
  1697. push @scripts, @s;
  1698. foreach my $a (@a) {
  1699. my $ak = $a;
  1700. my $av = 1;
  1701. if ($a =~ m|^(.*?)\s*=\s*(.*?)$|) {
  1702. $ak = $1;
  1703. $av = $2;
  1704. }
  1705. foreach my $s (@s) {
  1706. $attributes{$s}->{$ak} = $av;
  1707. }
  1708. }
  1709. }
  1710. },
  1711. qr/^\s*ORDINALS\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/,
  1712. => sub { push @{$ordinals{$1}}, tokenize($expand_variables->($2))
  1713. if !@skip || $skip[$#skip] > 0 },
  1714. qr/^\s*SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1715. => sub { push @{$sources{$1}}, tokenize($expand_variables->($2))
  1716. if !@skip || $skip[$#skip] > 0 },
  1717. qr/^\s*SHARED_SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1718. => sub { push @{$shared_sources{$1}},
  1719. tokenize($expand_variables->($2))
  1720. if !@skip || $skip[$#skip] > 0 },
  1721. qr/^\s*INCLUDE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1722. => sub { push @{$includes{$1}}, tokenize($expand_variables->($2))
  1723. if !@skip || $skip[$#skip] > 0 },
  1724. qr/^\s*DEFINE\[((?:\\.|[^\\\]])*)\]\s*=\s*(.*)\s*$/
  1725. => sub { push @{$defines{$1}}, tokenize($expand_variables->($2))
  1726. if !@skip || $skip[$#skip] > 0 },
  1727. qr/^\s*DEPEND\[((?:\\.|[^\\\]])*)\]\s*=\s*(.*)\s*$/
  1728. => sub { push @{$depends{$1}}, tokenize($expand_variables->($2))
  1729. if !@skip || $skip[$#skip] > 0 },
  1730. qr/^\s*GENERATE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1731. => sub { push @{$generate{$1}}, $2
  1732. if !@skip || $skip[$#skip] > 0 },
  1733. qr/^\s*(?:#.*)?$/ => sub { },
  1734. "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" },
  1735. "BEFORE" => sub {
  1736. if ($buildinfo_debug) {
  1737. print STDERR "DEBUG: Parsing ",join(" ", @_),"\n";
  1738. print STDERR "DEBUG: ... before parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1739. }
  1740. },
  1741. "AFTER" => sub {
  1742. if ($buildinfo_debug) {
  1743. print STDERR "DEBUG: .... after parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1744. }
  1745. },
  1746. );
  1747. die "runaway IF?" if (@skip);
  1748. if (grep { defined $attributes{$_}->{engine} } keys %attributes
  1749. and !$config{dynamic_engines}) {
  1750. die <<"EOF"
  1751. ENGINES can only be used if configured with 'dynamic-engine'.
  1752. This is usually a fault in a build.info file.
  1753. EOF
  1754. }
  1755. foreach (keys %attributes) {
  1756. my $dest = $_;
  1757. my $ddest = cleanfile($buildd, $_, $blddir);
  1758. foreach (keys %{$attributes{$dest} // {}}) {
  1759. $unified_info{attributes}->{$ddest}->{$_} =
  1760. $attributes{$dest}->{$_};
  1761. }
  1762. }
  1763. {
  1764. my %infos = ( programs => [ @programs ],
  1765. libraries => [ @libraries ],
  1766. modules => [ @modules ],
  1767. scripts => [ @scripts ] );
  1768. foreach my $k (keys %infos) {
  1769. foreach (@{$infos{$k}}) {
  1770. my $item = cleanfile($buildd, $_, $blddir);
  1771. $unified_info{$k}->{$item} = 1;
  1772. }
  1773. }
  1774. }
  1775. # Check that we haven't defined any library as both shared and
  1776. # explicitly static. That is forbidden.
  1777. my @doubles = ();
  1778. foreach (grep /\.a$/, keys %{$unified_info{libraries}}) {
  1779. (my $l = $_) =~ s/\.a$//;
  1780. push @doubles, $l if defined $unified_info{libraries}->{$l};
  1781. }
  1782. die "these libraries are both explicitly static and shared:\n ",
  1783. join(" ", @doubles), "\n"
  1784. if @doubles;
  1785. foreach (keys %sources) {
  1786. my $dest = $_;
  1787. my $ddest = cleanfile($buildd, $_, $blddir);
  1788. foreach (@{$sources{$dest}}) {
  1789. my $s = cleanfile($sourced, $_, $blddir);
  1790. # If it isn't in the source tree, we assume it's generated
  1791. # in the build tree
  1792. if ($s eq $src_configdata || ! -f $s || $generate{$_}) {
  1793. $s = cleanfile($buildd, $_, $blddir);
  1794. }
  1795. # We recognise C++, C and asm files
  1796. if ($s =~ /\.(cc|cpp|c|s|S)$/) {
  1797. my $o = $_;
  1798. $o =~ s/\.[csS]$/.o/; # C and assembler
  1799. $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
  1800. $o = cleanfile($buildd, $o, $blddir);
  1801. $unified_info{sources}->{$ddest}->{$o} = -1;
  1802. $unified_info{sources}->{$o}->{$s} = -1;
  1803. } elsif ($s =~ /\.rc$/) {
  1804. # We also recognise resource files
  1805. my $o = $_;
  1806. $o =~ s/\.rc$/.res/; # Resource configuration
  1807. my $o = cleanfile($buildd, $o, $blddir);
  1808. $unified_info{sources}->{$ddest}->{$o} = -1;
  1809. $unified_info{sources}->{$o}->{$s} = -1;
  1810. } else {
  1811. $unified_info{sources}->{$ddest}->{$s} = 1;
  1812. }
  1813. }
  1814. }
  1815. foreach (keys %shared_sources) {
  1816. my $dest = $_;
  1817. my $ddest = cleanfile($buildd, $_, $blddir);
  1818. foreach (@{$shared_sources{$dest}}) {
  1819. my $s = cleanfile($sourced, $_, $blddir);
  1820. # If it isn't in the source tree, we assume it's generated
  1821. # in the build tree
  1822. if ($s eq $src_configdata || ! -f $s || $generate{$_}) {
  1823. $s = cleanfile($buildd, $_, $blddir);
  1824. }
  1825. if ($s =~ /\.(cc|cpp|c|s|S)$/) {
  1826. # We recognise C++, C and asm files
  1827. my $o = $_;
  1828. $o =~ s/\.[csS]$/.o/; # C and assembler
  1829. $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
  1830. $o = cleanfile($buildd, $o, $blddir);
  1831. $unified_info{shared_sources}->{$ddest}->{$o} = -1;
  1832. $unified_info{sources}->{$o}->{$s} = -1;
  1833. } elsif ($s =~ /\.rc$/) {
  1834. # We also recognise resource files
  1835. my $o = $_;
  1836. $o =~ s/\.rc$/.res/; # Resource configuration
  1837. my $o = cleanfile($buildd, $o, $blddir);
  1838. $unified_info{shared_sources}->{$ddest}->{$o} = -1;
  1839. $unified_info{sources}->{$o}->{$s} = -1;
  1840. } elsif ($s =~ /\.ld$/) {
  1841. # We also recognise linker scripts (or corresponding)
  1842. # We know they are generated files
  1843. my $ld = cleanfile($buildd, $_, $blddir);
  1844. $unified_info{shared_sources}->{$ddest}->{$ld} = 1;
  1845. } else {
  1846. die "unrecognised source file type for shared library: $s\n";
  1847. }
  1848. }
  1849. }
  1850. foreach (keys %generate) {
  1851. my $dest = $_;
  1852. my $ddest = cleanfile($buildd, $_, $blddir);
  1853. die "more than one generator for $dest: "
  1854. ,join(" ", @{$generate{$_}}),"\n"
  1855. if scalar @{$generate{$_}} > 1;
  1856. my @generator = split /\s+/, $generate{$dest}->[0];
  1857. $generator[0] = cleanfile($sourced, $generator[0], $blddir),
  1858. $unified_info{generate}->{$ddest} = [ @generator ];
  1859. }
  1860. foreach (keys %depends) {
  1861. my $dest = $_;
  1862. my $ddest = $dest eq "" ? "" : cleanfile($sourced, $_, $blddir);
  1863. # If the destination doesn't exist in source, it can only be
  1864. # a generated file in the build tree.
  1865. if ($ddest ne "" && ($ddest eq $src_configdata || ! -f $ddest)) {
  1866. $ddest = cleanfile($buildd, $_, $blddir);
  1867. }
  1868. foreach (@{$depends{$dest}}) {
  1869. my $d = cleanfile($sourced, $_, $blddir);
  1870. # If we know it's generated, or assume it is because we can't
  1871. # find it in the source tree, we set file we depend on to be
  1872. # in the build tree rather than the source tree, and assume
  1873. # and that there are lines to build it in a BEGINRAW..ENDRAW
  1874. # section or in the Makefile template.
  1875. if ($d eq $src_configdata
  1876. || ! -f $d
  1877. || (grep { $d eq $_ }
  1878. map { cleanfile($srcdir, $_, $blddir) }
  1879. grep { /\.h$/ } keys %{$unified_info{generate}})) {
  1880. $d = cleanfile($buildd, $_, $blddir);
  1881. }
  1882. # Take note if the file to depend on is being renamed
  1883. # Take extra care with files ending with .a, they should
  1884. # be treated without that extension, and the extension
  1885. # should be added back after treatment.
  1886. $d =~ /(\.a)?$/;
  1887. my $e = $1 // "";
  1888. $d = $`.$e;
  1889. $unified_info{depends}->{$ddest}->{$d} = 1;
  1890. }
  1891. }
  1892. foreach (keys %includes) {
  1893. my $dest = $_;
  1894. my $ddest = cleanfile($sourced, $_, $blddir);
  1895. # If the destination doesn't exist in source, it can only be
  1896. # a generated file in the build tree.
  1897. if ($ddest eq $src_configdata || ! -f $ddest) {
  1898. $ddest = cleanfile($buildd, $_, $blddir);
  1899. }
  1900. foreach (@{$includes{$dest}}) {
  1901. my $is = cleandir($sourced, $_, $blddir);
  1902. my $ib = cleandir($buildd, $_, $blddir);
  1903. push @{$unified_info{includes}->{$ddest}->{source}}, $is
  1904. unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}};
  1905. push @{$unified_info{includes}->{$ddest}->{build}}, $ib
  1906. unless grep { $_ eq $ib } @{$unified_info{includes}->{$ddest}->{build}};
  1907. }
  1908. }
  1909. foreach my $dest (keys %defines) {
  1910. my $ddest;
  1911. if ($dest ne "") {
  1912. $ddest = cleanfile($sourced, $dest, $blddir);
  1913. # If the destination doesn't exist in source, it can only
  1914. # be a generated file in the build tree.
  1915. if (! -f $ddest) {
  1916. $ddest = cleanfile($buildd, $dest, $blddir);
  1917. if ($unified_info{rename}->{$ddest}) {
  1918. $ddest = $unified_info{rename}->{$ddest};
  1919. }
  1920. }
  1921. }
  1922. foreach my $v (@{$defines{$dest}}) {
  1923. $v =~ m|^([^=]*)(=.*)?$|;
  1924. die "0 length macro name not permitted\n" if $1 eq "";
  1925. if ($dest ne "") {
  1926. die "$1 defined more than once\n"
  1927. if defined $unified_info{defines}->{$ddest}->{$1};
  1928. $unified_info{defines}->{$ddest}->{$1} = $2;
  1929. } else {
  1930. die "$1 defined more than once\n"
  1931. if grep { $v eq $_ } @{$config{defines}};
  1932. push @{$config{defines}}, $v;
  1933. }
  1934. }
  1935. }
  1936. }
  1937. my $ordinals_text = join(', ', sort keys %ordinals);
  1938. warn <<"EOF" if $ordinals_text;
  1939. WARNING: ORDINALS were specified for $ordinals_text
  1940. They are ignored and should be replaced with a combination of GENERATE,
  1941. DEPEND and SHARED_SOURCE.
  1942. EOF
  1943. # Go through the sources of all libraries and check that the same basename
  1944. # doesn't appear more than once. Some static library archivers depend on
  1945. # them being unique.
  1946. {
  1947. my $err = 0;
  1948. foreach my $prod (keys %{$unified_info{libraries}}) {
  1949. my @prod_sources =
  1950. map { keys %{$unified_info{sources}->{$_}} }
  1951. keys %{$unified_info{sources}->{$prod}};
  1952. my %srccnt = ();
  1953. # Count how many times a given each source basename
  1954. # appears for each product.
  1955. foreach my $src (@prod_sources) {
  1956. $srccnt{basename $src}++;
  1957. }
  1958. foreach my $src (keys %srccnt) {
  1959. if ((my $cnt = $srccnt{$src}) > 1) {
  1960. print STDERR "$src appears $cnt times for the product $prod\n";
  1961. $err++
  1962. }
  1963. }
  1964. }
  1965. die if $err > 0;
  1966. }
  1967. # Massage the result
  1968. # If we depend on a header file or a perl module, add an inclusion of
  1969. # its directory to allow smoothe inclusion
  1970. foreach my $dest (keys %{$unified_info{depends}}) {
  1971. next if $dest eq "";
  1972. foreach my $d (keys %{$unified_info{depends}->{$dest}}) {
  1973. next unless $d =~ /\.(h|pm)$/;
  1974. my $i = dirname($d);
  1975. my $spot =
  1976. $d eq "configdata.pm" || defined($unified_info{generate}->{$d})
  1977. ? 'build' : 'source';
  1978. push @{$unified_info{includes}->{$dest}->{$spot}}, $i
  1979. unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{$spot}};
  1980. }
  1981. }
  1982. # Go through all intermediary files and change their names to something that
  1983. # reflects what they will be built for. Note that for some source files,
  1984. # this leads to duplicate object files because they are used multiple times.
  1985. # the goal is to rename all object files according to this scheme:
  1986. # {productname}-{midfix}-{origobjname}.[o|res]
  1987. # the {midfix} is a keyword indicating the type of product, which is mostly
  1988. # valuable for libraries since they come in two forms.
  1989. #
  1990. # This also reorganises the {sources} and {shared_sources} so that the
  1991. # former only contains ALL object files that are supposed to end up in
  1992. # static libraries and programs, while the latter contains ALL object files
  1993. # that are supposed to end up in shared libraries and DSOs.
  1994. # The main reason for having two different source structures is to allow
  1995. # the same name to be used for the static and the shared variants of a
  1996. # library.
  1997. {
  1998. # Take copies so we don't get interference from added stuff
  1999. my %unified_copy = ();
  2000. foreach (('sources', 'shared_sources')) {
  2001. $unified_copy{$_} = { %{$unified_info{$_}} }
  2002. if defined($unified_info{$_});
  2003. delete $unified_info{$_};
  2004. }
  2005. foreach my $prodtype (('programs', 'libraries', 'modules', 'scripts')) {
  2006. # $intent serves multi purposes:
  2007. # - give a prefix for the new object files names
  2008. # - in the case of libraries, rearrange the object files so static
  2009. # libraries use the 'sources' structure exclusively, while shared
  2010. # libraries use the 'shared_sources' structure exclusively.
  2011. my $intent = {
  2012. programs => { bin => { src => [ 'sources' ],
  2013. dst => 'sources' } },
  2014. libraries => { lib => { src => [ 'sources' ],
  2015. dst => 'sources' },
  2016. shlib => { prodselect =>
  2017. sub { grep !/\.a$/, @_ },
  2018. src => [ 'sources',
  2019. 'shared_sources' ],
  2020. dst => 'shared_sources' } },
  2021. modules => { dso => { src => [ 'sources' ],
  2022. dst => 'sources' } },
  2023. scripts => { script => { src => [ 'sources' ],
  2024. dst => 'sources' } }
  2025. } -> {$prodtype};
  2026. foreach my $kind (keys %$intent) {
  2027. next if ($intent->{$kind}->{dst} eq 'shared_sources'
  2028. && $disabled{shared});
  2029. my @src = @{$intent->{$kind}->{src}};
  2030. my $dst = $intent->{$kind}->{dst};
  2031. my $prodselect = $intent->{$kind}->{prodselect} // sub { @_ };
  2032. foreach my $prod ($prodselect->(keys %{$unified_info{$prodtype}})) {
  2033. # %prod_sources has all applicable objects as keys, and
  2034. # their corresponding sources as values
  2035. my %prod_sources =
  2036. map { $_ => [ keys %{$unified_copy{sources}->{$_}} ] }
  2037. map { keys %{$unified_copy{$_}->{$prod}} }
  2038. @src;
  2039. foreach (keys %prod_sources) {
  2040. # Only affect object files and resource files,
  2041. # the others simply get a new value
  2042. # (+1 instead of -1)
  2043. if ($_ =~ /\.(o|res)$/) {
  2044. (my $prodname = $prod) =~ s|\.a$||;
  2045. my $newobj =
  2046. catfile(dirname($_),
  2047. basename($prodname)
  2048. . '-' . $kind
  2049. . '-' . basename($_));
  2050. $unified_info{$dst}->{$prod}->{$newobj} = 1;
  2051. foreach my $src (@{$prod_sources{$_}}) {
  2052. $unified_info{sources}->{$newobj}->{$src} = 1;
  2053. }
  2054. # Adjust dependencies
  2055. foreach my $deps (keys %{$unified_info{depends}->{$_}}) {
  2056. $unified_info{depends}->{$_}->{$deps} = -1;
  2057. $unified_info{depends}->{$newobj}->{$deps} = 1;
  2058. }
  2059. # Adjust includes
  2060. foreach my $k (('source', 'build')) {
  2061. next unless
  2062. defined($unified_info{includes}->{$_}->{$k});
  2063. my @incs = @{$unified_info{includes}->{$_}->{$k}};
  2064. $unified_info{includes}->{$newobj}->{$k} = [ @incs ];
  2065. }
  2066. } else {
  2067. $unified_info{$dst}->{$prod}->{$_} = 1;
  2068. }
  2069. }
  2070. }
  2071. }
  2072. }
  2073. }
  2074. # At this point, we have a number of sources with the value -1. They
  2075. # aren't part of the local build and are probably meant for a different
  2076. # platform, and can therefore be cleaned away. That happens when making
  2077. # %unified_info more efficient below.
  2078. ### Make unified_info a bit more efficient
  2079. # One level structures
  2080. foreach (("programs", "libraries", "modules", "scripts")) {
  2081. $unified_info{$_} = [ sort keys %{$unified_info{$_}} ];
  2082. }
  2083. # Two level structures
  2084. foreach my $l1 (("sources", "shared_sources", "ldadd", "depends")) {
  2085. foreach my $l2 (sort keys %{$unified_info{$l1}}) {
  2086. my @items =
  2087. sort
  2088. grep { $unified_info{$l1}->{$l2}->{$_} > 0 }
  2089. keys %{$unified_info{$l1}->{$l2}};
  2090. if (@items) {
  2091. $unified_info{$l1}->{$l2} = [ @items ];
  2092. } else {
  2093. delete $unified_info{$l1}->{$l2};
  2094. }
  2095. }
  2096. }
  2097. # Defines
  2098. foreach my $dest (sort keys %{$unified_info{defines}}) {
  2099. $unified_info{defines}->{$dest}
  2100. = [ map { $_.$unified_info{defines}->{$dest}->{$_} }
  2101. sort keys %{$unified_info{defines}->{$dest}} ];
  2102. }
  2103. # Includes
  2104. foreach my $dest (sort keys %{$unified_info{includes}}) {
  2105. if (defined($unified_info{includes}->{$dest}->{build})) {
  2106. my @source_includes = ();
  2107. @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} )
  2108. if defined($unified_info{includes}->{$dest}->{source});
  2109. $unified_info{includes}->{$dest} =
  2110. [ @{$unified_info{includes}->{$dest}->{build}} ];
  2111. foreach my $inc (@source_includes) {
  2112. push @{$unified_info{includes}->{$dest}}, $inc
  2113. unless grep { $_ eq $inc } @{$unified_info{includes}->{$dest}};
  2114. }
  2115. } elsif (defined($unified_info{includes}->{$dest}->{source})) {
  2116. $unified_info{includes}->{$dest} =
  2117. [ @{$unified_info{includes}->{$dest}->{source}} ];
  2118. } else {
  2119. delete $unified_info{includes}->{$dest};
  2120. }
  2121. }
  2122. # For convenience collect information regarding directories where
  2123. # files are generated, those generated files and the end product
  2124. # they end up in where applicable. Then, add build rules for those
  2125. # directories
  2126. my %loopinfo = ( "lib" => [ @{$unified_info{libraries}} ],
  2127. "dso" => [ @{$unified_info{modules}} ],
  2128. "bin" => [ @{$unified_info{programs}} ],
  2129. "script" => [ @{$unified_info{scripts}} ] );
  2130. foreach my $type (keys %loopinfo) {
  2131. foreach my $product (@{$loopinfo{$type}}) {
  2132. my %dirs = ();
  2133. my $pd = dirname($product);
  2134. foreach (@{$unified_info{sources}->{$product} // []},
  2135. @{$unified_info{shared_sources}->{$product} // []}) {
  2136. my $d = dirname($_);
  2137. # We don't want to create targets for source directories
  2138. # when building out of source
  2139. next if ($config{sourcedir} ne $config{builddir}
  2140. && $d =~ m|^\Q$config{sourcedir}\E|);
  2141. # We already have a "test" target, and the current directory
  2142. # is just silly to make a target for
  2143. next if $d eq "test" || $d eq ".";
  2144. $dirs{$d} = 1;
  2145. push @{$unified_info{dirinfo}->{$d}->{deps}}, $_
  2146. if $d ne $pd;
  2147. }
  2148. foreach (keys %dirs) {
  2149. push @{$unified_info{dirinfo}->{$_}->{products}->{$type}},
  2150. $product;
  2151. }
  2152. }
  2153. }
  2154. }
  2155. # For the schemes that need it, we provide the old *_obj configs
  2156. # from the *_asm_obj ones
  2157. foreach (grep /_(asm|aux)_src$/, keys %target) {
  2158. my $src = $_;
  2159. (my $obj = $_) =~ s/_(asm|aux)_src$/_obj/;
  2160. $target{$obj} = $target{$src};
  2161. $target{$obj} =~ s/\.[csS]\b/.o/g; # C and assembler
  2162. $target{$obj} =~ s/\.(cc|cpp)\b/_cc.o/g; # C++
  2163. }
  2164. # Write down our configuration where it fits #########################
  2165. my %template_vars = (
  2166. config => \%config,
  2167. target => \%target,
  2168. disablables => \@disablables,
  2169. disablables_int => \@disablables_int,
  2170. disabled => \%disabled,
  2171. withargs => \%withargs,
  2172. unified_info => \%unified_info,
  2173. tls => \@tls,
  2174. dtls => \@dtls,
  2175. makevars => [ sort keys %user ],
  2176. disabled_info => \%disabled_info,
  2177. user_crossable => \@user_crossable,
  2178. );
  2179. my $configdata_outname = 'configdata.pm';
  2180. print "Creating $configdata_outname\n";
  2181. open CONFIGDATA, ">$configdata_outname.new"
  2182. or die "Trying to create $configdata_outname.new: $!";
  2183. my $configdata_tmplname = cleanfile($srcdir, "configdata.pm.in", $blddir);
  2184. my $configdata_tmpl =
  2185. OpenSSL::Template->new(TYPE => 'FILE', SOURCE => $configdata_tmplname);
  2186. $configdata_tmpl->fill_in(
  2187. FILENAME => $configdata_tmplname,
  2188. OUTPUT => \*CONFIGDATA,
  2189. HASH => { %template_vars,
  2190. autowarntext => [
  2191. 'WARNING: do not edit!',
  2192. "Generated by Configure from $configdata_tmplname",
  2193. ] }
  2194. ) or die $Text::Template::ERROR;
  2195. close CONFIGDATA;
  2196. rename "$configdata_outname.new", $configdata_outname;
  2197. if ($builder_platform eq 'unix') {
  2198. my $mode = (0755 & ~umask);
  2199. chmod $mode, 'configdata.pm'
  2200. or warn sprintf("WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s\n",$mode,$!);
  2201. }
  2202. print "Running $configdata_outname\n";
  2203. my $perlcmd = (quotify("maybeshell", $config{PERL}))[0];
  2204. my $cmd = "$perlcmd $configdata_outname";
  2205. #print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
  2206. system($cmd);
  2207. exit 1 if $? != 0;
  2208. $SIG{__DIE__} = $orig_death_handler;
  2209. print <<"EOF" if ($disabled{threads} eq "unavailable");
  2210. The library could not be configured for supporting multi-threaded
  2211. applications as the compiler options required on this system are not known.
  2212. See file INSTALL for details if you need multi-threading.
  2213. EOF
  2214. print <<"EOF" if ($no_shared_warn);
  2215. The options 'shared', 'pic' and 'dynamic-engine' aren't supported on this
  2216. platform, so we will pretend you gave the option 'no-pic', which also disables
  2217. 'shared' and 'dynamic-engine'. If you know how to implement shared libraries
  2218. or position independent code, please let us know (but please first make sure
  2219. you have tried with a current version of OpenSSL).
  2220. EOF
  2221. print <<"EOF";
  2222. **********************************************************************
  2223. *** ***
  2224. *** OpenSSL has been successfully configured ***
  2225. *** ***
  2226. *** If you encounter a problem while building, please open an ***
  2227. *** issue on GitHub <https://github.com/openssl/openssl/issues> ***
  2228. *** and include the output from the following command: ***
  2229. *** ***
  2230. *** perl configdata.pm --dump ***
  2231. *** ***
  2232. *** (If you are new to OpenSSL, you might want to consult the ***
  2233. *** 'Troubleshooting' section in the INSTALL file first) ***
  2234. *** ***
  2235. **********************************************************************
  2236. EOF
  2237. exit(0);
  2238. ######################################################################
  2239. #
  2240. # Helpers and utility functions
  2241. #
  2242. # Death handler, to print a helpful message in case of failure #######
  2243. #
  2244. sub death_handler {
  2245. die @_ if $^S; # To prevent the added message in eval blocks
  2246. my $build_file = $target{build_file} // "build file";
  2247. my @message = ( <<"_____", @_ );
  2248. Failure! $build_file wasn't produced.
  2249. Please read INSTALL and associated NOTES files. You may also have to look over
  2250. your available compiler tool chain or change your configuration.
  2251. _____
  2252. # Dying is terminal, so it's ok to reset the signal handler here.
  2253. $SIG{__DIE__} = $orig_death_handler;
  2254. die @message;
  2255. }
  2256. # Configuration file reading #########################################
  2257. # Note: All of the helper functions are for lazy evaluation. They all
  2258. # return a CODE ref, which will return the intended value when evaluated.
  2259. # Thus, whenever there's mention of a returned value, it's about that
  2260. # intended value.
  2261. # Helper function to implement conditional value variants, with a default
  2262. # plus additional values based on the value of $config{build_type}.
  2263. # Arguments are given in hash table form:
  2264. #
  2265. # picker(default => "Basic string: ",
  2266. # debug => "debug",
  2267. # release => "release")
  2268. #
  2269. # When configuring with --debug, the resulting string will be
  2270. # "Basic string: debug", and when not, it will be "Basic string: release"
  2271. #
  2272. # This can be used to create variants of sets of flags according to the
  2273. # build type:
  2274. #
  2275. # cflags => picker(default => "-Wall",
  2276. # debug => "-g -O0",
  2277. # release => "-O3")
  2278. #
  2279. sub picker {
  2280. my %opts = @_;
  2281. return sub { add($opts{default} || (),
  2282. $opts{$config{build_type}} || ())->(); }
  2283. }
  2284. # Helper function to combine several values of different types into one.
  2285. # This is useful if you want to combine a string with the result of a
  2286. # lazy function, such as:
  2287. #
  2288. # cflags => combine("-Wall", sub { $disabled{zlib} ? () : "-DZLIB" })
  2289. #
  2290. sub combine {
  2291. my @stuff = @_;
  2292. return sub { add(@stuff)->(); }
  2293. }
  2294. # Helper function to implement conditional values depending on the value
  2295. # of $disabled{threads}. Can be used as follows:
  2296. #
  2297. # cflags => combine("-Wall", threads("-pthread"))
  2298. #
  2299. sub threads {
  2300. my @flags = @_;
  2301. return sub { add($disabled{threads} ? () : @flags)->(); }
  2302. }
  2303. sub shared {
  2304. my @flags = @_;
  2305. return sub { add($disabled{shared} ? () : @flags)->(); }
  2306. }
  2307. our $add_called = 0;
  2308. # Helper function to implement adding values to already existing configuration
  2309. # values. It handles elements that are ARRAYs, CODEs and scalars
  2310. sub _add {
  2311. my $separator = shift;
  2312. # If there's any ARRAY in the collection of values OR the separator
  2313. # is undef, we will return an ARRAY of combined values, otherwise a
  2314. # string of joined values with $separator as the separator.
  2315. my $found_array = !defined($separator);
  2316. my @values =
  2317. map {
  2318. my $res = $_;
  2319. while (ref($res) eq "CODE") {
  2320. $res = $res->();
  2321. }
  2322. if (defined($res)) {
  2323. if (ref($res) eq "ARRAY") {
  2324. $found_array = 1;
  2325. @$res;
  2326. } else {
  2327. $res;
  2328. }
  2329. } else {
  2330. ();
  2331. }
  2332. } (@_);
  2333. $add_called = 1;
  2334. if ($found_array) {
  2335. [ @values ];
  2336. } else {
  2337. join($separator, grep { defined($_) && $_ ne "" } @values);
  2338. }
  2339. }
  2340. sub add_before {
  2341. my $separator = " ";
  2342. if (ref($_[$#_]) eq "HASH") {
  2343. my $opts = pop;
  2344. $separator = $opts->{separator};
  2345. }
  2346. my @x = @_;
  2347. sub { _add($separator, @x, @_) };
  2348. }
  2349. sub add {
  2350. my $separator = " ";
  2351. if (ref($_[$#_]) eq "HASH") {
  2352. my $opts = pop;
  2353. $separator = $opts->{separator};
  2354. }
  2355. my @x = @_;
  2356. sub { _add($separator, @_, @x) };
  2357. }
  2358. sub read_eval_file {
  2359. my $fname = shift;
  2360. my $content;
  2361. my @result;
  2362. open F, "< $fname" or die "Can't open '$fname': $!\n";
  2363. {
  2364. undef local $/;
  2365. $content = <F>;
  2366. }
  2367. close F;
  2368. {
  2369. local $@;
  2370. @result = ( eval $content );
  2371. warn $@ if $@;
  2372. }
  2373. return wantarray ? @result : $result[0];
  2374. }
  2375. # configuration reader, evaluates the input file as a perl script and expects
  2376. # it to fill %targets with target configurations. Those are then added to
  2377. # %table.
  2378. sub read_config {
  2379. my $fname = shift;
  2380. my %targets;
  2381. {
  2382. # Protect certain tables from tampering
  2383. local %table = ();
  2384. %targets = read_eval_file($fname);
  2385. }
  2386. my %preexisting = ();
  2387. foreach (sort keys %targets) {
  2388. $preexisting{$_} = 1 if $table{$_};
  2389. }
  2390. die <<"EOF",
  2391. The following config targets from $fname
  2392. shadow pre-existing config targets with the same name:
  2393. EOF
  2394. map { " $_\n" } sort keys %preexisting
  2395. if %preexisting;
  2396. # For each target, check that it's configured with a hash table.
  2397. foreach (keys %targets) {
  2398. if (ref($targets{$_}) ne "HASH") {
  2399. if (ref($targets{$_}) eq "") {
  2400. warn "Deprecated target configuration for $_, ignoring...\n";
  2401. } else {
  2402. warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
  2403. }
  2404. delete $targets{$_};
  2405. } else {
  2406. $targets{$_}->{_conf_fname_int} = add([ $fname ]);
  2407. }
  2408. }
  2409. %table = (%table, %targets);
  2410. }
  2411. # configuration resolver. Will only resolve all the lazy evaluation
  2412. # codeblocks for the chosen target and all those it inherits from,
  2413. # recursively
  2414. sub resolve_config {
  2415. my $target = shift;
  2416. my @breadcrumbs = @_;
  2417. # my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS});
  2418. if (grep { $_ eq $target } @breadcrumbs) {
  2419. die "inherit_from loop! target backtrace:\n "
  2420. ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
  2421. }
  2422. if (!defined($table{$target})) {
  2423. warn "Warning! target $target doesn't exist!\n";
  2424. return ();
  2425. }
  2426. # Recurse through all inheritances. They will be resolved on the
  2427. # fly, so when this operation is done, they will all just be a
  2428. # bunch of attributes with string values.
  2429. # What we get here, though, are keys with references to lists of
  2430. # the combined values of them all. We will deal with lists after
  2431. # this stage is done.
  2432. my %combined_inheritance = ();
  2433. if ($table{$target}->{inherit_from}) {
  2434. my @inherit_from =
  2435. map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
  2436. foreach (@inherit_from) {
  2437. my %inherited_config = resolve_config($_, $target, @breadcrumbs);
  2438. # 'template' is a marker that's considered private to
  2439. # the config that had it.
  2440. delete $inherited_config{template};
  2441. foreach (keys %inherited_config) {
  2442. if (!$combined_inheritance{$_}) {
  2443. $combined_inheritance{$_} = [];
  2444. }
  2445. push @{$combined_inheritance{$_}}, $inherited_config{$_};
  2446. }
  2447. }
  2448. }
  2449. # We won't need inherit_from in this target any more, since we've
  2450. # resolved all the inheritances that lead to this
  2451. delete $table{$target}->{inherit_from};
  2452. # Now is the time to deal with those lists. Here's the place to
  2453. # decide what shall be done with those lists, all based on the
  2454. # values of the target we're currently dealing with.
  2455. # - If a value is a coderef, it will be executed with the list of
  2456. # inherited values as arguments.
  2457. # - If the corresponding key doesn't have a value at all or is the
  2458. # empty string, the inherited value list will be run through the
  2459. # default combiner (below), and the result becomes this target's
  2460. # value.
  2461. # - Otherwise, this target's value is assumed to be a string that
  2462. # will simply override the inherited list of values.
  2463. my $default_combiner = add();
  2464. my %all_keys =
  2465. map { $_ => 1 } (keys %combined_inheritance,
  2466. keys %{$table{$target}});
  2467. sub process_values {
  2468. my $object = shift;
  2469. my $inherited = shift; # Always a [ list ]
  2470. my $target = shift;
  2471. my $entry = shift;
  2472. $add_called = 0;
  2473. while(ref($object) eq "CODE") {
  2474. $object = $object->(@$inherited);
  2475. }
  2476. if (!defined($object)) {
  2477. return ();
  2478. }
  2479. elsif (ref($object) eq "ARRAY") {
  2480. local $add_called; # To make sure recursive calls don't affect it
  2481. return [ map { process_values($_, $inherited, $target, $entry) }
  2482. @$object ];
  2483. } elsif (ref($object) eq "") {
  2484. return $object;
  2485. } else {
  2486. die "cannot handle reference type ",ref($object)
  2487. ," found in target ",$target," -> ",$entry,"\n";
  2488. }
  2489. }
  2490. foreach (sort keys %all_keys) {
  2491. my $previous = $combined_inheritance{$_};
  2492. # Current target doesn't have a value for the current key?
  2493. # Assign it the default combiner, the rest of this loop body
  2494. # will handle it just like any other coderef.
  2495. if (!exists $table{$target}->{$_}) {
  2496. $table{$target}->{$_} = $default_combiner;
  2497. }
  2498. $table{$target}->{$_} = process_values($table{$target}->{$_},
  2499. $combined_inheritance{$_},
  2500. $target, $_);
  2501. unless(defined($table{$target}->{$_})) {
  2502. delete $table{$target}->{$_};
  2503. }
  2504. # if ($extra_checks &&
  2505. # $previous && !($add_called || $previous ~~ $table{$target}->{$_})) {
  2506. # warn "$_ got replaced in $target\n";
  2507. # }
  2508. }
  2509. # Finally done, return the result.
  2510. return %{$table{$target}};
  2511. }
  2512. sub usage
  2513. {
  2514. print STDERR $usage;
  2515. print STDERR "\npick os/compiler from:\n";
  2516. my $j=0;
  2517. my $i;
  2518. my $k=0;
  2519. foreach $i (sort keys %table)
  2520. {
  2521. next if $table{$i}->{template};
  2522. next if $i =~ /^debug/;
  2523. $k += length($i) + 1;
  2524. if ($k > 78)
  2525. {
  2526. print STDERR "\n";
  2527. $k=length($i);
  2528. }
  2529. print STDERR $i . " ";
  2530. }
  2531. foreach $i (sort keys %table)
  2532. {
  2533. next if $table{$i}->{template};
  2534. next if $i !~ /^debug/;
  2535. $k += length($i) + 1;
  2536. if ($k > 78)
  2537. {
  2538. print STDERR "\n";
  2539. $k=length($i);
  2540. }
  2541. print STDERR $i . " ";
  2542. }
  2543. print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n";
  2544. exit(1);
  2545. }
  2546. sub compiler_predefined {
  2547. state %predefined;
  2548. my $cc = shift;
  2549. return () if $^O eq 'VMS';
  2550. die 'compiler_predefined called without a compiler command'
  2551. unless $cc;
  2552. if (! $predefined{$cc}) {
  2553. $predefined{$cc} = {};
  2554. # collect compiler pre-defines from gcc or gcc-alike...
  2555. open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |");
  2556. while (my $l = <PIPE>) {
  2557. $l =~ m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last;
  2558. $predefined{$cc}->{$1} = $2 // '';
  2559. }
  2560. close(PIPE);
  2561. }
  2562. return %{$predefined{$cc}};
  2563. }
  2564. sub which
  2565. {
  2566. my ($name)=@_;
  2567. if (eval { require IPC::Cmd; 1; }) {
  2568. IPC::Cmd->import();
  2569. return scalar IPC::Cmd::can_run($name);
  2570. } else {
  2571. # if there is $directories component in splitpath,
  2572. # then it's not something to test with $PATH...
  2573. return $name if (File::Spec->splitpath($name))[1];
  2574. foreach (File::Spec->path()) {
  2575. my $fullpath = catfile($_, "$name$target{exe_extension}");
  2576. if (-f $fullpath and -x $fullpath) {
  2577. return $fullpath;
  2578. }
  2579. }
  2580. }
  2581. }
  2582. sub env
  2583. {
  2584. my $name = shift;
  2585. my %opts = @_;
  2586. unless ($opts{cacheonly}) {
  2587. # Note that if $ENV{$name} doesn't exist or is undefined,
  2588. # $config{perlenv}->{$name} will be created with the value
  2589. # undef. This is intentional.
  2590. $config{perlenv}->{$name} = $ENV{$name}
  2591. if ! exists $config{perlenv}->{$name};
  2592. }
  2593. return $config{perlenv}->{$name};
  2594. }
  2595. # Configuration printer ##############################################
  2596. sub print_table_entry
  2597. {
  2598. local $now_printing = shift;
  2599. my %target = resolve_config($now_printing);
  2600. my $type = shift;
  2601. # Don't print the templates
  2602. return if $target{template};
  2603. my @sequence = (
  2604. "sys_id",
  2605. "cpp",
  2606. "cppflags",
  2607. "defines",
  2608. "includes",
  2609. "cc",
  2610. "cflags",
  2611. "ld",
  2612. "lflags",
  2613. "loutflag",
  2614. "ex_libs",
  2615. "bn_ops",
  2616. "poly1035_asm_src",
  2617. "thread_scheme",
  2618. "perlasm_scheme",
  2619. "dso_scheme",
  2620. "shared_target",
  2621. "shared_cflag",
  2622. "shared_defines",
  2623. "shared_ldflag",
  2624. "shared_rcflag",
  2625. "shared_extension",
  2626. "dso_extension",
  2627. "obj_extension",
  2628. "exe_extension",
  2629. "ranlib",
  2630. "ar",
  2631. "arflags",
  2632. "aroutflag",
  2633. "rc",
  2634. "rcflags",
  2635. "rcoutflag",
  2636. "mt",
  2637. "mtflags",
  2638. "mtinflag",
  2639. "mtoutflag",
  2640. "multilib",
  2641. "build_scheme",
  2642. );
  2643. if ($type eq "TABLE") {
  2644. print "\n";
  2645. print "*** $now_printing\n";
  2646. foreach (@sequence) {
  2647. if (ref($target{$_}) eq "ARRAY") {
  2648. printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}});
  2649. } else {
  2650. printf "\$%-12s = %s\n", $_, $target{$_};
  2651. }
  2652. }
  2653. } elsif ($type eq "HASH") {
  2654. my $largest =
  2655. length((sort { length($a) <=> length($b) } @sequence)[-1]);
  2656. print " '$now_printing' => {\n";
  2657. foreach (@sequence) {
  2658. if ($target{$_}) {
  2659. if (ref($target{$_}) eq "ARRAY") {
  2660. print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n";
  2661. } else {
  2662. print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
  2663. }
  2664. }
  2665. }
  2666. print " },\n";
  2667. }
  2668. }
  2669. # Utility routines ###################################################
  2670. # On VMS, if the given file is a logical name, File::Spec::Functions
  2671. # will consider it an absolute path. There are cases when we want a
  2672. # purely syntactic check without checking the environment.
  2673. sub isabsolute {
  2674. my $file = shift;
  2675. # On non-platforms, we just use file_name_is_absolute().
  2676. return file_name_is_absolute($file) unless $^O eq "VMS";
  2677. # If the file spec includes a device or a directory spec,
  2678. # file_name_is_absolute() is perfectly safe.
  2679. return file_name_is_absolute($file) if $file =~ m|[:\[]|;
  2680. # Here, we know the given file spec isn't absolute
  2681. return 0;
  2682. }
  2683. # Makes a directory absolute and cleans out /../ in paths like foo/../bar
  2684. # On some platforms, this uses rel2abs(), while on others, realpath() is used.
  2685. # realpath() requires that at least all path components except the last is an
  2686. # existing directory. On VMS, the last component of the directory spec must
  2687. # exist.
  2688. sub absolutedir {
  2689. my $dir = shift;
  2690. # realpath() is quite buggy on VMS. It uses LIB$FID_TO_NAME, which
  2691. # will return the volume name for the device, no matter what. Also,
  2692. # it will return an incorrect directory spec if the argument is a
  2693. # directory that doesn't exist.
  2694. if ($^O eq "VMS") {
  2695. return rel2abs($dir);
  2696. }
  2697. # We use realpath() on Unix, since no other will properly clean out
  2698. # a directory spec.
  2699. use Cwd qw/realpath/;
  2700. return realpath($dir);
  2701. }
  2702. sub quotify {
  2703. my %processors = (
  2704. perl => sub { my $x = shift;
  2705. $x =~ s/([\\\$\@"])/\\$1/g;
  2706. return '"'.$x.'"'; },
  2707. maybeshell => sub { my $x = shift;
  2708. (my $y = $x) =~ s/([\\\"])/\\$1/g;
  2709. if ($x ne $y || $x =~ m|\s|) {
  2710. return '"'.$y.'"';
  2711. } else {
  2712. return $x;
  2713. }
  2714. },
  2715. );
  2716. my $for = shift;
  2717. my $processor =
  2718. defined($processors{$for}) ? $processors{$for} : sub { shift; };
  2719. return map { $processor->($_); } @_;
  2720. }
  2721. # collect_from_file($filename, $line_concat_cond_re, $line_concat)
  2722. # $filename is a file name to read from
  2723. # $line_concat_cond_re is a regexp detecting a line continuation ending
  2724. # $line_concat is a CODEref that takes care of concatenating two lines
  2725. sub collect_from_file {
  2726. my $filename = shift;
  2727. my $line_concat_cond_re = shift;
  2728. my $line_concat = shift;
  2729. open my $fh, $filename || die "unable to read $filename: $!\n";
  2730. return sub {
  2731. my $saved_line = "";
  2732. $_ = "";
  2733. while (<$fh>) {
  2734. s|\R$||;
  2735. if (defined $line_concat) {
  2736. $_ = $line_concat->($saved_line, $_);
  2737. $saved_line = "";
  2738. }
  2739. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  2740. $saved_line = $_;
  2741. next;
  2742. }
  2743. return $_;
  2744. }
  2745. die "$filename ending with continuation line\n" if $_;
  2746. close $fh;
  2747. return undef;
  2748. }
  2749. }
  2750. # collect_from_array($array, $line_concat_cond_re, $line_concat)
  2751. # $array is an ARRAYref of lines
  2752. # $line_concat_cond_re is a regexp detecting a line continuation ending
  2753. # $line_concat is a CODEref that takes care of concatenating two lines
  2754. sub collect_from_array {
  2755. my $array = shift;
  2756. my $line_concat_cond_re = shift;
  2757. my $line_concat = shift;
  2758. my @array = (@$array);
  2759. return sub {
  2760. my $saved_line = "";
  2761. $_ = "";
  2762. while (defined($_ = shift @array)) {
  2763. s|\R$||;
  2764. if (defined $line_concat) {
  2765. $_ = $line_concat->($saved_line, $_);
  2766. $saved_line = "";
  2767. }
  2768. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  2769. $saved_line = $_;
  2770. next;
  2771. }
  2772. return $_;
  2773. }
  2774. die "input text ending with continuation line\n" if $_;
  2775. return undef;
  2776. }
  2777. }
  2778. # collect_information($lineiterator, $line_continue, $regexp => $CODEref, ...)
  2779. # $lineiterator is a CODEref that delivers one line at a time.
  2780. # All following arguments are regex/CODEref pairs, where the regexp detects a
  2781. # line and the CODEref does something with the result of the regexp.
  2782. sub collect_information {
  2783. my $lineiterator = shift;
  2784. my %collectors = @_;
  2785. while(defined($_ = $lineiterator->())) {
  2786. s|\R$||;
  2787. my $found = 0;
  2788. if ($collectors{"BEFORE"}) {
  2789. $collectors{"BEFORE"}->($_);
  2790. }
  2791. foreach my $re (keys %collectors) {
  2792. if ($re !~ /^OTHERWISE|BEFORE|AFTER$/ && /$re/) {
  2793. $collectors{$re}->($lineiterator);
  2794. $found = 1;
  2795. };
  2796. }
  2797. if ($collectors{"OTHERWISE"}) {
  2798. $collectors{"OTHERWISE"}->($lineiterator, $_)
  2799. unless $found || !defined $collectors{"OTHERWISE"};
  2800. }
  2801. if ($collectors{"AFTER"}) {
  2802. $collectors{"AFTER"}->($_);
  2803. }
  2804. }
  2805. }
  2806. # tokenize($line)
  2807. # tokenize($line,$separator)
  2808. # $line is a line of text to split up into tokens
  2809. # $separator [optional] is a regular expression that separates the tokens,
  2810. # the default being spaces. Do not use quotes of any kind as separators,
  2811. # that will give undefined results.
  2812. # Returns a list of tokens.
  2813. #
  2814. # Tokens are divided by separator (spaces by default). If the tokens include
  2815. # the separators, they have to be quoted with single or double quotes.
  2816. # Double quotes inside a double quoted token must be escaped. Escaping is done
  2817. # with backslash.
  2818. # Basically, the same quoting rules apply for " and ' as in any
  2819. # Unix shell.
  2820. sub tokenize {
  2821. my $line = my $debug_line = shift;
  2822. my $separator = shift // qr|\s+|;
  2823. my @result = ();
  2824. if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) {
  2825. print STDERR "DEBUG[tokenize]: \$separator = $separator\n";
  2826. }
  2827. while ($line =~ s|^${separator}||, $line ne "") {
  2828. my $token = "";
  2829. again:
  2830. $line =~ m/^(.*?)(${separator}|"|'|$)/;
  2831. $token .= $1;
  2832. $line = $2.$';
  2833. if ($line =~ m/^"((?:[^"\\]+|\\.)*)"/) {
  2834. $token .= $1;
  2835. $line = $';
  2836. goto again;
  2837. } elsif ($line =~ m/^'([^']*)'/) {
  2838. $token .= $1;
  2839. $line = $';
  2840. goto again;
  2841. }
  2842. push @result, $token;
  2843. }
  2844. if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) {
  2845. print STDERR "DEBUG[tokenize]: Parsed '$debug_line' into:\n";
  2846. print STDERR "DEBUG[tokenize]: ('", join("', '", @result), "')\n";
  2847. }
  2848. return @result;
  2849. }