Configure 114 KB

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