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