VirtualBox

source: vbox/trunk/src/libs/openssl-3.4.1/Configure

Last change on this file was 109052, checked in by vboxsync, 3 weeks ago

openssl-3.4.1: Applied our changes, regenerated files, added missing files and functions. This time with a three way merge. ​bugref:10890

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 137.9 KB
Line 
1#! /usr/bin/env perl
2# -*- mode: perl; -*-
3# Copyright 2016-2024 The OpenSSL Project Authors. All Rights Reserved.
4#
5# Licensed under the Apache License 2.0 (the "License"). You may not use
6# this file except in compliance with the License. You can obtain a copy
7# in the file LICENSE in the source distribution or at
8# https://www.openssl.org/source/license.html
9
10## Configure -- OpenSSL source tree configuration script
11
12use 5.10.0;
13use strict;
14use Config;
15use FindBin;
16use lib "$FindBin::Bin/util/perl";
17use File::Basename;
18use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs splitdir/;
19use File::Path qw/mkpath/;
20use OpenSSL::fallback "$FindBin::Bin/external/perl/MODULES.txt";
21use OpenSSL::Glob;
22use OpenSSL::Template;
23use OpenSSL::config;
24
25# see INSTALL.md for instructions.
26
27my $orig_death_handler = $SIG{__DIE__};
28$SIG{__DIE__} = \&death_handler;
29
30my $usage="Usage: Configure [no-<feature> ...] [enable-<feature> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]thread-pool] [[no-]default-thread-pool] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";
31
32my $banner = <<"EOF";
33
34**********************************************************************
35*** ***
36*** OpenSSL has been successfully configured ***
37*** ***
38*** If you encounter a problem while building, please open an ***
39*** issue on GitHub <https://github.com/openssl/openssl/issues> ***
40*** and include the output from the following command: ***
41*** ***
42*** perl configdata.pm --dump ***
43*** ***
44*** (If you are new to OpenSSL, you might want to consult the ***
45*** 'Troubleshooting' section in the INSTALL.md file first) ***
46*** ***
47**********************************************************************
48EOF
49
50# Options:
51#
52# --config add the given configuration file, which will be read after
53# any "Configurations*" files that are found in the same
54# directory as this script.
55# --prefix prefix for the OpenSSL installation, which includes the
56# directories bin, lib, include, share/man, share/doc/openssl
57# This becomes the value of INSTALLTOP in Makefile
58# (Default: /usr/local)
59# --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys.
60# If it's a relative directory, it will be added on the directory
61# given with --prefix.
62# This becomes the value of OPENSSLDIR in Makefile and in C.
63# (Default: PREFIX/ssl)
64# --banner=".." Output specified text instead of default completion banner
65#
66# -w Don't wait after showing a Configure warning
67#
68# --cross-compile-prefix Add specified prefix to binutils components.
69#
70# --api One of 0.9.8, 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.1, or 3.0
71# Define the public APIs as they were for that version
72# including patch releases. If 'no-deprecated' is also
73# given, do not compile support for interfaces deprecated
74# up to and including the specified OpenSSL version.
75#
76# no-hw-xxx do not compile support for specific crypto hardware.
77# Generic OpenSSL-style methods relating to this support
78# are always compiled but return NULL if the hardware
79# support isn't compiled.
80#
81# enable-demos Enable the building of the example code in the demos directory
82# enable-h3demo Enable the http3 demo, which currently only links to the
83# external nghttp3 library on unix platforms
84# no-hw do not compile support for any crypto hardware.
85# [no-]threads [don't] try to create a library that is suitable for
86# multithreaded applications (default is "threads" if we
87# know how to do it)
88# [no-]thread-pool
89# [don't] allow thread pool functionality
90# [no-]default-thread-pool
91# [don't] allow default thread pool functionality
92# [no-]shared [don't] try to create shared libraries when supported.
93# [no-]pic [don't] try to build position independent code when supported.
94# If disabled, it also disables shared and dynamic-engine.
95# no-asm do not use assembler
96# no-egd do not compile support for the entropy-gathering daemon APIs
97# [no-]zlib [don't] compile support for zlib compression.
98# zlib-dynamic Like "zlib", but the zlib library is expected to be a shared
99# library and will be loaded at run-time by the OpenSSL library.
100# sctp include SCTP support
101# no-quic disable QUIC support
102# no-uplink Don't build support for UPLINK interface.
103# enable-weak-ssl-ciphers
104# Enable weak ciphers that are disabled by default.
105# 386 generate 80386 code in assembly modules
106# no-sse2 disables IA-32 SSE2 code in assembly modules, the above
107# mentioned '386' option implies this one
108# no-<cipher> build without specified algorithm (dsa, idea, rc5, ...)
109# -<xxx> +<xxx> All options which are unknown to the 'Configure' script are
110# /<xxx> passed through to the compiler. Unix-style options beginning
111# with a '-' or '+' are recognized, as well as Windows-style
112# options beginning with a '/'. If the option contains arguments
113# separated by spaces, then the URL-style notation %20 can be
114# used for the space character in order to avoid having to quote
115# the option. For example, -opt%20arg gets expanded to -opt arg.
116# In fact, any ASCII character can be encoded as %xx using its
117# hexadecimal encoding.
118# -static while -static is also a pass-through compiler option (and
119# as such is limited to environments where it's actually
120# meaningful), it triggers a number configuration options,
121# namely no-pic, no-shared and no-threads. It is
122# argued that the only reason to produce statically linked
123# binaries (and in context it means executables linked with
124# -static flag, and not just executables linked with static
125# libcrypto.a) is to eliminate dependency on specific run-time,
126# a.k.a. libc version. The mentioned config options are meant
127# to achieve just that. Unfortunately on Linux it's impossible
128# to eliminate the dependency completely for openssl executable
129# because of getaddrinfo and gethostbyname calls, which can
130# invoke dynamically loadable library facility anyway to meet
131# the lookup requests. For this reason on Linux statically
132# linked openssl executable has rather debugging value than
133# production quality.
134#
135# BN_LLONG use the type 'long long' in crypto/bn/bn.h
136# RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
137# Following are set automatically by this script
138#
139# MD5_ASM use some extra md5 assembler,
140# SHA1_ASM use some extra sha1 assembler, must define L_ENDIAN for x86
141# RMD160_ASM use some extra ripemd160 assembler,
142# SHA256_ASM sha256_block is implemented in assembler
143# SHA512_ASM sha512_block is implemented in assembler
144# AES_ASM AES_[en|de]crypt is implemented in assembler
145
146# Minimum warning options... any contributions to OpenSSL should at least
147# get past these. Note that we only use these with C compilers, not with
148# C++ compilers.
149
150# -DPEDANTIC complements -pedantic and is meant to mask code that
151# is not strictly standard-compliant and/or implementation-specific,
152# e.g. inline assembly, disregards to alignment requirements, such
153# that -pedantic would complain about. Incidentally -DPEDANTIC has
154# to be used even in sanitized builds, because sanitizer too is
155# supposed to and does take notice of non-standard behaviour. Then
156# -pedantic with pre-C9x compiler would also complain about 'long
157# long' not being supported. As 64-bit algorithms are common now,
158# it grew impossible to resolve this without sizeable additional
159# code, so we just tell compiler to be pedantic about everything
160# but 'long long' type.
161
162my @gcc_devteam_warn = qw(
163 -DPEDANTIC -pedantic -Wno-long-long -DUNUSEDRESULT_DEBUG
164 -Wall
165 -Wmissing-declarations
166 -Wextra
167 -Wno-unused-parameter
168 -Wno-missing-field-initializers
169 -Wswitch
170 -Wsign-compare
171 -Wshadow
172 -Wformat
173 -Wno-type-limits
174 -Wundef
175 -Werror
176 -Wmissing-prototypes
177 -Wstrict-prototypes
178);
179
180# These are used in addition to $gcc_devteam_warn when the compiler is clang.
181# TODO(openssl-team): fix problems and investigate if (at least) the
182# following warnings can also be enabled:
183# -Wcast-align
184# -Wunreachable-code -- no, too ugly/compiler-specific
185# -Wlanguage-extension-token -- no, we use asm()
186# -Wunused-macros -- no, too tricky for BN and _XOPEN_SOURCE etc
187# -Wextended-offsetof -- no, needed in CMS ASN1 code
188my @clang_devteam_warn = qw(
189 -Wno-unknown-warning-option
190 -Wno-parentheses-equality
191 -Wno-language-extension-token
192 -Wno-extended-offsetof
193 -Wno-missing-braces
194 -Wno-tautological-constant-out-of-range-compare
195 -Wconditional-uninitialized
196 -Wincompatible-pointer-types-discards-qualifiers
197 -Wmissing-variable-declarations
198);
199
200my @cl_devteam_warn = qw(
201 /WX
202);
203
204my $strict_warnings = 0;
205
206# As for $BSDthreads. Idea is to maintain "collective" set of flags,
207# which would cover all BSD flavors. -pthread applies to them all,
208# but is treated differently. OpenBSD expands is as -D_POSIX_THREAD
209# -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r,
210# which has to be accompanied by explicit -D_THREAD_SAFE and
211# sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which
212# seems to be sufficient?
213our $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT";
214
215#
216# API compatibility name to version number mapping.
217#
218my $apitable = {
219 # This table expresses when API additions or changes can occur.
220 # The numbering used changes from 3.0 and on because we updated
221 # (solidified) our version numbering scheme at that point.
222
223 # From 3.0 and on, we internalise the given version number in decimal
224 # as MAJOR * 10000 + MINOR * 100 + 0
225 "3.0.0" => 30000,
226 "3.0" => 30000,
227
228 # Note that before 3.0, we didn't have the same version number scheme.
229 # Still, the numbering we use here covers what we need.
230 "1.1.1" => 10101,
231 "1.1.0" => 10100,
232 "1.0.2" => 10002,
233 "1.0.1" => 10001,
234 "1.0.0" => 10000,
235 "0.9.8" => 908,
236};
237
238# For OpenSSL::config::get_platform
239my %guess_opts = ();
240
241my $dryrun = 0;
242
243our %table = ();
244our %config = ();
245our %withargs = ();
246our $now_printing; # set to current entry's name in print_table_entry
247 # (todo: right thing would be to encapsulate name
248 # into %target [class] and make print_table_entry
249 # a method)
250
251# Forward declarations ###############################################
252
253# read_config(filename)
254#
255# Reads a configuration file and populates %table with the contents
256# (which the configuration file places in %targets).
257sub read_config;
258
259# resolve_config(target)
260#
261# Resolves all the late evaluations, inheritances and so on for the
262# chosen target and any target it inherits from.
263sub resolve_config;
264
265
266# Information collection #############################################
267
268# Unified build supports separate build dir
269my $srcdir = catdir(absolutedir(dirname($0))); # catdir ensures local syntax
270my $blddir = catdir(absolutedir(".")); # catdir ensures local syntax
271
272# File::Spec::Unix doesn't detect case insensitivity, so we make sure to
273# check if the source and build directory are really the same, and make
274# them so. This avoids all kinds of confusion later on.
275# We must check @File::Spec::ISA rather than using File::Spec->isa() to
276# know if File::Spec ended up loading File::Spec::Unix.
277$srcdir = $blddir
278 if (grep(/::Unix$/, @File::Spec::ISA)
279 && samedir($srcdir, $blddir));
280
281my $dofile = abs2rel(catfile($srcdir, "util/dofile.pl"));
282
283my $local_config_envname = 'OPENSSL_LOCAL_CONFIG_DIR';
284
285$config{sourcedir} = abs2rel($srcdir, $blddir);
286$config{builddir} = abs2rel($blddir, $blddir);
287# echo -n 'holy hand grenade of antioch' | openssl sha256
288$config{FIPSKEY} =
289 'f4556650ac31d35461610bac4ed81b1a181b2d8a43ea2854cbae22ca74560813';
290
291# Collect reconfiguration information if needed
292my @argvcopy=@ARGV;
293
294if (grep /^reconf(igure)?$/, @argvcopy) {
295 die "reconfiguring with other arguments present isn't supported"
296 if scalar @argvcopy > 1;
297 if (-f "./configdata.pm") {
298 my $file = "./configdata.pm";
299 unless (my $return = do $file) {
300 die "couldn't parse $file: $@" if $@;
301 die "couldn't do $file: $!" unless defined $return;
302 die "couldn't run $file" unless $return;
303 }
304
305 @argvcopy = defined($configdata::config{perlargv}) ?
306 @{$configdata::config{perlargv}} : ();
307 die "Incorrect data to reconfigure, please do a normal configuration\n"
308 if (grep(/^reconf/,@argvcopy));
309 $config{perlenv} = $configdata::config{perlenv} // {};
310 } else {
311 die "Insufficient data to reconfigure, please do a normal configuration\n";
312 }
313}
314
315$config{perlargv} = [ @argvcopy ];
316
317# Historical: if known directories in crypto/ have been removed, it means
318# that those sub-systems are disabled.
319# (the other option would be to removed them from the SUBDIRS statement in
320# crypto/build.info)
321# We reverse the input list for cosmetic purely reasons, to compensate that
322# 'unshift' adds at the front of the list (i.e. in reverse input order).
323foreach ( reverse sort( 'aes', 'aria', 'bf', 'camellia', 'cast', 'des', 'dh',
324 'dsa', 'ec', 'hmac', 'idea', 'md2', 'md5', 'mdc2',
325 'rc2', 'rc4', 'rc5', 'ripemd', 'seed', 'sha',
326 'sm2', 'sm3', 'sm4') ) {
327 unshift @argvcopy, "no-$_" if ! -d catdir($srcdir, 'crypto', $_);
328}
329
330# Collect version numbers
331my %version = ();
332
333collect_information(
334 collect_from_file(catfile($srcdir,'VERSION.dat')),
335 qr/\s*(\w+)\s*=\s*(.*?)\s*$/ =>
336 sub {
337 # Only define it if there is a value at all
338 if ($2 ne '') {
339 my $k = $1;
340 my $v = $2;
341 # Some values are quoted. Trim the quotes
342 $v = $1 if $v =~ /^"(.*)"$/;
343 $version{uc $k} = $v;
344 }
345 },
346 "OTHERWISE" =>
347 sub { die "Something wrong with this line:\n$_\nin $srcdir/VERSION.dat" },
348 );
349
350$config{major} = $version{MAJOR} // 'unknown';
351$config{minor} = $version{MINOR} // 'unknown';
352$config{patch} = $version{PATCH} // 'unknown';
353$config{prerelease} =
354 defined $version{PRE_RELEASE_TAG} ? "-$version{PRE_RELEASE_TAG}" : '';
355$config{build_metadata} =
356 defined $version{BUILD_METADATA} ? "+$version{BUILD_METADATA}" : '';
357$config{shlib_version} = $version{SHLIB_VERSION} // 'unknown';
358$config{release_date} = $version{RELEASE_DATE} // 'xx XXX xxxx';
359
360$config{version} = "$config{major}.$config{minor}.$config{patch}";
361$config{full_version} = "$config{version}$config{prerelease}$config{build_metadata}";
362
363die "erroneous version information in VERSION.dat: ",
364 "$config{version}, $config{shlib_version}\n"
365 unless (defined $version{MAJOR}
366 && defined $version{MINOR}
367 && defined $version{PATCH}
368 && defined $version{SHLIB_VERSION});
369
370# Collect target configurations
371
372my $pattern = catfile(dirname($0), "Configurations", "*.conf");
373foreach (sort glob($pattern)) {
374 &read_config($_);
375}
376
377if (defined env($local_config_envname)) {
378 if ($^O eq 'VMS') {
379 # VMS environment variables are logical names,
380 # which can be used as is
381 $pattern = $local_config_envname . ':' . '*.conf';
382 } else {
383 $pattern = catfile(env($local_config_envname), '*.conf');
384 }
385
386 foreach (sort glob($pattern)) {
387 &read_config($_);
388 }
389}
390
391# Fail if no configuration is apparent
392if (!%table) {
393 print "Failed to find any os/compiler configurations. Please make sure the Configurations directory is included.\n";
394 &usage;
395}
396
397# Save away perl command information
398$config{perl_cmd} = $^X;
399$config{perl_version} = $Config{version};
400$config{perl_archname} = $Config{archname};
401
402$config{prefix}="";
403$config{openssldir}="";
404$config{processor}="";
405$config{libdir}="";
406my $auto_threads=1; # enable threads automatically? true by default
407my $default_ranlib;
408
409# Known TLS and DTLS protocols
410my @tls = qw(ssl3 tls1 tls1_1 tls1_2 tls1_3);
411my @dtls = qw(dtls1 dtls1_2);
412
413# Explicitly known options that are possible to disable. They can
414# be regexps, and will be used like this: /^no-${option}$/
415# For developers: keep it sorted alphabetically
416
417my @disablables = (
418 "acvp-tests",
419 "afalgeng",
420 "apps",
421 "argon2",
422 "aria",
423 "asan",
424 "asm",
425 "async",
426 "atexit",
427 "autoalginit",
428 "autoerrinit",
429 "autoload-config",
430 "bf",
431 "blake2",
432 "brotli",
433 "brotli-dynamic",
434 "buildtest-c++",
435 "bulk",
436 "cached-fetch",
437 "camellia",
438 "capieng",
439 "winstore",
440 "cast",
441 "chacha",
442 "cmac",
443 "cmp",
444 "cms",
445 "comp",
446 "crypto-mdebug",
447 "ct",
448 "default-thread-pool",
449 "demos",
450 "h3demo",
451 "deprecated",
452 "des",
453 "devcryptoeng",
454 "dgram",
455 "dh",
456 "docs",
457 "dsa",
458 "dso",
459 "dtls",
460 "dynamic-engine",
461 "ec",
462 "ec2m",
463 "ec_nistp_64_gcc_128",
464 "ecdh",
465 "ecdsa",
466 "ecx",
467 "egd",
468 "engine",
469 "err",
470 "external-tests",
471 "filenames",
472 "fips",
473 "fips-securitychecks",
474 "fips-post",
475 "fuzz-afl",
476 "fuzz-libfuzzer",
477 "gost",
478 "http",
479 "idea",
480 "jitter",
481 "ktls",
482 "legacy",
483 "loadereng",
484 "makedepend",
485 "md2",
486 "md4",
487 "mdc2",
488 "module",
489 "msan",
490 "multiblock",
491 "nextprotoneg",
492 "ocb",
493 "ocsp",
494 "padlockeng",
495 "pic",
496 "pie",
497 "pinshared",
498 "poly1305",
499 "posix-io",
500 "psk",
501 "quic",
502 "unstable-qlog",
503 "rc2",
504 "rc4",
505 "rc5",
506 "rdrand",
507 "rfc3779",
508 "rmd160",
509 "scrypt",
510 "sctp",
511 "secure-memory",
512 "seed",
513 "shared",
514 "siphash",
515 "siv",
516 "sm2",
517 "sm2-precomp",
518 "sm3",
519 "sm4",
520 "sock",
521 "srp",
522 "srtp",
523 "sse2",
524 "ssl",
525 "ssl-trace",
526 "static-engine",
527 "stdio",
528 "tests",
529 "tfo",
530 "thread-pool",
531 "threads",
532 "tls",
533 "integrity-only-ciphers",
534 "trace",
535 "ts",
536 "ubsan",
537 "ui-console",
538 "unit-test",
539 "uplink",
540 "weak-ssl-ciphers",
541 "whirlpool",
542 "zlib",
543 "zlib-dynamic",
544 "zstd",
545 "zstd-dynamic",
546 );
547foreach my $proto ((@tls, @dtls))
548 {
549 push(@disablables, $proto);
550 push(@disablables, "$proto-method") unless $proto eq "tls1_3";
551 }
552
553# Internal disablables, for aliasing purposes. They serve no special
554# purpose here, but allow scripts to get to know them through configdata.pm,
555# where these are merged with @disablables.
556# The actual aliasing mechanism is done via %disable_cascades
557my @disablables_int = qw(
558 crmf
559 );
560
561my %deprecated_disablables = (
562 "ssl2" => undef,
563 "buf-freelists" => undef,
564 "crypto-mdebug-backtrace" => undef,
565 "hw" => "hw", # causes cascade, but no macro
566 "hw-padlock" => "padlockeng",
567 "ripemd" => "rmd160",
568 "ui" => "ui-console",
569 "heartbeats" => undef,
570 );
571
572# All of the following are disabled by default:
573
574our %disabled = ( # "what" => "comment"
575 "fips" => "default",
576 "asan" => "default",
577 "brotli" => "default",
578 "brotli-dynamic" => "default",
579 "buildtest-c++" => "default",
580 "crypto-mdebug" => "default",
581 "crypto-mdebug-backtrace" => "default",
582 "demos" => "default",
583 "h3demo" => "default",
584 "devcryptoeng" => "default",
585 "ec_nistp_64_gcc_128" => "default",
586 "egd" => "default",
587 "external-tests" => "default",
588 "fuzz-afl" => "default",
589 "fuzz-libfuzzer" => "default",
590 "pie" => "default",
591 "jitter" => "default",
592 "ktls" => "default",
593 "md2" => "default",
594 "msan" => "default",
595 "rc5" => "default",
596 "sctp" => "default",
597 "ssl3" => "default",
598 "ssl3-method" => "default",
599 "tfo" => "default",
600 "trace" => "default",
601 "ubsan" => "default",
602 "unit-test" => "default",
603 "weak-ssl-ciphers" => "default",
604 "zlib" => "default",
605 "zlib-dynamic" => "default",
606 "zstd" => "default",
607 "zstd-dynamic" => "default",
608 );
609
610# Note: => pair form used for aesthetics, not to truly make a hash table
611my @disable_cascades = (
612 # "what" => [ "cascade", ... ]
613 "bulk" => [ "shared", "dso",
614 "aria", "async", "atexit", "autoload-config",
615 "blake2", "bf", "camellia", "cast", "chacha",
616 "cmac", "cms", "cmp", "comp", "ct",
617 "des", "dgram", "dh", "dsa",
618 "ec", "engine",
619 "filenames",
620 "idea", "ktls",
621 "md4", "multiblock", "nextprotoneg",
622 "ocsp", "ocb", "poly1305", "psk",
623 "rc2", "rc4", "rmd160",
624 "seed", "siphash", "siv",
625 "sm3", "sm4", "srp",
626 "srtp", "ssl3-method", "ssl-trace",
627 "tfo",
628 "ts", "ui-console", "whirlpool",
629 "fips-securitychecks" ],
630 sub { $config{processor} eq "386" }
631 => [ "sse2" ],
632 "ssl" => [ "ssl3" ],
633 "ssl3-method" => [ "ssl3" ],
634 "zlib" => [ "zlib-dynamic" ],
635 "brotli" => [ "brotli-dynamic" ],
636 "zstd" => [ "zstd-dynamic" ],
637 "des" => [ "mdc2" ],
638 "ec" => [ "ec2m", "ecdsa", "ecdh", "sm2", "gost", "ecx" ],
639 "dgram" => [ "dtls", "quic", "sctp" ],
640 "sock" => [ "dgram", "tfo" ],
641 "dtls" => [ @dtls ],
642 sub { 0 == scalar grep { !$disabled{$_} } @dtls }
643 => [ "dtls" ],
644
645 "tls" => [ @tls ],
646 sub { 0 == scalar grep { !$disabled{$_} } @tls }
647 => [ "tls" ],
648 "tls1_3" => [ "quic" ],
649 "quic" => [ "unstable-qlog" ],
650
651 "crypto-mdebug" => [ "crypto-mdebug-backtrace" ],
652
653 "module" => [ "dynamic-engine", "fips" ],
654
655 # Without shared libraries, dynamic engines aren't possible.
656 # This is due to them having to link with libcrypto and register features
657 # using the ENGINE functionality, and since that relies on global tables,
658 # those *have* to be exactly the same as the ones accessed from the app,
659 # which cannot be guaranteed if shared libraries aren't present.
660 # (note that even with shared libraries, both the app and dynamic engines
661 # must be linked with the same library)
662 "shared" => [ "dynamic-engine", "uplink" ],
663 "dso" => [ "dynamic-engine", "module" ],
664 # Other modules don't necessarily have to link with libcrypto, so shared
665 # libraries do not have to be a condition to produce those.
666
667 # Without position independent code, there can be no shared libraries
668 # or modules.
669 "pic" => [ "shared", "module" ],
670
671 "engine" => [ "dynamic-engine", grep(/eng$/, @disablables) ],
672 "dynamic-engine" => [ "loadereng" ],
673 "hw" => [ "padlockeng" ],
674
675 # no-autoalginit is only useful when building non-shared
676 "autoalginit" => [ "shared", "apps", "fips" ],
677
678 "stdio" => [ "apps", "capieng", "egd" ],
679 "apps" => [ "tests" ],
680 "tests" => [ "external-tests" ],
681 "comp" => [ "zlib", "brotli", "zstd" ],
682 "sm3" => [ "sm2" ],
683 sub { !$disabled{"unit-test"} } => [ "heartbeats" ],
684
685 sub { !$disabled{"msan"} } => [ "asm" ],
686
687 "cmac" => [ "siv" ],
688 "legacy" => [ "md2" ],
689
690 "cmp" => [ "crmf" ],
691
692 "fips" => [ "fips-securitychecks", "fips-post", "acvp-tests" ],
693
694 "threads" => [ "thread-pool" ],
695 "thread-pool" => [ "default-thread-pool" ],
696
697 "blake2" => [ "argon2" ],
698
699 "deprecated-3.0" => [ "engine", "srp" ],
700
701 "http" => [ "ocsp" ]
702 );
703
704# Avoid protocol support holes. Also disable all versions below N, if version
705# N is disabled while N+1 is enabled.
706#
707my @list = (reverse @tls);
708while ((my $first, my $second) = (shift @list, shift @list)) {
709 last unless @list;
710 push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
711 => [ @list ] );
712 unshift @list, $second;
713}
714my @list = (reverse @dtls);
715while ((my $first, my $second) = (shift @list, shift @list)) {
716 last unless @list;
717 push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
718 => [ @list ] );
719 unshift @list, $second;
720}
721
722# Explicit "no-..." options will be collected in %disabled along with the defaults.
723# To remove something from %disabled, use "enable-foo".
724# For symmetry, "disable-foo" is a synonym for "no-foo".
725
726# For the "make variables" CPPINCLUDES and CPPDEFINES, we support lists with
727# platform specific list separators. Users from those platforms should
728# recognise those separators from how you set up the PATH to find executables.
729# The default is the Unix like separator, :, but as an exception, we also
730# support the space as separator.
731my $list_separator_re =
732 { VMS => qr/(?<!\^),/,
733 MSWin32 => qr/(?<!\\);/ } -> {$^O} // qr/(?<!\\)[:\s]/;
734# All the "make variables" we support
735# Some get pre-populated for the sake of backward compatibility
736# (we supported those before the change to "make variable" support.
737my %user = (
738 AR => env('AR'),
739 ARFLAGS => [],
740 AS => undef,
741 ASFLAGS => [],
742 CC => env('CC'),
743 CFLAGS => [ env('CFLAGS') || () ],
744 CXX => env('CXX'),
745 CXXFLAGS => [ env('CXXFLAGS') || () ],
746 CPP => undef,
747 CPPFLAGS => [ env('CPPFLAGS') || () ], # -D, -I, -Wp,
748 CPPDEFINES => [], # Alternative for -D
749 CPPINCLUDES => [], # Alternative for -I
750 CROSS_COMPILE => env('CROSS_COMPILE'),
751 HASHBANGPERL=> env('HASHBANGPERL') || env('PERL'),
752 LD => undef,
753 LDFLAGS => [ env('LDFLAGS') || () ], # -L, -Wl,
754 LDLIBS => [ env('LDLIBS') || () ], # -l
755 MT => undef,
756 MTFLAGS => [],
757 PERL => env('PERL') || ($^O ne "VMS" ? $^X : "perl"),
758 RANLIB => env('RANLIB'),
759 RC => env('RC') || env('WINDRES'),
760 RCFLAGS => [ env('RCFLAGS') || () ],
761 OBJCOPY => undef,
762 RM => undef,
763 );
764# Info about what "make variables" may be prefixed with the cross compiler
765# prefix. This should NEVER mention any such variable with a list for value.
766my @user_crossable = qw ( AR AS CC CXX CPP LD MT RANLIB RC );
767# The same but for flags given as Configure options. These are *additional*
768# input, as opposed to the VAR=string option that override the corresponding
769# config target attributes
770my %useradd = (
771 ASFLAGS => [],
772 CPPDEFINES => [],
773 CPPINCLUDES => [],
774 CPPFLAGS => [],
775 CFLAGS => [],
776 CXXFLAGS => [],
777 LDFLAGS => [],
778 LDLIBS => [],
779 RCFLAGS => [],
780 );
781
782my %user_synonyms = (
783 HASHBANGPERL=> 'PERL',
784 RC => 'WINDRES',
785 );
786
787# Some target attributes have been renamed, this is the translation table
788my %target_attr_translate =(
789 ar => 'AR',
790 as => 'AS',
791 cc => 'CC',
792 cxx => 'CXX',
793 cpp => 'CPP',
794 hashbangperl => 'HASHBANGPERL',
795 ld => 'LD',
796 mt => 'MT',
797 ranlib => 'RANLIB',
798 rc => 'RC',
799 rm => 'RM',
800 );
801
802# Initialisers coming from 'config' scripts
803$config{defines} = [ split(/$list_separator_re/, env('__CNF_CPPDEFINES')) ];
804$config{includes} = [ split(/$list_separator_re/, env('__CNF_CPPINCLUDES')) ];
805$config{cppflags} = [ env('__CNF_CPPFLAGS') || () ];
806$config{cflags} = [ env('__CNF_CFLAGS') || () ];
807$config{cxxflags} = [ env('__CNF_CXXFLAGS') || () ];
808$config{lflags} = [ env('__CNF_LDFLAGS') || () ];
809$config{ex_libs} = [ env('__CNF_LDLIBS') || () ];
810
811$config{openssl_api_defines}=[];
812$config{openssl_sys_defines}=[];
813$config{openssl_feature_defines}=[];
814$config{options}="";
815$config{build_type} = "release";
816my $target="";
817
818my %cmdvars = (); # Stores FOO='blah' type arguments
819my %unsupported_options = ();
820my %deprecated_options = ();
821# If you change this, update apps/version.c
822my @known_seed_sources = qw(getrandom devrandom os egd none rdcpu);
823my @seed_sources = ();
824while (@argvcopy)
825 {
826 $_ = shift @argvcopy;
827
828 # Support env variable assignments among the options
829 if (m|^(\w+)=(.+)?$|)
830 {
831 $cmdvars{$1} = $2;
832 # Every time a variable is given as a configuration argument,
833 # it acts as a reset if the variable.
834 if (exists $user{$1})
835 {
836 $user{$1} = ref $user{$1} eq "ARRAY" ? [] : undef;
837 }
838 #if (exists $useradd{$1})
839 # {
840 # $useradd{$1} = [];
841 # }
842 next;
843 }
844
845 # VMS is a case insensitive environment, and depending on settings
846 # out of our control, we may receive options uppercased. Let's
847 # downcase at least the part before any equal sign.
848 if ($^O eq "VMS")
849 {
850 s/^([^=]*)/lc($1)/e;
851 }
852
853 # some people just can't read the instructions, clang people have to...
854 s/^-no-(?!integrated-as)/no-/;
855
856 # rewrite some options in "enable-..." form
857 s /^-?-?shared$/enable-shared/;
858 s /^sctp$/enable-sctp/;
859 s /^threads$/enable-threads/;
860 s /^zlib$/enable-zlib/;
861 s /^zlib-dynamic$/enable-zlib-dynamic/;
862 s /^fips$/enable-fips/;
863
864 if (/^(no|disable|enable)-(.+)$/)
865 {
866 my $word = $2;
867 if ($word !~ m|hw(?:-.+)| # special treatment for hw regexp opt
868 && !exists $deprecated_disablables{$word}
869 && !grep { $word eq $_ } @disablables)
870 {
871 $unsupported_options{$_} = 1;
872 next;
873 }
874 }
875 if (/^no-(.+)$/ || /^disable-(.+)$/)
876 {
877 foreach my $proto ((@tls, @dtls))
878 {
879 if ($1 eq "$proto-method")
880 {
881 $disabled{"$proto"} = "option($proto-method)";
882 last;
883 }
884 }
885 if ($1 eq "dtls")
886 {
887 foreach my $proto (@dtls)
888 {
889 $disabled{$proto} = "option(dtls)";
890 }
891 $disabled{"dtls"} = "option(dtls)";
892 }
893 elsif ($1 eq "ssl")
894 {
895 # Last one of its kind
896 $disabled{"ssl3"} = "option(ssl)";
897 }
898 elsif ($1 eq "tls")
899 {
900 # XXX: Tests will fail if all SSL/TLS
901 # protocols are disabled.
902 foreach my $proto (@tls)
903 {
904 $disabled{$proto} = "option(tls)";
905 }
906 }
907 elsif ($1 eq "static-engine")
908 {
909 delete $disabled{"dynamic-engine"};
910 }
911 elsif ($1 eq "dynamic-engine")
912 {
913 $disabled{"dynamic-engine"} = "option";
914 }
915 elsif (exists $deprecated_disablables{$1})
916 {
917 $deprecated_options{$_} = 1;
918 if (defined $deprecated_disablables{$1})
919 {
920 $disabled{$deprecated_disablables{$1}} = "option";
921 }
922 }
923 elsif ($1 =~ m|hw(?:-.+)|) # deprecate hw options in regexp form
924 {
925 $deprecated_options{$_} = 1;
926 }
927 else
928 {
929 $disabled{$1} = "option";
930 }
931 # No longer an automatic choice
932 $auto_threads = 0 if ($1 eq "threads");
933 }
934 elsif (/^enable-(.+)$/)
935 {
936 if ($1 eq "static-engine")
937 {
938 $disabled{"dynamic-engine"} = "option";
939 }
940 elsif ($1 eq "dynamic-engine")
941 {
942 delete $disabled{"dynamic-engine"};
943 }
944 elsif ($1 eq "zlib-dynamic")
945 {
946 delete $disabled{"zlib"};
947 }
948 elsif ($1 eq "brotli-dynamic")
949 {
950 delete $disabled{"brotli"};
951 }
952 elsif ($1 eq "pie")
953 {
954 delete $disabled{"pie"};
955 }
956 elsif ($1 eq "zstd-dynamic")
957 {
958 delete $disabled{"zstd"};
959 }
960 my $algo = $1;
961 delete $disabled{$algo};
962
963 # No longer an automatic choice
964 $auto_threads = 0 if ($1 eq "threads");
965 }
966 elsif (/^-d$/) # From older 'config'
967 {
968 $config{build_type} = "debug";
969 }
970 elsif (/^-v$/) # From older 'config'
971 {
972 $guess_opts{verbose} = 1;
973 }
974 elsif (/^-w$/)
975 {
976 $guess_opts{nowait} = 1;
977 }
978 elsif (/^-t$/) # From older 'config'
979 {
980 $dryrun = 1;
981 }
982 elsif (/^--strict-warnings$/)
983 {
984 # Pretend that our strict flags is a C flag, and replace it
985 # with the proper flags later on
986 push @{$useradd{CFLAGS}}, '--ossl-strict-warnings';
987 $strict_warnings=1;
988 }
989 elsif (/^--debug$/)
990 {
991 $config{build_type} = "debug";
992 }
993 elsif (/^--release$/)
994 {
995 $config{build_type} = "release";
996 }
997 elsif (/^386$/)
998 { $config{processor}=386; }
999 elsif (/^rsaref$/)
1000 {
1001 # No RSAref support any more since it's not needed.
1002 # The check for the option is there so scripts aren't
1003 # broken
1004 }
1005 elsif (m|^[-+/]|)
1006 {
1007 if (/^--prefix=(.*)$/)
1008 {
1009 $config{prefix}=$1;
1010 }
1011 elsif (/^--api=(.*)$/)
1012 {
1013 my $api = $1;
1014 die "Unknown API compatibility level $api"
1015 unless defined $apitable->{$api};
1016 $config{api}=$apitable->{$api};
1017 }
1018 elsif (/^--libdir=(.*)$/)
1019 {
1020 $config{libdir}=$1;
1021 }
1022 elsif (/^--openssldir=(.*)$/)
1023 {
1024 $config{openssldir}=$1;
1025 }
1026 elsif (/^--with-jitter-include=(.*)$/)
1027 {
1028 $withargs{jitter_include}=$1;
1029 }
1030 elsif (/^--with-jitter-lib=(.*)$/)
1031 {
1032 $withargs{jitter_lib}=$1;
1033 }
1034 elsif (/^--with-zlib-lib=(.*)$/)
1035 {
1036 $withargs{zlib_lib}=$1;
1037 }
1038 elsif (/^--with-zlib-include=(.*)$/)
1039 {
1040 $withargs{zlib_include}=$1;
1041 }
1042 elsif (/^--with-brotli-lib=(.*)$/)
1043 {
1044 $withargs{brotli_lib}=$1;
1045 }
1046 elsif (/^--with-brotli-include=(.*)$/)
1047 {
1048 $withargs{brotli_include}=$1;
1049 }
1050 elsif (/^--with-zstd-lib=(.*)$/)
1051 {
1052 $withargs{zstd_lib}=$1;
1053 }
1054 elsif (/^--with-zstd-include=(.*)$/)
1055 {
1056 $withargs{zstd_include}=$1;
1057 }
1058 elsif (/^--with-fuzzer-lib=(.*)$/)
1059 {
1060 $withargs{fuzzer_lib}=$1;
1061 }
1062 elsif (/^--with-fuzzer-include=(.*)$/)
1063 {
1064 $withargs{fuzzer_include}=$1;
1065 }
1066 elsif (/^--with-rand-seed=(.*)$/)
1067 {
1068 foreach my $x (split(m|,|, $1))
1069 {
1070 die "Unknown --with-rand-seed choice $x\n"
1071 if ! grep { $x eq $_ } @known_seed_sources;
1072 push @seed_sources, $x;
1073 }
1074 }
1075 elsif (/^--fips-key=(.*)$/)
1076 {
1077 $user{FIPSKEY}=lc($1);
1078 die "Non-hex character in FIPS key\n"
1079 if $user{FIPSKEY} =~ /[^a-f0-9]/;
1080 die "FIPS key must have even number of characters\n"
1081 if length $1 & 1;
1082 die "FIPS key too long (64 bytes max)\n"
1083 if length $1 > 64;
1084 }
1085 elsif (/^--banner=(.*)$/)
1086 {
1087 $banner = $1 . "\n";
1088 }
1089 elsif (/^--cross-compile-prefix=(.*)$/)
1090 {
1091 $user{CROSS_COMPILE}=$1;
1092 }
1093 elsif (/^--config=(.*)$/)
1094 {
1095 read_config $1;
1096 }
1097 elsif (/^-l(.*)$/)
1098 {
1099 push @{$useradd{LDLIBS}}, $_;
1100 }
1101 elsif (/^-framework$/)
1102 {
1103 push @{$useradd{LDLIBS}}, $_, shift(@argvcopy);
1104 }
1105 elsif (/^-L(.*)$/ or /^-Wl,/)
1106 {
1107 push @{$useradd{LDFLAGS}}, $_;
1108 }
1109 elsif (/^-rpath$/ or /^-R$/)
1110 # -rpath is the OSF1 rpath flag
1111 # -R is the old Solaris rpath flag
1112 {
1113 my $rpath = shift(@argvcopy) || "";
1114 $rpath .= " " if $rpath ne "";
1115 push @{$useradd{LDFLAGS}}, $_, $rpath;
1116 }
1117 elsif (/^-static$/)
1118 {
1119 push @{$useradd{LDFLAGS}}, $_;
1120 }
1121 elsif (m|^[-/]D(.*)$|)
1122 {
1123 push @{$useradd{CPPDEFINES}}, $1;
1124 }
1125 elsif (m|^[-/]I(.*)$|)
1126 {
1127 push @{$useradd{CPPINCLUDES}}, $1;
1128 }
1129 elsif (/^-Wp,$/)
1130 {
1131 push @{$useradd{CPPFLAGS}}, $1;
1132 }
1133 else # common if (/^[-+]/), just pass down...
1134 {
1135 # Treat %xx as an ASCII code (e.g. replace %20 by a space character).
1136 # This provides a simple way to pass options with arguments separated
1137 # by spaces without quoting (e.g. -opt%20arg translates to -opt arg).
1138 $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
1139 push @{$useradd{CFLAGS}}, $_;
1140 push @{$useradd{CXXFLAGS}}, $_;
1141 }
1142 }
1143 elsif (m|^/|)
1144 {
1145 # Treat %xx as an ASCII code (e.g. replace %20 by a space character).
1146 # This provides a simple way to pass options with arguments separated
1147 # by spaces without quoting (e.g. /opt%20arg translates to /opt arg).
1148 $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
1149 push @{$useradd{CFLAGS}}, $_;
1150 push @{$useradd{CXXFLAGS}}, $_;
1151 }
1152 else
1153 {
1154 die "target already defined - $target (offending arg: $_)\n" if ($target ne "");
1155 $target=$_;
1156 }
1157 unless ($_ eq $target || /^no-/ || /^disable-/)
1158 {
1159 # "no-..." follows later after implied deactivations
1160 # have been derived. (Don't take this too seriously,
1161 # we really only write OPTIONS to the Makefile out of
1162 # nostalgia.)
1163
1164 if ($config{options} eq "")
1165 { $config{options} = $_; }
1166 else
1167 { $config{options} .= " ".$_; }
1168 }
1169 }
1170
1171if (keys %deprecated_options)
1172 {
1173 warn "***** Deprecated options: ",
1174 join(", ", keys %deprecated_options), "\n";
1175 }
1176if (keys %unsupported_options)
1177 {
1178 die "***** Unsupported options: ",
1179 join(", ", keys %unsupported_options), "\n";
1180 }
1181
1182# If any %useradd entry has been set, we must check that the "make
1183# variables" haven't been set. We start by checking of any %useradd entry
1184# is set.
1185if (grep { scalar @$_ > 0 } values %useradd) {
1186 # Hash of env / make variables names. The possible values are:
1187 # 1 - "make vars"
1188 # 2 - %useradd entry set
1189 # 3 - both set
1190 my %detected_vars =
1191 map { my $v = 0;
1192 $v += 1 if $cmdvars{$_};
1193 $v += 2 if @{$useradd{$_}};
1194 $_ => $v }
1195 keys %useradd;
1196
1197 # If any of the corresponding "make variables" is set, we error
1198 if (grep { $_ & 1 } values %detected_vars) {
1199 my $names = join(', ', grep { $detected_vars{$_} > 0 }
1200 sort keys %detected_vars);
1201 die <<"_____";
1202***** Mixing make variables and additional compiler/linker flags as
1203***** configure command line option is not permitted.
1204***** Affected make variables: $names
1205_____
1206 }
1207}
1208
1209# Check through all supported command line variables to see if any of them
1210# were set, and canonicalise the values we got. If no compiler or linker
1211# flag or anything else that affects %useradd was set, we also check the
1212# environment for values.
1213my $anyuseradd =
1214 grep { defined $_ && (ref $_ ne 'ARRAY' || @$_) } values %useradd;
1215foreach (keys %user) {
1216 my $value = $cmdvars{$_};
1217 $value //= env($_) unless $anyuseradd;
1218 $value //=
1219 defined $user_synonyms{$_} ? $cmdvars{$user_synonyms{$_}} : undef;
1220 $value //= defined $user_synonyms{$_} ? env($user_synonyms{$_}) : undef
1221 unless $anyuseradd;
1222
1223 if (defined $value) {
1224 if (ref $user{$_} eq 'ARRAY') {
1225 if ($_ eq 'CPPDEFINES' || $_ eq 'CPPINCLUDES') {
1226 $user{$_} = [ split /$list_separator_re/, $value ];
1227 } else {
1228 $user{$_} = [ $value ];
1229 }
1230 } elsif (!defined $user{$_}) {
1231 $user{$_} = $value;
1232 }
1233 }
1234}
1235
1236if (grep { /-rpath\b/ } ($user{LDFLAGS} ? @{$user{LDFLAGS}} : ())
1237 && !$disabled{shared}
1238 && !($disabled{asan} && $disabled{msan} && $disabled{ubsan})) {
1239 die "***** Cannot simultaneously use -rpath, shared libraries, and\n",
1240 "***** any of asan, msan or ubsan\n";
1241}
1242
1243# If no target was given, try guessing.
1244unless ($target) {
1245 my %system_config = OpenSSL::config::get_platform(%guess_opts, %user);
1246
1247 # The $system_config{disable} is used to populate %disabled with
1248 # entries that aren't already there.
1249 foreach ( @{$system_config{disable} // []} ) {
1250 $disabled{$_} = 'system' unless defined $disabled{$_};
1251 }
1252 delete $system_config{disable};
1253
1254 # Override config entries with stuff from the guesser.
1255 # It's assumed that this really is nothing new.
1256 %config = ( %config, %system_config );
1257 $target = $system_config{target};
1258}
1259
1260sub disable {
1261 my $disable_type = shift;
1262
1263 for (@_) {
1264 $disabled{$_} = $disable_type;
1265 }
1266
1267 my @tocheckfor = (@_ ? @_ : keys %disabled);
1268 while (@tocheckfor) {
1269 my %new_tocheckfor = ();
1270 my @cascade_copy = (@disable_cascades);
1271 while (@cascade_copy) {
1272 my ($test, $descendents) =
1273 (shift @cascade_copy, shift @cascade_copy);
1274 if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) {
1275 foreach (grep { !defined($disabled{$_}) } @$descendents) {
1276 $new_tocheckfor{$_} = 1; $disabled{$_} = "cascade";
1277 }
1278 }
1279 }
1280 @tocheckfor = (keys %new_tocheckfor);
1281 }
1282}
1283disable(); # First cascade run
1284
1285our $die = sub { die @_; };
1286if ($target eq "TABLE") {
1287 local $die = sub { warn @_; };
1288 foreach (sort keys %table) {
1289 print_table_entry($_, "TABLE");
1290 }
1291 exit 0;
1292}
1293
1294if ($target eq "LIST") {
1295 foreach (sort keys %table) {
1296 print $_,"\n" unless $table{$_}->{template};
1297 }
1298 exit 0;
1299}
1300
1301if ($target eq "HASH") {
1302 local $die = sub { warn @_; };
1303 print "%table = (\n";
1304 foreach (sort keys %table) {
1305 print_table_entry($_, "HASH");
1306 }
1307 exit 0;
1308}
1309
1310print "Configuring OpenSSL version $config{full_version} ";
1311print "for target $target\n";
1312
1313if (scalar(@seed_sources) == 0) {
1314 print "Using os-specific seed configuration\n";
1315 push @seed_sources, 'os';
1316}
1317if (scalar(grep { $_ eq 'egd' } @seed_sources) > 0) {
1318 delete $disabled{'egd'};
1319}
1320if (scalar(grep { $_ eq 'none' } @seed_sources) > 0) {
1321 die "Cannot seed with none and anything else" if scalar(@seed_sources) > 1;
1322 warn <<_____ if scalar(@seed_sources) == 1;
1323
1324============================== WARNING ===============================
1325You have selected the --with-rand-seed=none option, which effectively
1326disables automatic reseeding of the OpenSSL SEED-SRC random generator.
1327All operations depending on the random generator such as creating keys
1328will not work unless the random generator is seeded manually by the
1329application.
1330
1331Instead of manually seeding, a different random generator can be set
1332at runtime in openssl.cnf or configured at build time with
1333-DOPENSSL_DEFAULT_SEED_SRC.
1334
1335Please read the 'Note on random number generation' section in the
1336INSTALL.md instructions and the RAND_DRBG(7) manual page for more
1337details.
1338============================== WARNING ===============================
1339
1340_____
1341}
1342push @{$config{openssl_feature_defines}},
1343 map { (my $x = $_) =~ tr|[\-a-z]|[_A-Z]|; "OPENSSL_RAND_SEED_$x" }
1344 @seed_sources;
1345
1346my $provider_string = $disabled{"fips-post"} ? "non-compliant FIPS Provider" : "FIPS Provider";
1347
1348$config{FIPS_VENDOR} =
1349 (defined $version{FIPS_VENDOR} ? "$version{FIPS_VENDOR} $provider_string for OpenSSL" : "OpenSSL $provider_string");
1350
1351# Backward compatibility?
1352if ($target =~ m/^CygWin32(-.*)$/) {
1353 $target = "Cygwin".$1;
1354}
1355
1356# Support for legacy targets having a name starting with 'debug-'
1357my ($d, $t) = $target =~ m/^(debug-)?(.*)$/;
1358if ($d) {
1359 $config{build_type} = "debug";
1360
1361 # If we do not find debug-foo in the table, the target is set to foo.
1362 if (!$table{$target}) {
1363 $target = $t;
1364 }
1365}
1366
1367if ($target) {
1368 # It's possible that we have different config targets for specific
1369 # toolchains, so we try to detect them, and go for the plain config
1370 # target if not.
1371 my $found;
1372 foreach ( ( "$target-$user{CC}", "$target", undef ) ) {
1373 $found=$_ if $table{$_} && !$table{$_}->{template};
1374 last if $found;
1375 }
1376 $target = $found;
1377} else {
1378 # If we don't have a config target now, we try the C compiler as we
1379 # fallback
1380 my $cc = $user{CC} // 'cc';
1381 $target = $cc if $table{$cc} && !$table{$cc}->{template};
1382}
1383
1384&usage unless $target;
1385
1386exit 0 if $dryrun; # From older 'config'
1387
1388$config{target} = $target;
1389my %target = resolve_config($target);
1390
1391foreach (keys %target_attr_translate) {
1392 $target{$target_attr_translate{$_}} = $target{$_}
1393 if $target{$_};
1394 delete $target{$_};
1395}
1396
1397%target = ( %{$table{DEFAULTS}}, %target );
1398
1399my %conf_files = map { $_ => 1 } (@{$target{_conf_fname_int}});
1400$config{conf_files} = [ sort keys %conf_files ];
1401
1402# Using sub disable within these loops may prove fragile, so we run
1403# a cascade afterwards
1404foreach my $feature (@{$target{disable}}) {
1405 if (exists $deprecated_disablables{$feature}) {
1406 warn "***** config $target disables deprecated feature $feature\n";
1407 } elsif (!grep { $feature eq $_ } @disablables) {
1408 die "***** config $target disables unknown feature $feature\n";
1409 }
1410 $disabled{$feature} = 'config';
1411}
1412foreach my $feature (@{$target{enable}}) {
1413 if ("default" eq ($disabled{$feature} // "")) {
1414 if (exists $deprecated_disablables{$feature}) {
1415 warn "***** config $target enables deprecated feature $feature\n";
1416 } elsif (!grep { $feature eq $_ } @disablables) {
1417 die "***** config $target enables unknown feature $feature\n";
1418 }
1419 delete $disabled{$feature};
1420 }
1421}
1422
1423# If uplink_arch isn't defined, disable uplink
1424$disabled{uplink} = 'no uplink_arch' unless (defined $target{uplink_arch});
1425# If asm_arch isn't defined, disable asm
1426$disabled{asm} = 'no asm_arch' unless (defined $target{asm_arch});
1427
1428disable(); # Run a cascade now
1429
1430$target{CXXFLAGS}//=$target{CFLAGS} if $target{CXX};
1431$target{cxxflags}//=$target{cflags} if $target{CXX};
1432$target{exe_extension}=".exe" if ($config{target} eq "DJGPP");
1433$target{exe_extension}=".pm" if ($config{target} =~ /vos/);
1434
1435# Fill %config with values from %user, and in case those are undefined or
1436# empty, use values from %target (acting as a default).
1437foreach (keys %user) {
1438 my $ref_type = ref $user{$_};
1439
1440 # Temporary function. Takes an intended ref type (empty string or "ARRAY")
1441 # and a value that's to be coerced into that type.
1442 my $mkvalue = sub {
1443 my $type = shift;
1444 my $value = shift;
1445 my $undef_p = shift;
1446
1447 die "Too many arguments for \$mkvalue" if @_;
1448
1449 while (ref $value eq 'CODE') {
1450 $value = $value->();
1451 }
1452
1453 if ($type eq 'ARRAY') {
1454 return undef unless defined $value;
1455 return undef if ref $value ne 'ARRAY' && !$value;
1456 return undef if ref $value eq 'ARRAY' && !@$value;
1457 return [ $value ] unless ref $value eq 'ARRAY';
1458 }
1459 return undef unless $value;
1460 return $value;
1461 };
1462
1463 $config{$_} =
1464 $mkvalue->($ref_type, $user{$_})
1465 || $mkvalue->($ref_type, $target{$_});
1466 delete $config{$_} unless defined $config{$_};
1467}
1468
1469# Finish up %config by appending things the user gave us on the command line
1470# apart from "make variables"
1471foreach (keys %useradd) {
1472 # The must all be lists, so we assert that here
1473 die "internal error: \$useradd{$_} isn't an ARRAY\n"
1474 unless ref $useradd{$_} eq 'ARRAY';
1475
1476 if (defined $config{$_}) {
1477 push @{$config{$_}}, @{$useradd{$_}};
1478 } else {
1479 $config{$_} = [ @{$useradd{$_}} ];
1480 }
1481}
1482# At this point, we can forget everything about %user and %useradd,
1483# because it's now all been merged into the corresponding $config entry
1484
1485if ($config{prefix} && !$config{CROSS_COMPILE}) {
1486 die "Directory given with --prefix MUST be absolute\n"
1487 unless file_name_is_absolute($config{prefix});
1488}
1489
1490if (grep { $_ =~ /(?:^|\s)-static(?:\s|$)/ } @{$config{LDFLAGS}}) {
1491 disable('static', 'pic', 'threads');
1492}
1493
1494# Allow overriding the build file name
1495$config{build_file} = env('BUILDFILE') || $target{build_file} || "Makefile";
1496
1497# Make sure build_scheme is consistent.
1498$target{build_scheme} = [ $target{build_scheme} ]
1499 if ref($target{build_scheme}) ne "ARRAY";
1500
1501my ($builder, $builder_platform, @builder_opts) =
1502 @{$target{build_scheme}};
1503
1504foreach my $checker (($builder_platform."-".$config{build_file}."-checker.pm",
1505 $builder_platform."-checker.pm")) {
1506 my $checker_path = catfile($srcdir, "Configurations", $checker);
1507 if (-f $checker_path) {
1508 my $fn = $ENV{CONFIGURE_CHECKER_WARN}
1509 ? sub { warn $@; } : sub { die $@; };
1510 if (! do $checker_path) {
1511 if ($@) {
1512 $fn->($@);
1513 } elsif ($!) {
1514 $fn->($!);
1515 } else {
1516 $fn->("The detected tools didn't match the platform\n");
1517 }
1518 }
1519 last;
1520 }
1521}
1522
1523push @{$config{defines}}, "NDEBUG" if $config{build_type} eq "release";
1524
1525if ($target =~ /^mingw/ && `$config{CC} --target-help 2>&1` =~ m/-mno-cygwin/m)
1526 {
1527 push @{$config{cflags}}, "-mno-cygwin";
1528 push @{$config{cxxflags}}, "-mno-cygwin" if $config{CXX};
1529 push @{$config{shared_ldflag}}, "-mno-cygwin";
1530 }
1531
1532if ($target =~ /linux.*-mips/ && !$disabled{asm}
1533 && !grep { $_ =~ /-m(ips|arch=)/ } (@{$config{CFLAGS}})) {
1534 # minimally required architecture flags for assembly modules
1535 my $value;
1536 $value = '-mips2' if ($target =~ /mips32/);
1537 $value = '-mips3' if ($target =~ /mips64/);
1538 unshift @{$config{cflags}}, $value;
1539 unshift @{$config{cxxflags}}, $value if $config{CXX};
1540}
1541
1542# If threads aren't disabled, check how possible they are
1543unless ($disabled{threads}) {
1544 if ($auto_threads) {
1545 # Enabled by default, disable it forcibly if unavailable
1546 if ($target{thread_scheme} eq "(unknown)") {
1547 disable("unavailable", 'threads');
1548 }
1549 } else {
1550 # The user chose to enable threads explicitly, let's see
1551 # if there's a chance that's possible
1552 if ($target{thread_scheme} eq "(unknown)") {
1553 # If the user asked for "threads" and we don't have internal
1554 # knowledge how to do it, [s]he is expected to provide any
1555 # system-dependent compiler options that are necessary. We
1556 # can't truly check that the given options are correct, but
1557 # we expect the user to know what [s]He is doing.
1558 if (!@{$config{CFLAGS}} && !@{$config{CPPDEFINES}}) {
1559 die "You asked for multi-threading support, but didn't\n"
1560 ,"provide any system-specific compiler options\n";
1561 }
1562 }
1563 }
1564}
1565
1566# Find out if clang's sanitizers have been enabled with -fsanitize
1567# flags and ensure that the corresponding %disabled elements area
1568# removed to reflect that the sanitizers are indeed enabled.
1569my %detected_sanitizers = ();
1570foreach (grep /^-fsanitize=/, @{$config{CFLAGS} || []}) {
1571 (my $checks = $_) =~ s/^-fsanitize=//;
1572 foreach (split /,/, $checks) {
1573 my $d = { address => 'asan',
1574 undefined => 'ubsan',
1575 memory => 'msan' } -> {$_};
1576 next unless defined $d;
1577
1578 $detected_sanitizers{$d} = 1;
1579 if (defined $disabled{$d}) {
1580 die "***** Conflict between disabling $d and enabling $_ sanitizer"
1581 if $disabled{$d} ne "default";
1582 delete $disabled{$d};
1583 }
1584 }
1585}
1586
1587# If threads still aren't disabled, add a C macro to ensure the source
1588# code knows about it. Any other flag is taken care of by the configs.
1589unless($disabled{threads}) {
1590 push @{$config{openssl_feature_defines}}, "OPENSSL_THREADS";
1591}
1592
1593if ($disabled{"unstable-qlog"}) {
1594 $disabled{"qlog"} = 1;
1595}
1596
1597my $no_shared_warn=0;
1598if (($target{shared_target} // '') eq "")
1599 {
1600 $no_shared_warn = 1
1601 if (!$disabled{shared} || !$disabled{"dynamic-engine"});
1602 disable('no-shared-target', 'pic');
1603 }
1604
1605if ($disabled{"dynamic-engine"}) {
1606 $config{dynamic_engines} = 0;
1607} else {
1608 $config{dynamic_engines} = 1;
1609}
1610
1611unless ($disabled{asan} || defined $detected_sanitizers{asan}) {
1612 push @{$config{cflags}}, "-fsanitize=address";
1613}
1614
1615unless ($disabled{ubsan} || defined $detected_sanitizers{ubsan}) {
1616 push @{$config{cflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all", "-DPEDANTIC";
1617}
1618
1619unless ($disabled{msan} || defined $detected_sanitizers{msan}) {
1620 push @{$config{cflags}}, "-fsanitize=memory";
1621}
1622
1623unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
1624 && $disabled{asan} && $disabled{ubsan} && $disabled{msan}) {
1625 push @{$config{cflags}}, "-fno-omit-frame-pointer", "-g";
1626 push @{$config{cxxflags}}, "-fno-omit-frame-pointer", "-g" if $config{CXX};
1627}
1628#
1629# Platform fix-ups
1630#
1631
1632# This saves the build files from having to check
1633if ($disabled{pic})
1634 {
1635 foreach (qw(shared_cflag shared_cxxflag shared_cppflag
1636 shared_defines shared_includes shared_ldflag
1637 module_cflags module_cxxflags module_cppflags
1638 module_defines module_includes module_lflags))
1639 {
1640 delete $config{$_};
1641 $target{$_} = "";
1642 }
1643 }
1644else
1645 {
1646 push @{$config{lib_defines}}, "OPENSSL_PIC";
1647 }
1648
1649if ($target{sys_id} ne "")
1650 {
1651 push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}";
1652 }
1653
1654my %predefined_C = compiler_predefined($config{CROSS_COMPILE}.$config{CC});
1655my %predefined_CXX = $config{CXX}
1656 ? compiler_predefined($config{CROSS_COMPILE}.$config{CXX})
1657 : ();
1658
1659unless ($disabled{asm}) {
1660 # big endian systems can use ELFv2 ABI
1661 if ($target eq "linux-ppc64" || $target eq "BSD-ppc64") {
1662 $target{perlasm_scheme} = "linux64v2" if ($predefined_C{_CALL_ELF} == 2);
1663 }
1664}
1665
1666# Check for makedepend capabilities.
1667if (!$disabled{makedepend}) {
1668 # If the attribute makedep_scheme is defined, then we assume that the
1669 # config target and its associated build file are programmed to deal
1670 # with it.
1671 # If makedep_scheme is undefined, we go looking for GCC compatible
1672 # dependency making, and if that's not available, we try to fall back
1673 # on 'makedepend'.
1674 if ($target{makedep_scheme}) {
1675 $config{makedep_scheme} = $target{makedep_scheme};
1676 # If the makedepcmd attribute is defined, copy it. If not, the
1677 # build files will have to fend for themselves.
1678 $config{makedepcmd} = $target{makedepcmd} if $target{makedepcmd};
1679 } elsif (($predefined_C{__GNUC__} // -1) >= 3
1680 && !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) {
1681 # We know that GNU C version 3 and up as well as all clang
1682 # versions support dependency generation, but Xcode did not
1683 # handle $cc -M before clang support (but claims __GNUC__ = 3)
1684 $config{makedep_scheme} = 'gcc';
1685 } else {
1686 # In all other cases, we look for 'makedepend', and set the
1687 # makedep_scheme value if we found it.
1688 $config{makedepcmd} = which('makedepend');
1689 $config{makedep_scheme} = 'makedepend' if $config{makedepcmd};
1690 }
1691
1692 # If no depend scheme is set, we disable makedepend
1693 disable('unavailable', 'makedepend') unless $config{makedep_scheme};
1694}
1695
1696if (!$disabled{asm} && !$predefined_C{__MACH__} && $^O ne 'VMS' && !$predefined_C{_AIX}) {
1697 # probe for -Wa,--noexecstack option...
1698 if ($predefined_C{__clang__}) {
1699 # clang has builtin assembler, which doesn't recognize --help,
1700 # but it apparently recognizes the option in question on all
1701 # supported platforms even when it's meaningless. In other words
1702 # probe would fail, but probed option always accepted...
1703 push @{$config{cflags}}, "-Wa,--noexecstack", "-Qunused-arguments";
1704 } else {
1705 my $cc = $config{CROSS_COMPILE}.$config{CC};
1706 open(PIPE, "$cc -Wa,--help -c -o null.$$.o -x assembler /dev/null 2>&1 |");
1707 while(<PIPE>) {
1708 if (m/--noexecstack/) {
1709 push @{$config{cflags}}, "-Wa,--noexecstack";
1710 last;
1711 }
1712 }
1713 close(PIPE);
1714 unlink("null.$$.o");
1715 }
1716}
1717
1718# Deal with bn_ops ###################################################
1719
1720$config{bn_ll} =0;
1721my $def_int="unsigned int";
1722$config{rc4_int} =$def_int;
1723($config{b64l},$config{b64},$config{b32})=(0,0,1);
1724
1725my $count = 0;
1726foreach (sort split(/\s+/,$target{bn_ops})) {
1727 $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/;
1728 $config{bn_ll}=1 if $_ eq 'BN_LLONG';
1729 $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR';
1730 ($config{b64l},$config{b64},$config{b32})
1731 =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT';
1732 ($config{b64l},$config{b64},$config{b32})
1733 =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG';
1734 ($config{b64l},$config{b64},$config{b32})
1735 =(0,0,1) if $_ eq 'THIRTY_TWO_BIT';
1736}
1737die "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n"
1738 if $count > 1;
1739
1740$config{api} = $config{major} * 10000 + $config{minor} * 100
1741 unless $config{api};
1742foreach (keys %$apitable) {
1743 $disabled{"deprecated-$_"} = "deprecation"
1744 if $disabled{deprecated} && $config{api} >= $apitable->{$_};
1745}
1746
1747disable(); # Run a cascade now
1748
1749# Hack cflags for better warnings (dev option) #######################
1750
1751# "Stringify" the C and C++ flags string. This permits it to be made part of
1752# a string and works as well on command lines.
1753$config{cflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x }
1754 @{$config{cflags}} ];
1755$config{cxxflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x }
1756 @{$config{cxxflags}} ] if $config{CXX};
1757
1758$config{openssl_api_defines} = [
1759 "OPENSSL_CONFIGURED_API=".$config{api},
1760];
1761
1762my @strict_warnings_collection=();
1763if ($strict_warnings)
1764 {
1765 my $wopt;
1766 my $gccver = $predefined_C{__GNUC__} // -1;
1767
1768 if ($gccver >= 4)
1769 {
1770 push @strict_warnings_collection, @gcc_devteam_warn;
1771 push @strict_warnings_collection, @clang_devteam_warn
1772 if (defined($predefined_C{__clang__}));
1773 }
1774 elsif ($config{target} =~ /^VC-/)
1775 {
1776 push @strict_warnings_collection, @cl_devteam_warn;
1777 }
1778 else
1779 {
1780 warn "WARNING --strict-warnings requires gcc[>=4] or gcc-alike, or MSVC"
1781 }
1782 }
1783
1784$config{CFLAGS} = [ map { $_ eq '--ossl-strict-warnings'
1785 ? @strict_warnings_collection
1786 : ( $_ ) }
1787 @{$config{CFLAGS}} ];
1788
1789unless ($disabled{afalgeng}) {
1790 $config{afalgeng}="";
1791 if (grep { $_ eq 'afalgeng' } @{$target{enable}}) {
1792 push @{$config{engdirs}}, "afalg";
1793 } else {
1794 disable('not-linux', 'afalgeng');
1795 }
1796}
1797
1798unless ($disabled{devcryptoeng}) {
1799 if ($target =~ m/^BSD/) {
1800 my $maxver = 5*100 + 7;
1801 my $sysstr = `uname -s`;
1802 my $verstr = `uname -r`;
1803 $sysstr =~ s|\R$||;
1804 $verstr =~ s|\R$||;
1805 my ($ma, $mi, @rest) = split m|\.|, $verstr;
1806 my $ver = $ma*100 + $mi;
1807 if ($sysstr eq 'OpenBSD' && $ver >= $maxver) {
1808 disable('too-new-kernel', 'devcryptoeng');
1809 }
1810 }
1811}
1812
1813unless ($disabled{ktls}) {
1814 $config{ktls}="";
1815 my $cc = $config{CROSS_COMPILE}.$config{CC};
1816 if ($target =~ m/^linux/) {
1817 system("printf '#include <sys/types.h>\n#include <linux/tls.h>' | $cc -E - >/dev/null 2>&1");
1818 if ($? != 0) {
1819 disable('too-old-kernel', 'ktls');
1820 }
1821 } elsif ($target =~ m/^BSD/) {
1822 system("printf '#include <sys/types.h>\n#include <sys/ktls.h>' | $cc -E - >/dev/null 2>&1");
1823 if ($? != 0) {
1824 disable('too-old-freebsd', 'ktls');
1825 }
1826 } else {
1827 disable('not-linux-or-freebsd', 'ktls');
1828 }
1829}
1830
1831unless ($disabled{winstore}) {
1832 unless ($target =~ /^(?:Cygwin|mingw|VC-|BC-)/) {
1833 disable('not-windows', 'winstore');
1834 }
1835}
1836
1837push @{$config{openssl_other_defines}}, "OPENSSL_NO_KTLS" if ($disabled{ktls});
1838
1839# Get the extra flags used when building shared libraries and modules. We
1840# do this late because some of them depend on %disabled.
1841
1842# Make the flags to build DSOs the same as for shared libraries unless they
1843# are already defined
1844$target{module_cflags} = $target{shared_cflag} unless defined $target{module_cflags};
1845$target{module_cxxflags} = $target{shared_cxxflag} unless defined $target{module_cxxflags};
1846$target{module_ldflags} = $target{shared_ldflag} unless defined $target{module_ldflags};
1847{
1848 my $shared_info_pl =
1849 catfile(dirname($0), "Configurations", "shared-info.pl");
1850 my %shared_info = read_eval_file($shared_info_pl);
1851 push @{$target{_conf_fname_int}}, $shared_info_pl;
1852 my $si = $target{shared_target};
1853 while (ref $si ne "HASH") {
1854 last if ! defined $si;
1855 if (ref $si eq "CODE") {
1856 $si = $si->();
1857 } else {
1858 $si = $shared_info{$si};
1859 }
1860 }
1861
1862 # Some of the 'shared_target' values don't have any entries in
1863 # %shared_info. That's perfectly fine, AS LONG AS the build file
1864 # template knows how to handle this. That is currently the case for
1865 # Windows and VMS.
1866 if (defined $si) {
1867 # Just as above, copy certain shared_* attributes to the corresponding
1868 # module_ attribute unless the latter is already defined
1869 $si->{module_cflags} = $si->{shared_cflag} unless defined $si->{module_cflags};
1870 $si->{module_cxxflags} = $si->{shared_cxxflag} unless defined $si->{module_cxxflags};
1871 $si->{module_ldflags} = $si->{shared_ldflag} unless defined $si->{module_ldflags};
1872 foreach (sort keys %$si) {
1873 $target{$_} = defined $target{$_}
1874 ? add($si->{$_})->($target{$_})
1875 : $si->{$_};
1876 }
1877 }
1878}
1879
1880# ALL MODIFICATIONS TO %disabled, %config and %target MUST BE DONE FROM HERE ON
1881
1882######################################################################
1883# Build up information for skipping certain directories depending on disabled
1884# features, as well as setting up macros for disabled features.
1885
1886# This is a tentative database of directories to skip. Some entries may not
1887# correspond to anything real, but that's ok, they will simply be ignored.
1888# The actual processing of these entries is done in the build.info lookup
1889# loop further down.
1890#
1891# The key is a Unix formatted path in the source tree, the value is an index
1892# into %disabled_info, so any existing path gets added to a corresponding
1893# 'skipped' entry in there with the list of skipped directories.
1894my %skipdir = ();
1895my %disabled_info = (); # For configdata.pm
1896foreach my $what (sort keys %disabled) {
1897 # There are deprecated disablables that translate to themselves.
1898 # They cause disabling cascades, but should otherwise not register.
1899 next if $deprecated_disablables{$what};
1900 # The generated $disabled{"deprecated-x.y"} entries are special
1901 # and treated properly elsewhere
1902 next if $what =~ m|^deprecated-|;
1903
1904 $config{options} .= " no-$what";
1905
1906 if (!grep { $what eq $_ } ( 'buildtest-c++', 'fips', 'threads', 'shared',
1907 'module', 'pic', 'dynamic-engine', 'makedepend',
1908 'sse2', 'legacy' )) {
1909 (my $WHAT = uc $what) =~ s|-|_|g;
1910 my $skipdir = $what;
1911
1912 # fix-up crypto/directory name(s)
1913 $skipdir = "ripemd" if $what eq "rmd160";
1914 $skipdir = "whrlpool" if $what eq "whirlpool";
1915
1916 my $macro = $disabled_info{$what}->{macro} = "OPENSSL_NO_$WHAT";
1917 push @{$config{openssl_feature_defines}}, $macro;
1918
1919 $skipdir{engines} = $what if $what eq 'engine';
1920 $skipdir{"crypto/$skipdir"} = $what
1921 unless $what eq 'async' || $what eq 'err' || $what eq 'dso';
1922 }
1923}
1924
1925if ($disabled{"dynamic-engine"}) {
1926 push @{$config{openssl_feature_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE";
1927} else {
1928 push @{$config{openssl_feature_defines}}, "OPENSSL_NO_STATIC_ENGINE";
1929}
1930
1931# If we use the unified build, collect information from build.info files
1932my %unified_info = ();
1933
1934my $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO});
1935if ($builder eq "unified") {
1936 use Text::Template 1.46;
1937
1938 sub cleandir {
1939 my $base = shift;
1940 my $dir = shift;
1941 my $relativeto = shift || ".";
1942 my $no_mkpath = shift // 0;
1943
1944 $dir = catdir($base,$dir) unless isabsolute($dir);
1945
1946 # Make sure the directories we're building in exists
1947 mkpath($dir) unless $no_mkpath;
1948
1949 my $res = abs2rel(absolutedir($dir), rel2abs($relativeto));
1950 #print STDERR "DEBUG[cleandir]: $dir , $base => $res\n";
1951 return $res;
1952 }
1953
1954 sub cleanfile {
1955 my $base = shift;
1956 my $file = shift;
1957 my $relativeto = shift || ".";
1958 my $no_mkpath = shift // 0;
1959
1960 $file = catfile($base,$file) unless isabsolute($file);
1961
1962 my $d = dirname($file);
1963 my $f = basename($file);
1964
1965 # Make sure the directories we're building in exists
1966 mkpath($d) unless $no_mkpath;
1967
1968 my $res = abs2rel(catfile(absolutedir($d), $f), rel2abs($relativeto));
1969 #print STDERR "DEBUG[cleanfile]: $d , $f => $res\n";
1970 return $res;
1971 }
1972
1973 # Store the name of the template file we will build the build file from
1974 # in %config. This may be useful for the build file itself.
1975 my @build_file_template_names =
1976 ( $builder_platform."-".$config{build_file}.".tmpl",
1977 $config{build_file}.".tmpl" );
1978 my @build_file_templates = ();
1979
1980 # First, look in the user provided directory, if given
1981 if (defined env($local_config_envname)) {
1982 @build_file_templates =
1983 map {
1984 if ($^O eq 'VMS') {
1985 # VMS environment variables are logical names,
1986 # which can be used as is
1987 $local_config_envname . ':' . $_;
1988 } else {
1989 catfile(env($local_config_envname), $_);
1990 }
1991 }
1992 @build_file_template_names;
1993 }
1994 # Then, look in our standard directory
1995 push @build_file_templates,
1996 ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir, 1) }
1997 @build_file_template_names );
1998
1999 my $build_file_template;
2000 for $_ (@build_file_templates) {
2001 $build_file_template = $_;
2002 last if -f $build_file_template;
2003
2004 $build_file_template = undef;
2005 }
2006 if (!defined $build_file_template) {
2007 die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n";
2008 }
2009 $config{build_file_templates}
2010 = [ cleanfile($srcdir, catfile("Configurations", "common0.tmpl"),
2011 $blddir, 1),
2012 $build_file_template ];
2013
2014 my @build_dirs = ( [ ] ); # current directory
2015
2016 $config{build_infos} = [ ];
2017
2018 # We want to detect configdata.pm in the source tree, so we
2019 # don't use it if the build tree is different.
2020 my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir, 1);
2021
2022 # Any source file that we recognise is placed in this hash table, with
2023 # the list of its intended destinations as value. When everything has
2024 # been collected, there's a routine that checks that these source files
2025 # exist, or if they are generated, that the generator exists.
2026 my %check_exist = ();
2027 my %check_generate = ();
2028
2029 my %ordinals = ();
2030 while (@build_dirs) {
2031 my @curd = @{shift @build_dirs};
2032 my $sourced = catdir($srcdir, @curd);
2033 my $buildd = catdir($blddir, @curd);
2034
2035 my $unixdir = join('/', @curd);
2036 if (exists $skipdir{$unixdir}) {
2037 my $what = $skipdir{$unixdir};
2038 push @{$disabled_info{$what}->{skipped}}, catdir(@curd);
2039 next;
2040 }
2041
2042 mkpath($buildd);
2043
2044 my $f = 'build.info';
2045 # The basic things we're trying to build
2046 my @programs = ();
2047 my @libraries = ();
2048 my @modules = ();
2049 my @scripts = ();
2050
2051 my %sources = ();
2052 my %shared_sources = ();
2053 my %includes = ();
2054 my %defines = ();
2055 my %depends = ();
2056 my %generate = ();
2057 my %imagedocs = ();
2058 my %htmldocs = ();
2059 my %mandocs = ();
2060
2061 # Support for $variablename in build.info files.
2062 # Embedded perl code is the ultimate master, still. If its output
2063 # contains a dollar sign, it had better be escaped, or it will be
2064 # taken for a variable name prefix.
2065 my %variables = ();
2066 # Variable name syntax
2067 my $variable_name_re = qr/(?P<VARIABLE>[[:alpha:]][[:alnum:]_]*)/;
2068 # Value modifier syntaxes
2069 my $variable_subst_re = qr/\/(?P<RE>(?:\\\/|.)*?)\/(?P<SUBST>.*?)/;
2070 # Variable reference
2071 my $variable_simple_re = qr/(?<!\\)\$${variable_name_re}/;
2072 my $variable_w_mod_re =
2073 qr/(?<!\\)\$\{${variable_name_re}(?P<MOD>(?:\\\/|.)*?)\}/;
2074 # Tie it all together
2075 my $variable_re = qr/${variable_simple_re}|${variable_w_mod_re}/;
2076
2077 my $expand_variables = sub {
2078 my $value = '';
2079 my $value_rest = shift;
2080
2081 if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) {
2082 print STDERR
2083 "DEBUG[\$expand_variables] Parsed '$value_rest' ...\n"
2084 }
2085
2086 while ($value_rest =~ /${variable_re}/) {
2087 # We must save important regexp values, because the next
2088 # regexp clears them
2089 my $mod = $+{MOD};
2090 my $variable_value = $variables{$+{VARIABLE}};
2091
2092 $value_rest = $';
2093 $value .= $`;
2094
2095 # Process modifier expressions, if present
2096 if (defined $mod) {
2097 if ($mod =~ /^${variable_subst_re}$/) {
2098 my $re = $+{RE};
2099 my $subst = $+{SUBST};
2100
2101 $variable_value =~ s/\Q$re\E/$subst/g;
2102
2103 if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) {
2104 print STDERR
2105 "DEBUG[\$expand_variables] ... and substituted ",
2106 "'$re' with '$subst'\n";
2107 }
2108 }
2109 }
2110
2111 $value .= $variable_value;
2112 }
2113 if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) {
2114 print STDERR
2115 "DEBUG[\$expand_variables] ... into: '$value$value_rest'\n";
2116 }
2117 return $value . $value_rest;
2118 };
2119
2120 # Support for attributes in build.info files
2121 my %attributes = ();
2122 my $handle_attributes = sub {
2123 my $attr_str = shift;
2124 my $ref = shift;
2125 my @goals = @_;
2126
2127 return unless defined $attr_str;
2128
2129 my @a = tokenize($attr_str, qr|\s*,\s*|);
2130 foreach my $a (@a) {
2131 my $ac = 1;
2132 my $ak = $a;
2133 my $av = 1;
2134 if ($a =~ m|^(!)?(.*?)\s* = \s*(.*?)$|x) {
2135 $ac = ! $1;
2136 $ak = $2;
2137 $av = $3;
2138 }
2139 foreach my $g (@goals) {
2140 if ($ac) {
2141 $$ref->{$g}->{$ak} = $av;
2142 } else {
2143 delete $$ref->{$g}->{$ak};
2144 }
2145 }
2146 }
2147 };
2148
2149 # Support for pushing values on multiple indexes of a given hash
2150 # array.
2151 my $push_to = sub {
2152 my $valueref = shift;
2153 my $index_str = shift; # May be undef or empty
2154 my $attrref = shift; # May be undef
2155 my $attr_str = shift;
2156 my @values = @_;
2157
2158 if (defined $index_str) {
2159 my @indexes = ( '' );
2160 if ($index_str !~ m|^\s*$|) {
2161 @indexes = tokenize($index_str);
2162 }
2163 foreach (@indexes) {
2164 push @{$valueref->{$_}}, @values;
2165 if (defined $attrref) {
2166 $handle_attributes->($attr_str, \$$attrref->{$_},
2167 @values);
2168 }
2169 }
2170 } else {
2171 push @$valueref, @values;
2172 $handle_attributes->($attr_str, $attrref, @values)
2173 if defined $attrref;
2174 }
2175 };
2176
2177 if ($buildinfo_debug) {
2178 print STDERR "DEBUG: Reading ",catfile($sourced, $f),"\n";
2179 }
2180 push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f);
2181 my $template =
2182 Text::Template->new(TYPE => 'FILE',
2183 SOURCE => catfile($sourced, $f),
2184 PREPEND => qq{use lib "$FindBin::Bin/util/perl";});
2185 die "Something went wrong with $sourced/$f: $!\n" unless $template;
2186 my @text =
2187 split /^/m,
2188 $template->fill_in(HASH => { config => \%config,
2189 target => \%target,
2190 disabled => \%disabled,
2191 withargs => \%withargs,
2192 builddir => abs2rel($buildd, $blddir),
2193 sourcedir => abs2rel($sourced, $blddir),
2194 buildtop => abs2rel($blddir, $blddir),
2195 sourcetop => abs2rel($srcdir, $blddir) },
2196 DELIMITERS => [ "{-", "-}" ]);
2197
2198 # The top item of this stack has the following values
2199 # -2 positive already run and we found ELSE (following ELSIF should fail)
2200 # -1 positive already run (skip until ENDIF)
2201 # 0 negatives so far (if we're at a condition, check it)
2202 # 1 last was positive (don't skip lines until next ELSE, ELSIF or ENDIF)
2203 # 2 positive ELSE (following ELSIF should fail)
2204 my @skip = ();
2205
2206 # A few useful generic regexps
2207 my $index_re = qr/\[\s*(?P<INDEX>(?:\\.|.)*?)\s*\]/;
2208 my $cond_re = qr/\[\s*(?P<COND>(?:\\.|.)*?)\s*\]/;
2209 my $attribs_re = qr/(?:\{\s*(?P<ATTRIBS>(?:\\.|.)*?)\s*\})?/;
2210 my $value_re = qr/(?P<VALUE>.*?)/;
2211 collect_information(
2212 collect_from_array([ @text ],
2213 qr/\\$/ => sub { my $l1 = shift; my $l2 = shift;
2214 $l1 =~ s/\\$//; $l1.$l2 }),
2215 # Info we're looking for
2216 qr/^\s* IF ${cond_re} \s*$/x
2217 => sub {
2218 if (! @skip || $skip[$#skip] > 0) {
2219 push @skip, !! $expand_variables->($+{COND});
2220 } else {
2221 push @skip, -1;
2222 }
2223 },
2224 qr/^\s* ELSIF ${cond_re} \s*$/x
2225 => sub { die "ELSIF out of scope" if ! @skip;
2226 die "ELSIF following ELSE" if abs($skip[$#skip]) == 2;
2227 $skip[$#skip] = -1 if $skip[$#skip] != 0;
2228 $skip[$#skip] = !! $expand_variables->($+{COND})
2229 if $skip[$#skip] == 0; },
2230 qr/^\s* ELSE \s*$/x
2231 => sub { die "ELSE out of scope" if ! @skip;
2232 $skip[$#skip] = -2 if $skip[$#skip] != 0;
2233 $skip[$#skip] = 2 if $skip[$#skip] == 0; },
2234 qr/^\s* ENDIF \s*$/x
2235 => sub { die "ENDIF out of scope" if ! @skip;
2236 pop @skip; },
2237 qr/^\s* ${variable_re} \s* = \s* ${value_re} \s* $/x
2238 => sub {
2239 if (!@skip || $skip[$#skip] > 0) {
2240 $variables{$+{VARIABLE}} = $expand_variables->($+{VALUE});
2241 }
2242 },
2243 qr/^\s* SUBDIRS \s* = \s* ${value_re} \s* $/x
2244 => sub {
2245 if (!@skip || $skip[$#skip] > 0) {
2246 foreach (tokenize($expand_variables->($+{VALUE}))) {
2247 push @build_dirs, [ @curd, splitdir($_, 1) ];
2248 }
2249 }
2250 },
2251 qr/^\s* PROGRAMS ${attribs_re} \s* = \s* ${value_re} \s* $/x
2252 => sub { $push_to->(\@programs, undef,
2253 \$attributes{programs}, $+{ATTRIBS},
2254 tokenize($expand_variables->($+{VALUE})))
2255 if !@skip || $skip[$#skip] > 0; },
2256 qr/^\s* LIBS ${attribs_re} \s* = \s* ${value_re} \s* $/x
2257 => sub { $push_to->(\@libraries, undef,
2258 \$attributes{libraries}, $+{ATTRIBS},
2259 tokenize($expand_variables->($+{VALUE})))
2260 if !@skip || $skip[$#skip] > 0; },
2261 qr/^\s* MODULES ${attribs_re} \s* = \s* ${value_re} \s* $/x
2262 => sub { $push_to->(\@modules, undef,
2263 \$attributes{modules}, $+{ATTRIBS},
2264 tokenize($expand_variables->($+{VALUE})))
2265 if !@skip || $skip[$#skip] > 0; },
2266 qr/^\s* SCRIPTS ${attribs_re} \s* = \s* ${value_re} \s* $/x
2267 => sub { $push_to->(\@scripts, undef,
2268 \$attributes{scripts}, $+{ATTRIBS},
2269 tokenize($expand_variables->($+{VALUE})))
2270 if !@skip || $skip[$#skip] > 0; },
2271 qr/^\s* IMAGEDOCS ${index_re} \s* = \s* ${value_re} \s* $/x
2272 => sub { $push_to->(\%imagedocs, $expand_variables->($+{INDEX}),
2273 undef, undef,
2274 tokenize($expand_variables->($+{VALUE})))
2275 if !@skip || $skip[$#skip] > 0; },
2276 qr/^\s* HTMLDOCS ${index_re} \s* = \s* ${value_re} \s* $/x
2277 => sub { $push_to->(\%htmldocs, $expand_variables->($+{INDEX}),
2278 undef, undef,
2279 tokenize($expand_variables->($+{VALUE})))
2280 if !@skip || $skip[$#skip] > 0; },
2281 qr/^\s* MANDOCS ${index_re} \s* = \s* ${value_re} \s* $/x
2282 => sub { $push_to->(\%mandocs, $expand_variables->($+{INDEX}),
2283 undef, undef,
2284 tokenize($expand_variables->($+{VALUE})))
2285 if !@skip || $skip[$#skip] > 0; },
2286 qr/^\s* SOURCE ${index_re} ${attribs_re} \s* = \s* ${value_re} \s* $/x
2287 => sub { $push_to->(\%sources, $expand_variables->($+{INDEX}),
2288 \$attributes{sources}, $+{ATTRIBS},
2289 tokenize($expand_variables->($+{VALUE})))
2290 if !@skip || $skip[$#skip] > 0; },
2291 qr/^\s* SHARED_SOURCE ${index_re} ${attribs_re} \s* = \s* ${value_re} \s* $/x
2292 => sub { $push_to->(\%shared_sources, $expand_variables->($+{INDEX}),
2293 \$attributes{sources}, $+{ATTRIBS},
2294 tokenize($expand_variables->($+{VALUE})))
2295 if !@skip || $skip[$#skip] > 0; },
2296 qr/^\s* INCLUDE ${index_re} \s* = \s* ${value_re} \s* $/x
2297 => sub { $push_to->(\%includes, $expand_variables->($+{INDEX}),
2298 undef, undef,
2299 tokenize($expand_variables->($+{VALUE})))
2300 if !@skip || $skip[$#skip] > 0; },
2301 qr/^\s* DEFINE ${index_re} \s* = \s* ${value_re} \s* $/x
2302 => sub { $push_to->(\%defines, $expand_variables->($+{INDEX}),
2303 undef, undef,
2304 tokenize($expand_variables->($+{VALUE})))
2305 if !@skip || $skip[$#skip] > 0; },
2306 qr/^\s* DEPEND ${index_re} ${attribs_re} \s* = \s* ${value_re} \s* $/x
2307 => sub { $push_to->(\%depends, $expand_variables->($+{INDEX}),
2308 \$attributes{depends}, $+{ATTRIBS},
2309 tokenize($expand_variables->($+{VALUE})))
2310 if !@skip || $skip[$#skip] > 0; },
2311 qr/^\s* GENERATE ${index_re} ${attribs_re} \s* = \s* ${value_re} \s* $/x
2312 => sub { $push_to->(\%generate, $expand_variables->($+{INDEX}),
2313 \$attributes{generate}, $+{ATTRIBS},
2314 $expand_variables->($+{VALUE}))
2315 if !@skip || $skip[$#skip] > 0; },
2316 qr/^\s* (?:\#.*)? $/x => sub { },
2317 "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" },
2318 "BEFORE" => sub {
2319 if ($buildinfo_debug) {
2320 print STDERR "DEBUG: Parsing ",join(" ", @_),"\n";
2321 print STDERR "DEBUG: ... before parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
2322 }
2323 },
2324 "AFTER" => sub {
2325 if ($buildinfo_debug) {
2326 print STDERR "DEBUG: .... after parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n";
2327 }
2328 },
2329 );
2330 die "runaway IF?" if (@skip);
2331
2332 if (grep { defined $attributes{modules}->{$_}->{engine} } keys %attributes
2333 and !$config{dynamic_engines}) {
2334 die <<"EOF"
2335ENGINES can only be used if configured with 'dynamic-engine'.
2336This is usually a fault in a build.info file.
2337EOF
2338 }
2339
2340 {
2341 my %infos = ( programs => [ @programs ],
2342 libraries => [ @libraries ],
2343 modules => [ @modules ],
2344 scripts => [ @scripts ] );
2345 foreach my $k (keys %infos) {
2346 foreach (@{$infos{$k}}) {
2347 my $item = cleanfile($buildd, $_, $blddir);
2348 $unified_info{$k}->{$item} = 1;
2349
2350 # Fix up associated attributes
2351 $unified_info{attributes}->{$k}->{$item} =
2352 $attributes{$k}->{$_}
2353 if defined $attributes{$k}->{$_};
2354 }
2355 }
2356 }
2357
2358 # Check that we haven't defined any library as both shared and
2359 # explicitly static. That is forbidden.
2360 my @doubles = ();
2361 foreach (grep /\.a$/, keys %{$unified_info{libraries}}) {
2362 (my $l = $_) =~ s/\.a$//;
2363 push @doubles, $l if defined $unified_info{libraries}->{$l};
2364 }
2365 die "these libraries are both explicitly static and shared:\n ",
2366 join(" ", @doubles), "\n"
2367 if @doubles;
2368
2369 foreach (keys %sources) {
2370 my $dest = $_;
2371 my $ddest = cleanfile($buildd, $_, $blddir);
2372 foreach (@{$sources{$dest}}) {
2373 my $s = cleanfile($sourced, $_, $blddir, 1);
2374
2375 # If it's generated or we simply don't find it in the source
2376 # tree, we assume it's in the build tree.
2377 if ($s eq $src_configdata || $generate{$_} || ! -f $s) {
2378 $s = cleanfile($buildd, $_, $blddir);
2379 }
2380 my $o = $_;
2381 # We recognise C++, C and asm files
2382 if ($s =~ /\.(cc|cpp|c|s|S)$/) {
2383 push @{$check_exist{$s}}, $ddest;
2384 $o =~ s/\.[csS]$/.o/; # C and assembler
2385 $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
2386 $o = cleanfile($buildd, $o, $blddir);
2387 $unified_info{sources}->{$ddest}->{$o} = -1;
2388 $unified_info{sources}->{$o}->{$s} = -1;
2389 } elsif ($s =~ /\.rc$/) {
2390 # We also recognise resource files
2391 push @{$check_exist{$s}}, $ddest;
2392 $o =~ s/\.rc$/.res/; # Resource configuration
2393 $o = cleanfile($buildd, $o, $blddir);
2394 $unified_info{sources}->{$ddest}->{$o} = -1;
2395 $unified_info{sources}->{$o}->{$s} = -1;
2396 } else {
2397 push @{$check_exist{$s}}, $ddest;
2398 $unified_info{sources}->{$ddest}->{$s} = 1;
2399 }
2400 # Fix up associated attributes
2401 if ($o ne $_) {
2402 $unified_info{attributes}->{sources}->{$ddest}->{$o} =
2403 $unified_info{attributes}->{sources}->{$o}->{$s} =
2404 $attributes{sources}->{$dest}->{$_}
2405 if defined $attributes{sources}->{$dest}->{$_};
2406 } else {
2407 $unified_info{attributes}->{sources}->{$ddest}->{$s} =
2408 $attributes{sources}->{$dest}->{$_}
2409 if defined $attributes{sources}->{$dest}->{$_};
2410 }
2411 }
2412 }
2413
2414 foreach (keys %shared_sources) {
2415 my $dest = $_;
2416 my $ddest = cleanfile($buildd, $_, $blddir);
2417 foreach (@{$shared_sources{$dest}}) {
2418 my $s = cleanfile($sourced, $_, $blddir, 1);
2419
2420 # If it's generated or we simply don't find it in the source
2421 # tree, we assume it's in the build tree.
2422 if ($s eq $src_configdata || $generate{$_} || ! -f $s) {
2423 $s = cleanfile($buildd, $_, $blddir);
2424 }
2425
2426 my $o = $_;
2427 if ($s =~ /\.(cc|cpp|c|s|S)$/) {
2428 # We recognise C++, C and asm files
2429 push @{$check_exist{$s}}, $ddest;
2430 $o =~ s/\.[csS]$/.o/; # C and assembler
2431 $o =~ s/\.(cc|cpp)$/_cc.o/; # C++
2432 $o = cleanfile($buildd, $o, $blddir);
2433 $unified_info{shared_sources}->{$ddest}->{$o} = -1;
2434 $unified_info{sources}->{$o}->{$s} = -1;
2435 } elsif ($s =~ /\.rc$/) {
2436 # We also recognise resource files
2437 push @{$check_exist{$s}}, $ddest;
2438 $o =~ s/\.rc$/.res/; # Resource configuration
2439 $o = cleanfile($buildd, $o, $blddir);
2440 $unified_info{shared_sources}->{$ddest}->{$o} = -1;
2441 $unified_info{sources}->{$o}->{$s} = -1;
2442 } elsif ($s =~ /\.ld$/) {
2443 # We also recognise linker scripts (or corresponding)
2444 # We know they are generated files
2445 push @{$check_exist{$s}}, $ddest;
2446 $o = cleanfile($buildd, $_, $blddir);
2447 $unified_info{shared_sources}->{$ddest}->{$o} = 1;
2448 } else {
2449 die "unrecognised source file type for shared library: $s\n";
2450 }
2451 # Fix up associated attributes
2452 if ($o ne $_) {
2453 $unified_info{attributes}->{shared_sources}->{$ddest}->{$o} =
2454 $unified_info{attributes}->{sources}->{$o}->{$s} =
2455 $attributes{sources}->{$dest}->{$_}
2456 if defined $attributes{sources}->{$dest}->{$_};
2457 } else {
2458 $unified_info{attributes}->{shared_sources}->{$ddest}->{$o} =
2459 $attributes{sources}->{$dest}->{$_}
2460 if defined $attributes{sources}->{$dest}->{$_};
2461 }
2462 }
2463 }
2464
2465 foreach (keys %generate) {
2466 my $dest = $_;
2467 my $ddest = cleanfile($buildd, $_, $blddir);
2468 die "more than one generator for $dest: "
2469 ,join(" ", @{$generate{$_}}),"\n"
2470 if scalar @{$generate{$_}} > 1;
2471 my @generator = split /\s+/, $generate{$dest}->[0];
2472 my $gen = $generator[0];
2473 $generator[0] = cleanfile($sourced, $gen, $blddir, 1);
2474
2475 # If the generator is itself generated, it's in the build tree
2476 if ($generate{$gen} || ! -f $generator[0]) {
2477 $generator[0] = cleanfile($buildd, $gen, $blddir);
2478 }
2479 $check_generate{$ddest}->{$generator[0]}++;
2480
2481 $unified_info{generate}->{$ddest} = [ @generator ];
2482 # Fix up associated attributes
2483 $unified_info{attributes}->{generate}->{$ddest} =
2484 $attributes{generate}->{$dest}->{$gen}
2485 if defined $attributes{generate}->{$dest}->{$gen};
2486 }
2487
2488 foreach (keys %depends) {
2489 my $dest = $_;
2490 my $ddest = $dest;
2491
2492 if ($dest =~ /^\|(.*)\|$/) {
2493 # Collect the raw target
2494 $unified_info{targets}->{$1} = 1;
2495 $ddest = $1;
2496 } elsif ($dest eq '') {
2497 $ddest = '';
2498 } else {
2499 $ddest = cleanfile($sourced, $dest, $blddir, 1);
2500
2501 # If the destination doesn't exist in source, it can only be
2502 # a generated file in the build tree.
2503 if ($ddest eq $src_configdata || ! -f $ddest) {
2504 $ddest = cleanfile($buildd, $dest, $blddir);
2505 }
2506 }
2507 foreach my $f (@{$depends{$dest}}) {
2508 # If the dependency destination is generated, dependencies
2509 # may have an extra syntax to separate the intended inclusion
2510 # directory from the module to be loaded: a | instead of a
2511 # / as directory separator.
2512 # Do note that this has to be handled in the build file
2513 # template as well.
2514 # $i = inclusion path in source directory
2515 # $i2 = inclusion path in build directory
2516 # $m = module path (within the inclusion path)
2517 # $i = full module path in source directory
2518 # $i2 = full module path in build directory
2519 my $i; my $i2; my $m; my $d; my $d2;
2520 if ($unified_info{generate}->{$ddest}
2521 && $f =~ m/^(.*?)\|(.*)$/) {
2522 $i = $1;
2523 $m = $2;
2524 # We must be very careful to modify $i last
2525 $d = cleanfile($sourced, "$i/$m", $blddir, 1);
2526 $d2 = cleanfile($buildd, "$i/$m", $blddir);
2527 $i2 = cleandir($buildd, $i, $blddir);
2528 $i = cleandir($sourced, $i, $blddir, 1);
2529 } else {
2530 $d = cleanfile($sourced, $f, $blddir, 1);
2531 $d2 = cleanfile($buildd, $f, $blddir);
2532 }
2533
2534 # If we know it's generated, or assume it is because we can't
2535 # find it in the source tree, we set file we depend on to be
2536 # in the build tree rather than the source tree.
2537 if ($d eq $src_configdata
2538 || (grep { $d2 eq $_ }
2539 keys %{$unified_info{generate}})
2540 || ! -f $d) {
2541 $d = $d2;
2542 $i = $i2;
2543 }
2544 if ($i) {
2545 # Put together the computed inclusion dir with the
2546 # original module name. Do note that we conserve the
2547 # Unixly path syntax for the module path.
2548 $d = "$i|$m";
2549 }
2550 $unified_info{depends}->{$ddest}->{$d} = 1;
2551
2552 # Fix up associated attributes
2553 $unified_info{attributes}->{depends}->{$ddest}->{$d} =
2554 $attributes{depends}->{$dest}->{$f}
2555 if defined $attributes{depends}->{$dest}->{$f};
2556 }
2557 }
2558
2559 foreach (keys %includes) {
2560 my $dest = $_;
2561 my $ddest = cleanfile($sourced, $_, $blddir, 1);
2562
2563 # If the destination doesn't exist in source, it can only be
2564 # a generated file in the build tree.
2565 if ($ddest eq $src_configdata || ! -f $ddest) {
2566 $ddest = cleanfile($buildd, $_, $blddir);
2567 }
2568 foreach (@{$includes{$dest}}) {
2569 my $is = cleandir($sourced, $_, $blddir, 1);
2570 my $ib = cleandir($buildd, $_, $blddir);
2571 push @{$unified_info{includes}->{$ddest}->{source}}, $is
2572 unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}};
2573 push @{$unified_info{includes}->{$ddest}->{build}}, $ib
2574 unless grep { $_ eq $ib } @{$unified_info{includes}->{$ddest}->{build}};
2575 }
2576 }
2577
2578 foreach my $dest (keys %defines) {
2579 my $ddest;
2580
2581 if ($dest ne "") {
2582 $ddest = cleanfile($sourced, $dest, $blddir, 1);
2583
2584 # If the destination doesn't exist in source, it can only
2585 # be a generated file in the build tree.
2586 if (! -f $ddest) {
2587 $ddest = cleanfile($buildd, $dest, $blddir);
2588 }
2589 }
2590 foreach my $v (@{$defines{$dest}}) {
2591 $v =~ m|^([^=]*)(=.*)?$|;
2592 die "0 length macro name not permitted\n" if $1 eq "";
2593 if ($dest ne "") {
2594 die "$1 defined more than once\n"
2595 if defined $unified_info{defines}->{$ddest}->{$1};
2596 $unified_info{defines}->{$ddest}->{$1} = $2;
2597 } else {
2598 die "$1 defined more than once\n"
2599 if grep { $v eq $_ } @{$config{defines}};
2600 push @{$config{defines}}, $v;
2601 }
2602 }
2603 }
2604
2605 foreach my $section (keys %imagedocs) {
2606 foreach (@{$imagedocs{$section}}) {
2607 my $imagedocs = cleanfile($buildd, $_, $blddir);
2608 $unified_info{imagedocs}->{$section}->{$imagedocs} = 1;
2609 }
2610 }
2611
2612 foreach my $section (keys %htmldocs) {
2613 foreach (@{$htmldocs{$section}}) {
2614 my $htmldocs = cleanfile($buildd, $_, $blddir);
2615 $unified_info{htmldocs}->{$section}->{$htmldocs} = 1;
2616 }
2617 }
2618
2619 foreach my $section (keys %mandocs) {
2620 foreach (@{$mandocs{$section}}) {
2621 my $mandocs = cleanfile($buildd, $_, $blddir);
2622 $unified_info{mandocs}->{$section}->{$mandocs} = 1;
2623 }
2624 }
2625 }
2626
2627 my $ordinals_text = join(', ', sort keys %ordinals);
2628 warn <<"EOF" if $ordinals_text;
2629
2630WARNING: ORDINALS were specified for $ordinals_text
2631They are ignored and should be replaced with a combination of GENERATE,
2632DEPEND and SHARED_SOURCE.
2633EOF
2634
2635 # Check that each generated file is only generated once
2636 my $ambiguous_generation = 0;
2637 foreach (sort keys %check_generate) {
2638 my @generators = sort keys %{$check_generate{$_}};
2639 my $generators_txt = join(', ', @generators);
2640 if (scalar @generators > 1) {
2641 warn "$_ is GENERATEd by more than one generator ($generators_txt)\n";
2642 $ambiguous_generation++;
2643 }
2644 if ($check_generate{$_}->{$generators[0]} > 1) {
2645 warn "INFO: $_ has more than one GENERATE declaration (same generator)\n"
2646 }
2647 }
2648 die "There are ambiguous source file generations\n"
2649 if $ambiguous_generation > 0;
2650
2651 # All given source files should exist, or if generated, their
2652 # generator should exist. This loop ensures this is true.
2653 my $missing = 0;
2654 foreach my $orig (sort keys %check_exist) {
2655 foreach my $dest (@{$check_exist{$orig}}) {
2656 if ($orig ne $src_configdata) {
2657 if ($orig =~ /\.a$/) {
2658 # Static library names may be used as sources, so we
2659 # need to detect those and give them special treatment.
2660 unless (grep { $_ eq $orig }
2661 keys %{$unified_info{libraries}}) {
2662 warn "$orig is given as source for $dest, but no such library is built\n";
2663 $missing++;
2664 }
2665 } else {
2666 # A source may be generated, and its generator may be
2667 # generated as well. We therefore loop to dig out the
2668 # first generator.
2669 my $gen = $orig;
2670
2671 while (my @next = keys %{$check_generate{$gen}}) {
2672 $gen = $next[0];
2673 }
2674
2675 if (! -f $gen) {
2676 if ($gen ne $orig) {
2677 $missing++;
2678 warn "$orig is given as source for $dest, but its generator (leading to $gen) is missing\n";
2679 } else {
2680 $missing++;
2681 warn "$orig is given as source for $dest, but is missing\n";
2682 }
2683 }
2684 }
2685 }
2686 }
2687 }
2688 die "There are files missing\n" if $missing > 0;
2689
2690 # Go through the sources of all libraries and check that the same basename
2691 # doesn't appear more than once. Some static library archivers depend on
2692 # them being unique.
2693 {
2694 my $err = 0;
2695 foreach my $prod (keys %{$unified_info{libraries}}) {
2696 my @prod_sources =
2697 map { keys %{$unified_info{sources}->{$_}} }
2698 keys %{$unified_info{sources}->{$prod}};
2699 my %srccnt = ();
2700
2701 # Count how many times a given each source basename
2702 # appears for each product.
2703 foreach my $src (@prod_sources) {
2704 $srccnt{basename $src}++;
2705 }
2706
2707 foreach my $src (keys %srccnt) {
2708 if ((my $cnt = $srccnt{$src}) > 1) {
2709 print STDERR "$src appears $cnt times for the product $prod\n";
2710 $err++
2711 }
2712 }
2713 }
2714 die if $err > 0;
2715 }
2716
2717 # Massage the result
2718
2719 # If we depend on a header file or a perl module, add an inclusion of
2720 # its directory to allow smoothe inclusion
2721 foreach my $dest (keys %{$unified_info{depends}}) {
2722 next if $dest eq "";
2723 foreach my $d (keys %{$unified_info{depends}->{$dest}}) {
2724 next unless $d =~ /\.(h|pm)$/;
2725 # Take into account when a dependency uses the inclusion|module
2726 # syntax
2727 my $i = $d =~ m/\|/ ? $` : dirname($d);
2728 my $spot =
2729 $d eq "configdata.pm" || defined($unified_info{generate}->{$d})
2730 ? 'build' : 'source';
2731 push @{$unified_info{includes}->{$dest}->{$spot}}, $i
2732 unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{$spot}};
2733 }
2734 }
2735
2736 # Go through all intermediary files and change their names to something that
2737 # reflects what they will be built for. Note that for some source files,
2738 # this leads to duplicate object files because they are used multiple times.
2739 # the goal is to rename all object files according to this scheme:
2740 # {productname}-{midfix}-{origobjname}.[o|res]
2741 # the {midfix} is a keyword indicating the type of product, which is mostly
2742 # valuable for libraries since they come in two forms.
2743 #
2744 # This also reorganises the {sources} and {shared_sources} so that the
2745 # former only contains ALL object files that are supposed to end up in
2746 # static libraries and programs, while the latter contains ALL object files
2747 # that are supposed to end up in shared libraries and DSOs.
2748 # The main reason for having two different source structures is to allow
2749 # the same name to be used for the static and the shared variants of a
2750 # library.
2751 {
2752 # Take copies so we don't get interference from added stuff
2753 my %unified_copy = ();
2754 foreach (('sources', 'shared_sources')) {
2755 $unified_copy{$_} = { %{$unified_info{$_}} }
2756 if defined($unified_info{$_});
2757 delete $unified_info{$_};
2758 }
2759 foreach my $prodtype (('programs', 'libraries', 'modules', 'scripts')) {
2760 # $intent serves multi purposes:
2761 # - give a prefix for the new object files names
2762 # - in the case of libraries, rearrange the object files so static
2763 # libraries use the 'sources' structure exclusively, while shared
2764 # libraries use the 'shared_sources' structure exclusively.
2765 my $intent = {
2766 programs => { bin => { src => [ 'sources' ],
2767 dst => 'sources' } },
2768 libraries => { lib => { src => [ 'sources' ],
2769 dst => 'sources' },
2770 shlib => { prodselect =>
2771 sub { grep !/\.a$/, @_ },
2772 src => [ 'sources',
2773 'shared_sources' ],
2774 dst => 'shared_sources' } },
2775 modules => { dso => { src => [ 'sources' ],
2776 dst => 'sources' } },
2777 scripts => { script => { src => [ 'sources' ],
2778 dst => 'sources' } }
2779 } -> {$prodtype};
2780 foreach my $kind (keys %$intent) {
2781 next if ($intent->{$kind}->{dst} eq 'shared_sources'
2782 && $disabled{shared});
2783
2784 my @src = @{$intent->{$kind}->{src}};
2785 my $dst = $intent->{$kind}->{dst};
2786 my $prodselect = $intent->{$kind}->{prodselect} // sub { @_ };
2787 foreach my $prod ($prodselect->(keys %{$unified_info{$prodtype}})) {
2788 # %prod_sources has all applicable objects as keys, and
2789 # their corresponding sources as values
2790 my %prod_sources =
2791 map { $_ => [ keys %{$unified_copy{sources}->{$_}} ] }
2792 map { keys %{$unified_copy{$_}->{$prod}} }
2793 @src;
2794 foreach (keys %prod_sources) {
2795 # Only affect object files and resource files,
2796 # the others simply get a new value
2797 # (+1 instead of -1)
2798 if ($_ =~ /\.(o|res)$/) {
2799 (my $prodname = $prod) =~ s|\.a$||;
2800 my $newobj =
2801 catfile(dirname($_),
2802 basename($prodname)
2803 . '-' . $kind
2804 . '-' . basename($_));
2805 $unified_info{$dst}->{$prod}->{$newobj} = 1;
2806 foreach my $src (@{$prod_sources{$_}}) {
2807 $unified_info{sources}->{$newobj}->{$src} = 1;
2808 # Adjust source attributes
2809 my $attrs = $unified_info{attributes}->{sources};
2810 if (defined $attrs->{$prod}
2811 && defined $attrs->{$prod}->{$_}) {
2812 $attrs->{$prod}->{$newobj} =
2813 $attrs->{$prod}->{$_};
2814 delete $attrs->{$prod}->{$_};
2815 }
2816 foreach my $objsrc (keys %{$attrs->{$_} // {}}) {
2817 $attrs->{$newobj}->{$objsrc} =
2818 $attrs->{$_}->{$objsrc};
2819 delete $attrs->{$_}->{$objsrc};
2820 }
2821 }
2822 # Adjust dependencies
2823 foreach my $deps (keys %{$unified_info{depends}->{$_}}) {
2824 $unified_info{depends}->{$_}->{$deps} = -1;
2825 $unified_info{depends}->{$newobj}->{$deps} = 1;
2826 }
2827 # Adjust includes
2828 foreach my $k (('source', 'build')) {
2829 next unless
2830 defined($unified_info{includes}->{$_}->{$k});
2831 my @incs = @{$unified_info{includes}->{$_}->{$k}};
2832 $unified_info{includes}->{$newobj}->{$k} = [ @incs ];
2833 }
2834 } else {
2835 $unified_info{$dst}->{$prod}->{$_} = 1;
2836 }
2837 }
2838 }
2839 }
2840 }
2841 }
2842
2843 # At this point, we have a number of sources with the value -1. They
2844 # aren't part of the local build and are probably meant for a different
2845 # platform, and can therefore be cleaned away. That happens when making
2846 # %unified_info more efficient below.
2847
2848 ### Make unified_info a bit more efficient
2849 # One level structures
2850 foreach (("programs", "libraries", "modules", "scripts", "targets")) {
2851 $unified_info{$_} = [ sort keys %{$unified_info{$_}} ];
2852 }
2853 # Two level structures
2854 foreach my $l1 (("sources", "shared_sources", "ldadd", "depends",
2855 "imagedocs", "htmldocs", "mandocs")) {
2856 foreach my $l2 (sort keys %{$unified_info{$l1}}) {
2857 my @items =
2858 sort
2859 grep { $unified_info{$l1}->{$l2}->{$_} > 0 }
2860 keys %{$unified_info{$l1}->{$l2}};
2861 if (@items) {
2862 $unified_info{$l1}->{$l2} = [ @items ];
2863 } else {
2864 delete $unified_info{$l1}->{$l2};
2865 }
2866 }
2867 }
2868 # Defines
2869 foreach my $dest (sort keys %{$unified_info{defines}}) {
2870 $unified_info{defines}->{$dest}
2871 = [ map { $_.$unified_info{defines}->{$dest}->{$_} }
2872 sort keys %{$unified_info{defines}->{$dest}} ];
2873 }
2874 # Includes
2875 foreach my $dest (sort keys %{$unified_info{includes}}) {
2876 if (defined($unified_info{includes}->{$dest}->{build})) {
2877 my @source_includes = ();
2878 @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} )
2879 if defined($unified_info{includes}->{$dest}->{source});
2880 $unified_info{includes}->{$dest} =
2881 [ @{$unified_info{includes}->{$dest}->{build}} ];
2882 foreach my $inc (@source_includes) {
2883 push @{$unified_info{includes}->{$dest}}, $inc
2884 unless grep { $_ eq $inc } @{$unified_info{includes}->{$dest}};
2885 }
2886 } elsif (defined($unified_info{includes}->{$dest}->{source})) {
2887 $unified_info{includes}->{$dest} =
2888 [ @{$unified_info{includes}->{$dest}->{source}} ];
2889 } else {
2890 delete $unified_info{includes}->{$dest};
2891 }
2892 }
2893
2894 # For convenience collect information regarding directories where
2895 # files are generated, those generated files and the end product
2896 # they end up in where applicable. Then, add build rules for those
2897 # directories
2898 my %loopinfo = ( "lib" => [ @{$unified_info{libraries}} ],
2899 "dso" => [ @{$unified_info{modules}} ],
2900 "bin" => [ @{$unified_info{programs}} ],
2901 "script" => [ @{$unified_info{scripts}} ],
2902 "docs" => [ (map { @{$unified_info{imagedocs}->{$_} // []} }
2903 keys %{$unified_info{imagedocs} // {}}),
2904 (map { @{$unified_info{htmldocs}->{$_} // []} }
2905 keys %{$unified_info{htmldocs} // {}}),
2906 (map { @{$unified_info{mandocs}->{$_} // []} }
2907 keys %{$unified_info{mandocs} // {}}) ] );
2908 foreach my $type (sort keys %loopinfo) {
2909 foreach my $product (@{$loopinfo{$type}}) {
2910 my %dirs = ();
2911 my $pd = dirname($product);
2912
2913 foreach (@{$unified_info{sources}->{$product} // []},
2914 @{$unified_info{shared_sources}->{$product} // []}) {
2915 my $d = dirname($_);
2916
2917 # We don't want to create targets for source directories
2918 # when building out of source
2919 next if ($config{sourcedir} ne $config{builddir}
2920 && $d =~ m|^\Q$config{sourcedir}\E|);
2921 # We already have a "test" target, and the current directory
2922 # is just silly to make a target for
2923 next if $d eq "test" || $d eq ".";
2924
2925 $dirs{$d} = 1;
2926 push @{$unified_info{dirinfo}->{$d}->{deps}}, $_
2927 if $d ne $pd;
2928 }
2929 foreach (sort keys %dirs) {
2930 push @{$unified_info{dirinfo}->{$_}->{products}->{$type}},
2931 $product;
2932 }
2933 }
2934 }
2935}
2936
2937# For the schemes that need it, we provide the old *_obj configs
2938# from the *_asm_obj ones
2939foreach (grep /_(asm|aux)_src$/, keys %target) {
2940 my $src = $_;
2941 (my $obj = $_) =~ s/_(asm|aux)_src$/_obj/;
2942 $target{$obj} = $target{$src};
2943 $target{$obj} =~ s/\.[csS]\b/.o/g; # C and assembler
2944 $target{$obj} =~ s/\.(cc|cpp)\b/_cc.o/g; # C++
2945}
2946
2947# Write down our configuration where it fits #########################
2948
2949my %template_vars = (
2950 config => \%config,
2951 target => \%target,
2952 disablables => \@disablables,
2953 disablables_int => \@disablables_int,
2954 disabled => \%disabled,
2955 withargs => \%withargs,
2956 unified_info => \%unified_info,
2957 tls => \@tls,
2958 dtls => \@dtls,
2959 makevars => [ sort keys %user ],
2960 disabled_info => \%disabled_info,
2961 user_crossable => \@user_crossable,
2962);
2963my $configdata_outname = 'configdata.pm';
2964open CONFIGDATA, ">$configdata_outname.new"
2965 or die "Trying to create $configdata_outname.new: $!";
2966my $configdata_tmplname = cleanfile($srcdir, "configdata.pm.in", $blddir, 1);
2967my $configdata_tmpl =
2968 OpenSSL::Template->new(TYPE => 'FILE', SOURCE => $configdata_tmplname);
2969$configdata_tmpl->fill_in(
2970 FILENAME => $configdata_tmplname,
2971 OUTPUT => \*CONFIGDATA,
2972 HASH => { %template_vars,
2973 autowarntext => [
2974 'WARNING: do not edit!',
2975 "Generated by Configure from $configdata_tmplname",
2976 ] }
2977) or die $Text::Template::ERROR;
2978close CONFIGDATA;
2979
2980rename "$configdata_outname.new", $configdata_outname;
2981if ($builder_platform eq 'unix') {
2982 my $mode = (0755 & ~umask);
2983 chmod $mode, 'configdata.pm'
2984 or warn sprintf("WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s\n",$mode,$!);
2985}
2986print "Created $configdata_outname\n";
2987
2988print "Running $configdata_outname\n";
2989my $perlcmd = (quotify("maybeshell", $config{PERL}))[0];
2990my $cmd = "$perlcmd $configdata_outname";
2991#print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
2992system($cmd);
2993exit 1 if $? != 0;
2994
2995$SIG{__DIE__} = $orig_death_handler;
2996
2997print <<"EOF" if ($disabled{threads} eq "unavailable");
2998
2999The library could not be configured for supporting multi-threaded
3000applications as the compiler options required on this system are not known.
3001See file INSTALL.md for details if you need multi-threading.
3002EOF
3003
3004print <<"EOF" if ($no_shared_warn);
3005
3006The options 'shared', 'pic' and 'dynamic-engine' aren't supported on this
3007platform, so we will pretend you gave the option 'no-pic', which also disables
3008'shared' and 'dynamic-engine'. If you know how to implement shared libraries
3009or position independent code, please let us know (but please first make sure
3010you have tried with a current version of OpenSSL).
3011EOF
3012
3013print $banner;
3014
3015exit(0);
3016
3017######################################################################
3018#
3019# Helpers and utility functions
3020#
3021
3022# Death handler, to print a helpful message in case of failure #######
3023#
3024sub death_handler {
3025 die @_ if $^S; # To prevent the added message in eval blocks
3026 my $build_file = $config{build_file} // "build file";
3027 my @message = ( <<"_____", @_ );
3028
3029Failure! $build_file wasn't produced.
3030Please read INSTALL.md and associated NOTES-* files. You may also have to
3031look over your available compiler tool chain or change your configuration.
3032
3033_____
3034
3035 # Dying is terminal, so it's ok to reset the signal handler here.
3036 $SIG{__DIE__} = $orig_death_handler;
3037 die @message;
3038}
3039
3040# Configuration file reading #########################################
3041
3042# Note: All of the helper functions are for lazy evaluation. They all
3043# return a CODE ref, which will return the intended value when evaluated.
3044# Thus, whenever there's mention of a returned value, it's about that
3045# intended value.
3046
3047# Helper function to implement conditional value variants, with a default
3048# plus additional values based on the value of $config{build_type}.
3049# Arguments are given in hash table form:
3050#
3051# picker(default => "Basic string: ",
3052# debug => "debug",
3053# release => "release")
3054#
3055# When configuring with --debug, the resulting string will be
3056# "Basic string: debug", and when not, it will be "Basic string: release"
3057#
3058# This can be used to create variants of sets of flags according to the
3059# build type:
3060#
3061# cflags => picker(default => "-Wall",
3062# debug => "-g -O0",
3063# release => "-O3")
3064#
3065sub picker {
3066 my %opts = @_;
3067 return sub { add($opts{default} || (),
3068 $opts{$config{build_type}} || ())->(); }
3069}
3070
3071# Helper function to combine several values of different types into one.
3072# This is useful if you want to combine a string with the result of a
3073# lazy function, such as:
3074#
3075# cflags => combine("-Wall", sub { $disabled{zlib} ? () : "-DZLIB" })
3076#
3077sub combine {
3078 my @stuff = @_;
3079 return sub { add(@stuff)->(); }
3080}
3081
3082# Helper function to implement conditional values depending on the value
3083# of $disabled{threads}. Can be used as follows:
3084#
3085# cflags => combine("-Wall", threads("-pthread"))
3086#
3087sub threads {
3088 my @flags = @_;
3089 return sub { add($disabled{threads} ? () : @flags)->(); }
3090}
3091
3092sub shared {
3093 my @flags = @_;
3094 return sub { add($disabled{shared} ? () : @flags)->(); }
3095}
3096
3097our $add_called = 0;
3098# Helper function to implement adding values to already existing configuration
3099# values. It handles elements that are ARRAYs, CODEs and scalars
3100sub _add {
3101 my $separator = shift;
3102
3103 # If there's any ARRAY in the collection of values OR the separator
3104 # is undef, we will return an ARRAY of combined values, otherwise a
3105 # string of joined values with $separator as the separator.
3106 my $found_array = !defined($separator);
3107
3108 my @values =
3109 map {
3110 my $res = $_;
3111 while (ref($res) eq "CODE") {
3112 $res = $res->();
3113 }
3114 if (defined($res)) {
3115 if (ref($res) eq "ARRAY") {
3116 $found_array = 1;
3117 @$res;
3118 } else {
3119 $res;
3120 }
3121 } else {
3122 ();
3123 }
3124 } (@_);
3125
3126 $add_called = 1;
3127
3128 if ($found_array) {
3129 [ @values ];
3130 } else {
3131 join($separator, grep { defined($_) && $_ ne "" } @values);
3132 }
3133}
3134sub add_before {
3135 my $separator = " ";
3136 if (ref($_[$#_]) eq "HASH") {
3137 my $opts = pop;
3138 $separator = $opts->{separator};
3139 }
3140 my @x = @_;
3141 sub { _add($separator, @x, @_) };
3142}
3143sub add {
3144 my $separator = " ";
3145 if (ref($_[$#_]) eq "HASH") {
3146 my $opts = pop;
3147 $separator = $opts->{separator};
3148 }
3149 my @x = @_;
3150 sub { _add($separator, @_, @x) };
3151}
3152
3153sub read_eval_file {
3154 my $fname = shift;
3155 my $content;
3156 my @result;
3157
3158 open F, "< $fname" or die "Can't open '$fname': $!\n";
3159 {
3160 undef local $/;
3161 $content = <F>;
3162 }
3163 close F;
3164 {
3165 local $@;
3166
3167 @result = ( eval $content );
3168 warn $@ if $@;
3169 }
3170 return wantarray ? @result : $result[0];
3171}
3172
3173# configuration reader, evaluates the input file as a perl script and expects
3174# it to fill %targets with target configurations. Those are then added to
3175# %table.
3176sub read_config {
3177 my $fname = shift;
3178 my %targets;
3179
3180 {
3181 # Protect certain tables from tampering
3182 local %table = ();
3183
3184 %targets = read_eval_file($fname);
3185 }
3186 my %preexisting = ();
3187 foreach (sort keys %targets) {
3188 $preexisting{$_} = 1 if $table{$_};
3189 }
3190 die <<"EOF",
3191The following config targets from $fname
3192shadow pre-existing config targets with the same name:
3193EOF
3194 map { " $_\n" } sort keys %preexisting
3195 if %preexisting;
3196
3197
3198 # For each target, check that it's configured with a hash table.
3199 foreach (keys %targets) {
3200 if (ref($targets{$_}) ne "HASH") {
3201 if (ref($targets{$_}) eq "") {
3202 warn "Deprecated target configuration for $_, ignoring...\n";
3203 } else {
3204 warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
3205 }
3206 delete $targets{$_};
3207 } else {
3208 $targets{$_}->{_conf_fname_int} = add([ $fname ]);
3209 }
3210 }
3211
3212 %table = (%table, %targets);
3213
3214}
3215
3216# configuration resolver. Will only resolve all the lazy evaluation
3217# codeblocks for the chosen target and all those it inherits from,
3218# recursively
3219sub resolve_config {
3220 my $target = shift;
3221 my @breadcrumbs = @_;
3222
3223# my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS});
3224
3225 if (grep { $_ eq $target } @breadcrumbs) {
3226 die "inherit_from loop! target backtrace:\n "
3227 ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
3228 }
3229
3230 if (!defined($table{$target})) {
3231 warn "Warning! target $target doesn't exist!\n";
3232 return ();
3233 }
3234 # Recurse through all inheritances. They will be resolved on the
3235 # fly, so when this operation is done, they will all just be a
3236 # bunch of attributes with string values.
3237 # What we get here, though, are keys with references to lists of
3238 # the combined values of them all. We will deal with lists after
3239 # this stage is done.
3240 my %combined_inheritance = ();
3241 if ($table{$target}->{inherit_from}) {
3242 my @inherit_from =
3243 map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
3244 foreach (@inherit_from) {
3245 my %inherited_config = resolve_config($_, $target, @breadcrumbs);
3246
3247 # 'template' is a marker that's considered private to
3248 # the config that had it.
3249 delete $inherited_config{template};
3250
3251 foreach (keys %inherited_config) {
3252 if (!$combined_inheritance{$_}) {
3253 $combined_inheritance{$_} = [];
3254 }
3255 push @{$combined_inheritance{$_}}, $inherited_config{$_};
3256 }
3257 }
3258 }
3259
3260 # We won't need inherit_from in this target any more, since we've
3261 # resolved all the inheritances that lead to this
3262 delete $table{$target}->{inherit_from};
3263
3264 # Now is the time to deal with those lists. Here's the place to
3265 # decide what shall be done with those lists, all based on the
3266 # values of the target we're currently dealing with.
3267 # - If a value is a coderef, it will be executed with the list of
3268 # inherited values as arguments.
3269 # - If the corresponding key doesn't have a value at all or is the
3270 # empty string, the inherited value list will be run through the
3271 # default combiner (below), and the result becomes this target's
3272 # value.
3273 # - Otherwise, this target's value is assumed to be a string that
3274 # will simply override the inherited list of values.
3275 my $default_combiner = add();
3276
3277 my %all_keys =
3278 map { $_ => 1 } (keys %combined_inheritance,
3279 keys %{$table{$target}});
3280
3281 sub process_values {
3282 my $object = shift;
3283 my $inherited = shift; # Always a [ list ]
3284 my $target = shift;
3285 my $entry = shift;
3286
3287 $add_called = 0;
3288
3289 while(ref($object) eq "CODE") {
3290 $object = $object->(@$inherited);
3291 }
3292 if (!defined($object)) {
3293 return ();
3294 }
3295 elsif (ref($object) eq "ARRAY") {
3296 local $add_called; # To make sure recursive calls don't affect it
3297 return [ map { process_values($_, $inherited, $target, $entry) }
3298 @$object ];
3299 } elsif (ref($object) eq "") {
3300 return $object;
3301 } else {
3302 die "cannot handle reference type ",ref($object)
3303 ," found in target ",$target," -> ",$entry,"\n";
3304 }
3305 }
3306
3307 foreach my $key (sort keys %all_keys) {
3308 my $previous = $combined_inheritance{$key};
3309
3310 # Current target doesn't have a value for the current key?
3311 # Assign it the default combiner, the rest of this loop body
3312 # will handle it just like any other coderef.
3313 if (!exists $table{$target}->{$key}) {
3314 $table{$target}->{$key} = $default_combiner;
3315 }
3316
3317 $table{$target}->{$key} = process_values($table{$target}->{$key},
3318 $combined_inheritance{$key},
3319 $target, $key);
3320 unless(defined($table{$target}->{$key})) {
3321 delete $table{$target}->{$key};
3322 }
3323# if ($extra_checks &&
3324# $previous && !($add_called || $previous ~~ $table{$target}->{$key})) {
3325# warn "$key got replaced in $target\n";
3326# }
3327 }
3328
3329 # Finally done, return the result.
3330 return %{$table{$target}};
3331}
3332
3333sub usage
3334 {
3335 print STDERR $usage;
3336 print STDERR "\npick os/compiler from:\n";
3337 my $j=0;
3338 my $i;
3339 my $k=0;
3340 foreach $i (sort keys %table)
3341 {
3342 next if $table{$i}->{template};
3343 next if $i =~ /^debug/;
3344 $k += length($i) + 1;
3345 if ($k > 78)
3346 {
3347 print STDERR "\n";
3348 $k=length($i);
3349 }
3350 print STDERR $i . " ";
3351 }
3352 foreach $i (sort keys %table)
3353 {
3354 next if $table{$i}->{template};
3355 next if $i !~ /^debug/;
3356 $k += length($i) + 1;
3357 if ($k > 78)
3358 {
3359 print STDERR "\n";
3360 $k=length($i);
3361 }
3362 print STDERR $i . " ";
3363 }
3364 exit(1);
3365 }
3366
3367sub compiler_predefined {
3368 state %predefined;
3369 my $cc = shift;
3370
3371 return () if $^O eq 'VMS';
3372
3373 die 'compiler_predefined called without a compiler command'
3374 unless $cc;
3375
3376 if (! $predefined{$cc}) {
3377
3378 $predefined{$cc} = {};
3379
3380 # collect compiler pre-defines from gcc or gcc-alike...
3381 open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |");
3382 while (my $l = <PIPE>) {
3383 $l =~ m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last;
3384 $predefined{$cc}->{$1} = $2 // '';
3385 }
3386 close(PIPE);
3387 }
3388
3389 return %{$predefined{$cc}};
3390}
3391
3392sub which
3393{
3394 my ($name)=@_;
3395
3396 if (eval { require IPC::Cmd; 1; }) {
3397 IPC::Cmd->import();
3398 return scalar IPC::Cmd::can_run($name);
3399 } else {
3400 # if there is $directories component in splitpath,
3401 # then it's not something to test with $PATH...
3402 return $name if (File::Spec->splitpath($name))[1];
3403
3404 foreach (File::Spec->path()) {
3405 my $fullpath = catfile($_, "$name$target{exe_extension}");
3406 if (-f $fullpath and -x $fullpath) {
3407 return $fullpath;
3408 }
3409 }
3410 }
3411}
3412
3413sub env
3414{
3415 my $name = shift;
3416 my %opts = @_;
3417
3418 unless ($opts{cacheonly}) {
3419 # Note that if $ENV{$name} doesn't exist or is undefined,
3420 # $config{perlenv}->{$name} will be created with the value
3421 # undef. This is intentional.
3422
3423 $config{perlenv}->{$name} = $ENV{$name}
3424 if ! exists $config{perlenv}->{$name};
3425 }
3426 return $config{perlenv}->{$name};
3427}
3428
3429# Configuration printer ##############################################
3430
3431sub print_table_entry
3432{
3433 local $now_printing = shift;
3434 my %target = resolve_config($now_printing);
3435 my $type = shift;
3436
3437 # Don't print the templates
3438 return if $target{template};
3439
3440 my @sequence = (
3441 "sys_id",
3442 "cpp",
3443 "cppflags",
3444 "defines",
3445 "includes",
3446 "cc",
3447 "cflags",
3448 "ld",
3449 "lflags",
3450 "loutflag",
3451 "ex_libs",
3452 "bn_ops",
3453 "enable",
3454 "disable",
3455 "poly1035_asm_src",
3456 "thread_scheme",
3457 "perlasm_scheme",
3458 "dso_scheme",
3459 "shared_target",
3460 "shared_cflag",
3461 "shared_defines",
3462 "shared_ldflag",
3463 "shared_rcflag",
3464 "shared_extension",
3465 "dso_extension",
3466 "obj_extension",
3467 "exe_extension",
3468 "ranlib",
3469 "ar",
3470 "arflags",
3471 "aroutflag",
3472 "rc",
3473 "rcflags",
3474 "rcoutflag",
3475 "mt",
3476 "mtflags",
3477 "mtinflag",
3478 "mtoutflag",
3479 "multilib",
3480 "build_scheme",
3481 );
3482
3483 if ($type eq "TABLE") {
3484 print "\n";
3485 print "*** $now_printing\n";
3486 foreach (@sequence) {
3487 if (ref($target{$_}) eq "ARRAY") {
3488 printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}});
3489 } else {
3490 printf "\$%-12s = %s\n", $_, $target{$_};
3491 }
3492 }
3493 } elsif ($type eq "HASH") {
3494 my $largest =
3495 length((sort { length($a) <=> length($b) } @sequence)[-1]);
3496 print " '$now_printing' => {\n";
3497 foreach (@sequence) {
3498 if ($target{$_}) {
3499 if (ref($target{$_}) eq "ARRAY") {
3500 print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n";
3501 } else {
3502 print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
3503 }
3504 }
3505 }
3506 print " },\n";
3507 }
3508}
3509
3510# Utility routines ###################################################
3511
3512# On VMS, if the given file is a logical name, File::Spec::Functions
3513# will consider it an absolute path. There are cases when we want a
3514# purely syntactic check without checking the environment.
3515sub isabsolute {
3516 my $file = shift;
3517
3518 # On non-platforms, we just use file_name_is_absolute().
3519 return file_name_is_absolute($file) unless $^O eq "VMS";
3520
3521 # If the file spec includes a device or a directory spec,
3522 # file_name_is_absolute() is perfectly safe.
3523 return file_name_is_absolute($file) if $file =~ m|[:\[]|;
3524
3525 # Here, we know the given file spec isn't absolute
3526 return 0;
3527}
3528
3529# Makes a directory absolute and cleans out /../ in paths like foo/../bar
3530# On some platforms, this uses rel2abs(), while on others, realpath() is used.
3531# realpath() requires that at least all path components except the last is an
3532# existing directory. On VMS, the last component of the directory spec must
3533# exist.
3534sub absolutedir {
3535 my $dir = shift;
3536
3537 # realpath() is quite buggy on VMS. It uses LIB$FID_TO_NAME, which
3538 # will return the volume name for the device, no matter what. Also,
3539 # it will return an incorrect directory spec if the argument is a
3540 # directory that doesn't exist.
3541 if ($^O eq "VMS") {
3542 return rel2abs($dir);
3543 }
3544
3545 # realpath() on Windows seems to check if the directory actually exists,
3546 # which isn't what is wanted here. All we want to know is if a directory
3547 # spec is absolute, not if it exists.
3548 if ($^O eq "MSWin32") {
3549 return rel2abs($dir);
3550 }
3551
3552 # We use realpath() on Unix, since no other will properly clean out
3553 # a directory spec.
3554 use Cwd qw/realpath/;
3555
3556 return realpath($dir);
3557}
3558
3559# Check if all paths are one and the same, using stat. They must both exist
3560# We need this for the cases when File::Spec doesn't detect case insensitivity
3561# (File::Spec::Unix assumes case sensitivity)
3562sub samedir {
3563 die "samedir expects two arguments\n" unless scalar @_ == 2;
3564
3565 my @stat0 = stat($_[0]); # First argument
3566 my @stat1 = stat($_[1]); # Second argument
3567
3568 die "Couldn't stat $_[0]" unless @stat0;
3569 die "Couldn't stat $_[1]" unless @stat1;
3570
3571 # Compare device number
3572 return 0 unless ($stat0[0] == $stat1[0]);
3573 # Compare "inode". The perl manual recommends comparing as
3574 # string rather than as number.
3575 return 0 unless ($stat0[1] eq $stat1[1]);
3576
3577 return 1; # All the same
3578}
3579
3580sub quotify {
3581 my %processors = (
3582 perl => sub { my $x = shift;
3583 $x =~ s/([\\\$\@"])/\\$1/g;
3584 return '"'.$x.'"'; },
3585 maybeshell => sub { my $x = shift;
3586 (my $y = $x) =~ s/([\\\"])/\\$1/g;
3587 if ($x ne $y || $x =~ m|\s|) {
3588 return '"'.$y.'"';
3589 } else {
3590 return $x;
3591 }
3592 },
3593 );
3594 my $for = shift;
3595 my $processor =
3596 defined($processors{$for}) ? $processors{$for} : sub { shift; };
3597
3598 return map { $processor->($_); } @_;
3599}
3600
3601# collect_from_file($filename, $line_concat_cond_re, $line_concat)
3602# $filename is a file name to read from
3603# $line_concat_cond_re is a regexp detecting a line continuation ending
3604# $line_concat is a CODEref that takes care of concatenating two lines
3605sub collect_from_file {
3606 my $filename = shift;
3607 my $line_concat_cond_re = shift;
3608 my $line_concat = shift;
3609
3610 open my $fh, $filename || die "unable to read $filename: $!\n";
3611 return sub {
3612 my $saved_line = "";
3613 $_ = "";
3614 while (<$fh>) {
3615 s|\R$||;
3616 if (defined $line_concat) {
3617 $_ = $line_concat->($saved_line, $_);
3618 $saved_line = "";
3619 }
3620 if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
3621 $saved_line = $_;
3622 next;
3623 }
3624 return $_;
3625 }
3626 die "$filename ending with continuation line\n" if $_;
3627 close $fh;
3628 return undef;
3629 }
3630}
3631
3632# collect_from_array($array, $line_concat_cond_re, $line_concat)
3633# $array is an ARRAYref of lines
3634# $line_concat_cond_re is a regexp detecting a line continuation ending
3635# $line_concat is a CODEref that takes care of concatenating two lines
3636sub collect_from_array {
3637 my $array = shift;
3638 my $line_concat_cond_re = shift;
3639 my $line_concat = shift;
3640 my @array = (@$array);
3641
3642 return sub {
3643 my $saved_line = "";
3644 $_ = "";
3645 while (defined($_ = shift @array)) {
3646 s|\R$||;
3647 if (defined $line_concat) {
3648 $_ = $line_concat->($saved_line, $_);
3649 $saved_line = "";
3650 }
3651 if (defined $line_concat_cond_re && /$line_concat_cond_re/) {
3652 $saved_line = $_;
3653 next;
3654 }
3655 return $_;
3656 }
3657 die "input text ending with continuation line\n" if $_;
3658 return undef;
3659 }
3660}
3661
3662# collect_information($lineiterator, $line_continue, $regexp => $CODEref, ...)
3663# $lineiterator is a CODEref that delivers one line at a time.
3664# All following arguments are regex/CODEref pairs, where the regexp detects a
3665# line and the CODEref does something with the result of the regexp.
3666sub collect_information {
3667 my $lineiterator = shift;
3668 my %collectors = @_;
3669
3670 while(defined($_ = $lineiterator->())) {
3671 s|\R$||;
3672 my $found = 0;
3673 if ($collectors{"BEFORE"}) {
3674 $collectors{"BEFORE"}->($_);
3675 }
3676 foreach my $re (keys %collectors) {
3677 if ($re !~ /^OTHERWISE|BEFORE|AFTER$/ && /$re/) {
3678 $collectors{$re}->($lineiterator);
3679 $found = 1;
3680 };
3681 }
3682 if ($collectors{"OTHERWISE"}) {
3683 $collectors{"OTHERWISE"}->($lineiterator, $_)
3684 unless $found || !defined $collectors{"OTHERWISE"};
3685 }
3686 if ($collectors{"AFTER"}) {
3687 $collectors{"AFTER"}->($_);
3688 }
3689 }
3690}
3691
3692# tokenize($line)
3693# tokenize($line,$separator)
3694# $line is a line of text to split up into tokens
3695# $separator [optional] is a regular expression that separates the tokens,
3696# the default being spaces. Do not use quotes of any kind as separators,
3697# that will give undefined results.
3698# Returns a list of tokens.
3699#
3700# Tokens are divided by separator (spaces by default). If the tokens include
3701# the separators, they have to be quoted with single or double quotes.
3702# Double quotes inside a double quoted token must be escaped. Escaping is done
3703# with backslash.
3704# Basically, the same quoting rules apply for " and ' as in any
3705# Unix shell.
3706sub tokenize {
3707 my $line = my $debug_line = shift;
3708 my $separator = shift // qr|\s+|;
3709 my @result = ();
3710
3711 if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) {
3712 print STDERR "DEBUG[tokenize]: \$separator = $separator\n";
3713 }
3714
3715 while ($line =~ s|^${separator}||, $line ne "") {
3716 my $token = "";
3717 again:
3718 $line =~ m/^(.*?)(${separator}|"|'|$)/;
3719 $token .= $1;
3720 $line = $2.$';
3721
3722 if ($line =~ m/^"((?:[^"\\]+|\\.)*)"/) {
3723 $token .= $1;
3724 $line = $';
3725 goto again;
3726 } elsif ($line =~ m/^'([^']*)'/) {
3727 $token .= $1;
3728 $line = $';
3729 goto again;
3730 }
3731 push @result, $token;
3732 }
3733
3734 if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) {
3735 print STDERR "DEBUG[tokenize]: Parsed '$debug_line' into:\n";
3736 print STDERR "DEBUG[tokenize]: ('", join("', '", @result), "')\n";
3737 }
3738 return @result;
3739}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette