Configure 93 KB

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