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