Configure 113 KB

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