Configure 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760
  1. #! /usr/bin/env perl
  2. # -*- mode: perl; -*-
  3. # Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
  4. #
  5. # Licensed under the OpenSSL license (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. require 5.10.0;
  11. use strict;
  12. use Config;
  13. use File::Basename;
  14. use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
  15. use File::Path qw/mkpath/;
  16. use if $^O ne "VMS", 'File::Glob' => qw/glob/;
  17. # see INSTALL for instructions.
  18. my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";
  19. # Options:
  20. #
  21. # --config add the given configuration file, which will be read after
  22. # any "Configurations*" files that are found in the same
  23. # directory as this script.
  24. # --prefix prefix for the OpenSSL installation, which includes the
  25. # directories bin, lib, include, share/man, share/doc/openssl
  26. # This becomes the value of INSTALLTOP in Makefile
  27. # (Default: /usr/local)
  28. # --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys.
  29. # If it's a relative directory, it will be added on the directory
  30. # given with --prefix.
  31. # This becomes the value of OPENSSLDIR in Makefile and in C.
  32. # (Default: PREFIX/ssl)
  33. #
  34. # --cross-compile-prefix Add specified prefix to binutils components.
  35. #
  36. # --api One of 0.9.8, 1.0.0 or 1.1.0. Do not compile support for
  37. # interfaces deprecated as of the specified OpenSSL version.
  38. #
  39. # no-hw-xxx do not compile support for specific crypto hardware.
  40. # Generic OpenSSL-style methods relating to this support
  41. # are always compiled but return NULL if the hardware
  42. # support isn't compiled.
  43. # no-hw do not compile support for any crypto hardware.
  44. # [no-]threads [don't] try to create a library that is suitable for
  45. # multithreaded applications (default is "threads" if we
  46. # know how to do it)
  47. # [no-]shared [don't] try to create shared libraries when supported.
  48. # [no-]pic [don't] try to build position independent code when supported.
  49. # If disabled, it also disables shared and dynamic-engine.
  50. # no-asm do not use assembler
  51. # no-dso do not compile in any native shared-library methods. This
  52. # will ensure that all methods just return NULL.
  53. # no-egd do not compile support for the entropy-gathering daemon APIs
  54. # [no-]zlib [don't] compile support for zlib compression.
  55. # zlib-dynamic Like "zlib", but the zlib library is expected to be a shared
  56. # library and will be loaded in run-time by the OpenSSL library.
  57. # sctp include SCTP support
  58. # enable-weak-ssl-ciphers
  59. # Enable weak ciphers that are disabled by default. This currently
  60. # only includes RC4 based ciphers.
  61. # 386 generate 80386 code in assembly modules
  62. # no-sse2 disables IA-32 SSE2 code in assembly modules, the above
  63. # mentioned '386' option implies this one
  64. # no-<cipher> build without specified algorithm (rsa, idea, rc5, ...)
  65. # -<xxx> +<xxx> compiler options are passed through
  66. # -static while -static is also a pass-through compiler option (and
  67. # as such is limited to environments where it's actually
  68. # meaningful), it triggers a number configuration options,
  69. # namely no-dso, no-pic, no-shared and no-threads. It is
  70. # argued that the only reason to produce statically linked
  71. # binaries (and in context it means executables linked with
  72. # -static flag, and not just executables linked with static
  73. # libcrypto.a) is to eliminate dependency on specific run-time,
  74. # a.k.a. libc version. The mentioned config options are meant
  75. # to achieve just that. Unfortunately on Linux it's impossible
  76. # to eliminate the dependency completely for openssl executable
  77. # because of getaddrinfo and gethostbyname calls, which can
  78. # invoke dynamically loadable library facility anyway to meet
  79. # the lookup requests. For this reason on Linux statically
  80. # linked openssl executable has rather debugging value than
  81. # production quality.
  82. #
  83. # DEBUG_SAFESTACK use type-safe stacks to enforce type-safety on stack items
  84. # provided to stack calls. Generates unique stack functions for
  85. # each possible stack type.
  86. # BN_LLONG use the type 'long long' in crypto/bn/bn.h
  87. # RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
  88. # Following are set automatically by this script
  89. #
  90. # MD5_ASM use some extra md5 assembler,
  91. # SHA1_ASM use some extra sha1 assembler, must define L_ENDIAN for x86
  92. # RMD160_ASM use some extra ripemd160 assembler,
  93. # SHA256_ASM sha256_block is implemented in assembler
  94. # SHA512_ASM sha512_block is implemented in assembler
  95. # AES_ASM AES_[en|de]crypt is implemented in assembler
  96. # Minimum warning options... any contributions to OpenSSL should at least get
  97. # past these.
  98. # DEBUG_UNUSED enables __owur (warn unused result) checks.
  99. # -DPEDANTIC complements -pedantic and is meant to mask code that
  100. # is not strictly standard-compliant and/or implementation-specific,
  101. # e.g. inline assembly, disregards to alignment requirements, such
  102. # that -pedantic would complain about. Incidentally -DPEDANTIC has
  103. # to be used even in sanitized builds, because sanitizer too is
  104. # supposed to and does take notice of non-standard behaviour. Then
  105. # -pedantic with pre-C9x compiler would also complain about 'long
  106. # long' not being supported. As 64-bit algorithms are common now,
  107. # it grew impossible to resolve this without sizeable additional
  108. # code, so we just tell compiler to be pedantic about everything
  109. # but 'long long' type.
  110. my $gcc_devteam_warn = "-DDEBUG_UNUSED"
  111. . " -Wswitch"
  112. . " -DPEDANTIC -pedantic -Wno-long-long"
  113. . " -Wall"
  114. . " -Wsign-compare"
  115. . " -Wmissing-prototypes"
  116. . " -Wshadow"
  117. . " -Wformat"
  118. . " -Wtype-limits"
  119. . " -Wundef"
  120. . " -Werror"
  121. ;
  122. # These are used in addition to $gcc_devteam_warn when the compiler is clang.
  123. # TODO(openssl-team): fix problems and investigate if (at least) the
  124. # following warnings can also be enabled:
  125. # -Wcast-align
  126. # -Wunreachable-code -- no, too ugly/compiler-specific
  127. # -Wlanguage-extension-token -- no, we use asm()
  128. # -Wunused-macros -- no, too tricky for BN and _XOPEN_SOURCE etc
  129. # -Wextended-offsetof -- no, needed in CMS ASN1 code
  130. my $clang_devteam_warn = ""
  131. . " -Qunused-arguments"
  132. . " -Wextra"
  133. . " -Wswitch -Wswitch-default"
  134. . " -Wno-unused-parameter"
  135. . " -Wno-parentheses-equality"
  136. . " -Wno-missing-field-initializers"
  137. . " -Wno-language-extension-token"
  138. . " -Wno-extended-offsetof"
  139. . " -Wconditional-uninitialized"
  140. . " -Wincompatible-pointer-types-discards-qualifiers"
  141. . " -Wmissing-variable-declarations"
  142. . " -Wundef"
  143. ;
  144. # This adds backtrace information to the memory leak info. Is only used
  145. # when crypto-mdebug-backtrace is enabled.
  146. my $memleak_devteam_backtrace = "-rdynamic";
  147. my $strict_warnings = 0;
  148. # As for $BSDthreads. Idea is to maintain "collective" set of flags,
  149. # which would cover all BSD flavors. -pthread applies to them all,
  150. # but is treated differently. OpenBSD expands is as -D_POSIX_THREAD
  151. # -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r,
  152. # which has to be accompanied by explicit -D_THREAD_SAFE and
  153. # sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which
  154. # seems to be sufficient?
  155. our $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT";
  156. #
  157. # API compatibility name to version number mapping.
  158. #
  159. my $maxapi = "1.1.0"; # API for "no-deprecated" builds
  160. my $apitable = {
  161. "1.1.0" => "0x10100000L",
  162. "1.0.0" => "0x10000000L",
  163. "0.9.8" => "0x00908000L",
  164. };
  165. our %table = ();
  166. our %config = ();
  167. our %withargs = ();
  168. # Forward declarations ###############################################
  169. # read_config(filename)
  170. #
  171. # Reads a configuration file and populates %table with the contents
  172. # (which the configuration file places in %targets).
  173. sub read_config;
  174. # resolve_config(target)
  175. #
  176. # Resolves all the late evaluations, inheritances and so on for the
  177. # chosen target and any target it inherits from.
  178. sub resolve_config;
  179. # Information collection #############################################
  180. # Unified build supports separate build dir
  181. my $srcdir = catdir(absolutedir(dirname($0))); # catdir ensures local syntax
  182. my $blddir = catdir(absolutedir(".")); # catdir ensures local syntax
  183. my $dofile = abs2rel(catfile($srcdir, "util/dofile.pl"));
  184. my $local_config_envname = 'OPENSSL_LOCAL_CONFIG_DIR';
  185. $config{sourcedir} = abs2rel($srcdir);
  186. $config{builddir} = abs2rel($blddir);
  187. # Collect reconfiguration information if needed
  188. my @argvcopy=@ARGV;
  189. if (grep /^reconf(igure)?$/, @argvcopy) {
  190. if (-f "./configdata.pm") {
  191. my $file = "./configdata.pm";
  192. unless (my $return = do $file) {
  193. die "couldn't parse $file: $@" if $@;
  194. die "couldn't do $file: $!" unless defined $return;
  195. die "couldn't run $file" unless $return;
  196. }
  197. @argvcopy = defined($configdata::config{perlargv}) ?
  198. @{$configdata::config{perlargv}} : ();
  199. die "Incorrect data to reconfigure, please do a normal configuration\n"
  200. if (grep(/^reconf/,@argvcopy));
  201. $ENV{CROSS_COMPILE} = $configdata::config{cross_compile_prefix}
  202. if defined($configdata::config{cross_compile_prefix});
  203. $ENV{CC} = $configdata::config{cc}
  204. if defined($configdata::config{cc});
  205. $ENV{CXX} = $configdata::config{cxx}
  206. if defined($configdata::config{cxx});
  207. $ENV{BUILDFILE} = $configdata::config{build_file}
  208. if defined($configdata::config{build_file});
  209. $ENV{$local_config_envname} = $configdata::config{local_config_dir}
  210. if defined($configdata::config{local_config_dir});
  211. print "Reconfiguring with: ", join(" ",@argvcopy), "\n";
  212. print " CROSS_COMPILE = ",$ENV{CROSS_COMPILE},"\n"
  213. if $ENV{CROSS_COMPILE};
  214. print " CC = ",$ENV{CC},"\n" if $ENV{CC};
  215. print " CXX = ",$ENV{CXX},"\n" if $ENV{CXX};
  216. print " BUILDFILE = ",$ENV{BUILDFILE},"\n" if $ENV{BUILDFILE};
  217. print " $local_config_envname = ",$ENV{$local_config_envname},"\n"
  218. if $ENV{$local_config_envname};
  219. } else {
  220. die "Insufficient data to reconfigure, please do a normal configuration\n";
  221. }
  222. }
  223. $config{perlargv} = [ @argvcopy ];
  224. # Collect version numbers
  225. $config{version} = "unknown";
  226. $config{version_num} = "unknown";
  227. $config{shlib_version_number} = "unknown";
  228. $config{shlib_version_history} = "unknown";
  229. collect_information(
  230. collect_from_file(catfile($srcdir,'include/openssl/opensslv.h')),
  231. qr/OPENSSL.VERSION.TEXT.*OpenSSL (\S+) / => sub { $config{version} = $1; },
  232. qr/OPENSSL.VERSION.NUMBER.*(0x\S+)/ => sub { $config{version_num}=$1 },
  233. qr/SHLIB_VERSION_NUMBER *"([^"]+)"/ => sub { $config{shlib_version_number}=$1 },
  234. qr/SHLIB_VERSION_HISTORY *"([^"]*)"/ => sub { $config{shlib_version_history}=$1 }
  235. );
  236. if ($config{shlib_version_history} ne "") { $config{shlib_version_history} .= ":"; }
  237. ($config{major}, $config{minor})
  238. = ($config{version} =~ /^([0-9]+)\.([0-9\.]+)/);
  239. ($config{shlib_major}, $config{shlib_minor})
  240. = ($config{shlib_version_number} =~ /^([0-9]+)\.([0-9\.]+)/);
  241. die "erroneous version information in opensslv.h: ",
  242. "$config{major}, $config{minor}, $config{shlib_major}, $config{shlib_minor}\n"
  243. if ($config{major} eq "" || $config{minor} eq ""
  244. || $config{shlib_major} eq "" || $config{shlib_minor} eq "");
  245. # Collect target configurations
  246. my $pattern = catfile(dirname($0), "Configurations", "*.conf");
  247. foreach (sort glob($pattern)) {
  248. &read_config($_);
  249. }
  250. if (defined $ENV{$local_config_envname}) {
  251. if ($^O eq 'VMS') {
  252. # VMS environment variables are logical names,
  253. # which can be used as is
  254. $pattern = $local_config_envname . ':' . '*.conf';
  255. } else {
  256. $pattern = catfile($ENV{$local_config_envname}, '*.conf');
  257. }
  258. foreach (sort glob($pattern)) {
  259. &read_config($_);
  260. }
  261. }
  262. print "Configuring OpenSSL version $config{version} ($config{version_num})\n";
  263. $config{prefix}="";
  264. $config{openssldir}="";
  265. $config{processor}="";
  266. $config{libdir}="";
  267. $config{cross_compile_prefix}="";
  268. my $auto_threads=1; # enable threads automatically? true by default
  269. my $default_ranlib;
  270. # Top level directories to build
  271. $config{dirs} = [ "crypto", "ssl", "engines", "apps", "test", "util", "tools", "fuzz" ];
  272. # crypto/ subdirectories to build
  273. $config{sdirs} = [
  274. "objects",
  275. "md2", "md4", "md5", "sha", "mdc2", "hmac", "ripemd", "whrlpool", "poly1305", "blake2", "siphash",
  276. "des", "aes", "rc2", "rc4", "rc5", "idea", "aria", "bf", "cast", "camellia", "seed", "chacha", "modes",
  277. "bn", "ec", "rsa", "dsa", "dh", "dso", "engine",
  278. "buffer", "bio", "stack", "lhash", "rand", "err",
  279. "evp", "asn1", "pem", "x509", "x509v3", "conf", "txt_db", "pkcs7", "pkcs12", "comp", "ocsp", "ui",
  280. "cms", "ts", "srp", "cmac", "ct", "async", "kdf"
  281. ];
  282. # test/ subdirectories to build
  283. $config{tdirs} = [ "ossl_shim" ];
  284. # Known TLS and DTLS protocols
  285. my @tls = qw(ssl3 tls1 tls1_1 tls1_2 tls1_3);
  286. my @dtls = qw(dtls1 dtls1_2);
  287. # Explicitly known options that are possible to disable. They can
  288. # be regexps, and will be used like this: /^no-${option}$/
  289. # For developers: keep it sorted alphabetically
  290. my @disablables = (
  291. "afalgeng",
  292. "aria",
  293. "asan",
  294. "asm",
  295. "async",
  296. "autoalginit",
  297. "autoerrinit",
  298. "bf",
  299. "blake2",
  300. "camellia",
  301. "capieng",
  302. "cast",
  303. "chacha",
  304. "cmac",
  305. "cms",
  306. "comp",
  307. "crypto-mdebug",
  308. "crypto-mdebug-backtrace",
  309. "ct",
  310. "deprecated",
  311. "des",
  312. "dgram",
  313. "dh",
  314. "dsa",
  315. "dso",
  316. "dtls",
  317. "dynamic-engine",
  318. "ec",
  319. "ec2m",
  320. "ecdh",
  321. "ecdsa",
  322. "ec_nistp_64_gcc_128",
  323. "egd",
  324. "engine",
  325. "err",
  326. "external-tests",
  327. "filenames",
  328. "fuzz-libfuzzer",
  329. "fuzz-afl",
  330. "gost",
  331. "heartbeats",
  332. "hw(-.+)?",
  333. "idea",
  334. "makedepend",
  335. "md2",
  336. "md4",
  337. "mdc2",
  338. "msan",
  339. "multiblock",
  340. "nextprotoneg",
  341. "ocb",
  342. "ocsp",
  343. "pic",
  344. "poly1305",
  345. "posix-io",
  346. "psk",
  347. "rc2",
  348. "rc4",
  349. "rc5",
  350. "rdrand",
  351. "rfc3779",
  352. "rmd160",
  353. "scrypt",
  354. "sctp",
  355. "seed",
  356. "shared",
  357. "siphash",
  358. "sock",
  359. "srp",
  360. "srtp",
  361. "sse2",
  362. "ssl",
  363. "ssl-trace",
  364. "static-engine",
  365. "stdio",
  366. "tests",
  367. "threads",
  368. "tls",
  369. "ts",
  370. "ubsan",
  371. "ui",
  372. "unit-test",
  373. "whirlpool",
  374. "weak-ssl-ciphers",
  375. "zlib",
  376. "zlib-dynamic",
  377. );
  378. foreach my $proto ((@tls, @dtls))
  379. {
  380. push(@disablables, $proto);
  381. push(@disablables, "$proto-method");
  382. }
  383. my %deprecated_disablables = (
  384. "ssl2" => undef,
  385. "buf-freelists" => undef,
  386. "ripemd" => "rmd160"
  387. );
  388. # All of the following is disabled by default (RC5 was enabled before 0.9.8):
  389. our %disabled = ( # "what" => "comment"
  390. "aria" => "default",
  391. "asan" => "default",
  392. "crypto-mdebug" => "default",
  393. "crypto-mdebug-backtrace" => "default",
  394. "ec_nistp_64_gcc_128" => "default",
  395. "egd" => "default",
  396. "external-tests" => "default",
  397. "fuzz-libfuzzer" => "default",
  398. "fuzz-afl" => "default",
  399. "heartbeats" => "default",
  400. "md2" => "default",
  401. "msan" => "default",
  402. "rc5" => "default",
  403. "sctp" => "default",
  404. "ssl-trace" => "default",
  405. "ssl3" => "default",
  406. "ssl3-method" => "default",
  407. "ubsan" => "default",
  408. #TODO(TLS1.3): Temporarily disabled while this is a WIP
  409. "tls1_3" => "default",
  410. "unit-test" => "default",
  411. "weak-ssl-ciphers" => "default",
  412. "zlib" => "default",
  413. "zlib-dynamic" => "default",
  414. );
  415. # Note: => pair form used for aesthetics, not to truly make a hash table
  416. my @disable_cascades = (
  417. # "what" => [ "cascade", ... ]
  418. sub { $config{processor} eq "386" }
  419. => [ "sse2" ],
  420. "ssl" => [ "ssl3" ],
  421. "ssl3-method" => [ "ssl3" ],
  422. "zlib" => [ "zlib-dynamic" ],
  423. "des" => [ "mdc2" ],
  424. "ec" => [ "ecdsa", "ecdh" ],
  425. "dgram" => [ "dtls", "sctp" ],
  426. "sock" => [ "dgram" ],
  427. "dtls" => [ @dtls ],
  428. sub { 0 == scalar grep { !$disabled{$_} } @dtls }
  429. => [ "dtls" ],
  430. # SSL 3.0, (D)TLS 1.0 and TLS 1.1 require MD5 and SHA
  431. "md5" => [ "ssl", "tls1", "tls1_1", "dtls1" ],
  432. "sha" => [ "ssl", "tls1", "tls1_1", "dtls1" ],
  433. # Additionally, SSL 3.0 requires either RSA or DSA+DH
  434. sub { $disabled{rsa}
  435. && ($disabled{dsa} || $disabled{dh}); }
  436. => [ "ssl" ],
  437. # (D)TLS 1.0 and TLS 1.1 also require either RSA or DSA+DH
  438. # or ECDSA + ECDH. (D)TLS 1.2 has this requirement as well.
  439. # (XXX: We don't support PSK-only builds).
  440. sub { $disabled{rsa}
  441. && ($disabled{dsa} || $disabled{dh})
  442. && ($disabled{ecdsa} || $disabled{ecdh}); }
  443. => [ "tls1", "tls1_1", "tls1_2", "tls1_3",
  444. "dtls1", "dtls1_2" ],
  445. "tls" => [ @tls ],
  446. sub { 0 == scalar grep { !$disabled{$_} } @tls }
  447. => [ "tls" ],
  448. # SRP and HEARTBEATS require TLSEXT
  449. "tlsext" => [ "srp", "heartbeats" ],
  450. "crypto-mdebug" => [ "crypto-mdebug-backtrace" ],
  451. # Without DSO, we can't load dynamic engines, so don't build them dynamic
  452. "dso" => [ "dynamic-engine" ],
  453. # Without position independent code, there can be no shared libraries or DSOs
  454. "pic" => [ "shared" ],
  455. "shared" => [ "dynamic-engine" ],
  456. "engine" => [ "afalgeng" ],
  457. # no-autoalginit is only useful when building non-shared
  458. "autoalginit" => [ "shared", "apps" ],
  459. "stdio" => [ "apps", "capieng" ],
  460. "apps" => [ "tests" ],
  461. "comp" => [ "zlib" ],
  462. "ec" => [ "tls1_3" ],
  463. sub { !$disabled{"unit-test"} } => [ "heartbeats" ],
  464. sub { !$disabled{"msan"} } => [ "asm" ],
  465. );
  466. # Avoid protocol support holes. Also disable all versions below N, if version
  467. # N is disabled while N+1 is enabled.
  468. #
  469. my @list = (reverse @tls);
  470. while ((my $first, my $second) = (shift @list, shift @list)) {
  471. last unless @list;
  472. push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
  473. => [ @list ] );
  474. unshift @list, $second;
  475. }
  476. my @list = (reverse @dtls);
  477. while ((my $first, my $second) = (shift @list, shift @list)) {
  478. last unless @list;
  479. push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
  480. => [ @list ] );
  481. unshift @list, $second;
  482. }
  483. # Explicit "no-..." options will be collected in %disabled along with the defaults.
  484. # To remove something from %disabled, use "enable-foo".
  485. # For symmetry, "disable-foo" is a synonym for "no-foo".
  486. my $no_sse2=0;
  487. &usage if ($#ARGV < 0);
  488. my $user_cflags="";
  489. my @user_defines=();
  490. $config{openssl_api_defines}=[];
  491. $config{openssl_algorithm_defines}=[];
  492. $config{openssl_thread_defines}=[];
  493. $config{openssl_sys_defines}=[];
  494. $config{openssl_other_defines}=[];
  495. my $libs="";
  496. my $target="";
  497. $config{options}="";
  498. $config{build_type} = "release";
  499. my %unsupported_options = ();
  500. my %deprecated_options = ();
  501. while (@argvcopy)
  502. {
  503. $_ = shift @argvcopy;
  504. # VMS is a case insensitive environment, and depending on settings
  505. # out of our control, we may receive options uppercased. Let's
  506. # downcase at least the part before any equal sign.
  507. if ($^O eq "VMS")
  508. {
  509. s/^([^=]*)/lc($1)/e;
  510. }
  511. s /^-no-/no-/; # some people just can't read the instructions
  512. # rewrite some options in "enable-..." form
  513. s /^-?-?shared$/enable-shared/;
  514. s /^sctp$/enable-sctp/;
  515. s /^threads$/enable-threads/;
  516. s /^zlib$/enable-zlib/;
  517. s /^zlib-dynamic$/enable-zlib-dynamic/;
  518. if (/^(no|disable|enable)-(.+)$/)
  519. {
  520. my $word = $2;
  521. if (!exists $deprecated_disablables{$word}
  522. && !grep { $word =~ /^${_}$/ } @disablables)
  523. {
  524. $unsupported_options{$_} = 1;
  525. next;
  526. }
  527. }
  528. if (/^no-(.+)$/ || /^disable-(.+)$/)
  529. {
  530. foreach my $proto ((@tls, @dtls))
  531. {
  532. if ($1 eq "$proto-method")
  533. {
  534. $disabled{"$proto"} = "option($proto-method)";
  535. last;
  536. }
  537. }
  538. if ($1 eq "dtls")
  539. {
  540. foreach my $proto (@dtls)
  541. {
  542. $disabled{$proto} = "option(dtls)";
  543. }
  544. $disabled{"dtls"} = "option(dtls)";
  545. }
  546. elsif ($1 eq "ssl")
  547. {
  548. # Last one of its kind
  549. $disabled{"ssl3"} = "option(ssl)";
  550. }
  551. elsif ($1 eq "tls")
  552. {
  553. # XXX: Tests will fail if all SSL/TLS
  554. # protocols are disabled.
  555. foreach my $proto (@tls)
  556. {
  557. $disabled{$proto} = "option(tls)";
  558. }
  559. }
  560. elsif ($1 eq "static-engine")
  561. {
  562. delete $disabled{"dynamic-engine"};
  563. }
  564. elsif ($1 eq "dynamic-engine")
  565. {
  566. $disabled{"dynamic-engine"} = "option";
  567. }
  568. elsif (exists $deprecated_disablables{$1})
  569. {
  570. $deprecated_options{$_} = 1;
  571. if (defined $deprecated_disablables{$1})
  572. {
  573. $disabled{$deprecated_disablables{$1}} = "option";
  574. }
  575. }
  576. else
  577. {
  578. $disabled{$1} = "option";
  579. }
  580. # No longer an automatic choice
  581. $auto_threads = 0 if ($1 eq "threads");
  582. }
  583. elsif (/^enable-(.+)$/)
  584. {
  585. if ($1 eq "static-engine")
  586. {
  587. $disabled{"dynamic-engine"} = "option";
  588. }
  589. elsif ($1 eq "dynamic-engine")
  590. {
  591. delete $disabled{"dynamic-engine"};
  592. }
  593. elsif ($1 eq "zlib-dynamic")
  594. {
  595. delete $disabled{"zlib"};
  596. }
  597. my $algo = $1;
  598. delete $disabled{$algo};
  599. # No longer an automatic choice
  600. $auto_threads = 0 if ($1 eq "threads");
  601. }
  602. elsif (/^--strict-warnings$/)
  603. {
  604. $strict_warnings = 1;
  605. }
  606. elsif (/^--debug$/)
  607. {
  608. $config{build_type} = "debug";
  609. }
  610. elsif (/^--release$/)
  611. {
  612. $config{build_type} = "release";
  613. }
  614. elsif (/^386$/)
  615. { $config{processor}=386; }
  616. elsif (/^fips$/)
  617. {
  618. die "FIPS mode not supported\n";
  619. }
  620. elsif (/^rsaref$/)
  621. {
  622. # No RSAref support any more since it's not needed.
  623. # The check for the option is there so scripts aren't
  624. # broken
  625. }
  626. elsif (/^nofipscanistercheck$/)
  627. {
  628. die "FIPS mode not supported\n";
  629. }
  630. elsif (/^[-+]/)
  631. {
  632. if (/^--prefix=(.*)$/)
  633. {
  634. $config{prefix}=$1;
  635. die "Directory given with --prefix MUST be absolute\n"
  636. unless file_name_is_absolute($config{prefix});
  637. }
  638. elsif (/^--api=(.*)$/)
  639. {
  640. $config{api}=$1;
  641. }
  642. elsif (/^--libdir=(.*)$/)
  643. {
  644. $config{libdir}=$1;
  645. }
  646. elsif (/^--openssldir=(.*)$/)
  647. {
  648. $config{openssldir}=$1;
  649. }
  650. elsif (/^--with-zlib-lib=(.*)$/)
  651. {
  652. $withargs{zlib_lib}=$1;
  653. }
  654. elsif (/^--with-zlib-include=(.*)$/)
  655. {
  656. $withargs{zlib_include}=$1;
  657. }
  658. elsif (/^--with-fuzzer-lib=(.*)$/)
  659. {
  660. $withargs{fuzzer_lib}=$1;
  661. }
  662. elsif (/^--with-fuzzer-include=(.*)$/)
  663. {
  664. $withargs{fuzzer_include}=$1;
  665. }
  666. elsif (/^--cross-compile-prefix=(.*)$/)
  667. {
  668. $config{cross_compile_prefix}=$1;
  669. }
  670. elsif (/^--config=(.*)$/)
  671. {
  672. read_config $1;
  673. }
  674. elsif (/^-[lL](.*)$/ or /^-Wl,/)
  675. {
  676. $libs.=$_." ";
  677. }
  678. elsif (/^-rpath$/ or /^-R$/)
  679. # -rpath is the OSF1 rpath flag
  680. # -R is the old Solaris rpath flag
  681. {
  682. my $rpath = shift(@argvcopy) || "";
  683. $rpath .= " " if $rpath ne "";
  684. $libs.=$_." ".$rpath;
  685. }
  686. elsif (/^-static$/)
  687. {
  688. $libs.=$_." ";
  689. $disabled{"dso"} = "forced";
  690. $disabled{"pic"} = "forced";
  691. $disabled{"shared"} = "forced";
  692. $disabled{"threads"} = "forced";
  693. }
  694. elsif (/^-D(.*)$/)
  695. {
  696. push @user_defines, $1;
  697. }
  698. else # common if (/^[-+]/), just pass down...
  699. {
  700. $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
  701. $user_cflags.=" ".$_;
  702. }
  703. }
  704. else
  705. {
  706. die "target already defined - $target (offending arg: $_)\n" if ($target ne "");
  707. $target=$_;
  708. }
  709. unless ($_ eq $target || /^no-/ || /^disable-/)
  710. {
  711. # "no-..." follows later after implied disactivations
  712. # have been derived. (Don't take this too seriously,
  713. # we really only write OPTIONS to the Makefile out of
  714. # nostalgia.)
  715. if ($config{options} eq "")
  716. { $config{options} = $_; }
  717. else
  718. { $config{options} .= " ".$_; }
  719. }
  720. if (defined($config{api}) && !exists $apitable->{$config{api}}) {
  721. die "***** Unsupported api compatibility level: $config{api}\n",
  722. }
  723. if (keys %deprecated_options)
  724. {
  725. warn "***** Deprecated options: ",
  726. join(", ", keys %deprecated_options), "\n";
  727. }
  728. if (keys %unsupported_options)
  729. {
  730. die "***** Unsupported options: ",
  731. join(", ", keys %unsupported_options), "\n";
  732. }
  733. }
  734. if ($libs =~ /(^|\s)-Wl,-rpath,/
  735. && !$disabled{shared}
  736. && !($disabled{asan} && $disabled{msan} && $disabled{ubsan})) {
  737. die "***** Cannot simultaneously use -rpath, shared libraries, and\n",
  738. "***** any of asan, msan or ubsan\n";
  739. }
  740. my @tocheckfor = (keys %disabled);
  741. while (@tocheckfor) {
  742. my %new_tocheckfor = ();
  743. my @cascade_copy = (@disable_cascades);
  744. while (@cascade_copy) {
  745. my ($test, $descendents) = (shift @cascade_copy, shift @cascade_copy);
  746. if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) {
  747. foreach(grep { !defined($disabled{$_}) } @$descendents) {
  748. $new_tocheckfor{$_} = 1; $disabled{$_} = "forced";
  749. }
  750. }
  751. }
  752. @tocheckfor = (keys %new_tocheckfor);
  753. }
  754. our $die = sub { die @_; };
  755. if ($target eq "TABLE") {
  756. local $die = sub { warn @_; };
  757. foreach (sort keys %table) {
  758. print_table_entry($_, "TABLE");
  759. }
  760. exit 0;
  761. }
  762. if ($target eq "LIST") {
  763. foreach (sort keys %table) {
  764. print $_,"\n" unless $table{$_}->{template};
  765. }
  766. exit 0;
  767. }
  768. if ($target eq "HASH") {
  769. local $die = sub { warn @_; };
  770. print "%table = (\n";
  771. foreach (sort keys %table) {
  772. print_table_entry($_, "HASH");
  773. }
  774. exit 0;
  775. }
  776. # Backward compatibility?
  777. if ($target =~ m/^CygWin32(-.*)$/) {
  778. $target = "Cygwin".$1;
  779. }
  780. foreach (sort (keys %disabled))
  781. {
  782. $config{options} .= " no-$_";
  783. printf " no-%-12s %-10s", $_, "[$disabled{$_}]";
  784. if (/^dso$/)
  785. { }
  786. elsif (/^threads$/)
  787. { }
  788. elsif (/^shared$/)
  789. { }
  790. elsif (/^pic$/)
  791. { }
  792. elsif (/^zlib$/)
  793. { }
  794. elsif (/^dynamic-engine$/)
  795. { }
  796. elsif (/^makedepend$/)
  797. { }
  798. elsif (/^zlib-dynamic$/)
  799. { }
  800. elsif (/^sse2$/)
  801. { $no_sse2 = 1; }
  802. elsif (/^engine$/)
  803. {
  804. @{$config{dirs}} = grep !/^engines$/, @{$config{dirs}};
  805. @{$config{sdirs}} = grep !/^engine$/, @{$config{sdirs}};
  806. push @{$config{openssl_other_defines}}, "OPENSSL_NO_ENGINE";
  807. print " OPENSSL_NO_ENGINE (skip engines)";
  808. }
  809. else
  810. {
  811. my ($WHAT, $what);
  812. ($WHAT = $what = $_) =~ tr/[\-a-z]/[_A-Z]/;
  813. # Fix up C macro end names
  814. $WHAT = "RMD160" if $what eq "ripemd";
  815. # fix-up crypto/directory name(s)
  816. $what = "ripemd" if $what eq "rmd160";
  817. $what = "whrlpool" if $what eq "whirlpool";
  818. if ($what ne "async" && $what ne "err"
  819. && grep { $_ eq $what } @{$config{sdirs}})
  820. {
  821. push @{$config{openssl_algorithm_defines}}, "OPENSSL_NO_$WHAT";
  822. @{$config{sdirs}} = grep { $_ ne $what} @{$config{sdirs}};
  823. print " OPENSSL_NO_$WHAT (skip dir)";
  824. }
  825. else
  826. {
  827. push @{$config{openssl_other_defines}}, "OPENSSL_NO_$WHAT";
  828. print " OPENSSL_NO_$WHAT";
  829. if (/^err$/) { push @user_defines, "OPENSSL_NO_ERR"; }
  830. }
  831. }
  832. print "\n";
  833. }
  834. print "Configuring for $target\n";
  835. # Support for legacy targets having a name starting with 'debug-'
  836. my ($d, $t) = $target =~ m/^(debug-)?(.*)$/;
  837. if ($d) {
  838. $config{build_type} = "debug";
  839. # If we do not find debug-foo in the table, the target is set to foo.
  840. if (!$table{$target}) {
  841. $target = $t;
  842. }
  843. }
  844. $config{target} = $target;
  845. my %target = resolve_config($target);
  846. &usage if (!%target || $target{template});
  847. my %conf_files = map { $_ => 1 } (@{$target{_conf_fname_int}});
  848. $config{conf_files} = [ sort keys %conf_files ];
  849. %target = ( %{$table{DEFAULTS}}, %target );
  850. $target{cxxflags}=$target{cflags} unless defined $target{cxxflags};
  851. $target{exe_extension}="";
  852. $target{exe_extension}=".exe" if ($config{target} eq "DJGPP"
  853. || $config{target} =~ /^(?:Cygwin|mingw)/);
  854. $target{exe_extension}=".pm" if ($config{target} =~ /vos/);
  855. ($target{shared_extension_simple}=$target{shared_extension})
  856. =~ s|\.\$\(SHLIB_MAJOR\)\.\$\(SHLIB_MINOR\)||;
  857. $target{dso_extension}=$target{shared_extension_simple};
  858. ($target{shared_import_extension}=$target{shared_extension_simple}.".a")
  859. if ($config{target} =~ /^(?:Cygwin|mingw)/);
  860. $config{cross_compile_prefix} = $ENV{'CROSS_COMPILE'}
  861. if $config{cross_compile_prefix} eq "";
  862. # Allow overriding the names of some tools. USE WITH CARE
  863. # Note: only Unix cares about HASHBANGPERL... that explains
  864. # the default string.
  865. $config{perl} = ($^O ne "VMS" ? $^X : "perl");
  866. $config{hashbangperl} =
  867. $ENV{'HASHBANGPERL'} || $ENV{'PERL'} || "/usr/bin/env perl";
  868. $target{cc} = $ENV{'CC'} || $target{cc} || "cc";
  869. $target{cxx} = $ENV{'CXX'} || $target{cxx} || "c++";
  870. $target{ranlib} = $ENV{'RANLIB'} || $target{ranlib} ||
  871. (which("$config{cross_compile_prefix}ranlib") ?
  872. "\$(CROSS_COMPILE)ranlib" : "true");
  873. $target{ar} = $ENV{'AR'} || $target{ar} || "ar";
  874. $target{nm} = $ENV{'NM'} || $target{nm} || "nm";
  875. $target{rc} =
  876. $ENV{'RC'} || $ENV{'WINDRES'} || $target{rc} || "windres";
  877. # Allow overriding the build file name
  878. $target{build_file} = $ENV{BUILDFILE} || $target{build_file} || "Makefile";
  879. # Cache information necessary for reconfiguration
  880. $config{cc} = $target{cc};
  881. $config{cxx} = $target{cxx};
  882. $config{build_file} = $target{build_file};
  883. # For cflags, lflags, plib_lflags, ex_libs and defines, add the debug_
  884. # or release_ attributes.
  885. # Do it in such a way that no spurious space is appended (hence the grep).
  886. $config{defines} = [];
  887. $config{cflags} = "";
  888. $config{cxxflags} = "";
  889. $config{ex_libs} = "";
  890. $config{shared_ldflag} = "";
  891. # Make sure build_scheme is consistent.
  892. $target{build_scheme} = [ $target{build_scheme} ]
  893. if ref($target{build_scheme}) ne "ARRAY";
  894. my ($builder, $builder_platform, @builder_opts) =
  895. @{$target{build_scheme}};
  896. foreach my $checker (($builder_platform."-".$target{build_file}."-checker.pm",
  897. $builder_platform."-checker.pm")) {
  898. my $checker_path = catfile($srcdir, "Configurations", $checker);
  899. if (-f $checker_path) {
  900. my $fn = $ENV{CONFIGURE_CHECKER_WARN}
  901. ? sub { warn $@; } : sub { die $@; };
  902. if (! do $checker_path) {
  903. if ($@) {
  904. $fn->($@);
  905. } elsif ($!) {
  906. $fn->($!);
  907. } else {
  908. $fn->("The detected tools didn't match the platform\n");
  909. }
  910. }
  911. last;
  912. }
  913. }
  914. push @{$config{defines}}, "NDEBUG" if $config{build_type} eq "release";
  915. if ($target =~ /^mingw/ && `$target{cc} --target-help 2>&1` =~ m/-mno-cygwin/m)
  916. {
  917. $config{cflags} .= " -mno-cygwin";
  918. $config{shared_ldflag} .= " -mno-cygwin";
  919. }
  920. if ($target =~ /linux.*-mips/ && !$disabled{asm} && $user_cflags !~ /-m(ips|arch=)/) {
  921. # minimally required architecture flags for assembly modules
  922. $config{cflags}="-mips2 $config{cflags}" if ($target =~ /mips32/);
  923. $config{cflags}="-mips3 $config{cflags}" if ($target =~ /mips64/);
  924. }
  925. my $no_shared_warn=0;
  926. my $no_user_cflags=0;
  927. my $no_user_defines=0;
  928. # The DSO code currently always implements all functions so that no
  929. # applications will have to worry about that from a compilation point
  930. # of view. However, the "method"s may return zero unless that platform
  931. # has support compiled in for them. Currently each method is enabled
  932. # by a define "DSO_<name>" ... we translate the "dso_scheme" config
  933. # string entry into using the following logic;
  934. if (!$disabled{dso} && $target{dso_scheme} ne "")
  935. {
  936. $target{dso_scheme} =~ tr/[a-z]/[A-Z]/;
  937. if ($target{dso_scheme} eq "DLFCN")
  938. {
  939. unshift @{$config{defines}}, "DSO_DLFCN", "HAVE_DLFCN_H";
  940. }
  941. elsif ($target{dso_scheme} eq "DLFCN_NO_H")
  942. {
  943. unshift @{$config{defines}}, "DSO_DLFCN";
  944. }
  945. else
  946. {
  947. unshift @{$config{defines}}, "DSO_$target{dso_scheme}";
  948. }
  949. }
  950. $config{ex_libs}="$libs$config{ex_libs}" if ($libs ne "");
  951. # If threads aren't disabled, check how possible they are
  952. unless ($disabled{threads}) {
  953. if ($auto_threads) {
  954. # Enabled by default, disable it forcibly if unavailable
  955. if ($target{thread_scheme} eq "(unknown)") {
  956. $disabled{threads} = "unavailable";
  957. }
  958. } else {
  959. # The user chose to enable threads explicitly, let's see
  960. # if there's a chance that's possible
  961. if ($target{thread_scheme} eq "(unknown)") {
  962. # If the user asked for "threads" and we don't have internal
  963. # knowledge how to do it, [s]he is expected to provide any
  964. # system-dependent compiler options that are necessary. We
  965. # can't truly check that the given options are correct, but
  966. # we expect the user to know what [s]He is doing.
  967. if ($no_user_cflags && $no_user_defines) {
  968. die "You asked for multi-threading support, but didn't\n"
  969. ,"provide any system-specific compiler options\n";
  970. }
  971. }
  972. }
  973. }
  974. # If threads still aren't disabled, add a C macro to ensure the source
  975. # code knows about it. Any other flag is taken care of by the configs.
  976. unless($disabled{threads}) {
  977. foreach (("defines", "openssl_thread_defines")) {
  978. push @{$config{$_}}, "OPENSSL_THREADS";
  979. }
  980. }
  981. # With "deprecated" disable all deprecated features.
  982. if (defined($disabled{"deprecated"})) {
  983. $config{api} = $maxapi;
  984. }
  985. if ($target{shared_target} eq "")
  986. {
  987. $no_shared_warn = 1
  988. if (!$disabled{shared} || !$disabled{"dynamic-engine"});
  989. $disabled{shared} = "no-shared-target";
  990. $disabled{pic} = $disabled{shared} = $disabled{"dynamic-engine"} =
  991. "no-shared-target";
  992. }
  993. if ($disabled{"dynamic-engine"}) {
  994. push @{$config{defines}}, "OPENSSL_NO_DYNAMIC_ENGINE";
  995. $config{dynamic_engines} = 0;
  996. } else {
  997. push @{$config{defines}}, "OPENSSL_NO_STATIC_ENGINE";
  998. $config{dynamic_engines} = 1;
  999. }
  1000. unless ($disabled{asan}) {
  1001. $config{cflags} .= "-fsanitize=address ";
  1002. }
  1003. unless ($disabled{ubsan}) {
  1004. # -DPEDANTIC or -fnosanitize=alignment may also be required on some
  1005. # platforms.
  1006. $config{cflags} .= "-fsanitize=undefined -fno-sanitize-recover=all ";
  1007. }
  1008. unless ($disabled{msan}) {
  1009. $config{cflags} .= "-fsanitize=memory ";
  1010. }
  1011. unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
  1012. && $disabled{asan} && $disabled{ubsan} && $disabled{msan}) {
  1013. $config{cflags} .= "-fno-omit-frame-pointer -g ";
  1014. }
  1015. #
  1016. # Platform fix-ups
  1017. #
  1018. # This saves the build files from having to check
  1019. if ($disabled{pic})
  1020. {
  1021. $target{shared_cflag} = $target{shared_ldflag} =
  1022. $target{shared_rcflag} = "";
  1023. }
  1024. else
  1025. {
  1026. push @{$config{defines}}, "OPENSSL_PIC";
  1027. }
  1028. if ($target{sys_id} ne "")
  1029. {
  1030. push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}";
  1031. }
  1032. unless ($disabled{asm}) {
  1033. $target{cpuid_asm_src}=$table{DEFAULTS}->{cpuid_asm_src} if ($config{processor} eq "386");
  1034. $target{bn_asm_src} =~ s/\w+-gf2m.c// if (defined($disabled{ec2m}));
  1035. # bn-586 is the only one implementing bn_*_part_words
  1036. push @{$config{defines}}, "OPENSSL_BN_ASM_PART_WORDS" if ($target{bn_asm_src} =~ /bn-586/);
  1037. push @{$config{defines}}, "OPENSSL_IA32_SSE2" if (!$no_sse2 && $target{bn_asm_src} =~ /86/);
  1038. push @{$config{defines}}, "OPENSSL_BN_ASM_MONT" if ($target{bn_asm_src} =~ /-mont/);
  1039. push @{$config{defines}}, "OPENSSL_BN_ASM_MONT5" if ($target{bn_asm_src} =~ /-mont5/);
  1040. push @{$config{defines}}, "OPENSSL_BN_ASM_GF2m" if ($target{bn_asm_src} =~ /-gf2m/);
  1041. if ($target{sha1_asm_src}) {
  1042. push @{$config{defines}}, "SHA1_ASM" if ($target{sha1_asm_src} =~ /sx86/ || $target{sha1_asm_src} =~ /sha1/);
  1043. push @{$config{defines}}, "SHA256_ASM" if ($target{sha1_asm_src} =~ /sha256/);
  1044. push @{$config{defines}}, "SHA512_ASM" if ($target{sha1_asm_src} =~ /sha512/);
  1045. }
  1046. if ($target{rc4_asm_src} ne $table{DEFAULTS}->{rc4_asm_src}) {
  1047. push @{$config{defines}}, "RC4_ASM";
  1048. }
  1049. if ($target{md5_asm_src}) {
  1050. push @{$config{defines}}, "MD5_ASM";
  1051. }
  1052. $target{cast_asm_src}=$table{DEFAULTS}->{cast_asm_src} unless $disabled{pic}; # CAST assembler is not PIC
  1053. if ($target{rmd160_asm_src}) {
  1054. push @{$config{defines}}, "RMD160_ASM";
  1055. }
  1056. if ($target{aes_asm_src}) {
  1057. push @{$config{defines}}, "AES_ASM" if ($target{aes_asm_src} =~ m/\baes-/);;
  1058. # aes-ctr.fake is not a real file, only indication that assembler
  1059. # module implements AES_ctr32_encrypt...
  1060. push @{$config{defines}}, "AES_CTR_ASM" if ($target{aes_asm_src} =~ s/\s*aes-ctr\.fake//);
  1061. # aes-xts.fake indicates presence of AES_xts_[en|de]crypt...
  1062. push @{$config{defines}}, "AES_XTS_ASM" if ($target{aes_asm_src} =~ s/\s*aes-xts\.fake//);
  1063. $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($no_sse2);
  1064. push @{$config{defines}}, "VPAES_ASM" if ($target{aes_asm_src} =~ m/vpaes/);
  1065. push @{$config{defines}}, "BSAES_ASM" if ($target{aes_asm_src} =~ m/bsaes/);
  1066. }
  1067. if ($target{wp_asm_src} =~ /mmx/) {
  1068. if ($config{processor} eq "386") {
  1069. $target{wp_asm_src}=$table{DEFAULTS}->{wp_asm_src};
  1070. } elsif (!$disabled{"whirlpool"}) {
  1071. push @{$config{defines}}, "WHIRLPOOL_ASM";
  1072. }
  1073. }
  1074. if ($target{modes_asm_src} =~ /ghash-/) {
  1075. push @{$config{defines}}, "GHASH_ASM";
  1076. }
  1077. if ($target{ec_asm_src} =~ /ecp_nistz256/) {
  1078. push @{$config{defines}}, "ECP_NISTZ256_ASM";
  1079. }
  1080. if ($target{padlock_asm_src} ne $table{DEFAULTS}->{padlock_asm_src}) {
  1081. push @{$config{defines}}, "PADLOCK_ASM";
  1082. }
  1083. if ($target{poly1305_asm_src} ne "") {
  1084. push @{$config{defines}}, "POLY1305_ASM";
  1085. }
  1086. }
  1087. my $ecc = $target{cc};
  1088. if ($^O ne "VMS" && !$disabled{makedepend}) {
  1089. # Is the compiler gcc or clang? $ecc is used below to see if
  1090. # error-checking can be turned on.
  1091. my $ccpcc = "$config{cross_compile_prefix}$target{cc}";
  1092. open(PIPE, "$ccpcc --version 2>&1 |");
  1093. my $lines = 2;
  1094. while ( <PIPE> ) {
  1095. # Find the version number and save the major.
  1096. m|(?:.*)\b(\d+)\.\d+\.\d+\b(?:.*)|;
  1097. my $compiler_major = $1;
  1098. # We know that GNU C version 3 and up as well as all clang
  1099. # versions support dependency generation
  1100. $config{makedepprog} = $ccpcc
  1101. if (/clang/ || (/gcc/ && $compiler_major >= 3));
  1102. $ecc = "clang" if /clang/;
  1103. $ecc = "gcc" if /gcc/;
  1104. last if ($config{makedepprog} || !$lines--);
  1105. }
  1106. close(PIPE);
  1107. $config{makedepprog} = which('makedepend') unless $config{makedepprog};
  1108. $disabled{makedepend} = "unavailable" unless $config{makedepprog};
  1109. }
  1110. # Deal with bn_ops ###################################################
  1111. $config{bn_ll} =0;
  1112. $config{export_var_as_fn} =0;
  1113. my $def_int="unsigned int";
  1114. $config{rc4_int} =$def_int;
  1115. ($config{b64l},$config{b64},$config{b32})=(0,0,1);
  1116. my $count = 0;
  1117. foreach (sort split(/\s+/,$target{bn_ops})) {
  1118. $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/;
  1119. $config{export_var_as_fn}=1 if $_ eq 'EXPORT_VAR_AS_FN';
  1120. $config{bn_ll}=1 if $_ eq 'BN_LLONG';
  1121. $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR';
  1122. ($config{b64l},$config{b64},$config{b32})
  1123. =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT';
  1124. ($config{b64l},$config{b64},$config{b32})
  1125. =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG';
  1126. ($config{b64l},$config{b64},$config{b32})
  1127. =(0,0,1) if $_ eq 'THIRTY_TWO_BIT';
  1128. }
  1129. die "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n"
  1130. if $count > 1;
  1131. # Hack cflags for better warnings (dev option) #######################
  1132. # "Stringify" the C flags string. This permits it to be made part of a string
  1133. # and works as well on command lines.
  1134. $config{cflags} =~ s/([\\\"])/\\$1/g;
  1135. if (defined($config{api})) {
  1136. $config{openssl_api_defines} = [ "OPENSSL_MIN_API=".$apitable->{$config{api}} ];
  1137. my $apiflag = sprintf("OPENSSL_API_COMPAT=%s", $apitable->{$config{api}});
  1138. push @{$config{defines}}, $apiflag;
  1139. }
  1140. if ($strict_warnings)
  1141. {
  1142. my $wopt;
  1143. die "ERROR --strict-warnings requires gcc or clang"
  1144. unless $ecc eq 'gcc' || $ecc eq 'clang';
  1145. foreach $wopt (split /\s+/, $gcc_devteam_warn)
  1146. {
  1147. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(?:^|\s)$wopt(?:\s|$)/)
  1148. }
  1149. if ($ecc eq "clang")
  1150. {
  1151. foreach $wopt (split /\s+/, $clang_devteam_warn)
  1152. {
  1153. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(?:^|\s)$wopt(?:\s|$)/)
  1154. }
  1155. }
  1156. }
  1157. unless ($disabled{"crypto-mdebug-backtrace"})
  1158. {
  1159. foreach my $wopt (split /\s+/, $memleak_devteam_backtrace)
  1160. {
  1161. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(?:^|\s)$wopt(?:\s|$)/)
  1162. }
  1163. if ($target =~ /^BSD-/)
  1164. {
  1165. $config{ex_libs} .= " -lexecinfo";
  1166. }
  1167. }
  1168. if ($user_cflags ne "") { $config{cflags}="$config{cflags}$user_cflags"; $config{cxxflags}="$config{cxxflags}$user_cflags";}
  1169. else { $no_user_cflags=1; }
  1170. if (@user_defines) { $config{defines}=[ @{$config{defines}}, @user_defines ]; }
  1171. else { $no_user_defines=1; }
  1172. # ALL MODIFICATIONS TO %config and %target MUST BE DONE FROM HERE ON
  1173. unless ($disabled{afalgeng}) {
  1174. $config{afalgeng}="";
  1175. if ($target =~ m/^linux/) {
  1176. my $minver = 4*10000 + 1*100 + 0;
  1177. if ($config{cross_compile_prefix} eq "") {
  1178. my $verstr = `uname -r`;
  1179. my ($ma, $mi1, $mi2) = split("\\.", $verstr);
  1180. ($mi2) = $mi2 =~ /(\d+)/;
  1181. my $ver = $ma*10000 + $mi1*100 + $mi2;
  1182. if ($ver < $minver) {
  1183. $disabled{afalgeng} = "too-old-kernel";
  1184. } else {
  1185. push @{$config{engdirs}}, "afalg";
  1186. }
  1187. } else {
  1188. $disabled{afalgeng} = "cross-compiling";
  1189. }
  1190. } else {
  1191. $disabled{afalgeng} = "not-linux";
  1192. }
  1193. }
  1194. push @{$config{openssl_other_defines}}, "OPENSSL_NO_AFALGENG" if ($disabled{afalgeng});
  1195. # If we use the unified build, collect information from build.info files
  1196. my %unified_info = ();
  1197. my $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO});
  1198. if ($builder eq "unified") {
  1199. use lib catdir(dirname(__FILE__),"util");
  1200. use with_fallback qw(Text::Template);
  1201. sub cleandir {
  1202. my $base = shift;
  1203. my $dir = shift;
  1204. my $relativeto = shift || ".";
  1205. $dir = catdir($base,$dir) unless isabsolute($dir);
  1206. # Make sure the directories we're building in exists
  1207. mkpath($dir);
  1208. my $res = abs2rel(absolutedir($dir), rel2abs($relativeto));
  1209. #print STDERR "DEBUG[cleandir]: $dir , $base => $res\n";
  1210. return $res;
  1211. }
  1212. sub cleanfile {
  1213. my $base = shift;
  1214. my $file = shift;
  1215. my $relativeto = shift || ".";
  1216. $file = catfile($base,$file) unless isabsolute($file);
  1217. my $d = dirname($file);
  1218. my $f = basename($file);
  1219. # Make sure the directories we're building in exists
  1220. mkpath($d);
  1221. my $res = abs2rel(catfile(absolutedir($d), $f), rel2abs($relativeto));
  1222. #print STDERR "DEBUG[cleanfile]: $d , $f => $res\n";
  1223. return $res;
  1224. }
  1225. # Store the name of the template file we will build the build file from
  1226. # in %config. This may be useful for the build file itself.
  1227. my @build_file_template_names =
  1228. ( $builder_platform."-".$target{build_file}.".tmpl",
  1229. $target{build_file}.".tmpl" );
  1230. my @build_file_templates = ();
  1231. # First, look in the user provided directory, if given
  1232. if (defined $ENV{$local_config_envname}) {
  1233. @build_file_templates =
  1234. map {
  1235. if ($^O eq 'VMS') {
  1236. # VMS environment variables are logical names,
  1237. # which can be used as is
  1238. $local_config_envname . ':' . $_;
  1239. } else {
  1240. catfile($ENV{$local_config_envname}, $_);
  1241. }
  1242. }
  1243. @build_file_template_names;
  1244. }
  1245. # Then, look in our standard directory
  1246. push @build_file_templates,
  1247. ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir) }
  1248. @build_file_template_names );
  1249. my $build_file_template;
  1250. for $_ (@build_file_templates) {
  1251. $build_file_template = $_;
  1252. last if -f $build_file_template;
  1253. $build_file_template = undef;
  1254. }
  1255. if (!defined $build_file_template) {
  1256. die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n";
  1257. }
  1258. $config{build_file_templates}
  1259. = [ $build_file_template,
  1260. cleanfile($srcdir, catfile("Configurations", "common.tmpl"),
  1261. $blddir) ];
  1262. my @build_infos = ( [ ".", "build.info" ] );
  1263. foreach (@{$config{dirs}}) {
  1264. push @build_infos, [ $_, "build.info" ]
  1265. if (-f catfile($srcdir, $_, "build.info"));
  1266. }
  1267. foreach (@{$config{sdirs}}) {
  1268. push @build_infos, [ catdir("crypto", $_), "build.info" ]
  1269. if (-f catfile($srcdir, "crypto", $_, "build.info"));
  1270. }
  1271. foreach (@{$config{engdirs}}) {
  1272. push @build_infos, [ catdir("engines", $_), "build.info" ]
  1273. if (-f catfile($srcdir, "engines", $_, "build.info"));
  1274. }
  1275. foreach (@{$config{tdirs}}) {
  1276. push @build_infos, [ catdir("test", $_), "build.info" ]
  1277. if (-f catfile($srcdir, "test", $_, "build.info"));
  1278. }
  1279. $config{build_infos} = [ ];
  1280. foreach (@build_infos) {
  1281. my $sourced = catdir($srcdir, $_->[0]);
  1282. my $buildd = catdir($blddir, $_->[0]);
  1283. mkpath($buildd);
  1284. my $f = $_->[1];
  1285. # The basic things we're trying to build
  1286. my @programs = ();
  1287. my @programs_install = ();
  1288. my @libraries = ();
  1289. my @libraries_install = ();
  1290. my @engines = ();
  1291. my @engines_install = ();
  1292. my @scripts = ();
  1293. my @scripts_install = ();
  1294. my @extra = ();
  1295. my @overrides = ();
  1296. my @intermediates = ();
  1297. my @rawlines = ();
  1298. my %ordinals = ();
  1299. my %sources = ();
  1300. my %shared_sources = ();
  1301. my %includes = ();
  1302. my %depends = ();
  1303. my %renames = ();
  1304. my %sharednames = ();
  1305. my %generate = ();
  1306. push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f);
  1307. my $template = Text::Template->new(TYPE => 'FILE',
  1308. SOURCE => catfile($sourced, $f));
  1309. die "Something went wrong with $sourced/$f: $!\n" unless $template;
  1310. my @text =
  1311. split /^/m,
  1312. $template->fill_in(HASH => { config => \%config,
  1313. target => \%target,
  1314. disabled => \%disabled,
  1315. withargs => \%withargs,
  1316. builddir => abs2rel($buildd, $blddir),
  1317. sourcedir => abs2rel($sourced, $blddir),
  1318. buildtop => abs2rel($blddir, $blddir),
  1319. sourcetop => abs2rel($srcdir, $blddir) },
  1320. DELIMITERS => [ "{-", "-}" ]);
  1321. # The top item of this stack has the following values
  1322. # -2 positive already run and we found ELSE (following ELSIF should fail)
  1323. # -1 positive already run (skip until ENDIF)
  1324. # 0 negatives so far (if we're at a condition, check it)
  1325. # 1 last was positive (don't skip lines until next ELSE, ELSIF or ENDIF)
  1326. # 2 positive ELSE (following ELSIF should fail)
  1327. my @skip = ();
  1328. collect_information(
  1329. collect_from_array([ @text ],
  1330. qr/\\$/ => sub { my $l1 = shift; my $l2 = shift;
  1331. $l1 =~ s/\\$//; $l1.$l2 }),
  1332. # Info we're looking for
  1333. qr/^\s*IF\[((?:\\.|[^\\\]])*)\]\s*$/
  1334. => sub {
  1335. if (! @skip || $skip[$#skip] > 0) {
  1336. push @skip, !! $1;
  1337. } else {
  1338. push @skip, -1;
  1339. }
  1340. },
  1341. qr/^\s*ELSIF\[((?:\\.|[^\\\]])*)\]\s*$/
  1342. => sub { die "ELSIF out of scope" if ! @skip;
  1343. die "ELSIF following ELSE" if abs($skip[$#skip]) == 2;
  1344. $skip[$#skip] = -1 if $skip[$#skip] != 0;
  1345. $skip[$#skip] = !! $1
  1346. if $skip[$#skip] == 0; },
  1347. qr/^\s*ELSE\s*$/
  1348. => sub { die "ELSE out of scope" if ! @skip;
  1349. $skip[$#skip] = -2 if $skip[$#skip] != 0;
  1350. $skip[$#skip] = 2 if $skip[$#skip] == 0; },
  1351. qr/^\s*ENDIF\s*$/
  1352. => sub { die "ENDIF out of scope" if ! @skip;
  1353. pop @skip; },
  1354. qr/^\s*PROGRAMS(_NO_INST)?\s*=\s*(.*)\s*$/
  1355. => sub {
  1356. if (!@skip || $skip[$#skip] > 0) {
  1357. my $install = $1;
  1358. my @x = tokenize($2);
  1359. push @programs, @x;
  1360. push @programs_install, @x unless $install;
  1361. }
  1362. },
  1363. qr/^\s*LIBS(_NO_INST)?\s*=\s*(.*)\s*$/
  1364. => sub {
  1365. if (!@skip || $skip[$#skip] > 0) {
  1366. my $install = $1;
  1367. my @x = tokenize($2);
  1368. push @libraries, @x;
  1369. push @libraries_install, @x unless $install;
  1370. }
  1371. },
  1372. qr/^\s*ENGINES(_NO_INST)?\s*=\s*(.*)\s*$/
  1373. => sub {
  1374. if (!@skip || $skip[$#skip] > 0) {
  1375. my $install = $1;
  1376. my @x = tokenize($2);
  1377. push @engines, @x;
  1378. push @engines_install, @x unless $install;
  1379. }
  1380. },
  1381. qr/^\s*SCRIPTS(_NO_INST)?\s*=\s*(.*)\s*$/
  1382. => sub {
  1383. if (!@skip || $skip[$#skip] > 0) {
  1384. my $install = $1;
  1385. my @x = tokenize($2);
  1386. push @scripts, @x;
  1387. push @scripts_install, @x unless $install;
  1388. }
  1389. },
  1390. qr/^\s*EXTRA\s*=\s*(.*)\s*$/
  1391. => sub { push @extra, tokenize($1)
  1392. if !@skip || $skip[$#skip] > 0 },
  1393. qr/^\s*OVERRIDES\s*=\s*(.*)\s*$/
  1394. => sub { push @overrides, tokenize($1)
  1395. if !@skip || $skip[$#skip] > 0 },
  1396. qr/^\s*ORDINALS\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/,
  1397. => sub { push @{$ordinals{$1}}, tokenize($2)
  1398. if !@skip || $skip[$#skip] > 0 },
  1399. qr/^\s*SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1400. => sub { push @{$sources{$1}}, tokenize($2)
  1401. if !@skip || $skip[$#skip] > 0 },
  1402. qr/^\s*SHARED_SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1403. => sub { push @{$shared_sources{$1}}, tokenize($2)
  1404. if !@skip || $skip[$#skip] > 0 },
  1405. qr/^\s*INCLUDE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1406. => sub { push @{$includes{$1}}, tokenize($2)
  1407. if !@skip || $skip[$#skip] > 0 },
  1408. qr/^\s*DEPEND\[((?:\\.|[^\\\]])*)\]\s*=\s*(.*)\s*$/
  1409. => sub { push @{$depends{$1}}, tokenize($2)
  1410. if !@skip || $skip[$#skip] > 0 },
  1411. qr/^\s*GENERATE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1412. => sub { push @{$generate{$1}}, $2
  1413. if !@skip || $skip[$#skip] > 0 },
  1414. qr/^\s*RENAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1415. => sub { push @{$renames{$1}}, tokenize($2)
  1416. if !@skip || $skip[$#skip] > 0 },
  1417. qr/^\s*SHARED_NAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/
  1418. => sub { push @{$sharednames{$1}}, tokenize($2)
  1419. if !@skip || $skip[$#skip] > 0 },
  1420. qr/^\s*BEGINRAW\[((?:\\.|[^\\\]])+)\]\s*$/
  1421. => sub {
  1422. my $lineiterator = shift;
  1423. my $target_kind = $1;
  1424. while (defined $lineiterator->()) {
  1425. s|\R$||;
  1426. if (/^\s*ENDRAW\[((?:\\.|[^\\\]])+)\]\s*$/) {
  1427. die "ENDRAW doesn't match BEGINRAW"
  1428. if $1 ne $target_kind;
  1429. last;
  1430. }
  1431. next if @skip && $skip[$#skip] <= 0;
  1432. push @rawlines, $_
  1433. if ($target_kind eq $target{build_file}
  1434. || $target_kind eq $target{build_file}."(".$builder_platform.")");
  1435. }
  1436. },
  1437. qr/^\s*(?:#.*)?$/ => sub { },
  1438. "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" },
  1439. "BEFORE" => sub {
  1440. if ($buildinfo_debug) {
  1441. print STDERR "DEBUG: Parsing ",join(" ", @_),"\n";
  1442. print STDERR "DEBUG: ... before parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1443. }
  1444. },
  1445. "AFTER" => sub {
  1446. if ($buildinfo_debug) {
  1447. print STDERR "DEBUG: .... after parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
  1448. }
  1449. },
  1450. );
  1451. die "runaway IF?" if (@skip);
  1452. foreach (keys %renames) {
  1453. die "$_ renamed to more than one thing: "
  1454. ,join(" ", @{$renames{$_}}),"\n"
  1455. if scalar @{$renames{$_}} > 1;
  1456. my $dest = cleanfile($buildd, $_, $blddir);
  1457. my $to = cleanfile($buildd, $renames{$_}->[0], $blddir);
  1458. die "$dest renamed to more than one thing: "
  1459. ,$unified_info{rename}->{$dest}, $to
  1460. unless !defined($unified_info{rename}->{$dest})
  1461. or $unified_info{rename}->{$dest} eq $to;
  1462. $unified_info{rename}->{$dest} = $to;
  1463. }
  1464. foreach (@programs) {
  1465. my $program = cleanfile($buildd, $_, $blddir);
  1466. if ($unified_info{rename}->{$program}) {
  1467. $program = $unified_info{rename}->{$program};
  1468. }
  1469. $unified_info{programs}->{$program} = 1;
  1470. }
  1471. foreach (@programs_install) {
  1472. my $program = cleanfile($buildd, $_, $blddir);
  1473. if ($unified_info{rename}->{$program}) {
  1474. $program = $unified_info{rename}->{$program};
  1475. }
  1476. $unified_info{install}->{programs}->{$program} = 1;
  1477. }
  1478. foreach (@libraries) {
  1479. my $library = cleanfile($buildd, $_, $blddir);
  1480. if ($unified_info{rename}->{$library}) {
  1481. $library = $unified_info{rename}->{$library};
  1482. }
  1483. $unified_info{libraries}->{$library} = 1;
  1484. }
  1485. foreach (@libraries_install) {
  1486. my $library = cleanfile($buildd, $_, $blddir);
  1487. if ($unified_info{rename}->{$library}) {
  1488. $library = $unified_info{rename}->{$library};
  1489. }
  1490. $unified_info{install}->{libraries}->{$library} = 1;
  1491. }
  1492. die <<"EOF" if scalar @engines and !$config{dynamic_engines};
  1493. ENGINES can only be used if configured with 'dynamic-engine'.
  1494. This is usually a fault in a build.info file.
  1495. EOF
  1496. foreach (@engines) {
  1497. my $library = cleanfile($buildd, $_, $blddir);
  1498. if ($unified_info{rename}->{$library}) {
  1499. $library = $unified_info{rename}->{$library};
  1500. }
  1501. $unified_info{engines}->{$library} = 1;
  1502. }
  1503. foreach (@engines_install) {
  1504. my $library = cleanfile($buildd, $_, $blddir);
  1505. if ($unified_info{rename}->{$library}) {
  1506. $library = $unified_info{rename}->{$library};
  1507. }
  1508. $unified_info{install}->{engines}->{$library} = 1;
  1509. }
  1510. foreach (@scripts) {
  1511. my $script = cleanfile($buildd, $_, $blddir);
  1512. if ($unified_info{rename}->{$script}) {
  1513. $script = $unified_info{rename}->{$script};
  1514. }
  1515. $unified_info{scripts}->{$script} = 1;
  1516. }
  1517. foreach (@scripts_install) {
  1518. my $script = cleanfile($buildd, $_, $blddir);
  1519. if ($unified_info{rename}->{$script}) {
  1520. $script = $unified_info{rename}->{$script};
  1521. }
  1522. $unified_info{install}->{scripts}->{$script} = 1;
  1523. }
  1524. foreach (@extra) {
  1525. my $extra = cleanfile($buildd, $_, $blddir);
  1526. $unified_info{extra}->{$extra} = 1;
  1527. }
  1528. foreach (@overrides) {
  1529. my $override = cleanfile($buildd, $_, $blddir);
  1530. $unified_info{overrides}->{$override} = 1;
  1531. }
  1532. push @{$unified_info{rawlines}}, @rawlines;
  1533. unless ($disabled{shared}) {
  1534. # Check sharednames.
  1535. foreach (keys %sharednames) {
  1536. my $dest = cleanfile($buildd, $_, $blddir);
  1537. if ($unified_info{rename}->{$dest}) {
  1538. $dest = $unified_info{rename}->{$dest};
  1539. }
  1540. die "shared_name for $dest with multiple values: "
  1541. ,join(" ", @{$sharednames{$_}}),"\n"
  1542. if scalar @{$sharednames{$_}} > 1;
  1543. my $to = cleanfile($buildd, $sharednames{$_}->[0], $blddir);
  1544. die "shared_name found for a library $dest that isn't defined\n"
  1545. unless $unified_info{libraries}->{$dest};
  1546. die "shared_name for $dest with multiple values: "
  1547. ,$unified_info{sharednames}->{$dest}, ", ", $to
  1548. unless !defined($unified_info{sharednames}->{$dest})
  1549. or $unified_info{sharednames}->{$dest} eq $to;
  1550. $unified_info{sharednames}->{$dest} = $to;
  1551. }
  1552. # Additionally, we set up sharednames for libraries that don't
  1553. # have any, as themselves.
  1554. foreach (keys %{$unified_info{libraries}}) {
  1555. if (!defined $unified_info{sharednames}->{$_}) {
  1556. $unified_info{sharednames}->{$_} = $_
  1557. }
  1558. }
  1559. }
  1560. foreach (keys %ordinals) {
  1561. my $dest = $_;
  1562. my $ddest = cleanfile($buildd, $_, $blddir);
  1563. if ($unified_info{rename}->{$ddest}) {
  1564. $ddest = $unified_info{rename}->{$ddest};
  1565. }
  1566. foreach (@{$ordinals{$dest}}) {
  1567. my %known_ordinals =
  1568. (
  1569. crypto =>
  1570. cleanfile($sourced, catfile("util", "libcrypto.num"), $blddir),
  1571. ssl =>
  1572. cleanfile($sourced, catfile("util", "libssl.num"), $blddir)
  1573. );
  1574. my $o = $known_ordinals{$_};
  1575. die "Ordinals for $ddest defined more than once\n"
  1576. if $unified_info{ordinals}->{$ddest};
  1577. $unified_info{ordinals}->{$ddest} = [ $_, $o ];
  1578. }
  1579. }
  1580. foreach (keys %sources) {
  1581. my $dest = $_;
  1582. my $ddest = cleanfile($buildd, $_, $blddir);
  1583. if ($unified_info{rename}->{$ddest}) {
  1584. $ddest = $unified_info{rename}->{$ddest};
  1585. }
  1586. foreach (@{$sources{$dest}}) {
  1587. my $s = cleanfile($sourced, $_, $blddir);
  1588. # If it isn't in the source tree, we assume it's generated
  1589. # in the build tree
  1590. if (! -f $s) {
  1591. $s = cleanfile($buildd, $_, $blddir);
  1592. }
  1593. # We recognise C++, C and asm files
  1594. if ($s =~ /\.(cc|cpp|c|s|S)$/) {
  1595. my $o = $_;
  1596. $o =~ s/\.[csS]$/.o/; # C and assembler
  1597. $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
  1598. $o = cleanfile($buildd, $o, $blddir);
  1599. $unified_info{sources}->{$ddest}->{$o} = 1;
  1600. $unified_info{sources}->{$o}->{$s} = 1;
  1601. } else {
  1602. $unified_info{sources}->{$ddest}->{$s} = 1;
  1603. }
  1604. }
  1605. }
  1606. foreach (keys %shared_sources) {
  1607. my $dest = $_;
  1608. my $ddest = cleanfile($buildd, $_, $blddir);
  1609. if ($unified_info{rename}->{$ddest}) {
  1610. $ddest = $unified_info{rename}->{$ddest};
  1611. }
  1612. foreach (@{$shared_sources{$dest}}) {
  1613. my $s = cleanfile($sourced, $_, $blddir);
  1614. # If it isn't in the source tree, we assume it's generated
  1615. # in the build tree
  1616. if (! -f $s) {
  1617. $s = cleanfile($buildd, $_, $blddir);
  1618. }
  1619. # We recognise C++, C and asm files
  1620. if ($s =~ /\.(cc|cpp|c|s|S)$/) {
  1621. my $o = $_;
  1622. $o =~ s/\.[csS]$/.o/; # C and assembler
  1623. $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
  1624. $o = cleanfile($buildd, $o, $blddir);
  1625. $unified_info{shared_sources}->{$ddest}->{$o} = 1;
  1626. $unified_info{sources}->{$o}->{$s} = 1;
  1627. } else {
  1628. die "unrecognised source file type for shared library: $s\n";
  1629. }
  1630. }
  1631. }
  1632. foreach (keys %generate) {
  1633. my $dest = $_;
  1634. my $ddest = cleanfile($buildd, $_, $blddir);
  1635. if ($unified_info{rename}->{$ddest}) {
  1636. $ddest = $unified_info{rename}->{$ddest};
  1637. }
  1638. die "more than one generator for $dest: "
  1639. ,join(" ", @{$generate{$_}}),"\n"
  1640. if scalar @{$generate{$_}} > 1;
  1641. my @generator = split /\s+/, $generate{$dest}->[0];
  1642. $generator[0] = cleanfile($sourced, $generator[0], $blddir),
  1643. $unified_info{generate}->{$ddest} = [ @generator ];
  1644. }
  1645. foreach (keys %depends) {
  1646. my $dest = $_;
  1647. my $ddest = $dest eq "" ? "" : cleanfile($sourced, $_, $blddir);
  1648. # If the destination doesn't exist in source, it can only be
  1649. # a generated file in the build tree.
  1650. if ($ddest ne "" && ! -f $ddest) {
  1651. $ddest = cleanfile($buildd, $_, $blddir);
  1652. if ($unified_info{rename}->{$ddest}) {
  1653. $ddest = $unified_info{rename}->{$ddest};
  1654. }
  1655. }
  1656. foreach (@{$depends{$dest}}) {
  1657. my $d = cleanfile($sourced, $_, $blddir);
  1658. # If we know it's generated, or assume it is because we can't
  1659. # find it in the source tree, we set file we depend on to be
  1660. # in the build tree rather than the source tree, and assume
  1661. # and that there are lines to build it in a BEGINRAW..ENDRAW
  1662. # section or in the Makefile template.
  1663. if (! -f $d
  1664. || (grep { $d eq $_ }
  1665. map { cleanfile($srcdir, $_, $blddir) }
  1666. grep { /\.h$/ } keys %{$unified_info{generate}})) {
  1667. $d = cleanfile($buildd, $_, $blddir);
  1668. }
  1669. # Take note if the file to depend on is being renamed
  1670. # Take extra care with files ending with .a, they should
  1671. # be treated without that extension, and the extension
  1672. # should be added back after treatment.
  1673. $d =~ /(\.a)?$/;
  1674. my $e = $1 // "";
  1675. $d = $`;
  1676. if ($unified_info{rename}->{$d}) {
  1677. $d = $unified_info{rename}->{$d};
  1678. }
  1679. $d .= $e;
  1680. $unified_info{depends}->{$ddest}->{$d} = 1;
  1681. # If we depend on a header file or a perl module, let's make
  1682. # sure it can get included
  1683. if ($dest ne "" && $d =~ /\.(h|pm)$/) {
  1684. my $i = dirname($d);
  1685. push @{$unified_info{includes}->{$ddest}->{source}}, $i
  1686. unless grep { $_ eq $i } @{$unified_info{includes}->{$ddest}->{source}};
  1687. }
  1688. }
  1689. }
  1690. foreach (keys %includes) {
  1691. my $dest = $_;
  1692. my $ddest = cleanfile($sourced, $_, $blddir);
  1693. # If the destination doesn't exist in source, it can only be
  1694. # a generated file in the build tree.
  1695. if (! -f $ddest) {
  1696. $ddest = cleanfile($buildd, $_, $blddir);
  1697. if ($unified_info{rename}->{$ddest}) {
  1698. $ddest = $unified_info{rename}->{$ddest};
  1699. }
  1700. }
  1701. foreach (@{$includes{$dest}}) {
  1702. my $is = cleandir($sourced, $_, $blddir);
  1703. my $ib = cleandir($buildd, $_, $blddir);
  1704. push @{$unified_info{includes}->{$ddest}->{source}}, $is
  1705. unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}};
  1706. push @{$unified_info{includes}->{$ddest}->{build}}, $ib
  1707. unless grep { $_ eq $ib } @{$unified_info{includes}->{$ddest}->{build}};
  1708. }
  1709. }
  1710. }
  1711. ### Make unified_info a bit more efficient
  1712. # One level structures
  1713. foreach (("programs", "libraries", "engines", "scripts", "extra", "overrides")) {
  1714. $unified_info{$_} = [ sort keys %{$unified_info{$_}} ];
  1715. }
  1716. # Two level structures
  1717. foreach my $l1 (("install", "sources", "shared_sources", "ldadd", "depends")) {
  1718. foreach my $l2 (sort keys %{$unified_info{$l1}}) {
  1719. $unified_info{$l1}->{$l2} =
  1720. [ sort keys %{$unified_info{$l1}->{$l2}} ];
  1721. }
  1722. }
  1723. # Includes
  1724. foreach my $dest (sort keys %{$unified_info{includes}}) {
  1725. if (defined($unified_info{includes}->{$dest}->{build})) {
  1726. my @source_includes =
  1727. ( @{$unified_info{includes}->{$dest}->{source}} );
  1728. $unified_info{includes}->{$dest} =
  1729. [ @{$unified_info{includes}->{$dest}->{build}} ];
  1730. foreach my $inc (@source_includes) {
  1731. push @{$unified_info{includes}->{$dest}}, $inc
  1732. unless grep { $_ eq $inc } @{$unified_info{includes}->{$dest}};
  1733. }
  1734. } else {
  1735. $unified_info{includes}->{$dest} =
  1736. [ @{$unified_info{includes}->{$dest}->{source}} ];
  1737. }
  1738. }
  1739. }
  1740. # For the schemes that need it, we provide the old *_obj configs
  1741. # from the *_asm_obj ones
  1742. foreach (grep /_(asm|aux)_src$/, keys %target) {
  1743. my $src = $_;
  1744. (my $obj = $_) =~ s/_(asm|aux)_src$/_obj/;
  1745. $target{$obj} = $target{$src};
  1746. $target{$obj} =~ s/\.[csS]\b/.o/g; # C and assembler
  1747. $target{$obj} =~ s/\.(cc|cpp)\b/_cc.o/g; # C++
  1748. }
  1749. # Write down our configuration where it fits #########################
  1750. open(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n";
  1751. print OUT <<"EOF";
  1752. package configdata;
  1753. use strict;
  1754. use warnings;
  1755. use Exporter;
  1756. #use vars qw(\@ISA \@EXPORT);
  1757. our \@ISA = qw(Exporter);
  1758. our \@EXPORT = qw(\%config \%target \%disabled \%withargs \%unified_info \@disablables);
  1759. EOF
  1760. print OUT "our %config = (\n";
  1761. foreach (sort keys %config) {
  1762. if (ref($config{$_}) eq "ARRAY") {
  1763. print OUT " ", $_, " => [ ", join(", ",
  1764. map { quotify("perl", $_) }
  1765. @{$config{$_}}), " ],\n";
  1766. } else {
  1767. print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n"
  1768. }
  1769. }
  1770. print OUT <<"EOF";
  1771. );
  1772. EOF
  1773. print OUT "our %target = (\n";
  1774. foreach (sort keys %target) {
  1775. if (ref($target{$_}) eq "ARRAY") {
  1776. print OUT " ", $_, " => [ ", join(", ",
  1777. map { quotify("perl", $_) }
  1778. @{$target{$_}}), " ],\n";
  1779. } else {
  1780. print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n"
  1781. }
  1782. }
  1783. print OUT <<"EOF";
  1784. );
  1785. EOF
  1786. print OUT "our \%available_protocols = (\n";
  1787. print OUT " tls => [ ", join(", ", map { quotify("perl", $_) } @tls), " ],\n";
  1788. print OUT " dtls => [ ", join(", ", map { quotify("perl", $_) } @dtls), " ],\n";
  1789. print OUT <<"EOF";
  1790. );
  1791. EOF
  1792. print OUT "our \@disablables = (\n";
  1793. foreach (@disablables) {
  1794. print OUT " ", quotify("perl", $_), ",\n";
  1795. }
  1796. print OUT <<"EOF";
  1797. );
  1798. EOF
  1799. print OUT "our \%disabled = (\n";
  1800. foreach (sort keys %disabled) {
  1801. print OUT " ", quotify("perl", $_), " => ", quotify("perl", $disabled{$_}), ",\n";
  1802. }
  1803. print OUT <<"EOF";
  1804. );
  1805. EOF
  1806. print OUT "our %withargs = (\n";
  1807. foreach (sort keys %withargs) {
  1808. if (ref($withargs{$_}) eq "ARRAY") {
  1809. print OUT " ", $_, " => [ ", join(", ",
  1810. map { quotify("perl", $_) }
  1811. @{$withargs{$_}}), " ],\n";
  1812. } else {
  1813. print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n"
  1814. }
  1815. }
  1816. print OUT <<"EOF";
  1817. );
  1818. EOF
  1819. if ($builder eq "unified") {
  1820. my $recurse;
  1821. $recurse = sub {
  1822. my $indent = shift;
  1823. foreach (@_) {
  1824. if (ref $_ eq "ARRAY") {
  1825. print OUT " "x$indent, "[\n";
  1826. foreach (@$_) {
  1827. $recurse->($indent + 4, $_);
  1828. }
  1829. print OUT " "x$indent, "],\n";
  1830. } elsif (ref $_ eq "HASH") {
  1831. my %h = %$_;
  1832. print OUT " "x$indent, "{\n";
  1833. foreach (sort keys %h) {
  1834. if (ref $h{$_} eq "") {
  1835. print OUT " "x($indent + 4), quotify("perl", $_), " => ", quotify("perl", $h{$_}), ",\n";
  1836. } else {
  1837. print OUT " "x($indent + 4), quotify("perl", $_), " =>\n";
  1838. $recurse->($indent + 8, $h{$_});
  1839. }
  1840. }
  1841. print OUT " "x$indent, "},\n";
  1842. } else {
  1843. print OUT " "x$indent, quotify("perl", $_), ",\n";
  1844. }
  1845. }
  1846. };
  1847. print OUT "our %unified_info = (\n";
  1848. foreach (sort keys %unified_info) {
  1849. if (ref $unified_info{$_} eq "") {
  1850. print OUT " "x4, quotify("perl", $_), " => ", quotify("perl", $unified_info{$_}), ",\n";
  1851. } else {
  1852. print OUT " "x4, quotify("perl", $_), " =>\n";
  1853. $recurse->(8, $unified_info{$_});
  1854. }
  1855. }
  1856. print OUT <<"EOF";
  1857. );
  1858. EOF
  1859. }
  1860. print OUT "1;\n";
  1861. close(OUT);
  1862. print "\n";
  1863. print "PROCESSOR =$config{processor}\n" if $config{processor};
  1864. print "PERL =$config{perl}\n";
  1865. print "PERLVERSION =$Config{version} for $Config{archname}\n";
  1866. print "HASHBANGPERL =$config{hashbangperl}\n";
  1867. print "CC =$config{cross_compile_prefix}$target{cc}\n";
  1868. print "CFLAG =$target{cflags} $config{cflags}\n";
  1869. print "CXX =$config{cross_compile_prefix}$target{cxx}\n"
  1870. if defined $target{cxx};
  1871. print "CXXFLAG =$target{cxxflags} $config{cxxflags}\n"
  1872. if defined $target{cxx};
  1873. print "DEFINES =",join(" ", @{$target{defines}}, @{$config{defines}}),"\n";
  1874. #print "RANLIB =", $target{ranlib} eq '$(CROSS_COMPILE)ranlib' ?
  1875. # "$config{cross_compile_prefix}ranlib" :
  1876. # "$target{ranlib}", "\n";
  1877. print "EX_LIBS =$target{ex_libs} $config{ex_libs}\n";
  1878. my %builders = (
  1879. unified => sub {
  1880. run_dofile(catfile($blddir, $target{build_file}),
  1881. @{$config{build_file_templates}});
  1882. },
  1883. );
  1884. $builders{$builder}->($builder_platform, @builder_opts);
  1885. print <<"EOF" if ($disabled{threads} eq "unavailable");
  1886. The library could not be configured for supporting multi-threaded
  1887. applications as the compiler options required on this system are not known.
  1888. See file INSTALL for details if you need multi-threading.
  1889. EOF
  1890. print <<"EOF" if ($no_shared_warn);
  1891. The options 'shared', 'pic' and 'dynamic-engine' aren't supported on this
  1892. platform, so we will pretend you gave the option 'no-pic', which also disables
  1893. 'shared' and 'dynamic-engine'. If you know how to implement shared libraries
  1894. or position independent code, please let us know (but please first make sure
  1895. you have tried with a current version of OpenSSL).
  1896. EOF
  1897. print <<"EOF" if (-f catfile($srcdir, "configdata.pm") && $srcdir ne $blddir);
  1898. WARNING: there are indications that another build was made in the source
  1899. directory. This build may have picked up artifacts from that build, the
  1900. safest course of action is to clean the source directory and redo this
  1901. configuration.
  1902. EOF
  1903. exit(0);
  1904. ######################################################################
  1905. #
  1906. # Helpers and utility functions
  1907. #
  1908. # Configuration file reading #########################################
  1909. # Note: All of the helper functions are for lazy evaluation. They all
  1910. # return a CODE ref, which will return the intended value when evaluated.
  1911. # Thus, whenever there's mention of a returned value, it's about that
  1912. # intended value.
  1913. # Helper function to implement conditional inheritance depending on the
  1914. # value of $disabled{asm}. Used in inherit_from values as follows:
  1915. #
  1916. # inherit_from => [ "template", asm("asm_tmpl") ]
  1917. #
  1918. sub asm {
  1919. my @x = @_;
  1920. sub {
  1921. $disabled{asm} ? () : @x;
  1922. }
  1923. }
  1924. # Helper function to implement conditional value variants, with a default
  1925. # plus additional values based on the value of $config{build_type}.
  1926. # Arguments are given in hash table form:
  1927. #
  1928. # picker(default => "Basic string: ",
  1929. # debug => "debug",
  1930. # release => "release")
  1931. #
  1932. # When configuring with --debug, the resulting string will be
  1933. # "Basic string: debug", and when not, it will be "Basic string: release"
  1934. #
  1935. # This can be used to create variants of sets of flags according to the
  1936. # build type:
  1937. #
  1938. # cflags => picker(default => "-Wall",
  1939. # debug => "-g -O0",
  1940. # release => "-O3")
  1941. #
  1942. sub picker {
  1943. my %opts = @_;
  1944. return sub { add($opts{default} || (),
  1945. $opts{$config{build_type}} || ())->(); }
  1946. }
  1947. # Helper function to combine several values of different types into one.
  1948. # This is useful if you want to combine a string with the result of a
  1949. # lazy function, such as:
  1950. #
  1951. # cflags => combine("-Wall", sub { $disabled{zlib} ? () : "-DZLIB" })
  1952. #
  1953. sub combine {
  1954. my @stuff = @_;
  1955. return sub { add(@stuff)->(); }
  1956. }
  1957. # Helper function to implement conditional values depending on the value
  1958. # of $disabled{threads}. Can be used as follows:
  1959. #
  1960. # cflags => combine("-Wall", threads("-pthread"))
  1961. #
  1962. sub threads {
  1963. my @flags = @_;
  1964. return sub { add($disabled{threads} ? () : @flags)->(); }
  1965. }
  1966. our $add_called = 0;
  1967. # Helper function to implement adding values to already existing configuration
  1968. # values. It handles elements that are ARRAYs, CODEs and scalars
  1969. sub _add {
  1970. my $separator = shift;
  1971. # If there's any ARRAY in the collection of values OR the separator
  1972. # is undef, we will return an ARRAY of combined values, otherwise a
  1973. # string of joined values with $separator as the separator.
  1974. my $found_array = !defined($separator);
  1975. my @values =
  1976. map {
  1977. my $res = $_;
  1978. while (ref($res) eq "CODE") {
  1979. $res = $res->();
  1980. }
  1981. if (defined($res)) {
  1982. if (ref($res) eq "ARRAY") {
  1983. $found_array = 1;
  1984. @$res;
  1985. } else {
  1986. $res;
  1987. }
  1988. } else {
  1989. ();
  1990. }
  1991. } (@_);
  1992. $add_called = 1;
  1993. if ($found_array) {
  1994. [ @values ];
  1995. } else {
  1996. join($separator, grep { defined($_) && $_ ne "" } @values);
  1997. }
  1998. }
  1999. sub add_before {
  2000. my $separator = " ";
  2001. if (ref($_[$#_]) eq "HASH") {
  2002. my $opts = pop;
  2003. $separator = $opts->{separator};
  2004. }
  2005. my @x = @_;
  2006. sub { _add($separator, @x, @_) };
  2007. }
  2008. sub add {
  2009. my $separator = " ";
  2010. if (ref($_[$#_]) eq "HASH") {
  2011. my $opts = pop;
  2012. $separator = $opts->{separator};
  2013. }
  2014. my @x = @_;
  2015. sub { _add($separator, @_, @x) };
  2016. }
  2017. # configuration reader, evaluates the input file as a perl script and expects
  2018. # it to fill %targets with target configurations. Those are then added to
  2019. # %table.
  2020. sub read_config {
  2021. my $fname = shift;
  2022. open(CONFFILE, "< $fname")
  2023. or die "Can't open configuration file '$fname'!\n";
  2024. my $x = $/;
  2025. undef $/;
  2026. my $content = <CONFFILE>;
  2027. $/ = $x;
  2028. close(CONFFILE);
  2029. my %targets = ();
  2030. {
  2031. # Protect certain tables from tampering
  2032. local %table = %::table;
  2033. eval $content;
  2034. warn $@ if $@;
  2035. }
  2036. # For each target, check that it's configured with a hash table.
  2037. foreach (keys %targets) {
  2038. if (ref($targets{$_}) ne "HASH") {
  2039. if (ref($targets{$_}) eq "") {
  2040. warn "Deprecated target configuration for $_, ignoring...\n";
  2041. } else {
  2042. warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
  2043. }
  2044. delete $targets{$_};
  2045. } else {
  2046. $targets{$_}->{_conf_fname_int} = add([ $fname ]);
  2047. }
  2048. }
  2049. %table = (%table, %targets);
  2050. }
  2051. # configuration resolver. Will only resolve all the lazy evaluation
  2052. # codeblocks for the chosen target and all those it inherits from,
  2053. # recursively
  2054. sub resolve_config {
  2055. my $target = shift;
  2056. my @breadcrumbs = @_;
  2057. # my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS});
  2058. if (grep { $_ eq $target } @breadcrumbs) {
  2059. die "inherit_from loop! target backtrace:\n "
  2060. ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
  2061. }
  2062. if (!defined($table{$target})) {
  2063. warn "Warning! target $target doesn't exist!\n";
  2064. return ();
  2065. }
  2066. # Recurse through all inheritances. They will be resolved on the
  2067. # fly, so when this operation is done, they will all just be a
  2068. # bunch of attributes with string values.
  2069. # What we get here, though, are keys with references to lists of
  2070. # the combined values of them all. We will deal with lists after
  2071. # this stage is done.
  2072. my %combined_inheritance = ();
  2073. if ($table{$target}->{inherit_from}) {
  2074. my @inherit_from =
  2075. map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
  2076. foreach (@inherit_from) {
  2077. my %inherited_config = resolve_config($_, $target, @breadcrumbs);
  2078. # 'template' is a marker that's considered private to
  2079. # the config that had it.
  2080. delete $inherited_config{template};
  2081. foreach (keys %inherited_config) {
  2082. if (!$combined_inheritance{$_}) {
  2083. $combined_inheritance{$_} = [];
  2084. }
  2085. push @{$combined_inheritance{$_}}, $inherited_config{$_};
  2086. }
  2087. }
  2088. }
  2089. # We won't need inherit_from in this target any more, since we've
  2090. # resolved all the inheritances that lead to this
  2091. delete $table{$target}->{inherit_from};
  2092. # Now is the time to deal with those lists. Here's the place to
  2093. # decide what shall be done with those lists, all based on the
  2094. # values of the target we're currently dealing with.
  2095. # - If a value is a coderef, it will be executed with the list of
  2096. # inherited values as arguments.
  2097. # - If the corresponding key doesn't have a value at all or is the
  2098. # empty string, the inherited value list will be run through the
  2099. # default combiner (below), and the result becomes this target's
  2100. # value.
  2101. # - Otherwise, this target's value is assumed to be a string that
  2102. # will simply override the inherited list of values.
  2103. my $default_combiner = add();
  2104. my %all_keys =
  2105. map { $_ => 1 } (keys %combined_inheritance,
  2106. keys %{$table{$target}});
  2107. sub process_values {
  2108. my $object = shift;
  2109. my $inherited = shift; # Always a [ list ]
  2110. my $target = shift;
  2111. my $entry = shift;
  2112. $add_called = 0;
  2113. while(ref($object) eq "CODE") {
  2114. $object = $object->(@$inherited);
  2115. }
  2116. if (!defined($object)) {
  2117. return ();
  2118. }
  2119. elsif (ref($object) eq "ARRAY") {
  2120. local $add_called; # To make sure recursive calls don't affect it
  2121. return [ map { process_values($_, $inherited, $target, $entry) }
  2122. @$object ];
  2123. } elsif (ref($object) eq "") {
  2124. return $object;
  2125. } else {
  2126. die "cannot handle reference type ",ref($object)
  2127. ," found in target ",$target," -> ",$entry,"\n";
  2128. }
  2129. }
  2130. foreach (sort keys %all_keys) {
  2131. my $previous = $combined_inheritance{$_};
  2132. # Current target doesn't have a value for the current key?
  2133. # Assign it the default combiner, the rest of this loop body
  2134. # will handle it just like any other coderef.
  2135. if (!exists $table{$target}->{$_}) {
  2136. $table{$target}->{$_} = $default_combiner;
  2137. }
  2138. $table{$target}->{$_} = process_values($table{$target}->{$_},
  2139. $combined_inheritance{$_},
  2140. $target, $_);
  2141. unless(defined($table{$target}->{$_})) {
  2142. delete $table{$target}->{$_};
  2143. }
  2144. # if ($extra_checks &&
  2145. # $previous && !($add_called || $previous ~~ $table{$target}->{$_})) {
  2146. # warn "$_ got replaced in $target\n";
  2147. # }
  2148. }
  2149. # Finally done, return the result.
  2150. return %{$table{$target}};
  2151. }
  2152. sub usage
  2153. {
  2154. print STDERR $usage;
  2155. print STDERR "\npick os/compiler from:\n";
  2156. my $j=0;
  2157. my $i;
  2158. my $k=0;
  2159. foreach $i (sort keys %table)
  2160. {
  2161. next if $table{$i}->{template};
  2162. next if $i =~ /^debug/;
  2163. $k += length($i) + 1;
  2164. if ($k > 78)
  2165. {
  2166. print STDERR "\n";
  2167. $k=length($i);
  2168. }
  2169. print STDERR $i . " ";
  2170. }
  2171. foreach $i (sort keys %table)
  2172. {
  2173. next if $table{$i}->{template};
  2174. next if $i !~ /^debug/;
  2175. $k += length($i) + 1;
  2176. if ($k > 78)
  2177. {
  2178. print STDERR "\n";
  2179. $k=length($i);
  2180. }
  2181. print STDERR $i . " ";
  2182. }
  2183. print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n";
  2184. exit(1);
  2185. }
  2186. sub run_dofile
  2187. {
  2188. my $out = shift;
  2189. my @templates = @_;
  2190. unlink $out || warn "Can't remove $out, $!"
  2191. if -f $out;
  2192. foreach (@templates) {
  2193. die "Can't open $_, $!" unless -f $_;
  2194. }
  2195. my $perlcmd = (quotify("maybeshell", $config{perl}))[0];
  2196. my $cmd = "$perlcmd \"-I.\" \"-Mconfigdata\" \"$dofile\" -o\"Configure\" \"".join("\" \"",@templates)."\" > \"$out.new\"";
  2197. #print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
  2198. system($cmd);
  2199. exit 1 if $? != 0;
  2200. rename("$out.new", $out) || die "Can't rename $out.new, $!";
  2201. }
  2202. sub which
  2203. {
  2204. my ($name)=@_;
  2205. if (eval { require IPC::Cmd; 1; }) {
  2206. IPC::Cmd->import();
  2207. return scalar IPC::Cmd::can_run($name);
  2208. } else {
  2209. # if there is $directories component in splitpath,
  2210. # then it's not something to test with $PATH...
  2211. return $name if (File::Spec->splitpath($name))[1];
  2212. foreach (File::Spec->path()) {
  2213. my $fullpath = catfile($_, "$name$target{exe_extension}");
  2214. if (-f $fullpath and -x $fullpath) {
  2215. return $fullpath;
  2216. }
  2217. }
  2218. }
  2219. }
  2220. # Configuration printer ##############################################
  2221. sub print_table_entry
  2222. {
  2223. my $target = shift;
  2224. my %target = resolve_config($target);
  2225. my $type = shift;
  2226. # Don't print the templates
  2227. return if $target{template};
  2228. my @sequence = (
  2229. "sys_id",
  2230. "cc",
  2231. "cflags",
  2232. "defines",
  2233. "unistd",
  2234. "ld",
  2235. "lflags",
  2236. "loutflag",
  2237. "plib_lflags",
  2238. "ex_libs",
  2239. "bn_ops",
  2240. "apps_aux_src",
  2241. "cpuid_asm_src",
  2242. "uplink_aux_src",
  2243. "bn_asm_src",
  2244. "ec_asm_src",
  2245. "des_asm_src",
  2246. "aes_asm_src",
  2247. "bf_asm_src",
  2248. "md5_asm_src",
  2249. "cast_asm_src",
  2250. "sha1_asm_src",
  2251. "rc4_asm_src",
  2252. "rmd160_asm_src",
  2253. "rc5_asm_src",
  2254. "wp_asm_src",
  2255. "cmll_asm_src",
  2256. "modes_asm_src",
  2257. "padlock_asm_src",
  2258. "chacha_asm_src",
  2259. "poly1035_asm_src",
  2260. "thread_scheme",
  2261. "perlasm_scheme",
  2262. "dso_scheme",
  2263. "shared_target",
  2264. "shared_cflag",
  2265. "shared_defines",
  2266. "shared_ldflag",
  2267. "shared_rcflag",
  2268. "shared_extension",
  2269. "dso_extension",
  2270. "obj_extension",
  2271. "exe_extension",
  2272. "ranlib",
  2273. "ar",
  2274. "arflags",
  2275. "aroutflag",
  2276. "rc",
  2277. "rcflags",
  2278. "rcoutflag",
  2279. "mt",
  2280. "mtflags",
  2281. "mtinflag",
  2282. "mtoutflag",
  2283. "multilib",
  2284. "build_scheme",
  2285. );
  2286. if ($type eq "TABLE") {
  2287. print "\n";
  2288. print "*** $target\n";
  2289. foreach (@sequence) {
  2290. if (ref($target{$_}) eq "ARRAY") {
  2291. printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}});
  2292. } else {
  2293. printf "\$%-12s = %s\n", $_, $target{$_};
  2294. }
  2295. }
  2296. } elsif ($type eq "HASH") {
  2297. my $largest =
  2298. length((sort { length($a) <=> length($b) } @sequence)[-1]);
  2299. print " '$target' => {\n";
  2300. foreach (@sequence) {
  2301. if ($target{$_}) {
  2302. if (ref($target{$_}) eq "ARRAY") {
  2303. print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n";
  2304. } else {
  2305. print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
  2306. }
  2307. }
  2308. }
  2309. print " },\n";
  2310. }
  2311. }
  2312. # Utility routines ###################################################
  2313. # On VMS, if the given file is a logical name, File::Spec::Functions
  2314. # will consider it an absolute path. There are cases when we want a
  2315. # purely syntactic check without checking the environment.
  2316. sub isabsolute {
  2317. my $file = shift;
  2318. # On non-platforms, we just use file_name_is_absolute().
  2319. return file_name_is_absolute($file) unless $^O eq "VMS";
  2320. # If the file spec includes a device or a directpry spec,
  2321. # file_name_is_absolute() is perfectly safe.
  2322. return file_name_is_absolute($file) if $file =~ m|[:\[]|;
  2323. # Here, we know the given file spec isn't absolute
  2324. return 0;
  2325. }
  2326. # Makes a directory absolute and cleans out /../ in paths like foo/../bar
  2327. # On some platforms, this uses rel2abs(), while on others, realpath() is used.
  2328. # realpath() requires that at least all path components except the last is an
  2329. # existing directory. On VMS, the last component of the directory spec must
  2330. # exist.
  2331. sub absolutedir {
  2332. my $dir = shift;
  2333. # realpath() is quite buggy on VMS. It uses LIB$FID_TO_NAME, which
  2334. # will return the volume name for the device, no matter what. Also,
  2335. # it will return an incorrect directory spec if the argument is a
  2336. # directory that doesn't exist.
  2337. if ($^O eq "VMS") {
  2338. return rel2abs($dir);
  2339. }
  2340. # We use realpath() on Unix, since no other will properly clean out
  2341. # a directory spec.
  2342. use Cwd qw/realpath/;
  2343. return realpath($dir);
  2344. }
  2345. sub quotify {
  2346. my %processors = (
  2347. perl => sub { my $x = shift;
  2348. $x =~ s/([\\\$\@"])/\\$1/g;
  2349. return '"'.$x.'"'; },
  2350. maybeshell => sub { my $x = shift;
  2351. (my $y = $x) =~ s/([\\\"])/\\$1/g;
  2352. if ($x ne $y || $x =~ m|\s|) {
  2353. return '"'.$y.'"';
  2354. } else {
  2355. return $x;
  2356. }
  2357. },
  2358. );
  2359. my $for = shift;
  2360. my $processor =
  2361. defined($processors{$for}) ? $processors{$for} : sub { shift; };
  2362. return map { $processor->($_); } @_;
  2363. }
  2364. # collect_from_file($filename, $line_concat_cond_re, $line_concat)
  2365. # $filename is a file name to read from
  2366. # $line_concat_cond_re is a regexp detecting a line continuation ending
  2367. # $line_concat is a CODEref that takes care of concatenating two lines
  2368. sub collect_from_file {
  2369. my $filename = shift;
  2370. my $line_concat_cond_re = shift;
  2371. my $line_concat = shift;
  2372. open my $fh, $filename || die "unable to read $filename: $!\n";
  2373. return sub {
  2374. my $saved_line = "";
  2375. $_ = "";
  2376. while (<$fh>) {
  2377. s|\R$||;
  2378. if (defined $line_concat) {
  2379. $_ = $line_concat->($saved_line, $_);
  2380. $saved_line = "";
  2381. }
  2382. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  2383. $saved_line = $_;
  2384. next;
  2385. }
  2386. return $_;
  2387. }
  2388. die "$filename ending with continuation line\n" if $_;
  2389. close $fh;
  2390. return undef;
  2391. }
  2392. }
  2393. # collect_from_array($array, $line_concat_cond_re, $line_concat)
  2394. # $array is an ARRAYref of lines
  2395. # $line_concat_cond_re is a regexp detecting a line continuation ending
  2396. # $line_concat is a CODEref that takes care of concatenating two lines
  2397. sub collect_from_array {
  2398. my $array = shift;
  2399. my $line_concat_cond_re = shift;
  2400. my $line_concat = shift;
  2401. my @array = (@$array);
  2402. return sub {
  2403. my $saved_line = "";
  2404. $_ = "";
  2405. while (defined($_ = shift @array)) {
  2406. s|\R$||;
  2407. if (defined $line_concat) {
  2408. $_ = $line_concat->($saved_line, $_);
  2409. $saved_line = "";
  2410. }
  2411. if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
  2412. $saved_line = $_;
  2413. next;
  2414. }
  2415. return $_;
  2416. }
  2417. die "input text ending with continuation line\n" if $_;
  2418. return undef;
  2419. }
  2420. }
  2421. # collect_information($lineiterator, $line_continue, $regexp => $CODEref, ...)
  2422. # $lineiterator is a CODEref that delivers one line at a time.
  2423. # All following arguments are regex/CODEref pairs, where the regexp detects a
  2424. # line and the CODEref does something with the result of the regexp.
  2425. sub collect_information {
  2426. my $lineiterator = shift;
  2427. my %collectors = @_;
  2428. while(defined($_ = $lineiterator->())) {
  2429. s|\R$||;
  2430. my $found = 0;
  2431. if ($collectors{"BEFORE"}) {
  2432. $collectors{"BEFORE"}->($_);
  2433. }
  2434. foreach my $re (keys %collectors) {
  2435. if ($re !~ /^OTHERWISE|BEFORE|AFTER$/ && /$re/) {
  2436. $collectors{$re}->($lineiterator);
  2437. $found = 1;
  2438. };
  2439. }
  2440. if ($collectors{"OTHERWISE"}) {
  2441. $collectors{"OTHERWISE"}->($lineiterator, $_)
  2442. unless $found || !defined $collectors{"OTHERWISE"};
  2443. }
  2444. if ($collectors{"AFTER"}) {
  2445. $collectors{"AFTER"}->($_);
  2446. }
  2447. }
  2448. }
  2449. # tokenize($line)
  2450. # $line is a line of text to split up into tokens
  2451. # returns a list of tokens
  2452. #
  2453. # Tokens are divided by spaces. If the tokens include spaces, they
  2454. # have to be quoted with single or double quotes. Double quotes
  2455. # inside a double quoted token must be escaped. Escaping is done
  2456. # with backslash.
  2457. # Basically, the same quoting rules apply for " and ' as in any
  2458. # Unix shell.
  2459. sub tokenize {
  2460. my $line = my $debug_line = shift;
  2461. my @result = ();
  2462. while ($line =~ s|^\s+||, $line ne "") {
  2463. my $token = "";
  2464. while ($line ne "" && $line !~ m|^\s|) {
  2465. if ($line =~ m/^"((?:[^"\\]+|\\.)*)"/) {
  2466. $token .= $1;
  2467. $line = $';
  2468. } elsif ($line =~ m/^'([^']*)'/) {
  2469. $token .= $1;
  2470. $line = $';
  2471. } elsif ($line =~ m/^(\S+)/) {
  2472. $token .= $1;
  2473. $line = $';
  2474. }
  2475. }
  2476. push @result, $token;
  2477. }
  2478. if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) {
  2479. print STDERR "DEBUG[tokenize]: Parsed '$debug_line' into:\n";
  2480. print STDERR "DEBUG[tokenize]: ('", join("', '", @result), "')\n";
  2481. }
  2482. return @result;
  2483. }