Configure 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  1. #! /usr/bin/env perl
  2. # -*- mode: perl; -*-
  3. ##
  4. ## Configure -- OpenSSL source tree configuration script
  5. ## If editing this file, run this command before committing
  6. ## make -f Makefile.in TABLE
  7. ##
  8. require 5.000;
  9. use strict;
  10. use File::Basename;
  11. use File::Spec::Functions;
  12. # see INSTALL for instructions.
  13. my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimental-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";
  14. # Options:
  15. #
  16. # --config add the given configuration file, which will be read after
  17. # any "Configurations*" files that are found in the same
  18. # directory as this script.
  19. # --prefix prefix for the OpenSSL installation, which includes the
  20. # directories bin, lib, include, share/man, share/doc/openssl
  21. # This becomes the value of INSTALLTOP in Makefile
  22. # (Default: /usr/local)
  23. # --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys.
  24. # If it's a relative directory, it will be added on the directory
  25. # given with --prefix.
  26. # This becomes the value of OPENSSLDIR in Makefile and in C.
  27. # (Default: PREFIX/ssl)
  28. #
  29. # --install_prefix Additional prefix for package builders (empty by
  30. # default). This needn't be set in advance, you can
  31. # just as well use "make INSTALL_PREFIX=/whatever install".
  32. #
  33. # --cross-compile-prefix Add specified prefix to binutils components.
  34. #
  35. # --api One of 0.9.8, 1.0.0 or 1.1.0. Do not compile support for
  36. # interfaces deprecated as of the specified OpenSSL version.
  37. #
  38. # no-hw-xxx do not compile support for specific crypto hardware.
  39. # Generic OpenSSL-style methods relating to this support
  40. # are always compiled but return NULL if the hardware
  41. # support isn't compiled.
  42. # no-hw do not compile support for any crypto hardware.
  43. # [no-]threads [don't] try to create a library that is suitable for
  44. # multithreaded applications (default is "threads" if we
  45. # know how to do it)
  46. # [no-]shared [don't] try to create shared libraries when supported.
  47. # no-asm do not use assembler
  48. # no-dso do not compile in any native shared-library methods. This
  49. # will ensure that all methods just return NULL.
  50. # no-egd do not compile support for the entropy-gathering daemon APIs
  51. # [no-]zlib [don't] compile support for zlib compression.
  52. # zlib-dynamic Like "zlib", but the zlib library is expected to be a shared
  53. # library and will be loaded in run-time by the OpenSSL library.
  54. # sctp include SCTP support
  55. # 386 generate 80386 code
  56. # no-sse2 disables IA-32 SSE2 code, above option implies no-sse2
  57. # no-<cipher> build without specified algorithm (rsa, idea, rc5, ...)
  58. # -<xxx> +<xxx> compiler options are passed through
  59. #
  60. # DEBUG_SAFESTACK use type-safe stacks to enforce type-safety on stack items
  61. # provided to stack calls. Generates unique stack functions for
  62. # each possible stack type.
  63. # DES_PTR use pointer lookup vs arrays in the DES in crypto/des/des_locl.h
  64. # DES_RISC1 use different DES_ENCRYPT macro that helps reduce register
  65. # dependancies but needs to more registers, good for RISC CPU's
  66. # DES_RISC2 A different RISC variant.
  67. # DES_UNROLL unroll the inner DES loop, sometimes helps, somtimes hinders.
  68. # DES_INT use 'int' instead of 'long' for DES_LONG in crypto/des/des.h
  69. # This is used on the DEC Alpha where long is 8 bytes
  70. # and int is 4
  71. # BN_LLONG use the type 'long long' in crypto/bn/bn.h
  72. # MD2_CHAR use 'char' instead of 'int' for MD2_INT in crypto/md2/md2.h
  73. # MD2_LONG use 'long' instead of 'int' for MD2_INT in crypto/md2/md2.h
  74. # IDEA_SHORT use 'short' instead of 'int' for IDEA_INT in crypto/idea/idea.h
  75. # IDEA_LONG use 'long' instead of 'int' for IDEA_INT in crypto/idea/idea.h
  76. # RC2_SHORT use 'short' instead of 'int' for RC2_INT in crypto/rc2/rc2.h
  77. # RC2_LONG use 'long' instead of 'int' for RC2_INT in crypto/rc2/rc2.h
  78. # RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
  79. # RC4_LONG use 'long' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
  80. # RC4_INDEX define RC4_INDEX in crypto/rc4/rc4_locl.h. This turns on
  81. # array lookups instead of pointer use.
  82. # RC4_CHUNK enables code that handles data aligned at long (natural CPU
  83. # word) boundary.
  84. # RC4_CHUNK_LL enables code that handles data aligned at long long boundary
  85. # (intended for 64-bit CPUs running 32-bit OS).
  86. # BF_PTR use 'pointer arithmatic' for Blowfish (unsafe on Alpha).
  87. # BF_PTR2 intel specific version (generic version is more efficient).
  88. #
  89. # Following are set automatically by this script
  90. #
  91. # MD5_ASM use some extra md5 assember,
  92. # SHA1_ASM use some extra sha1 assember, must define L_ENDIAN for x86
  93. # RMD160_ASM use some extra ripemd160 assember,
  94. # SHA256_ASM sha256_block is implemented in assembler
  95. # SHA512_ASM sha512_block is implemented in assembler
  96. # AES_ASM ASE_[en|de]crypt is implemented in assembler
  97. # Minimum warning options... any contributions to OpenSSL should at least get
  98. # past these.
  99. my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DREF_CHECK -DDEBUG_UNUSED";
  100. # These are used in addition to $gcc_devteam_warn when the compiler is clang.
  101. # TODO(openssl-team): fix problems and investigate if (at least) the
  102. # following warnings can also be enabled:
  103. # -Wswitch-enum, -Wunused-macros, -Wmissing-field-initializers,
  104. # -Wcast-align,
  105. # -Wunreachable-code -Wunused-parameter -Wlanguage-extension-token
  106. # -Wextended-offsetof
  107. my $clang_devteam_warn = "-Wno-unused-parameter -Wno-missing-field-initializers -Wno-language-extension-token -Wno-extended-offsetof -Wconditional-uninitialized -Qunused-arguments -Wincompatible-pointer-types-discards-qualifiers -Wmissing-variable-declarations";
  108. # Warn that "make depend" should be run?
  109. my $warn_make_depend = 0;
  110. # These are used in addition to $gcc_devteam_warn unless this is a mingw build.
  111. # This adds backtrace information to the memory leak info.
  112. my $memleak_devteam_backtrace = "-rdynamic -DCRYPTO_MDEBUG_BACKTRACE";
  113. my $strict_warnings = 0;
  114. my $x86_gcc_des="DES_PTR DES_RISC1 DES_UNROLL";
  115. # MD2_CHAR slags pentium pros
  116. my $x86_gcc_opts="RC4_INDEX MD2_INT";
  117. # As for $BSDthreads. Idea is to maintain "collective" set of flags,
  118. # which would cover all BSD flavors. -pthread applies to them all,
  119. # but is treated differently. OpenBSD expands is as -D_POSIX_THREAD
  120. # -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r,
  121. # which has to be accompanied by explicit -D_THREAD_SAFE and
  122. # sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which
  123. # seems to be sufficient?
  124. my $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT";
  125. #
  126. # API compability name to version number mapping.
  127. #
  128. my $maxapi = "1.1.0"; # API for "no-deprecated" builds
  129. my $apitable = {
  130. "1.1.0" => "0x10100000L",
  131. "1.0.0" => "0x10000000L",
  132. "0.9.8" => "0x00908000L",
  133. };
  134. my $base_target = "BASE"; # The template that all other inherit from
  135. our %table = ();
  136. our %config = ();
  137. # Forward declarations ###############################################
  138. # read_config(filename)
  139. #
  140. # Reads a configuration file and populates %table with the contents
  141. # (which the configuration file places in %targets).
  142. sub read_config;
  143. # resolve_config(target)
  144. #
  145. # Resolves all the late evalutations, inheritances and so on for the
  146. # chosen target and any target it inherits from.
  147. sub resolve_config;
  148. # Information collection #############################################
  149. # Collect version numbers
  150. $config{version} = "unknown";
  151. $config{version_num} = "unknown";
  152. $config{shlib_version_number} = "unknown";
  153. $config{shlib_version_history} = "unknown";
  154. collect_information(
  155. '<include/openssl/opensslv.h',
  156. undef,
  157. qr/OPENSSL.VERSION.TEXT.*OpenSSL (\S+) / => sub { $config{version} = $1; },
  158. qr/OPENSSL.VERSION.NUMBER.*(0x\S+)/ => sub { $config{version_num}=$1 },
  159. qr/SHLIB_VERSION_NUMBER *"([^"]+)"/ => sub { $config{shlib_version_number}=$1 },
  160. qr/SHLIB_VERSION_HISTORY *"([^"]*)"/ => sub { $config{shlib_version_history}=$1 }
  161. );
  162. if ($config{shlib_version_history} ne "") { $config{shlib_version_history} .= ":"; }
  163. ($config{major}, $config{minor})
  164. = ($config{version} =~ /^([0-9]+)\.([0-9\.]+)/);
  165. ($config{shlib_major}, $config{shlib_minor})
  166. = ($config{shlib_version_number} =~ /^([0-9]+)\.([0-9\.]+)/);
  167. die "erroneous version information in opensslv.h: ",
  168. "$config{major}, $config{minor}, $config{shlib_major}, $config{shlib_minor}\n"
  169. if ($config{major} eq "" || $config{minor} eq ""
  170. || $config{shlib_major} eq "" || $config{shlib_minor} eq "");
  171. # Collect target configurations
  172. my ($vol, $dir, $dummy) = File::Spec->splitpath($0);
  173. my $pattern = File::Spec->catpath($vol, $dir, "Configurations/*.conf");
  174. foreach (sort glob($pattern) ) {
  175. &read_config($_);
  176. }
  177. print "Configuring OpenSSL version $config{version} (0x$config{version_num})\n";
  178. $config{perl};
  179. $config{prefix}="";
  180. $config{openssldir}="";
  181. $config{processor}="";
  182. $config{libdir}="";
  183. $config{install_prefix}= "$ENV{'INSTALL_PREFIX'}";
  184. $config{cross_compile_prefix}="";
  185. $config{fipslibdir}="/usr/local/ssl/fips-2.0/lib/";
  186. my $nofipscanistercheck=0;
  187. $config{baseaddr}="0xFB00000";
  188. my $no_threads=0;
  189. my $threads=0;
  190. $config{no_shared}=0; # but "no-shared" is default
  191. my $zlib=1; # but "no-zlib" is default
  192. my $no_rfc3779=0;
  193. my $no_asm=0;
  194. my $no_dso=0;
  195. my $Makefile="Makefile";
  196. my $default_ranlib;
  197. $config{fips}=0;
  198. # Top level directories to build
  199. $config{dirs} = [ "crypto", "ssl", "engines", "apps", "test", "tools" ];
  200. # crypto/ subdirectories to build
  201. $config{sdirs} = [
  202. "objects",
  203. "md2", "md4", "md5", "sha", "mdc2", "hmac", "ripemd", "whrlpool", "poly1305",
  204. "des", "aes", "rc2", "rc4", "rc5", "idea", "bf", "cast", "camellia", "seed", "chacha", "modes",
  205. "bn", "ec", "rsa", "dsa", "dh", "dso", "engine",
  206. "buffer", "bio", "stack", "lhash", "rand", "err",
  207. "evp", "asn1", "pem", "x509", "x509v3", "conf", "txt_db", "pkcs7", "pkcs12", "comp", "ocsp", "ui",
  208. "cms", "ts", "jpake", "srp", "store", "cmac", "ct", "async", "kdf"
  209. ];
  210. # Known TLS and DTLS protocols
  211. my @tls = qw(ssl3 tls1 tls1_1 tls1_2);
  212. my @dtls = qw(dtls1 dtls1_2);
  213. # Explicitelly known options that are possible to disable. They can
  214. # be regexps, and will be used like this: /^no-${option}$/
  215. # For developers: keep it sorted alphabetically
  216. my @disablables = (
  217. "aes",
  218. "asm",
  219. "bf",
  220. "camellia",
  221. "capieng",
  222. "cast",
  223. "chacha",
  224. "cmac",
  225. "cms",
  226. "comp",
  227. "crypto-mdebug",
  228. "ct",
  229. "deprecated",
  230. "des",
  231. "dgram",
  232. "dh",
  233. "dsa",
  234. "dso",
  235. "dtls",
  236. "dynamic[-_]engine",
  237. "ec",
  238. "ec2m",
  239. "ecdh",
  240. "ecdsa",
  241. "ec_nistp_64_gcc_128",
  242. "engine",
  243. "err", # Really???
  244. "heartbeats",
  245. "hmac",
  246. "hw(-.+)?",
  247. "idea",
  248. "jpake",
  249. "locking", # Really???
  250. "md2",
  251. "md4",
  252. "md5",
  253. "mdc2",
  254. "md[-_]ghost94",
  255. "nextprotoneg",
  256. "ocb",
  257. "ocsp",
  258. "poly1305",
  259. "posix-io",
  260. "psk",
  261. "rc2",
  262. "rc4",
  263. "rc5",
  264. "rdrand",
  265. "rfc3779",
  266. "rijndael", # Old AES name
  267. "rmd160",
  268. "rsa",
  269. "scrypt",
  270. "sct",
  271. "sctp",
  272. "seed",
  273. "sha",
  274. "shared",
  275. "sock",
  276. "srp",
  277. "srtp",
  278. "sse2",
  279. "ssl",
  280. "ssl-trace",
  281. "static-engine",
  282. "stdio",
  283. "store",
  284. "threads",
  285. "tls",
  286. "unit-test",
  287. "whirlpool",
  288. "zlib",
  289. "zlib-dynamic",
  290. );
  291. foreach my $proto ((@tls, @dtls))
  292. {
  293. push(@disablables, $proto);
  294. push(@disablables, "$proto-method");
  295. }
  296. # All of the following is disabled by default (RC5 was enabled before 0.9.8):
  297. my %disabled = ( # "what" => "comment" [or special keyword "experimental"]
  298. "ec_nistp_64_gcc_128" => "default",
  299. "egd" => "default",
  300. "jpake" => "experimental",
  301. "md2" => "default",
  302. "rc5" => "default",
  303. "sctp" => "default",
  304. "shared" => "default",
  305. "ssl-trace" => "default",
  306. "store" => "experimental",
  307. "unit-test" => "default",
  308. "zlib" => "default",
  309. "zlib-dynamic" => "default",
  310. "crypto-mdebug" => "default",
  311. );
  312. my @experimental = ();
  313. # Note: => pair form used for aesthetics, not to truly make a hash table
  314. my @disable_cascades = (
  315. # "what" => [ "cascade", ... ]
  316. sub { $config{processor} eq "386" }
  317. => [ "sse2" ],
  318. "ssl" => [ "ssl3" ],
  319. "ssl3-method" => [ "ssl3" ],
  320. "zlib" => [ "zlib-dynamic" ],
  321. "rijndael" => [ "aes" ],
  322. "des" => [ "mdc2" ],
  323. "ec" => [ "ecdsa", "ecdh" ],
  324. "psk" => [ "jpake" ],
  325. "dgram" => [ "dtls" ],
  326. "dtls" => [ @dtls ],
  327. # SSL 3.0, (D)TLS 1.0 and TLS 1.1 require MD5 and SHA
  328. "md5" => [ "ssl", "tls1", "tls1_1", "dtls1" ],
  329. "sha" => [ "ssl", "tls1", "tls1_1", "dtls1" ],
  330. # Additionally, SSL 3.0 requires either RSA or DSA+DH
  331. sub { $disabled{rsa}
  332. && ($disabled{dsa} || $disabled{dh}); }
  333. => [ "ssl" ],
  334. # (D)TLS 1.0 and TLS 1.1 also require either RSA or DSA+DH
  335. # or ECDSA + ECDH. (D)TLS 1.2 has this requirement as well.
  336. # (XXX: We don't support PSK-only builds).
  337. sub { $disabled{rsa}
  338. && ($disabled{dsa} || $disabled{dh})
  339. && ($disabled{ecdsa} || $disabled{ecdh}); }
  340. => [ "tls1", "tls1_1", "tls1_2",
  341. "dtls1", "dtls1_2" ],
  342. "tls" => [ @tls ],
  343. # SRP and HEARTBEATS require TLSEXT
  344. "tlsext" => [ "srp", "heartbeats" ],
  345. );
  346. # Avoid protocol support holes. Also disable all versions below N, if version
  347. # N is disabled while N+1 is enabled.
  348. #
  349. my @list = (reverse @tls);
  350. while ((my $first, my $second) = (shift @list, shift @list)) {
  351. last unless @list;
  352. push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
  353. => [ @list ] );
  354. unshift @list, $second;
  355. }
  356. my @list = (reverse @dtls);
  357. while ((my $first, my $second) = (shift @list, shift @list)) {
  358. last unless @list;
  359. push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
  360. => [ @list ] );
  361. unshift @list, $second;
  362. }
  363. # Construct the string of what $config{depflags} should look like with the defaults
  364. # from %disabled above. (we need this to see if we should advise the user
  365. # to run "make depend"):
  366. my $default_depflags = join(" ",
  367. map { my $x = $_; $x =~ tr{[a-z]-}{[A-Z]_}; "-DOPENSSL_NO_$x"; }
  368. grep { $disabled{$_} !~ /\(no-depflags\)$/ }
  369. sort keys %disabled);
  370. # Explicit "no-..." options will be collected in %disabled along with the defaults.
  371. # To remove something from %disabled, use "enable-foo" (unless it's experimental).
  372. # For symmetry, "disable-foo" is a synonym for "no-foo".
  373. # For features called "experimental" here, a more explicit "experimental-foo" is needed to enable.
  374. # We will collect such requests in @experimental.
  375. # To avoid accidental use of experimental features, applications will have to use -DOPENSSL_EXPERIMENTAL_FOO.
  376. my $no_sse2=0;
  377. &usage if ($#ARGV < 0);
  378. my $flags="";
  379. $config{depflags}="";
  380. $config{openssl_experimental_defines}=[];
  381. $config{openssl_api_defines}=[];
  382. $config{openssl_algorithm_defines}=[];
  383. $config{openssl_thread_defines}=[];
  384. $config{openssl_sys_defines}=[];
  385. $config{openssl_other_defines}=[];
  386. my $libs="";
  387. my $target="";
  388. $config{options}="";
  389. my $make_depend=0;
  390. my %withargs=();
  391. my $build_prefix = "release_";
  392. my @argvcopy=@ARGV;
  393. if (grep /^reconf(igure)?$/, @argvcopy) {
  394. if (-f "./configdata.pm") {
  395. my $file = "./configdata.pm";
  396. unless (my $return = do $file) {
  397. die "couldn't parse $file: $@" if $@;
  398. die "couldn't do $file: $!" unless defined $return;
  399. die "couldn't run $file" unless $return;
  400. }
  401. @argvcopy = defined($configdata::config{perlargv}) ?
  402. @{$configdata::config{perlargv}} : ();
  403. die "Incorrect data to reconfigure, please do a normal configuration\n"
  404. if (grep(/^reconf/,@argvcopy));
  405. $ENV{CROSS_COMPILE} = $configdata::config{cross_compile_prefix}
  406. if defined($configdata::config{cross_compile_prefix});
  407. $ENV{CROSS_COMPILE} = $configdata::config{cc}
  408. if defined($configdata::config{cc});
  409. print "Reconfiguring with: ", join(" ",@argvcopy), "\n";
  410. print " CROSS_COMPILE = ",$ENV{CROSS_COMPILE},"\n"
  411. if $ENV{CROSS_COMPILE};
  412. print " CC = ",$ENV{CC},"\n" if $ENV{CC};
  413. } elsif (open IN, "<Makefile") {
  414. #
  415. # THIS SECTION IS TEMPORARY, it helps transitioning from Makefile
  416. # centered information gathering the reading configdata.pm
  417. #
  418. while (<IN>) {
  419. chomp;
  420. if (/^CONFIGURE_ARGS=\s*(.*)\s*/) {
  421. # Older form, we split the string and hope for the best
  422. @argvcopy = split /\s+/, $_;
  423. die "Incorrect data to reconfigure, please do a normal configuration\n"
  424. if (grep(/^reconf/,@argvcopy));
  425. } elsif (/^CROSS_COMPILE=\s*(.*)/) {
  426. $ENV{CROSS_COMPILE}=$1;
  427. } elsif (/^CC=\s*(?:\$\(CROSS_COMPILE\))?(.*?)$/) {
  428. $ENV{CC}=$1;
  429. }
  430. }
  431. #
  432. # END OF TEMPORARY SECTION
  433. #
  434. } else {
  435. die "Insufficient data to reconfigure, please do a normal configuration\n";
  436. }
  437. }
  438. $config{perlargv} = [ @argvcopy ];
  439. my %unsupported_options = ();
  440. foreach (@argvcopy)
  441. {
  442. s /^-no-/no-/; # some people just can't read the instructions
  443. # rewrite some options in "enable-..." form
  444. s /^-?-?shared$/enable-shared/;
  445. s /^sctp$/enable-sctp/;
  446. s /^threads$/enable-threads/;
  447. s /^zlib$/enable-zlib/;
  448. s /^zlib-dynamic$/enable-zlib-dynamic/;
  449. if (/^(no|disable|enable|experimental)-(.+)$/)
  450. {
  451. my $word = $2;
  452. if (!grep { $word =~ /^${_}$/ } @disablables)
  453. {
  454. $unsupported_options{$_} = 1;
  455. next;
  456. }
  457. }
  458. if (/^no-(.+)$/ || /^disable-(.+)$/)
  459. {
  460. if (!($disabled{$1} eq "experimental"))
  461. {
  462. foreach my $proto ((@tls, @dtls))
  463. {
  464. if ($1 eq "$proto-method")
  465. {
  466. $disabled{"$proto"} = "option($proto-method)";
  467. last;
  468. }
  469. }
  470. if ($1 eq "dtls")
  471. {
  472. foreach my $proto (@dtls)
  473. {
  474. $disabled{$proto} = "option(dtls)";
  475. }
  476. }
  477. elsif ($1 eq "ssl")
  478. {
  479. # Last one of its kind
  480. $disabled{"ssl3"} = "option(ssl)";
  481. }
  482. elsif ($1 eq "tls")
  483. {
  484. # XXX: Tests will fail if all SSL/TLS
  485. # protocols are disabled.
  486. foreach my $proto (@tls)
  487. {
  488. $disabled{$proto} = "option(tls)";
  489. }
  490. }
  491. else
  492. {
  493. $disabled{$1} = "option";
  494. }
  495. }
  496. }
  497. elsif (/^enable-(.+)$/ || /^experimental-(.+)$/)
  498. {
  499. my $algo = $1;
  500. if ($disabled{$algo} eq "experimental")
  501. {
  502. die "You are requesting an experimental feature; please say 'experimental-$algo' if you are sure\n"
  503. unless (/^experimental-/);
  504. push @experimental, $algo;
  505. }
  506. delete $disabled{$algo};
  507. $threads = 1 if ($algo eq "threads");
  508. }
  509. elsif (/^--strict-warnings$/)
  510. {
  511. $strict_warnings = 1;
  512. }
  513. elsif (/^--debug$/)
  514. {
  515. $build_prefix = "debug_";
  516. }
  517. elsif (/^--release$/)
  518. {
  519. $build_prefix = "release_";
  520. }
  521. elsif (/^386$/)
  522. { $config{processor}=386; }
  523. elsif (/^fips$/)
  524. {
  525. $config{fips}=1;
  526. }
  527. elsif (/^rsaref$/)
  528. {
  529. # No RSAref support any more since it's not needed.
  530. # The check for the option is there so scripts aren't
  531. # broken
  532. }
  533. elsif (/^nofipscanistercheck$/)
  534. {
  535. $config{fips} = 1;
  536. $nofipscanistercheck = 1;
  537. }
  538. elsif (/^[-+]/)
  539. {
  540. if (/^--prefix=(.*)$/)
  541. {
  542. $config{prefix}=$1;
  543. }
  544. elsif (/^--api=(.*)$/)
  545. {
  546. $config{api}=$1;
  547. }
  548. elsif (/^--libdir=(.*)$/)
  549. {
  550. $config{libdir}=$1;
  551. }
  552. elsif (/^--openssldir=(.*)$/)
  553. {
  554. $config{openssldir}=$1;
  555. }
  556. elsif (/^--install.prefix=(.*)$/)
  557. {
  558. $config{install_prefix}=$1;
  559. }
  560. elsif (/^--with-zlib-lib=(.*)$/)
  561. {
  562. $withargs{"zlib-lib"}=$1;
  563. }
  564. elsif (/^--with-zlib-include=(.*)$/)
  565. {
  566. $withargs{"zlib-include"}="-I$1";
  567. }
  568. elsif (/^--with-fipslibdir=(.*)$/)
  569. {
  570. $config{fipslibdir}="$1/";
  571. }
  572. elsif (/^--with-baseaddr=(.*)$/)
  573. {
  574. $config{baseaddr}="$1";
  575. }
  576. elsif (/^--cross-compile-prefix=(.*)$/)
  577. {
  578. $config{cross_compile_prefix}=$1;
  579. }
  580. elsif (/^--config=(.*)$/)
  581. {
  582. read_config $1;
  583. }
  584. elsif (/^-[lL](.*)$/ or /^-Wl,/)
  585. {
  586. $libs.=$_." ";
  587. }
  588. else # common if (/^[-+]/), just pass down...
  589. {
  590. $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
  591. $flags.=$_." ";
  592. }
  593. }
  594. elsif ($_ =~ /^([^:]+):(.+)$/)
  595. {
  596. eval "\$table{\$1} = \"$2\""; # allow $xxx constructs in the string
  597. $target=$1;
  598. }
  599. else
  600. {
  601. die "target already defined - $target (offending arg: $_)\n" if ($target ne "");
  602. $target=$_;
  603. }
  604. unless ($_ eq $target || /^no-/ || /^disable-/)
  605. {
  606. # "no-..." follows later after implied disactivations
  607. # have been derived. (Don't take this too seroiusly,
  608. # we really only write OPTIONS to the Makefile out of
  609. # nostalgia.)
  610. if ($config{options} eq "")
  611. { $config{options} = $_; }
  612. else
  613. { $config{options} .= " ".$_; }
  614. }
  615. if (defined($config{api}) && !exists $apitable->{$config{api}}) {
  616. die "***** Unsupported api compatibility level: $config{api}\n",
  617. }
  618. if (keys %unsupported_options)
  619. {
  620. die "***** Unsupported options: ",
  621. join(", ", keys %unsupported_options), "\n";
  622. }
  623. }
  624. if ($config{fips})
  625. {
  626. delete $disabled{"shared"} if ($disabled{"shared"} =~ /^default/);
  627. }
  628. else
  629. {
  630. @{$config{dirs}} = grep !/^fips$/, @{$config{dirs}};
  631. }
  632. my @tocheckfor = (keys %disabled);
  633. while (@tocheckfor) {
  634. my %new_tocheckfor = ();
  635. my @cascade_copy = (@disable_cascades);
  636. while (@cascade_copy) {
  637. my ($test, $descendents) = (shift @cascade_copy, shift @cascade_copy);
  638. if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) {
  639. map {
  640. $new_tocheckfor{$_} => 1; $disabled{$_} = "forced";
  641. } grep { !defined($disabled{$_}) } @$descendents;
  642. }
  643. }
  644. @tocheckfor = (keys %new_tocheckfor);
  645. }
  646. if ($target eq "TABLE") {
  647. foreach (sort keys %table) {
  648. print_table_entry($_, "TABLE");
  649. }
  650. exit 0;
  651. }
  652. if ($target eq "LIST") {
  653. foreach (sort keys %table) {
  654. print $_,"\n" unless $table{$_}->{template};
  655. }
  656. exit 0;
  657. }
  658. if ($target eq "HASH") {
  659. print "%table = (\n";
  660. foreach (sort keys %table) {
  661. print_table_entry($_, "HASH");
  662. }
  663. exit 0;
  664. }
  665. # Backward compatibility?
  666. if ($target =~ m/^CygWin32(-.*)$/) {
  667. $target = "Cygwin".$1;
  668. }
  669. foreach (sort (keys %disabled))
  670. {
  671. $config{options} .= " no-$_";
  672. printf " no-%-12s %-10s", $_, "[$disabled{$_}]";
  673. if (/^dso$/)
  674. { $no_dso = 1; }
  675. elsif (/^threads$/)
  676. { $no_threads = 1; }
  677. elsif (/^shared$/)
  678. { $config{no_shared} = 1; }
  679. elsif (/^zlib$/)
  680. { $zlib = 0; }
  681. elsif (/^static-engine$/)
  682. { }
  683. elsif (/^zlib-dynamic$/)
  684. { }
  685. elsif (/^sse2$/)
  686. { $no_sse2 = 1; }
  687. elsif (/^engine$/)
  688. { @{$config{dirs}} = grep !/^engine$/, @{$config{dirs}}; }
  689. else
  690. {
  691. my ($ALGO, $algo);
  692. ($ALGO = $algo = $_) =~ tr/[\-a-z]/[_A-Z]/;
  693. if (/^asm$/ || /^err$/ || /^hw$/ || /^hw-/)
  694. {
  695. push @{$config{openssl_other_defines}}, "OPENSSL_NO_$ALGO";
  696. print " OPENSSL_NO_$ALGO";
  697. if (/^err$/) { $flags .= "-DOPENSSL_NO_ERR "; }
  698. elsif (/^asm$/) { $no_asm = 1; }
  699. }
  700. else
  701. {
  702. ($ALGO,$algo) = ("RMD160","rmd160") if ($algo eq "ripemd");
  703. push @{$config{openssl_algorithm_defines}}, "OPENSSL_NO_$ALGO";
  704. $config{depflags} .= " -DOPENSSL_NO_$ALGO";
  705. print " OPENSSL_NO_$ALGO";
  706. # fix-up crypto/directory name(s)
  707. $algo="whrlpool" if $algo eq "whirlpool";
  708. $algo="ripemd" if $algo eq "rmd160";
  709. @{$config{sdirs}} = grep { $_ ne $algo} @{$config{sdirs}};
  710. print " (skip dir)";
  711. }
  712. }
  713. print "\n";
  714. }
  715. my $exp_cflags = "";
  716. foreach (sort @experimental)
  717. {
  718. my $ALGO;
  719. ($ALGO = $_) =~ tr/[a-z]/[A-Z]/;
  720. # opensslconf.h will set OPENSSL_NO_... unless OPENSSL_EXPERIMENTAL_... is defined
  721. push @{$config{openssl_experimental_defines}}, "OPENSSL_NO_$ALGO";
  722. $exp_cflags .= " -DOPENSSL_EXPERIMENTAL_$ALGO";
  723. }
  724. print "Configuring for $target\n";
  725. # Support for legacy targets having a name starting with 'debug-'
  726. my ($d, $t) = $target =~ m/^(debug-)?(.*)$/;
  727. if ($d) {
  728. $build_prefix = "debug_";
  729. # If we do not find debug-foo in the table, the target is set to foo.
  730. if (!$table{$target}) {
  731. $target = $t;
  732. }
  733. }
  734. $config{target} = $target;
  735. delete $table{$base_target}->{template}; # or the next test will fail.
  736. my %target = ( %{$table{$base_target}}, resolve_config($target) );
  737. &usage if (!%target || $target{template});
  738. $target{exe_extension}="";
  739. $target{exe_extension}=".exe" if ($config{target} eq "Cygwin" || $config{target} eq "DJGPP" || $config{target} =~ /^mingw/);
  740. $target{exe_extension}=".nlm" if ($config{target} =~ /netware/);
  741. $target{exe_extension}=".pm" if ($config{target} =~ /vos/);
  742. $default_ranlib = which("ranlib") || "true";
  743. $config{perl} = $ENV{'PERL'} || which("perl5") || which("perl") || "perl";
  744. my $make = $ENV{'MAKE'} || "make";
  745. $config{cross_compile_prefix} = $ENV{'CROSS_COMPILE'}
  746. if $config{cross_compile_prefix} eq "";
  747. $config{prefix} = "/usr/local" if !$config{prefix};
  748. $config{openssldir} = "ssl" if !$config{openssldir};
  749. $config{openssldir} = catdir($config{prefix}, $config{openssldir})
  750. unless file_name_is_absolute($config{openssldir});
  751. # Allow environment CC to override compiler...
  752. $target{cc} = $ENV{CC} || $target{cc};
  753. # For cflags and lflags, add the debug_ or release_ attributes
  754. # Do it in such a way that no spurious space is appended (hence the grep).
  755. $config{cflags} = join(" ",
  756. grep { $_ ne "" } ($target{cflags},
  757. $target{$build_prefix."cflags"}));
  758. $config{lflags} = join(" ",
  759. grep { $_ ne "" } ($target{lflags},
  760. $target{$build_prefix."lflags"}));
  761. $target{ranlib} = $ENV{'RANLIB'} || $target{ranlib} || $default_ranlib;
  762. $target{ar} = $ENV{'AR'} || "ar";
  763. $target{arflags} = "" if !defined($target{arflags});
  764. $target{nm} = "nm";
  765. # Make sure build_scheme is consistent.
  766. $target{build_scheme} = [ $target{build_scheme} ]
  767. if ref($target{build_scheme}) ne "ARRAY";
  768. # if $config{prefix}/lib$target{multilib} is not an existing directory, then
  769. # assume that it's not searched by linker automatically, in
  770. # which case adding $target{multilib} suffix causes more grief than
  771. # we're ready to tolerate, so don't...
  772. $target{multilib}="" if !-d "$config{prefix}/lib$target{multilib}";
  773. $config{libdir}="lib$target{multilib}" if $config{libdir} eq "";
  774. $config{enginesdir}=$config{prefix} . "/" . $config{libdir} . "/engines";
  775. $config{cflags} .= "$exp_cflags";
  776. # '%' in $config{lflags} is used to split flags to "pre-" and post-flags
  777. my ($pre,$post)=split('%',$config{lflags});
  778. if (defined($post)) { $config{prelflags}=$pre; $config{lflags}=$post; }
  779. else { $config{prelflags}=""; $config{lflags}=$pre; }
  780. if ($target =~ /^mingw/ && `$target{cc} --target-help 2>&1` !~ m/-mno-cygwin/m)
  781. {
  782. $config{cflags} =~ s/-mno-cygwin\s*//;
  783. $target{shared_ldflag} =~ s/-mno-cygwin\s*//;
  784. }
  785. if ($target =~ /linux.*-mips/ && !$no_asm && $flags !~ /-m(ips|arch=)/) {
  786. # minimally required architecture flags for assembly modules
  787. $config{cflags}="-mips2 $config{cflags}" if ($target =~ /mips32/);
  788. $config{cflags}="-mips3 $config{cflags}" if ($target =~ /mips64/);
  789. }
  790. my $no_shared_warn=0;
  791. my $no_user_cflags=0;
  792. if ($flags ne "") { $config{cflags}="$flags$config{cflags}"; }
  793. else { $no_user_cflags=1; }
  794. # The DSO code currently always implements all functions so that no
  795. # applications will have to worry about that from a compilation point
  796. # of view. However, the "method"s may return zero unless that platform
  797. # has support compiled in for them. Currently each method is enabled
  798. # by a define "DSO_<name>" ... we translate the "dso_scheme" config
  799. # string entry into using the following logic;
  800. my $dso_cflags;
  801. if (!$no_dso && $target{dso_scheme} ne "")
  802. {
  803. $target{dso_scheme} =~ tr/[a-z]/[A-Z]/;
  804. if ($target{dso_scheme} eq "DLFCN")
  805. {
  806. $dso_cflags = "-DDSO_DLFCN -DHAVE_DLFCN_H";
  807. }
  808. elsif ($target{dso_scheme} eq "DLFCN_NO_H")
  809. {
  810. $dso_cflags = "-DDSO_DLFCN";
  811. }
  812. else
  813. {
  814. $dso_cflags = "-DDSO_$target{dso_scheme}";
  815. }
  816. $config{cflags} = "$dso_cflags $config{cflags}";
  817. }
  818. my $thread_cflags;
  819. my @thread_defines;
  820. if ($target{thread_cflag} ne "(unknown)" && !$no_threads)
  821. {
  822. # If we know how to do it, support threads by default.
  823. $threads = 1;
  824. }
  825. if ($target{thread_cflag} eq "(unknown)" && $threads)
  826. {
  827. # If the user asked for "threads", [s]he is also expected to
  828. # provide any system-dependent compiler options that are
  829. # necessary.
  830. if ($no_user_cflags)
  831. {
  832. print "You asked for multi-threading support, but didn't\n";
  833. print "provide any system-specific compiler options\n";
  834. exit(1);
  835. }
  836. $thread_cflags="-DOPENSSL_THREADS $config{cflags}" ;
  837. push @thread_defines, "OPENSSL_THREADS";
  838. }
  839. else
  840. {
  841. $thread_cflags="-DOPENSSL_THREADS $target{thread_cflag} $config{cflags}";
  842. push @thread_defines, "OPENSSL_THREADS";
  843. # my $def;
  844. # foreach $def (split ' ',$target{thread_cflag})
  845. # {
  846. # if ($def =~ s/^-D// && $def !~ /^_/)
  847. # {
  848. # push @thread_defines, "$def";
  849. # }
  850. # }
  851. }
  852. $config{lflags}="$libs$config{lflags}" if ($libs ne "");
  853. if ($no_asm)
  854. {
  855. $config{cflags}=~s/-D[BL]_ENDIAN// if ($config{fips});
  856. $thread_cflags=~s/-D[BL]_ENDIAN// if ($config{fips});
  857. }
  858. if ($threads)
  859. {
  860. $config{cflags}=$thread_cflags;
  861. push @{$config{openssl_thread_defines}}, @thread_defines;
  862. }
  863. if ($zlib)
  864. {
  865. $config{cflags} = "-DZLIB $config{cflags}";
  866. if (defined($disabled{"zlib-dynamic"}))
  867. {
  868. if (defined($withargs{"zlib-lib"}))
  869. {
  870. $config{lflags} .= " -L" . $withargs{"zlib-lib"} . " -lz";
  871. }
  872. else
  873. {
  874. $config{lflags} .= " -lz";
  875. }
  876. }
  877. else
  878. {
  879. $config{cflags} = "-DZLIB_SHARED $config{cflags}";
  880. }
  881. }
  882. # With "deprecated" disable all deprecated features.
  883. if (defined($disabled{"deprecated"})) {
  884. $config{api} = $maxapi;
  885. }
  886. if ($target{shared_target} eq "")
  887. {
  888. $no_shared_warn = 1 if !$config{no_shared} && !$config{fips};
  889. $config{no_shared} = 1;
  890. }
  891. if (!$config{no_shared})
  892. {
  893. if ($target{shared_cflag} ne "")
  894. {
  895. $config{cflags} = "$target{shared_cflag} -DOPENSSL_PIC $config{cflags}";
  896. }
  897. }
  898. if ($target{build_scheme}->[0] ne "mk1mf")
  899. {
  900. # add {no-}static-engine to options to allow mkdef.pl to work without extra arguments
  901. if ($config{no_shared})
  902. {
  903. push @{$config{openssl_other_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE";
  904. $config{options}.=" static-engine";
  905. }
  906. else
  907. {
  908. push @{$config{openssl_other_defines}}, "OPENSSL_NO_STATIC_ENGINE";
  909. $config{options}.=" no-static-engine";
  910. }
  911. }
  912. #
  913. # Platform fix-ups
  914. #
  915. if ($target =~ /-icc$/) # Intel C compiler
  916. {
  917. my $iccver=0;
  918. if (open(FD,"$target{cc} -V 2>&1 |"))
  919. {
  920. while(<FD>) { $iccver=$1 if (/Version ([0-9]+)\./); }
  921. close(FD);
  922. }
  923. if ($iccver>=8)
  924. {
  925. $config{cflags}=~s/-KPIC/-fPIC/;
  926. # Eliminate unnecessary dependency from libirc.a. This is
  927. # essential for shared library support, as otherwise
  928. # apps/openssl can end up in endless loop upon startup...
  929. $config{cflags}.=" -Dmemcpy=__builtin_memcpy -Dmemset=__builtin_memset";
  930. }
  931. if ($iccver>=9)
  932. {
  933. $config{lflags}.=" -i-static";
  934. $config{lflags}=~s/-no_cpprt/-no-cpprt/;
  935. }
  936. if ($iccver>=10)
  937. {
  938. $config{lflags}=~s/-i-static/-static-intel/;
  939. }
  940. if ($iccver>=11)
  941. {
  942. $config{cflags}.=" -no-intel-extensions"; # disable Cilk
  943. $config{lflags}=~s/-no-cpprt/-no-cxxlib/;
  944. }
  945. }
  946. # Unlike other OSes (like Solaris, Linux, Tru64, IRIX) BSD run-time
  947. # linkers (tested OpenBSD, NetBSD and FreeBSD) "demand" RPATH set on
  948. # .so objects. Apparently application RPATH is not global and does
  949. # not apply to .so linked with other .so. Problem manifests itself
  950. # when libssl.so fails to load libcrypto.so. One can argue that we
  951. # should engrave this into Makefile.shared rules or into BSD-* config
  952. # lines above. Meanwhile let's try to be cautious and pass -rpath to
  953. # linker only when --prefix is not /usr.
  954. if ($target =~ /^BSD-/)
  955. {
  956. $target{shared_ldflag}.=" -Wl,-rpath,\$\$(LIBRPATH)" if ($config{prefix} !~ m|^/usr[/]*$|);
  957. }
  958. if ($target{sys_id} ne "")
  959. {
  960. #$config{cflags}="-DOPENSSL_SYS_$target{sys_id} $config{cflags}";
  961. push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}";
  962. }
  963. if ($target{ranlib} eq "")
  964. {
  965. $target{ranlib} = $default_ranlib;
  966. }
  967. if (!$no_asm) {
  968. $target{cpuid_obj}=$table{BASE}->{cpuid_obj} if ($config{processor} eq "386");
  969. $target{cpuid_obj}.=" uplink.o uplink-x86.o" if ($config{cflags} =~ /-DOPENSSL_USE_APPLINK/);
  970. $target{bn_obj} =~ s/\w+-gf2m.o// if (defined($disabled{ec2m}));
  971. # bn-586 is the only one implementing bn_*_part_words
  972. $config{cflags}.=" -DOPENSSL_BN_ASM_PART_WORDS" if ($target{bn_obj} =~ /bn-586/);
  973. $config{cflags}.=" -DOPENSSL_IA32_SSE2" if (!$no_sse2 && $target{bn_obj} =~ /86/);
  974. $config{cflags}.=" -DOPENSSL_BN_ASM_MONT" if ($target{bn_obj} =~ /-mont/);
  975. $config{cflags}.=" -DOPENSSL_BN_ASM_MONT5" if ($target{bn_obj} =~ /-mont5/);
  976. $config{cflags}.=" -DOPENSSL_BN_ASM_GF2m" if ($target{bn_obj} =~ /-gf2m/);
  977. if ($config{fips}) {
  978. push @{$config{openssl_other_defines}}, "OPENSSL_FIPS";
  979. }
  980. if ($target{sha1_obj} =~ /\.o$/) {
  981. $config{cflags}.=" -DSHA1_ASM" if ($target{sha1_obj} =~ /sx86/ || $target{sha1_obj} =~ /sha1/);
  982. $config{cflags}.=" -DSHA256_ASM" if ($target{sha1_obj} =~ /sha256/);
  983. $config{cflags}.=" -DSHA512_ASM" if ($target{sha1_obj} =~ /sha512/);
  984. if ($target{sha1_obj} =~ /sse2/) {
  985. if ($no_sse2) {
  986. $target{sha1_obj} =~ s/\S*sse2\S+//;
  987. } elsif ($config{cflags} !~ /OPENSSL_IA32_SSE2/) {
  988. $config{cflags}.=" -DOPENSSL_IA32_SSE2";
  989. }
  990. }
  991. }
  992. if ($target{md5_obj} =~ /\.o$/) {
  993. $config{cflags}.=" -DMD5_ASM";
  994. }
  995. $target{cast_obj}=$table{BASE}->{cast_obj} if (!$config{no_shared}); # CAST assembler is not PIC
  996. if ($target{rmd160_obj} =~ /\.o$/) {
  997. $config{cflags}.=" -DRMD160_ASM";
  998. }
  999. if ($target{aes_obj} =~ /\.o$/) {
  1000. $config{cflags}.=" -DAES_ASM" if ($target{aes_obj} =~ m/\baes-/);;
  1001. # aes-ctr.o is not a real file, only indication that assembler
  1002. # module implements AES_ctr32_encrypt...
  1003. $config{cflags}.=" -DAES_CTR_ASM" if ($target{aes_obj} =~ s/\s*aes-ctr\.o//);
  1004. # aes-xts.o indicates presence of AES_xts_[en|de]crypt...
  1005. $config{cflags}.=" -DAES_XTS_ASM" if ($target{aes_obj} =~ s/\s*aes-xts\.o//);
  1006. $target{aes_obj} =~ s/\s*(vpaes|aesni)-x86\.o//g if ($no_sse2);
  1007. $config{cflags}.=" -DVPAES_ASM" if ($target{aes_obj} =~ m/vpaes/);
  1008. $config{cflags}.=" -DBSAES_ASM" if ($target{aes_obj} =~ m/bsaes/);
  1009. }
  1010. if ($target{wp_obj} =~ /mmx/ && $config{processor} eq "386") {
  1011. $target{wp_obj}=$table{BASE}->{wp_obj};
  1012. } elsif (!$disabled{"whirlpool"}) {
  1013. $config{cflags}.=" -DWHIRLPOOL_ASM";
  1014. }
  1015. if ($target{modes_obj} =~ /ghash-/) {
  1016. $config{cflags}.=" -DGHASH_ASM";
  1017. }
  1018. if ($target{ec_obj} =~ /ecp_nistz256/) {
  1019. $config{cflags}.=" -DECP_NISTZ256_ASM";
  1020. }
  1021. if ($target{poly1305_obj} =~ /\.o$/) {
  1022. $config{cflags}.=" -DPOLY1305_ASM";
  1023. }
  1024. }
  1025. $config{makedepprog} = "makedepend";
  1026. if ($target{cc} eq "gcc" || ($target{cc} eq 'cc' && $config{target} =~ /darwin/)) {
  1027. $config{makedepprog} = $target{cc};
  1028. }
  1029. $config{depflags} =~ s/^\s*//;
  1030. # Deal with bn_ops ###################################################
  1031. $config{des_ptr} =0;
  1032. $config{des_risc1} =0;
  1033. $config{des_risc2} =0;
  1034. $config{des_unroll} =0;
  1035. $config{bn_ll} =0;
  1036. $config{rc4_idx} =0;
  1037. $config{bf_ptr} =0;
  1038. $config{export_var_as_fn} =0;
  1039. my $def_int="unsigned int";
  1040. $config{rc4_int} =$def_int;
  1041. $config{rc4_chunk} ="";
  1042. $config{md2_int} =$def_int;
  1043. $config{idea_int} =$def_int;
  1044. $config{rc2_int} =$def_int;
  1045. ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})=(0,0,1,0,0);
  1046. $config{des_int} = "unsigned long";
  1047. foreach (sort split(/\s+/,$target{bn_ops})) {
  1048. $config{des_ptr}=1 if /DES_PTR/;
  1049. $config{des_risc1}=1 if /DES_RISC1/;
  1050. $config{des_risc2}=1 if /DES_RISC2/;
  1051. $config{des_unroll}=1 if /DES_UNROLL/;
  1052. $config{des_int}="unsigned int" if /DES_INT/;
  1053. $config{bn_ll}=1 if /BN_LLONG/;
  1054. $config{rc4_int}="unsigned char" if /RC4_CHAR/;
  1055. $config{rc4_int}="unsigned long" if /RC4_LONG/;
  1056. $config{rc4_idx}=1 if /RC4_INDEX/;
  1057. $config{rc4_chunk}="unsigned long" if /RC4_CHUNK/;
  1058. $config{rc4_chunk}="unsigned long long" if /RC4_CHUNK_LL/;
  1059. $config{md2_int}="unsigned char" if /MD2_CHAR/;
  1060. $config{md2_int}="unsigned long" if /MD2_LONG/;
  1061. $config{idea_int}="unsigned char" if /IDEA_CHAR/;
  1062. $config{idea_int}="unsigned long" if /IDEA_LONG/;
  1063. $config{rc2_int}="unsigned char" if /RC2_CHAR/;
  1064. $config{rc2_int}="unsigned long" if /RC2_LONG/;
  1065. $config{bf_ptr}=1 if $_ eq "BF_PTR";
  1066. $config{bf_ptr}=2 if $_ eq "BF_PTR2";
  1067. ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
  1068. =(0,1,0,0,0) if /SIXTY_FOUR_BIT/;
  1069. ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
  1070. =(1,0,0,0,0) if /SIXTY_FOUR_BIT_LONG/;
  1071. ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
  1072. =(0,0,1,0,0) if /THIRTY_TWO_BIT/;
  1073. ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
  1074. =(0,0,0,1,0) if /SIXTEEN_BIT/;
  1075. ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
  1076. =(0,0,0,0,1) if /EIGHT_BIT/;
  1077. $config{export_var_as_fn}=1 if /EXPORT_VAR_AS_FN/;
  1078. }
  1079. # Hack cflags for better warnings (dev option) #######################
  1080. # "Stringify" the C flags string. This permits it to be made part of a string
  1081. # and works as well on command lines.
  1082. $config{cflags} =~ s/([\\\"])/\\\1/g;
  1083. if (defined($config{api})) {
  1084. $config{openssl_api_defines} = [ "OPENSSL_MIN_API=".$apitable->{$config{api}} ];
  1085. my $apiflag = sprintf("-DOPENSSL_API_COMPAT=%s", $apitable->{$config{api}});
  1086. $default_depflags .= " $apiflag";
  1087. $config{cflags} .= " $apiflag";
  1088. }
  1089. my $ecc = $target{cc};
  1090. $ecc = "clang" if `$target{cc} --version 2>&1` =~ /clang/;
  1091. if ($strict_warnings)
  1092. {
  1093. my $wopt;
  1094. die "ERROR --strict-warnings requires gcc or clang" unless ($ecc =~ /gcc(-\d(\.\d)*)?$/ or $ecc =~ /clang$/);
  1095. foreach $wopt (split /\s+/, $gcc_devteam_warn)
  1096. {
  1097. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
  1098. }
  1099. if ($ecc eq "clang")
  1100. {
  1101. foreach $wopt (split /\s+/, $clang_devteam_warn)
  1102. {
  1103. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
  1104. }
  1105. }
  1106. if ($target !~ /^mingw/)
  1107. {
  1108. foreach $wopt (split /\s+/, $memleak_devteam_backtrace)
  1109. {
  1110. $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
  1111. }
  1112. if ($target =~ /^BSD-/)
  1113. {
  1114. $config{lflags} .= " -lexecinfo";
  1115. }
  1116. }
  1117. }
  1118. # Write down our configuration where it fits #########################
  1119. open(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n";
  1120. print OUT <<"EOF";
  1121. package configdata;
  1122. use strict;
  1123. use warnings;
  1124. use Exporter;
  1125. #use vars qw(\@ISA \@EXPORT);
  1126. our \@ISA = qw(Exporter);
  1127. our \@EXPORT = qw(\%config \%target %withargs);
  1128. EOF
  1129. print OUT "our %config = (\n";
  1130. foreach (sort keys %config) {
  1131. if (ref($config{$_}) eq "ARRAY") {
  1132. print OUT " ", $_, " => [ ", join(", ",
  1133. map { quotify("perl", $_) }
  1134. @{$config{$_}}), " ],\n";
  1135. } else {
  1136. print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n"
  1137. }
  1138. }
  1139. print OUT <<"EOF";
  1140. );
  1141. EOF
  1142. print OUT "our %target = (\n";
  1143. foreach (sort keys %target) {
  1144. if (ref($target{$_}) eq "ARRAY") {
  1145. print OUT " ", $_, " => [ ", join(", ",
  1146. map { quotify("perl", $_) }
  1147. @{$target{$_}}), " ],\n";
  1148. } else {
  1149. print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n"
  1150. }
  1151. }
  1152. print OUT <<"EOF";
  1153. );
  1154. EOF
  1155. print OUT "our \%available_protocols = (\n";
  1156. print OUT " tls => [ ", join(", ", map { quotify("perl", $_) } @tls), " ],\n";
  1157. print OUT " dtls => [ ", join(", ", map { quotify("perl", $_) } @dtls), " ],\n";
  1158. print OUT <<"EOF";
  1159. );
  1160. EOF
  1161. print OUT "our \%disabled = (\n";
  1162. foreach (sort keys %disabled) {
  1163. print OUT " ", quotify("perl", $_), " => ", quotify("perl", $disabled{$_}), ",\n";
  1164. }
  1165. print OUT <<"EOF";
  1166. );
  1167. EOF
  1168. print OUT "our %withargs = (\n";
  1169. foreach (sort keys %withargs) {
  1170. if (ref($withargs{$_}) eq "ARRAY") {
  1171. print OUT " ", $_, " => [ ", join(", ",
  1172. map { quotify("perl", $_) }
  1173. @{$withargs{$_}}), " ],\n";
  1174. } else {
  1175. print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n"
  1176. }
  1177. }
  1178. print OUT <<"EOF";
  1179. );
  1180. 1;
  1181. EOF
  1182. close(OUT);
  1183. print "IsMK1MF =", ($target{build_scheme}->[0] eq "mk1mf" ? "yes" : "no"), "\n";
  1184. print "CC =$target{cc}\n";
  1185. print "CFLAG =$config{cflags}\n";
  1186. print "EX_LIBS =$config{lflags}\n";
  1187. print "CPUID_OBJ =$target{cpuid_obj}\n";
  1188. print "BN_ASM =$target{bn_obj}\n";
  1189. print "EC_ASM =$target{ec_obj}\n";
  1190. print "DES_ENC =$target{des_obj}\n";
  1191. print "AES_ENC =$target{aes_obj}\n";
  1192. print "BF_ENC =$target{bf_obj}\n";
  1193. print "CAST_ENC =$target{cast_obj}\n";
  1194. print "RC4_ENC =$target{rc4_obj}\n";
  1195. print "RC5_ENC =$target{rc5_obj}\n";
  1196. print "MD5_OBJ_ASM =$target{md5_obj}\n";
  1197. print "SHA1_OBJ_ASM =$target{sha1_obj}\n";
  1198. print "RMD160_OBJ_ASM=$target{rmd160_obj}\n";
  1199. print "CMLL_ENC =$target{cmll_obj}\n";
  1200. print "MODES_OBJ =$target{modes_obj}\n";
  1201. print "PADLOCK_OBJ =$target{padlock_obj}\n";
  1202. print "CHACHA_ENC =$target{chacha_obj}\n";
  1203. print "POLY1305_OBJ =$target{poly1305_obj}\n";
  1204. print "PROCESSOR =$config{processor}\n";
  1205. print "RANLIB =$target{ranlib}\n";
  1206. print "ARFLAGS =$target{arflags}\n";
  1207. print "PERL =$config{perl}\n";
  1208. print "\n";
  1209. print "SIXTY_FOUR_BIT_LONG mode\n" if $config{b64l};
  1210. print "SIXTY_FOUR_BIT mode\n" if $config{b64};
  1211. print "THIRTY_TWO_BIT mode\n" if $config{b32};
  1212. print "SIXTEEN_BIT mode\n" if $config{b16};
  1213. print "EIGHT_BIT mode\n" if $config{b8};
  1214. print "DES_PTR used\n" if $config{des_ptr};
  1215. print "DES_RISC1 used\n" if $config{des_risc1};
  1216. print "DES_RISC2 used\n" if $config{des_risc2};
  1217. print "DES_UNROLL used\n" if $config{des_unroll};
  1218. print "DES_INT used\n" if $config{des_int} =~ / int$/;
  1219. print "BN_LLONG mode\n" if $config{bn_ll};
  1220. print "RC4 uses $config{rc4_int}\n" if $config{rc4_int} != $def_int;
  1221. print "RC4_INDEX mode\n" if $config{rc4_idx};
  1222. print "RC4_CHUNK is undefined\n" unless $config{rc4_chunk};
  1223. print "RC4_CHUNK is $config{rc4_chunk}\n" if $config{rc4_chunk};
  1224. print "MD2 uses $config{md2_int}\n" if $config{md2_int} != $def_int;
  1225. print "IDEA uses $config{idea_int}\n" if $config{idea_int} != $def_int;
  1226. print "RC2 uses $config{rc2_int}\n" if $config{rc2_int} != $def_int;
  1227. print "BF_PTR used\n" if $config{bf_ptr} == 1;
  1228. print "BF_PTR2 used\n" if $config{bf_ptr} == 2;
  1229. run_dofile("$Makefile.in","$Makefile");
  1230. run_dofile("include/openssl/opensslconf.h.in", "include/openssl/opensslconf.h");
  1231. foreach my $alg ( 'bf', 'bn', 'des', 'rc4' ) {
  1232. run_dofile("crypto/include/internal/${alg}_conf.h.in",
  1233. "crypto/include/internal/${alg}_conf.h");
  1234. }
  1235. # Copy all Makefile.in to Makefile (except top-level)
  1236. use File::Find;
  1237. use IO::File;
  1238. find(sub {
  1239. return if ($_ ne "Makefile.in" || $File::Find::dir eq ".");
  1240. my $in = IO::File->new($_, "r") or
  1241. die sprintf "Error reading Makefile.in in %s: !$\n",
  1242. $File::Find::dir;
  1243. my $out = IO::File->new("Makefile", "w") or
  1244. die sprintf "Error writing Makefile in %s: !$\n",
  1245. $File::Find::dir;
  1246. print $out "# Generated from $_, do not edit\n";
  1247. while (my $line = <$in>) { print $out $line }
  1248. $in->close() or
  1249. die sprintf "Error reading Makefile.in in %s: !$\n",
  1250. $File::Find::dir;
  1251. $out->close() or
  1252. die sprintf "Error writing Makefile in %s: !$\n",
  1253. $File::Find::dir;
  1254. }, ".");
  1255. my %builders = (
  1256. unixmake => sub {
  1257. my $make_command = "$make PERL=\'$config{perl}\'";
  1258. my $make_targets = "";
  1259. $make_targets .= " depend" if $config{depflags} ne $default_depflags && $make_depend;
  1260. (system $make_command.$make_targets) == 0 or die "make $make_targets failed"
  1261. if $make_targets ne "";
  1262. if ($config{depflags} ne $default_depflags && !$make_depend) {
  1263. $warn_make_depend++;
  1264. }
  1265. },
  1266. mk1mf => sub {
  1267. open (OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
  1268. printf OUT <<"EOF";
  1269. #ifndef MK1MF_BUILD
  1270. /* auto-generated by Configure for crypto/cversion.c:
  1271. * for Unix builds, crypto/Makefile.ssl generates functional definitions;
  1272. * Windows builds (and other mk1mf builds) compile cversion.c with
  1273. * -DMK1MF_BUILD and use definitions added to this file by util/mk1mf.pl. */
  1274. #error "Windows builds (PLATFORM=$target) use mk1mf.pl-created Makefiles"
  1275. #endif
  1276. EOF
  1277. close(OUT);
  1278. # create the ms/version32.rc file if needed
  1279. if (! grep /^netware/, @{$target{build_scheme}}) {
  1280. my ($v1, $v2, $v3, $v4);
  1281. if ($config{version_num} =~ /^0x([0-9a-f]{1})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{1})L$/i) {
  1282. $v1=hex $1;
  1283. $v2=hex $2;
  1284. $v3=hex $3;
  1285. $v4=hex $4;
  1286. }
  1287. open (OUT,">ms/version32.rc") || die "Can't open ms/version32.rc";
  1288. print OUT <<"EOF";
  1289. #include <winver.h>
  1290. LANGUAGE 0x09,0x01
  1291. 1 VERSIONINFO
  1292. FILEVERSION $v1,$v2,$v3,$v4
  1293. PRODUCTVERSION $v1,$v2,$v3,$v4
  1294. FILEFLAGSMASK 0x3fL
  1295. #ifdef _DEBUG
  1296. FILEFLAGS 0x01L
  1297. #else
  1298. FILEFLAGS 0x00L
  1299. #endif
  1300. FILEOS VOS__WINDOWS32
  1301. FILETYPE VFT_DLL
  1302. FILESUBTYPE 0x0L
  1303. BEGIN
  1304. BLOCK "StringFileInfo"
  1305. BEGIN
  1306. BLOCK "040904b0"
  1307. BEGIN
  1308. // Required:
  1309. VALUE "CompanyName", "The OpenSSL Project, http://www.openssl.org/\\0"
  1310. VALUE "FileDescription", "OpenSSL Shared Library\\0"
  1311. VALUE "FileVersion", "$config{version}\\0"
  1312. #if defined(CRYPTO)
  1313. VALUE "InternalName", "libeay32\\0"
  1314. VALUE "OriginalFilename", "libeay32.dll\\0"
  1315. #elif defined(SSL)
  1316. VALUE "InternalName", "ssleay32\\0"
  1317. VALUE "OriginalFilename", "ssleay32.dll\\0"
  1318. #endif
  1319. VALUE "ProductName", "The OpenSSL Toolkit\\0"
  1320. VALUE "ProductVersion", "$config{version}\\0"
  1321. // Optional:
  1322. //VALUE "Comments", "\\0"
  1323. VALUE "LegalCopyright", "Copyright © 1998-2015 The OpenSSL Project. Copyright © 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0"
  1324. //VALUE "LegalTrademarks", "\\0"
  1325. //VALUE "PrivateBuild", "\\0"
  1326. //VALUE "SpecialBuild", "\\0"
  1327. END
  1328. END
  1329. BLOCK "VarFileInfo"
  1330. BEGIN
  1331. VALUE "Translation", 0x409, 0x4b0
  1332. END
  1333. END
  1334. EOF
  1335. close(OUT);
  1336. }
  1337. },
  1338. );
  1339. my ($builder, @builder_opts) = @{$target{build_scheme}};
  1340. $builders{$builder}->(@builder_opts);
  1341. print <<"EOF";
  1342. Configured for $target.
  1343. EOF
  1344. print <<"EOF" if (!$no_threads && !$threads);
  1345. The library could not be configured for supporting multi-threaded
  1346. applications as the compiler options required on this system are not known.
  1347. See file INSTALL for details if you need multi-threading.
  1348. EOF
  1349. print <<"EOF" if ($no_shared_warn);
  1350. You gave the option 'shared', which is not supported on this platform, so
  1351. we will pretend you gave the option 'no-shared'. If you know how to implement
  1352. shared libraries, please let us know (but please first make sure you have
  1353. tried with a current version of OpenSSL).
  1354. EOF
  1355. print <<"EOF" if ($warn_make_depend);
  1356. *** Because of configuration changes, you MUST do the following before
  1357. *** building:
  1358. make depend
  1359. EOF
  1360. exit(0);
  1361. ######################################################################
  1362. #
  1363. # Helpers and utility functions
  1364. #
  1365. # Configuration file reading #########################################
  1366. # Helper function to implement conditional inheritance depending on the
  1367. # value of $no_asm. Used in inherit_from values as follows:
  1368. #
  1369. # inherit_from => [ "template", asm("asm_tmpl") ]
  1370. #
  1371. sub asm {
  1372. my @x = @_;
  1373. sub {
  1374. $no_asm ? () : @x;
  1375. }
  1376. }
  1377. # Helper function to implement adding values to already existing configuration
  1378. # values. It handles elements that are ARRAYs, CODEs and scalars
  1379. sub _add {
  1380. my $separator = shift;
  1381. # If there's any ARRAY in the collection of values, we will return
  1382. # an ARRAY of combined values, otherwise a string of joined values
  1383. # with $separator as the separator.
  1384. my $found_array = 0;
  1385. my @values =
  1386. map {
  1387. if (ref($_) eq "ARRAY") {
  1388. $found_array = 1;
  1389. @$_;
  1390. } else {
  1391. $_;
  1392. }
  1393. } (@_);
  1394. if ($found_array) {
  1395. [ @values ];
  1396. } else {
  1397. join($separator, @values);
  1398. }
  1399. }
  1400. sub add_before {
  1401. my $separator = shift;
  1402. my @x = @_;
  1403. sub { _add($separator, @x, @_) };
  1404. }
  1405. sub add {
  1406. my $separator = shift;
  1407. my @x = @_;
  1408. sub { _add($separator, @_, @x) };
  1409. }
  1410. # configuration reader, evaluates the input file as a perl script and expects
  1411. # it to fill %targets with target configurations. Those are then added to
  1412. # %table.
  1413. sub read_config {
  1414. my $fname = shift;
  1415. open(CONFFILE, "< $fname")
  1416. or die "Can't open configuration file '$fname'!\n";
  1417. my $x = $/;
  1418. undef $/;
  1419. my $content = <CONFFILE>;
  1420. $/ = $x;
  1421. close(CONFFILE);
  1422. my %targets = ();
  1423. {
  1424. local %table = %::table; # Protect %table from tampering
  1425. eval $content;
  1426. warn $@ if $@;
  1427. }
  1428. # For each target, check that it's configured with a hash table.
  1429. foreach (keys %targets) {
  1430. if (ref($targets{$_}) ne "HASH") {
  1431. if (ref($targets{$_}) eq "") {
  1432. warn "Deprecated target configuration for $_, ignoring...\n";
  1433. } else {
  1434. warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
  1435. }
  1436. delete $targets{$_};
  1437. }
  1438. }
  1439. %table = (%table, %targets);
  1440. }
  1441. # configuration resolver. Will only resolve all the lazy evalutation
  1442. # codeblocks for the chozen target and all those it inherits from,
  1443. # recursively
  1444. sub resolve_config {
  1445. my $target = shift;
  1446. my @breadcrumbs = @_;
  1447. if (grep { $_ eq $target } @breadcrumbs) {
  1448. die "inherit_from loop! target backtrace:\n "
  1449. ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
  1450. }
  1451. if (!defined($table{$target})) {
  1452. warn "Warning! target $target doesn't exist!\n";
  1453. return ();
  1454. }
  1455. # Recurse through all inheritances. They will be resolved on the
  1456. # fly, so when this operation is done, they will all just be a
  1457. # bunch of attributes with string values.
  1458. # What we get here, though, are keys with references to lists of
  1459. # the combined values of them all. We will deal with lists after
  1460. # this stage is done.
  1461. my %combined_inheritance = ();
  1462. if ($table{$target}->{inherit_from}) {
  1463. my @inherit_from =
  1464. map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
  1465. foreach (@inherit_from) {
  1466. my %inherited_config = resolve_config($_, $target, @breadcrumbs);
  1467. # 'template' is a marker that's considered private to
  1468. # the config that had it.
  1469. delete $inherited_config{template};
  1470. map {
  1471. if (!$combined_inheritance{$_}) {
  1472. $combined_inheritance{$_} = [];
  1473. }
  1474. push @{$combined_inheritance{$_}}, $inherited_config{$_};
  1475. } keys %inherited_config;
  1476. }
  1477. }
  1478. # We won't need inherit_from in this target any more, since we've
  1479. # resolved all the inheritances that lead to this
  1480. delete $table{$target}->{inherit_from};
  1481. # Now is the time to deal with those lists. Here's the place to
  1482. # decide what shall be done with those lists, all based on the
  1483. # values of the target we're currently dealing with.
  1484. # - If a value is a coderef, it will be executed with the list of
  1485. # inherited values as arguments.
  1486. # - If the corresponding key doesn't have a value at all or is the
  1487. # emoty string, the inherited value list will be run through the
  1488. # default combiner (below), and the result becomes this target's
  1489. # value.
  1490. # - Otherwise, this target's value is assumed to be a string that
  1491. # will simply override the inherited list of values.
  1492. my $default_combiner = add(" ");
  1493. my %all_keys =
  1494. map { $_ => 1 } (keys %combined_inheritance,
  1495. keys %{$table{$target}});
  1496. foreach (sort keys %all_keys) {
  1497. # Current target doesn't have a value for the current key?
  1498. # Assign it the default combiner, the rest of this loop body
  1499. # will handle it just like any other coderef.
  1500. if (!exists $table{$target}->{$_}) {
  1501. $table{$target}->{$_} = $default_combiner;
  1502. }
  1503. my $valuetype = ref($table{$target}->{$_});
  1504. if ($valuetype eq "CODE") {
  1505. # CODE reference, execute it with the inherited values as
  1506. # arguments.
  1507. $table{$target}->{$_} =
  1508. $table{$target}->{$_}->(@{$combined_inheritance{$_}});
  1509. } elsif ($valuetype eq "ARRAY" || $valuetype eq "") {
  1510. # ARRAY or Scalar, just leave it as is.
  1511. } else {
  1512. # Some other type of reference that we don't handle.
  1513. # Better to abort at this point.
  1514. die "cannot handle reference type $valuetype,"
  1515. ," found in target $target -> $_\n";
  1516. }
  1517. }
  1518. # Finally done, return the result.
  1519. return %{$table{$target}};
  1520. }
  1521. sub usage
  1522. {
  1523. print STDERR $usage;
  1524. print STDERR "\npick os/compiler from:\n";
  1525. my $j=0;
  1526. my $i;
  1527. my $k=0;
  1528. foreach $i (sort keys %table)
  1529. {
  1530. next if $table{$i}->{template};
  1531. next if $i =~ /^debug/;
  1532. $k += length($i) + 1;
  1533. if ($k > 78)
  1534. {
  1535. print STDERR "\n";
  1536. $k=length($i);
  1537. }
  1538. print STDERR $i . " ";
  1539. }
  1540. foreach $i (sort keys %table)
  1541. {
  1542. next if $table{$i}->{template};
  1543. next if $i !~ /^debug/;
  1544. $k += length($i) + 1;
  1545. if ($k > 78)
  1546. {
  1547. print STDERR "\n";
  1548. $k=length($i);
  1549. }
  1550. print STDERR $i . " ";
  1551. }
  1552. print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n";
  1553. exit(1);
  1554. }
  1555. sub run_dofile()
  1556. {
  1557. my $in = shift;
  1558. my $out = shift;
  1559. # should we remove $out ?
  1560. system("$config{perl} -I. -Mconfigdata util/dofile.pl -o\"Configure\" $in > $out.new");
  1561. exit 1 if $? != 0;
  1562. rename("$out.new", $out) || die "Can't rename $out.new, $!";
  1563. }
  1564. # Configuration printer ##############################################
  1565. sub print_table_entry
  1566. {
  1567. my $target = shift;
  1568. my %target = resolve_config($target);
  1569. my $type = shift;
  1570. # Don't print the templates
  1571. return if $target{template};
  1572. my @sequence = (
  1573. "sys_id",
  1574. "cc",
  1575. "cflags",
  1576. "debug_cflags",
  1577. "release_cflags",
  1578. "thread_cflag",
  1579. "unistd",
  1580. "ld",
  1581. "lflags",
  1582. "debug_lflags",
  1583. "release_lflags",
  1584. "bn_ops",
  1585. "cpuid_obj",
  1586. "bn_obj",
  1587. "ec_obj",
  1588. "des_obj",
  1589. "aes_obj",
  1590. "bf_obj",
  1591. "md5_obj",
  1592. "sha1_obj",
  1593. "cast_obj",
  1594. "rc4_obj",
  1595. "rmd160_obj",
  1596. "rc5_obj",
  1597. "wp_obj",
  1598. "cmll_obj",
  1599. "modes_obj",
  1600. "padlock_obj",
  1601. "perlasm_scheme",
  1602. "dso_scheme",
  1603. "shared_target",
  1604. "shared_cflag",
  1605. "shared_ldflag",
  1606. "shared_extension",
  1607. "obj_extension",
  1608. "exe_extension",
  1609. "ranlib",
  1610. "ar",
  1611. "arflags",
  1612. "multilib",
  1613. "build_scheme",
  1614. );
  1615. if ($type eq "TABLE") {
  1616. print "\n";
  1617. print "*** $target\n";
  1618. printf "\$%-12s = %s\n", $_, $target{$_} foreach (@sequence);
  1619. } elsif ($type eq "HASH") {
  1620. my $largest =
  1621. length((sort { length($a) <=> length($b) } @sequence)[-1]);
  1622. print " '$target' => {\n";
  1623. foreach (@sequence) {
  1624. if ($target{$_}) {
  1625. print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
  1626. }
  1627. }
  1628. print " },\n";
  1629. }
  1630. }
  1631. # Utility routines ###################################################
  1632. sub which
  1633. {
  1634. my($name)=@_;
  1635. my $path;
  1636. foreach $path (split /:/, $ENV{PATH})
  1637. {
  1638. if (-f "$path/$name$target{exe_extension}" and -x _)
  1639. {
  1640. return "$path/$name$target{exe_extension}" unless ($name eq "perl" and
  1641. system("$path/$name$target{exe_extension} -e " . '\'exit($]<5.0);\''));
  1642. }
  1643. }
  1644. }
  1645. sub quotify {
  1646. my %processors = (
  1647. perl => sub { my $x = shift;
  1648. $x =~ s/([\\\$\@"])/\\$1/g;
  1649. return '"'.$x.'"'; },
  1650. );
  1651. my $for = shift;
  1652. my $processor =
  1653. defined($processors{$for}) ? $processors{$for} : sub { shift; };
  1654. map { $processor->($_); } @_;
  1655. }
  1656. # collect_information($filename, $line_continue, $regexp => $CODEref, ...)
  1657. # $filename is the file to read.
  1658. # $line_continue is either undef (which is a noop), or two arguments, where
  1659. # the first is a regexp detecting a line continuation ending, and the
  1660. # following argument is a CODEref that takes care of concatenating two
  1661. # lines.
  1662. # All following arguments are regex/CODEref pairs, where the regexp detects a
  1663. # line and the CODEref does something with the result of the regexp.
  1664. sub collect_information {
  1665. my $filename = shift;
  1666. my $line_continue_re = shift;
  1667. my $line_concat = defined($line_continue_re) ? shift : undef;
  1668. my %collectors = @_;
  1669. my $saved_line = "";
  1670. open IN, $filename || die "unable to read $filename: $!\n";
  1671. while(<IN>) {
  1672. chomp;
  1673. if (defined $line_concat) {
  1674. $_ = $line_concat->($saved_line, $_);
  1675. }
  1676. if (defined $line_continue_re && /$line_continue_re/) {
  1677. $saved_line = $_;
  1678. next;
  1679. }
  1680. foreach my $re (keys %collectors) {
  1681. if (/$re/) { $collectors{$re}->() };
  1682. }
  1683. }
  1684. close IN;
  1685. }