1e71b7053SJung-uk Kim#! /usr/bin/env perl 2e71b7053SJung-uk Kim# -*- mode: perl; -*- 317f01e99SJung-uk Kim# Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. 4e71b7053SJung-uk Kim# 5e71b7053SJung-uk Kim# Licensed under the OpenSSL license (the "License"). You may not use 6e71b7053SJung-uk Kim# this file except in compliance with the License. You can obtain a copy 7e71b7053SJung-uk Kim# in the file LICENSE in the source distribution or at 8e71b7053SJung-uk Kim# https://www.openssl.org/source/license.html 974664626SKris Kennaway 10e71b7053SJung-uk Kim## Configure -- OpenSSL source tree configuration script 11e71b7053SJung-uk Kim 12e71b7053SJung-uk Kimuse 5.10.0; 131f13597dSJung-uk Kimuse strict; 14e71b7053SJung-uk Kimuse Config; 15e71b7053SJung-uk Kimuse FindBin; 16e71b7053SJung-uk Kimuse lib "$FindBin::Bin/util/perl"; 17e71b7053SJung-uk Kimuse File::Basename; 18e71b7053SJung-uk Kimuse File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/; 19e71b7053SJung-uk Kimuse File::Path qw/mkpath/; 20e71b7053SJung-uk Kimuse OpenSSL::Glob; 2174664626SKris Kennaway 2274664626SKris Kennaway# see INSTALL for instructions. 2374664626SKris Kennaway 24e71b7053SJung-uk Kimmy $orig_death_handler = $SIG{__DIE__}; 25e71b7053SJung-uk Kim$SIG{__DIE__} = \&death_handler; 26e71b7053SJung-uk Kim 27610a21fdSJung-uk Kimmy $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"; 2874664626SKris Kennaway 2974664626SKris Kennaway# Options: 3074664626SKris Kennaway# 31e71b7053SJung-uk Kim# --config add the given configuration file, which will be read after 32e71b7053SJung-uk Kim# any "Configurations*" files that are found in the same 33e71b7053SJung-uk Kim# directory as this script. 34e71b7053SJung-uk Kim# --prefix prefix for the OpenSSL installation, which includes the 35e71b7053SJung-uk Kim# directories bin, lib, include, share/man, share/doc/openssl 36e71b7053SJung-uk Kim# This becomes the value of INSTALLTOP in Makefile 37e71b7053SJung-uk Kim# (Default: /usr/local) 38e71b7053SJung-uk Kim# --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys. 39e71b7053SJung-uk Kim# If it's a relative directory, it will be added on the directory 40e71b7053SJung-uk Kim# given with --prefix. 41e71b7053SJung-uk Kim# This becomes the value of OPENSSLDIR in Makefile and in C. 42e71b7053SJung-uk Kim# (Default: PREFIX/ssl) 43c1803d78SJacques Vidrine# 441f13597dSJung-uk Kim# --cross-compile-prefix Add specified prefix to binutils components. 451f13597dSJung-uk Kim# 46e71b7053SJung-uk Kim# --api One of 0.9.8, 1.0.0 or 1.1.0. Do not compile support for 47e71b7053SJung-uk Kim# interfaces deprecated as of the specified OpenSSL version. 48e71b7053SJung-uk Kim# 495c87c606SMark Murray# no-hw-xxx do not compile support for specific crypto hardware. 505c87c606SMark Murray# Generic OpenSSL-style methods relating to this support 515c87c606SMark Murray# are always compiled but return NULL if the hardware 525c87c606SMark Murray# support isn't compiled. 535c87c606SMark Murray# no-hw do not compile support for any crypto hardware. 5474664626SKris Kennaway# [no-]threads [don't] try to create a library that is suitable for 5574664626SKris Kennaway# multithreaded applications (default is "threads" if we 5674664626SKris Kennaway# know how to do it) 57ddd58736SKris Kennaway# [no-]shared [don't] try to create shared libraries when supported. 58e71b7053SJung-uk Kim# [no-]pic [don't] try to build position independent code when supported. 59e71b7053SJung-uk Kim# If disabled, it also disables shared and dynamic-engine. 6074664626SKris Kennaway# no-asm do not use assembler 61e71b7053SJung-uk Kim# no-egd do not compile support for the entropy-gathering daemon APIs 625c87c606SMark Murray# [no-]zlib [don't] compile support for zlib compression. 635c87c606SMark Murray# zlib-dynamic Like "zlib", but the zlib library is expected to be a shared 645c87c606SMark Murray# library and will be loaded in run-time by the OpenSSL library. 651f13597dSJung-uk Kim# sctp include SCTP support 664c6a0400SJung-uk Kim# enable-weak-ssl-ciphers 67e71b7053SJung-uk Kim# Enable weak ciphers that are disabled by default. 686cf8931aSJung-uk Kim# 386 generate 80386 code in assembly modules 696cf8931aSJung-uk Kim# no-sse2 disables IA-32 SSE2 code in assembly modules, the above 706cf8931aSJung-uk Kim# mentioned '386' option implies this one 7174664626SKris Kennaway# no-<cipher> build without specified algorithm (rsa, idea, rc5, ...) 7217f01e99SJung-uk Kim# -<xxx> +<xxx> All options which are unknown to the 'Configure' script are 7317f01e99SJung-uk Kim# /<xxx> passed through to the compiler. Unix-style options beginning 7417f01e99SJung-uk Kim# with a '-' or '+' are recognized, as well as Windows-style 7517f01e99SJung-uk Kim# options beginning with a '/'. If the option contains arguments 7617f01e99SJung-uk Kim# separated by spaces, then the URL-style notation %20 can be 7717f01e99SJung-uk Kim# used for the space character in order to avoid having to quote 7817f01e99SJung-uk Kim# the option. For example, -opt%20arg gets expanded to -opt arg. 7917f01e99SJung-uk Kim# In fact, any ASCII character can be encoded as %xx using its 8017f01e99SJung-uk Kim# hexadecimal encoding. 81e71b7053SJung-uk Kim# -static while -static is also a pass-through compiler option (and 82e71b7053SJung-uk Kim# as such is limited to environments where it's actually 83e71b7053SJung-uk Kim# meaningful), it triggers a number configuration options, 84610a21fdSJung-uk Kim# namely no-pic, no-shared and no-threads. It is 85e71b7053SJung-uk Kim# argued that the only reason to produce statically linked 86e71b7053SJung-uk Kim# binaries (and in context it means executables linked with 87e71b7053SJung-uk Kim# -static flag, and not just executables linked with static 88e71b7053SJung-uk Kim# libcrypto.a) is to eliminate dependency on specific run-time, 89e71b7053SJung-uk Kim# a.k.a. libc version. The mentioned config options are meant 90e71b7053SJung-uk Kim# to achieve just that. Unfortunately on Linux it's impossible 91e71b7053SJung-uk Kim# to eliminate the dependency completely for openssl executable 92e71b7053SJung-uk Kim# because of getaddrinfo and gethostbyname calls, which can 93e71b7053SJung-uk Kim# invoke dynamically loadable library facility anyway to meet 94e71b7053SJung-uk Kim# the lookup requests. For this reason on Linux statically 95e71b7053SJung-uk Kim# linked openssl executable has rather debugging value than 96e71b7053SJung-uk Kim# production quality. 9774664626SKris Kennaway# 9874664626SKris Kennaway# BN_LLONG use the type 'long long' in crypto/bn/bn.h 9974664626SKris Kennaway# RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h 1003b4e3dcbSSimon L. B. Nielsen# Following are set automatically by this script 1013b4e3dcbSSimon L. B. Nielsen# 102e71b7053SJung-uk Kim# MD5_ASM use some extra md5 assembler, 103e71b7053SJung-uk Kim# SHA1_ASM use some extra sha1 assembler, must define L_ENDIAN for x86 104e71b7053SJung-uk Kim# RMD160_ASM use some extra ripemd160 assembler, 1053b4e3dcbSSimon L. B. Nielsen# SHA256_ASM sha256_block is implemented in assembler 1063b4e3dcbSSimon L. B. Nielsen# SHA512_ASM sha512_block is implemented in assembler 107e71b7053SJung-uk Kim# AES_ASM AES_[en|de]crypt is implemented in assembler 10874664626SKris Kennaway 109610a21fdSJung-uk Kim# Minimum warning options... any contributions to OpenSSL should at least 110610a21fdSJung-uk Kim# get past these. Note that we only use these with C compilers, not with 111610a21fdSJung-uk Kim# C++ compilers. 112db522d3aSSimon L. B. Nielsen 113e71b7053SJung-uk Kim# DEBUG_UNUSED enables __owur (warn unused result) checks. 114e71b7053SJung-uk Kim# -DPEDANTIC complements -pedantic and is meant to mask code that 115e71b7053SJung-uk Kim# is not strictly standard-compliant and/or implementation-specific, 116e71b7053SJung-uk Kim# e.g. inline assembly, disregards to alignment requirements, such 117e71b7053SJung-uk Kim# that -pedantic would complain about. Incidentally -DPEDANTIC has 118e71b7053SJung-uk Kim# to be used even in sanitized builds, because sanitizer too is 119e71b7053SJung-uk Kim# supposed to and does take notice of non-standard behaviour. Then 120e71b7053SJung-uk Kim# -pedantic with pre-C9x compiler would also complain about 'long 121e71b7053SJung-uk Kim# long' not being supported. As 64-bit algorithms are common now, 122e71b7053SJung-uk Kim# it grew impossible to resolve this without sizeable additional 123e71b7053SJung-uk Kim# code, so we just tell compiler to be pedantic about everything 124e71b7053SJung-uk Kim# but 'long long' type. 125db522d3aSSimon L. B. Nielsen 126610a21fdSJung-uk Kimmy @gcc_devteam_warn = qw( 127610a21fdSJung-uk Kim -DDEBUG_UNUSED 128610a21fdSJung-uk Kim -DPEDANTIC -pedantic -Wno-long-long 129610a21fdSJung-uk Kim -Wall 130610a21fdSJung-uk Kim -Wextra 131610a21fdSJung-uk Kim -Wno-unused-parameter 132610a21fdSJung-uk Kim -Wno-missing-field-initializers 133610a21fdSJung-uk Kim -Wswitch 134610a21fdSJung-uk Kim -Wsign-compare 135610a21fdSJung-uk Kim -Wshadow 136610a21fdSJung-uk Kim -Wformat 137610a21fdSJung-uk Kim -Wtype-limits 138610a21fdSJung-uk Kim -Wundef 139610a21fdSJung-uk Kim -Werror 140610a21fdSJung-uk Kim -Wmissing-prototypes 141610a21fdSJung-uk Kim -Wstrict-prototypes 142610a21fdSJung-uk Kim); 1437bded2dbSJung-uk Kim 1447bded2dbSJung-uk Kim# These are used in addition to $gcc_devteam_warn when the compiler is clang. 1457bded2dbSJung-uk Kim# TODO(openssl-team): fix problems and investigate if (at least) the 146e71b7053SJung-uk Kim# following warnings can also be enabled: 147e71b7053SJung-uk Kim# -Wcast-align 148e71b7053SJung-uk Kim# -Wunreachable-code -- no, too ugly/compiler-specific 149e71b7053SJung-uk Kim# -Wlanguage-extension-token -- no, we use asm() 150e71b7053SJung-uk Kim# -Wunused-macros -- no, too tricky for BN and _XOPEN_SOURCE etc 151e71b7053SJung-uk Kim# -Wextended-offsetof -- no, needed in CMS ASN1 code 152610a21fdSJung-uk Kimmy @clang_devteam_warn = qw( 153da327cd2SJung-uk Kim -Wno-unknown-warning-option 154610a21fdSJung-uk Kim -Wswitch-default 155610a21fdSJung-uk Kim -Wno-parentheses-equality 156610a21fdSJung-uk Kim -Wno-language-extension-token 157610a21fdSJung-uk Kim -Wno-extended-offsetof 158610a21fdSJung-uk Kim -Wconditional-uninitialized 159610a21fdSJung-uk Kim -Wincompatible-pointer-types-discards-qualifiers 160610a21fdSJung-uk Kim -Wmissing-variable-declarations 161610a21fdSJung-uk Kim); 1627bded2dbSJung-uk Kim 16317f01e99SJung-uk Kimmy @cl_devteam_warn = qw( 16417f01e99SJung-uk Kim /WX 16517f01e99SJung-uk Kim); 16617f01e99SJung-uk Kim 167e71b7053SJung-uk Kim# This adds backtrace information to the memory leak info. Is only used 168e71b7053SJung-uk Kim# when crypto-mdebug-backtrace is enabled. 169e71b7053SJung-uk Kimmy $memleak_devteam_backtrace = "-rdynamic"; 1708180e704SJung-uk Kim 1716a599222SSimon L. B. Nielsenmy $strict_warnings = 0; 1726a599222SSimon L. B. Nielsen 1733b4e3dcbSSimon L. B. Nielsen# As for $BSDthreads. Idea is to maintain "collective" set of flags, 1743b4e3dcbSSimon L. B. Nielsen# which would cover all BSD flavors. -pthread applies to them all, 1753b4e3dcbSSimon L. B. Nielsen# but is treated differently. OpenBSD expands is as -D_POSIX_THREAD 1763b4e3dcbSSimon L. B. Nielsen# -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r, 1773b4e3dcbSSimon L. B. Nielsen# which has to be accompanied by explicit -D_THREAD_SAFE and 1783b4e3dcbSSimon L. B. Nielsen# sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which 1793b4e3dcbSSimon L. B. Nielsen# seems to be sufficient? 180e71b7053SJung-uk Kimour $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT"; 18174664626SKris Kennaway 18274664626SKris Kennaway# 183e71b7053SJung-uk Kim# API compatibility name to version number mapping. 18474664626SKris Kennaway# 185e71b7053SJung-uk Kimmy $maxapi = "1.1.0"; # API for "no-deprecated" builds 186e71b7053SJung-uk Kimmy $apitable = { 187e71b7053SJung-uk Kim "1.1.0" => "0x10100000L", 188e71b7053SJung-uk Kim "1.0.0" => "0x10000000L", 189e71b7053SJung-uk Kim "0.9.8" => "0x00908000L", 190e71b7053SJung-uk Kim}; 191e71b7053SJung-uk Kim 192e71b7053SJung-uk Kimour %table = (); 193e71b7053SJung-uk Kimour %config = (); 194e71b7053SJung-uk Kimour %withargs = (); 195e71b7053SJung-uk Kimour $now_printing; # set to current entry's name in print_table_entry 196e71b7053SJung-uk Kim # (todo: right thing would be to encapsulate name 197e71b7053SJung-uk Kim # into %target [class] and make print_table_entry 198e71b7053SJung-uk Kim # a method) 199e71b7053SJung-uk Kim 200e71b7053SJung-uk Kim# Forward declarations ############################################### 201e71b7053SJung-uk Kim 202e71b7053SJung-uk Kim# read_config(filename) 203c1803d78SJacques Vidrine# 204e71b7053SJung-uk Kim# Reads a configuration file and populates %table with the contents 205e71b7053SJung-uk Kim# (which the configuration file places in %targets). 206e71b7053SJung-uk Kimsub read_config; 20774664626SKris Kennaway 208e71b7053SJung-uk Kim# resolve_config(target) 20974664626SKris Kennaway# 210e71b7053SJung-uk Kim# Resolves all the late evaluations, inheritances and so on for the 211e71b7053SJung-uk Kim# chosen target and any target it inherits from. 212e71b7053SJung-uk Kimsub resolve_config; 21374664626SKris Kennaway 21474664626SKris Kennaway 215e71b7053SJung-uk Kim# Information collection ############################################# 21674664626SKris Kennaway 217e71b7053SJung-uk Kim# Unified build supports separate build dir 218e71b7053SJung-uk Kimmy $srcdir = catdir(absolutedir(dirname($0))); # catdir ensures local syntax 219e71b7053SJung-uk Kimmy $blddir = catdir(absolutedir(".")); # catdir ensures local syntax 220*58f35182SJung-uk Kim 221*58f35182SJung-uk Kim# File::Spec::Unix doesn't detect case insensitivity, so we make sure to 222*58f35182SJung-uk Kim# check if the source and build directory are really the same, and make 223*58f35182SJung-uk Kim# them so. This avoids all kinds of confusion later on. 224*58f35182SJung-uk Kim# We must check @File::Spec::ISA rather than using File::Spec->isa() to 225*58f35182SJung-uk Kim# know if File::Spec ended up loading File::Spec::Unix. 226*58f35182SJung-uk Kim$srcdir = $blddir 227*58f35182SJung-uk Kim if (grep(/::Unix$/, @File::Spec::ISA) 228*58f35182SJung-uk Kim && samedir($srcdir, $blddir)); 229*58f35182SJung-uk Kim 230e71b7053SJung-uk Kimmy $dofile = abs2rel(catfile($srcdir, "util/dofile.pl")); 23174664626SKris Kennaway 232e71b7053SJung-uk Kimmy $local_config_envname = 'OPENSSL_LOCAL_CONFIG_DIR'; 233a21b1b38SKris Kennaway 234*58f35182SJung-uk Kim$config{sourcedir} = abs2rel($srcdir, $blddir); 235*58f35182SJung-uk Kim$config{builddir} = abs2rel($blddir, $blddir); 23674664626SKris Kennaway 237e71b7053SJung-uk Kim# Collect reconfiguration information if needed 238e71b7053SJung-uk Kimmy @argvcopy=@ARGV; 23974664626SKris Kennaway 240e71b7053SJung-uk Kimif (grep /^reconf(igure)?$/, @argvcopy) { 241e71b7053SJung-uk Kim die "reconfiguring with other arguments present isn't supported" 242e71b7053SJung-uk Kim if scalar @argvcopy > 1; 243e71b7053SJung-uk Kim if (-f "./configdata.pm") { 244e71b7053SJung-uk Kim my $file = "./configdata.pm"; 245e71b7053SJung-uk Kim unless (my $return = do $file) { 246e71b7053SJung-uk Kim die "couldn't parse $file: $@" if $@; 247e71b7053SJung-uk Kim die "couldn't do $file: $!" unless defined $return; 248e71b7053SJung-uk Kim die "couldn't run $file" unless $return; 2491f13597dSJung-uk Kim } 2503b4e3dcbSSimon L. B. Nielsen 251e71b7053SJung-uk Kim @argvcopy = defined($configdata::config{perlargv}) ? 252e71b7053SJung-uk Kim @{$configdata::config{perlargv}} : (); 253e71b7053SJung-uk Kim die "Incorrect data to reconfigure, please do a normal configuration\n" 254e71b7053SJung-uk Kim if (grep(/^reconf/,@argvcopy)); 255e71b7053SJung-uk Kim $config{perlenv} = $configdata::config{perlenv} // {}; 256e71b7053SJung-uk Kim } else { 257e71b7053SJung-uk Kim die "Insufficient data to reconfigure, please do a normal configuration\n"; 258e71b7053SJung-uk Kim } 259e71b7053SJung-uk Kim} 2603b4e3dcbSSimon L. B. Nielsen 261e71b7053SJung-uk Kim$config{perlargv} = [ @argvcopy ]; 262e71b7053SJung-uk Kim 263e71b7053SJung-uk Kim# Collect version numbers 264e71b7053SJung-uk Kim$config{version} = "unknown"; 265e71b7053SJung-uk Kim$config{version_num} = "unknown"; 266e71b7053SJung-uk Kim$config{shlib_version_number} = "unknown"; 267e71b7053SJung-uk Kim$config{shlib_version_history} = "unknown"; 268e71b7053SJung-uk Kim 269e71b7053SJung-uk Kimcollect_information( 270e71b7053SJung-uk Kim collect_from_file(catfile($srcdir,'include/openssl/opensslv.h')), 271e71b7053SJung-uk Kim qr/OPENSSL.VERSION.TEXT.*OpenSSL (\S+) / => sub { $config{version} = $1; }, 272e71b7053SJung-uk Kim qr/OPENSSL.VERSION.NUMBER.*(0x\S+)/ => sub { $config{version_num}=$1 }, 273e71b7053SJung-uk Kim qr/SHLIB_VERSION_NUMBER *"([^"]+)"/ => sub { $config{shlib_version_number}=$1 }, 274e71b7053SJung-uk Kim qr/SHLIB_VERSION_HISTORY *"([^"]*)"/ => sub { $config{shlib_version_history}=$1 } 275e71b7053SJung-uk Kim ); 276e71b7053SJung-uk Kimif ($config{shlib_version_history} ne "") { $config{shlib_version_history} .= ":"; } 277e71b7053SJung-uk Kim 278e71b7053SJung-uk Kim($config{major}, $config{minor}) 279e71b7053SJung-uk Kim = ($config{version} =~ /^([0-9]+)\.([0-9\.]+)/); 280e71b7053SJung-uk Kim($config{shlib_major}, $config{shlib_minor}) 281e71b7053SJung-uk Kim = ($config{shlib_version_number} =~ /^([0-9]+)\.([0-9\.]+)/); 282e71b7053SJung-uk Kimdie "erroneous version information in opensslv.h: ", 283e71b7053SJung-uk Kim "$config{major}, $config{minor}, $config{shlib_major}, $config{shlib_minor}\n" 284e71b7053SJung-uk Kim if ($config{major} eq "" || $config{minor} eq "" 285e71b7053SJung-uk Kim || $config{shlib_major} eq "" || $config{shlib_minor} eq ""); 286e71b7053SJung-uk Kim 287e71b7053SJung-uk Kim# Collect target configurations 288e71b7053SJung-uk Kim 289e71b7053SJung-uk Kimmy $pattern = catfile(dirname($0), "Configurations", "*.conf"); 290e71b7053SJung-uk Kimforeach (sort glob($pattern)) { 291e71b7053SJung-uk Kim &read_config($_); 292e71b7053SJung-uk Kim} 293e71b7053SJung-uk Kim 294e71b7053SJung-uk Kimif (defined env($local_config_envname)) { 295e71b7053SJung-uk Kim if ($^O eq 'VMS') { 296e71b7053SJung-uk Kim # VMS environment variables are logical names, 297e71b7053SJung-uk Kim # which can be used as is 298e71b7053SJung-uk Kim $pattern = $local_config_envname . ':' . '*.conf'; 299e71b7053SJung-uk Kim } else { 300e71b7053SJung-uk Kim $pattern = catfile(env($local_config_envname), '*.conf'); 301e71b7053SJung-uk Kim } 302e71b7053SJung-uk Kim 303e71b7053SJung-uk Kim foreach (sort glob($pattern)) { 304e71b7053SJung-uk Kim &read_config($_); 305e71b7053SJung-uk Kim } 306e71b7053SJung-uk Kim} 307e71b7053SJung-uk Kim 308e71b7053SJung-uk Kim# Save away perl command information 309e71b7053SJung-uk Kim$config{perl_cmd} = $^X; 310e71b7053SJung-uk Kim$config{perl_version} = $Config{version}; 311e71b7053SJung-uk Kim$config{perl_archname} = $Config{archname}; 312e71b7053SJung-uk Kim 313e71b7053SJung-uk Kim$config{prefix}=""; 314e71b7053SJung-uk Kim$config{openssldir}=""; 315e71b7053SJung-uk Kim$config{processor}=""; 316e71b7053SJung-uk Kim$config{libdir}=""; 317e71b7053SJung-uk Kimmy $auto_threads=1; # enable threads automatically? true by default 318e71b7053SJung-uk Kimmy $default_ranlib; 319e71b7053SJung-uk Kim 320e71b7053SJung-uk Kim# Top level directories to build 321e71b7053SJung-uk Kim$config{dirs} = [ "crypto", "ssl", "engines", "apps", "test", "util", "tools", "fuzz" ]; 322e71b7053SJung-uk Kim# crypto/ subdirectories to build 323e71b7053SJung-uk Kim$config{sdirs} = [ 324e71b7053SJung-uk Kim "objects", 325e71b7053SJung-uk Kim "md2", "md4", "md5", "sha", "mdc2", "hmac", "ripemd", "whrlpool", "poly1305", "blake2", "siphash", "sm3", 326e71b7053SJung-uk Kim "des", "aes", "rc2", "rc4", "rc5", "idea", "aria", "bf", "cast", "camellia", "seed", "sm4", "chacha", "modes", 327e71b7053SJung-uk Kim "bn", "ec", "rsa", "dsa", "dh", "sm2", "dso", "engine", 328e71b7053SJung-uk Kim "buffer", "bio", "stack", "lhash", "rand", "err", 329e71b7053SJung-uk Kim "evp", "asn1", "pem", "x509", "x509v3", "conf", "txt_db", "pkcs7", "pkcs12", "comp", "ocsp", "ui", 330e71b7053SJung-uk Kim "cms", "ts", "srp", "cmac", "ct", "async", "kdf", "store" 331e71b7053SJung-uk Kim ]; 332e71b7053SJung-uk Kim# test/ subdirectories to build 333e71b7053SJung-uk Kim$config{tdirs} = [ "ossl_shim" ]; 334e71b7053SJung-uk Kim 335e71b7053SJung-uk Kim# Known TLS and DTLS protocols 336e71b7053SJung-uk Kimmy @tls = qw(ssl3 tls1 tls1_1 tls1_2 tls1_3); 337e71b7053SJung-uk Kimmy @dtls = qw(dtls1 dtls1_2); 338e71b7053SJung-uk Kim 339e71b7053SJung-uk Kim# Explicitly known options that are possible to disable. They can 340e71b7053SJung-uk Kim# be regexps, and will be used like this: /^no-${option}$/ 341e71b7053SJung-uk Kim# For developers: keep it sorted alphabetically 342e71b7053SJung-uk Kim 343e71b7053SJung-uk Kimmy @disablables = ( 344e71b7053SJung-uk Kim "afalgeng", 345e71b7053SJung-uk Kim "aria", 346e71b7053SJung-uk Kim "asan", 347e71b7053SJung-uk Kim "asm", 348e71b7053SJung-uk Kim "async", 349e71b7053SJung-uk Kim "autoalginit", 350e71b7053SJung-uk Kim "autoerrinit", 351e71b7053SJung-uk Kim "autoload-config", 352e71b7053SJung-uk Kim "bf", 353e71b7053SJung-uk Kim "blake2", 354610a21fdSJung-uk Kim "buildtest-c\\+\\+", 355e71b7053SJung-uk Kim "camellia", 356e71b7053SJung-uk Kim "capieng", 357e71b7053SJung-uk Kim "cast", 358e71b7053SJung-uk Kim "chacha", 359e71b7053SJung-uk Kim "cmac", 360e71b7053SJung-uk Kim "cms", 361e71b7053SJung-uk Kim "comp", 362e71b7053SJung-uk Kim "crypto-mdebug", 363e71b7053SJung-uk Kim "crypto-mdebug-backtrace", 364e71b7053SJung-uk Kim "ct", 365e71b7053SJung-uk Kim "deprecated", 366e71b7053SJung-uk Kim "des", 367e71b7053SJung-uk Kim "devcryptoeng", 368e71b7053SJung-uk Kim "dgram", 369e71b7053SJung-uk Kim "dh", 370e71b7053SJung-uk Kim "dsa", 37117f01e99SJung-uk Kim "dso", 372e71b7053SJung-uk Kim "dtls", 373e71b7053SJung-uk Kim "dynamic-engine", 374e71b7053SJung-uk Kim "ec", 375e71b7053SJung-uk Kim "ec2m", 376e71b7053SJung-uk Kim "ecdh", 377e71b7053SJung-uk Kim "ecdsa", 378e71b7053SJung-uk Kim "ec_nistp_64_gcc_128", 379e71b7053SJung-uk Kim "egd", 380e71b7053SJung-uk Kim "engine", 381e71b7053SJung-uk Kim "err", 382e71b7053SJung-uk Kim "external-tests", 383e71b7053SJung-uk Kim "filenames", 384e71b7053SJung-uk Kim "fuzz-libfuzzer", 385e71b7053SJung-uk Kim "fuzz-afl", 386e71b7053SJung-uk Kim "gost", 387e71b7053SJung-uk Kim "heartbeats", 388e71b7053SJung-uk Kim "hw(-.+)?", 389e71b7053SJung-uk Kim "idea", 390e71b7053SJung-uk Kim "makedepend", 391e71b7053SJung-uk Kim "md2", 392e71b7053SJung-uk Kim "md4", 393e71b7053SJung-uk Kim "mdc2", 394e71b7053SJung-uk Kim "msan", 395e71b7053SJung-uk Kim "multiblock", 396e71b7053SJung-uk Kim "nextprotoneg", 3976935a639SJung-uk Kim "pinshared", 398e71b7053SJung-uk Kim "ocb", 399e71b7053SJung-uk Kim "ocsp", 400e71b7053SJung-uk Kim "pic", 401e71b7053SJung-uk Kim "poly1305", 402e71b7053SJung-uk Kim "posix-io", 403e71b7053SJung-uk Kim "psk", 404e71b7053SJung-uk Kim "rc2", 405e71b7053SJung-uk Kim "rc4", 406e71b7053SJung-uk Kim "rc5", 407e71b7053SJung-uk Kim "rdrand", 408e71b7053SJung-uk Kim "rfc3779", 409e71b7053SJung-uk Kim "rmd160", 410e71b7053SJung-uk Kim "scrypt", 411e71b7053SJung-uk Kim "sctp", 412e71b7053SJung-uk Kim "seed", 413e71b7053SJung-uk Kim "shared", 414e71b7053SJung-uk Kim "siphash", 415e71b7053SJung-uk Kim "sm2", 416e71b7053SJung-uk Kim "sm3", 417e71b7053SJung-uk Kim "sm4", 418e71b7053SJung-uk Kim "sock", 419e71b7053SJung-uk Kim "srp", 420e71b7053SJung-uk Kim "srtp", 421e71b7053SJung-uk Kim "sse2", 422e71b7053SJung-uk Kim "ssl", 423e71b7053SJung-uk Kim "ssl-trace", 424e71b7053SJung-uk Kim "static-engine", 425e71b7053SJung-uk Kim "stdio", 426e71b7053SJung-uk Kim "tests", 427e71b7053SJung-uk Kim "threads", 428e71b7053SJung-uk Kim "tls", 429e71b7053SJung-uk Kim "ts", 430e71b7053SJung-uk Kim "ubsan", 431e71b7053SJung-uk Kim "ui-console", 432e71b7053SJung-uk Kim "unit-test", 433e71b7053SJung-uk Kim "whirlpool", 434e71b7053SJung-uk Kim "weak-ssl-ciphers", 435e71b7053SJung-uk Kim "zlib", 436e71b7053SJung-uk Kim "zlib-dynamic", 437e71b7053SJung-uk Kim ); 438e71b7053SJung-uk Kimforeach my $proto ((@tls, @dtls)) 439e71b7053SJung-uk Kim { 440e71b7053SJung-uk Kim push(@disablables, $proto); 441e71b7053SJung-uk Kim push(@disablables, "$proto-method") unless $proto eq "tls1_3"; 442e71b7053SJung-uk Kim } 443e71b7053SJung-uk Kim 444e71b7053SJung-uk Kimmy %deprecated_disablables = ( 445e71b7053SJung-uk Kim "ssl2" => undef, 446e71b7053SJung-uk Kim "buf-freelists" => undef, 447e71b7053SJung-uk Kim "ripemd" => "rmd160", 448e71b7053SJung-uk Kim "ui" => "ui-console", 449e71b7053SJung-uk Kim ); 450e71b7053SJung-uk Kim 451e71b7053SJung-uk Kim# All of the following are disabled by default: 452e71b7053SJung-uk Kim 453e71b7053SJung-uk Kimour %disabled = ( # "what" => "comment" 454e71b7053SJung-uk Kim "asan" => "default", 455610a21fdSJung-uk Kim "buildtest-c++" => "default", 456e71b7053SJung-uk Kim "crypto-mdebug" => "default", 457e71b7053SJung-uk Kim "crypto-mdebug-backtrace" => "default", 458e71b7053SJung-uk Kim "devcryptoeng" => "default", 4591f13597dSJung-uk Kim "ec_nistp_64_gcc_128" => "default", 460e71b7053SJung-uk Kim "egd" => "default", 461e71b7053SJung-uk Kim "external-tests" => "default", 462e71b7053SJung-uk Kim "fuzz-libfuzzer" => "default", 463e71b7053SJung-uk Kim "fuzz-afl" => "default", 464e71b7053SJung-uk Kim "heartbeats" => "default", 4651f13597dSJung-uk Kim "md2" => "default", 466e71b7053SJung-uk Kim "msan" => "default", 4673b4e3dcbSSimon L. B. Nielsen "rc5" => "default", 4681f13597dSJung-uk Kim "sctp" => "default", 4697bded2dbSJung-uk Kim "ssl-trace" => "default", 470e71b7053SJung-uk Kim "ssl3" => "default", 471e71b7053SJung-uk Kim "ssl3-method" => "default", 472e71b7053SJung-uk Kim "ubsan" => "default", 473a93cbc2bSJung-uk Kim "unit-test" => "default", 4744c6a0400SJung-uk Kim "weak-ssl-ciphers" => "default", 4753b4e3dcbSSimon L. B. Nielsen "zlib" => "default", 476e71b7053SJung-uk Kim "zlib-dynamic" => "default", 4773b4e3dcbSSimon L. B. Nielsen ); 4783b4e3dcbSSimon L. B. Nielsen 479e71b7053SJung-uk Kim# Note: => pair form used for aesthetics, not to truly make a hash table 480e71b7053SJung-uk Kimmy @disable_cascades = ( 481e71b7053SJung-uk Kim # "what" => [ "cascade", ... ] 482e71b7053SJung-uk Kim sub { $config{processor} eq "386" } 483e71b7053SJung-uk Kim => [ "sse2" ], 484e71b7053SJung-uk Kim "ssl" => [ "ssl3" ], 485e71b7053SJung-uk Kim "ssl3-method" => [ "ssl3" ], 486e71b7053SJung-uk Kim "zlib" => [ "zlib-dynamic" ], 487e71b7053SJung-uk Kim "des" => [ "mdc2" ], 488e71b7053SJung-uk Kim "ec" => [ "ecdsa", "ecdh" ], 489e71b7053SJung-uk Kim 490e71b7053SJung-uk Kim "dgram" => [ "dtls", "sctp" ], 491e71b7053SJung-uk Kim "sock" => [ "dgram" ], 492e71b7053SJung-uk Kim "dtls" => [ @dtls ], 493e71b7053SJung-uk Kim sub { 0 == scalar grep { !$disabled{$_} } @dtls } 494e71b7053SJung-uk Kim => [ "dtls" ], 495e71b7053SJung-uk Kim 496e71b7053SJung-uk Kim "tls" => [ @tls ], 497e71b7053SJung-uk Kim sub { 0 == scalar grep { !$disabled{$_} } @tls } 498e71b7053SJung-uk Kim => [ "tls" ], 499e71b7053SJung-uk Kim 500e71b7053SJung-uk Kim "crypto-mdebug" => [ "crypto-mdebug-backtrace" ], 501e71b7053SJung-uk Kim 502e71b7053SJung-uk Kim # Without position independent code, there can be no shared libraries or DSOs 503e71b7053SJung-uk Kim "pic" => [ "shared" ], 504e71b7053SJung-uk Kim "shared" => [ "dynamic-engine" ], 50517f01e99SJung-uk Kim "dso" => [ "dynamic-engine" ], 506e71b7053SJung-uk Kim "engine" => [ "afalgeng", "devcryptoeng" ], 507e71b7053SJung-uk Kim 508e71b7053SJung-uk Kim # no-autoalginit is only useful when building non-shared 509e71b7053SJung-uk Kim "autoalginit" => [ "shared", "apps" ], 510e71b7053SJung-uk Kim 511e71b7053SJung-uk Kim "stdio" => [ "apps", "capieng", "egd" ], 512e71b7053SJung-uk Kim "apps" => [ "tests" ], 513e71b7053SJung-uk Kim "tests" => [ "external-tests" ], 514e71b7053SJung-uk Kim "comp" => [ "zlib" ], 515e71b7053SJung-uk Kim "ec" => [ "tls1_3", "sm2" ], 516e71b7053SJung-uk Kim "sm3" => [ "sm2" ], 517e71b7053SJung-uk Kim sub { !$disabled{"unit-test"} } => [ "heartbeats" ], 518e71b7053SJung-uk Kim 519e71b7053SJung-uk Kim sub { !$disabled{"msan"} } => [ "asm" ], 520e71b7053SJung-uk Kim ); 521e71b7053SJung-uk Kim 522e71b7053SJung-uk Kim# Avoid protocol support holes. Also disable all versions below N, if version 523e71b7053SJung-uk Kim# N is disabled while N+1 is enabled. 524e71b7053SJung-uk Kim# 525e71b7053SJung-uk Kimmy @list = (reverse @tls); 526e71b7053SJung-uk Kimwhile ((my $first, my $second) = (shift @list, shift @list)) { 527e71b7053SJung-uk Kim last unless @list; 528e71b7053SJung-uk Kim push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} } 529e71b7053SJung-uk Kim => [ @list ] ); 530e71b7053SJung-uk Kim unshift @list, $second; 531e71b7053SJung-uk Kim} 532e71b7053SJung-uk Kimmy @list = (reverse @dtls); 533e71b7053SJung-uk Kimwhile ((my $first, my $second) = (shift @list, shift @list)) { 534e71b7053SJung-uk Kim last unless @list; 535e71b7053SJung-uk Kim push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} } 536e71b7053SJung-uk Kim => [ @list ] ); 537e71b7053SJung-uk Kim unshift @list, $second; 538e71b7053SJung-uk Kim} 539db522d3aSSimon L. B. Nielsen 540db522d3aSSimon L. B. Nielsen# Explicit "no-..." options will be collected in %disabled along with the defaults. 541e71b7053SJung-uk Kim# To remove something from %disabled, use "enable-foo". 542db522d3aSSimon L. B. Nielsen# For symmetry, "disable-foo" is a synonym for "no-foo". 543db522d3aSSimon L. B. Nielsen 54474664626SKris Kennaway&usage if ($#ARGV < 0); 54574664626SKris Kennaway 54617f01e99SJung-uk Kim# For the "make variables" CPPINCLUDES and CPPDEFINES, we support lists with 547e71b7053SJung-uk Kim# platform specific list separators. Users from those platforms should 548e71b7053SJung-uk Kim# recognise those separators from how you set up the PATH to find executables. 549e71b7053SJung-uk Kim# The default is the Unix like separator, :, but as an exception, we also 550e71b7053SJung-uk Kim# support the space as separator. 551e71b7053SJung-uk Kimmy $list_separator_re = 552e71b7053SJung-uk Kim { VMS => qr/(?<!\^),/, 553e71b7053SJung-uk Kim MSWin32 => qr/(?<!\\);/ } -> {$^O} // qr/(?<!\\)[:\s]/; 554e71b7053SJung-uk Kim# All the "make variables" we support 555e71b7053SJung-uk Kim# Some get pre-populated for the sake of backward compatibility 556e71b7053SJung-uk Kim# (we supported those before the change to "make variable" support. 557e71b7053SJung-uk Kimmy %user = ( 558e71b7053SJung-uk Kim AR => env('AR'), 559e71b7053SJung-uk Kim ARFLAGS => [], 560e71b7053SJung-uk Kim AS => undef, 561e71b7053SJung-uk Kim ASFLAGS => [], 562e71b7053SJung-uk Kim CC => env('CC'), 563610a21fdSJung-uk Kim CFLAGS => [ env('CFLAGS') || () ], 564e71b7053SJung-uk Kim CXX => env('CXX'), 565610a21fdSJung-uk Kim CXXFLAGS => [ env('CXXFLAGS') || () ], 566e71b7053SJung-uk Kim CPP => undef, 567610a21fdSJung-uk Kim CPPFLAGS => [ env('CPPFLAGS') || () ], # -D, -I, -Wp, 568e71b7053SJung-uk Kim CPPDEFINES => [], # Alternative for -D 569e71b7053SJung-uk Kim CPPINCLUDES => [], # Alternative for -I 570e71b7053SJung-uk Kim CROSS_COMPILE => env('CROSS_COMPILE'), 571e71b7053SJung-uk Kim HASHBANGPERL=> env('HASHBANGPERL') || env('PERL'), 572e71b7053SJung-uk Kim LD => undef, 573610a21fdSJung-uk Kim LDFLAGS => [ env('LDFLAGS') || () ], # -L, -Wl, 574610a21fdSJung-uk Kim LDLIBS => [ env('LDLIBS') || () ], # -l 575e71b7053SJung-uk Kim MT => undef, 576e71b7053SJung-uk Kim MTFLAGS => [], 577e71b7053SJung-uk Kim PERL => env('PERL') || ($^O ne "VMS" ? $^X : "perl"), 578e71b7053SJung-uk Kim RANLIB => env('RANLIB'), 579e71b7053SJung-uk Kim RC => env('RC') || env('WINDRES'), 580610a21fdSJung-uk Kim RCFLAGS => [ env('RCFLAGS') || () ], 581e71b7053SJung-uk Kim RM => undef, 582e71b7053SJung-uk Kim ); 583e71b7053SJung-uk Kim# Info about what "make variables" may be prefixed with the cross compiler 584e71b7053SJung-uk Kim# prefix. This should NEVER mention any such variable with a list for value. 585e71b7053SJung-uk Kimmy @user_crossable = qw ( AR AS CC CXX CPP LD MT RANLIB RC ); 586e71b7053SJung-uk Kim# The same but for flags given as Configure options. These are *additional* 587e71b7053SJung-uk Kim# input, as opposed to the VAR=string option that override the corresponding 588e71b7053SJung-uk Kim# config target attributes 589e71b7053SJung-uk Kimmy %useradd = ( 590e71b7053SJung-uk Kim CPPDEFINES => [], 591e71b7053SJung-uk Kim CPPINCLUDES => [], 592e71b7053SJung-uk Kim CPPFLAGS => [], 593e71b7053SJung-uk Kim CFLAGS => [], 594e71b7053SJung-uk Kim CXXFLAGS => [], 595e71b7053SJung-uk Kim LDFLAGS => [], 596e71b7053SJung-uk Kim LDLIBS => [], 597610a21fdSJung-uk Kim RCFLAGS => [], 598e71b7053SJung-uk Kim ); 599ddd58736SKris Kennaway 600e71b7053SJung-uk Kimmy %user_synonyms = ( 601e71b7053SJung-uk Kim HASHBANGPERL=> 'PERL', 602e71b7053SJung-uk Kim RC => 'WINDRES', 603e71b7053SJung-uk Kim ); 604ddd58736SKris Kennaway 605e71b7053SJung-uk Kim# Some target attributes have been renamed, this is the translation table 606e71b7053SJung-uk Kimmy %target_attr_translate =( 607e71b7053SJung-uk Kim ar => 'AR', 608e71b7053SJung-uk Kim as => 'AS', 609e71b7053SJung-uk Kim cc => 'CC', 610e71b7053SJung-uk Kim cxx => 'CXX', 611e71b7053SJung-uk Kim cpp => 'CPP', 612e71b7053SJung-uk Kim hashbangperl => 'HASHBANGPERL', 613e71b7053SJung-uk Kim ld => 'LD', 614e71b7053SJung-uk Kim mt => 'MT', 615e71b7053SJung-uk Kim ranlib => 'RANLIB', 616e71b7053SJung-uk Kim rc => 'RC', 617e71b7053SJung-uk Kim rm => 'RM', 618e71b7053SJung-uk Kim ); 619e71b7053SJung-uk Kim 620e71b7053SJung-uk Kim# Initialisers coming from 'config' scripts 621e71b7053SJung-uk Kim$config{defines} = [ split(/$list_separator_re/, env('__CNF_CPPDEFINES')) ]; 622e71b7053SJung-uk Kim$config{includes} = [ split(/$list_separator_re/, env('__CNF_CPPINCLUDES')) ]; 623e71b7053SJung-uk Kim$config{cppflags} = [ env('__CNF_CPPFLAGS') || () ]; 624e71b7053SJung-uk Kim$config{cflags} = [ env('__CNF_CFLAGS') || () ]; 625e71b7053SJung-uk Kim$config{cxxflags} = [ env('__CNF_CXXFLAGS') || () ]; 626e71b7053SJung-uk Kim$config{lflags} = [ env('__CNF_LDFLAGS') || () ]; 627e71b7053SJung-uk Kim$config{ex_libs} = [ env('__CNF_LDLIBS') || () ]; 628e71b7053SJung-uk Kim 629e71b7053SJung-uk Kim$config{openssl_api_defines}=[]; 630e71b7053SJung-uk Kim$config{openssl_algorithm_defines}=[]; 631e71b7053SJung-uk Kim$config{openssl_thread_defines}=[]; 632e71b7053SJung-uk Kim$config{openssl_sys_defines}=[]; 633e71b7053SJung-uk Kim$config{openssl_other_defines}=[]; 634e71b7053SJung-uk Kim$config{options}=""; 635e71b7053SJung-uk Kim$config{build_type} = "release"; 636e71b7053SJung-uk Kimmy $target=""; 637e71b7053SJung-uk Kim 638e71b7053SJung-uk Kimmy %cmdvars = (); # Stores FOO='blah' type arguments 639e71b7053SJung-uk Kimmy %unsupported_options = (); 640e71b7053SJung-uk Kimmy %deprecated_options = (); 641e71b7053SJung-uk Kim# If you change this, update apps/version.c 642e71b7053SJung-uk Kimmy @known_seed_sources = qw(getrandom devrandom os egd none rdcpu librandom); 643e71b7053SJung-uk Kimmy @seed_sources = (); 644e71b7053SJung-uk Kimwhile (@argvcopy) 645ddd58736SKris Kennaway { 646e71b7053SJung-uk Kim $_ = shift @argvcopy; 647ddd58736SKris Kennaway 648e71b7053SJung-uk Kim # Support env variable assignments among the options 649e71b7053SJung-uk Kim if (m|^(\w+)=(.+)?$|) 65074664626SKris Kennaway { 651e71b7053SJung-uk Kim $cmdvars{$1} = $2; 652e71b7053SJung-uk Kim # Every time a variable is given as a configuration argument, 653e71b7053SJung-uk Kim # it acts as a reset if the variable. 654e71b7053SJung-uk Kim if (exists $user{$1}) 655e71b7053SJung-uk Kim { 656e71b7053SJung-uk Kim $user{$1} = ref $user{$1} eq "ARRAY" ? [] : undef; 657e71b7053SJung-uk Kim } 658e71b7053SJung-uk Kim #if (exists $useradd{$1}) 659e71b7053SJung-uk Kim # { 660e71b7053SJung-uk Kim # $useradd{$1} = []; 661e71b7053SJung-uk Kim # } 662e71b7053SJung-uk Kim next; 663e71b7053SJung-uk Kim } 664e71b7053SJung-uk Kim 665e71b7053SJung-uk Kim # VMS is a case insensitive environment, and depending on settings 666e71b7053SJung-uk Kim # out of our control, we may receive options uppercased. Let's 667e71b7053SJung-uk Kim # downcase at least the part before any equal sign. 668e71b7053SJung-uk Kim if ($^O eq "VMS") 669e71b7053SJung-uk Kim { 670e71b7053SJung-uk Kim s/^([^=]*)/lc($1)/e; 671e71b7053SJung-uk Kim } 672e71b7053SJung-uk Kim 673e71b7053SJung-uk Kim # some people just can't read the instructions, clang people have to... 674e71b7053SJung-uk Kim s/^-no-(?!integrated-as)/no-/; 6753b4e3dcbSSimon L. B. Nielsen 6763b4e3dcbSSimon L. B. Nielsen # rewrite some options in "enable-..." form 6773b4e3dcbSSimon L. B. Nielsen s /^-?-?shared$/enable-shared/; 6781f13597dSJung-uk Kim s /^sctp$/enable-sctp/; 6793b4e3dcbSSimon L. B. Nielsen s /^threads$/enable-threads/; 6803b4e3dcbSSimon L. B. Nielsen s /^zlib$/enable-zlib/; 6813b4e3dcbSSimon L. B. Nielsen s /^zlib-dynamic$/enable-zlib-dynamic/; 6823b4e3dcbSSimon L. B. Nielsen 683e71b7053SJung-uk Kim if (/^(no|disable|enable)-(.+)$/) 684e71b7053SJung-uk Kim { 685e71b7053SJung-uk Kim my $word = $2; 686e71b7053SJung-uk Kim if (!exists $deprecated_disablables{$word} 687e71b7053SJung-uk Kim && !grep { $word =~ /^${_}$/ } @disablables) 688e71b7053SJung-uk Kim { 689e71b7053SJung-uk Kim $unsupported_options{$_} = 1; 690e71b7053SJung-uk Kim next; 691e71b7053SJung-uk Kim } 692e71b7053SJung-uk Kim } 6933b4e3dcbSSimon L. B. Nielsen if (/^no-(.+)$/ || /^disable-(.+)$/) 6943b4e3dcbSSimon L. B. Nielsen { 695e71b7053SJung-uk Kim foreach my $proto ((@tls, @dtls)) 696db522d3aSSimon L. B. Nielsen { 697e71b7053SJung-uk Kim if ($1 eq "$proto-method") 6983b4e3dcbSSimon L. B. Nielsen { 699e71b7053SJung-uk Kim $disabled{"$proto"} = "option($proto-method)"; 700e71b7053SJung-uk Kim last; 701e71b7053SJung-uk Kim } 702e71b7053SJung-uk Kim } 703e71b7053SJung-uk Kim if ($1 eq "dtls") 704e71b7053SJung-uk Kim { 705e71b7053SJung-uk Kim foreach my $proto (@dtls) 706e71b7053SJung-uk Kim { 707e71b7053SJung-uk Kim $disabled{$proto} = "option(dtls)"; 708e71b7053SJung-uk Kim } 709e71b7053SJung-uk Kim $disabled{"dtls"} = "option(dtls)"; 710e71b7053SJung-uk Kim } 711e71b7053SJung-uk Kim elsif ($1 eq "ssl") 712e71b7053SJung-uk Kim { 713e71b7053SJung-uk Kim # Last one of its kind 7143b4e3dcbSSimon L. B. Nielsen $disabled{"ssl3"} = "option(ssl)"; 7153b4e3dcbSSimon L. B. Nielsen } 7163b4e3dcbSSimon L. B. Nielsen elsif ($1 eq "tls") 7173b4e3dcbSSimon L. B. Nielsen { 718e71b7053SJung-uk Kim # XXX: Tests will fail if all SSL/TLS 719e71b7053SJung-uk Kim # protocols are disabled. 720e71b7053SJung-uk Kim foreach my $proto (@tls) 721751d2991SJung-uk Kim { 722e71b7053SJung-uk Kim $disabled{$proto} = "option(tls)"; 723e71b7053SJung-uk Kim } 724e71b7053SJung-uk Kim } 725e71b7053SJung-uk Kim elsif ($1 eq "static-engine") 726e71b7053SJung-uk Kim { 727e71b7053SJung-uk Kim delete $disabled{"dynamic-engine"}; 728e71b7053SJung-uk Kim } 729e71b7053SJung-uk Kim elsif ($1 eq "dynamic-engine") 730e71b7053SJung-uk Kim { 731e71b7053SJung-uk Kim $disabled{"dynamic-engine"} = "option"; 732e71b7053SJung-uk Kim } 733e71b7053SJung-uk Kim elsif (exists $deprecated_disablables{$1}) 734e71b7053SJung-uk Kim { 735610a21fdSJung-uk Kim if ($deprecated_disablables{$1} ne "") 736610a21fdSJung-uk Kim { 737e71b7053SJung-uk Kim $deprecated_options{$_} = 1; 738e71b7053SJung-uk Kim if (defined $deprecated_disablables{$1}) 739e71b7053SJung-uk Kim { 740e71b7053SJung-uk Kim $disabled{$deprecated_disablables{$1}} = "option"; 741e71b7053SJung-uk Kim } 742751d2991SJung-uk Kim } 743610a21fdSJung-uk Kim } 7443b4e3dcbSSimon L. B. Nielsen else 7453b4e3dcbSSimon L. B. Nielsen { 7463b4e3dcbSSimon L. B. Nielsen $disabled{$1} = "option"; 7473b4e3dcbSSimon L. B. Nielsen } 748e71b7053SJung-uk Kim # No longer an automatic choice 749e71b7053SJung-uk Kim $auto_threads = 0 if ($1 eq "threads"); 7503b4e3dcbSSimon L. B. Nielsen } 751e71b7053SJung-uk Kim elsif (/^enable-(.+)$/) 7523b4e3dcbSSimon L. B. Nielsen { 753e71b7053SJung-uk Kim if ($1 eq "static-engine") 754e71b7053SJung-uk Kim { 755e71b7053SJung-uk Kim $disabled{"dynamic-engine"} = "option"; 756e71b7053SJung-uk Kim } 757e71b7053SJung-uk Kim elsif ($1 eq "dynamic-engine") 758e71b7053SJung-uk Kim { 759e71b7053SJung-uk Kim delete $disabled{"dynamic-engine"}; 760e71b7053SJung-uk Kim } 761e71b7053SJung-uk Kim elsif ($1 eq "zlib-dynamic") 762e71b7053SJung-uk Kim { 763e71b7053SJung-uk Kim delete $disabled{"zlib"}; 764e71b7053SJung-uk Kim } 765db522d3aSSimon L. B. Nielsen my $algo = $1; 766db522d3aSSimon L. B. Nielsen delete $disabled{$algo}; 7673b4e3dcbSSimon L. B. Nielsen 768e71b7053SJung-uk Kim # No longer an automatic choice 769e71b7053SJung-uk Kim $auto_threads = 0 if ($1 eq "threads"); 7703b4e3dcbSSimon L. B. Nielsen } 771e71b7053SJung-uk Kim elsif (/^--strict-warnings$/) 7726a599222SSimon L. B. Nielsen { 773610a21fdSJung-uk Kim # Pretend that our strict flags is a C flag, and replace it 774610a21fdSJung-uk Kim # with the proper flags later on 775610a21fdSJung-uk Kim push @{$useradd{CFLAGS}}, '--ossl-strict-warnings'; 7766a599222SSimon L. B. Nielsen $strict_warnings=1; 7776a599222SSimon L. B. Nielsen } 778e71b7053SJung-uk Kim elsif (/^--debug$/) 779ddd58736SKris Kennaway { 780e71b7053SJung-uk Kim $config{build_type} = "debug"; 781ddd58736SKris Kennaway } 782e71b7053SJung-uk Kim elsif (/^--release$/) 783e71b7053SJung-uk Kim { 784e71b7053SJung-uk Kim $config{build_type} = "release"; 785ddd58736SKris Kennaway } 78674664626SKris Kennaway elsif (/^386$/) 787e71b7053SJung-uk Kim { $config{processor}=386; } 788db522d3aSSimon L. B. Nielsen elsif (/^fips$/) 789db522d3aSSimon L. B. Nielsen { 790e71b7053SJung-uk Kim die "FIPS mode not supported\n"; 791db522d3aSSimon L. B. Nielsen } 79274664626SKris Kennaway elsif (/^rsaref$/) 79374664626SKris Kennaway { 7945c87c606SMark Murray # No RSAref support any more since it's not needed. 7955c87c606SMark Murray # The check for the option is there so scripts aren't 7965c87c606SMark Murray # broken 79774664626SKris Kennaway } 798e71b7053SJung-uk Kim elsif (/^nofipscanistercheck$/) 799e71b7053SJung-uk Kim { 800e71b7053SJung-uk Kim die "FIPS mode not supported\n"; 801e71b7053SJung-uk Kim } 80217f01e99SJung-uk Kim elsif (m|^[-+/]|) 80374664626SKris Kennaway { 8047bded2dbSJung-uk Kim if (/^--prefix=(.*)$/) 80574664626SKris Kennaway { 806e71b7053SJung-uk Kim $config{prefix}=$1; 807e71b7053SJung-uk Kim die "Directory given with --prefix MUST be absolute\n" 808e71b7053SJung-uk Kim unless file_name_is_absolute($config{prefix}); 809e71b7053SJung-uk Kim } 810e71b7053SJung-uk Kim elsif (/^--api=(.*)$/) 811e71b7053SJung-uk Kim { 812e71b7053SJung-uk Kim $config{api}=$1; 81374664626SKris Kennaway } 8146a599222SSimon L. B. Nielsen elsif (/^--libdir=(.*)$/) 8156a599222SSimon L. B. Nielsen { 816e71b7053SJung-uk Kim $config{libdir}=$1; 8176a599222SSimon L. B. Nielsen } 81874664626SKris Kennaway elsif (/^--openssldir=(.*)$/) 81974664626SKris Kennaway { 820e71b7053SJung-uk Kim $config{openssldir}=$1; 8215c87c606SMark Murray } 8223b4e3dcbSSimon L. B. Nielsen elsif (/^--with-zlib-lib=(.*)$/) 8233b4e3dcbSSimon L. B. Nielsen { 824e71b7053SJung-uk Kim $withargs{zlib_lib}=$1; 8253b4e3dcbSSimon L. B. Nielsen } 8263b4e3dcbSSimon L. B. Nielsen elsif (/^--with-zlib-include=(.*)$/) 8273b4e3dcbSSimon L. B. Nielsen { 828e71b7053SJung-uk Kim $withargs{zlib_include}=$1; 8293b4e3dcbSSimon L. B. Nielsen } 830e71b7053SJung-uk Kim elsif (/^--with-fuzzer-lib=(.*)$/) 8311f13597dSJung-uk Kim { 832e71b7053SJung-uk Kim $withargs{fuzzer_lib}=$1; 8331f13597dSJung-uk Kim } 834e71b7053SJung-uk Kim elsif (/^--with-fuzzer-include=(.*)$/) 835db522d3aSSimon L. B. Nielsen { 836e71b7053SJung-uk Kim $withargs{fuzzer_include}=$1; 837db522d3aSSimon L. B. Nielsen } 838e71b7053SJung-uk Kim elsif (/^--with-rand-seed=(.*)$/) 839db522d3aSSimon L. B. Nielsen { 840e71b7053SJung-uk Kim foreach my $x (split(m|,|, $1)) 841e71b7053SJung-uk Kim { 842e71b7053SJung-uk Kim die "Unknown --with-rand-seed choice $x\n" 843e71b7053SJung-uk Kim if ! grep { $x eq $_ } @known_seed_sources; 844e71b7053SJung-uk Kim push @seed_sources, $x; 845e71b7053SJung-uk Kim } 846db522d3aSSimon L. B. Nielsen } 8471f13597dSJung-uk Kim elsif (/^--cross-compile-prefix=(.*)$/) 8481f13597dSJung-uk Kim { 849e71b7053SJung-uk Kim $user{CROSS_COMPILE}=$1; 8501f13597dSJung-uk Kim } 851e71b7053SJung-uk Kim elsif (/^--config=(.*)$/) 85274664626SKris Kennaway { 853e71b7053SJung-uk Kim read_config $1; 854e71b7053SJung-uk Kim } 855e71b7053SJung-uk Kim elsif (/^-l(.*)$/) 856e71b7053SJung-uk Kim { 857e71b7053SJung-uk Kim push @{$useradd{LDLIBS}}, $_; 858e71b7053SJung-uk Kim } 859e71b7053SJung-uk Kim elsif (/^-framework$/) 860e71b7053SJung-uk Kim { 861e71b7053SJung-uk Kim push @{$useradd{LDLIBS}}, $_, shift(@argvcopy); 862e71b7053SJung-uk Kim } 863e71b7053SJung-uk Kim elsif (/^-L(.*)$/ or /^-Wl,/) 864e71b7053SJung-uk Kim { 865e71b7053SJung-uk Kim push @{$useradd{LDFLAGS}}, $_; 866e71b7053SJung-uk Kim } 867e71b7053SJung-uk Kim elsif (/^-rpath$/ or /^-R$/) 868e71b7053SJung-uk Kim # -rpath is the OSF1 rpath flag 869e71b7053SJung-uk Kim # -R is the old Solaris rpath flag 870e71b7053SJung-uk Kim { 871e71b7053SJung-uk Kim my $rpath = shift(@argvcopy) || ""; 872e71b7053SJung-uk Kim $rpath .= " " if $rpath ne ""; 873e71b7053SJung-uk Kim push @{$useradd{LDFLAGS}}, $_, $rpath; 874e71b7053SJung-uk Kim } 875e71b7053SJung-uk Kim elsif (/^-static$/) 876e71b7053SJung-uk Kim { 877e71b7053SJung-uk Kim push @{$useradd{LDFLAGS}}, $_; 878e71b7053SJung-uk Kim } 87917f01e99SJung-uk Kim elsif (m|^[-/]D(.*)$|) 880e71b7053SJung-uk Kim { 881e71b7053SJung-uk Kim push @{$useradd{CPPDEFINES}}, $1; 882e71b7053SJung-uk Kim } 88317f01e99SJung-uk Kim elsif (m|^[-/]I(.*)$|) 884e71b7053SJung-uk Kim { 885e71b7053SJung-uk Kim push @{$useradd{CPPINCLUDES}}, $1; 886e71b7053SJung-uk Kim } 887e71b7053SJung-uk Kim elsif (/^-Wp,$/) 888e71b7053SJung-uk Kim { 889e71b7053SJung-uk Kim push @{$useradd{CPPFLAGS}}, $1; 8907bded2dbSJung-uk Kim } 8917bded2dbSJung-uk Kim else # common if (/^[-+]/), just pass down... 8927bded2dbSJung-uk Kim { 89317f01e99SJung-uk Kim # Treat %xx as an ASCII code (e.g. replace %20 by a space character). 89417f01e99SJung-uk Kim # This provides a simple way to pass options with arguments separated 89517f01e99SJung-uk Kim # by spaces without quoting (e.g. -opt%20arg translates to -opt arg). 8967bded2dbSJung-uk Kim $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei; 897e71b7053SJung-uk Kim push @{$useradd{CFLAGS}}, $_; 898e71b7053SJung-uk Kim push @{$useradd{CXXFLAGS}}, $_; 89974664626SKris Kennaway } 90074664626SKris Kennaway } 90117f01e99SJung-uk Kim elsif (m|^/|) 90217f01e99SJung-uk Kim { 90317f01e99SJung-uk Kim # Treat %xx as an ASCII code (e.g. replace %20 by a space character). 90417f01e99SJung-uk Kim # This provides a simple way to pass options with arguments separated 90517f01e99SJung-uk Kim # by spaces without quoting (e.g. /opt%20arg translates to /opt arg). 90617f01e99SJung-uk Kim $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei; 90717f01e99SJung-uk Kim push @{$useradd{CFLAGS}}, $_; 90817f01e99SJung-uk Kim push @{$useradd{CXXFLAGS}}, $_; 90917f01e99SJung-uk Kim } 91074664626SKris Kennaway else 91174664626SKris Kennaway { 9123b4e3dcbSSimon L. B. Nielsen die "target already defined - $target (offending arg: $_)\n" if ($target ne ""); 91374664626SKris Kennaway $target=$_; 91474664626SKris Kennaway } 9153b4e3dcbSSimon L. B. Nielsen unless ($_ eq $target || /^no-/ || /^disable-/) 9165c87c606SMark Murray { 917e71b7053SJung-uk Kim # "no-..." follows later after implied deactivations 918e71b7053SJung-uk Kim # have been derived. (Don't take this too seriously, 9193b4e3dcbSSimon L. B. Nielsen # we really only write OPTIONS to the Makefile out of 9203b4e3dcbSSimon L. B. Nielsen # nostalgia.) 9213b4e3dcbSSimon L. B. Nielsen 922e71b7053SJung-uk Kim if ($config{options} eq "") 923e71b7053SJung-uk Kim { $config{options} = $_; } 9243b4e3dcbSSimon L. B. Nielsen else 925e71b7053SJung-uk Kim { $config{options} .= " ".$_; } 9263b4e3dcbSSimon L. B. Nielsen } 9275c87c606SMark Murray } 9285c87c606SMark Murray 929e71b7053SJung-uk Kimif (defined($config{api}) && !exists $apitable->{$config{api}}) { 930e71b7053SJung-uk Kim die "***** Unsupported api compatibility level: $config{api}\n", 931e71b7053SJung-uk Kim} 9323b4e3dcbSSimon L. B. Nielsen 933e71b7053SJung-uk Kimif (keys %deprecated_options) 9345c87c606SMark Murray { 935e71b7053SJung-uk Kim warn "***** Deprecated options: ", 936e71b7053SJung-uk Kim join(", ", keys %deprecated_options), "\n"; 937e71b7053SJung-uk Kim } 938e71b7053SJung-uk Kimif (keys %unsupported_options) 939e71b7053SJung-uk Kim { 940e71b7053SJung-uk Kim die "***** Unsupported options: ", 941e71b7053SJung-uk Kim join(", ", keys %unsupported_options), "\n"; 9425c87c606SMark Murray } 9435c87c606SMark Murray 944e71b7053SJung-uk Kim# If any %useradd entry has been set, we must check that the "make 945e71b7053SJung-uk Kim# variables" haven't been set. We start by checking of any %useradd entry 946e71b7053SJung-uk Kim# is set. 947e71b7053SJung-uk Kimif (grep { scalar @$_ > 0 } values %useradd) { 948e71b7053SJung-uk Kim # Hash of env / make variables names. The possible values are: 949e71b7053SJung-uk Kim # 1 - "make vars" 950e71b7053SJung-uk Kim # 2 - %useradd entry set 951e71b7053SJung-uk Kim # 3 - both set 952e71b7053SJung-uk Kim my %detected_vars = 953e71b7053SJung-uk Kim map { my $v = 0; 954e71b7053SJung-uk Kim $v += 1 if $cmdvars{$_}; 955e71b7053SJung-uk Kim $v += 2 if @{$useradd{$_}}; 956e71b7053SJung-uk Kim $_ => $v } 957e71b7053SJung-uk Kim keys %useradd; 958e71b7053SJung-uk Kim 959e71b7053SJung-uk Kim # If any of the corresponding "make variables" is set, we error 960e71b7053SJung-uk Kim if (grep { $_ & 1 } values %detected_vars) { 961e71b7053SJung-uk Kim my $names = join(', ', grep { $detected_vars{$_} > 0 } 962e71b7053SJung-uk Kim sort keys %detected_vars); 963e71b7053SJung-uk Kim die <<"_____"; 964e71b7053SJung-uk Kim***** Mixing make variables and additional compiler/linker flags as 965e71b7053SJung-uk Kim***** configure command line option is not permitted. 966e71b7053SJung-uk Kim***** Affected make variables: $names 967e71b7053SJung-uk Kim_____ 968e71b7053SJung-uk Kim } 9695c87c606SMark Murray} 9705c87c606SMark Murray 971e71b7053SJung-uk Kim# Check through all supported command line variables to see if any of them 972e71b7053SJung-uk Kim# were set, and canonicalise the values we got. If no compiler or linker 973e71b7053SJung-uk Kim# flag or anything else that affects %useradd was set, we also check the 974e71b7053SJung-uk Kim# environment for values. 975e71b7053SJung-uk Kimmy $anyuseradd = 976e71b7053SJung-uk Kim grep { defined $_ && (ref $_ ne 'ARRAY' || @$_) } values %useradd; 977e71b7053SJung-uk Kimforeach (keys %user) { 978e71b7053SJung-uk Kim my $value = $cmdvars{$_}; 979e71b7053SJung-uk Kim $value //= env($_) unless $anyuseradd; 980e71b7053SJung-uk Kim $value //= 981e71b7053SJung-uk Kim defined $user_synonyms{$_} ? $cmdvars{$user_synonyms{$_}} : undef; 982e71b7053SJung-uk Kim $value //= defined $user_synonyms{$_} ? env($user_synonyms{$_}) : undef 983e71b7053SJung-uk Kim unless $anyuseradd; 984e71b7053SJung-uk Kim 985e71b7053SJung-uk Kim if (defined $value) { 986e71b7053SJung-uk Kim if (ref $user{$_} eq 'ARRAY') { 98717f01e99SJung-uk Kim if ($_ eq 'CPPDEFINES' || $_ eq 'CPPINCLUDES') { 988e71b7053SJung-uk Kim $user{$_} = [ split /$list_separator_re/, $value ]; 98917f01e99SJung-uk Kim } else { 99017f01e99SJung-uk Kim $user{$_} = [ $value ]; 99117f01e99SJung-uk Kim } 992e71b7053SJung-uk Kim } elsif (!defined $user{$_}) { 993e71b7053SJung-uk Kim $user{$_} = $value; 994e71b7053SJung-uk Kim } 995e71b7053SJung-uk Kim } 9963b4e3dcbSSimon L. B. Nielsen} 9973b4e3dcbSSimon L. B. Nielsen 998e71b7053SJung-uk Kimif (grep { /-rpath\b/ } ($user{LDFLAGS} ? @{$user{LDFLAGS}} : ()) 999e71b7053SJung-uk Kim && !$disabled{shared} 1000e71b7053SJung-uk Kim && !($disabled{asan} && $disabled{msan} && $disabled{ubsan})) { 1001e71b7053SJung-uk Kim die "***** Cannot simultaneously use -rpath, shared libraries, and\n", 1002e71b7053SJung-uk Kim "***** any of asan, msan or ubsan\n"; 10033b4e3dcbSSimon L. B. Nielsen} 10043b4e3dcbSSimon L. B. Nielsen 1005610a21fdSJung-uk Kimsub disable { 1006610a21fdSJung-uk Kim my $disable_type = shift; 1007610a21fdSJung-uk Kim 1008610a21fdSJung-uk Kim for (@_) { 1009610a21fdSJung-uk Kim $disabled{$_} = $disable_type; 1010610a21fdSJung-uk Kim } 1011610a21fdSJung-uk Kim 1012610a21fdSJung-uk Kim my @tocheckfor = (@_ ? @_ : keys %disabled); 1013e71b7053SJung-uk Kim while (@tocheckfor) { 1014e71b7053SJung-uk Kim my %new_tocheckfor = (); 1015e71b7053SJung-uk Kim my @cascade_copy = (@disable_cascades); 1016e71b7053SJung-uk Kim while (@cascade_copy) { 1017610a21fdSJung-uk Kim my ($test, $descendents) = 1018610a21fdSJung-uk Kim (shift @cascade_copy, shift @cascade_copy); 1019e71b7053SJung-uk Kim if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) { 1020e71b7053SJung-uk Kim foreach (grep { !defined($disabled{$_}) } @$descendents) { 1021610a21fdSJung-uk Kim $new_tocheckfor{$_} = 1; $disabled{$_} = "cascade"; 1022e71b7053SJung-uk Kim } 1023e71b7053SJung-uk Kim } 1024e71b7053SJung-uk Kim } 1025e71b7053SJung-uk Kim @tocheckfor = (keys %new_tocheckfor); 10263b4e3dcbSSimon L. B. Nielsen } 1027610a21fdSJung-uk Kim} 1028610a21fdSJung-uk Kimdisable(); # First cascade run 10293b4e3dcbSSimon L. B. Nielsen 1030e71b7053SJung-uk Kimour $die = sub { die @_; }; 103174664626SKris Kennawayif ($target eq "TABLE") { 1032e71b7053SJung-uk Kim local $die = sub { warn @_; }; 1033e71b7053SJung-uk Kim foreach (sort keys %table) { 1034e71b7053SJung-uk Kim print_table_entry($_, "TABLE"); 103574664626SKris Kennaway } 103674664626SKris Kennaway exit 0; 103774664626SKris Kennaway} 103874664626SKris Kennaway 1039f579bf8eSKris Kennawayif ($target eq "LIST") { 1040f579bf8eSKris Kennaway foreach (sort keys %table) { 1041e71b7053SJung-uk Kim print $_,"\n" unless $table{$_}->{template}; 1042f579bf8eSKris Kennaway } 1043f579bf8eSKris Kennaway exit 0; 1044f579bf8eSKris Kennaway} 1045f579bf8eSKris Kennaway 1046e71b7053SJung-uk Kimif ($target eq "HASH") { 1047e71b7053SJung-uk Kim local $die = sub { warn @_; }; 1048e71b7053SJung-uk Kim print "%table = (\n"; 1049e71b7053SJung-uk Kim foreach (sort keys %table) { 1050e71b7053SJung-uk Kim print_table_entry($_, "HASH"); 1051e71b7053SJung-uk Kim } 1052e71b7053SJung-uk Kim exit 0; 1053e71b7053SJung-uk Kim} 1054e71b7053SJung-uk Kim 1055e71b7053SJung-uk Kimprint "Configuring OpenSSL version $config{version} ($config{version_num}) "; 1056e71b7053SJung-uk Kimprint "for $target\n"; 1057e71b7053SJung-uk Kim 1058e71b7053SJung-uk Kimif (scalar(@seed_sources) == 0) { 1059e71b7053SJung-uk Kim print "Using os-specific seed configuration\n"; 1060e71b7053SJung-uk Kim push @seed_sources, 'os'; 1061e71b7053SJung-uk Kim} 1062*58f35182SJung-uk Kimif (scalar(grep { $_ eq 'egd' } @seed_sources) > 0) { 1063*58f35182SJung-uk Kim delete $disabled{'egd'}; 1064*58f35182SJung-uk Kim} 1065e71b7053SJung-uk Kimif (scalar(grep { $_ eq 'none' } @seed_sources) > 0) { 1066e71b7053SJung-uk Kim die "Cannot seed with none and anything else" if scalar(@seed_sources) > 1; 1067e71b7053SJung-uk Kim warn <<_____ if scalar(@seed_sources) == 1; 1068e71b7053SJung-uk Kim 1069c9cf7b5cSJung-uk Kim============================== WARNING =============================== 1070c9cf7b5cSJung-uk KimYou have selected the --with-rand-seed=none option, which effectively 1071c9cf7b5cSJung-uk Kimdisables automatic reseeding of the OpenSSL random generator. 1072c9cf7b5cSJung-uk KimAll operations depending on the random generator such as creating keys 1073c9cf7b5cSJung-uk Kimwill not work unless the random generator is seeded manually by the 1074c9cf7b5cSJung-uk Kimapplication. 1075c9cf7b5cSJung-uk Kim 1076c9cf7b5cSJung-uk KimPlease read the 'Note on random number generation' section in the 1077c9cf7b5cSJung-uk KimINSTALL instructions and the RAND_DRBG(7) manual page for more details. 1078c9cf7b5cSJung-uk Kim============================== WARNING =============================== 1079c9cf7b5cSJung-uk Kim 1080e71b7053SJung-uk Kim_____ 1081e71b7053SJung-uk Kim} 1082e71b7053SJung-uk Kimpush @{$config{openssl_other_defines}}, 1083e71b7053SJung-uk Kim map { (my $x = $_) =~ tr|[\-a-z]|[_A-Z]|; "OPENSSL_RAND_SEED_$x" } 1084e71b7053SJung-uk Kim @seed_sources; 1085e71b7053SJung-uk Kim 1086e71b7053SJung-uk Kim# Backward compatibility? 1087c1803d78SJacques Vidrineif ($target =~ m/^CygWin32(-.*)$/) { 1088c1803d78SJacques Vidrine $target = "Cygwin".$1; 1089c1803d78SJacques Vidrine} 1090c1803d78SJacques Vidrine 1091e71b7053SJung-uk Kim# Support for legacy targets having a name starting with 'debug-' 1092e71b7053SJung-uk Kimmy ($d, $t) = $target =~ m/^(debug-)?(.*)$/; 1093e71b7053SJung-uk Kimif ($d) { 1094e71b7053SJung-uk Kim $config{build_type} = "debug"; 1095ddd58736SKris Kennaway 1096e71b7053SJung-uk Kim # If we do not find debug-foo in the table, the target is set to foo. 1097e71b7053SJung-uk Kim if (!$table{$target}) { 1098e71b7053SJung-uk Kim $target = $t; 10991f13597dSJung-uk Kim } 1100e71b7053SJung-uk Kim} 11011f13597dSJung-uk Kim 1102e71b7053SJung-uk Kim&usage if !$table{$target} || $table{$target}->{template}; 1103e71b7053SJung-uk Kim 1104e71b7053SJung-uk Kim$config{target} = $target; 1105e71b7053SJung-uk Kimmy %target = resolve_config($target); 1106e71b7053SJung-uk Kim 1107e71b7053SJung-uk Kimforeach (keys %target_attr_translate) { 1108e71b7053SJung-uk Kim $target{$target_attr_translate{$_}} = $target{$_} 1109e71b7053SJung-uk Kim if $target{$_}; 1110e71b7053SJung-uk Kim delete $target{$_}; 1111e71b7053SJung-uk Kim} 1112e71b7053SJung-uk Kim 1113e71b7053SJung-uk Kim%target = ( %{$table{DEFAULTS}}, %target ); 1114e71b7053SJung-uk Kim 1115e71b7053SJung-uk Kimmy %conf_files = map { $_ => 1 } (@{$target{_conf_fname_int}}); 1116e71b7053SJung-uk Kim$config{conf_files} = [ sort keys %conf_files ]; 1117e71b7053SJung-uk Kim 1118610a21fdSJung-uk Kim# Using sub disable within these loops may prove fragile, so we run 1119610a21fdSJung-uk Kim# a cascade afterwards 1120e71b7053SJung-uk Kimforeach my $feature (@{$target{disable}}) { 1121e71b7053SJung-uk Kim if (exists $deprecated_disablables{$feature}) { 1122e71b7053SJung-uk Kim warn "***** config $target disables deprecated feature $feature\n"; 1123e71b7053SJung-uk Kim } elsif (!grep { $feature eq $_ } @disablables) { 1124e71b7053SJung-uk Kim die "***** config $target disables unknown feature $feature\n"; 1125e71b7053SJung-uk Kim } 1126e71b7053SJung-uk Kim $disabled{$feature} = 'config'; 1127e71b7053SJung-uk Kim} 1128e71b7053SJung-uk Kimforeach my $feature (@{$target{enable}}) { 11296935a639SJung-uk Kim if ("default" eq ($disabled{$feature} // "")) { 1130e71b7053SJung-uk Kim if (exists $deprecated_disablables{$feature}) { 1131e71b7053SJung-uk Kim warn "***** config $target enables deprecated feature $feature\n"; 1132e71b7053SJung-uk Kim } elsif (!grep { $feature eq $_ } @disablables) { 1133e71b7053SJung-uk Kim die "***** config $target enables unknown feature $feature\n"; 1134e71b7053SJung-uk Kim } 11356935a639SJung-uk Kim delete $disabled{$feature}; 1136e71b7053SJung-uk Kim } 1137e71b7053SJung-uk Kim} 1138610a21fdSJung-uk Kimdisable(); # Run a cascade now 1139e71b7053SJung-uk Kim 1140e71b7053SJung-uk Kim$target{CXXFLAGS}//=$target{CFLAGS} if $target{CXX}; 1141e71b7053SJung-uk Kim$target{cxxflags}//=$target{cflags} if $target{CXX}; 1142e71b7053SJung-uk Kim$target{exe_extension}=""; 1143e71b7053SJung-uk Kim$target{exe_extension}=".exe" if ($config{target} eq "DJGPP" 1144e71b7053SJung-uk Kim || $config{target} =~ /^(?:Cygwin|mingw)/); 1145e71b7053SJung-uk Kim$target{exe_extension}=".pm" if ($config{target} =~ /vos/); 1146e71b7053SJung-uk Kim 1147e71b7053SJung-uk Kim($target{shared_extension_simple}=$target{shared_extension}) 1148e71b7053SJung-uk Kim =~ s|\.\$\(SHLIB_VERSION_NUMBER\)|| 1149e71b7053SJung-uk Kim unless defined($target{shared_extension_simple}); 1150e71b7053SJung-uk Kim$target{dso_extension}//=$target{shared_extension_simple}; 1151e71b7053SJung-uk Kim($target{shared_import_extension}=$target{shared_extension_simple}.".a") 1152e71b7053SJung-uk Kim if ($config{target} =~ /^(?:Cygwin|mingw)/); 1153e71b7053SJung-uk Kim 1154e71b7053SJung-uk Kim# Fill %config with values from %user, and in case those are undefined or 1155e71b7053SJung-uk Kim# empty, use values from %target (acting as a default). 1156e71b7053SJung-uk Kimforeach (keys %user) { 1157e71b7053SJung-uk Kim my $ref_type = ref $user{$_}; 1158e71b7053SJung-uk Kim 1159e71b7053SJung-uk Kim # Temporary function. Takes an intended ref type (empty string or "ARRAY") 1160e71b7053SJung-uk Kim # and a value that's to be coerced into that type. 1161e71b7053SJung-uk Kim my $mkvalue = sub { 1162e71b7053SJung-uk Kim my $type = shift; 1163e71b7053SJung-uk Kim my $value = shift; 1164e71b7053SJung-uk Kim my $undef_p = shift; 1165e71b7053SJung-uk Kim 1166e71b7053SJung-uk Kim die "Too many arguments for \$mkvalue" if @_; 1167e71b7053SJung-uk Kim 1168e71b7053SJung-uk Kim while (ref $value eq 'CODE') { 1169e71b7053SJung-uk Kim $value = $value->(); 1170e71b7053SJung-uk Kim } 1171e71b7053SJung-uk Kim 1172e71b7053SJung-uk Kim if ($type eq 'ARRAY') { 1173e71b7053SJung-uk Kim return undef unless defined $value; 1174e71b7053SJung-uk Kim return undef if ref $value ne 'ARRAY' && !$value; 1175e71b7053SJung-uk Kim return undef if ref $value eq 'ARRAY' && !@$value; 1176e71b7053SJung-uk Kim return [ $value ] unless ref $value eq 'ARRAY'; 1177e71b7053SJung-uk Kim } 1178e71b7053SJung-uk Kim return undef unless $value; 1179e71b7053SJung-uk Kim return $value; 1180e71b7053SJung-uk Kim }; 1181e71b7053SJung-uk Kim 1182e71b7053SJung-uk Kim $config{$_} = 1183e71b7053SJung-uk Kim $mkvalue->($ref_type, $user{$_}) 1184e71b7053SJung-uk Kim || $mkvalue->($ref_type, $target{$_}); 1185e71b7053SJung-uk Kim delete $config{$_} unless defined $config{$_}; 1186e71b7053SJung-uk Kim} 1187e71b7053SJung-uk Kim 1188610a21fdSJung-uk Kim# Finish up %config by appending things the user gave us on the command line 1189610a21fdSJung-uk Kim# apart from "make variables" 1190610a21fdSJung-uk Kimforeach (keys %useradd) { 1191610a21fdSJung-uk Kim # The must all be lists, so we assert that here 1192610a21fdSJung-uk Kim die "internal error: \$useradd{$_} isn't an ARRAY\n" 1193610a21fdSJung-uk Kim unless ref $useradd{$_} eq 'ARRAY'; 1194610a21fdSJung-uk Kim 1195610a21fdSJung-uk Kim if (defined $config{$_}) { 1196610a21fdSJung-uk Kim push @{$config{$_}}, @{$useradd{$_}}; 1197610a21fdSJung-uk Kim } else { 1198610a21fdSJung-uk Kim $config{$_} = [ @{$useradd{$_}} ]; 1199610a21fdSJung-uk Kim } 1200610a21fdSJung-uk Kim} 1201610a21fdSJung-uk Kim# At this point, we can forget everything about %user and %useradd, 1202610a21fdSJung-uk Kim# because it's now all been merged into the corresponding $config entry 1203610a21fdSJung-uk Kim 1204e71b7053SJung-uk Kim# Allow overriding the build file name 1205e71b7053SJung-uk Kim$config{build_file} = env('BUILDFILE') || $target{build_file} || "Makefile"; 1206e71b7053SJung-uk Kim 1207e71b7053SJung-uk Kim# Make sure build_scheme is consistent. 1208e71b7053SJung-uk Kim$target{build_scheme} = [ $target{build_scheme} ] 1209e71b7053SJung-uk Kim if ref($target{build_scheme}) ne "ARRAY"; 1210e71b7053SJung-uk Kim 1211e71b7053SJung-uk Kimmy ($builder, $builder_platform, @builder_opts) = 1212e71b7053SJung-uk Kim @{$target{build_scheme}}; 1213e71b7053SJung-uk Kim 1214e71b7053SJung-uk Kimforeach my $checker (($builder_platform."-".$target{build_file}."-checker.pm", 1215e71b7053SJung-uk Kim $builder_platform."-checker.pm")) { 1216e71b7053SJung-uk Kim my $checker_path = catfile($srcdir, "Configurations", $checker); 1217e71b7053SJung-uk Kim if (-f $checker_path) { 1218e71b7053SJung-uk Kim my $fn = $ENV{CONFIGURE_CHECKER_WARN} 1219e71b7053SJung-uk Kim ? sub { warn $@; } : sub { die $@; }; 1220e71b7053SJung-uk Kim if (! do $checker_path) { 1221e71b7053SJung-uk Kim if ($@) { 1222e71b7053SJung-uk Kim $fn->($@); 1223e71b7053SJung-uk Kim } elsif ($!) { 1224e71b7053SJung-uk Kim $fn->($!); 1225e71b7053SJung-uk Kim } else { 1226e71b7053SJung-uk Kim $fn->("The detected tools didn't match the platform\n"); 1227e71b7053SJung-uk Kim } 1228e71b7053SJung-uk Kim } 1229e71b7053SJung-uk Kim last; 1230e71b7053SJung-uk Kim } 1231e71b7053SJung-uk Kim} 1232e71b7053SJung-uk Kim 1233e71b7053SJung-uk Kimpush @{$config{defines}}, "NDEBUG" if $config{build_type} eq "release"; 1234e71b7053SJung-uk Kim 1235e71b7053SJung-uk Kimif ($target =~ /^mingw/ && `$config{CC} --target-help 2>&1` =~ m/-mno-cygwin/m) 12361f13597dSJung-uk Kim { 1237e71b7053SJung-uk Kim push @{$config{cflags}}, "-mno-cygwin"; 1238e71b7053SJung-uk Kim push @{$config{cxxflags}}, "-mno-cygwin" if $config{CXX}; 1239e71b7053SJung-uk Kim push @{$config{shared_ldflag}}, "-mno-cygwin"; 12401f13597dSJung-uk Kim } 12411f13597dSJung-uk Kim 1242e71b7053SJung-uk Kimif ($target =~ /linux.*-mips/ && !$disabled{asm} 1243610a21fdSJung-uk Kim && !grep { $_ !~ /-m(ips|arch=)/ } (@{$config{CFLAGS}})) { 12447bded2dbSJung-uk Kim # minimally required architecture flags for assembly modules 1245e71b7053SJung-uk Kim my $value; 1246e71b7053SJung-uk Kim $value = '-mips2' if ($target =~ /mips32/); 1247e71b7053SJung-uk Kim $value = '-mips3' if ($target =~ /mips64/); 1248e71b7053SJung-uk Kim unshift @{$config{cflags}}, $value; 1249e71b7053SJung-uk Kim unshift @{$config{cxxflags}}, $value if $config{CXX}; 1250e71b7053SJung-uk Kim} 1251e71b7053SJung-uk Kim 1252e71b7053SJung-uk Kim# If threads aren't disabled, check how possible they are 1253e71b7053SJung-uk Kimunless ($disabled{threads}) { 1254e71b7053SJung-uk Kim if ($auto_threads) { 1255e71b7053SJung-uk Kim # Enabled by default, disable it forcibly if unavailable 1256e71b7053SJung-uk Kim if ($target{thread_scheme} eq "(unknown)") { 1257610a21fdSJung-uk Kim disable("unavailable", 'threads'); 1258e71b7053SJung-uk Kim } 1259e71b7053SJung-uk Kim } else { 1260e71b7053SJung-uk Kim # The user chose to enable threads explicitly, let's see 1261e71b7053SJung-uk Kim # if there's a chance that's possible 1262e71b7053SJung-uk Kim if ($target{thread_scheme} eq "(unknown)") { 1263e71b7053SJung-uk Kim # If the user asked for "threads" and we don't have internal 1264e71b7053SJung-uk Kim # knowledge how to do it, [s]he is expected to provide any 1265e71b7053SJung-uk Kim # system-dependent compiler options that are necessary. We 1266e71b7053SJung-uk Kim # can't truly check that the given options are correct, but 1267e71b7053SJung-uk Kim # we expect the user to know what [s]He is doing. 1268610a21fdSJung-uk Kim if (!@{$config{CFLAGS}} && !@{$config{CPPDEFINES}}) { 1269e71b7053SJung-uk Kim die "You asked for multi-threading support, but didn't\n" 1270e71b7053SJung-uk Kim ,"provide any system-specific compiler options\n"; 1271e71b7053SJung-uk Kim } 1272e71b7053SJung-uk Kim } 1273e71b7053SJung-uk Kim } 1274e71b7053SJung-uk Kim} 1275e71b7053SJung-uk Kim 1276e71b7053SJung-uk Kim# If threads still aren't disabled, add a C macro to ensure the source 1277e71b7053SJung-uk Kim# code knows about it. Any other flag is taken care of by the configs. 1278e71b7053SJung-uk Kimunless($disabled{threads}) { 1279e71b7053SJung-uk Kim push @{$config{openssl_thread_defines}}, "OPENSSL_THREADS"; 1280e71b7053SJung-uk Kim} 1281e71b7053SJung-uk Kim 1282e71b7053SJung-uk Kim# With "deprecated" disable all deprecated features. 1283e71b7053SJung-uk Kimif (defined($disabled{"deprecated"})) { 1284e71b7053SJung-uk Kim $config{api} = $maxapi; 12857bded2dbSJung-uk Kim} 12867bded2dbSJung-uk Kim 1287fceca8a3SJacques Vidrinemy $no_shared_warn=0; 1288e71b7053SJung-uk Kimif ($target{shared_target} eq "") 12895c87c606SMark Murray { 1290e71b7053SJung-uk Kim $no_shared_warn = 1 1291e71b7053SJung-uk Kim if (!$disabled{shared} || !$disabled{"dynamic-engine"}); 1292610a21fdSJung-uk Kim disable('no-shared-target', 'pic'); 12935c87c606SMark Murray } 12945c87c606SMark Murray 1295e71b7053SJung-uk Kimif ($disabled{"dynamic-engine"}) { 1296e71b7053SJung-uk Kim $config{dynamic_engines} = 0; 1297e71b7053SJung-uk Kim} else { 1298e71b7053SJung-uk Kim $config{dynamic_engines} = 1; 1299ddd58736SKris Kennaway} 1300ddd58736SKris Kennaway 1301e71b7053SJung-uk Kimunless ($disabled{asan}) { 1302e71b7053SJung-uk Kim push @{$config{cflags}}, "-fsanitize=address"; 130374664626SKris Kennaway} 130474664626SKris Kennaway 1305e71b7053SJung-uk Kimunless ($disabled{ubsan}) { 1306e71b7053SJung-uk Kim # -DPEDANTIC or -fnosanitize=alignment may also be required on some 1307e71b7053SJung-uk Kim # platforms. 1308e71b7053SJung-uk Kim push @{$config{cflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all"; 130974664626SKris Kennaway} 131074664626SKris Kennaway 1311e71b7053SJung-uk Kimunless ($disabled{msan}) { 1312e71b7053SJung-uk Kim push @{$config{cflags}}, "-fsanitize=memory"; 13135c87c606SMark Murray} 13145c87c606SMark Murray 1315e71b7053SJung-uk Kimunless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"} 1316e71b7053SJung-uk Kim && $disabled{asan} && $disabled{ubsan} && $disabled{msan}) { 1317e71b7053SJung-uk Kim push @{$config{cflags}}, "-fno-omit-frame-pointer", "-g"; 1318e71b7053SJung-uk Kim push @{$config{cxxflags}}, "-fno-omit-frame-pointer", "-g" if $config{CXX}; 131974664626SKris Kennaway} 1320db522d3aSSimon L. B. Nielsen# 1321db522d3aSSimon L. B. Nielsen# Platform fix-ups 1322db522d3aSSimon L. B. Nielsen# 1323db522d3aSSimon L. B. Nielsen 1324e71b7053SJung-uk Kim# This saves the build files from having to check 1325e71b7053SJung-uk Kimif ($disabled{pic}) 1326db522d3aSSimon L. B. Nielsen { 1327e71b7053SJung-uk Kim foreach (qw(shared_cflag shared_cxxflag shared_cppflag 1328e71b7053SJung-uk Kim shared_defines shared_includes shared_ldflag 1329e71b7053SJung-uk Kim module_cflags module_cxxflags module_cppflags 1330e71b7053SJung-uk Kim module_defines module_includes module_lflags)) 1331e71b7053SJung-uk Kim { 1332e71b7053SJung-uk Kim delete $config{$_}; 1333e71b7053SJung-uk Kim $target{$_} = ""; 1334ddd58736SKris Kennaway } 1335aeb5019cSJung-uk Kim } 1336aeb5019cSJung-uk Kimelse 1337aeb5019cSJung-uk Kim { 1338e71b7053SJung-uk Kim push @{$config{lib_defines}}, "OPENSSL_PIC"; 1339aeb5019cSJung-uk Kim } 1340e71b7053SJung-uk Kim 1341e71b7053SJung-uk Kimif ($target{sys_id} ne "") 134274664626SKris Kennaway { 1343e71b7053SJung-uk Kim push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}"; 13443b4e3dcbSSimon L. B. Nielsen } 1345e71b7053SJung-uk Kim 1346e71b7053SJung-uk Kimunless ($disabled{asm}) { 1347e71b7053SJung-uk Kim $target{cpuid_asm_src}=$table{DEFAULTS}->{cpuid_asm_src} if ($config{processor} eq "386"); 1348e71b7053SJung-uk Kim push @{$config{lib_defines}}, "OPENSSL_CPUID_OBJ" if ($target{cpuid_asm_src} ne "mem_clr.c"); 1349e71b7053SJung-uk Kim 1350e71b7053SJung-uk Kim $target{bn_asm_src} =~ s/\w+-gf2m.c// if (defined($disabled{ec2m})); 1351e71b7053SJung-uk Kim 1352e71b7053SJung-uk Kim # bn-586 is the only one implementing bn_*_part_words 1353e71b7053SJung-uk Kim push @{$config{lib_defines}}, "OPENSSL_BN_ASM_PART_WORDS" if ($target{bn_asm_src} =~ /bn-586/); 1354e71b7053SJung-uk Kim push @{$config{lib_defines}}, "OPENSSL_IA32_SSE2" if (!$disabled{sse2} && $target{bn_asm_src} =~ /86/); 1355e71b7053SJung-uk Kim 1356e71b7053SJung-uk Kim push @{$config{lib_defines}}, "OPENSSL_BN_ASM_MONT" if ($target{bn_asm_src} =~ /-mont/); 1357e71b7053SJung-uk Kim push @{$config{lib_defines}}, "OPENSSL_BN_ASM_MONT5" if ($target{bn_asm_src} =~ /-mont5/); 1358e71b7053SJung-uk Kim push @{$config{lib_defines}}, "OPENSSL_BN_ASM_GF2m" if ($target{bn_asm_src} =~ /-gf2m/); 13596935a639SJung-uk Kim push @{$config{lib_defines}}, "BN_DIV3W" if ($target{bn_asm_src} =~ /-div3w/); 1360e71b7053SJung-uk Kim 1361e71b7053SJung-uk Kim if ($target{sha1_asm_src}) { 1362e71b7053SJung-uk Kim push @{$config{lib_defines}}, "SHA1_ASM" if ($target{sha1_asm_src} =~ /sx86/ || $target{sha1_asm_src} =~ /sha1/); 1363e71b7053SJung-uk Kim push @{$config{lib_defines}}, "SHA256_ASM" if ($target{sha1_asm_src} =~ /sha256/); 1364e71b7053SJung-uk Kim push @{$config{lib_defines}}, "SHA512_ASM" if ($target{sha1_asm_src} =~ /sha512/); 136574664626SKris Kennaway } 1366e71b7053SJung-uk Kim if ($target{keccak1600_asm_src} ne $table{DEFAULTS}->{keccak1600_asm_src}) { 1367e71b7053SJung-uk Kim push @{$config{lib_defines}}, "KECCAK1600_ASM"; 136874664626SKris Kennaway } 1369e71b7053SJung-uk Kim if ($target{rc4_asm_src} ne $table{DEFAULTS}->{rc4_asm_src}) { 1370e71b7053SJung-uk Kim push @{$config{lib_defines}}, "RC4_ASM"; 137174664626SKris Kennaway } 1372e71b7053SJung-uk Kim if ($target{md5_asm_src}) { 1373e71b7053SJung-uk Kim push @{$config{lib_defines}}, "MD5_ASM"; 1374e71b7053SJung-uk Kim } 1375e71b7053SJung-uk Kim $target{cast_asm_src}=$table{DEFAULTS}->{cast_asm_src} unless $disabled{pic}; # CAST assembler is not PIC 1376e71b7053SJung-uk Kim if ($target{rmd160_asm_src}) { 1377e71b7053SJung-uk Kim push @{$config{lib_defines}}, "RMD160_ASM"; 1378e71b7053SJung-uk Kim } 1379e71b7053SJung-uk Kim if ($target{aes_asm_src}) { 1380e71b7053SJung-uk Kim push @{$config{lib_defines}}, "AES_ASM" if ($target{aes_asm_src} =~ m/\baes-/);; 138117f01e99SJung-uk Kim push @{$config{lib_defines}}, "AESNI_ASM" if ($target{aes_asm_src} =~ m/\baesni-/);; 1382e71b7053SJung-uk Kim # aes-ctr.fake is not a real file, only indication that assembler 13831f13597dSJung-uk Kim # module implements AES_ctr32_encrypt... 1384e71b7053SJung-uk Kim push @{$config{lib_defines}}, "AES_CTR_ASM" if ($target{aes_asm_src} =~ s/\s*aes-ctr\.fake//); 1385e71b7053SJung-uk Kim # aes-xts.fake indicates presence of AES_xts_[en|de]crypt... 1386e71b7053SJung-uk Kim push @{$config{lib_defines}}, "AES_XTS_ASM" if ($target{aes_asm_src} =~ s/\s*aes-xts\.fake//); 1387e71b7053SJung-uk Kim $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($disabled{sse2}); 1388e71b7053SJung-uk Kim push @{$config{lib_defines}}, "VPAES_ASM" if ($target{aes_asm_src} =~ m/vpaes/); 1389e71b7053SJung-uk Kim push @{$config{lib_defines}}, "BSAES_ASM" if ($target{aes_asm_src} =~ m/bsaes/); 13903b4e3dcbSSimon L. B. Nielsen } 1391e71b7053SJung-uk Kim if ($target{wp_asm_src} =~ /mmx/) { 1392e71b7053SJung-uk Kim if ($config{processor} eq "386") { 1393e71b7053SJung-uk Kim $target{wp_asm_src}=$table{DEFAULTS}->{wp_asm_src}; 1394e71b7053SJung-uk Kim } elsif (!$disabled{"whirlpool"}) { 1395e71b7053SJung-uk Kim push @{$config{lib_defines}}, "WHIRLPOOL_ASM"; 13966be8ae07SJacques Vidrine } 13971f13597dSJung-uk Kim } 1398e71b7053SJung-uk Kim if ($target{modes_asm_src} =~ /ghash-/) { 1399e71b7053SJung-uk Kim push @{$config{lib_defines}}, "GHASH_ASM"; 14001f13597dSJung-uk Kim } 1401e71b7053SJung-uk Kim if ($target{ec_asm_src} =~ /ecp_nistz256/) { 1402e71b7053SJung-uk Kim push @{$config{lib_defines}}, "ECP_NISTZ256_ASM"; 14031f13597dSJung-uk Kim } 1404e71b7053SJung-uk Kim if ($target{ec_asm_src} =~ /x25519/) { 1405e71b7053SJung-uk Kim push @{$config{lib_defines}}, "X25519_ASM"; 1406e71b7053SJung-uk Kim } 1407e71b7053SJung-uk Kim if ($target{padlock_asm_src} ne $table{DEFAULTS}->{padlock_asm_src}) { 1408610a21fdSJung-uk Kim push @{$config{dso_defines}}, "PADLOCK_ASM"; 1409e71b7053SJung-uk Kim } 1410e71b7053SJung-uk Kim if ($target{poly1305_asm_src} ne "") { 1411e71b7053SJung-uk Kim push @{$config{lib_defines}}, "POLY1305_ASM"; 1412e71b7053SJung-uk Kim } 14137bded2dbSJung-uk Kim} 14146be8ae07SJacques Vidrine 1415610a21fdSJung-uk Kimmy %predefined_C = compiler_predefined($config{CROSS_COMPILE}.$config{CC}); 1416610a21fdSJung-uk Kimmy %predefined_CXX = $config{CXX} 1417610a21fdSJung-uk Kim ? compiler_predefined($config{CROSS_COMPILE}.$config{CXX}) 1418610a21fdSJung-uk Kim : (); 14194f20a5a2SJacques Vidrine 1420e71b7053SJung-uk Kim# Check for makedepend capabilities. 1421e71b7053SJung-uk Kimif (!$disabled{makedepend}) { 1422e71b7053SJung-uk Kim if ($config{target} =~ /^(VC|vms)-/) { 1423e71b7053SJung-uk Kim # For VC- and vms- targets, there's nothing more to do here. The 1424e71b7053SJung-uk Kim # functionality is hard coded in the corresponding build files for 1425e71b7053SJung-uk Kim # cl (Windows) and CC/DECC (VMS). 1426610a21fdSJung-uk Kim } elsif (($predefined_C{__GNUC__} // -1) >= 3 1427610a21fdSJung-uk Kim && !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) { 1428e71b7053SJung-uk Kim # We know that GNU C version 3 and up as well as all clang 1429e71b7053SJung-uk Kim # versions support dependency generation, but Xcode did not 1430e71b7053SJung-uk Kim # handle $cc -M before clang support (but claims __GNUC__ = 3) 1431e71b7053SJung-uk Kim $config{makedepprog} = "\$(CROSS_COMPILE)$config{CC}"; 1432e71b7053SJung-uk Kim } else { 1433e71b7053SJung-uk Kim # In all other cases, we look for 'makedepend', and disable the 1434e71b7053SJung-uk Kim # capability if not found. 1435e71b7053SJung-uk Kim $config{makedepprog} = which('makedepend'); 1436610a21fdSJung-uk Kim disable('unavailable', 'makedepend') unless $config{makedepprog}; 143774664626SKris Kennaway } 143874664626SKris Kennaway} 143974664626SKris Kennaway 1440610a21fdSJung-uk Kimif (!$disabled{asm} && !$predefined_C{__MACH__} && $^O ne 'VMS') { 1441e71b7053SJung-uk Kim # probe for -Wa,--noexecstack option... 1442610a21fdSJung-uk Kim if ($predefined_C{__clang__}) { 1443e71b7053SJung-uk Kim # clang has builtin assembler, which doesn't recognize --help, 1444e71b7053SJung-uk Kim # but it apparently recognizes the option in question on all 1445e71b7053SJung-uk Kim # supported platforms even when it's meaningless. In other words 1446e71b7053SJung-uk Kim # probe would fail, but probed option always accepted... 1447e71b7053SJung-uk Kim push @{$config{cflags}}, "-Wa,--noexecstack", "-Qunused-arguments"; 1448e71b7053SJung-uk Kim } else { 1449e71b7053SJung-uk Kim my $cc = $config{CROSS_COMPILE}.$config{CC}; 1450e71b7053SJung-uk Kim open(PIPE, "$cc -Wa,--help -c -o null.$$.o -x assembler /dev/null 2>&1 |"); 1451dee36b4fSJung-uk Kim while(<PIPE>) { 1452e71b7053SJung-uk Kim if (m/--noexecstack/) { 1453e71b7053SJung-uk Kim push @{$config{cflags}}, "-Wa,--noexecstack"; 1454e71b7053SJung-uk Kim last; 1455e71b7053SJung-uk Kim } 1456dee36b4fSJung-uk Kim } 1457dee36b4fSJung-uk Kim close(PIPE); 1458e71b7053SJung-uk Kim unlink("null.$$.o"); 1459e71b7053SJung-uk Kim } 1460e71b7053SJung-uk Kim} 146180815a77SJung-uk Kim 1462e71b7053SJung-uk Kim# Deal with bn_ops ################################################### 1463e71b7053SJung-uk Kim 1464e71b7053SJung-uk Kim$config{bn_ll} =0; 1465e71b7053SJung-uk Kim$config{export_var_as_fn} =0; 1466e71b7053SJung-uk Kimmy $def_int="unsigned int"; 1467e71b7053SJung-uk Kim$config{rc4_int} =$def_int; 1468e71b7053SJung-uk Kim($config{b64l},$config{b64},$config{b32})=(0,0,1); 1469e71b7053SJung-uk Kim 1470e71b7053SJung-uk Kimmy $count = 0; 1471e71b7053SJung-uk Kimforeach (sort split(/\s+/,$target{bn_ops})) { 1472e71b7053SJung-uk Kim $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/; 1473e71b7053SJung-uk Kim $config{export_var_as_fn}=1 if $_ eq 'EXPORT_VAR_AS_FN'; 1474e71b7053SJung-uk Kim $config{bn_ll}=1 if $_ eq 'BN_LLONG'; 1475e71b7053SJung-uk Kim $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR'; 1476e71b7053SJung-uk Kim ($config{b64l},$config{b64},$config{b32}) 1477e71b7053SJung-uk Kim =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT'; 1478e71b7053SJung-uk Kim ($config{b64l},$config{b64},$config{b32}) 1479e71b7053SJung-uk Kim =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG'; 1480e71b7053SJung-uk Kim ($config{b64l},$config{b64},$config{b32}) 1481e71b7053SJung-uk Kim =(0,0,1) if $_ eq 'THIRTY_TWO_BIT'; 1482e71b7053SJung-uk Kim} 1483e71b7053SJung-uk Kimdie "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n" 1484e71b7053SJung-uk Kim if $count > 1; 1485e71b7053SJung-uk Kim 1486e71b7053SJung-uk Kim 1487e71b7053SJung-uk Kim# Hack cflags for better warnings (dev option) ####################### 1488e71b7053SJung-uk Kim 1489e71b7053SJung-uk Kim# "Stringify" the C and C++ flags string. This permits it to be made part of 1490e71b7053SJung-uk Kim# a string and works as well on command lines. 1491e71b7053SJung-uk Kim$config{cflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x } 1492e71b7053SJung-uk Kim @{$config{cflags}} ]; 1493e71b7053SJung-uk Kim$config{cxxflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x } 1494e71b7053SJung-uk Kim @{$config{cxxflags}} ] if $config{CXX}; 1495e71b7053SJung-uk Kim 1496e71b7053SJung-uk Kimif (defined($config{api})) { 1497e71b7053SJung-uk Kim $config{openssl_api_defines} = [ "OPENSSL_MIN_API=".$apitable->{$config{api}} ]; 1498e71b7053SJung-uk Kim my $apiflag = sprintf("OPENSSL_API_COMPAT=%s", $apitable->{$config{api}}); 1499e71b7053SJung-uk Kim push @{$config{defines}}, $apiflag; 1500dea77ea6SJung-uk Kim} 1501dea77ea6SJung-uk Kim 1502610a21fdSJung-uk Kimmy @strict_warnings_collection=(); 150380815a77SJung-uk Kimif ($strict_warnings) 150480815a77SJung-uk Kim { 15056a599222SSimon L. B. Nielsen my $wopt; 1506610a21fdSJung-uk Kim my $gccver = $predefined_C{__GNUC__} // -1; 1507e71b7053SJung-uk Kim 150817f01e99SJung-uk Kim if ($gccver >= 4) 150917f01e99SJung-uk Kim { 1510610a21fdSJung-uk Kim push @strict_warnings_collection, @gcc_devteam_warn; 1511610a21fdSJung-uk Kim push @strict_warnings_collection, @clang_devteam_warn 1512610a21fdSJung-uk Kim if (defined($predefined_C{__clang__})); 15136a599222SSimon L. B. Nielsen } 151417f01e99SJung-uk Kim elsif ($config{target} =~ /^VC-/) 151517f01e99SJung-uk Kim { 151617f01e99SJung-uk Kim push @strict_warnings_collection, @cl_devteam_warn; 151717f01e99SJung-uk Kim } 151817f01e99SJung-uk Kim else 151917f01e99SJung-uk Kim { 152017f01e99SJung-uk Kim warn "WARNING --strict-warnings requires gcc[>=4] or gcc-alike, or MSVC" 152117f01e99SJung-uk Kim } 152217f01e99SJung-uk Kim } 1523610a21fdSJung-uk Kim 1524610a21fdSJung-uk Kimif (grep { $_ eq '-static' } @{$config{LDFLAGS}}) { 1525610a21fdSJung-uk Kim disable('static', 'pic', 'threads'); 15267bded2dbSJung-uk Kim} 1527610a21fdSJung-uk Kim 1528610a21fdSJung-uk Kim$config{CFLAGS} = [ map { $_ eq '--ossl-strict-warnings' 1529610a21fdSJung-uk Kim ? @strict_warnings_collection 1530610a21fdSJung-uk Kim : ( $_ ) } 1531610a21fdSJung-uk Kim @{$config{CFLAGS}} ]; 15326a599222SSimon L. B. Nielsen 1533e71b7053SJung-uk Kimunless ($disabled{"crypto-mdebug-backtrace"}) 153474664626SKris Kennaway { 1535e71b7053SJung-uk Kim foreach my $wopt (split /\s+/, $memleak_devteam_backtrace) 15366a599222SSimon L. B. Nielsen { 1537e71b7053SJung-uk Kim push @{$config{cflags}}, $wopt 1538e71b7053SJung-uk Kim unless grep { $_ eq $wopt } @{$config{cflags}}; 15396a599222SSimon L. B. Nielsen } 1540e71b7053SJung-uk Kim if ($target =~ /^BSD-/) 1541a21b1b38SKris Kennaway { 1542e71b7053SJung-uk Kim push @{$config{ex_libs}}, "-lexecinfo"; 15434f20a5a2SJacques Vidrine } 154474664626SKris Kennaway } 154574664626SKris Kennaway 1546e71b7053SJung-uk Kimunless ($disabled{afalgeng}) { 1547e71b7053SJung-uk Kim $config{afalgeng}=""; 1548e71b7053SJung-uk Kim if (grep { $_ eq 'afalgeng' } @{$target{enable}}) { 1549e71b7053SJung-uk Kim my $minver = 4*10000 + 1*100 + 0; 1550e71b7053SJung-uk Kim if ($config{CROSS_COMPILE} eq "") { 1551e71b7053SJung-uk Kim my $verstr = `uname -r`; 1552e71b7053SJung-uk Kim my ($ma, $mi1, $mi2) = split("\\.", $verstr); 1553e71b7053SJung-uk Kim ($mi2) = $mi2 =~ /(\d+)/; 1554e71b7053SJung-uk Kim my $ver = $ma*10000 + $mi1*100 + $mi2; 1555e71b7053SJung-uk Kim if ($ver < $minver) { 1556610a21fdSJung-uk Kim disable('too-old-kernel', 'afalgeng'); 1557e71b7053SJung-uk Kim } else { 1558e71b7053SJung-uk Kim push @{$config{engdirs}}, "afalg"; 1559e71b7053SJung-uk Kim } 1560e71b7053SJung-uk Kim } else { 1561610a21fdSJung-uk Kim disable('cross-compiling', 'afalgeng'); 1562e71b7053SJung-uk Kim } 1563e71b7053SJung-uk Kim } else { 1564610a21fdSJung-uk Kim disable('not-linux', 'afalgeng'); 1565e71b7053SJung-uk Kim } 1566e71b7053SJung-uk Kim} 1567f579bf8eSKris Kennaway 156817f01e99SJung-uk Kimunless ($disabled{devcryptoeng}) { 156917f01e99SJung-uk Kim if ($target =~ m/^BSD/) { 157017f01e99SJung-uk Kim my $maxver = 5*100 + 7; 157117f01e99SJung-uk Kim my $sysstr = `uname -s`; 157217f01e99SJung-uk Kim my $verstr = `uname -r`; 157317f01e99SJung-uk Kim $sysstr =~ s|\R$||; 157417f01e99SJung-uk Kim $verstr =~ s|\R$||; 157517f01e99SJung-uk Kim my ($ma, $mi, @rest) = split m|\.|, $verstr; 157617f01e99SJung-uk Kim my $ver = $ma*100 + $mi; 157717f01e99SJung-uk Kim if ($sysstr eq 'OpenBSD' && $ver >= $maxver) { 157817f01e99SJung-uk Kim disable('too-new-kernel', 'devcryptoeng'); 157917f01e99SJung-uk Kim } 158017f01e99SJung-uk Kim } 158117f01e99SJung-uk Kim} 1582e71b7053SJung-uk Kim 1583610a21fdSJung-uk Kim# Get the extra flags used when building shared libraries and modules. We 1584610a21fdSJung-uk Kim# do this late because some of them depend on %disabled. 1585e71b7053SJung-uk Kim 1586610a21fdSJung-uk Kim# Make the flags to build DSOs the same as for shared libraries unless they 1587610a21fdSJung-uk Kim# are already defined 1588610a21fdSJung-uk Kim$target{module_cflags} = $target{shared_cflag} unless defined $target{module_cflags}; 1589610a21fdSJung-uk Kim$target{module_cxxflags} = $target{shared_cxxflag} unless defined $target{module_cxxflags}; 1590610a21fdSJung-uk Kim$target{module_ldflags} = $target{shared_ldflag} unless defined $target{module_ldflags}; 1591610a21fdSJung-uk Kim{ 1592610a21fdSJung-uk Kim my $shared_info_pl = 1593610a21fdSJung-uk Kim catfile(dirname($0), "Configurations", "shared-info.pl"); 1594610a21fdSJung-uk Kim my %shared_info = read_eval_file($shared_info_pl); 1595610a21fdSJung-uk Kim push @{$target{_conf_fname_int}}, $shared_info_pl; 1596610a21fdSJung-uk Kim my $si = $target{shared_target}; 1597610a21fdSJung-uk Kim while (ref $si ne "HASH") { 1598610a21fdSJung-uk Kim last if ! defined $si; 1599610a21fdSJung-uk Kim if (ref $si eq "CODE") { 1600610a21fdSJung-uk Kim $si = $si->(); 1601e71b7053SJung-uk Kim } else { 1602610a21fdSJung-uk Kim $si = $shared_info{$si}; 1603e71b7053SJung-uk Kim } 1604e71b7053SJung-uk Kim } 1605e71b7053SJung-uk Kim 1606610a21fdSJung-uk Kim # Some of the 'shared_target' values don't have any entries in 1607610a21fdSJung-uk Kim # %shared_info. That's perfectly fine, AS LONG AS the build file 1608610a21fdSJung-uk Kim # template knows how to handle this. That is currently the case for 1609610a21fdSJung-uk Kim # Windows and VMS. 1610610a21fdSJung-uk Kim if (defined $si) { 1611610a21fdSJung-uk Kim # Just as above, copy certain shared_* attributes to the corresponding 1612610a21fdSJung-uk Kim # module_ attribute unless the latter is already defined 1613610a21fdSJung-uk Kim $si->{module_cflags} = $si->{shared_cflag} unless defined $si->{module_cflags}; 1614610a21fdSJung-uk Kim $si->{module_cxxflags} = $si->{shared_cxxflag} unless defined $si->{module_cxxflags}; 1615610a21fdSJung-uk Kim $si->{module_ldflags} = $si->{shared_ldflag} unless defined $si->{module_ldflags}; 1616610a21fdSJung-uk Kim foreach (sort keys %$si) { 1617610a21fdSJung-uk Kim $target{$_} = defined $target{$_} 1618610a21fdSJung-uk Kim ? add($si->{$_})->($target{$_}) 1619610a21fdSJung-uk Kim : $si->{$_}; 1620610a21fdSJung-uk Kim } 1621610a21fdSJung-uk Kim } 1622610a21fdSJung-uk Kim} 1623610a21fdSJung-uk Kim 1624610a21fdSJung-uk Kim# ALL MODIFICATIONS TO %disabled, %config and %target MUST BE DONE FROM HERE ON 1625e71b7053SJung-uk Kim 162617f01e99SJung-uk Kimmy %disabled_info = (); # For configdata.pm 162717f01e99SJung-uk Kimforeach my $what (sort keys %disabled) { 162817f01e99SJung-uk Kim $config{options} .= " no-$what"; 162917f01e99SJung-uk Kim 163017f01e99SJung-uk Kim if (!grep { $what eq $_ } ( 'buildtest-c++', 'threads', 'shared', 'pic', 163117f01e99SJung-uk Kim 'dynamic-engine', 'makedepend', 163217f01e99SJung-uk Kim 'zlib-dynamic', 'zlib', 'sse2' )) { 163317f01e99SJung-uk Kim (my $WHAT = uc $what) =~ s|-|_|g; 163417f01e99SJung-uk Kim 163517f01e99SJung-uk Kim # Fix up C macro end names 163617f01e99SJung-uk Kim $WHAT = "RMD160" if $what eq "ripemd"; 163717f01e99SJung-uk Kim 163817f01e99SJung-uk Kim # fix-up crypto/directory name(s) 163917f01e99SJung-uk Kim $what = "ripemd" if $what eq "rmd160"; 164017f01e99SJung-uk Kim $what = "whrlpool" if $what eq "whirlpool"; 164117f01e99SJung-uk Kim 164217f01e99SJung-uk Kim my $macro = $disabled_info{$what}->{macro} = "OPENSSL_NO_$WHAT"; 164317f01e99SJung-uk Kim 164417f01e99SJung-uk Kim if ((grep { $what eq $_ } @{$config{sdirs}}) 164517f01e99SJung-uk Kim && $what ne 'async' && $what ne 'err' && $what ne 'dso') { 164617f01e99SJung-uk Kim @{$config{sdirs}} = grep { $what ne $_} @{$config{sdirs}}; 164717f01e99SJung-uk Kim $disabled_info{$what}->{skipped} = [ catdir('crypto', $what) ]; 164817f01e99SJung-uk Kim 164917f01e99SJung-uk Kim if ($what ne 'engine') { 165017f01e99SJung-uk Kim push @{$config{openssl_algorithm_defines}}, $macro; 165117f01e99SJung-uk Kim } else { 165217f01e99SJung-uk Kim @{$config{dirs}} = grep !/^engines$/, @{$config{dirs}}; 165317f01e99SJung-uk Kim push @{$disabled_info{engine}->{skipped}}, catdir('engines'); 165417f01e99SJung-uk Kim push @{$config{openssl_other_defines}}, $macro; 165517f01e99SJung-uk Kim } 165617f01e99SJung-uk Kim } else { 165717f01e99SJung-uk Kim push @{$config{openssl_other_defines}}, $macro; 165817f01e99SJung-uk Kim } 165917f01e99SJung-uk Kim 166017f01e99SJung-uk Kim } 166117f01e99SJung-uk Kim} 166217f01e99SJung-uk Kim 166317f01e99SJung-uk Kimif ($disabled{"dynamic-engine"}) { 166417f01e99SJung-uk Kim push @{$config{openssl_other_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE"; 166517f01e99SJung-uk Kim} else { 166617f01e99SJung-uk Kim push @{$config{openssl_other_defines}}, "OPENSSL_NO_STATIC_ENGINE"; 166717f01e99SJung-uk Kim} 166817f01e99SJung-uk Kim 1669e71b7053SJung-uk Kim# If we use the unified build, collect information from build.info files 1670e71b7053SJung-uk Kimmy %unified_info = (); 1671e71b7053SJung-uk Kim 1672e71b7053SJung-uk Kimmy $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO}); 1673e71b7053SJung-uk Kimif ($builder eq "unified") { 1674e71b7053SJung-uk Kim use with_fallback qw(Text::Template); 1675e71b7053SJung-uk Kim 1676e71b7053SJung-uk Kim sub cleandir { 1677e71b7053SJung-uk Kim my $base = shift; 1678e71b7053SJung-uk Kim my $dir = shift; 1679e71b7053SJung-uk Kim my $relativeto = shift || "."; 1680e71b7053SJung-uk Kim 1681e71b7053SJung-uk Kim $dir = catdir($base,$dir) unless isabsolute($dir); 1682e71b7053SJung-uk Kim 1683e71b7053SJung-uk Kim # Make sure the directories we're building in exists 1684e71b7053SJung-uk Kim mkpath($dir); 1685e71b7053SJung-uk Kim 1686e71b7053SJung-uk Kim my $res = abs2rel(absolutedir($dir), rel2abs($relativeto)); 1687e71b7053SJung-uk Kim #print STDERR "DEBUG[cleandir]: $dir , $base => $res\n"; 1688e71b7053SJung-uk Kim return $res; 1689e71b7053SJung-uk Kim } 1690e71b7053SJung-uk Kim 1691e71b7053SJung-uk Kim sub cleanfile { 1692e71b7053SJung-uk Kim my $base = shift; 1693e71b7053SJung-uk Kim my $file = shift; 1694e71b7053SJung-uk Kim my $relativeto = shift || "."; 1695e71b7053SJung-uk Kim 1696e71b7053SJung-uk Kim $file = catfile($base,$file) unless isabsolute($file); 1697e71b7053SJung-uk Kim 1698e71b7053SJung-uk Kim my $d = dirname($file); 1699e71b7053SJung-uk Kim my $f = basename($file); 1700e71b7053SJung-uk Kim 1701e71b7053SJung-uk Kim # Make sure the directories we're building in exists 1702e71b7053SJung-uk Kim mkpath($d); 1703e71b7053SJung-uk Kim 1704e71b7053SJung-uk Kim my $res = abs2rel(catfile(absolutedir($d), $f), rel2abs($relativeto)); 1705e71b7053SJung-uk Kim #print STDERR "DEBUG[cleanfile]: $d , $f => $res\n"; 1706e71b7053SJung-uk Kim return $res; 1707e71b7053SJung-uk Kim } 1708e71b7053SJung-uk Kim 1709e71b7053SJung-uk Kim # Store the name of the template file we will build the build file from 1710e71b7053SJung-uk Kim # in %config. This may be useful for the build file itself. 1711e71b7053SJung-uk Kim my @build_file_template_names = 1712e71b7053SJung-uk Kim ( $builder_platform."-".$target{build_file}.".tmpl", 1713e71b7053SJung-uk Kim $target{build_file}.".tmpl" ); 1714e71b7053SJung-uk Kim my @build_file_templates = (); 1715e71b7053SJung-uk Kim 1716e71b7053SJung-uk Kim # First, look in the user provided directory, if given 1717e71b7053SJung-uk Kim if (defined env($local_config_envname)) { 1718e71b7053SJung-uk Kim @build_file_templates = 1719e71b7053SJung-uk Kim map { 1720e71b7053SJung-uk Kim if ($^O eq 'VMS') { 1721e71b7053SJung-uk Kim # VMS environment variables are logical names, 1722e71b7053SJung-uk Kim # which can be used as is 1723e71b7053SJung-uk Kim $local_config_envname . ':' . $_; 1724e71b7053SJung-uk Kim } else { 1725e71b7053SJung-uk Kim catfile(env($local_config_envname), $_); 1726e71b7053SJung-uk Kim } 1727e71b7053SJung-uk Kim } 1728e71b7053SJung-uk Kim @build_file_template_names; 1729e71b7053SJung-uk Kim } 1730e71b7053SJung-uk Kim # Then, look in our standard directory 1731e71b7053SJung-uk Kim push @build_file_templates, 1732e71b7053SJung-uk Kim ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir) } 1733e71b7053SJung-uk Kim @build_file_template_names ); 1734e71b7053SJung-uk Kim 1735e71b7053SJung-uk Kim my $build_file_template; 1736e71b7053SJung-uk Kim for $_ (@build_file_templates) { 1737e71b7053SJung-uk Kim $build_file_template = $_; 1738e71b7053SJung-uk Kim last if -f $build_file_template; 1739e71b7053SJung-uk Kim 1740e71b7053SJung-uk Kim $build_file_template = undef; 1741e71b7053SJung-uk Kim } 1742e71b7053SJung-uk Kim if (!defined $build_file_template) { 1743e71b7053SJung-uk Kim die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n"; 1744e71b7053SJung-uk Kim } 1745e71b7053SJung-uk Kim $config{build_file_templates} 1746e71b7053SJung-uk Kim = [ cleanfile($srcdir, catfile("Configurations", "common0.tmpl"), 1747e71b7053SJung-uk Kim $blddir), 1748e71b7053SJung-uk Kim $build_file_template, 1749e71b7053SJung-uk Kim cleanfile($srcdir, catfile("Configurations", "common.tmpl"), 1750e71b7053SJung-uk Kim $blddir) ]; 1751e71b7053SJung-uk Kim 1752e71b7053SJung-uk Kim my @build_infos = ( [ ".", "build.info" ] ); 1753e71b7053SJung-uk Kim foreach (@{$config{dirs}}) { 1754e71b7053SJung-uk Kim push @build_infos, [ $_, "build.info" ] 1755e71b7053SJung-uk Kim if (-f catfile($srcdir, $_, "build.info")); 1756e71b7053SJung-uk Kim } 1757e71b7053SJung-uk Kim foreach (@{$config{sdirs}}) { 1758e71b7053SJung-uk Kim push @build_infos, [ catdir("crypto", $_), "build.info" ] 1759e71b7053SJung-uk Kim if (-f catfile($srcdir, "crypto", $_, "build.info")); 1760e71b7053SJung-uk Kim } 1761e71b7053SJung-uk Kim foreach (@{$config{engdirs}}) { 1762e71b7053SJung-uk Kim push @build_infos, [ catdir("engines", $_), "build.info" ] 1763e71b7053SJung-uk Kim if (-f catfile($srcdir, "engines", $_, "build.info")); 1764e71b7053SJung-uk Kim } 1765e71b7053SJung-uk Kim foreach (@{$config{tdirs}}) { 1766e71b7053SJung-uk Kim push @build_infos, [ catdir("test", $_), "build.info" ] 1767e71b7053SJung-uk Kim if (-f catfile($srcdir, "test", $_, "build.info")); 1768e71b7053SJung-uk Kim } 1769e71b7053SJung-uk Kim 1770e71b7053SJung-uk Kim $config{build_infos} = [ ]; 1771e71b7053SJung-uk Kim 1772e71b7053SJung-uk Kim my %ordinals = (); 1773e71b7053SJung-uk Kim foreach (@build_infos) { 1774e71b7053SJung-uk Kim my $sourced = catdir($srcdir, $_->[0]); 1775e71b7053SJung-uk Kim my $buildd = catdir($blddir, $_->[0]); 1776e71b7053SJung-uk Kim 1777e71b7053SJung-uk Kim mkpath($buildd); 1778e71b7053SJung-uk Kim 1779e71b7053SJung-uk Kim my $f = $_->[1]; 1780e71b7053SJung-uk Kim # The basic things we're trying to build 1781e71b7053SJung-uk Kim my @programs = (); 1782e71b7053SJung-uk Kim my @programs_install = (); 1783e71b7053SJung-uk Kim my @libraries = (); 1784e71b7053SJung-uk Kim my @libraries_install = (); 1785e71b7053SJung-uk Kim my @engines = (); 1786e71b7053SJung-uk Kim my @engines_install = (); 1787e71b7053SJung-uk Kim my @scripts = (); 1788e71b7053SJung-uk Kim my @scripts_install = (); 1789e71b7053SJung-uk Kim my @extra = (); 1790e71b7053SJung-uk Kim my @overrides = (); 1791e71b7053SJung-uk Kim my @intermediates = (); 1792e71b7053SJung-uk Kim my @rawlines = (); 1793e71b7053SJung-uk Kim 1794e71b7053SJung-uk Kim my %sources = (); 1795e71b7053SJung-uk Kim my %shared_sources = (); 1796e71b7053SJung-uk Kim my %includes = (); 1797e71b7053SJung-uk Kim my %depends = (); 1798e71b7053SJung-uk Kim my %renames = (); 1799e71b7053SJung-uk Kim my %sharednames = (); 1800e71b7053SJung-uk Kim my %generate = (); 1801e71b7053SJung-uk Kim 1802e71b7053SJung-uk Kim # We want to detect configdata.pm in the source tree, so we 1803e71b7053SJung-uk Kim # don't use it if the build tree is different. 1804e71b7053SJung-uk Kim my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir); 1805e71b7053SJung-uk Kim 1806e71b7053SJung-uk Kim push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f); 1807e71b7053SJung-uk Kim my $template = 1808e71b7053SJung-uk Kim Text::Template->new(TYPE => 'FILE', 1809e71b7053SJung-uk Kim SOURCE => catfile($sourced, $f), 1810e71b7053SJung-uk Kim PREPEND => qq{use lib "$FindBin::Bin/util/perl";}); 1811e71b7053SJung-uk Kim die "Something went wrong with $sourced/$f: $!\n" unless $template; 1812e71b7053SJung-uk Kim my @text = 1813e71b7053SJung-uk Kim split /^/m, 1814e71b7053SJung-uk Kim $template->fill_in(HASH => { config => \%config, 1815e71b7053SJung-uk Kim target => \%target, 1816e71b7053SJung-uk Kim disabled => \%disabled, 1817e71b7053SJung-uk Kim withargs => \%withargs, 1818e71b7053SJung-uk Kim builddir => abs2rel($buildd, $blddir), 1819e71b7053SJung-uk Kim sourcedir => abs2rel($sourced, $blddir), 1820e71b7053SJung-uk Kim buildtop => abs2rel($blddir, $blddir), 1821e71b7053SJung-uk Kim sourcetop => abs2rel($srcdir, $blddir) }, 1822e71b7053SJung-uk Kim DELIMITERS => [ "{-", "-}" ]); 1823e71b7053SJung-uk Kim 1824e71b7053SJung-uk Kim # The top item of this stack has the following values 1825e71b7053SJung-uk Kim # -2 positive already run and we found ELSE (following ELSIF should fail) 1826e71b7053SJung-uk Kim # -1 positive already run (skip until ENDIF) 1827e71b7053SJung-uk Kim # 0 negatives so far (if we're at a condition, check it) 1828e71b7053SJung-uk Kim # 1 last was positive (don't skip lines until next ELSE, ELSIF or ENDIF) 1829e71b7053SJung-uk Kim # 2 positive ELSE (following ELSIF should fail) 1830e71b7053SJung-uk Kim my @skip = (); 1831e71b7053SJung-uk Kim collect_information( 1832e71b7053SJung-uk Kim collect_from_array([ @text ], 1833e71b7053SJung-uk Kim qr/\\$/ => sub { my $l1 = shift; my $l2 = shift; 1834e71b7053SJung-uk Kim $l1 =~ s/\\$//; $l1.$l2 }), 1835e71b7053SJung-uk Kim # Info we're looking for 1836e71b7053SJung-uk Kim qr/^\s*IF\[((?:\\.|[^\\\]])*)\]\s*$/ 1837e71b7053SJung-uk Kim => sub { 1838e71b7053SJung-uk Kim if (! @skip || $skip[$#skip] > 0) { 1839e71b7053SJung-uk Kim push @skip, !! $1; 1840e71b7053SJung-uk Kim } else { 1841e71b7053SJung-uk Kim push @skip, -1; 1842e71b7053SJung-uk Kim } 1843e71b7053SJung-uk Kim }, 1844e71b7053SJung-uk Kim qr/^\s*ELSIF\[((?:\\.|[^\\\]])*)\]\s*$/ 1845e71b7053SJung-uk Kim => sub { die "ELSIF out of scope" if ! @skip; 1846e71b7053SJung-uk Kim die "ELSIF following ELSE" if abs($skip[$#skip]) == 2; 1847e71b7053SJung-uk Kim $skip[$#skip] = -1 if $skip[$#skip] != 0; 1848e71b7053SJung-uk Kim $skip[$#skip] = !! $1 1849e71b7053SJung-uk Kim if $skip[$#skip] == 0; }, 1850e71b7053SJung-uk Kim qr/^\s*ELSE\s*$/ 1851e71b7053SJung-uk Kim => sub { die "ELSE out of scope" if ! @skip; 1852e71b7053SJung-uk Kim $skip[$#skip] = -2 if $skip[$#skip] != 0; 1853e71b7053SJung-uk Kim $skip[$#skip] = 2 if $skip[$#skip] == 0; }, 1854e71b7053SJung-uk Kim qr/^\s*ENDIF\s*$/ 1855e71b7053SJung-uk Kim => sub { die "ENDIF out of scope" if ! @skip; 1856e71b7053SJung-uk Kim pop @skip; }, 1857e71b7053SJung-uk Kim qr/^\s*PROGRAMS(_NO_INST)?\s*=\s*(.*)\s*$/ 1858e71b7053SJung-uk Kim => sub { 1859e71b7053SJung-uk Kim if (!@skip || $skip[$#skip] > 0) { 1860e71b7053SJung-uk Kim my $install = $1; 1861e71b7053SJung-uk Kim my @x = tokenize($2); 1862e71b7053SJung-uk Kim push @programs, @x; 1863e71b7053SJung-uk Kim push @programs_install, @x unless $install; 1864e71b7053SJung-uk Kim } 1865e71b7053SJung-uk Kim }, 1866e71b7053SJung-uk Kim qr/^\s*LIBS(_NO_INST)?\s*=\s*(.*)\s*$/ 1867e71b7053SJung-uk Kim => sub { 1868e71b7053SJung-uk Kim if (!@skip || $skip[$#skip] > 0) { 1869e71b7053SJung-uk Kim my $install = $1; 1870e71b7053SJung-uk Kim my @x = tokenize($2); 1871e71b7053SJung-uk Kim push @libraries, @x; 1872e71b7053SJung-uk Kim push @libraries_install, @x unless $install; 1873e71b7053SJung-uk Kim } 1874e71b7053SJung-uk Kim }, 1875e71b7053SJung-uk Kim qr/^\s*ENGINES(_NO_INST)?\s*=\s*(.*)\s*$/ 1876e71b7053SJung-uk Kim => sub { 1877e71b7053SJung-uk Kim if (!@skip || $skip[$#skip] > 0) { 1878e71b7053SJung-uk Kim my $install = $1; 1879e71b7053SJung-uk Kim my @x = tokenize($2); 1880e71b7053SJung-uk Kim push @engines, @x; 1881e71b7053SJung-uk Kim push @engines_install, @x unless $install; 1882e71b7053SJung-uk Kim } 1883e71b7053SJung-uk Kim }, 1884e71b7053SJung-uk Kim qr/^\s*SCRIPTS(_NO_INST)?\s*=\s*(.*)\s*$/ 1885e71b7053SJung-uk Kim => sub { 1886e71b7053SJung-uk Kim if (!@skip || $skip[$#skip] > 0) { 1887e71b7053SJung-uk Kim my $install = $1; 1888e71b7053SJung-uk Kim my @x = tokenize($2); 1889e71b7053SJung-uk Kim push @scripts, @x; 1890e71b7053SJung-uk Kim push @scripts_install, @x unless $install; 1891e71b7053SJung-uk Kim } 1892e71b7053SJung-uk Kim }, 1893e71b7053SJung-uk Kim qr/^\s*EXTRA\s*=\s*(.*)\s*$/ 1894e71b7053SJung-uk Kim => sub { push @extra, tokenize($1) 1895e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1896e71b7053SJung-uk Kim qr/^\s*OVERRIDES\s*=\s*(.*)\s*$/ 1897e71b7053SJung-uk Kim => sub { push @overrides, tokenize($1) 1898e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1899e71b7053SJung-uk Kim 1900e71b7053SJung-uk Kim qr/^\s*ORDINALS\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/, 1901e71b7053SJung-uk Kim => sub { push @{$ordinals{$1}}, tokenize($2) 1902e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1903e71b7053SJung-uk Kim qr/^\s*SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ 1904e71b7053SJung-uk Kim => sub { push @{$sources{$1}}, tokenize($2) 1905e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1906e71b7053SJung-uk Kim qr/^\s*SHARED_SOURCE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ 1907e71b7053SJung-uk Kim => sub { push @{$shared_sources{$1}}, tokenize($2) 1908e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1909e71b7053SJung-uk Kim qr/^\s*INCLUDE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ 1910e71b7053SJung-uk Kim => sub { push @{$includes{$1}}, tokenize($2) 1911e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1912e71b7053SJung-uk Kim qr/^\s*DEPEND\[((?:\\.|[^\\\]])*)\]\s*=\s*(.*)\s*$/ 1913e71b7053SJung-uk Kim => sub { push @{$depends{$1}}, tokenize($2) 1914e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1915e71b7053SJung-uk Kim qr/^\s*GENERATE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ 1916e71b7053SJung-uk Kim => sub { push @{$generate{$1}}, $2 1917e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1918e71b7053SJung-uk Kim qr/^\s*RENAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ 1919e71b7053SJung-uk Kim => sub { push @{$renames{$1}}, tokenize($2) 1920e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1921e71b7053SJung-uk Kim qr/^\s*SHARED_NAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ 1922e71b7053SJung-uk Kim => sub { push @{$sharednames{$1}}, tokenize($2) 1923e71b7053SJung-uk Kim if !@skip || $skip[$#skip] > 0 }, 1924e71b7053SJung-uk Kim qr/^\s*BEGINRAW\[((?:\\.|[^\\\]])+)\]\s*$/ 1925e71b7053SJung-uk Kim => sub { 1926e71b7053SJung-uk Kim my $lineiterator = shift; 1927e71b7053SJung-uk Kim my $target_kind = $1; 1928e71b7053SJung-uk Kim while (defined $lineiterator->()) { 1929e71b7053SJung-uk Kim s|\R$||; 1930e71b7053SJung-uk Kim if (/^\s*ENDRAW\[((?:\\.|[^\\\]])+)\]\s*$/) { 1931e71b7053SJung-uk Kim die "ENDRAW doesn't match BEGINRAW" 1932e71b7053SJung-uk Kim if $1 ne $target_kind; 1933e71b7053SJung-uk Kim last; 1934e71b7053SJung-uk Kim } 1935e71b7053SJung-uk Kim next if @skip && $skip[$#skip] <= 0; 1936e71b7053SJung-uk Kim push @rawlines, $_ 1937e71b7053SJung-uk Kim if ($target_kind eq $target{build_file} 1938e71b7053SJung-uk Kim || $target_kind eq $target{build_file}."(".$builder_platform.")"); 1939e71b7053SJung-uk Kim } 1940e71b7053SJung-uk Kim }, 1941e71b7053SJung-uk Kim qr/^\s*(?:#.*)?$/ => sub { }, 1942e71b7053SJung-uk Kim "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" }, 1943e71b7053SJung-uk Kim "BEFORE" => sub { 1944e71b7053SJung-uk Kim if ($buildinfo_debug) { 1945e71b7053SJung-uk Kim print STDERR "DEBUG: Parsing ",join(" ", @_),"\n"; 1946e71b7053SJung-uk Kim print STDERR "DEBUG: ... before parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n"; 1947e71b7053SJung-uk Kim } 1948e71b7053SJung-uk Kim }, 1949e71b7053SJung-uk Kim "AFTER" => sub { 1950e71b7053SJung-uk Kim if ($buildinfo_debug) { 1951e71b7053SJung-uk Kim print STDERR "DEBUG: .... after parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n"; 1952e71b7053SJung-uk Kim } 1953e71b7053SJung-uk Kim }, 1954e71b7053SJung-uk Kim ); 1955e71b7053SJung-uk Kim die "runaway IF?" if (@skip); 1956e71b7053SJung-uk Kim 1957e71b7053SJung-uk Kim foreach (keys %renames) { 1958e71b7053SJung-uk Kim die "$_ renamed to more than one thing: " 1959e71b7053SJung-uk Kim ,join(" ", @{$renames{$_}}),"\n" 1960e71b7053SJung-uk Kim if scalar @{$renames{$_}} > 1; 1961e71b7053SJung-uk Kim my $dest = cleanfile($buildd, $_, $blddir); 1962e71b7053SJung-uk Kim my $to = cleanfile($buildd, $renames{$_}->[0], $blddir); 1963e71b7053SJung-uk Kim die "$dest renamed to more than one thing: " 1964e71b7053SJung-uk Kim ,$unified_info{rename}->{$dest}, $to 1965e71b7053SJung-uk Kim unless !defined($unified_info{rename}->{$dest}) 1966e71b7053SJung-uk Kim or $unified_info{rename}->{$dest} eq $to; 1967e71b7053SJung-uk Kim $unified_info{rename}->{$dest} = $to; 1968e71b7053SJung-uk Kim } 1969e71b7053SJung-uk Kim 1970e71b7053SJung-uk Kim foreach (@programs) { 1971e71b7053SJung-uk Kim my $program = cleanfile($buildd, $_, $blddir); 1972e71b7053SJung-uk Kim if ($unified_info{rename}->{$program}) { 1973e71b7053SJung-uk Kim $program = $unified_info{rename}->{$program}; 1974e71b7053SJung-uk Kim } 1975e71b7053SJung-uk Kim $unified_info{programs}->{$program} = 1; 1976e71b7053SJung-uk Kim } 1977e71b7053SJung-uk Kim 1978e71b7053SJung-uk Kim foreach (@programs_install) { 1979e71b7053SJung-uk Kim my $program = cleanfile($buildd, $_, $blddir); 1980e71b7053SJung-uk Kim if ($unified_info{rename}->{$program}) { 1981e71b7053SJung-uk Kim $program = $unified_info{rename}->{$program}; 1982e71b7053SJung-uk Kim } 1983e71b7053SJung-uk Kim $unified_info{install}->{programs}->{$program} = 1; 1984e71b7053SJung-uk Kim } 1985e71b7053SJung-uk Kim 1986e71b7053SJung-uk Kim foreach (@libraries) { 1987e71b7053SJung-uk Kim my $library = cleanfile($buildd, $_, $blddir); 1988e71b7053SJung-uk Kim if ($unified_info{rename}->{$library}) { 1989e71b7053SJung-uk Kim $library = $unified_info{rename}->{$library}; 1990e71b7053SJung-uk Kim } 1991e71b7053SJung-uk Kim $unified_info{libraries}->{$library} = 1; 1992e71b7053SJung-uk Kim } 1993e71b7053SJung-uk Kim 1994e71b7053SJung-uk Kim foreach (@libraries_install) { 1995e71b7053SJung-uk Kim my $library = cleanfile($buildd, $_, $blddir); 1996e71b7053SJung-uk Kim if ($unified_info{rename}->{$library}) { 1997e71b7053SJung-uk Kim $library = $unified_info{rename}->{$library}; 1998e71b7053SJung-uk Kim } 1999e71b7053SJung-uk Kim $unified_info{install}->{libraries}->{$library} = 1; 2000e71b7053SJung-uk Kim } 2001e71b7053SJung-uk Kim 2002e71b7053SJung-uk Kim die <<"EOF" if scalar @engines and !$config{dynamic_engines}; 2003e71b7053SJung-uk KimENGINES can only be used if configured with 'dynamic-engine'. 2004e71b7053SJung-uk KimThis is usually a fault in a build.info file. 2005e71b7053SJung-uk KimEOF 2006e71b7053SJung-uk Kim foreach (@engines) { 2007e71b7053SJung-uk Kim my $library = cleanfile($buildd, $_, $blddir); 2008e71b7053SJung-uk Kim if ($unified_info{rename}->{$library}) { 2009e71b7053SJung-uk Kim $library = $unified_info{rename}->{$library}; 2010e71b7053SJung-uk Kim } 2011e71b7053SJung-uk Kim $unified_info{engines}->{$library} = 1; 2012e71b7053SJung-uk Kim } 2013e71b7053SJung-uk Kim 2014e71b7053SJung-uk Kim foreach (@engines_install) { 2015e71b7053SJung-uk Kim my $library = cleanfile($buildd, $_, $blddir); 2016e71b7053SJung-uk Kim if ($unified_info{rename}->{$library}) { 2017e71b7053SJung-uk Kim $library = $unified_info{rename}->{$library}; 2018e71b7053SJung-uk Kim } 2019e71b7053SJung-uk Kim $unified_info{install}->{engines}->{$library} = 1; 2020e71b7053SJung-uk Kim } 2021e71b7053SJung-uk Kim 2022e71b7053SJung-uk Kim foreach (@scripts) { 2023e71b7053SJung-uk Kim my $script = cleanfile($buildd, $_, $blddir); 2024e71b7053SJung-uk Kim if ($unified_info{rename}->{$script}) { 2025e71b7053SJung-uk Kim $script = $unified_info{rename}->{$script}; 2026e71b7053SJung-uk Kim } 2027e71b7053SJung-uk Kim $unified_info{scripts}->{$script} = 1; 2028e71b7053SJung-uk Kim } 2029e71b7053SJung-uk Kim 2030e71b7053SJung-uk Kim foreach (@scripts_install) { 2031e71b7053SJung-uk Kim my $script = cleanfile($buildd, $_, $blddir); 2032e71b7053SJung-uk Kim if ($unified_info{rename}->{$script}) { 2033e71b7053SJung-uk Kim $script = $unified_info{rename}->{$script}; 2034e71b7053SJung-uk Kim } 2035e71b7053SJung-uk Kim $unified_info{install}->{scripts}->{$script} = 1; 2036e71b7053SJung-uk Kim } 2037e71b7053SJung-uk Kim 2038e71b7053SJung-uk Kim foreach (@extra) { 2039e71b7053SJung-uk Kim my $extra = cleanfile($buildd, $_, $blddir); 2040e71b7053SJung-uk Kim $unified_info{extra}->{$extra} = 1; 2041e71b7053SJung-uk Kim } 2042e71b7053SJung-uk Kim 2043e71b7053SJung-uk Kim foreach (@overrides) { 2044e71b7053SJung-uk Kim my $override = cleanfile($buildd, $_, $blddir); 2045e71b7053SJung-uk Kim $unified_info{overrides}->{$override} = 1; 2046e71b7053SJung-uk Kim } 2047e71b7053SJung-uk Kim 2048e71b7053SJung-uk Kim push @{$unified_info{rawlines}}, @rawlines; 2049e71b7053SJung-uk Kim 2050e71b7053SJung-uk Kim unless ($disabled{shared}) { 2051e71b7053SJung-uk Kim # Check sharednames. 2052e71b7053SJung-uk Kim foreach (keys %sharednames) { 2053e71b7053SJung-uk Kim my $dest = cleanfile($buildd, $_, $blddir); 2054e71b7053SJung-uk Kim if ($unified_info{rename}->{$dest}) { 2055e71b7053SJung-uk Kim $dest = $unified_info{rename}->{$dest}; 2056e71b7053SJung-uk Kim } 2057e71b7053SJung-uk Kim die "shared_name for $dest with multiple values: " 2058e71b7053SJung-uk Kim ,join(" ", @{$sharednames{$_}}),"\n" 2059e71b7053SJung-uk Kim if scalar @{$sharednames{$_}} > 1; 2060e71b7053SJung-uk Kim my $to = cleanfile($buildd, $sharednames{$_}->[0], $blddir); 2061e71b7053SJung-uk Kim die "shared_name found for a library $dest that isn't defined\n" 2062e71b7053SJung-uk Kim unless $unified_info{libraries}->{$dest}; 2063e71b7053SJung-uk Kim die "shared_name for $dest with multiple values: " 2064e71b7053SJung-uk Kim ,$unified_info{sharednames}->{$dest}, ", ", $to 2065e71b7053SJung-uk Kim unless !defined($unified_info{sharednames}->{$dest}) 2066e71b7053SJung-uk Kim or $unified_info{sharednames}->{$dest} eq $to; 2067e71b7053SJung-uk Kim $unified_info{sharednames}->{$dest} = $to; 2068e71b7053SJung-uk Kim } 2069e71b7053SJung-uk Kim 2070e71b7053SJung-uk Kim # Additionally, we set up sharednames for libraries that don't 2071e71b7053SJung-uk Kim # have any, as themselves. Only for libraries that aren't 2072e71b7053SJung-uk Kim # explicitly static. 2073e71b7053SJung-uk Kim foreach (grep !/\.a$/, keys %{$unified_info{libraries}}) { 2074e71b7053SJung-uk Kim if (!defined $unified_info{sharednames}->{$_}) { 2075e71b7053SJung-uk Kim $unified_info{sharednames}->{$_} = $_ 2076e71b7053SJung-uk Kim } 2077e71b7053SJung-uk Kim } 2078e71b7053SJung-uk Kim 2079e71b7053SJung-uk Kim # Check that we haven't defined any library as both shared and 2080e71b7053SJung-uk Kim # explicitly static. That is forbidden. 2081e71b7053SJung-uk Kim my @doubles = (); 2082e71b7053SJung-uk Kim foreach (grep /\.a$/, keys %{$unified_info{libraries}}) { 2083e71b7053SJung-uk Kim (my $l = $_) =~ s/\.a$//; 2084e71b7053SJung-uk Kim push @doubles, $l if defined $unified_info{sharednames}->{$l}; 2085e71b7053SJung-uk Kim } 2086e71b7053SJung-uk Kim die "these libraries are both explicitly static and shared:\n ", 2087e71b7053SJung-uk Kim join(" ", @doubles), "\n" 2088e71b7053SJung-uk Kim if @doubles; 2089e71b7053SJung-uk Kim } 2090e71b7053SJung-uk Kim 2091e71b7053SJung-uk Kim foreach (keys %sources) { 2092e71b7053SJung-uk Kim my $dest = $_; 2093e71b7053SJung-uk Kim my $ddest = cleanfile($buildd, $_, $blddir); 2094e71b7053SJung-uk Kim if ($unified_info{rename}->{$ddest}) { 2095e71b7053SJung-uk Kim $ddest = $unified_info{rename}->{$ddest}; 2096e71b7053SJung-uk Kim } 2097e71b7053SJung-uk Kim foreach (@{$sources{$dest}}) { 2098e71b7053SJung-uk Kim my $s = cleanfile($sourced, $_, $blddir); 2099e71b7053SJung-uk Kim 2100e71b7053SJung-uk Kim # If it isn't in the source tree, we assume it's generated 2101e71b7053SJung-uk Kim # in the build tree 2102e71b7053SJung-uk Kim if ($s eq $src_configdata || ! -f $s || $generate{$_}) { 2103e71b7053SJung-uk Kim $s = cleanfile($buildd, $_, $blddir); 2104e71b7053SJung-uk Kim } 2105e71b7053SJung-uk Kim # We recognise C++, C and asm files 2106e71b7053SJung-uk Kim if ($s =~ /\.(cc|cpp|c|s|S)$/) { 2107e71b7053SJung-uk Kim my $o = $_; 2108e71b7053SJung-uk Kim $o =~ s/\.[csS]$/.o/; # C and assembler 2109e71b7053SJung-uk Kim $o =~ s/\.(cc|cpp)$/_cc.o/; # C++ 2110e71b7053SJung-uk Kim $o = cleanfile($buildd, $o, $blddir); 2111e71b7053SJung-uk Kim $unified_info{sources}->{$ddest}->{$o} = 1; 2112e71b7053SJung-uk Kim $unified_info{sources}->{$o}->{$s} = 1; 2113e71b7053SJung-uk Kim } elsif ($s =~ /\.rc$/) { 2114e71b7053SJung-uk Kim # We also recognise resource files 2115e71b7053SJung-uk Kim my $o = $_; 2116e71b7053SJung-uk Kim $o =~ s/\.rc$/.res/; # Resource configuration 2117e71b7053SJung-uk Kim my $o = cleanfile($buildd, $o, $blddir); 2118e71b7053SJung-uk Kim $unified_info{sources}->{$ddest}->{$o} = 1; 2119e71b7053SJung-uk Kim $unified_info{sources}->{$o}->{$s} = 1; 2120e71b7053SJung-uk Kim } else { 2121e71b7053SJung-uk Kim $unified_info{sources}->{$ddest}->{$s} = 1; 2122e71b7053SJung-uk Kim } 2123e71b7053SJung-uk Kim } 2124e71b7053SJung-uk Kim } 2125e71b7053SJung-uk Kim 2126e71b7053SJung-uk Kim foreach (keys %shared_sources) { 2127e71b7053SJung-uk Kim my $dest = $_; 2128e71b7053SJung-uk Kim my $ddest = cleanfile($buildd, $_, $blddir); 2129e71b7053SJung-uk Kim if ($unified_info{rename}->{$ddest}) { 2130e71b7053SJung-uk Kim $ddest = $unified_info{rename}->{$ddest}; 2131e71b7053SJung-uk Kim } 2132e71b7053SJung-uk Kim foreach (@{$shared_sources{$dest}}) { 2133e71b7053SJung-uk Kim my $s = cleanfile($sourced, $_, $blddir); 2134e71b7053SJung-uk Kim 2135e71b7053SJung-uk Kim # If it isn't in the source tree, we assume it's generated 2136e71b7053SJung-uk Kim # in the build tree 2137e71b7053SJung-uk Kim if ($s eq $src_configdata || ! -f $s || $generate{$_}) { 2138e71b7053SJung-uk Kim $s = cleanfile($buildd, $_, $blddir); 2139e71b7053SJung-uk Kim } 2140e71b7053SJung-uk Kim 2141e71b7053SJung-uk Kim if ($s =~ /\.(cc|cpp|c|s|S)$/) { 2142e71b7053SJung-uk Kim # We recognise C++, C and asm files 2143e71b7053SJung-uk Kim my $o = $_; 2144e71b7053SJung-uk Kim $o =~ s/\.[csS]$/.o/; # C and assembler 2145e71b7053SJung-uk Kim $o =~ s/\.(cc|cpp)$/_cc.o/; # C++ 2146e71b7053SJung-uk Kim $o = cleanfile($buildd, $o, $blddir); 2147e71b7053SJung-uk Kim $unified_info{shared_sources}->{$ddest}->{$o} = 1; 2148e71b7053SJung-uk Kim $unified_info{sources}->{$o}->{$s} = 1; 2149e71b7053SJung-uk Kim } elsif ($s =~ /\.rc$/) { 2150e71b7053SJung-uk Kim # We also recognise resource files 2151e71b7053SJung-uk Kim my $o = $_; 2152e71b7053SJung-uk Kim $o =~ s/\.rc$/.res/; # Resource configuration 2153e71b7053SJung-uk Kim my $o = cleanfile($buildd, $o, $blddir); 2154e71b7053SJung-uk Kim $unified_info{shared_sources}->{$ddest}->{$o} = 1; 2155e71b7053SJung-uk Kim $unified_info{sources}->{$o}->{$s} = 1; 2156e71b7053SJung-uk Kim } elsif ($s =~ /\.(def|map|opt)$/) { 2157e71b7053SJung-uk Kim # We also recognise .def / .map / .opt files 2158e71b7053SJung-uk Kim # We know they are generated files 2159e71b7053SJung-uk Kim my $def = cleanfile($buildd, $s, $blddir); 2160e71b7053SJung-uk Kim $unified_info{shared_sources}->{$ddest}->{$def} = 1; 2161e71b7053SJung-uk Kim } else { 2162e71b7053SJung-uk Kim die "unrecognised source file type for shared library: $s\n"; 2163e71b7053SJung-uk Kim } 2164e71b7053SJung-uk Kim } 2165e71b7053SJung-uk Kim } 2166e71b7053SJung-uk Kim 2167e71b7053SJung-uk Kim foreach (keys %generate) { 2168e71b7053SJung-uk Kim my $dest = $_; 2169e71b7053SJung-uk Kim my $ddest = cleanfile($buildd, $_, $blddir); 2170e71b7053SJung-uk Kim if ($unified_info{rename}->{$ddest}) { 2171e71b7053SJung-uk Kim $ddest = $unified_info{rename}->{$ddest}; 2172e71b7053SJung-uk Kim } 2173e71b7053SJung-uk Kim die "more than one generator for $dest: " 2174e71b7053SJung-uk Kim ,join(" ", @{$generate{$_}}),"\n" 2175e71b7053SJung-uk Kim if scalar @{$generate{$_}} > 1; 2176e71b7053SJung-uk Kim my @generator = split /\s+/, $generate{$dest}->[0]; 2177e71b7053SJung-uk Kim $generator[0] = cleanfile($sourced, $generator[0], $blddir), 2178e71b7053SJung-uk Kim $unified_info{generate}->{$ddest} = [ @generator ]; 2179e71b7053SJung-uk Kim } 2180e71b7053SJung-uk Kim 2181e71b7053SJung-uk Kim foreach (keys %depends) { 2182e71b7053SJung-uk Kim my $dest = $_; 2183e71b7053SJung-uk Kim my $ddest = $dest eq "" ? "" : cleanfile($sourced, $_, $blddir); 2184e71b7053SJung-uk Kim 2185e71b7053SJung-uk Kim # If the destination doesn't exist in source, it can only be 2186e71b7053SJung-uk Kim # a generated file in the build tree. 2187e71b7053SJung-uk Kim if ($ddest ne "" && ($ddest eq $src_configdata || ! -f $ddest)) { 2188e71b7053SJung-uk Kim $ddest = cleanfile($buildd, $_, $blddir); 2189e71b7053SJung-uk Kim if ($unified_info{rename}->{$ddest}) { 2190e71b7053SJung-uk Kim $ddest = $unified_info{rename}->{$ddest}; 2191e71b7053SJung-uk Kim } 2192e71b7053SJung-uk Kim } 2193e71b7053SJung-uk Kim foreach (@{$depends{$dest}}) { 2194e71b7053SJung-uk Kim my $d = cleanfile($sourced, $_, $blddir); 2195e71b7053SJung-uk Kim 2196e71b7053SJung-uk Kim # If we know it's generated, or assume it is because we can't 2197e71b7053SJung-uk Kim # find it in the source tree, we set file we depend on to be 2198e71b7053SJung-uk Kim # in the build tree rather than the source tree, and assume 2199e71b7053SJung-uk Kim # and that there are lines to build it in a BEGINRAW..ENDRAW 2200e71b7053SJung-uk Kim # section or in the Makefile template. 2201e71b7053SJung-uk Kim if ($d eq $src_configdata 2202e71b7053SJung-uk Kim || ! -f $d 2203e71b7053SJung-uk Kim || (grep { $d eq $_ } 2204e71b7053SJung-uk Kim map { cleanfile($srcdir, $_, $blddir) } 2205e71b7053SJung-uk Kim grep { /\.h$/ } keys %{$unified_info{generate}})) { 2206e71b7053SJung-uk Kim $d = cleanfile($buildd, $_, $blddir); 2207e71b7053SJung-uk Kim } 2208e71b7053SJung-uk Kim # Take note if the file to depend on is being renamed 2209e71b7053SJung-uk Kim # Take extra care with files ending with .a, they should 2210e71b7053SJung-uk Kim # be treated without that extension, and the extension 2211e71b7053SJung-uk Kim # should be added back after treatment. 2212e71b7053SJung-uk Kim $d =~ /(\.a)?$/; 2213e71b7053SJung-uk Kim my $e = $1 // ""; 2214e71b7053SJung-uk Kim $d = $`; 2215e71b7053SJung-uk Kim if ($unified_info{rename}->{$d}) { 2216e71b7053SJung-uk Kim $d = $unified_info{rename}->{$d}; 2217e71b7053SJung-uk Kim } 2218e71b7053SJung-uk Kim $d .= $e; 2219e71b7053SJung-uk Kim $unified_info{depends}->{$ddest}->{$d} = 1; 2220e71b7053SJung-uk Kim } 2221e71b7053SJung-uk Kim } 2222e71b7053SJung-uk Kim 2223e71b7053SJung-uk Kim foreach (keys %includes) { 2224e71b7053SJung-uk Kim my $dest = $_; 2225e71b7053SJung-uk Kim my $ddest = cleanfile($sourced, $_, $blddir); 2226e71b7053SJung-uk Kim 2227e71b7053SJung-uk Kim # If the destination doesn't exist in source, it can only be 2228e71b7053SJung-uk Kim # a generated file in the build tree. 2229e71b7053SJung-uk Kim if ($ddest eq $src_configdata || ! -f $ddest) { 2230e71b7053SJung-uk Kim $ddest = cleanfile($buildd, $_, $blddir); 2231e71b7053SJung-uk Kim if ($unified_info{rename}->{$ddest}) { 2232e71b7053SJung-uk Kim $ddest = $unified_info{rename}->{$ddest}; 2233e71b7053SJung-uk Kim } 2234e71b7053SJung-uk Kim } 2235e71b7053SJung-uk Kim foreach (@{$includes{$dest}}) { 2236e71b7053SJung-uk Kim my $is = cleandir($sourced, $_, $blddir); 2237e71b7053SJung-uk Kim my $ib = cleandir($buildd, $_, $blddir); 2238e71b7053SJung-uk Kim push @{$unified_info{includes}->{$ddest}->{source}}, $is 2239e71b7053SJung-uk Kim unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}}; 2240e71b7053SJung-uk Kim push @{$unified_info{includes}->{$ddest}->{build}}, $ib 2241e71b7053SJung-uk Kim unless grep { $_ eq $ib } @{$unified_info{includes}->{$ddest}->{build}}; 2242e71b7053SJung-uk Kim } 2243e71b7053SJung-uk Kim } 2244e71b7053SJung-uk Kim } 2245e71b7053SJung-uk Kim 2246e71b7053SJung-uk Kim my $ordinals_text = join(', ', sort keys %ordinals); 2247e71b7053SJung-uk Kim warn <<"EOF" if $ordinals_text; 2248e71b7053SJung-uk Kim 2249e71b7053SJung-uk KimWARNING: ORDINALS were specified for $ordinals_text 2250e71b7053SJung-uk KimThey are ignored and should be replaced with a combination of GENERATE, 2251e71b7053SJung-uk KimDEPEND and SHARED_SOURCE. 2252e71b7053SJung-uk KimEOF 2253e71b7053SJung-uk Kim 2254e71b7053SJung-uk Kim # Massage the result 2255e71b7053SJung-uk Kim 2256c9cf7b5cSJung-uk Kim # If the user configured no-shared, we allow no shared sources 2257c9cf7b5cSJung-uk Kim if ($disabled{shared}) { 2258c9cf7b5cSJung-uk Kim foreach (keys %{$unified_info{shared_sources}}) { 2259c9cf7b5cSJung-uk Kim foreach (keys %{$unified_info{shared_sources}->{$_}}) { 2260c9cf7b5cSJung-uk Kim delete $unified_info{sources}->{$_}; 2261c9cf7b5cSJung-uk Kim } 2262c9cf7b5cSJung-uk Kim } 2263c9cf7b5cSJung-uk Kim $unified_info{shared_sources} = {}; 2264c9cf7b5cSJung-uk Kim } 2265c9cf7b5cSJung-uk Kim 2266e71b7053SJung-uk Kim # If we depend on a header file or a perl module, add an inclusion of 2267e71b7053SJung-uk Kim # its directory to allow smoothe inclusion 2268e71b7053SJung-uk Kim foreach my $dest (keys %{$unified_info{depends}}) { 2269e71b7053SJung-uk Kim next if $dest eq ""; 2270e71b7053SJung-uk Kim foreach my $d (keys %{$unified_info{depends}->{$dest}}) { 2271e71b7053SJung-uk Kim next unless $d =~ /\.(h|pm)$/; 2272e71b7053SJung-uk Kim my $i = dirname($d); 2273e71b7053SJung-uk Kim my $spot = 2274e71b7053SJung-uk Kim $d eq "configdata.pm" || defined($unified_info{generate}->{$d}) 2275e71b7053SJung-uk Kim ? 'build' : 'source'; 2276e71b7053SJung-uk Kim push @{$unified_info{includes}->{$dest}->{$spot}}, $i 2277e71b7053SJung-uk Kim unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{$spot}}; 2278e71b7053SJung-uk Kim } 2279e71b7053SJung-uk Kim } 2280e71b7053SJung-uk Kim 2281e71b7053SJung-uk Kim # Trickle down includes placed on libraries, engines and programs to 2282e71b7053SJung-uk Kim # their sources (i.e. object files) 2283e71b7053SJung-uk Kim foreach my $dest (keys %{$unified_info{engines}}, 2284e71b7053SJung-uk Kim keys %{$unified_info{libraries}}, 2285e71b7053SJung-uk Kim keys %{$unified_info{programs}}) { 2286e71b7053SJung-uk Kim foreach my $k (("source", "build")) { 2287e71b7053SJung-uk Kim next unless defined($unified_info{includes}->{$dest}->{$k}); 2288e71b7053SJung-uk Kim my @incs = reverse @{$unified_info{includes}->{$dest}->{$k}}; 2289e71b7053SJung-uk Kim foreach my $obj (grep /\.o$/, 2290c9cf7b5cSJung-uk Kim (keys %{$unified_info{sources}->{$dest} // {}}, 2291c9cf7b5cSJung-uk Kim keys %{$unified_info{shared_sources}->{$dest} // {}})) { 2292e71b7053SJung-uk Kim foreach my $inc (@incs) { 2293e71b7053SJung-uk Kim unshift @{$unified_info{includes}->{$obj}->{$k}}, $inc 2294e71b7053SJung-uk Kim unless grep { $_ eq $inc } @{$unified_info{includes}->{$obj}->{$k}}; 2295e71b7053SJung-uk Kim } 2296e71b7053SJung-uk Kim } 2297e71b7053SJung-uk Kim } 2298e71b7053SJung-uk Kim delete $unified_info{includes}->{$dest}; 2299e71b7053SJung-uk Kim } 2300e71b7053SJung-uk Kim 2301e71b7053SJung-uk Kim ### Make unified_info a bit more efficient 2302e71b7053SJung-uk Kim # One level structures 2303e71b7053SJung-uk Kim foreach (("programs", "libraries", "engines", "scripts", "extra", "overrides")) { 2304e71b7053SJung-uk Kim $unified_info{$_} = [ sort keys %{$unified_info{$_}} ]; 2305e71b7053SJung-uk Kim } 2306e71b7053SJung-uk Kim # Two level structures 2307e71b7053SJung-uk Kim foreach my $l1 (("install", "sources", "shared_sources", "ldadd", "depends")) { 2308e71b7053SJung-uk Kim foreach my $l2 (sort keys %{$unified_info{$l1}}) { 2309e71b7053SJung-uk Kim $unified_info{$l1}->{$l2} = 2310e71b7053SJung-uk Kim [ sort keys %{$unified_info{$l1}->{$l2}} ]; 2311e71b7053SJung-uk Kim } 2312e71b7053SJung-uk Kim } 2313e71b7053SJung-uk Kim # Includes 2314e71b7053SJung-uk Kim foreach my $dest (sort keys %{$unified_info{includes}}) { 2315e71b7053SJung-uk Kim if (defined($unified_info{includes}->{$dest}->{build})) { 2316e71b7053SJung-uk Kim my @source_includes = (); 2317e71b7053SJung-uk Kim @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} ) 2318e71b7053SJung-uk Kim if defined($unified_info{includes}->{$dest}->{source}); 2319e71b7053SJung-uk Kim $unified_info{includes}->{$dest} = 2320e71b7053SJung-uk Kim [ @{$unified_info{includes}->{$dest}->{build}} ]; 2321e71b7053SJung-uk Kim foreach my $inc (@source_includes) { 2322e71b7053SJung-uk Kim push @{$unified_info{includes}->{$dest}}, $inc 2323e71b7053SJung-uk Kim unless grep { $_ eq $inc } @{$unified_info{includes}->{$dest}}; 2324e71b7053SJung-uk Kim } 2325e71b7053SJung-uk Kim } else { 2326e71b7053SJung-uk Kim $unified_info{includes}->{$dest} = 2327e71b7053SJung-uk Kim [ @{$unified_info{includes}->{$dest}->{source}} ]; 2328e71b7053SJung-uk Kim } 2329e71b7053SJung-uk Kim } 2330c9cf7b5cSJung-uk Kim 2331c9cf7b5cSJung-uk Kim # For convenience collect information regarding directories where 2332c9cf7b5cSJung-uk Kim # files are generated, those generated files and the end product 2333c9cf7b5cSJung-uk Kim # they end up in where applicable. Then, add build rules for those 2334c9cf7b5cSJung-uk Kim # directories 2335c9cf7b5cSJung-uk Kim my %loopinfo = ( "lib" => [ @{$unified_info{libraries}} ], 2336c9cf7b5cSJung-uk Kim "dso" => [ @{$unified_info{engines}} ], 2337c9cf7b5cSJung-uk Kim "bin" => [ @{$unified_info{programs}} ], 2338c9cf7b5cSJung-uk Kim "script" => [ @{$unified_info{scripts}} ] ); 2339c9cf7b5cSJung-uk Kim foreach my $type (keys %loopinfo) { 2340c9cf7b5cSJung-uk Kim foreach my $product (@{$loopinfo{$type}}) { 2341c9cf7b5cSJung-uk Kim my %dirs = (); 2342c9cf7b5cSJung-uk Kim my $pd = dirname($product); 2343c9cf7b5cSJung-uk Kim 2344c9cf7b5cSJung-uk Kim foreach (@{$unified_info{sources}->{$product} // []}, 2345c9cf7b5cSJung-uk Kim @{$unified_info{shared_sources}->{$product} // []}) { 2346c9cf7b5cSJung-uk Kim my $d = dirname($_); 2347c9cf7b5cSJung-uk Kim 2348c9cf7b5cSJung-uk Kim # We don't want to create targets for source directories 2349c9cf7b5cSJung-uk Kim # when building out of source 2350c9cf7b5cSJung-uk Kim next if ($config{sourcedir} ne $config{builddir} 2351c9cf7b5cSJung-uk Kim && $d =~ m|^\Q$config{sourcedir}\E|); 2352c9cf7b5cSJung-uk Kim # We already have a "test" target, and the current directory 2353c9cf7b5cSJung-uk Kim # is just silly to make a target for 2354c9cf7b5cSJung-uk Kim next if $d eq "test" || $d eq "."; 2355c9cf7b5cSJung-uk Kim 2356c9cf7b5cSJung-uk Kim $dirs{$d} = 1; 2357c9cf7b5cSJung-uk Kim push @{$unified_info{dirinfo}->{$d}->{deps}}, $_ 2358c9cf7b5cSJung-uk Kim if $d ne $pd; 2359c9cf7b5cSJung-uk Kim } 2360c9cf7b5cSJung-uk Kim foreach (keys %dirs) { 2361c9cf7b5cSJung-uk Kim push @{$unified_info{dirinfo}->{$_}->{products}->{$type}}, 2362c9cf7b5cSJung-uk Kim $product; 2363c9cf7b5cSJung-uk Kim } 2364c9cf7b5cSJung-uk Kim } 2365c9cf7b5cSJung-uk Kim } 2366e71b7053SJung-uk Kim} 2367e71b7053SJung-uk Kim 2368e71b7053SJung-uk Kim# For the schemes that need it, we provide the old *_obj configs 2369e71b7053SJung-uk Kim# from the *_asm_obj ones 2370e71b7053SJung-uk Kimforeach (grep /_(asm|aux)_src$/, keys %target) { 2371e71b7053SJung-uk Kim my $src = $_; 2372e71b7053SJung-uk Kim (my $obj = $_) =~ s/_(asm|aux)_src$/_obj/; 2373e71b7053SJung-uk Kim $target{$obj} = $target{$src}; 2374e71b7053SJung-uk Kim $target{$obj} =~ s/\.[csS]\b/.o/g; # C and assembler 2375e71b7053SJung-uk Kim $target{$obj} =~ s/\.(cc|cpp)\b/_cc.o/g; # C++ 2376e71b7053SJung-uk Kim} 2377e71b7053SJung-uk Kim 2378e71b7053SJung-uk Kim# Write down our configuration where it fits ######################### 2379e71b7053SJung-uk Kim 2380e71b7053SJung-uk Kimprint "Creating configdata.pm\n"; 2381e71b7053SJung-uk Kimopen(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n"; 2382e71b7053SJung-uk Kimprint OUT <<"EOF"; 2383e71b7053SJung-uk Kim#! $config{HASHBANGPERL} 2384e71b7053SJung-uk Kim 2385e71b7053SJung-uk Kimpackage configdata; 2386e71b7053SJung-uk Kim 2387e71b7053SJung-uk Kimuse strict; 2388e71b7053SJung-uk Kimuse warnings; 2389e71b7053SJung-uk Kim 2390e71b7053SJung-uk Kimuse Exporter; 2391e71b7053SJung-uk Kim#use vars qw(\@ISA \@EXPORT); 2392e71b7053SJung-uk Kimour \@ISA = qw(Exporter); 2393e71b7053SJung-uk Kimour \@EXPORT = qw(\%config \%target \%disabled \%withargs \%unified_info \@disablables); 2394e71b7053SJung-uk Kim 2395e71b7053SJung-uk KimEOF 2396e71b7053SJung-uk Kimprint OUT "our %config = (\n"; 2397e71b7053SJung-uk Kimforeach (sort keys %config) { 2398e71b7053SJung-uk Kim if (ref($config{$_}) eq "ARRAY") { 2399e71b7053SJung-uk Kim print OUT " ", $_, " => [ ", join(", ", 2400e71b7053SJung-uk Kim map { quotify("perl", $_) } 2401e71b7053SJung-uk Kim @{$config{$_}}), " ],\n"; 2402e71b7053SJung-uk Kim } elsif (ref($config{$_}) eq "HASH") { 2403e71b7053SJung-uk Kim print OUT " ", $_, " => {"; 2404e71b7053SJung-uk Kim if (scalar keys %{$config{$_}} > 0) { 2405db522d3aSSimon L. B. Nielsen print OUT "\n"; 2406e71b7053SJung-uk Kim foreach my $key (sort keys %{$config{$_}}) { 2407e71b7053SJung-uk Kim print OUT " ", 2408e71b7053SJung-uk Kim join(" => ", 2409e71b7053SJung-uk Kim quotify("perl", $key), 2410e71b7053SJung-uk Kim defined $config{$_}->{$key} 2411e71b7053SJung-uk Kim ? quotify("perl", $config{$_}->{$key}) 2412e71b7053SJung-uk Kim : "undef"); 2413e71b7053SJung-uk Kim print OUT ",\n"; 24146a599222SSimon L. B. Nielsen } 2415e71b7053SJung-uk Kim print OUT " "; 24166a599222SSimon L. B. Nielsen } 2417e71b7053SJung-uk Kim print OUT "},\n"; 241874664626SKris Kennaway } else { 2419e71b7053SJung-uk Kim print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n" 2420ed7112f0SJung-uk Kim } 2421e71b7053SJung-uk Kim} 2422e71b7053SJung-uk Kimprint OUT <<"EOF"; 2423e71b7053SJung-uk Kim); 2424e71b7053SJung-uk Kim 2425e71b7053SJung-uk KimEOF 2426e71b7053SJung-uk Kimprint OUT "our %target = (\n"; 2427e71b7053SJung-uk Kimforeach (sort keys %target) { 2428e71b7053SJung-uk Kim if (ref($target{$_}) eq "ARRAY") { 2429e71b7053SJung-uk Kim print OUT " ", $_, " => [ ", join(", ", 2430e71b7053SJung-uk Kim map { quotify("perl", $_) } 2431e71b7053SJung-uk Kim @{$target{$_}}), " ],\n"; 243274664626SKris Kennaway } else { 2433e71b7053SJung-uk Kim print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n" 243474664626SKris Kennaway } 2435e71b7053SJung-uk Kim} 2436e71b7053SJung-uk Kimprint OUT <<"EOF"; 2437e71b7053SJung-uk Kim); 2438e71b7053SJung-uk Kim 2439e71b7053SJung-uk KimEOF 2440e71b7053SJung-uk Kimprint OUT "our \%available_protocols = (\n"; 2441e71b7053SJung-uk Kimprint OUT " tls => [ ", join(", ", map { quotify("perl", $_) } @tls), " ],\n"; 2442e71b7053SJung-uk Kimprint OUT " dtls => [ ", join(", ", map { quotify("perl", $_) } @dtls), " ],\n"; 2443e71b7053SJung-uk Kimprint OUT <<"EOF"; 2444e71b7053SJung-uk Kim); 2445e71b7053SJung-uk Kim 2446e71b7053SJung-uk KimEOF 2447e71b7053SJung-uk Kimprint OUT "our \@disablables = (\n"; 2448e71b7053SJung-uk Kimforeach (@disablables) { 2449e71b7053SJung-uk Kim print OUT " ", quotify("perl", $_), ",\n"; 2450e71b7053SJung-uk Kim} 2451e71b7053SJung-uk Kimprint OUT <<"EOF"; 2452e71b7053SJung-uk Kim); 2453e71b7053SJung-uk Kim 2454e71b7053SJung-uk KimEOF 2455e71b7053SJung-uk Kimprint OUT "our \%disabled = (\n"; 2456e71b7053SJung-uk Kimforeach (sort keys %disabled) { 2457e71b7053SJung-uk Kim print OUT " ", quotify("perl", $_), " => ", quotify("perl", $disabled{$_}), ",\n"; 2458e71b7053SJung-uk Kim} 2459e71b7053SJung-uk Kimprint OUT <<"EOF"; 2460e71b7053SJung-uk Kim); 2461e71b7053SJung-uk Kim 2462e71b7053SJung-uk KimEOF 2463e71b7053SJung-uk Kimprint OUT "our %withargs = (\n"; 2464e71b7053SJung-uk Kimforeach (sort keys %withargs) { 2465e71b7053SJung-uk Kim if (ref($withargs{$_}) eq "ARRAY") { 2466e71b7053SJung-uk Kim print OUT " ", $_, " => [ ", join(", ", 2467e71b7053SJung-uk Kim map { quotify("perl", $_) } 2468e71b7053SJung-uk Kim @{$withargs{$_}}), " ],\n"; 2469e71b7053SJung-uk Kim } else { 2470e71b7053SJung-uk Kim print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n" 2471e71b7053SJung-uk Kim } 2472e71b7053SJung-uk Kim} 2473e71b7053SJung-uk Kimprint OUT <<"EOF"; 2474e71b7053SJung-uk Kim); 2475e71b7053SJung-uk Kim 2476e71b7053SJung-uk KimEOF 2477e71b7053SJung-uk Kimif ($builder eq "unified") { 2478e71b7053SJung-uk Kim my $recurse; 2479e71b7053SJung-uk Kim $recurse = sub { 2480e71b7053SJung-uk Kim my $indent = shift; 2481e71b7053SJung-uk Kim foreach (@_) { 2482e71b7053SJung-uk Kim if (ref $_ eq "ARRAY") { 2483e71b7053SJung-uk Kim print OUT " "x$indent, "[\n"; 2484e71b7053SJung-uk Kim foreach (@$_) { 2485e71b7053SJung-uk Kim $recurse->($indent + 4, $_); 2486e71b7053SJung-uk Kim } 2487e71b7053SJung-uk Kim print OUT " "x$indent, "],\n"; 2488e71b7053SJung-uk Kim } elsif (ref $_ eq "HASH") { 2489e71b7053SJung-uk Kim my %h = %$_; 2490e71b7053SJung-uk Kim print OUT " "x$indent, "{\n"; 2491e71b7053SJung-uk Kim foreach (sort keys %h) { 2492e71b7053SJung-uk Kim if (ref $h{$_} eq "") { 2493e71b7053SJung-uk Kim print OUT " "x($indent + 4), quotify("perl", $_), " => ", quotify("perl", $h{$_}), ",\n"; 2494e71b7053SJung-uk Kim } else { 2495e71b7053SJung-uk Kim print OUT " "x($indent + 4), quotify("perl", $_), " =>\n"; 2496e71b7053SJung-uk Kim $recurse->($indent + 8, $h{$_}); 2497e71b7053SJung-uk Kim } 2498e71b7053SJung-uk Kim } 2499e71b7053SJung-uk Kim print OUT " "x$indent, "},\n"; 2500e71b7053SJung-uk Kim } else { 2501e71b7053SJung-uk Kim print OUT " "x$indent, quotify("perl", $_), ",\n"; 2502e71b7053SJung-uk Kim } 2503e71b7053SJung-uk Kim } 2504e71b7053SJung-uk Kim }; 2505e71b7053SJung-uk Kim print OUT "our %unified_info = (\n"; 2506e71b7053SJung-uk Kim foreach (sort keys %unified_info) { 2507e71b7053SJung-uk Kim if (ref $unified_info{$_} eq "") { 2508e71b7053SJung-uk Kim print OUT " "x4, quotify("perl", $_), " => ", quotify("perl", $unified_info{$_}), ",\n"; 2509e71b7053SJung-uk Kim } else { 2510e71b7053SJung-uk Kim print OUT " "x4, quotify("perl", $_), " =>\n"; 2511e71b7053SJung-uk Kim $recurse->(8, $unified_info{$_}); 2512e71b7053SJung-uk Kim } 2513e71b7053SJung-uk Kim } 2514e71b7053SJung-uk Kim print OUT <<"EOF"; 2515e71b7053SJung-uk Kim); 2516e71b7053SJung-uk Kim 2517e71b7053SJung-uk KimEOF 2518e71b7053SJung-uk Kim} 2519e71b7053SJung-uk Kimprint OUT 2520e71b7053SJung-uk Kim "# The following data is only used when this files is use as a script\n"; 2521e71b7053SJung-uk Kimprint OUT "my \@makevars = (\n"; 2522e71b7053SJung-uk Kimforeach (sort keys %user) { 2523e71b7053SJung-uk Kim print OUT " '",$_,"',\n"; 2524e71b7053SJung-uk Kim} 2525e71b7053SJung-uk Kimprint OUT ");\n"; 2526e71b7053SJung-uk Kimprint OUT "my \%disabled_info = (\n"; 2527e71b7053SJung-uk Kimforeach my $what (sort keys %disabled_info) { 2528e71b7053SJung-uk Kim print OUT " '$what' => {\n"; 2529e71b7053SJung-uk Kim foreach my $info (sort keys %{$disabled_info{$what}}) { 2530e71b7053SJung-uk Kim if (ref $disabled_info{$what}->{$info} eq 'ARRAY') { 2531e71b7053SJung-uk Kim print OUT " $info => [ ", 2532e71b7053SJung-uk Kim join(', ', map { "'$_'" } @{$disabled_info{$what}->{$info}}), 2533e71b7053SJung-uk Kim " ],\n"; 2534e71b7053SJung-uk Kim } else { 2535e71b7053SJung-uk Kim print OUT " $info => '", $disabled_info{$what}->{$info}, 2536e71b7053SJung-uk Kim "',\n"; 2537e71b7053SJung-uk Kim } 2538e71b7053SJung-uk Kim } 2539e71b7053SJung-uk Kim print OUT " },\n"; 2540e71b7053SJung-uk Kim} 2541e71b7053SJung-uk Kimprint OUT ");\n"; 2542e71b7053SJung-uk Kimprint OUT 'my @user_crossable = qw( ', join (' ', @user_crossable), " );\n"; 2543e71b7053SJung-uk Kimprint OUT << 'EOF'; 2544e71b7053SJung-uk Kim# If run directly, we can give some answers, and even reconfigure 2545e71b7053SJung-uk Kimunless (caller) { 2546e71b7053SJung-uk Kim use Getopt::Long; 2547e71b7053SJung-uk Kim use File::Spec::Functions; 2548e71b7053SJung-uk Kim use File::Basename; 2549e71b7053SJung-uk Kim use Pod::Usage; 2550e71b7053SJung-uk Kim 2551e71b7053SJung-uk Kim my $here = dirname($0); 2552e71b7053SJung-uk Kim 2553e71b7053SJung-uk Kim my $dump = undef; 2554e71b7053SJung-uk Kim my $cmdline = undef; 2555e71b7053SJung-uk Kim my $options = undef; 2556e71b7053SJung-uk Kim my $target = undef; 2557e71b7053SJung-uk Kim my $envvars = undef; 2558e71b7053SJung-uk Kim my $makevars = undef; 2559e71b7053SJung-uk Kim my $buildparams = undef; 2560e71b7053SJung-uk Kim my $reconf = undef; 2561e71b7053SJung-uk Kim my $verbose = undef; 2562e71b7053SJung-uk Kim my $help = undef; 2563e71b7053SJung-uk Kim my $man = undef; 2564e71b7053SJung-uk Kim GetOptions('dump|d' => \$dump, 2565e71b7053SJung-uk Kim 'command-line|c' => \$cmdline, 2566e71b7053SJung-uk Kim 'options|o' => \$options, 2567e71b7053SJung-uk Kim 'target|t' => \$target, 2568e71b7053SJung-uk Kim 'environment|e' => \$envvars, 2569e71b7053SJung-uk Kim 'make-variables|m' => \$makevars, 2570e71b7053SJung-uk Kim 'build-parameters|b' => \$buildparams, 2571e71b7053SJung-uk Kim 'reconfigure|reconf|r' => \$reconf, 2572e71b7053SJung-uk Kim 'verbose|v' => \$verbose, 2573e71b7053SJung-uk Kim 'help' => \$help, 2574e71b7053SJung-uk Kim 'man' => \$man) 2575e71b7053SJung-uk Kim or die "Errors in command line arguments\n"; 2576e71b7053SJung-uk Kim 2577e71b7053SJung-uk Kim unless ($dump || $cmdline || $options || $target || $envvars || $makevars 2578e71b7053SJung-uk Kim || $buildparams || $reconf || $verbose || $help || $man) { 2579e71b7053SJung-uk Kim print STDERR <<"_____"; 2580e71b7053SJung-uk KimYou must give at least one option. 2581e71b7053SJung-uk KimFor more information, do '$0 --help' 2582e71b7053SJung-uk Kim_____ 2583e71b7053SJung-uk Kim exit(2); 2584e71b7053SJung-uk Kim } 2585e71b7053SJung-uk Kim 2586e71b7053SJung-uk Kim if ($help) { 2587e71b7053SJung-uk Kim pod2usage(-exitval => 0, 2588e71b7053SJung-uk Kim -verbose => 1); 2589e71b7053SJung-uk Kim } 2590e71b7053SJung-uk Kim if ($man) { 2591e71b7053SJung-uk Kim pod2usage(-exitval => 0, 2592e71b7053SJung-uk Kim -verbose => 2); 2593e71b7053SJung-uk Kim } 2594e71b7053SJung-uk Kim if ($dump || $cmdline) { 2595e71b7053SJung-uk Kim print "\nCommand line (with current working directory = $here):\n\n"; 2596e71b7053SJung-uk Kim print ' ',join(' ', 2597e71b7053SJung-uk Kim $config{PERL}, 2598e71b7053SJung-uk Kim catfile($config{sourcedir}, 'Configure'), 2599e71b7053SJung-uk Kim @{$config{perlargv}}), "\n"; 2600e71b7053SJung-uk Kim print "\nPerl information:\n\n"; 2601e71b7053SJung-uk Kim print ' ',$config{perl_cmd},"\n"; 2602e71b7053SJung-uk Kim print ' ',$config{perl_version},' for ',$config{perl_archname},"\n"; 2603e71b7053SJung-uk Kim } 2604e71b7053SJung-uk Kim if ($dump || $options) { 2605e71b7053SJung-uk Kim my $longest = 0; 2606e71b7053SJung-uk Kim my $longest2 = 0; 2607e71b7053SJung-uk Kim foreach my $what (@disablables) { 2608e71b7053SJung-uk Kim $longest = length($what) if $longest < length($what); 2609e71b7053SJung-uk Kim $longest2 = length($disabled{$what}) 2610e71b7053SJung-uk Kim if $disabled{$what} && $longest2 < length($disabled{$what}); 2611e71b7053SJung-uk Kim } 2612e71b7053SJung-uk Kim print "\nEnabled features:\n\n"; 2613e71b7053SJung-uk Kim foreach my $what (@disablables) { 2614e71b7053SJung-uk Kim print " $what\n" unless $disabled{$what}; 2615e71b7053SJung-uk Kim } 2616e71b7053SJung-uk Kim print "\nDisabled features:\n\n"; 2617e71b7053SJung-uk Kim foreach my $what (@disablables) { 2618e71b7053SJung-uk Kim if ($disabled{$what}) { 2619e71b7053SJung-uk Kim print " $what", ' ' x ($longest - length($what) + 1), 2620e71b7053SJung-uk Kim "[$disabled{$what}]", ' ' x ($longest2 - length($disabled{$what}) + 1); 2621e71b7053SJung-uk Kim print $disabled_info{$what}->{macro} 2622e71b7053SJung-uk Kim if $disabled_info{$what}->{macro}; 2623e71b7053SJung-uk Kim print ' (skip ', 2624e71b7053SJung-uk Kim join(', ', @{$disabled_info{$what}->{skipped}}), 2625e71b7053SJung-uk Kim ')' 2626e71b7053SJung-uk Kim if $disabled_info{$what}->{skipped}; 2627e71b7053SJung-uk Kim print "\n"; 2628e71b7053SJung-uk Kim } 2629e71b7053SJung-uk Kim } 2630e71b7053SJung-uk Kim } 2631e71b7053SJung-uk Kim if ($dump || $target) { 2632e71b7053SJung-uk Kim print "\nConfig target attributes:\n\n"; 2633e71b7053SJung-uk Kim foreach (sort keys %target) { 2634e71b7053SJung-uk Kim next if $_ =~ m|^_| || $_ eq 'template'; 2635e71b7053SJung-uk Kim my $quotify = sub { 2636e71b7053SJung-uk Kim map { (my $x = $_) =~ s|([\\\$\@"])|\\$1|g; "\"$x\""} @_; 2637e71b7053SJung-uk Kim }; 2638e71b7053SJung-uk Kim print ' ', $_, ' => '; 2639e71b7053SJung-uk Kim if (ref($target{$_}) eq "ARRAY") { 2640e71b7053SJung-uk Kim print '[ ', join(', ', $quotify->(@{$target{$_}})), " ],\n"; 2641e71b7053SJung-uk Kim } else { 2642e71b7053SJung-uk Kim print $quotify->($target{$_}), ",\n" 2643e71b7053SJung-uk Kim } 2644e71b7053SJung-uk Kim } 2645e71b7053SJung-uk Kim } 2646e71b7053SJung-uk Kim if ($dump || $envvars) { 2647e71b7053SJung-uk Kim print "\nRecorded environment:\n\n"; 2648e71b7053SJung-uk Kim foreach (sort keys %{$config{perlenv}}) { 2649e71b7053SJung-uk Kim print ' ',$_,' = ',($config{perlenv}->{$_} || ''),"\n"; 2650e71b7053SJung-uk Kim } 2651e71b7053SJung-uk Kim } 2652e71b7053SJung-uk Kim if ($dump || $makevars) { 2653e71b7053SJung-uk Kim print "\nMakevars:\n\n"; 2654e71b7053SJung-uk Kim foreach my $var (@makevars) { 2655e71b7053SJung-uk Kim my $prefix = ''; 2656e71b7053SJung-uk Kim $prefix = $config{CROSS_COMPILE} 2657e71b7053SJung-uk Kim if grep { $var eq $_ } @user_crossable; 2658e71b7053SJung-uk Kim $prefix //= ''; 2659e71b7053SJung-uk Kim print ' ',$var,' ' x (16 - length $var),'= ', 2660e71b7053SJung-uk Kim (ref $config{$var} eq 'ARRAY' 2661e71b7053SJung-uk Kim ? join(' ', @{$config{$var}}) 2662e71b7053SJung-uk Kim : $prefix.$config{$var}), 2663e71b7053SJung-uk Kim "\n" 2664e71b7053SJung-uk Kim if defined $config{$var}; 2665e71b7053SJung-uk Kim } 2666e71b7053SJung-uk Kim 2667e71b7053SJung-uk Kim my @buildfile = ($config{builddir}, $config{build_file}); 2668e71b7053SJung-uk Kim unshift @buildfile, $here 2669e71b7053SJung-uk Kim unless file_name_is_absolute($config{builddir}); 2670e71b7053SJung-uk Kim my $buildfile = canonpath(catdir(@buildfile)); 2671e71b7053SJung-uk Kim print <<"_____"; 2672e71b7053SJung-uk Kim 2673e71b7053SJung-uk KimNOTE: These variables only represent the configuration view. The build file 2674e71b7053SJung-uk Kimtemplate may have processed these variables further, please have a look at the 2675e71b7053SJung-uk Kimbuild file for more exact data: 2676e71b7053SJung-uk Kim $buildfile 2677e71b7053SJung-uk Kim_____ 2678e71b7053SJung-uk Kim } 2679e71b7053SJung-uk Kim if ($dump || $buildparams) { 2680e71b7053SJung-uk Kim my @buildfile = ($config{builddir}, $config{build_file}); 2681e71b7053SJung-uk Kim unshift @buildfile, $here 2682e71b7053SJung-uk Kim unless file_name_is_absolute($config{builddir}); 2683e71b7053SJung-uk Kim print "\nbuild file:\n\n"; 2684e71b7053SJung-uk Kim print " ", canonpath(catfile(@buildfile)),"\n"; 2685e71b7053SJung-uk Kim 2686e71b7053SJung-uk Kim print "\nbuild file templates:\n\n"; 2687e71b7053SJung-uk Kim foreach (@{$config{build_file_templates}}) { 2688e71b7053SJung-uk Kim my @tmpl = ($_); 2689e71b7053SJung-uk Kim unshift @tmpl, $here 2690e71b7053SJung-uk Kim unless file_name_is_absolute($config{sourcedir}); 2691e71b7053SJung-uk Kim print ' ',canonpath(catfile(@tmpl)),"\n"; 2692e71b7053SJung-uk Kim } 2693e71b7053SJung-uk Kim } 2694e71b7053SJung-uk Kim if ($reconf) { 2695e71b7053SJung-uk Kim if ($verbose) { 2696e71b7053SJung-uk Kim print 'Reconfiguring with: ', join(' ',@{$config{perlargv}}), "\n"; 2697e71b7053SJung-uk Kim foreach (sort keys %{$config{perlenv}}) { 2698e71b7053SJung-uk Kim print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n"; 26995c87c606SMark Murray } 270074664626SKris Kennaway } 270174664626SKris Kennaway 2702e71b7053SJung-uk Kim chdir $here; 2703e71b7053SJung-uk Kim exec $^X,catfile($config{sourcedir}, 'Configure'),'reconf'; 27043b4e3dcbSSimon L. B. Nielsen } 2705e71b7053SJung-uk Kim} 27063b4e3dcbSSimon L. B. Nielsen 2707e71b7053SJung-uk Kim1; 27083b4e3dcbSSimon L. B. Nielsen 2709e71b7053SJung-uk Kim__END__ 2710e71b7053SJung-uk Kim 2711e71b7053SJung-uk Kim=head1 NAME 2712e71b7053SJung-uk Kim 2713e71b7053SJung-uk Kimconfigdata.pm - configuration data for OpenSSL builds 2714e71b7053SJung-uk Kim 2715e71b7053SJung-uk Kim=head1 SYNOPSIS 2716e71b7053SJung-uk Kim 2717e71b7053SJung-uk KimInteractive: 2718e71b7053SJung-uk Kim 2719e71b7053SJung-uk Kim perl configdata.pm [options] 2720e71b7053SJung-uk Kim 2721e71b7053SJung-uk KimAs data bank module: 2722e71b7053SJung-uk Kim 2723e71b7053SJung-uk Kim use configdata; 2724e71b7053SJung-uk Kim 2725e71b7053SJung-uk Kim=head1 DESCRIPTION 2726e71b7053SJung-uk Kim 2727e71b7053SJung-uk KimThis module can be used in two modes, interactively and as a module containing 2728e71b7053SJung-uk Kimall the data recorded by OpenSSL's Configure script. 2729e71b7053SJung-uk Kim 2730e71b7053SJung-uk KimWhen used interactively, simply run it as any perl script, with at least one 2731e71b7053SJung-uk Kimoption, and you will get the information you ask for. See L</OPTIONS> below. 2732e71b7053SJung-uk Kim 2733e71b7053SJung-uk KimWhen loaded as a module, you get a few databanks with useful information to 2734e71b7053SJung-uk Kimperform build related tasks. The databanks are: 2735e71b7053SJung-uk Kim 2736e71b7053SJung-uk Kim %config Configured things. 2737e71b7053SJung-uk Kim %target The OpenSSL config target with all inheritances 2738e71b7053SJung-uk Kim resolved. 2739e71b7053SJung-uk Kim %disabled The features that are disabled. 2740e71b7053SJung-uk Kim @disablables The list of features that can be disabled. 2741e71b7053SJung-uk Kim %withargs All data given through --with-THING options. 2742e71b7053SJung-uk Kim %unified_info All information that was computed from the build.info 2743e71b7053SJung-uk Kim files. 2744e71b7053SJung-uk Kim 2745e71b7053SJung-uk Kim=head1 OPTIONS 2746e71b7053SJung-uk Kim 2747e71b7053SJung-uk Kim=over 4 2748e71b7053SJung-uk Kim 2749e71b7053SJung-uk Kim=item B<--help> 2750e71b7053SJung-uk Kim 2751e71b7053SJung-uk KimPrint a brief help message and exit. 2752e71b7053SJung-uk Kim 2753e71b7053SJung-uk Kim=item B<--man> 2754e71b7053SJung-uk Kim 2755e71b7053SJung-uk KimPrint the manual page and exit. 2756e71b7053SJung-uk Kim 2757e71b7053SJung-uk Kim=item B<--dump> | B<-d> 2758e71b7053SJung-uk Kim 2759e71b7053SJung-uk KimPrint all relevant configuration data. This is equivalent to B<--command-line> 2760e71b7053SJung-uk KimB<--options> B<--target> B<--environment> B<--make-variables> 2761e71b7053SJung-uk KimB<--build-parameters>. 2762e71b7053SJung-uk Kim 2763e71b7053SJung-uk Kim=item B<--command-line> | B<-c> 2764e71b7053SJung-uk Kim 2765e71b7053SJung-uk KimPrint the current configuration command line. 2766e71b7053SJung-uk Kim 2767e71b7053SJung-uk Kim=item B<--options> | B<-o> 2768e71b7053SJung-uk Kim 2769e71b7053SJung-uk KimPrint the features, both enabled and disabled, and display defined macro and 2770e71b7053SJung-uk Kimskipped directories where applicable. 2771e71b7053SJung-uk Kim 2772e71b7053SJung-uk Kim=item B<--target> | B<-t> 2773e71b7053SJung-uk Kim 2774e71b7053SJung-uk KimPrint the config attributes for this config target. 2775e71b7053SJung-uk Kim 2776e71b7053SJung-uk Kim=item B<--environment> | B<-e> 2777e71b7053SJung-uk Kim 2778e71b7053SJung-uk KimPrint the environment variables and their values at the time of configuration. 2779e71b7053SJung-uk Kim 2780e71b7053SJung-uk Kim=item B<--make-variables> | B<-m> 2781e71b7053SJung-uk Kim 2782e71b7053SJung-uk KimPrint the main make variables generated in the current configuration 2783e71b7053SJung-uk Kim 2784e71b7053SJung-uk Kim=item B<--build-parameters> | B<-b> 2785e71b7053SJung-uk Kim 2786e71b7053SJung-uk KimPrint the build parameters, i.e. build file and build file templates. 2787e71b7053SJung-uk Kim 2788e71b7053SJung-uk Kim=item B<--reconfigure> | B<--reconf> | B<-r> 2789e71b7053SJung-uk Kim 2790e71b7053SJung-uk KimRedo the configuration. 2791e71b7053SJung-uk Kim 2792e71b7053SJung-uk Kim=item B<--verbose> | B<-v> 2793e71b7053SJung-uk Kim 2794e71b7053SJung-uk KimVerbose output. 2795e71b7053SJung-uk Kim 2796e71b7053SJung-uk Kim=back 2797e71b7053SJung-uk Kim 2798e71b7053SJung-uk Kim=cut 2799e71b7053SJung-uk Kim 28003b4e3dcbSSimon L. B. NielsenEOF 28013b4e3dcbSSimon L. B. Nielsenclose(OUT); 2802e71b7053SJung-uk Kimif ($builder_platform eq 'unix') { 2803e71b7053SJung-uk Kim my $mode = (0755 & ~umask); 2804e71b7053SJung-uk Kim chmod $mode, 'configdata.pm' 2805e71b7053SJung-uk Kim or warn sprintf("WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s\n",$mode,$!); 28063b4e3dcbSSimon L. B. Nielsen} 28073b4e3dcbSSimon L. B. Nielsen 2808e71b7053SJung-uk Kimmy %builders = ( 2809e71b7053SJung-uk Kim unified => sub { 2810e71b7053SJung-uk Kim print 'Creating ',$target{build_file},"\n"; 2811e71b7053SJung-uk Kim run_dofile(catfile($blddir, $target{build_file}), 2812e71b7053SJung-uk Kim @{$config{build_file_templates}}); 2813e71b7053SJung-uk Kim }, 2814e71b7053SJung-uk Kim ); 281574664626SKris Kennaway 2816e71b7053SJung-uk Kim$builders{$builder}->($builder_platform, @builder_opts); 281774664626SKris Kennaway 2818e71b7053SJung-uk Kim$SIG{__DIE__} = $orig_death_handler; 2819e71b7053SJung-uk Kim 2820e71b7053SJung-uk Kimprint <<"EOF" if ($disabled{threads} eq "unavailable"); 282174664626SKris Kennaway 282274664626SKris KennawayThe library could not be configured for supporting multi-threaded 282374664626SKris Kennawayapplications as the compiler options required on this system are not known. 282474664626SKris KennawaySee file INSTALL for details if you need multi-threading. 282574664626SKris KennawayEOF 282674664626SKris Kennaway 2827e71b7053SJung-uk Kimprint <<"EOF" if ($no_shared_warn); 2828fceca8a3SJacques Vidrine 2829e71b7053SJung-uk KimThe options 'shared', 'pic' and 'dynamic-engine' aren't supported on this 2830e71b7053SJung-uk Kimplatform, so we will pretend you gave the option 'no-pic', which also disables 2831e71b7053SJung-uk Kim'shared' and 'dynamic-engine'. If you know how to implement shared libraries 2832e71b7053SJung-uk Kimor position independent code, please let us know (but please first make sure 2833e71b7053SJung-uk Kimyou have tried with a current version of OpenSSL). 28348180e704SJung-uk KimEOF 28358180e704SJung-uk Kim 2836e71b7053SJung-uk Kimprint <<"EOF"; 28378180e704SJung-uk Kim 2838e71b7053SJung-uk Kim********************************************************************** 2839e71b7053SJung-uk Kim*** *** 2840c9cf7b5cSJung-uk Kim*** OpenSSL has been successfully configured *** 2841c9cf7b5cSJung-uk Kim*** *** 2842c9cf7b5cSJung-uk Kim*** If you encounter a problem while building, please open an *** 2843c9cf7b5cSJung-uk Kim*** issue on GitHub <https://github.com/openssl/openssl/issues> *** 2844c9cf7b5cSJung-uk Kim*** and include the output from the following command: *** 2845e71b7053SJung-uk Kim*** *** 2846e71b7053SJung-uk Kim*** perl configdata.pm --dump *** 2847e71b7053SJung-uk Kim*** *** 2848c9cf7b5cSJung-uk Kim*** (If you are new to OpenSSL, you might want to consult the *** 2849c9cf7b5cSJung-uk Kim*** 'Troubleshooting' section in the INSTALL file first) *** 2850c9cf7b5cSJung-uk Kim*** *** 2851e71b7053SJung-uk Kim********************************************************************** 2852fceca8a3SJacques VidrineEOF 2853fceca8a3SJacques Vidrine 285474664626SKris Kennawayexit(0); 285574664626SKris Kennaway 2856e71b7053SJung-uk Kim###################################################################### 2857e71b7053SJung-uk Kim# 2858e71b7053SJung-uk Kim# Helpers and utility functions 2859e71b7053SJung-uk Kim# 2860e71b7053SJung-uk Kim 2861e71b7053SJung-uk Kim# Death handler, to print a helpful message in case of failure ####### 2862e71b7053SJung-uk Kim# 2863e71b7053SJung-uk Kimsub death_handler { 2864e71b7053SJung-uk Kim die @_ if $^S; # To prevent the added message in eval blocks 2865e71b7053SJung-uk Kim my $build_file = $target{build_file} // "build file"; 2866e71b7053SJung-uk Kim my @message = ( <<"_____", @_ ); 2867e71b7053SJung-uk Kim 2868e71b7053SJung-uk KimFailure! $build_file wasn't produced. 2869e71b7053SJung-uk KimPlease read INSTALL and associated NOTES files. You may also have to look over 2870e71b7053SJung-uk Kimyour available compiler tool chain or change your configuration. 2871e71b7053SJung-uk Kim 2872e71b7053SJung-uk Kim_____ 2873e71b7053SJung-uk Kim 2874e71b7053SJung-uk Kim # Dying is terminal, so it's ok to reset the signal handler here. 2875e71b7053SJung-uk Kim $SIG{__DIE__} = $orig_death_handler; 2876e71b7053SJung-uk Kim die @message; 2877e71b7053SJung-uk Kim} 2878e71b7053SJung-uk Kim 2879e71b7053SJung-uk Kim# Configuration file reading ######################################### 2880e71b7053SJung-uk Kim 2881e71b7053SJung-uk Kim# Note: All of the helper functions are for lazy evaluation. They all 2882e71b7053SJung-uk Kim# return a CODE ref, which will return the intended value when evaluated. 2883e71b7053SJung-uk Kim# Thus, whenever there's mention of a returned value, it's about that 2884e71b7053SJung-uk Kim# intended value. 2885e71b7053SJung-uk Kim 2886e71b7053SJung-uk Kim# Helper function to implement conditional inheritance depending on the 2887e71b7053SJung-uk Kim# value of $disabled{asm}. Used in inherit_from values as follows: 2888e71b7053SJung-uk Kim# 2889e71b7053SJung-uk Kim# inherit_from => [ "template", asm("asm_tmpl") ] 2890e71b7053SJung-uk Kim# 2891e71b7053SJung-uk Kimsub asm { 2892e71b7053SJung-uk Kim my @x = @_; 2893e71b7053SJung-uk Kim sub { 2894e71b7053SJung-uk Kim $disabled{asm} ? () : @x; 2895e71b7053SJung-uk Kim } 2896e71b7053SJung-uk Kim} 2897e71b7053SJung-uk Kim 2898e71b7053SJung-uk Kim# Helper function to implement conditional value variants, with a default 2899e71b7053SJung-uk Kim# plus additional values based on the value of $config{build_type}. 2900e71b7053SJung-uk Kim# Arguments are given in hash table form: 2901e71b7053SJung-uk Kim# 2902e71b7053SJung-uk Kim# picker(default => "Basic string: ", 2903e71b7053SJung-uk Kim# debug => "debug", 2904e71b7053SJung-uk Kim# release => "release") 2905e71b7053SJung-uk Kim# 2906e71b7053SJung-uk Kim# When configuring with --debug, the resulting string will be 2907e71b7053SJung-uk Kim# "Basic string: debug", and when not, it will be "Basic string: release" 2908e71b7053SJung-uk Kim# 2909e71b7053SJung-uk Kim# This can be used to create variants of sets of flags according to the 2910e71b7053SJung-uk Kim# build type: 2911e71b7053SJung-uk Kim# 2912e71b7053SJung-uk Kim# cflags => picker(default => "-Wall", 2913e71b7053SJung-uk Kim# debug => "-g -O0", 2914e71b7053SJung-uk Kim# release => "-O3") 2915e71b7053SJung-uk Kim# 2916e71b7053SJung-uk Kimsub picker { 2917e71b7053SJung-uk Kim my %opts = @_; 2918e71b7053SJung-uk Kim return sub { add($opts{default} || (), 2919e71b7053SJung-uk Kim $opts{$config{build_type}} || ())->(); } 2920e71b7053SJung-uk Kim} 2921e71b7053SJung-uk Kim 2922e71b7053SJung-uk Kim# Helper function to combine several values of different types into one. 2923e71b7053SJung-uk Kim# This is useful if you want to combine a string with the result of a 2924e71b7053SJung-uk Kim# lazy function, such as: 2925e71b7053SJung-uk Kim# 2926e71b7053SJung-uk Kim# cflags => combine("-Wall", sub { $disabled{zlib} ? () : "-DZLIB" }) 2927e71b7053SJung-uk Kim# 2928e71b7053SJung-uk Kimsub combine { 2929e71b7053SJung-uk Kim my @stuff = @_; 2930e71b7053SJung-uk Kim return sub { add(@stuff)->(); } 2931e71b7053SJung-uk Kim} 2932e71b7053SJung-uk Kim 2933e71b7053SJung-uk Kim# Helper function to implement conditional values depending on the value 2934e71b7053SJung-uk Kim# of $disabled{threads}. Can be used as follows: 2935e71b7053SJung-uk Kim# 2936e71b7053SJung-uk Kim# cflags => combine("-Wall", threads("-pthread")) 2937e71b7053SJung-uk Kim# 2938e71b7053SJung-uk Kimsub threads { 2939e71b7053SJung-uk Kim my @flags = @_; 2940e71b7053SJung-uk Kim return sub { add($disabled{threads} ? () : @flags)->(); } 2941e71b7053SJung-uk Kim} 2942e71b7053SJung-uk Kim 2943e71b7053SJung-uk Kimsub shared { 2944e71b7053SJung-uk Kim my @flags = @_; 2945e71b7053SJung-uk Kim return sub { add($disabled{shared} ? () : @flags)->(); } 2946e71b7053SJung-uk Kim} 2947e71b7053SJung-uk Kim 2948e71b7053SJung-uk Kimour $add_called = 0; 2949e71b7053SJung-uk Kim# Helper function to implement adding values to already existing configuration 2950e71b7053SJung-uk Kim# values. It handles elements that are ARRAYs, CODEs and scalars 2951e71b7053SJung-uk Kimsub _add { 2952e71b7053SJung-uk Kim my $separator = shift; 2953e71b7053SJung-uk Kim 2954e71b7053SJung-uk Kim # If there's any ARRAY in the collection of values OR the separator 2955e71b7053SJung-uk Kim # is undef, we will return an ARRAY of combined values, otherwise a 2956e71b7053SJung-uk Kim # string of joined values with $separator as the separator. 2957e71b7053SJung-uk Kim my $found_array = !defined($separator); 2958e71b7053SJung-uk Kim 2959e71b7053SJung-uk Kim my @values = 2960e71b7053SJung-uk Kim map { 2961e71b7053SJung-uk Kim my $res = $_; 2962e71b7053SJung-uk Kim while (ref($res) eq "CODE") { 2963e71b7053SJung-uk Kim $res = $res->(); 2964e71b7053SJung-uk Kim } 2965e71b7053SJung-uk Kim if (defined($res)) { 2966e71b7053SJung-uk Kim if (ref($res) eq "ARRAY") { 2967e71b7053SJung-uk Kim $found_array = 1; 2968e71b7053SJung-uk Kim @$res; 2969e71b7053SJung-uk Kim } else { 2970e71b7053SJung-uk Kim $res; 2971e71b7053SJung-uk Kim } 2972e71b7053SJung-uk Kim } else { 2973e71b7053SJung-uk Kim (); 2974e71b7053SJung-uk Kim } 2975e71b7053SJung-uk Kim } (@_); 2976e71b7053SJung-uk Kim 2977e71b7053SJung-uk Kim $add_called = 1; 2978e71b7053SJung-uk Kim 2979e71b7053SJung-uk Kim if ($found_array) { 2980e71b7053SJung-uk Kim [ @values ]; 2981e71b7053SJung-uk Kim } else { 2982e71b7053SJung-uk Kim join($separator, grep { defined($_) && $_ ne "" } @values); 2983e71b7053SJung-uk Kim } 2984e71b7053SJung-uk Kim} 2985e71b7053SJung-uk Kimsub add_before { 2986e71b7053SJung-uk Kim my $separator = " "; 2987e71b7053SJung-uk Kim if (ref($_[$#_]) eq "HASH") { 2988e71b7053SJung-uk Kim my $opts = pop; 2989e71b7053SJung-uk Kim $separator = $opts->{separator}; 2990e71b7053SJung-uk Kim } 2991e71b7053SJung-uk Kim my @x = @_; 2992e71b7053SJung-uk Kim sub { _add($separator, @x, @_) }; 2993e71b7053SJung-uk Kim} 2994e71b7053SJung-uk Kimsub add { 2995e71b7053SJung-uk Kim my $separator = " "; 2996e71b7053SJung-uk Kim if (ref($_[$#_]) eq "HASH") { 2997e71b7053SJung-uk Kim my $opts = pop; 2998e71b7053SJung-uk Kim $separator = $opts->{separator}; 2999e71b7053SJung-uk Kim } 3000e71b7053SJung-uk Kim my @x = @_; 3001e71b7053SJung-uk Kim sub { _add($separator, @_, @x) }; 3002e71b7053SJung-uk Kim} 3003e71b7053SJung-uk Kim 3004e71b7053SJung-uk Kimsub read_eval_file { 3005e71b7053SJung-uk Kim my $fname = shift; 3006e71b7053SJung-uk Kim my $content; 3007e71b7053SJung-uk Kim my @result; 3008e71b7053SJung-uk Kim 3009e71b7053SJung-uk Kim open F, "< $fname" or die "Can't open '$fname': $!\n"; 3010e71b7053SJung-uk Kim { 3011e71b7053SJung-uk Kim undef local $/; 3012e71b7053SJung-uk Kim $content = <F>; 3013e71b7053SJung-uk Kim } 3014e71b7053SJung-uk Kim close F; 3015e71b7053SJung-uk Kim { 3016e71b7053SJung-uk Kim local $@; 3017e71b7053SJung-uk Kim 3018e71b7053SJung-uk Kim @result = ( eval $content ); 3019e71b7053SJung-uk Kim warn $@ if $@; 3020e71b7053SJung-uk Kim } 3021e71b7053SJung-uk Kim return wantarray ? @result : $result[0]; 3022e71b7053SJung-uk Kim} 3023e71b7053SJung-uk Kim 3024e71b7053SJung-uk Kim# configuration reader, evaluates the input file as a perl script and expects 3025e71b7053SJung-uk Kim# it to fill %targets with target configurations. Those are then added to 3026e71b7053SJung-uk Kim# %table. 3027e71b7053SJung-uk Kimsub read_config { 3028e71b7053SJung-uk Kim my $fname = shift; 3029e71b7053SJung-uk Kim my %targets; 3030e71b7053SJung-uk Kim 3031e71b7053SJung-uk Kim { 3032e71b7053SJung-uk Kim # Protect certain tables from tampering 3033e71b7053SJung-uk Kim local %table = (); 3034e71b7053SJung-uk Kim 3035e71b7053SJung-uk Kim %targets = read_eval_file($fname); 3036e71b7053SJung-uk Kim } 3037e71b7053SJung-uk Kim my %preexisting = (); 3038e71b7053SJung-uk Kim foreach (sort keys %targets) { 3039e71b7053SJung-uk Kim $preexisting{$_} = 1 if $table{$_}; 3040e71b7053SJung-uk Kim } 3041e71b7053SJung-uk Kim die <<"EOF", 3042e71b7053SJung-uk KimThe following config targets from $fname 3043e71b7053SJung-uk Kimshadow pre-existing config targets with the same name: 3044e71b7053SJung-uk KimEOF 3045e71b7053SJung-uk Kim map { " $_\n" } sort keys %preexisting 3046e71b7053SJung-uk Kim if %preexisting; 3047e71b7053SJung-uk Kim 3048e71b7053SJung-uk Kim 3049e71b7053SJung-uk Kim # For each target, check that it's configured with a hash table. 3050e71b7053SJung-uk Kim foreach (keys %targets) { 3051e71b7053SJung-uk Kim if (ref($targets{$_}) ne "HASH") { 3052e71b7053SJung-uk Kim if (ref($targets{$_}) eq "") { 3053e71b7053SJung-uk Kim warn "Deprecated target configuration for $_, ignoring...\n"; 3054e71b7053SJung-uk Kim } else { 3055e71b7053SJung-uk Kim warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n"; 3056e71b7053SJung-uk Kim } 3057e71b7053SJung-uk Kim delete $targets{$_}; 3058e71b7053SJung-uk Kim } else { 3059e71b7053SJung-uk Kim $targets{$_}->{_conf_fname_int} = add([ $fname ]); 3060e71b7053SJung-uk Kim } 3061e71b7053SJung-uk Kim } 3062e71b7053SJung-uk Kim 3063e71b7053SJung-uk Kim %table = (%table, %targets); 3064e71b7053SJung-uk Kim 3065e71b7053SJung-uk Kim} 3066e71b7053SJung-uk Kim 3067e71b7053SJung-uk Kim# configuration resolver. Will only resolve all the lazy evaluation 3068e71b7053SJung-uk Kim# codeblocks for the chosen target and all those it inherits from, 3069e71b7053SJung-uk Kim# recursively 3070e71b7053SJung-uk Kimsub resolve_config { 3071e71b7053SJung-uk Kim my $target = shift; 3072e71b7053SJung-uk Kim my @breadcrumbs = @_; 3073e71b7053SJung-uk Kim 3074e71b7053SJung-uk Kim# my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS}); 3075e71b7053SJung-uk Kim 3076e71b7053SJung-uk Kim if (grep { $_ eq $target } @breadcrumbs) { 3077e71b7053SJung-uk Kim die "inherit_from loop! target backtrace:\n " 3078e71b7053SJung-uk Kim ,$target,"\n ",join("\n ", @breadcrumbs),"\n"; 3079e71b7053SJung-uk Kim } 3080e71b7053SJung-uk Kim 3081e71b7053SJung-uk Kim if (!defined($table{$target})) { 3082e71b7053SJung-uk Kim warn "Warning! target $target doesn't exist!\n"; 3083e71b7053SJung-uk Kim return (); 3084e71b7053SJung-uk Kim } 3085e71b7053SJung-uk Kim # Recurse through all inheritances. They will be resolved on the 3086e71b7053SJung-uk Kim # fly, so when this operation is done, they will all just be a 3087e71b7053SJung-uk Kim # bunch of attributes with string values. 3088e71b7053SJung-uk Kim # What we get here, though, are keys with references to lists of 3089e71b7053SJung-uk Kim # the combined values of them all. We will deal with lists after 3090e71b7053SJung-uk Kim # this stage is done. 3091e71b7053SJung-uk Kim my %combined_inheritance = (); 3092e71b7053SJung-uk Kim if ($table{$target}->{inherit_from}) { 3093e71b7053SJung-uk Kim my @inherit_from = 3094e71b7053SJung-uk Kim map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}}; 3095e71b7053SJung-uk Kim foreach (@inherit_from) { 3096e71b7053SJung-uk Kim my %inherited_config = resolve_config($_, $target, @breadcrumbs); 3097e71b7053SJung-uk Kim 3098e71b7053SJung-uk Kim # 'template' is a marker that's considered private to 3099e71b7053SJung-uk Kim # the config that had it. 3100e71b7053SJung-uk Kim delete $inherited_config{template}; 3101e71b7053SJung-uk Kim 3102e71b7053SJung-uk Kim foreach (keys %inherited_config) { 3103e71b7053SJung-uk Kim if (!$combined_inheritance{$_}) { 3104e71b7053SJung-uk Kim $combined_inheritance{$_} = []; 3105e71b7053SJung-uk Kim } 3106e71b7053SJung-uk Kim push @{$combined_inheritance{$_}}, $inherited_config{$_}; 3107e71b7053SJung-uk Kim } 3108e71b7053SJung-uk Kim } 3109e71b7053SJung-uk Kim } 3110e71b7053SJung-uk Kim 3111e71b7053SJung-uk Kim # We won't need inherit_from in this target any more, since we've 3112e71b7053SJung-uk Kim # resolved all the inheritances that lead to this 3113e71b7053SJung-uk Kim delete $table{$target}->{inherit_from}; 3114e71b7053SJung-uk Kim 3115e71b7053SJung-uk Kim # Now is the time to deal with those lists. Here's the place to 3116e71b7053SJung-uk Kim # decide what shall be done with those lists, all based on the 3117e71b7053SJung-uk Kim # values of the target we're currently dealing with. 3118e71b7053SJung-uk Kim # - If a value is a coderef, it will be executed with the list of 3119e71b7053SJung-uk Kim # inherited values as arguments. 3120e71b7053SJung-uk Kim # - If the corresponding key doesn't have a value at all or is the 3121e71b7053SJung-uk Kim # empty string, the inherited value list will be run through the 3122e71b7053SJung-uk Kim # default combiner (below), and the result becomes this target's 3123e71b7053SJung-uk Kim # value. 3124e71b7053SJung-uk Kim # - Otherwise, this target's value is assumed to be a string that 3125e71b7053SJung-uk Kim # will simply override the inherited list of values. 3126e71b7053SJung-uk Kim my $default_combiner = add(); 3127e71b7053SJung-uk Kim 3128e71b7053SJung-uk Kim my %all_keys = 3129e71b7053SJung-uk Kim map { $_ => 1 } (keys %combined_inheritance, 3130e71b7053SJung-uk Kim keys %{$table{$target}}); 3131e71b7053SJung-uk Kim 3132e71b7053SJung-uk Kim sub process_values { 3133e71b7053SJung-uk Kim my $object = shift; 3134e71b7053SJung-uk Kim my $inherited = shift; # Always a [ list ] 3135e71b7053SJung-uk Kim my $target = shift; 3136e71b7053SJung-uk Kim my $entry = shift; 3137e71b7053SJung-uk Kim 3138e71b7053SJung-uk Kim $add_called = 0; 3139e71b7053SJung-uk Kim 3140e71b7053SJung-uk Kim while(ref($object) eq "CODE") { 3141e71b7053SJung-uk Kim $object = $object->(@$inherited); 3142e71b7053SJung-uk Kim } 3143e71b7053SJung-uk Kim if (!defined($object)) { 3144e71b7053SJung-uk Kim return (); 3145e71b7053SJung-uk Kim } 3146e71b7053SJung-uk Kim elsif (ref($object) eq "ARRAY") { 3147e71b7053SJung-uk Kim local $add_called; # To make sure recursive calls don't affect it 3148e71b7053SJung-uk Kim return [ map { process_values($_, $inherited, $target, $entry) } 3149e71b7053SJung-uk Kim @$object ]; 3150e71b7053SJung-uk Kim } elsif (ref($object) eq "") { 3151e71b7053SJung-uk Kim return $object; 3152e71b7053SJung-uk Kim } else { 3153e71b7053SJung-uk Kim die "cannot handle reference type ",ref($object) 3154e71b7053SJung-uk Kim ," found in target ",$target," -> ",$entry,"\n"; 3155e71b7053SJung-uk Kim } 3156e71b7053SJung-uk Kim } 3157e71b7053SJung-uk Kim 3158e71b7053SJung-uk Kim foreach (sort keys %all_keys) { 3159e71b7053SJung-uk Kim my $previous = $combined_inheritance{$_}; 3160e71b7053SJung-uk Kim 3161e71b7053SJung-uk Kim # Current target doesn't have a value for the current key? 3162e71b7053SJung-uk Kim # Assign it the default combiner, the rest of this loop body 3163e71b7053SJung-uk Kim # will handle it just like any other coderef. 3164e71b7053SJung-uk Kim if (!exists $table{$target}->{$_}) { 3165e71b7053SJung-uk Kim $table{$target}->{$_} = $default_combiner; 3166e71b7053SJung-uk Kim } 3167e71b7053SJung-uk Kim 3168e71b7053SJung-uk Kim $table{$target}->{$_} = process_values($table{$target}->{$_}, 3169e71b7053SJung-uk Kim $combined_inheritance{$_}, 3170e71b7053SJung-uk Kim $target, $_); 3171e71b7053SJung-uk Kim unless(defined($table{$target}->{$_})) { 3172e71b7053SJung-uk Kim delete $table{$target}->{$_}; 3173e71b7053SJung-uk Kim } 3174e71b7053SJung-uk Kim# if ($extra_checks && 3175e71b7053SJung-uk Kim# $previous && !($add_called || $previous ~~ $table{$target}->{$_})) { 3176e71b7053SJung-uk Kim# warn "$_ got replaced in $target\n"; 3177e71b7053SJung-uk Kim# } 3178e71b7053SJung-uk Kim } 3179e71b7053SJung-uk Kim 3180e71b7053SJung-uk Kim # Finally done, return the result. 3181e71b7053SJung-uk Kim return %{$table{$target}}; 3182e71b7053SJung-uk Kim} 3183e71b7053SJung-uk Kim 318474664626SKris Kennawaysub usage 318574664626SKris Kennaway { 318674664626SKris Kennaway print STDERR $usage; 3187f579bf8eSKris Kennaway print STDERR "\npick os/compiler from:\n"; 318874664626SKris Kennaway my $j=0; 318974664626SKris Kennaway my $i; 3190f579bf8eSKris Kennaway my $k=0; 319174664626SKris Kennaway foreach $i (sort keys %table) 319274664626SKris Kennaway { 3193e71b7053SJung-uk Kim next if $table{$i}->{template}; 319474664626SKris Kennaway next if $i =~ /^debug/; 3195f579bf8eSKris Kennaway $k += length($i) + 1; 3196f579bf8eSKris Kennaway if ($k > 78) 3197f579bf8eSKris Kennaway { 3198f579bf8eSKris Kennaway print STDERR "\n"; 3199f579bf8eSKris Kennaway $k=length($i); 3200f579bf8eSKris Kennaway } 3201f579bf8eSKris Kennaway print STDERR $i . " "; 320274664626SKris Kennaway } 320374664626SKris Kennaway foreach $i (sort keys %table) 320474664626SKris Kennaway { 3205e71b7053SJung-uk Kim next if $table{$i}->{template}; 320674664626SKris Kennaway next if $i !~ /^debug/; 3207f579bf8eSKris Kennaway $k += length($i) + 1; 3208f579bf8eSKris Kennaway if ($k > 78) 3209f579bf8eSKris Kennaway { 321074664626SKris Kennaway print STDERR "\n"; 3211f579bf8eSKris Kennaway $k=length($i); 3212f579bf8eSKris Kennaway } 3213f579bf8eSKris Kennaway print STDERR $i . " "; 3214f579bf8eSKris Kennaway } 3215f579bf8eSKris Kennaway print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n"; 321674664626SKris Kennaway exit(1); 321774664626SKris Kennaway } 321874664626SKris Kennaway 3219e71b7053SJung-uk Kimsub run_dofile 3220e71b7053SJung-uk Kim{ 3221e71b7053SJung-uk Kim my $out = shift; 3222e71b7053SJung-uk Kim my @templates = @_; 3223e71b7053SJung-uk Kim 3224e71b7053SJung-uk Kim unlink $out || warn "Can't remove $out, $!" 3225e71b7053SJung-uk Kim if -f $out; 3226e71b7053SJung-uk Kim foreach (@templates) { 3227e71b7053SJung-uk Kim die "Can't open $_, $!" unless -f $_; 3228e71b7053SJung-uk Kim } 3229e71b7053SJung-uk Kim my $perlcmd = (quotify("maybeshell", $config{PERL}))[0]; 3230e71b7053SJung-uk Kim my $cmd = "$perlcmd \"-I.\" \"-Mconfigdata\" \"$dofile\" -o\"Configure\" \"".join("\" \"",@templates)."\" > \"$out.new\""; 3231e71b7053SJung-uk Kim #print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n"; 3232e71b7053SJung-uk Kim system($cmd); 3233e71b7053SJung-uk Kim exit 1 if $? != 0; 3234e71b7053SJung-uk Kim rename("$out.new", $out) || die "Can't rename $out.new, $!"; 3235e71b7053SJung-uk Kim} 3236e71b7053SJung-uk Kim 3237e71b7053SJung-uk Kimsub compiler_predefined { 3238e71b7053SJung-uk Kim state %predefined; 3239e71b7053SJung-uk Kim my $cc = shift; 3240e71b7053SJung-uk Kim 3241e71b7053SJung-uk Kim return () if $^O eq 'VMS'; 3242e71b7053SJung-uk Kim 3243e71b7053SJung-uk Kim die 'compiler_predefined called without a compiler command' 3244e71b7053SJung-uk Kim unless $cc; 3245e71b7053SJung-uk Kim 3246e71b7053SJung-uk Kim if (! $predefined{$cc}) { 3247e71b7053SJung-uk Kim 3248e71b7053SJung-uk Kim $predefined{$cc} = {}; 3249e71b7053SJung-uk Kim 3250e71b7053SJung-uk Kim # collect compiler pre-defines from gcc or gcc-alike... 3251e71b7053SJung-uk Kim open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |"); 3252e71b7053SJung-uk Kim while (my $l = <PIPE>) { 3253e71b7053SJung-uk Kim $l =~ m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last; 3254e71b7053SJung-uk Kim $predefined{$cc}->{$1} = $2 // ''; 3255e71b7053SJung-uk Kim } 3256e71b7053SJung-uk Kim close(PIPE); 3257e71b7053SJung-uk Kim } 3258e71b7053SJung-uk Kim 3259e71b7053SJung-uk Kim return %{$predefined{$cc}}; 3260e71b7053SJung-uk Kim} 3261e71b7053SJung-uk Kim 326274664626SKris Kennawaysub which 326374664626SKris Kennaway{ 326474664626SKris Kennaway my ($name)=@_; 3265e71b7053SJung-uk Kim 3266e71b7053SJung-uk Kim if (eval { require IPC::Cmd; 1; }) { 3267e71b7053SJung-uk Kim IPC::Cmd->import(); 3268e71b7053SJung-uk Kim return scalar IPC::Cmd::can_run($name); 3269e71b7053SJung-uk Kim } else { 3270e71b7053SJung-uk Kim # if there is $directories component in splitpath, 3271e71b7053SJung-uk Kim # then it's not something to test with $PATH... 3272e71b7053SJung-uk Kim return $name if (File::Spec->splitpath($name))[1]; 3273e71b7053SJung-uk Kim 3274e71b7053SJung-uk Kim foreach (File::Spec->path()) { 3275e71b7053SJung-uk Kim my $fullpath = catfile($_, "$name$target{exe_extension}"); 3276e71b7053SJung-uk Kim if (-f $fullpath and -x $fullpath) { 3277e71b7053SJung-uk Kim return $fullpath; 3278e71b7053SJung-uk Kim } 327974664626SKris Kennaway } 328074664626SKris Kennaway } 328174664626SKris Kennaway} 328274664626SKris Kennaway 3283e71b7053SJung-uk Kimsub env 328474664626SKris Kennaway{ 3285e71b7053SJung-uk Kim my $name = shift; 3286e71b7053SJung-uk Kim my %opts = @_; 328774664626SKris Kennaway 3288e71b7053SJung-uk Kim unless ($opts{cacheonly}) { 3289e71b7053SJung-uk Kim # Note that if $ENV{$name} doesn't exist or is undefined, 3290e71b7053SJung-uk Kim # $config{perlenv}->{$name} will be created with the value 3291e71b7053SJung-uk Kim # undef. This is intentional. 3292e71b7053SJung-uk Kim 3293e71b7053SJung-uk Kim $config{perlenv}->{$name} = $ENV{$name} 3294e71b7053SJung-uk Kim if ! exists $config{perlenv}->{$name}; 329574664626SKris Kennaway } 3296e71b7053SJung-uk Kim return $config{perlenv}->{$name}; 329774664626SKris Kennaway} 329874664626SKris Kennaway 3299e71b7053SJung-uk Kim# Configuration printer ############################################## 3300e71b7053SJung-uk Kim 330174664626SKris Kennawaysub print_table_entry 330274664626SKris Kennaway{ 3303e71b7053SJung-uk Kim local $now_printing = shift; 3304e71b7053SJung-uk Kim my %target = resolve_config($now_printing); 3305e71b7053SJung-uk Kim my $type = shift; 330674664626SKris Kennaway 3307e71b7053SJung-uk Kim # Don't print the templates 3308e71b7053SJung-uk Kim return if $target{template}; 330974664626SKris Kennaway 3310e71b7053SJung-uk Kim my @sequence = ( 3311e71b7053SJung-uk Kim "sys_id", 3312e71b7053SJung-uk Kim "cpp", 3313e71b7053SJung-uk Kim "cppflags", 3314e71b7053SJung-uk Kim "defines", 3315e71b7053SJung-uk Kim "includes", 3316e71b7053SJung-uk Kim "cc", 3317e71b7053SJung-uk Kim "cflags", 3318e71b7053SJung-uk Kim "unistd", 3319e71b7053SJung-uk Kim "ld", 3320e71b7053SJung-uk Kim "lflags", 3321e71b7053SJung-uk Kim "loutflag", 3322e71b7053SJung-uk Kim "ex_libs", 3323e71b7053SJung-uk Kim "bn_ops", 3324e71b7053SJung-uk Kim "apps_aux_src", 3325e71b7053SJung-uk Kim "cpuid_asm_src", 3326e71b7053SJung-uk Kim "uplink_aux_src", 3327e71b7053SJung-uk Kim "bn_asm_src", 3328e71b7053SJung-uk Kim "ec_asm_src", 3329e71b7053SJung-uk Kim "des_asm_src", 3330e71b7053SJung-uk Kim "aes_asm_src", 3331e71b7053SJung-uk Kim "bf_asm_src", 3332e71b7053SJung-uk Kim "md5_asm_src", 3333e71b7053SJung-uk Kim "cast_asm_src", 3334e71b7053SJung-uk Kim "sha1_asm_src", 3335e71b7053SJung-uk Kim "rc4_asm_src", 3336e71b7053SJung-uk Kim "rmd160_asm_src", 3337e71b7053SJung-uk Kim "rc5_asm_src", 3338e71b7053SJung-uk Kim "wp_asm_src", 3339e71b7053SJung-uk Kim "cmll_asm_src", 3340e71b7053SJung-uk Kim "modes_asm_src", 3341e71b7053SJung-uk Kim "padlock_asm_src", 3342e71b7053SJung-uk Kim "chacha_asm_src", 3343e71b7053SJung-uk Kim "poly1035_asm_src", 3344e71b7053SJung-uk Kim "thread_scheme", 3345e71b7053SJung-uk Kim "perlasm_scheme", 3346e71b7053SJung-uk Kim "dso_scheme", 3347e71b7053SJung-uk Kim "shared_target", 3348e71b7053SJung-uk Kim "shared_cflag", 3349e71b7053SJung-uk Kim "shared_defines", 3350e71b7053SJung-uk Kim "shared_ldflag", 3351e71b7053SJung-uk Kim "shared_rcflag", 3352e71b7053SJung-uk Kim "shared_extension", 3353e71b7053SJung-uk Kim "dso_extension", 3354e71b7053SJung-uk Kim "obj_extension", 3355e71b7053SJung-uk Kim "exe_extension", 3356e71b7053SJung-uk Kim "ranlib", 3357e71b7053SJung-uk Kim "ar", 3358e71b7053SJung-uk Kim "arflags", 3359e71b7053SJung-uk Kim "aroutflag", 3360e71b7053SJung-uk Kim "rc", 3361e71b7053SJung-uk Kim "rcflags", 3362e71b7053SJung-uk Kim "rcoutflag", 3363e71b7053SJung-uk Kim "mt", 3364e71b7053SJung-uk Kim "mtflags", 3365e71b7053SJung-uk Kim "mtinflag", 3366e71b7053SJung-uk Kim "mtoutflag", 3367e71b7053SJung-uk Kim "multilib", 3368e71b7053SJung-uk Kim "build_scheme", 3369e71b7053SJung-uk Kim ); 337074664626SKris Kennaway 3371e71b7053SJung-uk Kim if ($type eq "TABLE") { 3372e71b7053SJung-uk Kim print "\n"; 3373e71b7053SJung-uk Kim print "*** $now_printing\n"; 3374e71b7053SJung-uk Kim foreach (@sequence) { 3375e71b7053SJung-uk Kim if (ref($target{$_}) eq "ARRAY") { 3376e71b7053SJung-uk Kim printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}}); 3377e71b7053SJung-uk Kim } else { 3378e71b7053SJung-uk Kim printf "\$%-12s = %s\n", $_, $target{$_}; 3379c1803d78SJacques Vidrine } 3380c1803d78SJacques Vidrine } 3381e71b7053SJung-uk Kim } elsif ($type eq "HASH") { 3382e71b7053SJung-uk Kim my $largest = 3383e71b7053SJung-uk Kim length((sort { length($a) <=> length($b) } @sequence)[-1]); 3384e71b7053SJung-uk Kim print " '$now_printing' => {\n"; 3385e71b7053SJung-uk Kim foreach (@sequence) { 3386e71b7053SJung-uk Kim if ($target{$_}) { 3387e71b7053SJung-uk Kim if (ref($target{$_}) eq "ARRAY") { 3388e71b7053SJung-uk Kim print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n"; 3389e71b7053SJung-uk Kim } else { 3390e71b7053SJung-uk Kim print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n"; 3391e71b7053SJung-uk Kim } 3392e71b7053SJung-uk Kim } 3393e71b7053SJung-uk Kim } 3394e71b7053SJung-uk Kim print " },\n"; 3395e71b7053SJung-uk Kim } 3396c1803d78SJacques Vidrine} 33976cf8931aSJung-uk Kim 3398e71b7053SJung-uk Kim# Utility routines ################################################### 3399e71b7053SJung-uk Kim 3400e71b7053SJung-uk Kim# On VMS, if the given file is a logical name, File::Spec::Functions 3401e71b7053SJung-uk Kim# will consider it an absolute path. There are cases when we want a 3402e71b7053SJung-uk Kim# purely syntactic check without checking the environment. 3403e71b7053SJung-uk Kimsub isabsolute { 3404e71b7053SJung-uk Kim my $file = shift; 3405e71b7053SJung-uk Kim 3406e71b7053SJung-uk Kim # On non-platforms, we just use file_name_is_absolute(). 3407e71b7053SJung-uk Kim return file_name_is_absolute($file) unless $^O eq "VMS"; 3408e71b7053SJung-uk Kim 3409e71b7053SJung-uk Kim # If the file spec includes a device or a directory spec, 3410e71b7053SJung-uk Kim # file_name_is_absolute() is perfectly safe. 3411e71b7053SJung-uk Kim return file_name_is_absolute($file) if $file =~ m|[:\[]|; 3412e71b7053SJung-uk Kim 3413e71b7053SJung-uk Kim # Here, we know the given file spec isn't absolute 3414e71b7053SJung-uk Kim return 0; 3415e71b7053SJung-uk Kim} 3416e71b7053SJung-uk Kim 3417e71b7053SJung-uk Kim# Makes a directory absolute and cleans out /../ in paths like foo/../bar 3418e71b7053SJung-uk Kim# On some platforms, this uses rel2abs(), while on others, realpath() is used. 3419e71b7053SJung-uk Kim# realpath() requires that at least all path components except the last is an 3420e71b7053SJung-uk Kim# existing directory. On VMS, the last component of the directory spec must 3421e71b7053SJung-uk Kim# exist. 3422e71b7053SJung-uk Kimsub absolutedir { 3423e71b7053SJung-uk Kim my $dir = shift; 3424e71b7053SJung-uk Kim 3425e71b7053SJung-uk Kim # realpath() is quite buggy on VMS. It uses LIB$FID_TO_NAME, which 3426e71b7053SJung-uk Kim # will return the volume name for the device, no matter what. Also, 3427e71b7053SJung-uk Kim # it will return an incorrect directory spec if the argument is a 3428e71b7053SJung-uk Kim # directory that doesn't exist. 3429e71b7053SJung-uk Kim if ($^O eq "VMS") { 3430e71b7053SJung-uk Kim return rel2abs($dir); 3431e71b7053SJung-uk Kim } 3432e71b7053SJung-uk Kim 3433e71b7053SJung-uk Kim # We use realpath() on Unix, since no other will properly clean out 3434e71b7053SJung-uk Kim # a directory spec. 3435e71b7053SJung-uk Kim use Cwd qw/realpath/; 3436e71b7053SJung-uk Kim 3437e71b7053SJung-uk Kim return realpath($dir); 3438e71b7053SJung-uk Kim} 3439e71b7053SJung-uk Kim 3440*58f35182SJung-uk Kim# Check if all paths are one and the same, using stat. They must both exist 3441*58f35182SJung-uk Kim# We need this for the cases when File::Spec doesn't detect case insensitivity 3442*58f35182SJung-uk Kim# (File::Spec::Unix assumes case sensitivity) 3443*58f35182SJung-uk Kimsub samedir { 3444*58f35182SJung-uk Kim die "samedir expects two arguments\n" unless scalar @_ == 2; 3445*58f35182SJung-uk Kim 3446*58f35182SJung-uk Kim my @stat0 = stat($_[0]); # First argument 3447*58f35182SJung-uk Kim my @stat1 = stat($_[1]); # Second argument 3448*58f35182SJung-uk Kim 3449*58f35182SJung-uk Kim die "Couldn't stat $_[0]" unless @stat0; 3450*58f35182SJung-uk Kim die "Couldn't stat $_[1]" unless @stat1; 3451*58f35182SJung-uk Kim 3452*58f35182SJung-uk Kim # Compare device number 3453*58f35182SJung-uk Kim return 0 unless ($stat0[0] == $stat1[0]); 3454*58f35182SJung-uk Kim # Compare "inode". The perl manual recommends comparing as 3455*58f35182SJung-uk Kim # string rather than as number. 3456*58f35182SJung-uk Kim return 0 unless ($stat0[1] eq $stat1[1]); 3457*58f35182SJung-uk Kim 3458*58f35182SJung-uk Kim return 1; # All the same 3459*58f35182SJung-uk Kim} 3460*58f35182SJung-uk Kim 3461e71b7053SJung-uk Kimsub quotify { 3462e71b7053SJung-uk Kim my %processors = ( 3463e71b7053SJung-uk Kim perl => sub { my $x = shift; 3464e71b7053SJung-uk Kim $x =~ s/([\\\$\@"])/\\$1/g; 3465e71b7053SJung-uk Kim return '"'.$x.'"'; }, 3466e71b7053SJung-uk Kim maybeshell => sub { my $x = shift; 3467e71b7053SJung-uk Kim (my $y = $x) =~ s/([\\\"])/\\$1/g; 3468e71b7053SJung-uk Kim if ($x ne $y || $x =~ m|\s|) { 3469e71b7053SJung-uk Kim return '"'.$y.'"'; 3470e71b7053SJung-uk Kim } else { 3471e71b7053SJung-uk Kim return $x; 3472e71b7053SJung-uk Kim } 3473e71b7053SJung-uk Kim }, 3474e71b7053SJung-uk Kim ); 3475e71b7053SJung-uk Kim my $for = shift; 3476e71b7053SJung-uk Kim my $processor = 3477e71b7053SJung-uk Kim defined($processors{$for}) ? $processors{$for} : sub { shift; }; 3478e71b7053SJung-uk Kim 3479e71b7053SJung-uk Kim return map { $processor->($_); } @_; 3480e71b7053SJung-uk Kim} 3481e71b7053SJung-uk Kim 3482e71b7053SJung-uk Kim# collect_from_file($filename, $line_concat_cond_re, $line_concat) 3483e71b7053SJung-uk Kim# $filename is a file name to read from 3484e71b7053SJung-uk Kim# $line_concat_cond_re is a regexp detecting a line continuation ending 3485e71b7053SJung-uk Kim# $line_concat is a CODEref that takes care of concatenating two lines 3486e71b7053SJung-uk Kimsub collect_from_file { 3487e71b7053SJung-uk Kim my $filename = shift; 3488e71b7053SJung-uk Kim my $line_concat_cond_re = shift; 3489e71b7053SJung-uk Kim my $line_concat = shift; 3490e71b7053SJung-uk Kim 3491e71b7053SJung-uk Kim open my $fh, $filename || die "unable to read $filename: $!\n"; 3492e71b7053SJung-uk Kim return sub { 3493e71b7053SJung-uk Kim my $saved_line = ""; 3494e71b7053SJung-uk Kim $_ = ""; 3495e71b7053SJung-uk Kim while (<$fh>) { 3496e71b7053SJung-uk Kim s|\R$||; 3497e71b7053SJung-uk Kim if (defined $line_concat) { 3498e71b7053SJung-uk Kim $_ = $line_concat->($saved_line, $_); 3499e71b7053SJung-uk Kim $saved_line = ""; 3500e71b7053SJung-uk Kim } 3501e71b7053SJung-uk Kim if (defined $line_concat_cond_re && /$line_concat_cond_re/) { 3502e71b7053SJung-uk Kim $saved_line = $_; 3503e71b7053SJung-uk Kim next; 3504e71b7053SJung-uk Kim } 3505e71b7053SJung-uk Kim return $_; 3506e71b7053SJung-uk Kim } 3507e71b7053SJung-uk Kim die "$filename ending with continuation line\n" if $_; 3508e71b7053SJung-uk Kim close $fh; 3509e71b7053SJung-uk Kim return undef; 3510e71b7053SJung-uk Kim } 3511e71b7053SJung-uk Kim} 3512e71b7053SJung-uk Kim 3513e71b7053SJung-uk Kim# collect_from_array($array, $line_concat_cond_re, $line_concat) 3514e71b7053SJung-uk Kim# $array is an ARRAYref of lines 3515e71b7053SJung-uk Kim# $line_concat_cond_re is a regexp detecting a line continuation ending 3516e71b7053SJung-uk Kim# $line_concat is a CODEref that takes care of concatenating two lines 3517e71b7053SJung-uk Kimsub collect_from_array { 3518e71b7053SJung-uk Kim my $array = shift; 3519e71b7053SJung-uk Kim my $line_concat_cond_re = shift; 3520e71b7053SJung-uk Kim my $line_concat = shift; 3521e71b7053SJung-uk Kim my @array = (@$array); 3522e71b7053SJung-uk Kim 3523e71b7053SJung-uk Kim return sub { 3524e71b7053SJung-uk Kim my $saved_line = ""; 3525e71b7053SJung-uk Kim $_ = ""; 3526e71b7053SJung-uk Kim while (defined($_ = shift @array)) { 3527e71b7053SJung-uk Kim s|\R$||; 3528e71b7053SJung-uk Kim if (defined $line_concat) { 3529e71b7053SJung-uk Kim $_ = $line_concat->($saved_line, $_); 3530e71b7053SJung-uk Kim $saved_line = ""; 3531e71b7053SJung-uk Kim } 3532e71b7053SJung-uk Kim if (defined $line_concat_cond_re && /$line_concat_cond_re/) { 3533e71b7053SJung-uk Kim $saved_line = $_; 3534e71b7053SJung-uk Kim next; 3535e71b7053SJung-uk Kim } 3536e71b7053SJung-uk Kim return $_; 3537e71b7053SJung-uk Kim } 3538e71b7053SJung-uk Kim die "input text ending with continuation line\n" if $_; 3539e71b7053SJung-uk Kim return undef; 3540e71b7053SJung-uk Kim } 3541e71b7053SJung-uk Kim} 3542e71b7053SJung-uk Kim 3543e71b7053SJung-uk Kim# collect_information($lineiterator, $line_continue, $regexp => $CODEref, ...) 3544e71b7053SJung-uk Kim# $lineiterator is a CODEref that delivers one line at a time. 3545e71b7053SJung-uk Kim# All following arguments are regex/CODEref pairs, where the regexp detects a 3546e71b7053SJung-uk Kim# line and the CODEref does something with the result of the regexp. 3547e71b7053SJung-uk Kimsub collect_information { 3548e71b7053SJung-uk Kim my $lineiterator = shift; 3549e71b7053SJung-uk Kim my %collectors = @_; 3550e71b7053SJung-uk Kim 3551e71b7053SJung-uk Kim while(defined($_ = $lineiterator->())) { 3552e71b7053SJung-uk Kim s|\R$||; 3553e71b7053SJung-uk Kim my $found = 0; 3554e71b7053SJung-uk Kim if ($collectors{"BEFORE"}) { 3555e71b7053SJung-uk Kim $collectors{"BEFORE"}->($_); 3556e71b7053SJung-uk Kim } 3557e71b7053SJung-uk Kim foreach my $re (keys %collectors) { 3558e71b7053SJung-uk Kim if ($re !~ /^OTHERWISE|BEFORE|AFTER$/ && /$re/) { 3559e71b7053SJung-uk Kim $collectors{$re}->($lineiterator); 3560e71b7053SJung-uk Kim $found = 1; 3561e71b7053SJung-uk Kim }; 3562e71b7053SJung-uk Kim } 3563e71b7053SJung-uk Kim if ($collectors{"OTHERWISE"}) { 3564e71b7053SJung-uk Kim $collectors{"OTHERWISE"}->($lineiterator, $_) 3565e71b7053SJung-uk Kim unless $found || !defined $collectors{"OTHERWISE"}; 3566e71b7053SJung-uk Kim } 3567e71b7053SJung-uk Kim if ($collectors{"AFTER"}) { 3568e71b7053SJung-uk Kim $collectors{"AFTER"}->($_); 3569e71b7053SJung-uk Kim } 3570e71b7053SJung-uk Kim } 3571e71b7053SJung-uk Kim} 3572e71b7053SJung-uk Kim 3573e71b7053SJung-uk Kim# tokenize($line) 3574e71b7053SJung-uk Kim# $line is a line of text to split up into tokens 3575e71b7053SJung-uk Kim# returns a list of tokens 3576e71b7053SJung-uk Kim# 3577e71b7053SJung-uk Kim# Tokens are divided by spaces. If the tokens include spaces, they 3578e71b7053SJung-uk Kim# have to be quoted with single or double quotes. Double quotes 3579e71b7053SJung-uk Kim# inside a double quoted token must be escaped. Escaping is done 3580e71b7053SJung-uk Kim# with backslash. 3581e71b7053SJung-uk Kim# Basically, the same quoting rules apply for " and ' as in any 3582e71b7053SJung-uk Kim# Unix shell. 3583e71b7053SJung-uk Kimsub tokenize { 3584e71b7053SJung-uk Kim my $line = my $debug_line = shift; 3585e71b7053SJung-uk Kim my @result = (); 3586e71b7053SJung-uk Kim 3587e71b7053SJung-uk Kim while ($line =~ s|^\s+||, $line ne "") { 3588e71b7053SJung-uk Kim my $token = ""; 3589e71b7053SJung-uk Kim while ($line ne "" && $line !~ m|^\s|) { 3590e71b7053SJung-uk Kim if ($line =~ m/^"((?:[^"\\]+|\\.)*)"/) { 3591e71b7053SJung-uk Kim $token .= $1; 3592e71b7053SJung-uk Kim $line = $'; 3593e71b7053SJung-uk Kim } elsif ($line =~ m/^'([^']*)'/) { 3594e71b7053SJung-uk Kim $token .= $1; 3595e71b7053SJung-uk Kim $line = $'; 3596e71b7053SJung-uk Kim } elsif ($line =~ m/^(\S+)/) { 3597e71b7053SJung-uk Kim $token .= $1; 3598e71b7053SJung-uk Kim $line = $'; 3599e71b7053SJung-uk Kim } 3600e71b7053SJung-uk Kim } 3601e71b7053SJung-uk Kim push @result, $token; 3602e71b7053SJung-uk Kim } 3603e71b7053SJung-uk Kim 3604e71b7053SJung-uk Kim if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) { 3605e71b7053SJung-uk Kim print STDERR "DEBUG[tokenize]: Parsed '$debug_line' into:\n"; 3606e71b7053SJung-uk Kim print STDERR "DEBUG[tokenize]: ('", join("', '", @result), "')\n"; 3607e71b7053SJung-uk Kim } 3608e71b7053SJung-uk Kim return @result; 36096cf8931aSJung-uk Kim} 3610