Configure 91 KB

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