Debian Codegraph @

debian/rust-vendor/openssl-src/openssl/Configure

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