Configure 116 KB

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