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