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