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