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