1e71b7053SJung-uk Kim#! /usr/bin/env perl 2e71b7053SJung-uk Kim# -*- mode: perl; -*- 3*44096ebdSEnji Cooper# Copyright 2016-2024 The OpenSSL Project Authors. All Rights Reserved. 4e71b7053SJung-uk Kim# 5b077aed3SPierre Pronchery# Licensed under the Apache License 2.0 (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; 18b077aed3SPierre Proncheryuse File::Spec::Functions qw/:DEFAULT abs2rel rel2abs splitdir/; 19e71b7053SJung-uk Kimuse File::Path qw/mkpath/; 20b077aed3SPierre Proncheryuse OpenSSL::fallback "$FindBin::Bin/external/perl/MODULES.txt"; 21e71b7053SJung-uk Kimuse OpenSSL::Glob; 22b077aed3SPierre Proncheryuse OpenSSL::Template; 23b077aed3SPierre Proncheryuse OpenSSL::config; 2474664626SKris Kennaway 25b077aed3SPierre Pronchery# see INSTALL.md for instructions. 2674664626SKris Kennaway 27e71b7053SJung-uk Kimmy $orig_death_handler = $SIG{__DIE__}; 28e71b7053SJung-uk Kim$SIG{__DIE__} = \&death_handler; 29e71b7053SJung-uk Kim 30610a21fdSJung-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"; 3174664626SKris Kennaway 32b077aed3SPierre Proncherymy $banner = <<"EOF"; 33b077aed3SPierre Pronchery 34b077aed3SPierre Pronchery********************************************************************** 35b077aed3SPierre Pronchery*** *** 36b077aed3SPierre Pronchery*** OpenSSL has been successfully configured *** 37b077aed3SPierre Pronchery*** *** 38b077aed3SPierre Pronchery*** If you encounter a problem while building, please open an *** 39b077aed3SPierre Pronchery*** issue on GitHub <https://github.com/openssl/openssl/issues> *** 40b077aed3SPierre Pronchery*** and include the output from the following command: *** 41b077aed3SPierre Pronchery*** *** 42b077aed3SPierre Pronchery*** perl configdata.pm --dump *** 43b077aed3SPierre Pronchery*** *** 44b077aed3SPierre Pronchery*** (If you are new to OpenSSL, you might want to consult the *** 45b077aed3SPierre Pronchery*** 'Troubleshooting' section in the INSTALL.md file first) *** 46b077aed3SPierre Pronchery*** *** 47b077aed3SPierre Pronchery********************************************************************** 48b077aed3SPierre ProncheryEOF 49b077aed3SPierre Pronchery 5074664626SKris Kennaway# Options: 5174664626SKris Kennaway# 52e71b7053SJung-uk Kim# --config add the given configuration file, which will be read after 53e71b7053SJung-uk Kim# any "Configurations*" files that are found in the same 54e71b7053SJung-uk Kim# directory as this script. 55e71b7053SJung-uk Kim# --prefix prefix for the OpenSSL installation, which includes the 56e71b7053SJung-uk Kim# directories bin, lib, include, share/man, share/doc/openssl 57e71b7053SJung-uk Kim# This becomes the value of INSTALLTOP in Makefile 58e71b7053SJung-uk Kim# (Default: /usr/local) 59e71b7053SJung-uk Kim# --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys. 60e71b7053SJung-uk Kim# If it's a relative directory, it will be added on the directory 61e71b7053SJung-uk Kim# given with --prefix. 62e71b7053SJung-uk Kim# This becomes the value of OPENSSLDIR in Makefile and in C. 63e71b7053SJung-uk Kim# (Default: PREFIX/ssl) 64b077aed3SPierre Pronchery# --banner=".." Output specified text instead of default completion banner 65b077aed3SPierre Pronchery# 66b077aed3SPierre Pronchery# -w Don't wait after showing a Configure warning 67c1803d78SJacques Vidrine# 681f13597dSJung-uk Kim# --cross-compile-prefix Add specified prefix to binutils components. 691f13597dSJung-uk Kim# 70b077aed3SPierre Pronchery# --api One of 0.9.8, 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.1, or 3.0 71b077aed3SPierre Pronchery# Define the public APIs as they were for that version 72b077aed3SPierre Pronchery# including patch releases. If 'no-deprecated' is also 73b077aed3SPierre Pronchery# given, do not compile support for interfaces deprecated 74b077aed3SPierre Pronchery# up to and including the specified OpenSSL version. 75e71b7053SJung-uk Kim# 765c87c606SMark Murray# no-hw-xxx do not compile support for specific crypto hardware. 775c87c606SMark Murray# Generic OpenSSL-style methods relating to this support 785c87c606SMark Murray# are always compiled but return NULL if the hardware 795c87c606SMark Murray# support isn't compiled. 805c87c606SMark Murray# no-hw do not compile support for any crypto hardware. 8174664626SKris Kennaway# [no-]threads [don't] try to create a library that is suitable for 8274664626SKris Kennaway# multithreaded applications (default is "threads" if we 8374664626SKris Kennaway# know how to do it) 84ddd58736SKris Kennaway# [no-]shared [don't] try to create shared libraries when supported. 85e71b7053SJung-uk Kim# [no-]pic [don't] try to build position independent code when supported. 86e71b7053SJung-uk Kim# If disabled, it also disables shared and dynamic-engine. 8774664626SKris Kennaway# no-asm do not use assembler 88e71b7053SJung-uk Kim# no-egd do not compile support for the entropy-gathering daemon APIs 895c87c606SMark Murray# [no-]zlib [don't] compile support for zlib compression. 905c87c606SMark Murray# zlib-dynamic Like "zlib", but the zlib library is expected to be a shared 915c87c606SMark Murray# library and will be loaded in run-time by the OpenSSL library. 921f13597dSJung-uk Kim# sctp include SCTP support 93b077aed3SPierre Pronchery# no-uplink Don't build support for UPLINK interface. 944c6a0400SJung-uk Kim# enable-weak-ssl-ciphers 95e71b7053SJung-uk Kim# Enable weak ciphers that are disabled by default. 966cf8931aSJung-uk Kim# 386 generate 80386 code in assembly modules 976cf8931aSJung-uk Kim# no-sse2 disables IA-32 SSE2 code in assembly modules, the above 986cf8931aSJung-uk Kim# mentioned '386' option implies this one 99b077aed3SPierre Pronchery# no-<cipher> build without specified algorithm (dsa, idea, rc5, ...) 10017f01e99SJung-uk Kim# -<xxx> +<xxx> All options which are unknown to the 'Configure' script are 10117f01e99SJung-uk Kim# /<xxx> passed through to the compiler. Unix-style options beginning 10217f01e99SJung-uk Kim# with a '-' or '+' are recognized, as well as Windows-style 10317f01e99SJung-uk Kim# options beginning with a '/'. If the option contains arguments 10417f01e99SJung-uk Kim# separated by spaces, then the URL-style notation %20 can be 10517f01e99SJung-uk Kim# used for the space character in order to avoid having to quote 10617f01e99SJung-uk Kim# the option. For example, -opt%20arg gets expanded to -opt arg. 10717f01e99SJung-uk Kim# In fact, any ASCII character can be encoded as %xx using its 10817f01e99SJung-uk Kim# hexadecimal encoding. 109e71b7053SJung-uk Kim# -static while -static is also a pass-through compiler option (and 110e71b7053SJung-uk Kim# as such is limited to environments where it's actually 111e71b7053SJung-uk Kim# meaningful), it triggers a number configuration options, 112610a21fdSJung-uk Kim# namely no-pic, no-shared and no-threads. It is 113e71b7053SJung-uk Kim# argued that the only reason to produce statically linked 114e71b7053SJung-uk Kim# binaries (and in context it means executables linked with 115e71b7053SJung-uk Kim# -static flag, and not just executables linked with static 116e71b7053SJung-uk Kim# libcrypto.a) is to eliminate dependency on specific run-time, 117e71b7053SJung-uk Kim# a.k.a. libc version. The mentioned config options are meant 118e71b7053SJung-uk Kim# to achieve just that. Unfortunately on Linux it's impossible 119e71b7053SJung-uk Kim# to eliminate the dependency completely for openssl executable 120e71b7053SJung-uk Kim# because of getaddrinfo and gethostbyname calls, which can 121e71b7053SJung-uk Kim# invoke dynamically loadable library facility anyway to meet 122e71b7053SJung-uk Kim# the lookup requests. For this reason on Linux statically 123e71b7053SJung-uk Kim# linked openssl executable has rather debugging value than 124e71b7053SJung-uk Kim# production quality. 12574664626SKris Kennaway# 12674664626SKris Kennaway# BN_LLONG use the type 'long long' in crypto/bn/bn.h 12774664626SKris Kennaway# RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h 1283b4e3dcbSSimon L. B. Nielsen# Following are set automatically by this script 1293b4e3dcbSSimon L. B. Nielsen# 130e71b7053SJung-uk Kim# MD5_ASM use some extra md5 assembler, 131e71b7053SJung-uk Kim# SHA1_ASM use some extra sha1 assembler, must define L_ENDIAN for x86 132e71b7053SJung-uk Kim# RMD160_ASM use some extra ripemd160 assembler, 1333b4e3dcbSSimon L. B. Nielsen# SHA256_ASM sha256_block is implemented in assembler 1343b4e3dcbSSimon L. B. Nielsen# SHA512_ASM sha512_block is implemented in assembler 135e71b7053SJung-uk Kim# AES_ASM AES_[en|de]crypt is implemented in assembler 13674664626SKris Kennaway 137610a21fdSJung-uk Kim# Minimum warning options... any contributions to OpenSSL should at least 138610a21fdSJung-uk Kim# get past these. Note that we only use these with C compilers, not with 139610a21fdSJung-uk Kim# C++ compilers. 140db522d3aSSimon L. B. Nielsen 141e71b7053SJung-uk Kim# -DPEDANTIC complements -pedantic and is meant to mask code that 142e71b7053SJung-uk Kim# is not strictly standard-compliant and/or implementation-specific, 143e71b7053SJung-uk Kim# e.g. inline assembly, disregards to alignment requirements, such 144e71b7053SJung-uk Kim# that -pedantic would complain about. Incidentally -DPEDANTIC has 145e71b7053SJung-uk Kim# to be used even in sanitized builds, because sanitizer too is 146e71b7053SJung-uk Kim# supposed to and does take notice of non-standard behaviour. Then 147e71b7053SJung-uk Kim# -pedantic with pre-C9x compiler would also complain about 'long 148e71b7053SJung-uk Kim# long' not being supported. As 64-bit algorithms are common now, 149e71b7053SJung-uk Kim# it grew impossible to resolve this without sizeable additional 150e71b7053SJung-uk Kim# code, so we just tell compiler to be pedantic about everything 151e71b7053SJung-uk Kim# but 'long long' type. 152db522d3aSSimon L. B. Nielsen 153610a21fdSJung-uk Kimmy @gcc_devteam_warn = qw( 154b077aed3SPierre Pronchery -DPEDANTIC -pedantic -Wno-long-long -DUNUSEDRESULT_DEBUG 155610a21fdSJung-uk Kim -Wall 156b077aed3SPierre Pronchery -Wmissing-declarations 157610a21fdSJung-uk Kim -Wextra 158610a21fdSJung-uk Kim -Wno-unused-parameter 159610a21fdSJung-uk Kim -Wno-missing-field-initializers 160610a21fdSJung-uk Kim -Wswitch 161610a21fdSJung-uk Kim -Wsign-compare 162610a21fdSJung-uk Kim -Wshadow 163610a21fdSJung-uk Kim -Wformat 164610a21fdSJung-uk Kim -Wtype-limits 165610a21fdSJung-uk Kim -Wundef 166610a21fdSJung-uk Kim -Werror 167610a21fdSJung-uk Kim -Wmissing-prototypes 168610a21fdSJung-uk Kim -Wstrict-prototypes 169610a21fdSJung-uk Kim); 1707bded2dbSJung-uk Kim 1717bded2dbSJung-uk Kim# These are used in addition to $gcc_devteam_warn when the compiler is clang. 1727bded2dbSJung-uk Kim# TODO(openssl-team): fix problems and investigate if (at least) the 173e71b7053SJung-uk Kim# following warnings can also be enabled: 174e71b7053SJung-uk Kim# -Wcast-align 175e71b7053SJung-uk Kim# -Wunreachable-code -- no, too ugly/compiler-specific 176e71b7053SJung-uk Kim# -Wlanguage-extension-token -- no, we use asm() 177e71b7053SJung-uk Kim# -Wunused-macros -- no, too tricky for BN and _XOPEN_SOURCE etc 178e71b7053SJung-uk Kim# -Wextended-offsetof -- no, needed in CMS ASN1 code 179610a21fdSJung-uk Kimmy @clang_devteam_warn = qw( 180da327cd2SJung-uk Kim -Wno-unknown-warning-option 181610a21fdSJung-uk Kim -Wswitch-default 182610a21fdSJung-uk Kim -Wno-parentheses-equality 183610a21fdSJung-uk Kim -Wno-language-extension-token 184610a21fdSJung-uk Kim -Wno-extended-offsetof 185610a21fdSJung-uk Kim -Wconditional-uninitialized 186610a21fdSJung-uk Kim -Wincompatible-pointer-types-discards-qualifiers 187610a21fdSJung-uk Kim -Wmissing-variable-declarations 188610a21fdSJung-uk Kim); 1897bded2dbSJung-uk Kim 19017f01e99SJung-uk Kimmy @cl_devteam_warn = qw( 19117f01e99SJung-uk Kim /WX 19217f01e99SJung-uk Kim); 19317f01e99SJung-uk Kim 1946a599222SSimon L. B. Nielsenmy $strict_warnings = 0; 1956a599222SSimon L. B. Nielsen 1963b4e3dcbSSimon L. B. Nielsen# As for $BSDthreads. Idea is to maintain "collective" set of flags, 1973b4e3dcbSSimon L. B. Nielsen# which would cover all BSD flavors. -pthread applies to them all, 1983b4e3dcbSSimon L. B. Nielsen# but is treated differently. OpenBSD expands is as -D_POSIX_THREAD 1993b4e3dcbSSimon L. B. Nielsen# -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r, 2003b4e3dcbSSimon L. B. Nielsen# which has to be accompanied by explicit -D_THREAD_SAFE and 2013b4e3dcbSSimon L. B. Nielsen# sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which 2023b4e3dcbSSimon L. B. Nielsen# seems to be sufficient? 203e71b7053SJung-uk Kimour $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT"; 20474664626SKris Kennaway 20574664626SKris Kennaway# 206e71b7053SJung-uk Kim# API compatibility name to version number mapping. 20774664626SKris Kennaway# 208e71b7053SJung-uk Kimmy $apitable = { 209b077aed3SPierre Pronchery # This table expresses when API additions or changes can occur. 210b077aed3SPierre Pronchery # The numbering used changes from 3.0 and on because we updated 211b077aed3SPierre Pronchery # (solidified) our version numbering scheme at that point. 212b077aed3SPierre Pronchery 213b077aed3SPierre Pronchery # From 3.0 and on, we internalise the given version number in decimal 214b077aed3SPierre Pronchery # as MAJOR * 10000 + MINOR * 100 + 0 215b077aed3SPierre Pronchery "3.0.0" => 30000, 216b077aed3SPierre Pronchery "3.0" => 30000, 217b077aed3SPierre Pronchery 218b077aed3SPierre Pronchery # Note that before 3.0, we didn't have the same version number scheme. 219b077aed3SPierre Pronchery # Still, the numbering we use here covers what we need. 220b077aed3SPierre Pronchery "1.1.1" => 10101, 221b077aed3SPierre Pronchery "1.1.0" => 10100, 222b077aed3SPierre Pronchery "1.0.2" => 10002, 223b077aed3SPierre Pronchery "1.0.1" => 10001, 224b077aed3SPierre Pronchery "1.0.0" => 10000, 225b077aed3SPierre Pronchery "0.9.8" => 908, 226e71b7053SJung-uk Kim}; 227e71b7053SJung-uk Kim 228b077aed3SPierre Pronchery# For OpenSSL::config::get_platform 229b077aed3SPierre Proncherymy %guess_opts = (); 230b077aed3SPierre Pronchery 231b077aed3SPierre Proncherymy $dryrun = 0; 232b077aed3SPierre Pronchery 233e71b7053SJung-uk Kimour %table = (); 234e71b7053SJung-uk Kimour %config = (); 235e71b7053SJung-uk Kimour %withargs = (); 236e71b7053SJung-uk Kimour $now_printing; # set to current entry's name in print_table_entry 237e71b7053SJung-uk Kim # (todo: right thing would be to encapsulate name 238e71b7053SJung-uk Kim # into %target [class] and make print_table_entry 239e71b7053SJung-uk Kim # a method) 240e71b7053SJung-uk Kim 241e71b7053SJung-uk Kim# Forward declarations ############################################### 242e71b7053SJung-uk Kim 243e71b7053SJung-uk Kim# read_config(filename) 244c1803d78SJacques Vidrine# 245e71b7053SJung-uk Kim# Reads a configuration file and populates %table with the contents 246e71b7053SJung-uk Kim# (which the configuration file places in %targets). 247e71b7053SJung-uk Kimsub read_config; 24874664626SKris Kennaway 249e71b7053SJung-uk Kim# resolve_config(target) 25074664626SKris Kennaway# 251e71b7053SJung-uk Kim# Resolves all the late evaluations, inheritances and so on for the 252e71b7053SJung-uk Kim# chosen target and any target it inherits from. 253e71b7053SJung-uk Kimsub resolve_config; 25474664626SKris Kennaway 25574664626SKris Kennaway 256e71b7053SJung-uk Kim# Information collection ############################################# 25774664626SKris Kennaway 258e71b7053SJung-uk Kim# Unified build supports separate build dir 259e71b7053SJung-uk Kimmy $srcdir = catdir(absolutedir(dirname($0))); # catdir ensures local syntax 260e71b7053SJung-uk Kimmy $blddir = catdir(absolutedir(".")); # catdir ensures local syntax 26158f35182SJung-uk Kim 26258f35182SJung-uk Kim# File::Spec::Unix doesn't detect case insensitivity, so we make sure to 26358f35182SJung-uk Kim# check if the source and build directory are really the same, and make 26458f35182SJung-uk Kim# them so. This avoids all kinds of confusion later on. 26558f35182SJung-uk Kim# We must check @File::Spec::ISA rather than using File::Spec->isa() to 26658f35182SJung-uk Kim# know if File::Spec ended up loading File::Spec::Unix. 26758f35182SJung-uk Kim$srcdir = $blddir 26858f35182SJung-uk Kim if (grep(/::Unix$/, @File::Spec::ISA) 26958f35182SJung-uk Kim && samedir($srcdir, $blddir)); 27058f35182SJung-uk Kim 271e71b7053SJung-uk Kimmy $dofile = abs2rel(catfile($srcdir, "util/dofile.pl")); 27274664626SKris Kennaway 273e71b7053SJung-uk Kimmy $local_config_envname = 'OPENSSL_LOCAL_CONFIG_DIR'; 274a21b1b38SKris Kennaway 27558f35182SJung-uk Kim$config{sourcedir} = abs2rel($srcdir, $blddir); 27658f35182SJung-uk Kim$config{builddir} = abs2rel($blddir, $blddir); 277b077aed3SPierre Pronchery# echo -n 'holy hand grenade of antioch' | openssl sha256 278b077aed3SPierre Pronchery$config{FIPSKEY} = 279b077aed3SPierre Pronchery 'f4556650ac31d35461610bac4ed81b1a181b2d8a43ea2854cbae22ca74560813'; 28074664626SKris Kennaway 281e71b7053SJung-uk Kim# Collect reconfiguration information if needed 282e71b7053SJung-uk Kimmy @argvcopy=@ARGV; 28374664626SKris Kennaway 284e71b7053SJung-uk Kimif (grep /^reconf(igure)?$/, @argvcopy) { 285e71b7053SJung-uk Kim die "reconfiguring with other arguments present isn't supported" 286e71b7053SJung-uk Kim if scalar @argvcopy > 1; 287e71b7053SJung-uk Kim if (-f "./configdata.pm") { 288e71b7053SJung-uk Kim my $file = "./configdata.pm"; 289e71b7053SJung-uk Kim unless (my $return = do $file) { 290e71b7053SJung-uk Kim die "couldn't parse $file: $@" if $@; 291e71b7053SJung-uk Kim die "couldn't do $file: $!" unless defined $return; 292e71b7053SJung-uk Kim die "couldn't run $file" unless $return; 2931f13597dSJung-uk Kim } 2943b4e3dcbSSimon L. B. Nielsen 295e71b7053SJung-uk Kim @argvcopy = defined($configdata::config{perlargv}) ? 296e71b7053SJung-uk Kim @{$configdata::config{perlargv}} : (); 297e71b7053SJung-uk Kim die "Incorrect data to reconfigure, please do a normal configuration\n" 298e71b7053SJung-uk Kim if (grep(/^reconf/,@argvcopy)); 299e71b7053SJung-uk Kim $config{perlenv} = $configdata::config{perlenv} // {}; 300e71b7053SJung-uk Kim } else { 301e71b7053SJung-uk Kim die "Insufficient data to reconfigure, please do a normal configuration\n"; 302e71b7053SJung-uk Kim } 303e71b7053SJung-uk Kim} 3043b4e3dcbSSimon L. B. Nielsen 305e71b7053SJung-uk Kim$config{perlargv} = [ @argvcopy ]; 306e71b7053SJung-uk Kim 307b077aed3SPierre Pronchery# Historical: if known directories in crypto/ have been removed, it means 308b077aed3SPierre Pronchery# that those sub-systems are disabled. 309b077aed3SPierre Pronchery# (the other option would be to removed them from the SUBDIRS statement in 310b077aed3SPierre Pronchery# crypto/build.info) 311b077aed3SPierre Pronchery# We reverse the input list for cosmetic purely reasons, to compensate that 312b077aed3SPierre Pronchery# 'unshift' adds at the front of the list (i.e. in reverse input order). 313b077aed3SPierre Proncheryforeach ( reverse sort( 'aes', 'aria', 'bf', 'camellia', 'cast', 'des', 'dh', 314b077aed3SPierre Pronchery 'dsa', 'ec', 'hmac', 'idea', 'md2', 'md5', 'mdc2', 315b077aed3SPierre Pronchery 'rc2', 'rc4', 'rc5', 'ripemd', 'seed', 'sha', 316b077aed3SPierre Pronchery 'sm2', 'sm3', 'sm4') ) { 317b077aed3SPierre Pronchery unshift @argvcopy, "no-$_" if ! -d catdir($srcdir, 'crypto', $_); 318b077aed3SPierre Pronchery} 319b077aed3SPierre Pronchery 320e71b7053SJung-uk Kim# Collect version numbers 321b077aed3SPierre Proncherymy %version = (); 322e71b7053SJung-uk Kim 323e71b7053SJung-uk Kimcollect_information( 324b077aed3SPierre Pronchery collect_from_file(catfile($srcdir,'VERSION.dat')), 325b077aed3SPierre Pronchery qr/\s*(\w+)\s*=\s*(.*?)\s*$/ => 326b077aed3SPierre Pronchery sub { 327b077aed3SPierre Pronchery # Only define it if there is a value at all 328b077aed3SPierre Pronchery if ($2 ne '') { 329b077aed3SPierre Pronchery my $k = $1; 330b077aed3SPierre Pronchery my $v = $2; 331b077aed3SPierre Pronchery # Some values are quoted. Trim the quotes 332b077aed3SPierre Pronchery $v = $1 if $v =~ /^"(.*)"$/; 333b077aed3SPierre Pronchery $version{uc $k} = $v; 334b077aed3SPierre Pronchery } 335b077aed3SPierre Pronchery }, 336b077aed3SPierre Pronchery "OTHERWISE" => 337b077aed3SPierre Pronchery sub { die "Something wrong with this line:\n$_\nin $srcdir/VERSION.dat" }, 338e71b7053SJung-uk Kim ); 339e71b7053SJung-uk Kim 340b077aed3SPierre Pronchery$config{major} = $version{MAJOR} // 'unknown'; 341b077aed3SPierre Pronchery$config{minor} = $version{MINOR} // 'unknown'; 342b077aed3SPierre Pronchery$config{patch} = $version{PATCH} // 'unknown'; 343b077aed3SPierre Pronchery$config{prerelease} = 344b077aed3SPierre Pronchery defined $version{PRE_RELEASE_TAG} ? "-$version{PRE_RELEASE_TAG}" : ''; 345b077aed3SPierre Pronchery$config{build_metadata} = 346b077aed3SPierre Pronchery defined $version{BUILD_METADATA} ? "+$version{BUILD_METADATA}" : ''; 347b077aed3SPierre Pronchery$config{shlib_version} = $version{SHLIB_VERSION} // 'unknown'; 348b077aed3SPierre Pronchery$config{release_date} = $version{RELEASE_DATE} // 'xx XXX xxxx'; 349b077aed3SPierre Pronchery 350b077aed3SPierre Pronchery$config{version} = "$config{major}.$config{minor}.$config{patch}"; 351b077aed3SPierre Pronchery$config{full_version} = "$config{version}$config{prerelease}$config{build_metadata}"; 352b077aed3SPierre Pronchery 353b077aed3SPierre Proncherydie "erroneous version information in VERSION.dat: ", 354b077aed3SPierre Pronchery "$config{version}, $config{shlib_version}\n" 355b077aed3SPierre Pronchery unless (defined $version{MAJOR} 356b077aed3SPierre Pronchery && defined $version{MINOR} 357b077aed3SPierre Pronchery && defined $version{PATCH} 358b077aed3SPierre Pronchery && defined $version{SHLIB_VERSION}); 359e71b7053SJung-uk Kim 360e71b7053SJung-uk Kim# Collect target configurations 361e71b7053SJung-uk Kim 362e71b7053SJung-uk Kimmy $pattern = catfile(dirname($0), "Configurations", "*.conf"); 363e71b7053SJung-uk Kimforeach (sort glob($pattern)) { 364e71b7053SJung-uk Kim &read_config($_); 365e71b7053SJung-uk Kim} 366e71b7053SJung-uk Kim 367e71b7053SJung-uk Kimif (defined env($local_config_envname)) { 368e71b7053SJung-uk Kim if ($^O eq 'VMS') { 369e71b7053SJung-uk Kim # VMS environment variables are logical names, 370e71b7053SJung-uk Kim # which can be used as is 371e71b7053SJung-uk Kim $pattern = $local_config_envname . ':' . '*.conf'; 372e71b7053SJung-uk Kim } else { 373e71b7053SJung-uk Kim $pattern = catfile(env($local_config_envname), '*.conf'); 374e71b7053SJung-uk Kim } 375e71b7053SJung-uk Kim 376e71b7053SJung-uk Kim foreach (sort glob($pattern)) { 377e71b7053SJung-uk Kim &read_config($_); 378e71b7053SJung-uk Kim } 379e71b7053SJung-uk Kim} 380e71b7053SJung-uk Kim 381e71b7053SJung-uk Kim# Save away perl command information 382e71b7053SJung-uk Kim$config{perl_cmd} = $^X; 383e71b7053SJung-uk Kim$config{perl_version} = $Config{version}; 384e71b7053SJung-uk Kim$config{perl_archname} = $Config{archname}; 385e71b7053SJung-uk Kim 386e71b7053SJung-uk Kim$config{prefix}=""; 387e71b7053SJung-uk Kim$config{openssldir}=""; 388e71b7053SJung-uk Kim$config{processor}=""; 389e71b7053SJung-uk Kim$config{libdir}=""; 390e71b7053SJung-uk Kimmy $auto_threads=1; # enable threads automatically? true by default 391e71b7053SJung-uk Kimmy $default_ranlib; 392e71b7053SJung-uk Kim 393e71b7053SJung-uk Kim# Known TLS and DTLS protocols 394e71b7053SJung-uk Kimmy @tls = qw(ssl3 tls1 tls1_1 tls1_2 tls1_3); 395e71b7053SJung-uk Kimmy @dtls = qw(dtls1 dtls1_2); 396e71b7053SJung-uk Kim 397e71b7053SJung-uk Kim# Explicitly known options that are possible to disable. They can 398e71b7053SJung-uk Kim# be regexps, and will be used like this: /^no-${option}$/ 399e71b7053SJung-uk Kim# For developers: keep it sorted alphabetically 400e71b7053SJung-uk Kim 401e71b7053SJung-uk Kimmy @disablables = ( 402b077aed3SPierre Pronchery "acvp-tests", 403e71b7053SJung-uk Kim "afalgeng", 404e71b7053SJung-uk Kim "aria", 405e71b7053SJung-uk Kim "asan", 406e71b7053SJung-uk Kim "asm", 407e71b7053SJung-uk Kim "async", 408*44096ebdSEnji Cooper "atexit", 409e71b7053SJung-uk Kim "autoalginit", 410e71b7053SJung-uk Kim "autoerrinit", 411e71b7053SJung-uk Kim "autoload-config", 412e71b7053SJung-uk Kim "bf", 413e71b7053SJung-uk Kim "blake2", 414b077aed3SPierre Pronchery "buildtest-c++", 415b077aed3SPierre Pronchery "bulk", 416b077aed3SPierre Pronchery "cached-fetch", 417e71b7053SJung-uk Kim "camellia", 418e71b7053SJung-uk Kim "capieng", 419e71b7053SJung-uk Kim "cast", 420e71b7053SJung-uk Kim "chacha", 421e71b7053SJung-uk Kim "cmac", 422b077aed3SPierre Pronchery "cmp", 423e71b7053SJung-uk Kim "cms", 424e71b7053SJung-uk Kim "comp", 425e71b7053SJung-uk Kim "crypto-mdebug", 426e71b7053SJung-uk Kim "ct", 427e71b7053SJung-uk Kim "deprecated", 428e71b7053SJung-uk Kim "des", 429e71b7053SJung-uk Kim "devcryptoeng", 430e71b7053SJung-uk Kim "dgram", 431e71b7053SJung-uk Kim "dh", 432e71b7053SJung-uk Kim "dsa", 43317f01e99SJung-uk Kim "dso", 434e71b7053SJung-uk Kim "dtls", 435e71b7053SJung-uk Kim "dynamic-engine", 436e71b7053SJung-uk Kim "ec", 437e71b7053SJung-uk Kim "ec2m", 438b077aed3SPierre Pronchery "ec_nistp_64_gcc_128", 439e71b7053SJung-uk Kim "ecdh", 440e71b7053SJung-uk Kim "ecdsa", 441e71b7053SJung-uk Kim "egd", 442e71b7053SJung-uk Kim "engine", 443e71b7053SJung-uk Kim "err", 444e71b7053SJung-uk Kim "external-tests", 445e71b7053SJung-uk Kim "filenames", 446b077aed3SPierre Pronchery "fips", 447b077aed3SPierre Pronchery "fips-securitychecks", 448e71b7053SJung-uk Kim "fuzz-afl", 449b077aed3SPierre Pronchery "fuzz-libfuzzer", 450e71b7053SJung-uk Kim "gost", 451e71b7053SJung-uk Kim "idea", 452aa906e2aSJohn Baldwin "ktls", 453b077aed3SPierre Pronchery "legacy", 454b077aed3SPierre Pronchery "loadereng", 455e71b7053SJung-uk Kim "makedepend", 456e71b7053SJung-uk Kim "md2", 457e71b7053SJung-uk Kim "md4", 458e71b7053SJung-uk Kim "mdc2", 459b077aed3SPierre Pronchery "module", 460e71b7053SJung-uk Kim "msan", 461e71b7053SJung-uk Kim "multiblock", 462e71b7053SJung-uk Kim "nextprotoneg", 463e71b7053SJung-uk Kim "ocb", 464e71b7053SJung-uk Kim "ocsp", 465b077aed3SPierre Pronchery "padlockeng", 466e71b7053SJung-uk Kim "pic", 467b077aed3SPierre Pronchery "pinshared", 468e71b7053SJung-uk Kim "poly1305", 469e71b7053SJung-uk Kim "posix-io", 470e71b7053SJung-uk Kim "psk", 471e71b7053SJung-uk Kim "rc2", 472e71b7053SJung-uk Kim "rc4", 473e71b7053SJung-uk Kim "rc5", 474e71b7053SJung-uk Kim "rdrand", 475e71b7053SJung-uk Kim "rfc3779", 476e71b7053SJung-uk Kim "rmd160", 477e71b7053SJung-uk Kim "scrypt", 478e71b7053SJung-uk Kim "sctp", 479b077aed3SPierre Pronchery "secure-memory", 480e71b7053SJung-uk Kim "seed", 481e71b7053SJung-uk Kim "shared", 482e71b7053SJung-uk Kim "siphash", 483b077aed3SPierre Pronchery "siv", 484e71b7053SJung-uk Kim "sm2", 485e71b7053SJung-uk Kim "sm3", 486e71b7053SJung-uk Kim "sm4", 487e71b7053SJung-uk Kim "sock", 488e71b7053SJung-uk Kim "srp", 489e71b7053SJung-uk Kim "srtp", 490e71b7053SJung-uk Kim "sse2", 491e71b7053SJung-uk Kim "ssl", 492e71b7053SJung-uk Kim "ssl-trace", 493e71b7053SJung-uk Kim "static-engine", 494e71b7053SJung-uk Kim "stdio", 495e71b7053SJung-uk Kim "tests", 496e71b7053SJung-uk Kim "threads", 497e71b7053SJung-uk Kim "tls", 498b077aed3SPierre Pronchery "trace", 499e71b7053SJung-uk Kim "ts", 500e71b7053SJung-uk Kim "ubsan", 501e71b7053SJung-uk Kim "ui-console", 502e71b7053SJung-uk Kim "unit-test", 503b077aed3SPierre Pronchery "uplink", 504e71b7053SJung-uk Kim "weak-ssl-ciphers", 505b077aed3SPierre Pronchery "whirlpool", 506e71b7053SJung-uk Kim "zlib", 507e71b7053SJung-uk Kim "zlib-dynamic", 508e71b7053SJung-uk Kim ); 509e71b7053SJung-uk Kimforeach my $proto ((@tls, @dtls)) 510e71b7053SJung-uk Kim { 511e71b7053SJung-uk Kim push(@disablables, $proto); 512e71b7053SJung-uk Kim push(@disablables, "$proto-method") unless $proto eq "tls1_3"; 513e71b7053SJung-uk Kim } 514e71b7053SJung-uk Kim 515b077aed3SPierre Pronchery# Internal disablables, for aliasing purposes. They serve no special 516b077aed3SPierre Pronchery# purpose here, but allow scripts to get to know them through configdata.pm, 517b077aed3SPierre Pronchery# where these are merged with @disablables. 518b077aed3SPierre Pronchery# The actual aliasing mechanism is done via %disable_cascades 519b077aed3SPierre Proncherymy @disablables_int = qw( 520b077aed3SPierre Pronchery crmf 521b077aed3SPierre Pronchery ); 522b077aed3SPierre Pronchery 523e71b7053SJung-uk Kimmy %deprecated_disablables = ( 524e71b7053SJung-uk Kim "ssl2" => undef, 525e71b7053SJung-uk Kim "buf-freelists" => undef, 526b077aed3SPierre Pronchery "crypto-mdebug-backtrace" => undef, 527b077aed3SPierre Pronchery "hw" => "hw", # causes cascade, but no macro 528b077aed3SPierre Pronchery "hw-padlock" => "padlockeng", 529e71b7053SJung-uk Kim "ripemd" => "rmd160", 530e71b7053SJung-uk Kim "ui" => "ui-console", 531b077aed3SPierre Pronchery "heartbeats" => undef, 532e71b7053SJung-uk Kim ); 533e71b7053SJung-uk Kim 534e71b7053SJung-uk Kim# All of the following are disabled by default: 535e71b7053SJung-uk Kim 536e71b7053SJung-uk Kimour %disabled = ( # "what" => "comment" 537b077aed3SPierre Pronchery "fips" => "default", 538e71b7053SJung-uk Kim "asan" => "default", 539610a21fdSJung-uk Kim "buildtest-c++" => "default", 540e71b7053SJung-uk Kim "crypto-mdebug" => "default", 541e71b7053SJung-uk Kim "crypto-mdebug-backtrace" => "default", 542e71b7053SJung-uk Kim "devcryptoeng" => "default", 5431f13597dSJung-uk Kim "ec_nistp_64_gcc_128" => "default", 544e71b7053SJung-uk Kim "egd" => "default", 545e71b7053SJung-uk Kim "external-tests" => "default", 546e71b7053SJung-uk Kim "fuzz-afl" => "default", 547b077aed3SPierre Pronchery "fuzz-libfuzzer" => "default", 548b077aed3SPierre Pronchery "ktls" => "default", 5491f13597dSJung-uk Kim "md2" => "default", 550e71b7053SJung-uk Kim "msan" => "default", 5513b4e3dcbSSimon L. B. Nielsen "rc5" => "default", 5521f13597dSJung-uk Kim "sctp" => "default", 553e71b7053SJung-uk Kim "ssl3" => "default", 554e71b7053SJung-uk Kim "ssl3-method" => "default", 555b077aed3SPierre Pronchery "trace" => "default", 556e71b7053SJung-uk Kim "ubsan" => "default", 557a93cbc2bSJung-uk Kim "unit-test" => "default", 5584c6a0400SJung-uk Kim "weak-ssl-ciphers" => "default", 5593b4e3dcbSSimon L. B. Nielsen "zlib" => "default", 560e71b7053SJung-uk Kim "zlib-dynamic" => "default", 5613b4e3dcbSSimon L. B. Nielsen ); 5623b4e3dcbSSimon L. B. Nielsen 563e71b7053SJung-uk Kim# Note: => pair form used for aesthetics, not to truly make a hash table 564e71b7053SJung-uk Kimmy @disable_cascades = ( 565e71b7053SJung-uk Kim # "what" => [ "cascade", ... ] 566b077aed3SPierre Pronchery "bulk" => [ "shared", "dso", 567b077aed3SPierre Pronchery "aria", "async", "autoload-config", 568b077aed3SPierre Pronchery "blake2", "bf", "camellia", "cast", "chacha", 569b077aed3SPierre Pronchery "cmac", "cms", "cmp", "comp", "ct", 570b077aed3SPierre Pronchery "des", "dgram", "dh", "dsa", 571b077aed3SPierre Pronchery "ec", "engine", 572b077aed3SPierre Pronchery "filenames", 573b077aed3SPierre Pronchery "idea", "ktls", 574b077aed3SPierre Pronchery "md4", "multiblock", "nextprotoneg", 575b077aed3SPierre Pronchery "ocsp", "ocb", "poly1305", "psk", 576b077aed3SPierre Pronchery "rc2", "rc4", "rmd160", 577b077aed3SPierre Pronchery "seed", "siphash", "siv", 578b077aed3SPierre Pronchery "sm3", "sm4", "srp", 579b077aed3SPierre Pronchery "srtp", "ssl3-method", "ssl-trace", 580b077aed3SPierre Pronchery "ts", "ui-console", "whirlpool", 581b077aed3SPierre Pronchery "fips-securitychecks" ], 582e71b7053SJung-uk Kim sub { $config{processor} eq "386" } 583e71b7053SJung-uk Kim => [ "sse2" ], 584e71b7053SJung-uk Kim "ssl" => [ "ssl3" ], 585e71b7053SJung-uk Kim "ssl3-method" => [ "ssl3" ], 586e71b7053SJung-uk Kim "zlib" => [ "zlib-dynamic" ], 587e71b7053SJung-uk Kim "des" => [ "mdc2" ], 588b077aed3SPierre Pronchery "ec" => [ "ec2m", "ecdsa", "ecdh", "sm2", "gost" ], 589e71b7053SJung-uk Kim "dgram" => [ "dtls", "sctp" ], 590e71b7053SJung-uk Kim "sock" => [ "dgram" ], 591e71b7053SJung-uk Kim "dtls" => [ @dtls ], 592e71b7053SJung-uk Kim sub { 0 == scalar grep { !$disabled{$_} } @dtls } 593e71b7053SJung-uk Kim => [ "dtls" ], 594e71b7053SJung-uk Kim 595e71b7053SJung-uk Kim "tls" => [ @tls ], 596e71b7053SJung-uk Kim sub { 0 == scalar grep { !$disabled{$_} } @tls } 597e71b7053SJung-uk Kim => [ "tls" ], 598e71b7053SJung-uk Kim 599e71b7053SJung-uk Kim "crypto-mdebug" => [ "crypto-mdebug-backtrace" ], 600e71b7053SJung-uk Kim 601aa795734SPierre Pronchery "module" => [ "dynamic-engine", "fips" ], 602b077aed3SPierre Pronchery 603b077aed3SPierre Pronchery # Without shared libraries, dynamic engines aren't possible. 604b077aed3SPierre Pronchery # This is due to them having to link with libcrypto and register features 605b077aed3SPierre Pronchery # using the ENGINE functionality, and since that relies on global tables, 606b077aed3SPierre Pronchery # those *have* to be exacty the same as the ones accessed from the app, 607b077aed3SPierre Pronchery # which cannot be guaranteed if shared libraries aren't present. 608b077aed3SPierre Pronchery # (note that even with shared libraries, both the app and dynamic engines 609b077aed3SPierre Pronchery # must be linked with the same library) 610b077aed3SPierre Pronchery "shared" => [ "dynamic-engine", "uplink" ], 611b077aed3SPierre Pronchery "dso" => [ "dynamic-engine", "module" ], 612b077aed3SPierre Pronchery # Other modules don't necessarily have to link with libcrypto, so shared 613b077aed3SPierre Pronchery # libraries do not have to be a condition to produce those. 614b077aed3SPierre Pronchery 615b077aed3SPierre Pronchery # Without position independent code, there can be no shared libraries 616b077aed3SPierre Pronchery # or modules. 617b077aed3SPierre Pronchery "pic" => [ "shared", "module" ], 618b077aed3SPierre Pronchery 619b077aed3SPierre Pronchery "engine" => [ "dynamic-engine", grep(/eng$/, @disablables) ], 620b077aed3SPierre Pronchery "dynamic-engine" => [ "loadereng" ], 621b077aed3SPierre Pronchery "hw" => [ "padlockeng" ], 622e71b7053SJung-uk Kim 623e71b7053SJung-uk Kim # no-autoalginit is only useful when building non-shared 624b077aed3SPierre Pronchery "autoalginit" => [ "shared", "apps", "fips" ], 625e71b7053SJung-uk Kim 626e71b7053SJung-uk Kim "stdio" => [ "apps", "capieng", "egd" ], 627e71b7053SJung-uk Kim "apps" => [ "tests" ], 628e71b7053SJung-uk Kim "tests" => [ "external-tests" ], 629e71b7053SJung-uk Kim "comp" => [ "zlib" ], 630e71b7053SJung-uk Kim "sm3" => [ "sm2" ], 631e71b7053SJung-uk Kim sub { !$disabled{"unit-test"} } => [ "heartbeats" ], 632e71b7053SJung-uk Kim 633e71b7053SJung-uk Kim sub { !$disabled{"msan"} } => [ "asm" ], 634b077aed3SPierre Pronchery 635b077aed3SPierre Pronchery "cmac" => [ "siv" ], 636b077aed3SPierre Pronchery "legacy" => [ "md2" ], 637b077aed3SPierre Pronchery 638b077aed3SPierre Pronchery "cmp" => [ "crmf" ], 639b077aed3SPierre Pronchery 640b077aed3SPierre Pronchery "fips" => [ "fips-securitychecks", "acvp-tests" ], 641b077aed3SPierre Pronchery 642b077aed3SPierre Pronchery "deprecated-3.0" => [ "engine", "srp" ] 643e71b7053SJung-uk Kim ); 644e71b7053SJung-uk Kim 645e71b7053SJung-uk Kim# Avoid protocol support holes. Also disable all versions below N, if version 646e71b7053SJung-uk Kim# N is disabled while N+1 is enabled. 647e71b7053SJung-uk Kim# 648e71b7053SJung-uk Kimmy @list = (reverse @tls); 649e71b7053SJung-uk Kimwhile ((my $first, my $second) = (shift @list, shift @list)) { 650e71b7053SJung-uk Kim last unless @list; 651e71b7053SJung-uk Kim push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} } 652e71b7053SJung-uk Kim => [ @list ] ); 653e71b7053SJung-uk Kim unshift @list, $second; 654e71b7053SJung-uk Kim} 655e71b7053SJung-uk Kimmy @list = (reverse @dtls); 656e71b7053SJung-uk Kimwhile ((my $first, my $second) = (shift @list, shift @list)) { 657e71b7053SJung-uk Kim last unless @list; 658e71b7053SJung-uk Kim push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} } 659e71b7053SJung-uk Kim => [ @list ] ); 660e71b7053SJung-uk Kim unshift @list, $second; 661e71b7053SJung-uk Kim} 662db522d3aSSimon L. B. Nielsen 663db522d3aSSimon L. B. Nielsen# Explicit "no-..." options will be collected in %disabled along with the defaults. 664e71b7053SJung-uk Kim# To remove something from %disabled, use "enable-foo". 665db522d3aSSimon L. B. Nielsen# For symmetry, "disable-foo" is a synonym for "no-foo". 666db522d3aSSimon L. B. Nielsen 66717f01e99SJung-uk Kim# For the "make variables" CPPINCLUDES and CPPDEFINES, we support lists with 668e71b7053SJung-uk Kim# platform specific list separators. Users from those platforms should 669e71b7053SJung-uk Kim# recognise those separators from how you set up the PATH to find executables. 670e71b7053SJung-uk Kim# The default is the Unix like separator, :, but as an exception, we also 671e71b7053SJung-uk Kim# support the space as separator. 672e71b7053SJung-uk Kimmy $list_separator_re = 673e71b7053SJung-uk Kim { VMS => qr/(?<!\^),/, 674e71b7053SJung-uk Kim MSWin32 => qr/(?<!\\);/ } -> {$^O} // qr/(?<!\\)[:\s]/; 675e71b7053SJung-uk Kim# All the "make variables" we support 676e71b7053SJung-uk Kim# Some get pre-populated for the sake of backward compatibility 677e71b7053SJung-uk Kim# (we supported those before the change to "make variable" support. 678e71b7053SJung-uk Kimmy %user = ( 679e71b7053SJung-uk Kim AR => env('AR'), 680e71b7053SJung-uk Kim ARFLAGS => [], 681e71b7053SJung-uk Kim AS => undef, 682e71b7053SJung-uk Kim ASFLAGS => [], 683e71b7053SJung-uk Kim CC => env('CC'), 684610a21fdSJung-uk Kim CFLAGS => [ env('CFLAGS') || () ], 685e71b7053SJung-uk Kim CXX => env('CXX'), 686610a21fdSJung-uk Kim CXXFLAGS => [ env('CXXFLAGS') || () ], 687e71b7053SJung-uk Kim CPP => undef, 688610a21fdSJung-uk Kim CPPFLAGS => [ env('CPPFLAGS') || () ], # -D, -I, -Wp, 689e71b7053SJung-uk Kim CPPDEFINES => [], # Alternative for -D 690e71b7053SJung-uk Kim CPPINCLUDES => [], # Alternative for -I 691e71b7053SJung-uk Kim CROSS_COMPILE => env('CROSS_COMPILE'), 692e71b7053SJung-uk Kim HASHBANGPERL=> env('HASHBANGPERL') || env('PERL'), 693e71b7053SJung-uk Kim LD => undef, 694610a21fdSJung-uk Kim LDFLAGS => [ env('LDFLAGS') || () ], # -L, -Wl, 695610a21fdSJung-uk Kim LDLIBS => [ env('LDLIBS') || () ], # -l 696e71b7053SJung-uk Kim MT => undef, 697e71b7053SJung-uk Kim MTFLAGS => [], 698e71b7053SJung-uk Kim PERL => env('PERL') || ($^O ne "VMS" ? $^X : "perl"), 699e71b7053SJung-uk Kim RANLIB => env('RANLIB'), 700e71b7053SJung-uk Kim RC => env('RC') || env('WINDRES'), 701610a21fdSJung-uk Kim RCFLAGS => [ env('RCFLAGS') || () ], 702e71b7053SJung-uk Kim RM => undef, 703e71b7053SJung-uk Kim ); 704e71b7053SJung-uk Kim# Info about what "make variables" may be prefixed with the cross compiler 705e71b7053SJung-uk Kim# prefix. This should NEVER mention any such variable with a list for value. 706e71b7053SJung-uk Kimmy @user_crossable = qw ( AR AS CC CXX CPP LD MT RANLIB RC ); 707e71b7053SJung-uk Kim# The same but for flags given as Configure options. These are *additional* 708e71b7053SJung-uk Kim# input, as opposed to the VAR=string option that override the corresponding 709e71b7053SJung-uk Kim# config target attributes 710e71b7053SJung-uk Kimmy %useradd = ( 711e71b7053SJung-uk Kim CPPDEFINES => [], 712e71b7053SJung-uk Kim CPPINCLUDES => [], 713e71b7053SJung-uk Kim CPPFLAGS => [], 714e71b7053SJung-uk Kim CFLAGS => [], 715e71b7053SJung-uk Kim CXXFLAGS => [], 716e71b7053SJung-uk Kim LDFLAGS => [], 717e71b7053SJung-uk Kim LDLIBS => [], 718610a21fdSJung-uk Kim RCFLAGS => [], 719e71b7053SJung-uk Kim ); 720ddd58736SKris Kennaway 721e71b7053SJung-uk Kimmy %user_synonyms = ( 722e71b7053SJung-uk Kim HASHBANGPERL=> 'PERL', 723e71b7053SJung-uk Kim RC => 'WINDRES', 724e71b7053SJung-uk Kim ); 725ddd58736SKris Kennaway 726e71b7053SJung-uk Kim# Some target attributes have been renamed, this is the translation table 727e71b7053SJung-uk Kimmy %target_attr_translate =( 728e71b7053SJung-uk Kim ar => 'AR', 729e71b7053SJung-uk Kim as => 'AS', 730e71b7053SJung-uk Kim cc => 'CC', 731e71b7053SJung-uk Kim cxx => 'CXX', 732e71b7053SJung-uk Kim cpp => 'CPP', 733e71b7053SJung-uk Kim hashbangperl => 'HASHBANGPERL', 734e71b7053SJung-uk Kim ld => 'LD', 735e71b7053SJung-uk Kim mt => 'MT', 736e71b7053SJung-uk Kim ranlib => 'RANLIB', 737e71b7053SJung-uk Kim rc => 'RC', 738e71b7053SJung-uk Kim rm => 'RM', 739e71b7053SJung-uk Kim ); 740e71b7053SJung-uk Kim 741e71b7053SJung-uk Kim# Initialisers coming from 'config' scripts 742e71b7053SJung-uk Kim$config{defines} = [ split(/$list_separator_re/, env('__CNF_CPPDEFINES')) ]; 743e71b7053SJung-uk Kim$config{includes} = [ split(/$list_separator_re/, env('__CNF_CPPINCLUDES')) ]; 744e71b7053SJung-uk Kim$config{cppflags} = [ env('__CNF_CPPFLAGS') || () ]; 745e71b7053SJung-uk Kim$config{cflags} = [ env('__CNF_CFLAGS') || () ]; 746e71b7053SJung-uk Kim$config{cxxflags} = [ env('__CNF_CXXFLAGS') || () ]; 747e71b7053SJung-uk Kim$config{lflags} = [ env('__CNF_LDFLAGS') || () ]; 748e71b7053SJung-uk Kim$config{ex_libs} = [ env('__CNF_LDLIBS') || () ]; 749e71b7053SJung-uk Kim 750e71b7053SJung-uk Kim$config{openssl_api_defines}=[]; 751e71b7053SJung-uk Kim$config{openssl_sys_defines}=[]; 752b077aed3SPierre Pronchery$config{openssl_feature_defines}=[]; 753e71b7053SJung-uk Kim$config{options}=""; 754e71b7053SJung-uk Kim$config{build_type} = "release"; 755e71b7053SJung-uk Kimmy $target=""; 756e71b7053SJung-uk Kim 757e71b7053SJung-uk Kimmy %cmdvars = (); # Stores FOO='blah' type arguments 758e71b7053SJung-uk Kimmy %unsupported_options = (); 759e71b7053SJung-uk Kimmy %deprecated_options = (); 760e71b7053SJung-uk Kim# If you change this, update apps/version.c 761e71b7053SJung-uk Kimmy @known_seed_sources = qw(getrandom devrandom os egd none rdcpu librandom); 762e71b7053SJung-uk Kimmy @seed_sources = (); 763e71b7053SJung-uk Kimwhile (@argvcopy) 764ddd58736SKris Kennaway { 765e71b7053SJung-uk Kim $_ = shift @argvcopy; 766ddd58736SKris Kennaway 767e71b7053SJung-uk Kim # Support env variable assignments among the options 768e71b7053SJung-uk Kim if (m|^(\w+)=(.+)?$|) 76974664626SKris Kennaway { 770e71b7053SJung-uk Kim $cmdvars{$1} = $2; 771e71b7053SJung-uk Kim # Every time a variable is given as a configuration argument, 772e71b7053SJung-uk Kim # it acts as a reset if the variable. 773e71b7053SJung-uk Kim if (exists $user{$1}) 774e71b7053SJung-uk Kim { 775e71b7053SJung-uk Kim $user{$1} = ref $user{$1} eq "ARRAY" ? [] : undef; 776e71b7053SJung-uk Kim } 777e71b7053SJung-uk Kim #if (exists $useradd{$1}) 778e71b7053SJung-uk Kim # { 779e71b7053SJung-uk Kim # $useradd{$1} = []; 780e71b7053SJung-uk Kim # } 781e71b7053SJung-uk Kim next; 782e71b7053SJung-uk Kim } 783e71b7053SJung-uk Kim 784e71b7053SJung-uk Kim # VMS is a case insensitive environment, and depending on settings 785e71b7053SJung-uk Kim # out of our control, we may receive options uppercased. Let's 786e71b7053SJung-uk Kim # downcase at least the part before any equal sign. 787e71b7053SJung-uk Kim if ($^O eq "VMS") 788e71b7053SJung-uk Kim { 789e71b7053SJung-uk Kim s/^([^=]*)/lc($1)/e; 790e71b7053SJung-uk Kim } 791e71b7053SJung-uk Kim 792e71b7053SJung-uk Kim # some people just can't read the instructions, clang people have to... 793e71b7053SJung-uk Kim s/^-no-(?!integrated-as)/no-/; 7943b4e3dcbSSimon L. B. Nielsen 7953b4e3dcbSSimon L. B. Nielsen # rewrite some options in "enable-..." form 7963b4e3dcbSSimon L. B. Nielsen s /^-?-?shared$/enable-shared/; 7971f13597dSJung-uk Kim s /^sctp$/enable-sctp/; 7983b4e3dcbSSimon L. B. Nielsen s /^threads$/enable-threads/; 7993b4e3dcbSSimon L. B. Nielsen s /^zlib$/enable-zlib/; 8003b4e3dcbSSimon L. B. Nielsen s /^zlib-dynamic$/enable-zlib-dynamic/; 801b077aed3SPierre Pronchery s /^fips$/enable-fips/; 8023b4e3dcbSSimon L. B. Nielsen 803e71b7053SJung-uk Kim if (/^(no|disable|enable)-(.+)$/) 804e71b7053SJung-uk Kim { 805e71b7053SJung-uk Kim my $word = $2; 806b077aed3SPierre Pronchery if ($word !~ m|hw(?:-.+)| # special treatment for hw regexp opt 807b077aed3SPierre Pronchery && !exists $deprecated_disablables{$word} 808b077aed3SPierre Pronchery && !grep { $word eq $_ } @disablables) 809e71b7053SJung-uk Kim { 810e71b7053SJung-uk Kim $unsupported_options{$_} = 1; 811e71b7053SJung-uk Kim next; 812e71b7053SJung-uk Kim } 813e71b7053SJung-uk Kim } 8143b4e3dcbSSimon L. B. Nielsen if (/^no-(.+)$/ || /^disable-(.+)$/) 8153b4e3dcbSSimon L. B. Nielsen { 816e71b7053SJung-uk Kim foreach my $proto ((@tls, @dtls)) 817db522d3aSSimon L. B. Nielsen { 818e71b7053SJung-uk Kim if ($1 eq "$proto-method") 8193b4e3dcbSSimon L. B. Nielsen { 820e71b7053SJung-uk Kim $disabled{"$proto"} = "option($proto-method)"; 821e71b7053SJung-uk Kim last; 822e71b7053SJung-uk Kim } 823e71b7053SJung-uk Kim } 824e71b7053SJung-uk Kim if ($1 eq "dtls") 825e71b7053SJung-uk Kim { 826e71b7053SJung-uk Kim foreach my $proto (@dtls) 827e71b7053SJung-uk Kim { 828e71b7053SJung-uk Kim $disabled{$proto} = "option(dtls)"; 829e71b7053SJung-uk Kim } 830e71b7053SJung-uk Kim $disabled{"dtls"} = "option(dtls)"; 831e71b7053SJung-uk Kim } 832e71b7053SJung-uk Kim elsif ($1 eq "ssl") 833e71b7053SJung-uk Kim { 834e71b7053SJung-uk Kim # Last one of its kind 8353b4e3dcbSSimon L. B. Nielsen $disabled{"ssl3"} = "option(ssl)"; 8363b4e3dcbSSimon L. B. Nielsen } 8373b4e3dcbSSimon L. B. Nielsen elsif ($1 eq "tls") 8383b4e3dcbSSimon L. B. Nielsen { 839e71b7053SJung-uk Kim # XXX: Tests will fail if all SSL/TLS 840e71b7053SJung-uk Kim # protocols are disabled. 841e71b7053SJung-uk Kim foreach my $proto (@tls) 842751d2991SJung-uk Kim { 843e71b7053SJung-uk Kim $disabled{$proto} = "option(tls)"; 844e71b7053SJung-uk Kim } 845e71b7053SJung-uk Kim } 846e71b7053SJung-uk Kim elsif ($1 eq "static-engine") 847e71b7053SJung-uk Kim { 848e71b7053SJung-uk Kim delete $disabled{"dynamic-engine"}; 849e71b7053SJung-uk Kim } 850e71b7053SJung-uk Kim elsif ($1 eq "dynamic-engine") 851e71b7053SJung-uk Kim { 852e71b7053SJung-uk Kim $disabled{"dynamic-engine"} = "option"; 853e71b7053SJung-uk Kim } 854e71b7053SJung-uk Kim elsif (exists $deprecated_disablables{$1}) 855e71b7053SJung-uk Kim { 856e71b7053SJung-uk Kim $deprecated_options{$_} = 1; 857e71b7053SJung-uk Kim if (defined $deprecated_disablables{$1}) 858e71b7053SJung-uk Kim { 859e71b7053SJung-uk Kim $disabled{$deprecated_disablables{$1}} = "option"; 860e71b7053SJung-uk Kim } 861751d2991SJung-uk Kim } 862b077aed3SPierre Pronchery elsif ($1 =~ m|hw(?:-.+)|) # deprecate hw options in regexp form 863b077aed3SPierre Pronchery { 864b077aed3SPierre Pronchery $deprecated_options{$_} = 1; 865610a21fdSJung-uk Kim } 8663b4e3dcbSSimon L. B. Nielsen else 8673b4e3dcbSSimon L. B. Nielsen { 8683b4e3dcbSSimon L. B. Nielsen $disabled{$1} = "option"; 8693b4e3dcbSSimon L. B. Nielsen } 870e71b7053SJung-uk Kim # No longer an automatic choice 871e71b7053SJung-uk Kim $auto_threads = 0 if ($1 eq "threads"); 8723b4e3dcbSSimon L. B. Nielsen } 873e71b7053SJung-uk Kim elsif (/^enable-(.+)$/) 8743b4e3dcbSSimon L. B. Nielsen { 875e71b7053SJung-uk Kim if ($1 eq "static-engine") 876e71b7053SJung-uk Kim { 877e71b7053SJung-uk Kim $disabled{"dynamic-engine"} = "option"; 878e71b7053SJung-uk Kim } 879e71b7053SJung-uk Kim elsif ($1 eq "dynamic-engine") 880e71b7053SJung-uk Kim { 881e71b7053SJung-uk Kim delete $disabled{"dynamic-engine"}; 882e71b7053SJung-uk Kim } 883e71b7053SJung-uk Kim elsif ($1 eq "zlib-dynamic") 884e71b7053SJung-uk Kim { 885e71b7053SJung-uk Kim delete $disabled{"zlib"}; 886e71b7053SJung-uk Kim } 887db522d3aSSimon L. B. Nielsen my $algo = $1; 888db522d3aSSimon L. B. Nielsen delete $disabled{$algo}; 8893b4e3dcbSSimon L. B. Nielsen 890e71b7053SJung-uk Kim # No longer an automatic choice 891e71b7053SJung-uk Kim $auto_threads = 0 if ($1 eq "threads"); 8923b4e3dcbSSimon L. B. Nielsen } 893b077aed3SPierre Pronchery elsif (/^-d$/) # From older 'config' 894b077aed3SPierre Pronchery { 895b077aed3SPierre Pronchery $config{build_type} = "debug"; 896b077aed3SPierre Pronchery } 897b077aed3SPierre Pronchery elsif (/^-v$/) # From older 'config' 898b077aed3SPierre Pronchery { 899b077aed3SPierre Pronchery $guess_opts{verbose} = 1; 900b077aed3SPierre Pronchery } 901b077aed3SPierre Pronchery elsif (/^-w$/) 902b077aed3SPierre Pronchery { 903b077aed3SPierre Pronchery $guess_opts{nowait} = 1; 904b077aed3SPierre Pronchery } 905b077aed3SPierre Pronchery elsif (/^-t$/) # From older 'config' 906b077aed3SPierre Pronchery { 907b077aed3SPierre Pronchery $dryrun = 1; 908b077aed3SPierre Pronchery } 909e71b7053SJung-uk Kim elsif (/^--strict-warnings$/) 9106a599222SSimon L. B. Nielsen { 911610a21fdSJung-uk Kim # Pretend that our strict flags is a C flag, and replace it 912610a21fdSJung-uk Kim # with the proper flags later on 913610a21fdSJung-uk Kim push @{$useradd{CFLAGS}}, '--ossl-strict-warnings'; 9146a599222SSimon L. B. Nielsen $strict_warnings=1; 9156a599222SSimon L. B. Nielsen } 916e71b7053SJung-uk Kim elsif (/^--debug$/) 917ddd58736SKris Kennaway { 918e71b7053SJung-uk Kim $config{build_type} = "debug"; 919ddd58736SKris Kennaway } 920e71b7053SJung-uk Kim elsif (/^--release$/) 921e71b7053SJung-uk Kim { 922e71b7053SJung-uk Kim $config{build_type} = "release"; 923ddd58736SKris Kennaway } 92474664626SKris Kennaway elsif (/^386$/) 925e71b7053SJung-uk Kim { $config{processor}=386; } 92674664626SKris Kennaway elsif (/^rsaref$/) 92774664626SKris Kennaway { 9285c87c606SMark Murray # No RSAref support any more since it's not needed. 9295c87c606SMark Murray # The check for the option is there so scripts aren't 9305c87c606SMark Murray # broken 93174664626SKris Kennaway } 93217f01e99SJung-uk Kim elsif (m|^[-+/]|) 93374664626SKris Kennaway { 9347bded2dbSJung-uk Kim if (/^--prefix=(.*)$/) 93574664626SKris Kennaway { 936e71b7053SJung-uk Kim $config{prefix}=$1; 937e71b7053SJung-uk Kim } 938e71b7053SJung-uk Kim elsif (/^--api=(.*)$/) 939e71b7053SJung-uk Kim { 940b077aed3SPierre Pronchery my $api = $1; 941b077aed3SPierre Pronchery die "Unknown API compatibility level $api" 942b077aed3SPierre Pronchery unless defined $apitable->{$api}; 943b077aed3SPierre Pronchery $config{api}=$apitable->{$api}; 94474664626SKris Kennaway } 9456a599222SSimon L. B. Nielsen elsif (/^--libdir=(.*)$/) 9466a599222SSimon L. B. Nielsen { 947e71b7053SJung-uk Kim $config{libdir}=$1; 9486a599222SSimon L. B. Nielsen } 94974664626SKris Kennaway elsif (/^--openssldir=(.*)$/) 95074664626SKris Kennaway { 951e71b7053SJung-uk Kim $config{openssldir}=$1; 9525c87c606SMark Murray } 9533b4e3dcbSSimon L. B. Nielsen elsif (/^--with-zlib-lib=(.*)$/) 9543b4e3dcbSSimon L. B. Nielsen { 955e71b7053SJung-uk Kim $withargs{zlib_lib}=$1; 9563b4e3dcbSSimon L. B. Nielsen } 9573b4e3dcbSSimon L. B. Nielsen elsif (/^--with-zlib-include=(.*)$/) 9583b4e3dcbSSimon L. B. Nielsen { 959e71b7053SJung-uk Kim $withargs{zlib_include}=$1; 9603b4e3dcbSSimon L. B. Nielsen } 961e71b7053SJung-uk Kim elsif (/^--with-fuzzer-lib=(.*)$/) 9621f13597dSJung-uk Kim { 963e71b7053SJung-uk Kim $withargs{fuzzer_lib}=$1; 9641f13597dSJung-uk Kim } 965e71b7053SJung-uk Kim elsif (/^--with-fuzzer-include=(.*)$/) 966db522d3aSSimon L. B. Nielsen { 967e71b7053SJung-uk Kim $withargs{fuzzer_include}=$1; 968db522d3aSSimon L. B. Nielsen } 969e71b7053SJung-uk Kim elsif (/^--with-rand-seed=(.*)$/) 970db522d3aSSimon L. B. Nielsen { 971e71b7053SJung-uk Kim foreach my $x (split(m|,|, $1)) 972e71b7053SJung-uk Kim { 973e71b7053SJung-uk Kim die "Unknown --with-rand-seed choice $x\n" 974e71b7053SJung-uk Kim if ! grep { $x eq $_ } @known_seed_sources; 975e71b7053SJung-uk Kim push @seed_sources, $x; 976e71b7053SJung-uk Kim } 977db522d3aSSimon L. B. Nielsen } 978b077aed3SPierre Pronchery elsif (/^--fips-key=(.*)$/) 979b077aed3SPierre Pronchery { 980b077aed3SPierre Pronchery $user{FIPSKEY}=lc($1); 981b077aed3SPierre Pronchery die "Non-hex character in FIPS key\n" 982b077aed3SPierre Pronchery if $user{FIPSKEY} =~ /[^a-f0-9]/; 983b077aed3SPierre Pronchery die "FIPS key must have even number of characters\n" 984b077aed3SPierre Pronchery if length $1 & 1; 985b077aed3SPierre Pronchery die "FIPS key too long (64 bytes max)\n" 986b077aed3SPierre Pronchery if length $1 > 64; 987b077aed3SPierre Pronchery } 988b077aed3SPierre Pronchery elsif (/^--banner=(.*)$/) 989b077aed3SPierre Pronchery { 990b077aed3SPierre Pronchery $banner = $1 . "\n"; 991b077aed3SPierre Pronchery } 9921f13597dSJung-uk Kim elsif (/^--cross-compile-prefix=(.*)$/) 9931f13597dSJung-uk Kim { 994e71b7053SJung-uk Kim $user{CROSS_COMPILE}=$1; 9951f13597dSJung-uk Kim } 996e71b7053SJung-uk Kim elsif (/^--config=(.*)$/) 99774664626SKris Kennaway { 998e71b7053SJung-uk Kim read_config $1; 999e71b7053SJung-uk Kim } 1000e71b7053SJung-uk Kim elsif (/^-l(.*)$/) 1001e71b7053SJung-uk Kim { 1002e71b7053SJung-uk Kim push @{$useradd{LDLIBS}}, $_; 1003e71b7053SJung-uk Kim } 1004e71b7053SJung-uk Kim elsif (/^-framework$/) 1005e71b7053SJung-uk Kim { 1006e71b7053SJung-uk Kim push @{$useradd{LDLIBS}}, $_, shift(@argvcopy); 1007e71b7053SJung-uk Kim } 1008e71b7053SJung-uk Kim elsif (/^-L(.*)$/ or /^-Wl,/) 1009e71b7053SJung-uk Kim { 1010e71b7053SJung-uk Kim push @{$useradd{LDFLAGS}}, $_; 1011e71b7053SJung-uk Kim } 1012e71b7053SJung-uk Kim elsif (/^-rpath$/ or /^-R$/) 1013e71b7053SJung-uk Kim # -rpath is the OSF1 rpath flag 1014e71b7053SJung-uk Kim # -R is the old Solaris rpath flag 1015e71b7053SJung-uk Kim { 1016e71b7053SJung-uk Kim my $rpath = shift(@argvcopy) || ""; 1017e71b7053SJung-uk Kim $rpath .= " " if $rpath ne ""; 1018e71b7053SJung-uk Kim push @{$useradd{LDFLAGS}}, $_, $rpath; 1019e71b7053SJung-uk Kim } 1020e71b7053SJung-uk Kim elsif (/^-static$/) 1021e71b7053SJung-uk Kim { 1022e71b7053SJung-uk Kim push @{$useradd{LDFLAGS}}, $_; 1023e71b7053SJung-uk Kim } 102417f01e99SJung-uk Kim elsif (m|^[-/]D(.*)$|) 1025e71b7053SJung-uk Kim { 1026e71b7053SJung-uk Kim push @{$useradd{CPPDEFINES}}, $1; 1027e71b7053SJung-uk Kim } 102817f01e99SJung-uk Kim elsif (m|^[-/]I(.*)$|) 1029e71b7053SJung-uk Kim { 1030e71b7053SJung-uk Kim push @{$useradd{CPPINCLUDES}}, $1; 1031e71b7053SJung-uk Kim } 1032e71b7053SJung-uk Kim elsif (/^-Wp,$/) 1033e71b7053SJung-uk Kim { 1034e71b7053SJung-uk Kim push @{$useradd{CPPFLAGS}}, $1; 10357bded2dbSJung-uk Kim } 10367bded2dbSJung-uk Kim else # common if (/^[-+]/), just pass down... 10377bded2dbSJung-uk Kim { 103817f01e99SJung-uk Kim # Treat %xx as an ASCII code (e.g. replace %20 by a space character). 103917f01e99SJung-uk Kim # This provides a simple way to pass options with arguments separated 104017f01e99SJung-uk Kim # by spaces without quoting (e.g. -opt%20arg translates to -opt arg). 10417bded2dbSJung-uk Kim $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei; 1042e71b7053SJung-uk Kim push @{$useradd{CFLAGS}}, $_; 1043e71b7053SJung-uk Kim push @{$useradd{CXXFLAGS}}, $_; 104474664626SKris Kennaway } 104574664626SKris Kennaway } 104617f01e99SJung-uk Kim elsif (m|^/|) 104717f01e99SJung-uk Kim { 104817f01e99SJung-uk Kim # Treat %xx as an ASCII code (e.g. replace %20 by a space character). 104917f01e99SJung-uk Kim # This provides a simple way to pass options with arguments separated 105017f01e99SJung-uk Kim # by spaces without quoting (e.g. /opt%20arg translates to /opt arg). 105117f01e99SJung-uk Kim $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei; 105217f01e99SJung-uk Kim push @{$useradd{CFLAGS}}, $_; 105317f01e99SJung-uk Kim push @{$useradd{CXXFLAGS}}, $_; 105417f01e99SJung-uk Kim } 105574664626SKris Kennaway else 105674664626SKris Kennaway { 10573b4e3dcbSSimon L. B. Nielsen die "target already defined - $target (offending arg: $_)\n" if ($target ne ""); 105874664626SKris Kennaway $target=$_; 105974664626SKris Kennaway } 10603b4e3dcbSSimon L. B. Nielsen unless ($_ eq $target || /^no-/ || /^disable-/) 10615c87c606SMark Murray { 1062e71b7053SJung-uk Kim # "no-..." follows later after implied deactivations 1063e71b7053SJung-uk Kim # have been derived. (Don't take this too seriously, 10643b4e3dcbSSimon L. B. Nielsen # we really only write OPTIONS to the Makefile out of 10653b4e3dcbSSimon L. B. Nielsen # nostalgia.) 10663b4e3dcbSSimon L. B. Nielsen 1067e71b7053SJung-uk Kim if ($config{options} eq "") 1068e71b7053SJung-uk Kim { $config{options} = $_; } 10693b4e3dcbSSimon L. B. Nielsen else 1070e71b7053SJung-uk Kim { $config{options} .= " ".$_; } 10713b4e3dcbSSimon L. B. Nielsen } 10725c87c606SMark Murray } 10735c87c606SMark Murray 1074e71b7053SJung-uk Kimif (keys %deprecated_options) 10755c87c606SMark Murray { 1076e71b7053SJung-uk Kim warn "***** Deprecated options: ", 1077e71b7053SJung-uk Kim join(", ", keys %deprecated_options), "\n"; 1078e71b7053SJung-uk Kim } 1079e71b7053SJung-uk Kimif (keys %unsupported_options) 1080e71b7053SJung-uk Kim { 1081e71b7053SJung-uk Kim die "***** Unsupported options: ", 1082e71b7053SJung-uk Kim join(", ", keys %unsupported_options), "\n"; 10835c87c606SMark Murray } 10845c87c606SMark Murray 1085e71b7053SJung-uk Kim# If any %useradd entry has been set, we must check that the "make 1086e71b7053SJung-uk Kim# variables" haven't been set. We start by checking of any %useradd entry 1087e71b7053SJung-uk Kim# is set. 1088e71b7053SJung-uk Kimif (grep { scalar @$_ > 0 } values %useradd) { 1089e71b7053SJung-uk Kim # Hash of env / make variables names. The possible values are: 1090e71b7053SJung-uk Kim # 1 - "make vars" 1091e71b7053SJung-uk Kim # 2 - %useradd entry set 1092e71b7053SJung-uk Kim # 3 - both set 1093e71b7053SJung-uk Kim my %detected_vars = 1094e71b7053SJung-uk Kim map { my $v = 0; 1095e71b7053SJung-uk Kim $v += 1 if $cmdvars{$_}; 1096e71b7053SJung-uk Kim $v += 2 if @{$useradd{$_}}; 1097e71b7053SJung-uk Kim $_ => $v } 1098e71b7053SJung-uk Kim keys %useradd; 1099e71b7053SJung-uk Kim 1100e71b7053SJung-uk Kim # If any of the corresponding "make variables" is set, we error 1101e71b7053SJung-uk Kim if (grep { $_ & 1 } values %detected_vars) { 1102e71b7053SJung-uk Kim my $names = join(', ', grep { $detected_vars{$_} > 0 } 1103e71b7053SJung-uk Kim sort keys %detected_vars); 1104e71b7053SJung-uk Kim die <<"_____"; 1105e71b7053SJung-uk Kim***** Mixing make variables and additional compiler/linker flags as 1106e71b7053SJung-uk Kim***** configure command line option is not permitted. 1107e71b7053SJung-uk Kim***** Affected make variables: $names 1108e71b7053SJung-uk Kim_____ 1109e71b7053SJung-uk Kim } 11105c87c606SMark Murray} 11115c87c606SMark Murray 1112e71b7053SJung-uk Kim# Check through all supported command line variables to see if any of them 1113e71b7053SJung-uk Kim# were set, and canonicalise the values we got. If no compiler or linker 1114e71b7053SJung-uk Kim# flag or anything else that affects %useradd was set, we also check the 1115e71b7053SJung-uk Kim# environment for values. 1116e71b7053SJung-uk Kimmy $anyuseradd = 1117e71b7053SJung-uk Kim grep { defined $_ && (ref $_ ne 'ARRAY' || @$_) } values %useradd; 1118e71b7053SJung-uk Kimforeach (keys %user) { 1119e71b7053SJung-uk Kim my $value = $cmdvars{$_}; 1120e71b7053SJung-uk Kim $value //= env($_) unless $anyuseradd; 1121e71b7053SJung-uk Kim $value //= 1122e71b7053SJung-uk Kim defined $user_synonyms{$_} ? $cmdvars{$user_synonyms{$_}} : undef; 1123e71b7053SJung-uk Kim $value //= defined $user_synonyms{$_} ? env($user_synonyms{$_}) : undef 1124e71b7053SJung-uk Kim unless $anyuseradd; 1125e71b7053SJung-uk Kim 1126e71b7053SJung-uk Kim if (defined $value) { 1127e71b7053SJung-uk Kim if (ref $user{$_} eq 'ARRAY') { 112817f01e99SJung-uk Kim if ($_ eq 'CPPDEFINES' || $_ eq 'CPPINCLUDES') { 1129e71b7053SJung-uk Kim $user{$_} = [ split /$list_separator_re/, $value ]; 113017f01e99SJung-uk Kim } else { 113117f01e99SJung-uk Kim $user{$_} = [ $value ]; 113217f01e99SJung-uk Kim } 1133e71b7053SJung-uk Kim } elsif (!defined $user{$_}) { 1134e71b7053SJung-uk Kim $user{$_} = $value; 1135e71b7053SJung-uk Kim } 1136e71b7053SJung-uk Kim } 11373b4e3dcbSSimon L. B. Nielsen} 11383b4e3dcbSSimon L. B. Nielsen 1139e71b7053SJung-uk Kimif (grep { /-rpath\b/ } ($user{LDFLAGS} ? @{$user{LDFLAGS}} : ()) 1140e71b7053SJung-uk Kim && !$disabled{shared} 1141e71b7053SJung-uk Kim && !($disabled{asan} && $disabled{msan} && $disabled{ubsan})) { 1142e71b7053SJung-uk Kim die "***** Cannot simultaneously use -rpath, shared libraries, and\n", 1143e71b7053SJung-uk Kim "***** any of asan, msan or ubsan\n"; 11443b4e3dcbSSimon L. B. Nielsen} 11453b4e3dcbSSimon L. B. Nielsen 1146b077aed3SPierre Pronchery# If no target was given, try guessing. 1147b077aed3SPierre Proncheryunless ($target) { 1148b077aed3SPierre Pronchery my %system_config = OpenSSL::config::get_platform(%guess_opts, %user); 1149b077aed3SPierre Pronchery 1150b077aed3SPierre Pronchery # The $system_config{disable} is used to populate %disabled with 1151b077aed3SPierre Pronchery # entries that aren't already there. 1152b077aed3SPierre Pronchery foreach ( @{$system_config{disable} // []} ) { 1153b077aed3SPierre Pronchery $disabled{$_} = 'system' unless defined $disabled{$_}; 1154b077aed3SPierre Pronchery } 1155b077aed3SPierre Pronchery delete $system_config{disable}; 1156b077aed3SPierre Pronchery 1157b077aed3SPierre Pronchery # Override config entries with stuff from the guesser. 1158b077aed3SPierre Pronchery # It's assumed that this really is nothing new. 1159b077aed3SPierre Pronchery %config = ( %config, %system_config ); 1160b077aed3SPierre Pronchery $target = $system_config{target}; 1161b077aed3SPierre Pronchery} 1162b077aed3SPierre Pronchery 1163610a21fdSJung-uk Kimsub disable { 1164610a21fdSJung-uk Kim my $disable_type = shift; 1165610a21fdSJung-uk Kim 1166610a21fdSJung-uk Kim for (@_) { 1167610a21fdSJung-uk Kim $disabled{$_} = $disable_type; 1168610a21fdSJung-uk Kim } 1169610a21fdSJung-uk Kim 1170610a21fdSJung-uk Kim my @tocheckfor = (@_ ? @_ : keys %disabled); 1171e71b7053SJung-uk Kim while (@tocheckfor) { 1172e71b7053SJung-uk Kim my %new_tocheckfor = (); 1173e71b7053SJung-uk Kim my @cascade_copy = (@disable_cascades); 1174e71b7053SJung-uk Kim while (@cascade_copy) { 1175610a21fdSJung-uk Kim my ($test, $descendents) = 1176610a21fdSJung-uk Kim (shift @cascade_copy, shift @cascade_copy); 1177e71b7053SJung-uk Kim if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) { 1178e71b7053SJung-uk Kim foreach (grep { !defined($disabled{$_}) } @$descendents) { 1179610a21fdSJung-uk Kim $new_tocheckfor{$_} = 1; $disabled{$_} = "cascade"; 1180e71b7053SJung-uk Kim } 1181e71b7053SJung-uk Kim } 1182e71b7053SJung-uk Kim } 1183e71b7053SJung-uk Kim @tocheckfor = (keys %new_tocheckfor); 11843b4e3dcbSSimon L. B. Nielsen } 1185610a21fdSJung-uk Kim} 1186610a21fdSJung-uk Kimdisable(); # First cascade run 11873b4e3dcbSSimon L. B. Nielsen 1188e71b7053SJung-uk Kimour $die = sub { die @_; }; 118974664626SKris Kennawayif ($target eq "TABLE") { 1190e71b7053SJung-uk Kim local $die = sub { warn @_; }; 1191e71b7053SJung-uk Kim foreach (sort keys %table) { 1192e71b7053SJung-uk Kim print_table_entry($_, "TABLE"); 119374664626SKris Kennaway } 119474664626SKris Kennaway exit 0; 119574664626SKris Kennaway} 119674664626SKris Kennaway 1197f579bf8eSKris Kennawayif ($target eq "LIST") { 1198f579bf8eSKris Kennaway foreach (sort keys %table) { 1199e71b7053SJung-uk Kim print $_,"\n" unless $table{$_}->{template}; 1200f579bf8eSKris Kennaway } 1201f579bf8eSKris Kennaway exit 0; 1202f579bf8eSKris Kennaway} 1203f579bf8eSKris Kennaway 1204e71b7053SJung-uk Kimif ($target eq "HASH") { 1205e71b7053SJung-uk Kim local $die = sub { warn @_; }; 1206e71b7053SJung-uk Kim print "%table = (\n"; 1207e71b7053SJung-uk Kim foreach (sort keys %table) { 1208e71b7053SJung-uk Kim print_table_entry($_, "HASH"); 1209e71b7053SJung-uk Kim } 1210e71b7053SJung-uk Kim exit 0; 1211e71b7053SJung-uk Kim} 1212e71b7053SJung-uk Kim 1213b077aed3SPierre Proncheryprint "Configuring OpenSSL version $config{full_version} "; 1214b077aed3SPierre Proncheryprint "for target $target\n"; 1215e71b7053SJung-uk Kim 1216e71b7053SJung-uk Kimif (scalar(@seed_sources) == 0) { 1217e71b7053SJung-uk Kim print "Using os-specific seed configuration\n"; 1218e71b7053SJung-uk Kim push @seed_sources, 'os'; 1219e71b7053SJung-uk Kim} 122058f35182SJung-uk Kimif (scalar(grep { $_ eq 'egd' } @seed_sources) > 0) { 122158f35182SJung-uk Kim delete $disabled{'egd'}; 122258f35182SJung-uk Kim} 1223e71b7053SJung-uk Kimif (scalar(grep { $_ eq 'none' } @seed_sources) > 0) { 1224e71b7053SJung-uk Kim die "Cannot seed with none and anything else" if scalar(@seed_sources) > 1; 1225e71b7053SJung-uk Kim warn <<_____ if scalar(@seed_sources) == 1; 1226e71b7053SJung-uk Kim 1227c9cf7b5cSJung-uk Kim============================== WARNING =============================== 1228c9cf7b5cSJung-uk KimYou have selected the --with-rand-seed=none option, which effectively 1229c9cf7b5cSJung-uk Kimdisables automatic reseeding of the OpenSSL random generator. 1230c9cf7b5cSJung-uk KimAll operations depending on the random generator such as creating keys 1231c9cf7b5cSJung-uk Kimwill not work unless the random generator is seeded manually by the 1232c9cf7b5cSJung-uk Kimapplication. 1233c9cf7b5cSJung-uk Kim 1234c9cf7b5cSJung-uk KimPlease read the 'Note on random number generation' section in the 1235b077aed3SPierre ProncheryINSTALL.md instructions and the RAND_DRBG(7) manual page for more 1236b077aed3SPierre Proncherydetails. 1237c9cf7b5cSJung-uk Kim============================== WARNING =============================== 1238c9cf7b5cSJung-uk Kim 1239e71b7053SJung-uk Kim_____ 1240e71b7053SJung-uk Kim} 1241b077aed3SPierre Proncherypush @{$config{openssl_feature_defines}}, 1242e71b7053SJung-uk Kim map { (my $x = $_) =~ tr|[\-a-z]|[_A-Z]|; "OPENSSL_RAND_SEED_$x" } 1243e71b7053SJung-uk Kim @seed_sources; 1244e71b7053SJung-uk Kim 1245e71b7053SJung-uk Kim# Backward compatibility? 1246c1803d78SJacques Vidrineif ($target =~ m/^CygWin32(-.*)$/) { 1247c1803d78SJacques Vidrine $target = "Cygwin".$1; 1248c1803d78SJacques Vidrine} 1249c1803d78SJacques Vidrine 1250e71b7053SJung-uk Kim# Support for legacy targets having a name starting with 'debug-' 1251e71b7053SJung-uk Kimmy ($d, $t) = $target =~ m/^(debug-)?(.*)$/; 1252e71b7053SJung-uk Kimif ($d) { 1253e71b7053SJung-uk Kim $config{build_type} = "debug"; 1254ddd58736SKris Kennaway 1255e71b7053SJung-uk Kim # If we do not find debug-foo in the table, the target is set to foo. 1256e71b7053SJung-uk Kim if (!$table{$target}) { 1257e71b7053SJung-uk Kim $target = $t; 12581f13597dSJung-uk Kim } 1259e71b7053SJung-uk Kim} 12601f13597dSJung-uk Kim 1261b077aed3SPierre Proncheryif ($target) { 1262b077aed3SPierre Pronchery # It's possible that we have different config targets for specific 1263b077aed3SPierre Pronchery # toolchains, so we try to detect them, and go for the plain config 1264b077aed3SPierre Pronchery # target if not. 1265b077aed3SPierre Pronchery my $found; 1266b077aed3SPierre Pronchery foreach ( ( "$target-$user{CC}", "$target", undef ) ) { 1267b077aed3SPierre Pronchery $found=$_ if $table{$_} && !$table{$_}->{template}; 1268b077aed3SPierre Pronchery last if $found; 1269b077aed3SPierre Pronchery } 1270b077aed3SPierre Pronchery $target = $found; 1271b077aed3SPierre Pronchery} else { 1272b077aed3SPierre Pronchery # If we don't have a config target now, we try the C compiler as we 1273b077aed3SPierre Pronchery # fallback 1274b077aed3SPierre Pronchery my $cc = $user{CC} // 'cc'; 1275b077aed3SPierre Pronchery $target = $cc if $table{$cc} && !$table{$cc}->{template}; 1276b077aed3SPierre Pronchery} 1277b077aed3SPierre Pronchery 1278b077aed3SPierre Pronchery&usage unless $target; 1279b077aed3SPierre Pronchery 1280b077aed3SPierre Proncheryexit 0 if $dryrun; # From older 'config' 1281e71b7053SJung-uk Kim 1282e71b7053SJung-uk Kim$config{target} = $target; 1283e71b7053SJung-uk Kimmy %target = resolve_config($target); 1284e71b7053SJung-uk Kim 1285e71b7053SJung-uk Kimforeach (keys %target_attr_translate) { 1286e71b7053SJung-uk Kim $target{$target_attr_translate{$_}} = $target{$_} 1287e71b7053SJung-uk Kim if $target{$_}; 1288e71b7053SJung-uk Kim delete $target{$_}; 1289e71b7053SJung-uk Kim} 1290e71b7053SJung-uk Kim 1291e71b7053SJung-uk Kim%target = ( %{$table{DEFAULTS}}, %target ); 1292e71b7053SJung-uk Kim 1293e71b7053SJung-uk Kimmy %conf_files = map { $_ => 1 } (@{$target{_conf_fname_int}}); 1294e71b7053SJung-uk Kim$config{conf_files} = [ sort keys %conf_files ]; 1295e71b7053SJung-uk Kim 1296610a21fdSJung-uk Kim# Using sub disable within these loops may prove fragile, so we run 1297610a21fdSJung-uk Kim# a cascade afterwards 1298e71b7053SJung-uk Kimforeach my $feature (@{$target{disable}}) { 1299e71b7053SJung-uk Kim if (exists $deprecated_disablables{$feature}) { 1300e71b7053SJung-uk Kim warn "***** config $target disables deprecated feature $feature\n"; 1301e71b7053SJung-uk Kim } elsif (!grep { $feature eq $_ } @disablables) { 1302e71b7053SJung-uk Kim die "***** config $target disables unknown feature $feature\n"; 1303e71b7053SJung-uk Kim } 1304e71b7053SJung-uk Kim $disabled{$feature} = 'config'; 1305e71b7053SJung-uk Kim} 1306e71b7053SJung-uk Kimforeach my $feature (@{$target{enable}}) { 13076935a639SJung-uk Kim if ("default" eq ($disabled{$feature} // "")) { 1308e71b7053SJung-uk Kim if (exists $deprecated_disablables{$feature}) { 1309e71b7053SJung-uk Kim warn "***** config $target enables deprecated feature $feature\n"; 1310e71b7053SJung-uk Kim } elsif (!grep { $feature eq $_ } @disablables) { 1311e71b7053SJung-uk Kim die "***** config $target enables unknown feature $feature\n"; 1312e71b7053SJung-uk Kim } 13136935a639SJung-uk Kim delete $disabled{$feature}; 1314e71b7053SJung-uk Kim } 1315e71b7053SJung-uk Kim} 1316b077aed3SPierre Pronchery 1317b077aed3SPierre Pronchery# If uplink_arch isn't defined, disable uplink 1318b077aed3SPierre Pronchery$disabled{uplink} = 'no uplink_arch' unless (defined $target{uplink_arch}); 1319b077aed3SPierre Pronchery# If asm_arch isn't defined, disable asm 1320b077aed3SPierre Pronchery$disabled{asm} = 'no asm_arch' unless (defined $target{asm_arch}); 1321b077aed3SPierre Pronchery 1322610a21fdSJung-uk Kimdisable(); # Run a cascade now 1323e71b7053SJung-uk Kim 1324e71b7053SJung-uk Kim$target{CXXFLAGS}//=$target{CFLAGS} if $target{CXX}; 1325e71b7053SJung-uk Kim$target{cxxflags}//=$target{cflags} if $target{CXX}; 1326b077aed3SPierre Pronchery$target{exe_extension}=".exe" if ($config{target} eq "DJGPP"); 1327e71b7053SJung-uk Kim$target{exe_extension}=".pm" if ($config{target} =~ /vos/); 1328e71b7053SJung-uk Kim 1329e71b7053SJung-uk Kim# Fill %config with values from %user, and in case those are undefined or 1330e71b7053SJung-uk Kim# empty, use values from %target (acting as a default). 1331e71b7053SJung-uk Kimforeach (keys %user) { 1332e71b7053SJung-uk Kim my $ref_type = ref $user{$_}; 1333e71b7053SJung-uk Kim 1334e71b7053SJung-uk Kim # Temporary function. Takes an intended ref type (empty string or "ARRAY") 1335e71b7053SJung-uk Kim # and a value that's to be coerced into that type. 1336e71b7053SJung-uk Kim my $mkvalue = sub { 1337e71b7053SJung-uk Kim my $type = shift; 1338e71b7053SJung-uk Kim my $value = shift; 1339e71b7053SJung-uk Kim my $undef_p = shift; 1340e71b7053SJung-uk Kim 1341e71b7053SJung-uk Kim die "Too many arguments for \$mkvalue" if @_; 1342e71b7053SJung-uk Kim 1343e71b7053SJung-uk Kim while (ref $value eq 'CODE') { 1344e71b7053SJung-uk Kim $value = $value->(); 1345e71b7053SJung-uk Kim } 1346e71b7053SJung-uk Kim 1347e71b7053SJung-uk Kim if ($type eq 'ARRAY') { 1348e71b7053SJung-uk Kim return undef unless defined $value; 1349e71b7053SJung-uk Kim return undef if ref $value ne 'ARRAY' && !$value; 1350e71b7053SJung-uk Kim return undef if ref $value eq 'ARRAY' && !@$value; 1351e71b7053SJung-uk Kim return [ $value ] unless ref $value eq 'ARRAY'; 1352e71b7053SJung-uk Kim } 1353e71b7053SJung-uk Kim return undef unless $value; 1354e71b7053SJung-uk Kim return $value; 1355e71b7053SJung-uk Kim }; 1356e71b7053SJung-uk Kim 1357e71b7053SJung-uk Kim $config{$_} = 1358e71b7053SJung-uk Kim $mkvalue->($ref_type, $user{$_}) 1359e71b7053SJung-uk Kim || $mkvalue->($ref_type, $target{$_}); 1360e71b7053SJung-uk Kim delete $config{$_} unless defined $config{$_}; 1361e71b7053SJung-uk Kim} 1362e71b7053SJung-uk Kim 1363610a21fdSJung-uk Kim# Finish up %config by appending things the user gave us on the command line 1364610a21fdSJung-uk Kim# apart from "make variables" 1365610a21fdSJung-uk Kimforeach (keys %useradd) { 1366610a21fdSJung-uk Kim # The must all be lists, so we assert that here 1367610a21fdSJung-uk Kim die "internal error: \$useradd{$_} isn't an ARRAY\n" 1368610a21fdSJung-uk Kim unless ref $useradd{$_} eq 'ARRAY'; 1369610a21fdSJung-uk Kim 1370610a21fdSJung-uk Kim if (defined $config{$_}) { 1371610a21fdSJung-uk Kim push @{$config{$_}}, @{$useradd{$_}}; 1372610a21fdSJung-uk Kim } else { 1373610a21fdSJung-uk Kim $config{$_} = [ @{$useradd{$_}} ]; 1374610a21fdSJung-uk Kim } 1375610a21fdSJung-uk Kim} 1376610a21fdSJung-uk Kim# At this point, we can forget everything about %user and %useradd, 1377610a21fdSJung-uk Kim# because it's now all been merged into the corresponding $config entry 1378610a21fdSJung-uk Kim 1379e0c4386eSCy Schubertif ($config{prefix} && !$config{CROSS_COMPILE}) { 1380e0c4386eSCy Schubert die "Directory given with --prefix MUST be absolute\n" 1381e0c4386eSCy Schubert unless file_name_is_absolute($config{prefix}); 1382e0c4386eSCy Schubert} 1383e0c4386eSCy Schubert 1384b077aed3SPierre Proncheryif (grep { $_ =~ /(?:^|\s)-static(?:\s|$)/ } @{$config{LDFLAGS}}) { 138588e852c0SJung-uk Kim disable('static', 'pic', 'threads'); 138688e852c0SJung-uk Kim} 138788e852c0SJung-uk Kim 1388e71b7053SJung-uk Kim# Allow overriding the build file name 1389e71b7053SJung-uk Kim$config{build_file} = env('BUILDFILE') || $target{build_file} || "Makefile"; 1390e71b7053SJung-uk Kim 1391e71b7053SJung-uk Kim# Make sure build_scheme is consistent. 1392e71b7053SJung-uk Kim$target{build_scheme} = [ $target{build_scheme} ] 1393e71b7053SJung-uk Kim if ref($target{build_scheme}) ne "ARRAY"; 1394e71b7053SJung-uk Kim 1395e71b7053SJung-uk Kimmy ($builder, $builder_platform, @builder_opts) = 1396e71b7053SJung-uk Kim @{$target{build_scheme}}; 1397e71b7053SJung-uk Kim 1398640242a5SJung-uk Kimforeach my $checker (($builder_platform."-".$config{build_file}."-checker.pm", 1399e71b7053SJung-uk Kim $builder_platform."-checker.pm")) { 1400e71b7053SJung-uk Kim my $checker_path = catfile($srcdir, "Configurations", $checker); 1401e71b7053SJung-uk Kim if (-f $checker_path) { 1402e71b7053SJung-uk Kim my $fn = $ENV{CONFIGURE_CHECKER_WARN} 1403e71b7053SJung-uk Kim ? sub { warn $@; } : sub { die $@; }; 1404e71b7053SJung-uk Kim if (! do $checker_path) { 1405e71b7053SJung-uk Kim if ($@) { 1406e71b7053SJung-uk Kim $fn->($@); 1407e71b7053SJung-uk Kim } elsif ($!) { 1408e71b7053SJung-uk Kim $fn->($!); 1409e71b7053SJung-uk Kim } else { 1410e71b7053SJung-uk Kim $fn->("The detected tools didn't match the platform\n"); 1411e71b7053SJung-uk Kim } 1412e71b7053SJung-uk Kim } 1413e71b7053SJung-uk Kim last; 1414e71b7053SJung-uk Kim } 1415e71b7053SJung-uk Kim} 1416e71b7053SJung-uk Kim 1417e71b7053SJung-uk Kimpush @{$config{defines}}, "NDEBUG" if $config{build_type} eq "release"; 1418e71b7053SJung-uk Kim 1419e71b7053SJung-uk Kimif ($target =~ /^mingw/ && `$config{CC} --target-help 2>&1` =~ m/-mno-cygwin/m) 14201f13597dSJung-uk Kim { 1421e71b7053SJung-uk Kim push @{$config{cflags}}, "-mno-cygwin"; 1422e71b7053SJung-uk Kim push @{$config{cxxflags}}, "-mno-cygwin" if $config{CXX}; 1423e71b7053SJung-uk Kim push @{$config{shared_ldflag}}, "-mno-cygwin"; 14241f13597dSJung-uk Kim } 14251f13597dSJung-uk Kim 1426e71b7053SJung-uk Kimif ($target =~ /linux.*-mips/ && !$disabled{asm} 14278f1ef87aSJung-uk Kim && !grep { $_ =~ /-m(ips|arch=)/ } (@{$config{CFLAGS}})) { 14287bded2dbSJung-uk Kim # minimally required architecture flags for assembly modules 1429e71b7053SJung-uk Kim my $value; 1430e71b7053SJung-uk Kim $value = '-mips2' if ($target =~ /mips32/); 1431e71b7053SJung-uk Kim $value = '-mips3' if ($target =~ /mips64/); 1432e71b7053SJung-uk Kim unshift @{$config{cflags}}, $value; 1433e71b7053SJung-uk Kim unshift @{$config{cxxflags}}, $value if $config{CXX}; 1434e71b7053SJung-uk Kim} 1435e71b7053SJung-uk Kim 1436e71b7053SJung-uk Kim# If threads aren't disabled, check how possible they are 1437e71b7053SJung-uk Kimunless ($disabled{threads}) { 1438e71b7053SJung-uk Kim if ($auto_threads) { 1439e71b7053SJung-uk Kim # Enabled by default, disable it forcibly if unavailable 1440e71b7053SJung-uk Kim if ($target{thread_scheme} eq "(unknown)") { 1441610a21fdSJung-uk Kim disable("unavailable", 'threads'); 1442e71b7053SJung-uk Kim } 1443e71b7053SJung-uk Kim } else { 1444e71b7053SJung-uk Kim # The user chose to enable threads explicitly, let's see 1445e71b7053SJung-uk Kim # if there's a chance that's possible 1446e71b7053SJung-uk Kim if ($target{thread_scheme} eq "(unknown)") { 1447e71b7053SJung-uk Kim # If the user asked for "threads" and we don't have internal 1448e71b7053SJung-uk Kim # knowledge how to do it, [s]he is expected to provide any 1449e71b7053SJung-uk Kim # system-dependent compiler options that are necessary. We 1450e71b7053SJung-uk Kim # can't truly check that the given options are correct, but 1451e71b7053SJung-uk Kim # we expect the user to know what [s]He is doing. 1452610a21fdSJung-uk Kim if (!@{$config{CFLAGS}} && !@{$config{CPPDEFINES}}) { 1453e71b7053SJung-uk Kim die "You asked for multi-threading support, but didn't\n" 1454e71b7053SJung-uk Kim ,"provide any system-specific compiler options\n"; 1455e71b7053SJung-uk Kim } 1456e71b7053SJung-uk Kim } 1457e71b7053SJung-uk Kim } 1458e71b7053SJung-uk Kim} 1459e71b7053SJung-uk Kim 1460b077aed3SPierre Pronchery# Find out if clang's sanitizers have been enabled with -fsanitize 1461b077aed3SPierre Pronchery# flags and ensure that the corresponding %disabled elements area 1462b077aed3SPierre Pronchery# removed to reflect that the sanitizers are indeed enabled. 1463b077aed3SPierre Proncherymy %detected_sanitizers = (); 1464b077aed3SPierre Proncheryforeach (grep /^-fsanitize=/, @{$config{CFLAGS} || []}) { 1465b077aed3SPierre Pronchery (my $checks = $_) =~ s/^-fsanitize=//; 1466b077aed3SPierre Pronchery foreach (split /,/, $checks) { 1467b077aed3SPierre Pronchery my $d = { address => 'asan', 1468b077aed3SPierre Pronchery undefined => 'ubsan', 1469b077aed3SPierre Pronchery memory => 'msan' } -> {$_}; 1470b077aed3SPierre Pronchery next unless defined $d; 1471b077aed3SPierre Pronchery 1472b077aed3SPierre Pronchery $detected_sanitizers{$d} = 1; 1473b077aed3SPierre Pronchery if (defined $disabled{$d}) { 1474b077aed3SPierre Pronchery die "***** Conflict between disabling $d and enabling $_ sanitizer" 1475b077aed3SPierre Pronchery if $disabled{$d} ne "default"; 1476b077aed3SPierre Pronchery delete $disabled{$d}; 1477b077aed3SPierre Pronchery } 1478b077aed3SPierre Pronchery } 1479b077aed3SPierre Pronchery} 1480b077aed3SPierre Pronchery 1481e71b7053SJung-uk Kim# If threads still aren't disabled, add a C macro to ensure the source 1482e71b7053SJung-uk Kim# code knows about it. Any other flag is taken care of by the configs. 1483e71b7053SJung-uk Kimunless($disabled{threads}) { 1484b077aed3SPierre Pronchery push @{$config{openssl_feature_defines}}, "OPENSSL_THREADS"; 14857bded2dbSJung-uk Kim} 14867bded2dbSJung-uk Kim 1487fceca8a3SJacques Vidrinemy $no_shared_warn=0; 1488b077aed3SPierre Proncheryif (($target{shared_target} // '') eq "") 14895c87c606SMark Murray { 1490e71b7053SJung-uk Kim $no_shared_warn = 1 1491e71b7053SJung-uk Kim if (!$disabled{shared} || !$disabled{"dynamic-engine"}); 1492610a21fdSJung-uk Kim disable('no-shared-target', 'pic'); 14935c87c606SMark Murray } 14945c87c606SMark Murray 1495e71b7053SJung-uk Kimif ($disabled{"dynamic-engine"}) { 1496e71b7053SJung-uk Kim $config{dynamic_engines} = 0; 1497e71b7053SJung-uk Kim} else { 1498e71b7053SJung-uk Kim $config{dynamic_engines} = 1; 1499ddd58736SKris Kennaway} 1500ddd58736SKris Kennaway 1501b077aed3SPierre Proncheryunless ($disabled{asan} || defined $detected_sanitizers{asan}) { 1502e71b7053SJung-uk Kim push @{$config{cflags}}, "-fsanitize=address"; 150374664626SKris Kennaway} 150474664626SKris Kennaway 1505b077aed3SPierre Proncheryunless ($disabled{ubsan} || defined $detected_sanitizers{ubsan}) { 1506b077aed3SPierre Pronchery push @{$config{cflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all", "-DPEDANTIC"; 150774664626SKris Kennaway} 150874664626SKris Kennaway 1509b077aed3SPierre Proncheryunless ($disabled{msan} || defined $detected_sanitizers{msan}) { 1510e71b7053SJung-uk Kim push @{$config{cflags}}, "-fsanitize=memory"; 15115c87c606SMark Murray} 15125c87c606SMark Murray 1513e71b7053SJung-uk Kimunless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"} 1514e71b7053SJung-uk Kim && $disabled{asan} && $disabled{ubsan} && $disabled{msan}) { 1515e71b7053SJung-uk Kim push @{$config{cflags}}, "-fno-omit-frame-pointer", "-g"; 1516e71b7053SJung-uk Kim push @{$config{cxxflags}}, "-fno-omit-frame-pointer", "-g" if $config{CXX}; 151774664626SKris Kennaway} 1518db522d3aSSimon L. B. Nielsen# 1519db522d3aSSimon L. B. Nielsen# Platform fix-ups 1520db522d3aSSimon L. B. Nielsen# 1521db522d3aSSimon L. B. Nielsen 1522e71b7053SJung-uk Kim# This saves the build files from having to check 1523e71b7053SJung-uk Kimif ($disabled{pic}) 1524db522d3aSSimon L. B. Nielsen { 1525e71b7053SJung-uk Kim foreach (qw(shared_cflag shared_cxxflag shared_cppflag 1526e71b7053SJung-uk Kim shared_defines shared_includes shared_ldflag 1527e71b7053SJung-uk Kim module_cflags module_cxxflags module_cppflags 1528e71b7053SJung-uk Kim module_defines module_includes module_lflags)) 1529e71b7053SJung-uk Kim { 1530e71b7053SJung-uk Kim delete $config{$_}; 1531e71b7053SJung-uk Kim $target{$_} = ""; 1532ddd58736SKris Kennaway } 1533aeb5019cSJung-uk Kim } 1534aeb5019cSJung-uk Kimelse 1535aeb5019cSJung-uk Kim { 1536e71b7053SJung-uk Kim push @{$config{lib_defines}}, "OPENSSL_PIC"; 1537aeb5019cSJung-uk Kim } 1538e71b7053SJung-uk Kim 1539e71b7053SJung-uk Kimif ($target{sys_id} ne "") 154074664626SKris Kennaway { 1541e71b7053SJung-uk Kim push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}"; 15423b4e3dcbSSimon L. B. Nielsen } 1543e71b7053SJung-uk Kim 1544610a21fdSJung-uk Kimmy %predefined_C = compiler_predefined($config{CROSS_COMPILE}.$config{CC}); 1545610a21fdSJung-uk Kimmy %predefined_CXX = $config{CXX} 1546610a21fdSJung-uk Kim ? compiler_predefined($config{CROSS_COMPILE}.$config{CXX}) 1547610a21fdSJung-uk Kim : (); 15484f20a5a2SJacques Vidrine 1549b077aed3SPierre Proncheryunless ($disabled{asm}) { 1550b077aed3SPierre Pronchery # big endian systems can use ELFv2 ABI 1551b077aed3SPierre Pronchery if ($target eq "linux-ppc64") { 1552b077aed3SPierre Pronchery $target{perlasm_scheme} = "linux64v2" if ($predefined_C{_CALL_ELF} == 2); 1553b077aed3SPierre Pronchery } 1554b077aed3SPierre Pronchery} 1555b077aed3SPierre Pronchery 1556e71b7053SJung-uk Kim# Check for makedepend capabilities. 1557e71b7053SJung-uk Kimif (!$disabled{makedepend}) { 1558b077aed3SPierre Pronchery # If the attribute makedep_scheme is defined, then we assume that the 1559b077aed3SPierre Pronchery # config target and its associated build file are programmed to deal 1560b077aed3SPierre Pronchery # with it. 1561b077aed3SPierre Pronchery # If makedep_scheme is undefined, we go looking for GCC compatible 1562b077aed3SPierre Pronchery # dependency making, and if that's not available, we try to fall back 1563b077aed3SPierre Pronchery # on 'makedepend'. 1564b077aed3SPierre Pronchery if ($target{makedep_scheme}) { 1565b077aed3SPierre Pronchery $config{makedep_scheme} = $target{makedep_scheme}; 1566b077aed3SPierre Pronchery # If the makedepcmd attribute is defined, copy it. If not, the 1567b077aed3SPierre Pronchery # build files will have to fend for themselves. 1568b077aed3SPierre Pronchery $config{makedepcmd} = $target{makedepcmd} if $target{makedepcmd}; 1569610a21fdSJung-uk Kim } elsif (($predefined_C{__GNUC__} // -1) >= 3 1570610a21fdSJung-uk Kim && !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) { 1571e71b7053SJung-uk Kim # We know that GNU C version 3 and up as well as all clang 1572e71b7053SJung-uk Kim # versions support dependency generation, but Xcode did not 1573e71b7053SJung-uk Kim # handle $cc -M before clang support (but claims __GNUC__ = 3) 1574b077aed3SPierre Pronchery $config{makedep_scheme} = 'gcc'; 1575e71b7053SJung-uk Kim } else { 1576b077aed3SPierre Pronchery # In all other cases, we look for 'makedepend', and set the 1577b077aed3SPierre Pronchery # makedep_scheme value if we found it. 1578b077aed3SPierre Pronchery $config{makedepcmd} = which('makedepend'); 1579b077aed3SPierre Pronchery $config{makedep_scheme} = 'makedepend' if $config{makedepcmd}; 158074664626SKris Kennaway } 1581b077aed3SPierre Pronchery 1582b077aed3SPierre Pronchery # If no depend scheme is set, we disable makedepend 1583b077aed3SPierre Pronchery disable('unavailable', 'makedepend') unless $config{makedep_scheme}; 158474664626SKris Kennaway} 158574664626SKris Kennaway 1586610a21fdSJung-uk Kimif (!$disabled{asm} && !$predefined_C{__MACH__} && $^O ne 'VMS') { 1587e71b7053SJung-uk Kim # probe for -Wa,--noexecstack option... 1588610a21fdSJung-uk Kim if ($predefined_C{__clang__}) { 1589e71b7053SJung-uk Kim # clang has builtin assembler, which doesn't recognize --help, 1590e71b7053SJung-uk Kim # but it apparently recognizes the option in question on all 1591e71b7053SJung-uk Kim # supported platforms even when it's meaningless. In other words 1592e71b7053SJung-uk Kim # probe would fail, but probed option always accepted... 1593e71b7053SJung-uk Kim push @{$config{cflags}}, "-Wa,--noexecstack", "-Qunused-arguments"; 1594e71b7053SJung-uk Kim } else { 1595e71b7053SJung-uk Kim my $cc = $config{CROSS_COMPILE}.$config{CC}; 1596e71b7053SJung-uk Kim open(PIPE, "$cc -Wa,--help -c -o null.$$.o -x assembler /dev/null 2>&1 |"); 1597dee36b4fSJung-uk Kim while(<PIPE>) { 1598e71b7053SJung-uk Kim if (m/--noexecstack/) { 1599e71b7053SJung-uk Kim push @{$config{cflags}}, "-Wa,--noexecstack"; 1600e71b7053SJung-uk Kim last; 1601e71b7053SJung-uk Kim } 1602dee36b4fSJung-uk Kim } 1603dee36b4fSJung-uk Kim close(PIPE); 1604e71b7053SJung-uk Kim unlink("null.$$.o"); 1605e71b7053SJung-uk Kim } 1606e71b7053SJung-uk Kim} 160780815a77SJung-uk Kim 1608e71b7053SJung-uk Kim# Deal with bn_ops ################################################### 1609e71b7053SJung-uk Kim 1610e71b7053SJung-uk Kim$config{bn_ll} =0; 1611e71b7053SJung-uk Kimmy $def_int="unsigned int"; 1612e71b7053SJung-uk Kim$config{rc4_int} =$def_int; 1613e71b7053SJung-uk Kim($config{b64l},$config{b64},$config{b32})=(0,0,1); 1614e71b7053SJung-uk Kim 1615e71b7053SJung-uk Kimmy $count = 0; 1616e71b7053SJung-uk Kimforeach (sort split(/\s+/,$target{bn_ops})) { 1617e71b7053SJung-uk Kim $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/; 1618e71b7053SJung-uk Kim $config{bn_ll}=1 if $_ eq 'BN_LLONG'; 1619e71b7053SJung-uk Kim $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR'; 1620e71b7053SJung-uk Kim ($config{b64l},$config{b64},$config{b32}) 1621e71b7053SJung-uk Kim =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT'; 1622e71b7053SJung-uk Kim ($config{b64l},$config{b64},$config{b32}) 1623e71b7053SJung-uk Kim =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG'; 1624e71b7053SJung-uk Kim ($config{b64l},$config{b64},$config{b32}) 1625e71b7053SJung-uk Kim =(0,0,1) if $_ eq 'THIRTY_TWO_BIT'; 1626e71b7053SJung-uk Kim} 1627e71b7053SJung-uk Kimdie "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n" 1628e71b7053SJung-uk Kim if $count > 1; 1629e71b7053SJung-uk Kim 1630b077aed3SPierre Pronchery$config{api} = $config{major} * 10000 + $config{minor} * 100 1631b077aed3SPierre Pronchery unless $config{api}; 1632b077aed3SPierre Proncheryforeach (keys %$apitable) { 1633b077aed3SPierre Pronchery $disabled{"deprecated-$_"} = "deprecation" 1634b077aed3SPierre Pronchery if $disabled{deprecated} && $config{api} >= $apitable->{$_}; 1635b077aed3SPierre Pronchery} 1636b077aed3SPierre Pronchery 1637b077aed3SPierre Proncherydisable(); # Run a cascade now 1638e71b7053SJung-uk Kim 1639e71b7053SJung-uk Kim# Hack cflags for better warnings (dev option) ####################### 1640e71b7053SJung-uk Kim 1641e71b7053SJung-uk Kim# "Stringify" the C and C++ flags string. This permits it to be made part of 1642e71b7053SJung-uk Kim# a string and works as well on command lines. 1643e71b7053SJung-uk Kim$config{cflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x } 1644e71b7053SJung-uk Kim @{$config{cflags}} ]; 1645e71b7053SJung-uk Kim$config{cxxflags} = [ map { (my $x = $_) =~ s/([\\\"])/\\$1/g; $x } 1646e71b7053SJung-uk Kim @{$config{cxxflags}} ] if $config{CXX}; 1647e71b7053SJung-uk Kim 1648b077aed3SPierre Pronchery$config{openssl_api_defines} = [ 1649b077aed3SPierre Pronchery "OPENSSL_CONFIGURED_API=".$config{api}, 1650b077aed3SPierre Pronchery]; 1651dea77ea6SJung-uk Kim 1652610a21fdSJung-uk Kimmy @strict_warnings_collection=(); 165380815a77SJung-uk Kimif ($strict_warnings) 165480815a77SJung-uk Kim { 16556a599222SSimon L. B. Nielsen my $wopt; 1656610a21fdSJung-uk Kim my $gccver = $predefined_C{__GNUC__} // -1; 1657e71b7053SJung-uk Kim 165817f01e99SJung-uk Kim if ($gccver >= 4) 165917f01e99SJung-uk Kim { 1660610a21fdSJung-uk Kim push @strict_warnings_collection, @gcc_devteam_warn; 1661610a21fdSJung-uk Kim push @strict_warnings_collection, @clang_devteam_warn 1662610a21fdSJung-uk Kim if (defined($predefined_C{__clang__})); 16636a599222SSimon L. B. Nielsen } 166417f01e99SJung-uk Kim elsif ($config{target} =~ /^VC-/) 166517f01e99SJung-uk Kim { 166617f01e99SJung-uk Kim push @strict_warnings_collection, @cl_devteam_warn; 166717f01e99SJung-uk Kim } 166817f01e99SJung-uk Kim else 166917f01e99SJung-uk Kim { 167017f01e99SJung-uk Kim warn "WARNING --strict-warnings requires gcc[>=4] or gcc-alike, or MSVC" 167117f01e99SJung-uk Kim } 167217f01e99SJung-uk Kim } 1673610a21fdSJung-uk Kim 1674610a21fdSJung-uk Kim$config{CFLAGS} = [ map { $_ eq '--ossl-strict-warnings' 1675610a21fdSJung-uk Kim ? @strict_warnings_collection 1676610a21fdSJung-uk Kim : ( $_ ) } 1677610a21fdSJung-uk Kim @{$config{CFLAGS}} ]; 16786a599222SSimon L. B. Nielsen 1679e71b7053SJung-uk Kimunless ($disabled{afalgeng}) { 1680e71b7053SJung-uk Kim $config{afalgeng}=""; 1681e71b7053SJung-uk Kim if (grep { $_ eq 'afalgeng' } @{$target{enable}}) { 1682e71b7053SJung-uk Kim my $minver = 4*10000 + 1*100 + 0; 1683e71b7053SJung-uk Kim if ($config{CROSS_COMPILE} eq "") { 1684e71b7053SJung-uk Kim my $verstr = `uname -r`; 1685e71b7053SJung-uk Kim my ($ma, $mi1, $mi2) = split("\\.", $verstr); 1686e71b7053SJung-uk Kim ($mi2) = $mi2 =~ /(\d+)/; 1687e71b7053SJung-uk Kim my $ver = $ma*10000 + $mi1*100 + $mi2; 1688e71b7053SJung-uk Kim if ($ver < $minver) { 1689610a21fdSJung-uk Kim disable('too-old-kernel', 'afalgeng'); 1690e71b7053SJung-uk Kim } else { 1691e71b7053SJung-uk Kim push @{$config{engdirs}}, "afalg"; 1692e71b7053SJung-uk Kim } 1693e71b7053SJung-uk Kim } else { 1694610a21fdSJung-uk Kim disable('cross-compiling', 'afalgeng'); 1695e71b7053SJung-uk Kim } 1696e71b7053SJung-uk Kim } else { 1697610a21fdSJung-uk Kim disable('not-linux', 'afalgeng'); 1698e71b7053SJung-uk Kim } 1699e71b7053SJung-uk Kim} 1700f579bf8eSKris Kennaway 170117f01e99SJung-uk Kimunless ($disabled{devcryptoeng}) { 170217f01e99SJung-uk Kim if ($target =~ m/^BSD/) { 170317f01e99SJung-uk Kim my $maxver = 5*100 + 7; 170417f01e99SJung-uk Kim my $sysstr = `uname -s`; 170517f01e99SJung-uk Kim my $verstr = `uname -r`; 170617f01e99SJung-uk Kim $sysstr =~ s|\R$||; 170717f01e99SJung-uk Kim $verstr =~ s|\R$||; 170817f01e99SJung-uk Kim my ($ma, $mi, @rest) = split m|\.|, $verstr; 170917f01e99SJung-uk Kim my $ver = $ma*100 + $mi; 171017f01e99SJung-uk Kim if ($sysstr eq 'OpenBSD' && $ver >= $maxver) { 171117f01e99SJung-uk Kim disable('too-new-kernel', 'devcryptoeng'); 171217f01e99SJung-uk Kim } 171317f01e99SJung-uk Kim } 171417f01e99SJung-uk Kim} 1715e71b7053SJung-uk Kim 1716aa906e2aSJohn Baldwinunless ($disabled{ktls}) { 1717aa906e2aSJohn Baldwin $config{ktls}=""; 1718b077aed3SPierre Pronchery my $cc = $config{CROSS_COMPILE}.$config{CC}; 1719aa906e2aSJohn Baldwin if ($target =~ m/^linux/) { 1720b077aed3SPierre Pronchery system("printf '#include <sys/types.h>\n#include <linux/tls.h>' | $cc -E - >/dev/null 2>&1"); 1721b077aed3SPierre Pronchery if ($? != 0) { 1722aa906e2aSJohn Baldwin disable('too-old-kernel', 'ktls'); 1723aa906e2aSJohn Baldwin } 1724aa906e2aSJohn Baldwin } elsif ($target =~ m/^BSD/) { 1725aa906e2aSJohn Baldwin system("printf '#include <sys/types.h>\n#include <sys/ktls.h>' | $cc -E - >/dev/null 2>&1"); 1726aa906e2aSJohn Baldwin if ($? != 0) { 1727aa906e2aSJohn Baldwin disable('too-old-freebsd', 'ktls'); 1728aa906e2aSJohn Baldwin } 1729aa906e2aSJohn Baldwin } else { 1730aa906e2aSJohn Baldwin disable('not-linux-or-freebsd', 'ktls'); 1731aa906e2aSJohn Baldwin } 1732aa906e2aSJohn Baldwin} 1733aa906e2aSJohn Baldwin 1734aa906e2aSJohn Baldwinpush @{$config{openssl_other_defines}}, "OPENSSL_NO_KTLS" if ($disabled{ktls}); 1735aa906e2aSJohn Baldwin 1736610a21fdSJung-uk Kim# Get the extra flags used when building shared libraries and modules. We 1737610a21fdSJung-uk Kim# do this late because some of them depend on %disabled. 1738e71b7053SJung-uk Kim 1739610a21fdSJung-uk Kim# Make the flags to build DSOs the same as for shared libraries unless they 1740610a21fdSJung-uk Kim# are already defined 1741610a21fdSJung-uk Kim$target{module_cflags} = $target{shared_cflag} unless defined $target{module_cflags}; 1742610a21fdSJung-uk Kim$target{module_cxxflags} = $target{shared_cxxflag} unless defined $target{module_cxxflags}; 1743610a21fdSJung-uk Kim$target{module_ldflags} = $target{shared_ldflag} unless defined $target{module_ldflags}; 1744610a21fdSJung-uk Kim{ 1745610a21fdSJung-uk Kim my $shared_info_pl = 1746610a21fdSJung-uk Kim catfile(dirname($0), "Configurations", "shared-info.pl"); 1747610a21fdSJung-uk Kim my %shared_info = read_eval_file($shared_info_pl); 1748610a21fdSJung-uk Kim push @{$target{_conf_fname_int}}, $shared_info_pl; 1749610a21fdSJung-uk Kim my $si = $target{shared_target}; 1750610a21fdSJung-uk Kim while (ref $si ne "HASH") { 1751610a21fdSJung-uk Kim last if ! defined $si; 1752610a21fdSJung-uk Kim if (ref $si eq "CODE") { 1753610a21fdSJung-uk Kim $si = $si->(); 1754e71b7053SJung-uk Kim } else { 1755610a21fdSJung-uk Kim $si = $shared_info{$si}; 1756e71b7053SJung-uk Kim } 1757e71b7053SJung-uk Kim } 1758e71b7053SJung-uk Kim 1759610a21fdSJung-uk Kim # Some of the 'shared_target' values don't have any entries in 1760610a21fdSJung-uk Kim # %shared_info. That's perfectly fine, AS LONG AS the build file 1761610a21fdSJung-uk Kim # template knows how to handle this. That is currently the case for 1762610a21fdSJung-uk Kim # Windows and VMS. 1763610a21fdSJung-uk Kim if (defined $si) { 1764610a21fdSJung-uk Kim # Just as above, copy certain shared_* attributes to the corresponding 1765610a21fdSJung-uk Kim # module_ attribute unless the latter is already defined 1766610a21fdSJung-uk Kim $si->{module_cflags} = $si->{shared_cflag} unless defined $si->{module_cflags}; 1767610a21fdSJung-uk Kim $si->{module_cxxflags} = $si->{shared_cxxflag} unless defined $si->{module_cxxflags}; 1768610a21fdSJung-uk Kim $si->{module_ldflags} = $si->{shared_ldflag} unless defined $si->{module_ldflags}; 1769610a21fdSJung-uk Kim foreach (sort keys %$si) { 1770610a21fdSJung-uk Kim $target{$_} = defined $target{$_} 1771610a21fdSJung-uk Kim ? add($si->{$_})->($target{$_}) 1772610a21fdSJung-uk Kim : $si->{$_}; 1773610a21fdSJung-uk Kim } 1774610a21fdSJung-uk Kim } 1775610a21fdSJung-uk Kim} 1776610a21fdSJung-uk Kim 1777610a21fdSJung-uk Kim# ALL MODIFICATIONS TO %disabled, %config and %target MUST BE DONE FROM HERE ON 1778e71b7053SJung-uk Kim 1779b077aed3SPierre Pronchery###################################################################### 1780b077aed3SPierre Pronchery# Build up information for skipping certain directories depending on disabled 1781b077aed3SPierre Pronchery# features, as well as setting up macros for disabled features. 1782b077aed3SPierre Pronchery 1783b077aed3SPierre Pronchery# This is a tentative database of directories to skip. Some entries may not 1784b077aed3SPierre Pronchery# correspond to anything real, but that's ok, they will simply be ignored. 1785b077aed3SPierre Pronchery# The actual processing of these entries is done in the build.info lookup 1786b077aed3SPierre Pronchery# loop further down. 1787b077aed3SPierre Pronchery# 1788b077aed3SPierre Pronchery# The key is a Unix formatted path in the source tree, the value is an index 1789b077aed3SPierre Pronchery# into %disabled_info, so any existing path gets added to a corresponding 1790b077aed3SPierre Pronchery# 'skipped' entry in there with the list of skipped directories. 1791b077aed3SPierre Proncherymy %skipdir = (); 179217f01e99SJung-uk Kimmy %disabled_info = (); # For configdata.pm 179317f01e99SJung-uk Kimforeach my $what (sort keys %disabled) { 1794b077aed3SPierre Pronchery # There are deprecated disablables that translate to themselves. 1795b077aed3SPierre Pronchery # They cause disabling cascades, but should otherwise not regiter. 1796b077aed3SPierre Pronchery next if $deprecated_disablables{$what}; 1797b077aed3SPierre Pronchery # The generated $disabled{"deprecated-x.y"} entries are special 1798b077aed3SPierre Pronchery # and treated properly elsewhere 1799b077aed3SPierre Pronchery next if $what =~ m|^deprecated-|; 1800b077aed3SPierre Pronchery 180117f01e99SJung-uk Kim $config{options} .= " no-$what"; 180217f01e99SJung-uk Kim 1803b077aed3SPierre Pronchery if (!grep { $what eq $_ } ( 'buildtest-c++', 'fips', 'threads', 'shared', 1804b077aed3SPierre Pronchery 'module', 'pic', 'dynamic-engine', 'makedepend', 1805b077aed3SPierre Pronchery 'zlib-dynamic', 'zlib', 'sse2', 'legacy' )) { 180617f01e99SJung-uk Kim (my $WHAT = uc $what) =~ s|-|_|g; 1807b077aed3SPierre Pronchery my $skipdir = $what; 180817f01e99SJung-uk Kim 180917f01e99SJung-uk Kim # fix-up crypto/directory name(s) 1810b077aed3SPierre Pronchery $skipdir = "ripemd" if $what eq "rmd160"; 1811b077aed3SPierre Pronchery $skipdir = "whrlpool" if $what eq "whirlpool"; 181217f01e99SJung-uk Kim 181317f01e99SJung-uk Kim my $macro = $disabled_info{$what}->{macro} = "OPENSSL_NO_$WHAT"; 1814b077aed3SPierre Pronchery push @{$config{openssl_feature_defines}}, $macro; 181517f01e99SJung-uk Kim 1816b077aed3SPierre Pronchery $skipdir{engines} = $what if $what eq 'engine'; 1817b077aed3SPierre Pronchery $skipdir{"crypto/$skipdir"} = $what 1818b077aed3SPierre Pronchery unless $what eq 'async' || $what eq 'err' || $what eq 'dso'; 181917f01e99SJung-uk Kim } 182017f01e99SJung-uk Kim} 182117f01e99SJung-uk Kim 182217f01e99SJung-uk Kimif ($disabled{"dynamic-engine"}) { 1823b077aed3SPierre Pronchery push @{$config{openssl_feature_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE"; 182417f01e99SJung-uk Kim} else { 1825b077aed3SPierre Pronchery push @{$config{openssl_feature_defines}}, "OPENSSL_NO_STATIC_ENGINE"; 182617f01e99SJung-uk Kim} 182717f01e99SJung-uk Kim 1828e71b7053SJung-uk Kim# If we use the unified build, collect information from build.info files 1829e71b7053SJung-uk Kimmy %unified_info = (); 1830e71b7053SJung-uk Kim 1831e71b7053SJung-uk Kimmy $buildinfo_debug = defined($ENV{CONFIGURE_DEBUG_BUILDINFO}); 1832e71b7053SJung-uk Kimif ($builder eq "unified") { 1833b077aed3SPierre Pronchery use Text::Template 1.46; 1834e71b7053SJung-uk Kim 1835e71b7053SJung-uk Kim sub cleandir { 1836e71b7053SJung-uk Kim my $base = shift; 1837e71b7053SJung-uk Kim my $dir = shift; 1838e71b7053SJung-uk Kim my $relativeto = shift || "."; 1839e0c4386eSCy Schubert my $no_mkpath = shift // 0; 1840e71b7053SJung-uk Kim 1841e71b7053SJung-uk Kim $dir = catdir($base,$dir) unless isabsolute($dir); 1842e71b7053SJung-uk Kim 1843e71b7053SJung-uk Kim # Make sure the directories we're building in exists 1844e0c4386eSCy Schubert mkpath($dir) unless $no_mkpath; 1845e71b7053SJung-uk Kim 1846e71b7053SJung-uk Kim my $res = abs2rel(absolutedir($dir), rel2abs($relativeto)); 1847e71b7053SJung-uk Kim #print STDERR "DEBUG[cleandir]: $dir , $base => $res\n"; 1848e71b7053SJung-uk Kim return $res; 1849e71b7053SJung-uk Kim } 1850e71b7053SJung-uk Kim 1851e71b7053SJung-uk Kim sub cleanfile { 1852e71b7053SJung-uk Kim my $base = shift; 1853e71b7053SJung-uk Kim my $file = shift; 1854e71b7053SJung-uk Kim my $relativeto = shift || "."; 1855e0c4386eSCy Schubert my $no_mkpath = shift // 0; 1856e71b7053SJung-uk Kim 1857e71b7053SJung-uk Kim $file = catfile($base,$file) unless isabsolute($file); 1858e71b7053SJung-uk Kim 1859e71b7053SJung-uk Kim my $d = dirname($file); 1860e71b7053SJung-uk Kim my $f = basename($file); 1861e71b7053SJung-uk Kim 1862e71b7053SJung-uk Kim # Make sure the directories we're building in exists 1863e0c4386eSCy Schubert mkpath($d) unless $no_mkpath; 1864e71b7053SJung-uk Kim 1865e71b7053SJung-uk Kim my $res = abs2rel(catfile(absolutedir($d), $f), rel2abs($relativeto)); 1866e71b7053SJung-uk Kim #print STDERR "DEBUG[cleanfile]: $d , $f => $res\n"; 1867e71b7053SJung-uk Kim return $res; 1868e71b7053SJung-uk Kim } 1869e71b7053SJung-uk Kim 1870e71b7053SJung-uk Kim # Store the name of the template file we will build the build file from 1871e71b7053SJung-uk Kim # in %config. This may be useful for the build file itself. 1872e71b7053SJung-uk Kim my @build_file_template_names = 1873640242a5SJung-uk Kim ( $builder_platform."-".$config{build_file}.".tmpl", 1874640242a5SJung-uk Kim $config{build_file}.".tmpl" ); 1875e71b7053SJung-uk Kim my @build_file_templates = (); 1876e71b7053SJung-uk Kim 1877e71b7053SJung-uk Kim # First, look in the user provided directory, if given 1878e71b7053SJung-uk Kim if (defined env($local_config_envname)) { 1879e71b7053SJung-uk Kim @build_file_templates = 1880e71b7053SJung-uk Kim map { 1881e71b7053SJung-uk Kim if ($^O eq 'VMS') { 1882e71b7053SJung-uk Kim # VMS environment variables are logical names, 1883e71b7053SJung-uk Kim # which can be used as is 1884e71b7053SJung-uk Kim $local_config_envname . ':' . $_; 1885e71b7053SJung-uk Kim } else { 1886e71b7053SJung-uk Kim catfile(env($local_config_envname), $_); 1887e71b7053SJung-uk Kim } 1888e71b7053SJung-uk Kim } 1889e71b7053SJung-uk Kim @build_file_template_names; 1890e71b7053SJung-uk Kim } 1891e71b7053SJung-uk Kim # Then, look in our standard directory 1892e71b7053SJung-uk Kim push @build_file_templates, 1893e0c4386eSCy Schubert ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir, 1) } 1894e71b7053SJung-uk Kim @build_file_template_names ); 1895e71b7053SJung-uk Kim 1896e71b7053SJung-uk Kim my $build_file_template; 1897e71b7053SJung-uk Kim for $_ (@build_file_templates) { 1898e71b7053SJung-uk Kim $build_file_template = $_; 1899e71b7053SJung-uk Kim last if -f $build_file_template; 1900e71b7053SJung-uk Kim 1901e71b7053SJung-uk Kim $build_file_template = undef; 1902e71b7053SJung-uk Kim } 1903e71b7053SJung-uk Kim if (!defined $build_file_template) { 1904e71b7053SJung-uk Kim die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n"; 1905e71b7053SJung-uk Kim } 1906e71b7053SJung-uk Kim $config{build_file_templates} 1907e71b7053SJung-uk Kim = [ cleanfile($srcdir, catfile("Configurations", "common0.tmpl"), 1908e0c4386eSCy Schubert $blddir, 1), 1909b077aed3SPierre Pronchery $build_file_template ]; 1910e71b7053SJung-uk Kim 1911b077aed3SPierre Pronchery my @build_dirs = ( [ ] ); # current directory 1912e71b7053SJung-uk Kim 1913e71b7053SJung-uk Kim $config{build_infos} = [ ]; 1914e71b7053SJung-uk Kim 1915e71b7053SJung-uk Kim # We want to detect configdata.pm in the source tree, so we 1916e71b7053SJung-uk Kim # don't use it if the build tree is different. 1917e0c4386eSCy Schubert my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir, 1); 1918e71b7053SJung-uk Kim 1919b077aed3SPierre Pronchery # Any source file that we recognise is placed in this hash table, with 1920b077aed3SPierre Pronchery # the list of its intended destinations as value. When everything has 1921b077aed3SPierre Pronchery # been collected, there's a routine that checks that these source files 1922b077aed3SPierre Pronchery # exist, or if they are generated, that the generator exists. 1923b077aed3SPierre Pronchery my %check_exist = (); 1924b077aed3SPierre Pronchery my %check_generate = (); 1925b077aed3SPierre Pronchery 1926b077aed3SPierre Pronchery my %ordinals = (); 1927b077aed3SPierre Pronchery while (@build_dirs) { 1928b077aed3SPierre Pronchery my @curd = @{shift @build_dirs}; 1929b077aed3SPierre Pronchery my $sourced = catdir($srcdir, @curd); 1930b077aed3SPierre Pronchery my $buildd = catdir($blddir, @curd); 1931b077aed3SPierre Pronchery 1932b077aed3SPierre Pronchery my $unixdir = join('/', @curd); 1933b077aed3SPierre Pronchery if (exists $skipdir{$unixdir}) { 1934b077aed3SPierre Pronchery my $what = $skipdir{$unixdir}; 1935b077aed3SPierre Pronchery push @{$disabled_info{$what}->{skipped}}, catdir(@curd); 1936b077aed3SPierre Pronchery next; 1937b077aed3SPierre Pronchery } 1938b077aed3SPierre Pronchery 1939b077aed3SPierre Pronchery mkpath($buildd); 1940b077aed3SPierre Pronchery 1941b077aed3SPierre Pronchery my $f = 'build.info'; 1942b077aed3SPierre Pronchery # The basic things we're trying to build 1943b077aed3SPierre Pronchery my @programs = (); 1944b077aed3SPierre Pronchery my @libraries = (); 1945b077aed3SPierre Pronchery my @modules = (); 1946b077aed3SPierre Pronchery my @scripts = (); 1947b077aed3SPierre Pronchery 1948b077aed3SPierre Pronchery my %sources = (); 1949b077aed3SPierre Pronchery my %shared_sources = (); 1950b077aed3SPierre Pronchery my %includes = (); 1951b077aed3SPierre Pronchery my %defines = (); 1952b077aed3SPierre Pronchery my %depends = (); 1953b077aed3SPierre Pronchery my %generate = (); 1954b077aed3SPierre Pronchery my %imagedocs = (); 1955b077aed3SPierre Pronchery my %htmldocs = (); 1956b077aed3SPierre Pronchery my %mandocs = (); 1957b077aed3SPierre Pronchery 1958b077aed3SPierre Pronchery # Support for $variablename in build.info files. 1959b077aed3SPierre Pronchery # Embedded perl code is the ultimate master, still. If its output 1960b077aed3SPierre Pronchery # contains a dollar sign, it had better be escaped, or it will be 1961b077aed3SPierre Pronchery # taken for a variable name prefix. 1962b077aed3SPierre Pronchery my %variables = (); 1963b077aed3SPierre Pronchery # Variable name syntax 1964b077aed3SPierre Pronchery my $variable_name_re = qr/(?P<VARIABLE>[[:alpha:]][[:alnum:]_]*)/; 1965b077aed3SPierre Pronchery # Value modifier syntaxes 1966b077aed3SPierre Pronchery my $variable_subst_re = qr/\/(?P<RE>(?:\\\/|.)*?)\/(?P<SUBST>.*?)/; 1967b077aed3SPierre Pronchery # Variable reference 1968b077aed3SPierre Pronchery my $variable_simple_re = qr/(?<!\\)\$${variable_name_re}/; 1969b077aed3SPierre Pronchery my $variable_w_mod_re = 1970b077aed3SPierre Pronchery qr/(?<!\\)\$\{${variable_name_re}(?P<MOD>(?:\\\/|.)*?)\}/; 1971b077aed3SPierre Pronchery # Tie it all together 1972b077aed3SPierre Pronchery my $variable_re = qr/${variable_simple_re}|${variable_w_mod_re}/; 1973b077aed3SPierre Pronchery 1974b077aed3SPierre Pronchery my $expand_variables = sub { 1975b077aed3SPierre Pronchery my $value = ''; 1976b077aed3SPierre Pronchery my $value_rest = shift; 1977b077aed3SPierre Pronchery 1978b077aed3SPierre Pronchery if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) { 1979b077aed3SPierre Pronchery print STDERR 1980b077aed3SPierre Pronchery "DEBUG[\$expand_variables] Parsed '$value_rest' ...\n" 1981b077aed3SPierre Pronchery } 1982b077aed3SPierre Pronchery 1983b077aed3SPierre Pronchery while ($value_rest =~ /${variable_re}/) { 1984b077aed3SPierre Pronchery # We must save important regexp values, because the next 1985b077aed3SPierre Pronchery # regexp clears them 1986b077aed3SPierre Pronchery my $mod = $+{MOD}; 1987b077aed3SPierre Pronchery my $variable_value = $variables{$+{VARIABLE}}; 1988b077aed3SPierre Pronchery 1989b077aed3SPierre Pronchery $value_rest = $'; 1990b077aed3SPierre Pronchery $value .= $`; 1991b077aed3SPierre Pronchery 1992b077aed3SPierre Pronchery # Process modifier expressions, if present 1993b077aed3SPierre Pronchery if (defined $mod) { 1994b077aed3SPierre Pronchery if ($mod =~ /^${variable_subst_re}$/) { 1995b077aed3SPierre Pronchery my $re = $+{RE}; 1996b077aed3SPierre Pronchery my $subst = $+{SUBST}; 1997b077aed3SPierre Pronchery 1998b077aed3SPierre Pronchery $variable_value =~ s/\Q$re\E/$subst/g; 1999b077aed3SPierre Pronchery 2000b077aed3SPierre Pronchery if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) { 2001b077aed3SPierre Pronchery print STDERR 2002b077aed3SPierre Pronchery "DEBUG[\$expand_variables] ... and substituted ", 2003b077aed3SPierre Pronchery "'$re' with '$subst'\n"; 2004b077aed3SPierre Pronchery } 2005b077aed3SPierre Pronchery } 2006b077aed3SPierre Pronchery } 2007b077aed3SPierre Pronchery 2008b077aed3SPierre Pronchery $value .= $variable_value; 2009b077aed3SPierre Pronchery } 2010b077aed3SPierre Pronchery if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) { 2011b077aed3SPierre Pronchery print STDERR 2012b077aed3SPierre Pronchery "DEBUG[\$expand_variables] ... into: '$value$value_rest'\n"; 2013b077aed3SPierre Pronchery } 2014b077aed3SPierre Pronchery return $value . $value_rest; 2015b077aed3SPierre Pronchery }; 2016b077aed3SPierre Pronchery 2017b077aed3SPierre Pronchery # Support for attributes in build.info files 2018b077aed3SPierre Pronchery my %attributes = (); 2019b077aed3SPierre Pronchery my $handle_attributes = sub { 2020b077aed3SPierre Pronchery my $attr_str = shift; 2021b077aed3SPierre Pronchery my $ref = shift; 2022b077aed3SPierre Pronchery my @goals = @_; 2023b077aed3SPierre Pronchery 2024b077aed3SPierre Pronchery return unless defined $attr_str; 2025b077aed3SPierre Pronchery 2026b077aed3SPierre Pronchery my @a = tokenize($attr_str, qr|\s*,\s*|); 2027b077aed3SPierre Pronchery foreach my $a (@a) { 2028b077aed3SPierre Pronchery my $ac = 1; 2029b077aed3SPierre Pronchery my $ak = $a; 2030b077aed3SPierre Pronchery my $av = 1; 2031b077aed3SPierre Pronchery if ($a =~ m|^(!)?(.*?)\s* = \s*(.*?)$|x) { 2032b077aed3SPierre Pronchery $ac = ! $1; 2033b077aed3SPierre Pronchery $ak = $2; 2034b077aed3SPierre Pronchery $av = $3; 2035b077aed3SPierre Pronchery } 2036b077aed3SPierre Pronchery foreach my $g (@goals) { 2037b077aed3SPierre Pronchery if ($ac) { 2038b077aed3SPierre Pronchery $$ref->{$g}->{$ak} = $av; 2039b077aed3SPierre Pronchery } else { 2040b077aed3SPierre Pronchery delete $$ref->{$g}->{$ak}; 2041b077aed3SPierre Pronchery } 2042b077aed3SPierre Pronchery } 2043b077aed3SPierre Pronchery } 2044b077aed3SPierre Pronchery }; 2045b077aed3SPierre Pronchery 2046b077aed3SPierre Pronchery # Support for pushing values on multiple indexes of a given hash 2047b077aed3SPierre Pronchery # array. 2048b077aed3SPierre Pronchery my $push_to = sub { 2049b077aed3SPierre Pronchery my $valueref = shift; 2050b077aed3SPierre Pronchery my $index_str = shift; # May be undef or empty 2051b077aed3SPierre Pronchery my $attrref = shift; # May be undef 2052b077aed3SPierre Pronchery my $attr_str = shift; 2053b077aed3SPierre Pronchery my @values = @_; 2054b077aed3SPierre Pronchery 2055b077aed3SPierre Pronchery if (defined $index_str) { 2056b077aed3SPierre Pronchery my @indexes = ( '' ); 2057b077aed3SPierre Pronchery if ($index_str !~ m|^\s*$|) { 2058b077aed3SPierre Pronchery @indexes = tokenize($index_str); 2059b077aed3SPierre Pronchery } 2060b077aed3SPierre Pronchery foreach (@indexes) { 2061b077aed3SPierre Pronchery push @{$valueref->{$_}}, @values; 2062b077aed3SPierre Pronchery if (defined $attrref) { 2063b077aed3SPierre Pronchery $handle_attributes->($attr_str, \$$attrref->{$_}, 2064b077aed3SPierre Pronchery @values); 2065b077aed3SPierre Pronchery } 2066b077aed3SPierre Pronchery } 2067b077aed3SPierre Pronchery } else { 2068b077aed3SPierre Pronchery push @$valueref, @values; 2069b077aed3SPierre Pronchery $handle_attributes->($attr_str, $attrref, @values) 2070b077aed3SPierre Pronchery if defined $attrref; 2071b077aed3SPierre Pronchery } 2072b077aed3SPierre Pronchery }; 2073b077aed3SPierre Pronchery 2074b077aed3SPierre Pronchery if ($buildinfo_debug) { 2075b077aed3SPierre Pronchery print STDERR "DEBUG: Reading ",catfile($sourced, $f),"\n"; 2076b077aed3SPierre Pronchery } 2077e71b7053SJung-uk Kim push @{$config{build_infos}}, catfile(abs2rel($sourced, $blddir), $f); 2078e71b7053SJung-uk Kim my $template = 2079e71b7053SJung-uk Kim Text::Template->new(TYPE => 'FILE', 2080e71b7053SJung-uk Kim SOURCE => catfile($sourced, $f), 2081e71b7053SJung-uk Kim PREPEND => qq{use lib "$FindBin::Bin/util/perl";}); 2082e71b7053SJung-uk Kim die "Something went wrong with $sourced/$f: $!\n" unless $template; 2083e71b7053SJung-uk Kim my @text = 2084e71b7053SJung-uk Kim split /^/m, 2085e71b7053SJung-uk Kim $template->fill_in(HASH => { config => \%config, 2086e71b7053SJung-uk Kim target => \%target, 2087e71b7053SJung-uk Kim disabled => \%disabled, 2088e71b7053SJung-uk Kim withargs => \%withargs, 2089e71b7053SJung-uk Kim builddir => abs2rel($buildd, $blddir), 2090e71b7053SJung-uk Kim sourcedir => abs2rel($sourced, $blddir), 2091e71b7053SJung-uk Kim buildtop => abs2rel($blddir, $blddir), 2092e71b7053SJung-uk Kim sourcetop => abs2rel($srcdir, $blddir) }, 2093e71b7053SJung-uk Kim DELIMITERS => [ "{-", "-}" ]); 2094e71b7053SJung-uk Kim 2095e71b7053SJung-uk Kim # The top item of this stack has the following values 2096e71b7053SJung-uk Kim # -2 positive already run and we found ELSE (following ELSIF should fail) 2097e71b7053SJung-uk Kim # -1 positive already run (skip until ENDIF) 2098e71b7053SJung-uk Kim # 0 negatives so far (if we're at a condition, check it) 2099e71b7053SJung-uk Kim # 1 last was positive (don't skip lines until next ELSE, ELSIF or ENDIF) 2100e71b7053SJung-uk Kim # 2 positive ELSE (following ELSIF should fail) 2101e71b7053SJung-uk Kim my @skip = (); 2102b077aed3SPierre Pronchery 2103b077aed3SPierre Pronchery # A few useful generic regexps 2104b077aed3SPierre Pronchery my $index_re = qr/\[\s*(?P<INDEX>(?:\\.|.)*?)\s*\]/; 2105b077aed3SPierre Pronchery my $cond_re = qr/\[\s*(?P<COND>(?:\\.|.)*?)\s*\]/; 2106b077aed3SPierre Pronchery my $attribs_re = qr/(?:\{\s*(?P<ATTRIBS>(?:\\.|.)*?)\s*\})?/; 2107b077aed3SPierre Pronchery my $value_re = qr/(?P<VALUE>.*?)/; 2108e71b7053SJung-uk Kim collect_information( 2109e71b7053SJung-uk Kim collect_from_array([ @text ], 2110e71b7053SJung-uk Kim qr/\\$/ => sub { my $l1 = shift; my $l2 = shift; 2111e71b7053SJung-uk Kim $l1 =~ s/\\$//; $l1.$l2 }), 2112e71b7053SJung-uk Kim # Info we're looking for 2113b077aed3SPierre Pronchery qr/^\s* IF ${cond_re} \s*$/x 2114e71b7053SJung-uk Kim => sub { 2115e71b7053SJung-uk Kim if (! @skip || $skip[$#skip] > 0) { 2116b077aed3SPierre Pronchery push @skip, !! $expand_variables->($+{COND}); 2117e71b7053SJung-uk Kim } else { 2118e71b7053SJung-uk Kim push @skip, -1; 2119e71b7053SJung-uk Kim } 2120e71b7053SJung-uk Kim }, 2121b077aed3SPierre Pronchery qr/^\s* ELSIF ${cond_re} \s*$/x 2122e71b7053SJung-uk Kim => sub { die "ELSIF out of scope" if ! @skip; 2123e71b7053SJung-uk Kim die "ELSIF following ELSE" if abs($skip[$#skip]) == 2; 2124e71b7053SJung-uk Kim $skip[$#skip] = -1 if $skip[$#skip] != 0; 2125b077aed3SPierre Pronchery $skip[$#skip] = !! $expand_variables->($+{COND}) 2126e71b7053SJung-uk Kim if $skip[$#skip] == 0; }, 2127b077aed3SPierre Pronchery qr/^\s* ELSE \s*$/x 2128e71b7053SJung-uk Kim => sub { die "ELSE out of scope" if ! @skip; 2129e71b7053SJung-uk Kim $skip[$#skip] = -2 if $skip[$#skip] != 0; 2130e71b7053SJung-uk Kim $skip[$#skip] = 2 if $skip[$#skip] == 0; }, 2131b077aed3SPierre Pronchery qr/^\s* ENDIF \s*$/x 2132e71b7053SJung-uk Kim => sub { die "ENDIF out of scope" if ! @skip; 2133e71b7053SJung-uk Kim pop @skip; }, 2134b077aed3SPierre Pronchery qr/^\s* ${variable_re} \s* = \s* ${value_re} \s* $/x 2135e71b7053SJung-uk Kim => sub { 2136e71b7053SJung-uk Kim if (!@skip || $skip[$#skip] > 0) { 2137b077aed3SPierre Pronchery $variables{$+{VARIABLE}} = $expand_variables->($+{VALUE}); 2138e71b7053SJung-uk Kim } 2139e71b7053SJung-uk Kim }, 2140b077aed3SPierre Pronchery qr/^\s* SUBDIRS \s* = \s* ${value_re} \s* $/x 2141e71b7053SJung-uk Kim => sub { 2142e71b7053SJung-uk Kim if (!@skip || $skip[$#skip] > 0) { 2143b077aed3SPierre Pronchery foreach (tokenize($expand_variables->($+{VALUE}))) { 2144b077aed3SPierre Pronchery push @build_dirs, [ @curd, splitdir($_, 1) ]; 2145b077aed3SPierre Pronchery } 2146e71b7053SJung-uk Kim } 2147e71b7053SJung-uk Kim }, 2148b077aed3SPierre Pronchery qr/^\s* PROGRAMS ${attribs_re} \s* = \s* ${value_re} \s* $/x 2149b077aed3SPierre Pronchery => sub { $push_to->(\@programs, undef, 2150b077aed3SPierre Pronchery \$attributes{programs}, $+{ATTRIBS}, 2151b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2152b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2153b077aed3SPierre Pronchery qr/^\s* LIBS ${attribs_re} \s* = \s* ${value_re} \s* $/x 2154b077aed3SPierre Pronchery => sub { $push_to->(\@libraries, undef, 2155b077aed3SPierre Pronchery \$attributes{libraries}, $+{ATTRIBS}, 2156b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2157b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2158b077aed3SPierre Pronchery qr/^\s* MODULES ${attribs_re} \s* = \s* ${value_re} \s* $/x 2159b077aed3SPierre Pronchery => sub { $push_to->(\@modules, undef, 2160b077aed3SPierre Pronchery \$attributes{modules}, $+{ATTRIBS}, 2161b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2162b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2163b077aed3SPierre Pronchery qr/^\s* SCRIPTS ${attribs_re} \s* = \s* ${value_re} \s* $/x 2164b077aed3SPierre Pronchery => sub { $push_to->(\@scripts, undef, 2165b077aed3SPierre Pronchery \$attributes{scripts}, $+{ATTRIBS}, 2166b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2167b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2168b077aed3SPierre Pronchery qr/^\s* IMAGEDOCS ${index_re} \s* = \s* ${value_re} \s* $/x 2169b077aed3SPierre Pronchery => sub { $push_to->(\%imagedocs, $expand_variables->($+{INDEX}), 2170b077aed3SPierre Pronchery undef, undef, 2171b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2172b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2173b077aed3SPierre Pronchery qr/^\s* HTMLDOCS ${index_re} \s* = \s* ${value_re} \s* $/x 2174b077aed3SPierre Pronchery => sub { $push_to->(\%htmldocs, $expand_variables->($+{INDEX}), 2175b077aed3SPierre Pronchery undef, undef, 2176b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2177b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2178b077aed3SPierre Pronchery qr/^\s* MANDOCS ${index_re} \s* = \s* ${value_re} \s* $/x 2179b077aed3SPierre Pronchery => sub { $push_to->(\%mandocs, $expand_variables->($+{INDEX}), 2180b077aed3SPierre Pronchery undef, undef, 2181b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2182b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2183b077aed3SPierre Pronchery qr/^\s* SOURCE ${index_re} ${attribs_re} \s* = \s* ${value_re} \s* $/x 2184b077aed3SPierre Pronchery => sub { $push_to->(\%sources, $expand_variables->($+{INDEX}), 2185b077aed3SPierre Pronchery \$attributes{sources}, $+{ATTRIBS}, 2186b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2187b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2188b077aed3SPierre Pronchery qr/^\s* SHARED_SOURCE ${index_re} ${attribs_re} \s* = \s* ${value_re} \s* $/x 2189b077aed3SPierre Pronchery => sub { $push_to->(\%shared_sources, $expand_variables->($+{INDEX}), 2190b077aed3SPierre Pronchery \$attributes{sources}, $+{ATTRIBS}, 2191b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2192b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2193b077aed3SPierre Pronchery qr/^\s* INCLUDE ${index_re} \s* = \s* ${value_re} \s* $/x 2194b077aed3SPierre Pronchery => sub { $push_to->(\%includes, $expand_variables->($+{INDEX}), 2195b077aed3SPierre Pronchery undef, undef, 2196b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2197b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2198b077aed3SPierre Pronchery qr/^\s* DEFINE ${index_re} \s* = \s* ${value_re} \s* $/x 2199b077aed3SPierre Pronchery => sub { $push_to->(\%defines, $expand_variables->($+{INDEX}), 2200b077aed3SPierre Pronchery undef, undef, 2201b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2202b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2203b077aed3SPierre Pronchery qr/^\s* DEPEND ${index_re} ${attribs_re} \s* = \s* ${value_re} \s* $/x 2204b077aed3SPierre Pronchery => sub { $push_to->(\%depends, $expand_variables->($+{INDEX}), 2205b077aed3SPierre Pronchery \$attributes{depends}, $+{ATTRIBS}, 2206b077aed3SPierre Pronchery tokenize($expand_variables->($+{VALUE}))) 2207b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2208b077aed3SPierre Pronchery qr/^\s* GENERATE ${index_re} ${attribs_re} \s* = \s* ${value_re} \s* $/x 2209b077aed3SPierre Pronchery => sub { $push_to->(\%generate, $expand_variables->($+{INDEX}), 2210b077aed3SPierre Pronchery \$attributes{generate}, $+{ATTRIBS}, 2211b077aed3SPierre Pronchery $expand_variables->($+{VALUE})) 2212b077aed3SPierre Pronchery if !@skip || $skip[$#skip] > 0; }, 2213b077aed3SPierre Pronchery qr/^\s* (?:\#.*)? $/x => sub { }, 2214e71b7053SJung-uk Kim "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" }, 2215e71b7053SJung-uk Kim "BEFORE" => sub { 2216e71b7053SJung-uk Kim if ($buildinfo_debug) { 2217e71b7053SJung-uk Kim print STDERR "DEBUG: Parsing ",join(" ", @_),"\n"; 2218e71b7053SJung-uk Kim print STDERR "DEBUG: ... before parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n"; 2219e71b7053SJung-uk Kim } 2220e71b7053SJung-uk Kim }, 2221e71b7053SJung-uk Kim "AFTER" => sub { 2222e71b7053SJung-uk Kim if ($buildinfo_debug) { 2223e71b7053SJung-uk Kim print STDERR "DEBUG: .... after parsing, skip stack is ",join(" ", map { int($_) } @skip),"\n"; 2224e71b7053SJung-uk Kim } 2225e71b7053SJung-uk Kim }, 2226e71b7053SJung-uk Kim ); 2227e71b7053SJung-uk Kim die "runaway IF?" if (@skip); 2228e71b7053SJung-uk Kim 2229b077aed3SPierre Pronchery if (grep { defined $attributes{modules}->{$_}->{engine} } keys %attributes 2230b077aed3SPierre Pronchery and !$config{dynamic_engines}) { 2231b077aed3SPierre Pronchery die <<"EOF" 2232e71b7053SJung-uk KimENGINES can only be used if configured with 'dynamic-engine'. 2233e71b7053SJung-uk KimThis is usually a fault in a build.info file. 2234e71b7053SJung-uk KimEOF 2235e71b7053SJung-uk Kim } 2236e71b7053SJung-uk Kim 2237b077aed3SPierre Pronchery { 2238b077aed3SPierre Pronchery my %infos = ( programs => [ @programs ], 2239b077aed3SPierre Pronchery libraries => [ @libraries ], 2240b077aed3SPierre Pronchery modules => [ @modules ], 2241b077aed3SPierre Pronchery scripts => [ @scripts ] ); 2242b077aed3SPierre Pronchery foreach my $k (keys %infos) { 2243b077aed3SPierre Pronchery foreach (@{$infos{$k}}) { 2244b077aed3SPierre Pronchery my $item = cleanfile($buildd, $_, $blddir); 2245b077aed3SPierre Pronchery $unified_info{$k}->{$item} = 1; 2246e71b7053SJung-uk Kim 2247b077aed3SPierre Pronchery # Fix up associated attributes 2248b077aed3SPierre Pronchery $unified_info{attributes}->{$k}->{$item} = 2249b077aed3SPierre Pronchery $attributes{$k}->{$_} 2250b077aed3SPierre Pronchery if defined $attributes{$k}->{$_}; 2251e71b7053SJung-uk Kim } 2252e71b7053SJung-uk Kim } 2253e71b7053SJung-uk Kim } 2254e71b7053SJung-uk Kim 2255e71b7053SJung-uk Kim # Check that we haven't defined any library as both shared and 2256e71b7053SJung-uk Kim # explicitly static. That is forbidden. 2257e71b7053SJung-uk Kim my @doubles = (); 2258e71b7053SJung-uk Kim foreach (grep /\.a$/, keys %{$unified_info{libraries}}) { 2259e71b7053SJung-uk Kim (my $l = $_) =~ s/\.a$//; 2260b077aed3SPierre Pronchery push @doubles, $l if defined $unified_info{libraries}->{$l}; 2261e71b7053SJung-uk Kim } 2262e71b7053SJung-uk Kim die "these libraries are both explicitly static and shared:\n ", 2263e71b7053SJung-uk Kim join(" ", @doubles), "\n" 2264e71b7053SJung-uk Kim if @doubles; 2265e71b7053SJung-uk Kim 2266e71b7053SJung-uk Kim foreach (keys %sources) { 2267e71b7053SJung-uk Kim my $dest = $_; 2268e71b7053SJung-uk Kim my $ddest = cleanfile($buildd, $_, $blddir); 2269e71b7053SJung-uk Kim foreach (@{$sources{$dest}}) { 2270e0c4386eSCy Schubert my $s = cleanfile($sourced, $_, $blddir, 1); 2271e71b7053SJung-uk Kim 2272b077aed3SPierre Pronchery # If it's generated or we simply don't find it in the source 2273b077aed3SPierre Pronchery # tree, we assume it's in the build tree. 2274b077aed3SPierre Pronchery if ($s eq $src_configdata || $generate{$_} || ! -f $s) { 2275e71b7053SJung-uk Kim $s = cleanfile($buildd, $_, $blddir); 2276e71b7053SJung-uk Kim } 2277b077aed3SPierre Pronchery my $o = $_; 2278e71b7053SJung-uk Kim # We recognise C++, C and asm files 2279e71b7053SJung-uk Kim if ($s =~ /\.(cc|cpp|c|s|S)$/) { 2280b077aed3SPierre Pronchery push @{$check_exist{$s}}, $ddest; 2281e71b7053SJung-uk Kim $o =~ s/\.[csS]$/.o/; # C and assembler 2282e71b7053SJung-uk Kim $o =~ s/\.(cc|cpp)$/_cc.o/; # C++ 2283e71b7053SJung-uk Kim $o = cleanfile($buildd, $o, $blddir); 2284b077aed3SPierre Pronchery $unified_info{sources}->{$ddest}->{$o} = -1; 2285b077aed3SPierre Pronchery $unified_info{sources}->{$o}->{$s} = -1; 2286e71b7053SJung-uk Kim } elsif ($s =~ /\.rc$/) { 2287e71b7053SJung-uk Kim # We also recognise resource files 2288b077aed3SPierre Pronchery push @{$check_exist{$s}}, $ddest; 2289e71b7053SJung-uk Kim $o =~ s/\.rc$/.res/; # Resource configuration 2290b077aed3SPierre Pronchery $o = cleanfile($buildd, $o, $blddir); 2291b077aed3SPierre Pronchery $unified_info{sources}->{$ddest}->{$o} = -1; 2292b077aed3SPierre Pronchery $unified_info{sources}->{$o}->{$s} = -1; 2293e71b7053SJung-uk Kim } else { 2294b077aed3SPierre Pronchery push @{$check_exist{$s}}, $ddest; 2295e71b7053SJung-uk Kim $unified_info{sources}->{$ddest}->{$s} = 1; 2296e71b7053SJung-uk Kim } 2297b077aed3SPierre Pronchery # Fix up associated attributes 2298b077aed3SPierre Pronchery if ($o ne $_) { 2299b077aed3SPierre Pronchery $unified_info{attributes}->{sources}->{$ddest}->{$o} = 2300b077aed3SPierre Pronchery $unified_info{attributes}->{sources}->{$o}->{$s} = 2301b077aed3SPierre Pronchery $attributes{sources}->{$dest}->{$_} 2302b077aed3SPierre Pronchery if defined $attributes{sources}->{$dest}->{$_}; 2303b077aed3SPierre Pronchery } else { 2304b077aed3SPierre Pronchery $unified_info{attributes}->{sources}->{$ddest}->{$s} = 2305b077aed3SPierre Pronchery $attributes{sources}->{$dest}->{$_} 2306b077aed3SPierre Pronchery if defined $attributes{sources}->{$dest}->{$_}; 2307b077aed3SPierre Pronchery } 2308e71b7053SJung-uk Kim } 2309e71b7053SJung-uk Kim } 2310e71b7053SJung-uk Kim 2311e71b7053SJung-uk Kim foreach (keys %shared_sources) { 2312e71b7053SJung-uk Kim my $dest = $_; 2313e71b7053SJung-uk Kim my $ddest = cleanfile($buildd, $_, $blddir); 2314e71b7053SJung-uk Kim foreach (@{$shared_sources{$dest}}) { 2315e0c4386eSCy Schubert my $s = cleanfile($sourced, $_, $blddir, 1); 2316e71b7053SJung-uk Kim 2317b077aed3SPierre Pronchery # If it's generated or we simply don't find it in the source 2318b077aed3SPierre Pronchery # tree, we assume it's in the build tree. 2319b077aed3SPierre Pronchery if ($s eq $src_configdata || $generate{$_} || ! -f $s) { 2320e71b7053SJung-uk Kim $s = cleanfile($buildd, $_, $blddir); 2321e71b7053SJung-uk Kim } 2322e71b7053SJung-uk Kim 2323b077aed3SPierre Pronchery my $o = $_; 2324e71b7053SJung-uk Kim if ($s =~ /\.(cc|cpp|c|s|S)$/) { 2325e71b7053SJung-uk Kim # We recognise C++, C and asm files 2326b077aed3SPierre Pronchery push @{$check_exist{$s}}, $ddest; 2327e71b7053SJung-uk Kim $o =~ s/\.[csS]$/.o/; # C and assembler 2328e71b7053SJung-uk Kim $o =~ s/\.(cc|cpp)$/_cc.o/; # C++ 2329e71b7053SJung-uk Kim $o = cleanfile($buildd, $o, $blddir); 2330b077aed3SPierre Pronchery $unified_info{shared_sources}->{$ddest}->{$o} = -1; 2331b077aed3SPierre Pronchery $unified_info{sources}->{$o}->{$s} = -1; 2332e71b7053SJung-uk Kim } elsif ($s =~ /\.rc$/) { 2333e71b7053SJung-uk Kim # We also recognise resource files 2334b077aed3SPierre Pronchery push @{$check_exist{$s}}, $ddest; 2335e71b7053SJung-uk Kim $o =~ s/\.rc$/.res/; # Resource configuration 2336b077aed3SPierre Pronchery $o = cleanfile($buildd, $o, $blddir); 2337b077aed3SPierre Pronchery $unified_info{shared_sources}->{$ddest}->{$o} = -1; 2338b077aed3SPierre Pronchery $unified_info{sources}->{$o}->{$s} = -1; 2339b077aed3SPierre Pronchery } elsif ($s =~ /\.ld$/) { 2340b077aed3SPierre Pronchery # We also recognise linker scripts (or corresponding) 2341e71b7053SJung-uk Kim # We know they are generated files 2342b077aed3SPierre Pronchery push @{$check_exist{$s}}, $ddest; 2343b077aed3SPierre Pronchery $o = cleanfile($buildd, $_, $blddir); 2344b077aed3SPierre Pronchery $unified_info{shared_sources}->{$ddest}->{$o} = 1; 2345e71b7053SJung-uk Kim } else { 2346e71b7053SJung-uk Kim die "unrecognised source file type for shared library: $s\n"; 2347e71b7053SJung-uk Kim } 2348b077aed3SPierre Pronchery # Fix up associated attributes 2349b077aed3SPierre Pronchery if ($o ne $_) { 2350b077aed3SPierre Pronchery $unified_info{attributes}->{shared_sources}->{$ddest}->{$o} = 2351b077aed3SPierre Pronchery $unified_info{attributes}->{sources}->{$o}->{$s} = 2352b077aed3SPierre Pronchery $attributes{sources}->{$dest}->{$_} 2353b077aed3SPierre Pronchery if defined $attributes{sources}->{$dest}->{$_}; 2354b077aed3SPierre Pronchery } else { 2355b077aed3SPierre Pronchery $unified_info{attributes}->{shared_sources}->{$ddest}->{$o} = 2356b077aed3SPierre Pronchery $attributes{sources}->{$dest}->{$_} 2357b077aed3SPierre Pronchery if defined $attributes{sources}->{$dest}->{$_}; 2358b077aed3SPierre Pronchery } 2359e71b7053SJung-uk Kim } 2360e71b7053SJung-uk Kim } 2361e71b7053SJung-uk Kim 2362e71b7053SJung-uk Kim foreach (keys %generate) { 2363e71b7053SJung-uk Kim my $dest = $_; 2364e71b7053SJung-uk Kim my $ddest = cleanfile($buildd, $_, $blddir); 2365e71b7053SJung-uk Kim die "more than one generator for $dest: " 2366e71b7053SJung-uk Kim ,join(" ", @{$generate{$_}}),"\n" 2367e71b7053SJung-uk Kim if scalar @{$generate{$_}} > 1; 2368e71b7053SJung-uk Kim my @generator = split /\s+/, $generate{$dest}->[0]; 2369b077aed3SPierre Pronchery my $gen = $generator[0]; 2370e0c4386eSCy Schubert $generator[0] = cleanfile($sourced, $gen, $blddir, 1); 2371b077aed3SPierre Pronchery 2372b077aed3SPierre Pronchery # If the generator is itself generated, it's in the build tree 2373b077aed3SPierre Pronchery if ($generate{$gen} || ! -f $generator[0]) { 2374b077aed3SPierre Pronchery $generator[0] = cleanfile($buildd, $gen, $blddir); 2375b077aed3SPierre Pronchery } 2376b077aed3SPierre Pronchery $check_generate{$ddest}->{$generator[0]}++; 2377b077aed3SPierre Pronchery 2378e71b7053SJung-uk Kim $unified_info{generate}->{$ddest} = [ @generator ]; 2379b077aed3SPierre Pronchery # Fix up associated attributes 2380b077aed3SPierre Pronchery $unified_info{attributes}->{generate}->{$ddest} = 2381b077aed3SPierre Pronchery $attributes{generate}->{$dest}->{$gen} 2382b077aed3SPierre Pronchery if defined $attributes{generate}->{$dest}->{$gen}; 2383e71b7053SJung-uk Kim } 2384e71b7053SJung-uk Kim 2385e71b7053SJung-uk Kim foreach (keys %depends) { 2386e71b7053SJung-uk Kim my $dest = $_; 2387b077aed3SPierre Pronchery my $ddest = $dest; 2388b077aed3SPierre Pronchery 2389b077aed3SPierre Pronchery if ($dest =~ /^\|(.*)\|$/) { 2390b077aed3SPierre Pronchery # Collect the raw target 2391b077aed3SPierre Pronchery $unified_info{targets}->{$1} = 1; 2392b077aed3SPierre Pronchery $ddest = $1; 2393b077aed3SPierre Pronchery } elsif ($dest eq '') { 2394b077aed3SPierre Pronchery $ddest = ''; 2395b077aed3SPierre Pronchery } else { 2396e0c4386eSCy Schubert $ddest = cleanfile($sourced, $_, $blddir, 1); 2397e71b7053SJung-uk Kim 2398e71b7053SJung-uk Kim # If the destination doesn't exist in source, it can only be 2399e71b7053SJung-uk Kim # a generated file in the build tree. 2400b077aed3SPierre Pronchery if ($ddest eq $src_configdata || ! -f $ddest) { 2401e71b7053SJung-uk Kim $ddest = cleanfile($buildd, $_, $blddir); 2402e71b7053SJung-uk Kim } 2403e71b7053SJung-uk Kim } 2404e71b7053SJung-uk Kim foreach (@{$depends{$dest}}) { 2405e0c4386eSCy Schubert my $d = cleanfile($sourced, $_, $blddir, 1); 2406b077aed3SPierre Pronchery my $d2 = cleanfile($buildd, $_, $blddir); 2407e71b7053SJung-uk Kim 2408e71b7053SJung-uk Kim # If we know it's generated, or assume it is because we can't 2409e71b7053SJung-uk Kim # find it in the source tree, we set file we depend on to be 2410b077aed3SPierre Pronchery # in the build tree rather than the source tree. 2411e71b7053SJung-uk Kim if ($d eq $src_configdata 2412b077aed3SPierre Pronchery || (grep { $d2 eq $_ } 2413b077aed3SPierre Pronchery keys %{$unified_info{generate}}) 2414b077aed3SPierre Pronchery || ! -f $d) { 2415b077aed3SPierre Pronchery $d = $d2; 2416e71b7053SJung-uk Kim } 2417e71b7053SJung-uk Kim $unified_info{depends}->{$ddest}->{$d} = 1; 2418b077aed3SPierre Pronchery 2419b077aed3SPierre Pronchery # Fix up associated attributes 2420b077aed3SPierre Pronchery $unified_info{attributes}->{depends}->{$ddest}->{$d} = 2421b077aed3SPierre Pronchery $attributes{depends}->{$dest}->{$_} 2422b077aed3SPierre Pronchery if defined $attributes{depends}->{$dest}->{$_}; 2423e71b7053SJung-uk Kim } 2424e71b7053SJung-uk Kim } 2425e71b7053SJung-uk Kim 2426e71b7053SJung-uk Kim foreach (keys %includes) { 2427e71b7053SJung-uk Kim my $dest = $_; 2428e0c4386eSCy Schubert my $ddest = cleanfile($sourced, $_, $blddir, 1); 2429e71b7053SJung-uk Kim 2430e71b7053SJung-uk Kim # If the destination doesn't exist in source, it can only be 2431e71b7053SJung-uk Kim # a generated file in the build tree. 2432e71b7053SJung-uk Kim if ($ddest eq $src_configdata || ! -f $ddest) { 2433e71b7053SJung-uk Kim $ddest = cleanfile($buildd, $_, $blddir); 2434e71b7053SJung-uk Kim } 2435e71b7053SJung-uk Kim foreach (@{$includes{$dest}}) { 2436e0c4386eSCy Schubert my $is = cleandir($sourced, $_, $blddir, 1); 2437e71b7053SJung-uk Kim my $ib = cleandir($buildd, $_, $blddir); 2438e71b7053SJung-uk Kim push @{$unified_info{includes}->{$ddest}->{source}}, $is 2439e71b7053SJung-uk Kim unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}}; 2440e71b7053SJung-uk Kim push @{$unified_info{includes}->{$ddest}->{build}}, $ib 2441e71b7053SJung-uk Kim unless grep { $_ eq $ib } @{$unified_info{includes}->{$ddest}->{build}}; 2442e71b7053SJung-uk Kim } 2443e71b7053SJung-uk Kim } 2444b077aed3SPierre Pronchery 2445b077aed3SPierre Pronchery foreach my $dest (keys %defines) { 2446b077aed3SPierre Pronchery my $ddest; 2447b077aed3SPierre Pronchery 2448b077aed3SPierre Pronchery if ($dest ne "") { 2449e0c4386eSCy Schubert $ddest = cleanfile($sourced, $dest, $blddir, 1); 2450b077aed3SPierre Pronchery 2451b077aed3SPierre Pronchery # If the destination doesn't exist in source, it can only 2452b077aed3SPierre Pronchery # be a generated file in the build tree. 2453b077aed3SPierre Pronchery if (! -f $ddest) { 2454b077aed3SPierre Pronchery $ddest = cleanfile($buildd, $dest, $blddir); 2455b077aed3SPierre Pronchery } 2456b077aed3SPierre Pronchery } 2457b077aed3SPierre Pronchery foreach my $v (@{$defines{$dest}}) { 2458b077aed3SPierre Pronchery $v =~ m|^([^=]*)(=.*)?$|; 2459b077aed3SPierre Pronchery die "0 length macro name not permitted\n" if $1 eq ""; 2460b077aed3SPierre Pronchery if ($dest ne "") { 2461b077aed3SPierre Pronchery die "$1 defined more than once\n" 2462b077aed3SPierre Pronchery if defined $unified_info{defines}->{$ddest}->{$1}; 2463b077aed3SPierre Pronchery $unified_info{defines}->{$ddest}->{$1} = $2; 2464b077aed3SPierre Pronchery } else { 2465b077aed3SPierre Pronchery die "$1 defined more than once\n" 2466b077aed3SPierre Pronchery if grep { $v eq $_ } @{$config{defines}}; 2467b077aed3SPierre Pronchery push @{$config{defines}}, $v; 2468b077aed3SPierre Pronchery } 2469b077aed3SPierre Pronchery } 2470b077aed3SPierre Pronchery } 2471b077aed3SPierre Pronchery 2472b077aed3SPierre Pronchery foreach my $section (keys %imagedocs) { 2473b077aed3SPierre Pronchery foreach (@{$imagedocs{$section}}) { 2474b077aed3SPierre Pronchery my $imagedocs = cleanfile($buildd, $_, $blddir); 2475b077aed3SPierre Pronchery $unified_info{imagedocs}->{$section}->{$imagedocs} = 1; 2476b077aed3SPierre Pronchery } 2477b077aed3SPierre Pronchery } 2478b077aed3SPierre Pronchery 2479b077aed3SPierre Pronchery foreach my $section (keys %htmldocs) { 2480b077aed3SPierre Pronchery foreach (@{$htmldocs{$section}}) { 2481b077aed3SPierre Pronchery my $htmldocs = cleanfile($buildd, $_, $blddir); 2482b077aed3SPierre Pronchery $unified_info{htmldocs}->{$section}->{$htmldocs} = 1; 2483b077aed3SPierre Pronchery } 2484b077aed3SPierre Pronchery } 2485b077aed3SPierre Pronchery 2486b077aed3SPierre Pronchery foreach my $section (keys %mandocs) { 2487b077aed3SPierre Pronchery foreach (@{$mandocs{$section}}) { 2488b077aed3SPierre Pronchery my $mandocs = cleanfile($buildd, $_, $blddir); 2489b077aed3SPierre Pronchery $unified_info{mandocs}->{$section}->{$mandocs} = 1; 2490b077aed3SPierre Pronchery } 2491b077aed3SPierre Pronchery } 2492e71b7053SJung-uk Kim } 2493e71b7053SJung-uk Kim 2494e71b7053SJung-uk Kim my $ordinals_text = join(', ', sort keys %ordinals); 2495e71b7053SJung-uk Kim warn <<"EOF" if $ordinals_text; 2496e71b7053SJung-uk Kim 2497e71b7053SJung-uk KimWARNING: ORDINALS were specified for $ordinals_text 2498e71b7053SJung-uk KimThey are ignored and should be replaced with a combination of GENERATE, 2499e71b7053SJung-uk KimDEPEND and SHARED_SOURCE. 2500e71b7053SJung-uk KimEOF 2501e71b7053SJung-uk Kim 2502b077aed3SPierre Pronchery # Check that each generated file is only generated once 2503b077aed3SPierre Pronchery my $ambiguous_generation = 0; 2504b077aed3SPierre Pronchery foreach (sort keys %check_generate) { 2505b077aed3SPierre Pronchery my @generators = sort keys %{$check_generate{$_}}; 2506b077aed3SPierre Pronchery my $generators_txt = join(', ', @generators); 2507b077aed3SPierre Pronchery if (scalar @generators > 1) { 2508b077aed3SPierre Pronchery warn "$_ is GENERATEd by more than one generator ($generators_txt)\n"; 2509b077aed3SPierre Pronchery $ambiguous_generation++; 2510b077aed3SPierre Pronchery } 2511b077aed3SPierre Pronchery if ($check_generate{$_}->{$generators[0]} > 1) { 2512b077aed3SPierre Pronchery warn "INFO: $_ has more than one GENERATE declaration (same generator)\n" 2513b077aed3SPierre Pronchery } 2514b077aed3SPierre Pronchery } 2515b077aed3SPierre Pronchery die "There are ambiguous source file generations\n" 2516b077aed3SPierre Pronchery if $ambiguous_generation > 0; 2517e71b7053SJung-uk Kim 2518b077aed3SPierre Pronchery # All given source files should exist, or if generated, their 2519b077aed3SPierre Pronchery # generator should exist. This loop ensures this is true. 2520b077aed3SPierre Pronchery my $missing = 0; 2521b077aed3SPierre Pronchery foreach my $orig (sort keys %check_exist) { 2522b077aed3SPierre Pronchery foreach my $dest (@{$check_exist{$orig}}) { 2523b077aed3SPierre Pronchery if ($orig ne $src_configdata) { 2524b077aed3SPierre Pronchery if ($orig =~ /\.a$/) { 2525b077aed3SPierre Pronchery # Static library names may be used as sources, so we 2526b077aed3SPierre Pronchery # need to detect those and give them special treatment. 2527b077aed3SPierre Pronchery unless (grep { $_ eq $orig } 2528b077aed3SPierre Pronchery keys %{$unified_info{libraries}}) { 2529b077aed3SPierre Pronchery warn "$orig is given as source for $dest, but no such library is built\n"; 2530b077aed3SPierre Pronchery $missing++; 2531b077aed3SPierre Pronchery } 2532b077aed3SPierre Pronchery } else { 2533b077aed3SPierre Pronchery # A source may be generated, and its generator may be 2534b077aed3SPierre Pronchery # generated as well. We therefore loop to dig out the 2535b077aed3SPierre Pronchery # first generator. 2536b077aed3SPierre Pronchery my $gen = $orig; 2537b077aed3SPierre Pronchery 2538b077aed3SPierre Pronchery while (my @next = keys %{$check_generate{$gen}}) { 2539b077aed3SPierre Pronchery $gen = $next[0]; 2540b077aed3SPierre Pronchery } 2541b077aed3SPierre Pronchery 2542b077aed3SPierre Pronchery if (! -f $gen) { 2543b077aed3SPierre Pronchery if ($gen ne $orig) { 2544b077aed3SPierre Pronchery $missing++; 2545b077aed3SPierre Pronchery warn "$orig is given as source for $dest, but its generator (leading to $gen) is missing\n"; 2546b077aed3SPierre Pronchery } else { 2547b077aed3SPierre Pronchery $missing++; 2548b077aed3SPierre Pronchery warn "$orig is given as source for $dest, but is missing\n"; 2549c9cf7b5cSJung-uk Kim } 2550c9cf7b5cSJung-uk Kim } 2551c9cf7b5cSJung-uk Kim } 2552b077aed3SPierre Pronchery } 2553b077aed3SPierre Pronchery } 2554b077aed3SPierre Pronchery } 2555b077aed3SPierre Pronchery die "There are files missing\n" if $missing > 0; 2556b077aed3SPierre Pronchery 2557b077aed3SPierre Pronchery # Go through the sources of all libraries and check that the same basename 2558b077aed3SPierre Pronchery # doesn't appear more than once. Some static library archivers depend on 2559b077aed3SPierre Pronchery # them being unique. 2560b077aed3SPierre Pronchery { 2561b077aed3SPierre Pronchery my $err = 0; 2562b077aed3SPierre Pronchery foreach my $prod (keys %{$unified_info{libraries}}) { 2563b077aed3SPierre Pronchery my @prod_sources = 2564b077aed3SPierre Pronchery map { keys %{$unified_info{sources}->{$_}} } 2565b077aed3SPierre Pronchery keys %{$unified_info{sources}->{$prod}}; 2566b077aed3SPierre Pronchery my %srccnt = (); 2567b077aed3SPierre Pronchery 2568b077aed3SPierre Pronchery # Count how many times a given each source basename 2569b077aed3SPierre Pronchery # appears for each product. 2570b077aed3SPierre Pronchery foreach my $src (@prod_sources) { 2571b077aed3SPierre Pronchery $srccnt{basename $src}++; 2572b077aed3SPierre Pronchery } 2573b077aed3SPierre Pronchery 2574b077aed3SPierre Pronchery foreach my $src (keys %srccnt) { 2575b077aed3SPierre Pronchery if ((my $cnt = $srccnt{$src}) > 1) { 2576b077aed3SPierre Pronchery print STDERR "$src appears $cnt times for the product $prod\n"; 2577b077aed3SPierre Pronchery $err++ 2578b077aed3SPierre Pronchery } 2579b077aed3SPierre Pronchery } 2580b077aed3SPierre Pronchery } 2581b077aed3SPierre Pronchery die if $err > 0; 2582b077aed3SPierre Pronchery } 2583b077aed3SPierre Pronchery 2584b077aed3SPierre Pronchery # Massage the result 2585c9cf7b5cSJung-uk Kim 2586e71b7053SJung-uk Kim # If we depend on a header file or a perl module, add an inclusion of 2587e71b7053SJung-uk Kim # its directory to allow smoothe inclusion 2588e71b7053SJung-uk Kim foreach my $dest (keys %{$unified_info{depends}}) { 2589e71b7053SJung-uk Kim next if $dest eq ""; 2590e71b7053SJung-uk Kim foreach my $d (keys %{$unified_info{depends}->{$dest}}) { 2591e71b7053SJung-uk Kim next unless $d =~ /\.(h|pm)$/; 2592e71b7053SJung-uk Kim my $i = dirname($d); 2593e71b7053SJung-uk Kim my $spot = 2594e71b7053SJung-uk Kim $d eq "configdata.pm" || defined($unified_info{generate}->{$d}) 2595e71b7053SJung-uk Kim ? 'build' : 'source'; 2596e71b7053SJung-uk Kim push @{$unified_info{includes}->{$dest}->{$spot}}, $i 2597e71b7053SJung-uk Kim unless grep { $_ eq $i } @{$unified_info{includes}->{$dest}->{$spot}}; 2598e71b7053SJung-uk Kim } 2599e71b7053SJung-uk Kim } 2600e71b7053SJung-uk Kim 2601b077aed3SPierre Pronchery # Go through all intermediary files and change their names to something that 2602b077aed3SPierre Pronchery # reflects what they will be built for. Note that for some source files, 2603b077aed3SPierre Pronchery # this leads to duplicate object files because they are used multiple times. 2604b077aed3SPierre Pronchery # the goal is to rename all object files according to this scheme: 2605b077aed3SPierre Pronchery # {productname}-{midfix}-{origobjname}.[o|res] 2606b077aed3SPierre Pronchery # the {midfix} is a keyword indicating the type of product, which is mostly 2607b077aed3SPierre Pronchery # valuable for libraries since they come in two forms. 2608b077aed3SPierre Pronchery # 2609b077aed3SPierre Pronchery # This also reorganises the {sources} and {shared_sources} so that the 2610b077aed3SPierre Pronchery # former only contains ALL object files that are supposed to end up in 2611b077aed3SPierre Pronchery # static libraries and programs, while the latter contains ALL object files 2612b077aed3SPierre Pronchery # that are supposed to end up in shared libraries and DSOs. 2613b077aed3SPierre Pronchery # The main reason for having two different source structures is to allow 2614b077aed3SPierre Pronchery # the same name to be used for the static and the shared variants of a 2615b077aed3SPierre Pronchery # library. 2616b077aed3SPierre Pronchery { 2617b077aed3SPierre Pronchery # Take copies so we don't get interference from added stuff 2618b077aed3SPierre Pronchery my %unified_copy = (); 2619b077aed3SPierre Pronchery foreach (('sources', 'shared_sources')) { 2620b077aed3SPierre Pronchery $unified_copy{$_} = { %{$unified_info{$_}} } 2621b077aed3SPierre Pronchery if defined($unified_info{$_}); 2622b077aed3SPierre Pronchery delete $unified_info{$_}; 2623b077aed3SPierre Pronchery } 2624b077aed3SPierre Pronchery foreach my $prodtype (('programs', 'libraries', 'modules', 'scripts')) { 2625b077aed3SPierre Pronchery # $intent serves multi purposes: 2626b077aed3SPierre Pronchery # - give a prefix for the new object files names 2627b077aed3SPierre Pronchery # - in the case of libraries, rearrange the object files so static 2628b077aed3SPierre Pronchery # libraries use the 'sources' structure exclusively, while shared 2629b077aed3SPierre Pronchery # libraries use the 'shared_sources' structure exclusively. 2630b077aed3SPierre Pronchery my $intent = { 2631b077aed3SPierre Pronchery programs => { bin => { src => [ 'sources' ], 2632b077aed3SPierre Pronchery dst => 'sources' } }, 2633b077aed3SPierre Pronchery libraries => { lib => { src => [ 'sources' ], 2634b077aed3SPierre Pronchery dst => 'sources' }, 2635b077aed3SPierre Pronchery shlib => { prodselect => 2636b077aed3SPierre Pronchery sub { grep !/\.a$/, @_ }, 2637b077aed3SPierre Pronchery src => [ 'sources', 2638b077aed3SPierre Pronchery 'shared_sources' ], 2639b077aed3SPierre Pronchery dst => 'shared_sources' } }, 2640b077aed3SPierre Pronchery modules => { dso => { src => [ 'sources' ], 2641b077aed3SPierre Pronchery dst => 'sources' } }, 2642b077aed3SPierre Pronchery scripts => { script => { src => [ 'sources' ], 2643b077aed3SPierre Pronchery dst => 'sources' } } 2644b077aed3SPierre Pronchery } -> {$prodtype}; 2645b077aed3SPierre Pronchery foreach my $kind (keys %$intent) { 2646b077aed3SPierre Pronchery next if ($intent->{$kind}->{dst} eq 'shared_sources' 2647b077aed3SPierre Pronchery && $disabled{shared}); 2648b077aed3SPierre Pronchery 2649b077aed3SPierre Pronchery my @src = @{$intent->{$kind}->{src}}; 2650b077aed3SPierre Pronchery my $dst = $intent->{$kind}->{dst}; 2651b077aed3SPierre Pronchery my $prodselect = $intent->{$kind}->{prodselect} // sub { @_ }; 2652b077aed3SPierre Pronchery foreach my $prod ($prodselect->(keys %{$unified_info{$prodtype}})) { 2653b077aed3SPierre Pronchery # %prod_sources has all applicable objects as keys, and 2654b077aed3SPierre Pronchery # their corresponding sources as values 2655b077aed3SPierre Pronchery my %prod_sources = 2656b077aed3SPierre Pronchery map { $_ => [ keys %{$unified_copy{sources}->{$_}} ] } 2657b077aed3SPierre Pronchery map { keys %{$unified_copy{$_}->{$prod}} } 2658b077aed3SPierre Pronchery @src; 2659b077aed3SPierre Pronchery foreach (keys %prod_sources) { 2660b077aed3SPierre Pronchery # Only affect object files and resource files, 2661b077aed3SPierre Pronchery # the others simply get a new value 2662b077aed3SPierre Pronchery # (+1 instead of -1) 2663b077aed3SPierre Pronchery if ($_ =~ /\.(o|res)$/) { 2664b077aed3SPierre Pronchery (my $prodname = $prod) =~ s|\.a$||; 2665b077aed3SPierre Pronchery my $newobj = 2666b077aed3SPierre Pronchery catfile(dirname($_), 2667b077aed3SPierre Pronchery basename($prodname) 2668b077aed3SPierre Pronchery . '-' . $kind 2669b077aed3SPierre Pronchery . '-' . basename($_)); 2670b077aed3SPierre Pronchery $unified_info{$dst}->{$prod}->{$newobj} = 1; 2671b077aed3SPierre Pronchery foreach my $src (@{$prod_sources{$_}}) { 2672b077aed3SPierre Pronchery $unified_info{sources}->{$newobj}->{$src} = 1; 2673b077aed3SPierre Pronchery # Adjust source attributes 2674b077aed3SPierre Pronchery my $attrs = $unified_info{attributes}->{sources}; 2675b077aed3SPierre Pronchery if (defined $attrs->{$prod} 2676b077aed3SPierre Pronchery && defined $attrs->{$prod}->{$_}) { 2677b077aed3SPierre Pronchery $attrs->{$prod}->{$newobj} = 2678b077aed3SPierre Pronchery $attrs->{$prod}->{$_}; 2679b077aed3SPierre Pronchery delete $attrs->{$prod}->{$_}; 2680b077aed3SPierre Pronchery } 2681b077aed3SPierre Pronchery foreach my $objsrc (keys %{$attrs->{$_} // {}}) { 2682b077aed3SPierre Pronchery $attrs->{$newobj}->{$objsrc} = 2683b077aed3SPierre Pronchery $attrs->{$_}->{$objsrc}; 2684b077aed3SPierre Pronchery delete $attrs->{$_}->{$objsrc}; 2685b077aed3SPierre Pronchery } 2686b077aed3SPierre Pronchery } 2687b077aed3SPierre Pronchery # Adjust dependencies 2688b077aed3SPierre Pronchery foreach my $deps (keys %{$unified_info{depends}->{$_}}) { 2689b077aed3SPierre Pronchery $unified_info{depends}->{$_}->{$deps} = -1; 2690b077aed3SPierre Pronchery $unified_info{depends}->{$newobj}->{$deps} = 1; 2691b077aed3SPierre Pronchery } 2692b077aed3SPierre Pronchery # Adjust includes 2693b077aed3SPierre Pronchery foreach my $k (('source', 'build')) { 2694b077aed3SPierre Pronchery next unless 2695b077aed3SPierre Pronchery defined($unified_info{includes}->{$_}->{$k}); 2696b077aed3SPierre Pronchery my @incs = @{$unified_info{includes}->{$_}->{$k}}; 2697b077aed3SPierre Pronchery $unified_info{includes}->{$newobj}->{$k} = [ @incs ]; 2698b077aed3SPierre Pronchery } 2699b077aed3SPierre Pronchery } else { 2700b077aed3SPierre Pronchery $unified_info{$dst}->{$prod}->{$_} = 1; 2701e71b7053SJung-uk Kim } 2702e71b7053SJung-uk Kim } 2703e71b7053SJung-uk Kim } 2704e71b7053SJung-uk Kim } 2705b077aed3SPierre Pronchery } 2706b077aed3SPierre Pronchery } 2707b077aed3SPierre Pronchery 2708b077aed3SPierre Pronchery # At this point, we have a number of sources with the value -1. They 2709b077aed3SPierre Pronchery # aren't part of the local build and are probably meant for a different 2710b077aed3SPierre Pronchery # platform, and can therefore be cleaned away. That happens when making 2711b077aed3SPierre Pronchery # %unified_info more efficient below. 2712e71b7053SJung-uk Kim 2713e71b7053SJung-uk Kim ### Make unified_info a bit more efficient 2714e71b7053SJung-uk Kim # One level structures 2715b077aed3SPierre Pronchery foreach (("programs", "libraries", "modules", "scripts", "targets")) { 2716e71b7053SJung-uk Kim $unified_info{$_} = [ sort keys %{$unified_info{$_}} ]; 2717e71b7053SJung-uk Kim } 2718e71b7053SJung-uk Kim # Two level structures 2719b077aed3SPierre Pronchery foreach my $l1 (("sources", "shared_sources", "ldadd", "depends", 2720b077aed3SPierre Pronchery "imagedocs", "htmldocs", "mandocs")) { 2721e71b7053SJung-uk Kim foreach my $l2 (sort keys %{$unified_info{$l1}}) { 2722b077aed3SPierre Pronchery my @items = 2723b077aed3SPierre Pronchery sort 2724b077aed3SPierre Pronchery grep { $unified_info{$l1}->{$l2}->{$_} > 0 } 2725b077aed3SPierre Pronchery keys %{$unified_info{$l1}->{$l2}}; 2726b077aed3SPierre Pronchery if (@items) { 2727b077aed3SPierre Pronchery $unified_info{$l1}->{$l2} = [ @items ]; 2728b077aed3SPierre Pronchery } else { 2729b077aed3SPierre Pronchery delete $unified_info{$l1}->{$l2}; 2730e71b7053SJung-uk Kim } 2731e71b7053SJung-uk Kim } 2732b077aed3SPierre Pronchery } 2733b077aed3SPierre Pronchery # Defines 2734b077aed3SPierre Pronchery foreach my $dest (sort keys %{$unified_info{defines}}) { 2735b077aed3SPierre Pronchery $unified_info{defines}->{$dest} 2736b077aed3SPierre Pronchery = [ map { $_.$unified_info{defines}->{$dest}->{$_} } 2737b077aed3SPierre Pronchery sort keys %{$unified_info{defines}->{$dest}} ]; 2738b077aed3SPierre Pronchery } 2739e71b7053SJung-uk Kim # Includes 2740e71b7053SJung-uk Kim foreach my $dest (sort keys %{$unified_info{includes}}) { 2741e71b7053SJung-uk Kim if (defined($unified_info{includes}->{$dest}->{build})) { 2742e71b7053SJung-uk Kim my @source_includes = (); 2743e71b7053SJung-uk Kim @source_includes = ( @{$unified_info{includes}->{$dest}->{source}} ) 2744e71b7053SJung-uk Kim if defined($unified_info{includes}->{$dest}->{source}); 2745e71b7053SJung-uk Kim $unified_info{includes}->{$dest} = 2746e71b7053SJung-uk Kim [ @{$unified_info{includes}->{$dest}->{build}} ]; 2747e71b7053SJung-uk Kim foreach my $inc (@source_includes) { 2748e71b7053SJung-uk Kim push @{$unified_info{includes}->{$dest}}, $inc 2749e71b7053SJung-uk Kim unless grep { $_ eq $inc } @{$unified_info{includes}->{$dest}}; 2750e71b7053SJung-uk Kim } 2751b077aed3SPierre Pronchery } elsif (defined($unified_info{includes}->{$dest}->{source})) { 2752e71b7053SJung-uk Kim $unified_info{includes}->{$dest} = 2753e71b7053SJung-uk Kim [ @{$unified_info{includes}->{$dest}->{source}} ]; 2754b077aed3SPierre Pronchery } else { 2755b077aed3SPierre Pronchery delete $unified_info{includes}->{$dest}; 2756e71b7053SJung-uk Kim } 2757e71b7053SJung-uk Kim } 2758c9cf7b5cSJung-uk Kim 2759c9cf7b5cSJung-uk Kim # For convenience collect information regarding directories where 2760c9cf7b5cSJung-uk Kim # files are generated, those generated files and the end product 2761c9cf7b5cSJung-uk Kim # they end up in where applicable. Then, add build rules for those 2762c9cf7b5cSJung-uk Kim # directories 2763c9cf7b5cSJung-uk Kim my %loopinfo = ( "lib" => [ @{$unified_info{libraries}} ], 2764b077aed3SPierre Pronchery "dso" => [ @{$unified_info{modules}} ], 2765c9cf7b5cSJung-uk Kim "bin" => [ @{$unified_info{programs}} ], 2766b077aed3SPierre Pronchery "script" => [ @{$unified_info{scripts}} ], 2767b077aed3SPierre Pronchery "docs" => [ (map { @{$unified_info{imagedocs}->{$_} // []} } 2768b077aed3SPierre Pronchery keys %{$unified_info{imagedocs} // {}}), 2769b077aed3SPierre Pronchery (map { @{$unified_info{htmldocs}->{$_} // []} } 2770b077aed3SPierre Pronchery keys %{$unified_info{htmldocs} // {}}), 2771b077aed3SPierre Pronchery (map { @{$unified_info{mandocs}->{$_} // []} } 2772b077aed3SPierre Pronchery keys %{$unified_info{mandocs} // {}}) ] ); 2773b077aed3SPierre Pronchery foreach my $type (sort keys %loopinfo) { 2774c9cf7b5cSJung-uk Kim foreach my $product (@{$loopinfo{$type}}) { 2775c9cf7b5cSJung-uk Kim my %dirs = (); 2776c9cf7b5cSJung-uk Kim my $pd = dirname($product); 2777c9cf7b5cSJung-uk Kim 2778c9cf7b5cSJung-uk Kim foreach (@{$unified_info{sources}->{$product} // []}, 2779c9cf7b5cSJung-uk Kim @{$unified_info{shared_sources}->{$product} // []}) { 2780c9cf7b5cSJung-uk Kim my $d = dirname($_); 2781c9cf7b5cSJung-uk Kim 2782c9cf7b5cSJung-uk Kim # We don't want to create targets for source directories 2783c9cf7b5cSJung-uk Kim # when building out of source 2784c9cf7b5cSJung-uk Kim next if ($config{sourcedir} ne $config{builddir} 2785c9cf7b5cSJung-uk Kim && $d =~ m|^\Q$config{sourcedir}\E|); 2786c9cf7b5cSJung-uk Kim # We already have a "test" target, and the current directory 2787c9cf7b5cSJung-uk Kim # is just silly to make a target for 2788c9cf7b5cSJung-uk Kim next if $d eq "test" || $d eq "."; 2789c9cf7b5cSJung-uk Kim 2790c9cf7b5cSJung-uk Kim $dirs{$d} = 1; 2791c9cf7b5cSJung-uk Kim push @{$unified_info{dirinfo}->{$d}->{deps}}, $_ 2792c9cf7b5cSJung-uk Kim if $d ne $pd; 2793c9cf7b5cSJung-uk Kim } 2794b077aed3SPierre Pronchery foreach (sort keys %dirs) { 2795c9cf7b5cSJung-uk Kim push @{$unified_info{dirinfo}->{$_}->{products}->{$type}}, 2796c9cf7b5cSJung-uk Kim $product; 2797c9cf7b5cSJung-uk Kim } 2798c9cf7b5cSJung-uk Kim } 2799c9cf7b5cSJung-uk Kim } 2800e71b7053SJung-uk Kim} 2801e71b7053SJung-uk Kim 2802e71b7053SJung-uk Kim# For the schemes that need it, we provide the old *_obj configs 2803e71b7053SJung-uk Kim# from the *_asm_obj ones 2804e71b7053SJung-uk Kimforeach (grep /_(asm|aux)_src$/, keys %target) { 2805e71b7053SJung-uk Kim my $src = $_; 2806e71b7053SJung-uk Kim (my $obj = $_) =~ s/_(asm|aux)_src$/_obj/; 2807e71b7053SJung-uk Kim $target{$obj} = $target{$src}; 2808e71b7053SJung-uk Kim $target{$obj} =~ s/\.[csS]\b/.o/g; # C and assembler 2809e71b7053SJung-uk Kim $target{$obj} =~ s/\.(cc|cpp)\b/_cc.o/g; # C++ 2810e71b7053SJung-uk Kim} 2811e71b7053SJung-uk Kim 2812e71b7053SJung-uk Kim# Write down our configuration where it fits ######################### 2813e71b7053SJung-uk Kim 2814b077aed3SPierre Proncherymy %template_vars = ( 2815b077aed3SPierre Pronchery config => \%config, 2816b077aed3SPierre Pronchery target => \%target, 2817b077aed3SPierre Pronchery disablables => \@disablables, 2818b077aed3SPierre Pronchery disablables_int => \@disablables_int, 2819b077aed3SPierre Pronchery disabled => \%disabled, 2820b077aed3SPierre Pronchery withargs => \%withargs, 2821b077aed3SPierre Pronchery unified_info => \%unified_info, 2822b077aed3SPierre Pronchery tls => \@tls, 2823b077aed3SPierre Pronchery dtls => \@dtls, 2824b077aed3SPierre Pronchery makevars => [ sort keys %user ], 2825b077aed3SPierre Pronchery disabled_info => \%disabled_info, 2826b077aed3SPierre Pronchery user_crossable => \@user_crossable, 2827e71b7053SJung-uk Kim); 2828b077aed3SPierre Proncherymy $configdata_outname = 'configdata.pm'; 2829b077aed3SPierre Proncheryopen CONFIGDATA, ">$configdata_outname.new" 2830b077aed3SPierre Pronchery or die "Trying to create $configdata_outname.new: $!"; 2831e0c4386eSCy Schubertmy $configdata_tmplname = cleanfile($srcdir, "configdata.pm.in", $blddir, 1); 2832b077aed3SPierre Proncherymy $configdata_tmpl = 2833b077aed3SPierre Pronchery OpenSSL::Template->new(TYPE => 'FILE', SOURCE => $configdata_tmplname); 2834b077aed3SPierre Pronchery$configdata_tmpl->fill_in( 2835b077aed3SPierre Pronchery FILENAME => $configdata_tmplname, 2836b077aed3SPierre Pronchery OUTPUT => \*CONFIGDATA, 2837b077aed3SPierre Pronchery HASH => { %template_vars, 2838b077aed3SPierre Pronchery autowarntext => [ 2839b077aed3SPierre Pronchery 'WARNING: do not edit!', 2840b077aed3SPierre Pronchery "Generated by Configure from $configdata_tmplname", 2841b077aed3SPierre Pronchery ] } 2842b077aed3SPierre Pronchery) or die $Text::Template::ERROR; 2843b077aed3SPierre Proncheryclose CONFIGDATA; 2844e71b7053SJung-uk Kim 2845b077aed3SPierre Proncheryrename "$configdata_outname.new", $configdata_outname; 2846e71b7053SJung-uk Kimif ($builder_platform eq 'unix') { 2847e71b7053SJung-uk Kim my $mode = (0755 & ~umask); 2848e71b7053SJung-uk Kim chmod $mode, 'configdata.pm' 2849e71b7053SJung-uk Kim or warn sprintf("WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s\n",$mode,$!); 28503b4e3dcbSSimon L. B. Nielsen} 2851b077aed3SPierre Proncheryprint "Created $configdata_outname\n"; 28523b4e3dcbSSimon L. B. Nielsen 2853b077aed3SPierre Proncheryprint "Running $configdata_outname\n"; 2854b077aed3SPierre Proncherymy $perlcmd = (quotify("maybeshell", $config{PERL}))[0]; 2855b077aed3SPierre Proncherymy $cmd = "$perlcmd $configdata_outname"; 2856b077aed3SPierre Pronchery#print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n"; 2857b077aed3SPierre Proncherysystem($cmd); 2858b077aed3SPierre Proncheryexit 1 if $? != 0; 285974664626SKris Kennaway 2860e71b7053SJung-uk Kim$SIG{__DIE__} = $orig_death_handler; 2861e71b7053SJung-uk Kim 2862e71b7053SJung-uk Kimprint <<"EOF" if ($disabled{threads} eq "unavailable"); 286374664626SKris Kennaway 286474664626SKris KennawayThe library could not be configured for supporting multi-threaded 286574664626SKris Kennawayapplications as the compiler options required on this system are not known. 2866b077aed3SPierre ProncherySee file INSTALL.md for details if you need multi-threading. 286774664626SKris KennawayEOF 286874664626SKris Kennaway 2869e71b7053SJung-uk Kimprint <<"EOF" if ($no_shared_warn); 2870fceca8a3SJacques Vidrine 2871e71b7053SJung-uk KimThe options 'shared', 'pic' and 'dynamic-engine' aren't supported on this 2872e71b7053SJung-uk Kimplatform, so we will pretend you gave the option 'no-pic', which also disables 2873e71b7053SJung-uk Kim'shared' and 'dynamic-engine'. If you know how to implement shared libraries 2874e71b7053SJung-uk Kimor position independent code, please let us know (but please first make sure 2875e71b7053SJung-uk Kimyou have tried with a current version of OpenSSL). 28768180e704SJung-uk KimEOF 28778180e704SJung-uk Kim 2878b077aed3SPierre Proncheryprint $banner; 2879fceca8a3SJacques Vidrine 288074664626SKris Kennawayexit(0); 288174664626SKris Kennaway 2882e71b7053SJung-uk Kim###################################################################### 2883e71b7053SJung-uk Kim# 2884e71b7053SJung-uk Kim# Helpers and utility functions 2885e71b7053SJung-uk Kim# 2886e71b7053SJung-uk Kim 2887e71b7053SJung-uk Kim# Death handler, to print a helpful message in case of failure ####### 2888e71b7053SJung-uk Kim# 2889e71b7053SJung-uk Kimsub death_handler { 2890e71b7053SJung-uk Kim die @_ if $^S; # To prevent the added message in eval blocks 2891640242a5SJung-uk Kim my $build_file = $config{build_file} // "build file"; 2892e71b7053SJung-uk Kim my @message = ( <<"_____", @_ ); 2893e71b7053SJung-uk Kim 2894e71b7053SJung-uk KimFailure! $build_file wasn't produced. 2895b077aed3SPierre ProncheryPlease read INSTALL.md and associated NOTES-* files. You may also have to 2896b077aed3SPierre Proncherylook over your available compiler tool chain or change your configuration. 2897e71b7053SJung-uk Kim 2898e71b7053SJung-uk Kim_____ 2899e71b7053SJung-uk Kim 2900e71b7053SJung-uk Kim # Dying is terminal, so it's ok to reset the signal handler here. 2901e71b7053SJung-uk Kim $SIG{__DIE__} = $orig_death_handler; 2902e71b7053SJung-uk Kim die @message; 2903e71b7053SJung-uk Kim} 2904e71b7053SJung-uk Kim 2905e71b7053SJung-uk Kim# Configuration file reading ######################################### 2906e71b7053SJung-uk Kim 2907e71b7053SJung-uk Kim# Note: All of the helper functions are for lazy evaluation. They all 2908e71b7053SJung-uk Kim# return a CODE ref, which will return the intended value when evaluated. 2909e71b7053SJung-uk Kim# Thus, whenever there's mention of a returned value, it's about that 2910e71b7053SJung-uk Kim# intended value. 2911e71b7053SJung-uk Kim 2912e71b7053SJung-uk Kim# Helper function to implement conditional value variants, with a default 2913e71b7053SJung-uk Kim# plus additional values based on the value of $config{build_type}. 2914e71b7053SJung-uk Kim# Arguments are given in hash table form: 2915e71b7053SJung-uk Kim# 2916e71b7053SJung-uk Kim# picker(default => "Basic string: ", 2917e71b7053SJung-uk Kim# debug => "debug", 2918e71b7053SJung-uk Kim# release => "release") 2919e71b7053SJung-uk Kim# 2920e71b7053SJung-uk Kim# When configuring with --debug, the resulting string will be 2921e71b7053SJung-uk Kim# "Basic string: debug", and when not, it will be "Basic string: release" 2922e71b7053SJung-uk Kim# 2923e71b7053SJung-uk Kim# This can be used to create variants of sets of flags according to the 2924e71b7053SJung-uk Kim# build type: 2925e71b7053SJung-uk Kim# 2926e71b7053SJung-uk Kim# cflags => picker(default => "-Wall", 2927e71b7053SJung-uk Kim# debug => "-g -O0", 2928e71b7053SJung-uk Kim# release => "-O3") 2929e71b7053SJung-uk Kim# 2930e71b7053SJung-uk Kimsub picker { 2931e71b7053SJung-uk Kim my %opts = @_; 2932e71b7053SJung-uk Kim return sub { add($opts{default} || (), 2933e71b7053SJung-uk Kim $opts{$config{build_type}} || ())->(); } 2934e71b7053SJung-uk Kim} 2935e71b7053SJung-uk Kim 2936e71b7053SJung-uk Kim# Helper function to combine several values of different types into one. 2937e71b7053SJung-uk Kim# This is useful if you want to combine a string with the result of a 2938e71b7053SJung-uk Kim# lazy function, such as: 2939e71b7053SJung-uk Kim# 2940e71b7053SJung-uk Kim# cflags => combine("-Wall", sub { $disabled{zlib} ? () : "-DZLIB" }) 2941e71b7053SJung-uk Kim# 2942e71b7053SJung-uk Kimsub combine { 2943e71b7053SJung-uk Kim my @stuff = @_; 2944e71b7053SJung-uk Kim return sub { add(@stuff)->(); } 2945e71b7053SJung-uk Kim} 2946e71b7053SJung-uk Kim 2947e71b7053SJung-uk Kim# Helper function to implement conditional values depending on the value 2948e71b7053SJung-uk Kim# of $disabled{threads}. Can be used as follows: 2949e71b7053SJung-uk Kim# 2950e71b7053SJung-uk Kim# cflags => combine("-Wall", threads("-pthread")) 2951e71b7053SJung-uk Kim# 2952e71b7053SJung-uk Kimsub threads { 2953e71b7053SJung-uk Kim my @flags = @_; 2954e71b7053SJung-uk Kim return sub { add($disabled{threads} ? () : @flags)->(); } 2955e71b7053SJung-uk Kim} 2956e71b7053SJung-uk Kim 2957e71b7053SJung-uk Kimsub shared { 2958e71b7053SJung-uk Kim my @flags = @_; 2959e71b7053SJung-uk Kim return sub { add($disabled{shared} ? () : @flags)->(); } 2960e71b7053SJung-uk Kim} 2961e71b7053SJung-uk Kim 2962e71b7053SJung-uk Kimour $add_called = 0; 2963e71b7053SJung-uk Kim# Helper function to implement adding values to already existing configuration 2964e71b7053SJung-uk Kim# values. It handles elements that are ARRAYs, CODEs and scalars 2965e71b7053SJung-uk Kimsub _add { 2966e71b7053SJung-uk Kim my $separator = shift; 2967e71b7053SJung-uk Kim 2968e71b7053SJung-uk Kim # If there's any ARRAY in the collection of values OR the separator 2969e71b7053SJung-uk Kim # is undef, we will return an ARRAY of combined values, otherwise a 2970e71b7053SJung-uk Kim # string of joined values with $separator as the separator. 2971e71b7053SJung-uk Kim my $found_array = !defined($separator); 2972e71b7053SJung-uk Kim 2973e71b7053SJung-uk Kim my @values = 2974e71b7053SJung-uk Kim map { 2975e71b7053SJung-uk Kim my $res = $_; 2976e71b7053SJung-uk Kim while (ref($res) eq "CODE") { 2977e71b7053SJung-uk Kim $res = $res->(); 2978e71b7053SJung-uk Kim } 2979e71b7053SJung-uk Kim if (defined($res)) { 2980e71b7053SJung-uk Kim if (ref($res) eq "ARRAY") { 2981e71b7053SJung-uk Kim $found_array = 1; 2982e71b7053SJung-uk Kim @$res; 2983e71b7053SJung-uk Kim } else { 2984e71b7053SJung-uk Kim $res; 2985e71b7053SJung-uk Kim } 2986e71b7053SJung-uk Kim } else { 2987e71b7053SJung-uk Kim (); 2988e71b7053SJung-uk Kim } 2989e71b7053SJung-uk Kim } (@_); 2990e71b7053SJung-uk Kim 2991e71b7053SJung-uk Kim $add_called = 1; 2992e71b7053SJung-uk Kim 2993e71b7053SJung-uk Kim if ($found_array) { 2994e71b7053SJung-uk Kim [ @values ]; 2995e71b7053SJung-uk Kim } else { 2996e71b7053SJung-uk Kim join($separator, grep { defined($_) && $_ ne "" } @values); 2997e71b7053SJung-uk Kim } 2998e71b7053SJung-uk Kim} 2999e71b7053SJung-uk Kimsub add_before { 3000e71b7053SJung-uk Kim my $separator = " "; 3001e71b7053SJung-uk Kim if (ref($_[$#_]) eq "HASH") { 3002e71b7053SJung-uk Kim my $opts = pop; 3003e71b7053SJung-uk Kim $separator = $opts->{separator}; 3004e71b7053SJung-uk Kim } 3005e71b7053SJung-uk Kim my @x = @_; 3006e71b7053SJung-uk Kim sub { _add($separator, @x, @_) }; 3007e71b7053SJung-uk Kim} 3008e71b7053SJung-uk Kimsub add { 3009e71b7053SJung-uk Kim my $separator = " "; 3010e71b7053SJung-uk Kim if (ref($_[$#_]) eq "HASH") { 3011e71b7053SJung-uk Kim my $opts = pop; 3012e71b7053SJung-uk Kim $separator = $opts->{separator}; 3013e71b7053SJung-uk Kim } 3014e71b7053SJung-uk Kim my @x = @_; 3015e71b7053SJung-uk Kim sub { _add($separator, @_, @x) }; 3016e71b7053SJung-uk Kim} 3017e71b7053SJung-uk Kim 3018e71b7053SJung-uk Kimsub read_eval_file { 3019e71b7053SJung-uk Kim my $fname = shift; 3020e71b7053SJung-uk Kim my $content; 3021e71b7053SJung-uk Kim my @result; 3022e71b7053SJung-uk Kim 3023e71b7053SJung-uk Kim open F, "< $fname" or die "Can't open '$fname': $!\n"; 3024e71b7053SJung-uk Kim { 3025e71b7053SJung-uk Kim undef local $/; 3026e71b7053SJung-uk Kim $content = <F>; 3027e71b7053SJung-uk Kim } 3028e71b7053SJung-uk Kim close F; 3029e71b7053SJung-uk Kim { 3030e71b7053SJung-uk Kim local $@; 3031e71b7053SJung-uk Kim 3032e71b7053SJung-uk Kim @result = ( eval $content ); 3033e71b7053SJung-uk Kim warn $@ if $@; 3034e71b7053SJung-uk Kim } 3035e71b7053SJung-uk Kim return wantarray ? @result : $result[0]; 3036e71b7053SJung-uk Kim} 3037e71b7053SJung-uk Kim 3038e71b7053SJung-uk Kim# configuration reader, evaluates the input file as a perl script and expects 3039e71b7053SJung-uk Kim# it to fill %targets with target configurations. Those are then added to 3040e71b7053SJung-uk Kim# %table. 3041e71b7053SJung-uk Kimsub read_config { 3042e71b7053SJung-uk Kim my $fname = shift; 3043e71b7053SJung-uk Kim my %targets; 3044e71b7053SJung-uk Kim 3045e71b7053SJung-uk Kim { 3046e71b7053SJung-uk Kim # Protect certain tables from tampering 3047e71b7053SJung-uk Kim local %table = (); 3048e71b7053SJung-uk Kim 3049e71b7053SJung-uk Kim %targets = read_eval_file($fname); 3050e71b7053SJung-uk Kim } 3051e71b7053SJung-uk Kim my %preexisting = (); 3052e71b7053SJung-uk Kim foreach (sort keys %targets) { 3053e71b7053SJung-uk Kim $preexisting{$_} = 1 if $table{$_}; 3054e71b7053SJung-uk Kim } 3055e71b7053SJung-uk Kim die <<"EOF", 3056e71b7053SJung-uk KimThe following config targets from $fname 3057e71b7053SJung-uk Kimshadow pre-existing config targets with the same name: 3058e71b7053SJung-uk KimEOF 3059e71b7053SJung-uk Kim map { " $_\n" } sort keys %preexisting 3060e71b7053SJung-uk Kim if %preexisting; 3061e71b7053SJung-uk Kim 3062e71b7053SJung-uk Kim 3063e71b7053SJung-uk Kim # For each target, check that it's configured with a hash table. 3064e71b7053SJung-uk Kim foreach (keys %targets) { 3065e71b7053SJung-uk Kim if (ref($targets{$_}) ne "HASH") { 3066e71b7053SJung-uk Kim if (ref($targets{$_}) eq "") { 3067e71b7053SJung-uk Kim warn "Deprecated target configuration for $_, ignoring...\n"; 3068e71b7053SJung-uk Kim } else { 3069e71b7053SJung-uk Kim warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n"; 3070e71b7053SJung-uk Kim } 3071e71b7053SJung-uk Kim delete $targets{$_}; 3072e71b7053SJung-uk Kim } else { 3073e71b7053SJung-uk Kim $targets{$_}->{_conf_fname_int} = add([ $fname ]); 3074e71b7053SJung-uk Kim } 3075e71b7053SJung-uk Kim } 3076e71b7053SJung-uk Kim 3077e71b7053SJung-uk Kim %table = (%table, %targets); 3078e71b7053SJung-uk Kim 3079e71b7053SJung-uk Kim} 3080e71b7053SJung-uk Kim 3081e71b7053SJung-uk Kim# configuration resolver. Will only resolve all the lazy evaluation 3082e71b7053SJung-uk Kim# codeblocks for the chosen target and all those it inherits from, 3083e71b7053SJung-uk Kim# recursively 3084e71b7053SJung-uk Kimsub resolve_config { 3085e71b7053SJung-uk Kim my $target = shift; 3086e71b7053SJung-uk Kim my @breadcrumbs = @_; 3087e71b7053SJung-uk Kim 3088e71b7053SJung-uk Kim# my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS}); 3089e71b7053SJung-uk Kim 3090e71b7053SJung-uk Kim if (grep { $_ eq $target } @breadcrumbs) { 3091e71b7053SJung-uk Kim die "inherit_from loop! target backtrace:\n " 3092e71b7053SJung-uk Kim ,$target,"\n ",join("\n ", @breadcrumbs),"\n"; 3093e71b7053SJung-uk Kim } 3094e71b7053SJung-uk Kim 3095e71b7053SJung-uk Kim if (!defined($table{$target})) { 3096e71b7053SJung-uk Kim warn "Warning! target $target doesn't exist!\n"; 3097e71b7053SJung-uk Kim return (); 3098e71b7053SJung-uk Kim } 3099e71b7053SJung-uk Kim # Recurse through all inheritances. They will be resolved on the 3100e71b7053SJung-uk Kim # fly, so when this operation is done, they will all just be a 3101e71b7053SJung-uk Kim # bunch of attributes with string values. 3102e71b7053SJung-uk Kim # What we get here, though, are keys with references to lists of 3103e71b7053SJung-uk Kim # the combined values of them all. We will deal with lists after 3104e71b7053SJung-uk Kim # this stage is done. 3105e71b7053SJung-uk Kim my %combined_inheritance = (); 3106e71b7053SJung-uk Kim if ($table{$target}->{inherit_from}) { 3107e71b7053SJung-uk Kim my @inherit_from = 3108e71b7053SJung-uk Kim map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}}; 3109e71b7053SJung-uk Kim foreach (@inherit_from) { 3110e71b7053SJung-uk Kim my %inherited_config = resolve_config($_, $target, @breadcrumbs); 3111e71b7053SJung-uk Kim 3112e71b7053SJung-uk Kim # 'template' is a marker that's considered private to 3113e71b7053SJung-uk Kim # the config that had it. 3114e71b7053SJung-uk Kim delete $inherited_config{template}; 3115e71b7053SJung-uk Kim 3116e71b7053SJung-uk Kim foreach (keys %inherited_config) { 3117e71b7053SJung-uk Kim if (!$combined_inheritance{$_}) { 3118e71b7053SJung-uk Kim $combined_inheritance{$_} = []; 3119e71b7053SJung-uk Kim } 3120e71b7053SJung-uk Kim push @{$combined_inheritance{$_}}, $inherited_config{$_}; 3121e71b7053SJung-uk Kim } 3122e71b7053SJung-uk Kim } 3123e71b7053SJung-uk Kim } 3124e71b7053SJung-uk Kim 3125e71b7053SJung-uk Kim # We won't need inherit_from in this target any more, since we've 3126e71b7053SJung-uk Kim # resolved all the inheritances that lead to this 3127e71b7053SJung-uk Kim delete $table{$target}->{inherit_from}; 3128e71b7053SJung-uk Kim 3129e71b7053SJung-uk Kim # Now is the time to deal with those lists. Here's the place to 3130e71b7053SJung-uk Kim # decide what shall be done with those lists, all based on the 3131e71b7053SJung-uk Kim # values of the target we're currently dealing with. 3132e71b7053SJung-uk Kim # - If a value is a coderef, it will be executed with the list of 3133e71b7053SJung-uk Kim # inherited values as arguments. 3134e71b7053SJung-uk Kim # - If the corresponding key doesn't have a value at all or is the 3135e71b7053SJung-uk Kim # empty string, the inherited value list will be run through the 3136e71b7053SJung-uk Kim # default combiner (below), and the result becomes this target's 3137e71b7053SJung-uk Kim # value. 3138e71b7053SJung-uk Kim # - Otherwise, this target's value is assumed to be a string that 3139e71b7053SJung-uk Kim # will simply override the inherited list of values. 3140e71b7053SJung-uk Kim my $default_combiner = add(); 3141e71b7053SJung-uk Kim 3142e71b7053SJung-uk Kim my %all_keys = 3143e71b7053SJung-uk Kim map { $_ => 1 } (keys %combined_inheritance, 3144e71b7053SJung-uk Kim keys %{$table{$target}}); 3145e71b7053SJung-uk Kim 3146e71b7053SJung-uk Kim sub process_values { 3147e71b7053SJung-uk Kim my $object = shift; 3148e71b7053SJung-uk Kim my $inherited = shift; # Always a [ list ] 3149e71b7053SJung-uk Kim my $target = shift; 3150e71b7053SJung-uk Kim my $entry = shift; 3151e71b7053SJung-uk Kim 3152e71b7053SJung-uk Kim $add_called = 0; 3153e71b7053SJung-uk Kim 3154e71b7053SJung-uk Kim while(ref($object) eq "CODE") { 3155e71b7053SJung-uk Kim $object = $object->(@$inherited); 3156e71b7053SJung-uk Kim } 3157e71b7053SJung-uk Kim if (!defined($object)) { 3158e71b7053SJung-uk Kim return (); 3159e71b7053SJung-uk Kim } 3160e71b7053SJung-uk Kim elsif (ref($object) eq "ARRAY") { 3161e71b7053SJung-uk Kim local $add_called; # To make sure recursive calls don't affect it 3162e71b7053SJung-uk Kim return [ map { process_values($_, $inherited, $target, $entry) } 3163e71b7053SJung-uk Kim @$object ]; 3164e71b7053SJung-uk Kim } elsif (ref($object) eq "") { 3165e71b7053SJung-uk Kim return $object; 3166e71b7053SJung-uk Kim } else { 3167e71b7053SJung-uk Kim die "cannot handle reference type ",ref($object) 3168e71b7053SJung-uk Kim ," found in target ",$target," -> ",$entry,"\n"; 3169e71b7053SJung-uk Kim } 3170e71b7053SJung-uk Kim } 3171e71b7053SJung-uk Kim 31725ac766abSJung-uk Kim foreach my $key (sort keys %all_keys) { 31735ac766abSJung-uk Kim my $previous = $combined_inheritance{$key}; 3174e71b7053SJung-uk Kim 3175e71b7053SJung-uk Kim # Current target doesn't have a value for the current key? 3176e71b7053SJung-uk Kim # Assign it the default combiner, the rest of this loop body 3177e71b7053SJung-uk Kim # will handle it just like any other coderef. 31785ac766abSJung-uk Kim if (!exists $table{$target}->{$key}) { 31795ac766abSJung-uk Kim $table{$target}->{$key} = $default_combiner; 3180e71b7053SJung-uk Kim } 3181e71b7053SJung-uk Kim 31825ac766abSJung-uk Kim $table{$target}->{$key} = process_values($table{$target}->{$key}, 31835ac766abSJung-uk Kim $combined_inheritance{$key}, 31845ac766abSJung-uk Kim $target, $key); 31855ac766abSJung-uk Kim unless(defined($table{$target}->{$key})) { 31865ac766abSJung-uk Kim delete $table{$target}->{$key}; 3187e71b7053SJung-uk Kim } 3188e71b7053SJung-uk Kim# if ($extra_checks && 31895ac766abSJung-uk Kim# $previous && !($add_called || $previous ~~ $table{$target}->{$key})) { 31905ac766abSJung-uk Kim# warn "$key got replaced in $target\n"; 3191e71b7053SJung-uk Kim# } 3192e71b7053SJung-uk Kim } 3193e71b7053SJung-uk Kim 3194e71b7053SJung-uk Kim # Finally done, return the result. 3195e71b7053SJung-uk Kim return %{$table{$target}}; 3196e71b7053SJung-uk Kim} 3197e71b7053SJung-uk Kim 319874664626SKris Kennawaysub usage 319974664626SKris Kennaway { 320074664626SKris Kennaway print STDERR $usage; 3201f579bf8eSKris Kennaway print STDERR "\npick os/compiler from:\n"; 320274664626SKris Kennaway my $j=0; 320374664626SKris Kennaway my $i; 3204f579bf8eSKris Kennaway my $k=0; 320574664626SKris Kennaway foreach $i (sort keys %table) 320674664626SKris Kennaway { 3207e71b7053SJung-uk Kim next if $table{$i}->{template}; 320874664626SKris Kennaway next if $i =~ /^debug/; 3209f579bf8eSKris Kennaway $k += length($i) + 1; 3210f579bf8eSKris Kennaway if ($k > 78) 3211f579bf8eSKris Kennaway { 3212f579bf8eSKris Kennaway print STDERR "\n"; 3213f579bf8eSKris Kennaway $k=length($i); 3214f579bf8eSKris Kennaway } 3215f579bf8eSKris Kennaway print STDERR $i . " "; 321674664626SKris Kennaway } 321774664626SKris Kennaway foreach $i (sort keys %table) 321874664626SKris Kennaway { 3219e71b7053SJung-uk Kim next if $table{$i}->{template}; 322074664626SKris Kennaway next if $i !~ /^debug/; 3221f579bf8eSKris Kennaway $k += length($i) + 1; 3222f579bf8eSKris Kennaway if ($k > 78) 3223f579bf8eSKris Kennaway { 322474664626SKris Kennaway print STDERR "\n"; 3225f579bf8eSKris Kennaway $k=length($i); 3226f579bf8eSKris Kennaway } 3227f579bf8eSKris Kennaway print STDERR $i . " "; 3228f579bf8eSKris Kennaway } 322974664626SKris Kennaway exit(1); 323074664626SKris Kennaway } 323174664626SKris Kennaway 3232e71b7053SJung-uk Kimsub compiler_predefined { 3233e71b7053SJung-uk Kim state %predefined; 3234e71b7053SJung-uk Kim my $cc = shift; 3235e71b7053SJung-uk Kim 3236e71b7053SJung-uk Kim return () if $^O eq 'VMS'; 3237e71b7053SJung-uk Kim 3238e71b7053SJung-uk Kim die 'compiler_predefined called without a compiler command' 3239e71b7053SJung-uk Kim unless $cc; 3240e71b7053SJung-uk Kim 3241e71b7053SJung-uk Kim if (! $predefined{$cc}) { 3242e71b7053SJung-uk Kim 3243e71b7053SJung-uk Kim $predefined{$cc} = {}; 3244e71b7053SJung-uk Kim 3245e71b7053SJung-uk Kim # collect compiler pre-defines from gcc or gcc-alike... 3246e71b7053SJung-uk Kim open(PIPE, "$cc -dM -E -x c /dev/null 2>&1 |"); 3247e71b7053SJung-uk Kim while (my $l = <PIPE>) { 3248e71b7053SJung-uk Kim $l =~ m/^#define\s+(\w+(?:\(\w+\))?)(?:\s+(.+))?/ or last; 3249e71b7053SJung-uk Kim $predefined{$cc}->{$1} = $2 // ''; 3250e71b7053SJung-uk Kim } 3251e71b7053SJung-uk Kim close(PIPE); 3252e71b7053SJung-uk Kim } 3253e71b7053SJung-uk Kim 3254e71b7053SJung-uk Kim return %{$predefined{$cc}}; 3255e71b7053SJung-uk Kim} 3256e71b7053SJung-uk Kim 325774664626SKris Kennawaysub which 325874664626SKris Kennaway{ 325974664626SKris Kennaway my ($name)=@_; 3260e71b7053SJung-uk Kim 3261e71b7053SJung-uk Kim if (eval { require IPC::Cmd; 1; }) { 3262e71b7053SJung-uk Kim IPC::Cmd->import(); 3263e71b7053SJung-uk Kim return scalar IPC::Cmd::can_run($name); 3264e71b7053SJung-uk Kim } else { 3265e71b7053SJung-uk Kim # if there is $directories component in splitpath, 3266e71b7053SJung-uk Kim # then it's not something to test with $PATH... 3267e71b7053SJung-uk Kim return $name if (File::Spec->splitpath($name))[1]; 3268e71b7053SJung-uk Kim 3269e71b7053SJung-uk Kim foreach (File::Spec->path()) { 3270e71b7053SJung-uk Kim my $fullpath = catfile($_, "$name$target{exe_extension}"); 3271e71b7053SJung-uk Kim if (-f $fullpath and -x $fullpath) { 3272e71b7053SJung-uk Kim return $fullpath; 3273e71b7053SJung-uk Kim } 327474664626SKris Kennaway } 327574664626SKris Kennaway } 327674664626SKris Kennaway} 327774664626SKris Kennaway 3278e71b7053SJung-uk Kimsub env 327974664626SKris Kennaway{ 3280e71b7053SJung-uk Kim my $name = shift; 3281e71b7053SJung-uk Kim my %opts = @_; 328274664626SKris Kennaway 3283e71b7053SJung-uk Kim unless ($opts{cacheonly}) { 3284e71b7053SJung-uk Kim # Note that if $ENV{$name} doesn't exist or is undefined, 3285e71b7053SJung-uk Kim # $config{perlenv}->{$name} will be created with the value 3286e71b7053SJung-uk Kim # undef. This is intentional. 3287e71b7053SJung-uk Kim 3288e71b7053SJung-uk Kim $config{perlenv}->{$name} = $ENV{$name} 3289e71b7053SJung-uk Kim if ! exists $config{perlenv}->{$name}; 329074664626SKris Kennaway } 3291e71b7053SJung-uk Kim return $config{perlenv}->{$name}; 329274664626SKris Kennaway} 329374664626SKris Kennaway 3294e71b7053SJung-uk Kim# Configuration printer ############################################## 3295e71b7053SJung-uk Kim 329674664626SKris Kennawaysub print_table_entry 329774664626SKris Kennaway{ 3298e71b7053SJung-uk Kim local $now_printing = shift; 3299e71b7053SJung-uk Kim my %target = resolve_config($now_printing); 3300e71b7053SJung-uk Kim my $type = shift; 330174664626SKris Kennaway 3302e71b7053SJung-uk Kim # Don't print the templates 3303e71b7053SJung-uk Kim return if $target{template}; 330474664626SKris Kennaway 3305e71b7053SJung-uk Kim my @sequence = ( 3306e71b7053SJung-uk Kim "sys_id", 3307e71b7053SJung-uk Kim "cpp", 3308e71b7053SJung-uk Kim "cppflags", 3309e71b7053SJung-uk Kim "defines", 3310e71b7053SJung-uk Kim "includes", 3311e71b7053SJung-uk Kim "cc", 3312e71b7053SJung-uk Kim "cflags", 3313e71b7053SJung-uk Kim "ld", 3314e71b7053SJung-uk Kim "lflags", 3315e71b7053SJung-uk Kim "loutflag", 3316e71b7053SJung-uk Kim "ex_libs", 3317e71b7053SJung-uk Kim "bn_ops", 3318b077aed3SPierre Pronchery "enable", 3319b077aed3SPierre Pronchery "disable", 3320e71b7053SJung-uk Kim "poly1035_asm_src", 3321e71b7053SJung-uk Kim "thread_scheme", 3322e71b7053SJung-uk Kim "perlasm_scheme", 3323e71b7053SJung-uk Kim "dso_scheme", 3324e71b7053SJung-uk Kim "shared_target", 3325e71b7053SJung-uk Kim "shared_cflag", 3326e71b7053SJung-uk Kim "shared_defines", 3327e71b7053SJung-uk Kim "shared_ldflag", 3328e71b7053SJung-uk Kim "shared_rcflag", 3329e71b7053SJung-uk Kim "shared_extension", 3330e71b7053SJung-uk Kim "dso_extension", 3331e71b7053SJung-uk Kim "obj_extension", 3332e71b7053SJung-uk Kim "exe_extension", 3333e71b7053SJung-uk Kim "ranlib", 3334e71b7053SJung-uk Kim "ar", 3335e71b7053SJung-uk Kim "arflags", 3336e71b7053SJung-uk Kim "aroutflag", 3337e71b7053SJung-uk Kim "rc", 3338e71b7053SJung-uk Kim "rcflags", 3339e71b7053SJung-uk Kim "rcoutflag", 3340e71b7053SJung-uk Kim "mt", 3341e71b7053SJung-uk Kim "mtflags", 3342e71b7053SJung-uk Kim "mtinflag", 3343e71b7053SJung-uk Kim "mtoutflag", 3344e71b7053SJung-uk Kim "multilib", 3345e71b7053SJung-uk Kim "build_scheme", 3346e71b7053SJung-uk Kim ); 334774664626SKris Kennaway 3348e71b7053SJung-uk Kim if ($type eq "TABLE") { 3349e71b7053SJung-uk Kim print "\n"; 3350e71b7053SJung-uk Kim print "*** $now_printing\n"; 3351e71b7053SJung-uk Kim foreach (@sequence) { 3352e71b7053SJung-uk Kim if (ref($target{$_}) eq "ARRAY") { 3353e71b7053SJung-uk Kim printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}}); 3354e71b7053SJung-uk Kim } else { 3355e71b7053SJung-uk Kim printf "\$%-12s = %s\n", $_, $target{$_}; 3356c1803d78SJacques Vidrine } 3357c1803d78SJacques Vidrine } 3358e71b7053SJung-uk Kim } elsif ($type eq "HASH") { 3359e71b7053SJung-uk Kim my $largest = 3360e71b7053SJung-uk Kim length((sort { length($a) <=> length($b) } @sequence)[-1]); 3361e71b7053SJung-uk Kim print " '$now_printing' => {\n"; 3362e71b7053SJung-uk Kim foreach (@sequence) { 3363e71b7053SJung-uk Kim if ($target{$_}) { 3364e71b7053SJung-uk Kim if (ref($target{$_}) eq "ARRAY") { 3365e71b7053SJung-uk Kim print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n"; 3366e71b7053SJung-uk Kim } else { 3367e71b7053SJung-uk Kim print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n"; 3368e71b7053SJung-uk Kim } 3369e71b7053SJung-uk Kim } 3370e71b7053SJung-uk Kim } 3371e71b7053SJung-uk Kim print " },\n"; 3372e71b7053SJung-uk Kim } 3373c1803d78SJacques Vidrine} 33746cf8931aSJung-uk Kim 3375e71b7053SJung-uk Kim# Utility routines ################################################### 3376e71b7053SJung-uk Kim 3377e71b7053SJung-uk Kim# On VMS, if the given file is a logical name, File::Spec::Functions 3378e71b7053SJung-uk Kim# will consider it an absolute path. There are cases when we want a 3379e71b7053SJung-uk Kim# purely syntactic check without checking the environment. 3380e71b7053SJung-uk Kimsub isabsolute { 3381e71b7053SJung-uk Kim my $file = shift; 3382e71b7053SJung-uk Kim 3383e71b7053SJung-uk Kim # On non-platforms, we just use file_name_is_absolute(). 3384e71b7053SJung-uk Kim return file_name_is_absolute($file) unless $^O eq "VMS"; 3385e71b7053SJung-uk Kim 3386e71b7053SJung-uk Kim # If the file spec includes a device or a directory spec, 3387e71b7053SJung-uk Kim # file_name_is_absolute() is perfectly safe. 3388e71b7053SJung-uk Kim return file_name_is_absolute($file) if $file =~ m|[:\[]|; 3389e71b7053SJung-uk Kim 3390e71b7053SJung-uk Kim # Here, we know the given file spec isn't absolute 3391e71b7053SJung-uk Kim return 0; 3392e71b7053SJung-uk Kim} 3393e71b7053SJung-uk Kim 3394e71b7053SJung-uk Kim# Makes a directory absolute and cleans out /../ in paths like foo/../bar 3395e71b7053SJung-uk Kim# On some platforms, this uses rel2abs(), while on others, realpath() is used. 3396e71b7053SJung-uk Kim# realpath() requires that at least all path components except the last is an 3397e71b7053SJung-uk Kim# existing directory. On VMS, the last component of the directory spec must 3398e71b7053SJung-uk Kim# exist. 3399e71b7053SJung-uk Kimsub absolutedir { 3400e71b7053SJung-uk Kim my $dir = shift; 3401e71b7053SJung-uk Kim 3402e71b7053SJung-uk Kim # realpath() is quite buggy on VMS. It uses LIB$FID_TO_NAME, which 3403e71b7053SJung-uk Kim # will return the volume name for the device, no matter what. Also, 3404e71b7053SJung-uk Kim # it will return an incorrect directory spec if the argument is a 3405e71b7053SJung-uk Kim # directory that doesn't exist. 3406e71b7053SJung-uk Kim if ($^O eq "VMS") { 3407e71b7053SJung-uk Kim return rel2abs($dir); 3408e71b7053SJung-uk Kim } 3409e71b7053SJung-uk Kim 3410e71b7053SJung-uk Kim # We use realpath() on Unix, since no other will properly clean out 3411e71b7053SJung-uk Kim # a directory spec. 3412e71b7053SJung-uk Kim use Cwd qw/realpath/; 3413e71b7053SJung-uk Kim 3414e71b7053SJung-uk Kim return realpath($dir); 3415e71b7053SJung-uk Kim} 3416e71b7053SJung-uk Kim 341758f35182SJung-uk Kim# Check if all paths are one and the same, using stat. They must both exist 341858f35182SJung-uk Kim# We need this for the cases when File::Spec doesn't detect case insensitivity 341958f35182SJung-uk Kim# (File::Spec::Unix assumes case sensitivity) 342058f35182SJung-uk Kimsub samedir { 342158f35182SJung-uk Kim die "samedir expects two arguments\n" unless scalar @_ == 2; 342258f35182SJung-uk Kim 342358f35182SJung-uk Kim my @stat0 = stat($_[0]); # First argument 342458f35182SJung-uk Kim my @stat1 = stat($_[1]); # Second argument 342558f35182SJung-uk Kim 342658f35182SJung-uk Kim die "Couldn't stat $_[0]" unless @stat0; 342758f35182SJung-uk Kim die "Couldn't stat $_[1]" unless @stat1; 342858f35182SJung-uk Kim 342958f35182SJung-uk Kim # Compare device number 343058f35182SJung-uk Kim return 0 unless ($stat0[0] == $stat1[0]); 343158f35182SJung-uk Kim # Compare "inode". The perl manual recommends comparing as 343258f35182SJung-uk Kim # string rather than as number. 343358f35182SJung-uk Kim return 0 unless ($stat0[1] eq $stat1[1]); 343458f35182SJung-uk Kim 343558f35182SJung-uk Kim return 1; # All the same 343658f35182SJung-uk Kim} 343758f35182SJung-uk Kim 3438e71b7053SJung-uk Kimsub quotify { 3439e71b7053SJung-uk Kim my %processors = ( 3440e71b7053SJung-uk Kim perl => sub { my $x = shift; 3441e71b7053SJung-uk Kim $x =~ s/([\\\$\@"])/\\$1/g; 3442e71b7053SJung-uk Kim return '"'.$x.'"'; }, 3443e71b7053SJung-uk Kim maybeshell => sub { my $x = shift; 3444e71b7053SJung-uk Kim (my $y = $x) =~ s/([\\\"])/\\$1/g; 3445e71b7053SJung-uk Kim if ($x ne $y || $x =~ m|\s|) { 3446e71b7053SJung-uk Kim return '"'.$y.'"'; 3447e71b7053SJung-uk Kim } else { 3448e71b7053SJung-uk Kim return $x; 3449e71b7053SJung-uk Kim } 3450e71b7053SJung-uk Kim }, 3451e71b7053SJung-uk Kim ); 3452e71b7053SJung-uk Kim my $for = shift; 3453e71b7053SJung-uk Kim my $processor = 3454e71b7053SJung-uk Kim defined($processors{$for}) ? $processors{$for} : sub { shift; }; 3455e71b7053SJung-uk Kim 3456e71b7053SJung-uk Kim return map { $processor->($_); } @_; 3457e71b7053SJung-uk Kim} 3458e71b7053SJung-uk Kim 3459e71b7053SJung-uk Kim# collect_from_file($filename, $line_concat_cond_re, $line_concat) 3460e71b7053SJung-uk Kim# $filename is a file name to read from 3461e71b7053SJung-uk Kim# $line_concat_cond_re is a regexp detecting a line continuation ending 3462e71b7053SJung-uk Kim# $line_concat is a CODEref that takes care of concatenating two lines 3463e71b7053SJung-uk Kimsub collect_from_file { 3464e71b7053SJung-uk Kim my $filename = shift; 3465e71b7053SJung-uk Kim my $line_concat_cond_re = shift; 3466e71b7053SJung-uk Kim my $line_concat = shift; 3467e71b7053SJung-uk Kim 3468e71b7053SJung-uk Kim open my $fh, $filename || die "unable to read $filename: $!\n"; 3469e71b7053SJung-uk Kim return sub { 3470e71b7053SJung-uk Kim my $saved_line = ""; 3471e71b7053SJung-uk Kim $_ = ""; 3472e71b7053SJung-uk Kim while (<$fh>) { 3473e71b7053SJung-uk Kim s|\R$||; 3474e71b7053SJung-uk Kim if (defined $line_concat) { 3475e71b7053SJung-uk Kim $_ = $line_concat->($saved_line, $_); 3476e71b7053SJung-uk Kim $saved_line = ""; 3477e71b7053SJung-uk Kim } 3478e71b7053SJung-uk Kim if (defined $line_concat_cond_re && /$line_concat_cond_re/) { 3479e71b7053SJung-uk Kim $saved_line = $_; 3480e71b7053SJung-uk Kim next; 3481e71b7053SJung-uk Kim } 3482e71b7053SJung-uk Kim return $_; 3483e71b7053SJung-uk Kim } 3484e71b7053SJung-uk Kim die "$filename ending with continuation line\n" if $_; 3485e71b7053SJung-uk Kim close $fh; 3486e71b7053SJung-uk Kim return undef; 3487e71b7053SJung-uk Kim } 3488e71b7053SJung-uk Kim} 3489e71b7053SJung-uk Kim 3490e71b7053SJung-uk Kim# collect_from_array($array, $line_concat_cond_re, $line_concat) 3491e71b7053SJung-uk Kim# $array is an ARRAYref of lines 3492e71b7053SJung-uk Kim# $line_concat_cond_re is a regexp detecting a line continuation ending 3493e71b7053SJung-uk Kim# $line_concat is a CODEref that takes care of concatenating two lines 3494e71b7053SJung-uk Kimsub collect_from_array { 3495e71b7053SJung-uk Kim my $array = shift; 3496e71b7053SJung-uk Kim my $line_concat_cond_re = shift; 3497e71b7053SJung-uk Kim my $line_concat = shift; 3498e71b7053SJung-uk Kim my @array = (@$array); 3499e71b7053SJung-uk Kim 3500e71b7053SJung-uk Kim return sub { 3501e71b7053SJung-uk Kim my $saved_line = ""; 3502e71b7053SJung-uk Kim $_ = ""; 3503e71b7053SJung-uk Kim while (defined($_ = shift @array)) { 3504e71b7053SJung-uk Kim s|\R$||; 3505e71b7053SJung-uk Kim if (defined $line_concat) { 3506e71b7053SJung-uk Kim $_ = $line_concat->($saved_line, $_); 3507e71b7053SJung-uk Kim $saved_line = ""; 3508e71b7053SJung-uk Kim } 3509e71b7053SJung-uk Kim if (defined $line_concat_cond_re && /$line_concat_cond_re/) { 3510e71b7053SJung-uk Kim $saved_line = $_; 3511e71b7053SJung-uk Kim next; 3512e71b7053SJung-uk Kim } 3513e71b7053SJung-uk Kim return $_; 3514e71b7053SJung-uk Kim } 3515e71b7053SJung-uk Kim die "input text ending with continuation line\n" if $_; 3516e71b7053SJung-uk Kim return undef; 3517e71b7053SJung-uk Kim } 3518e71b7053SJung-uk Kim} 3519e71b7053SJung-uk Kim 3520e71b7053SJung-uk Kim# collect_information($lineiterator, $line_continue, $regexp => $CODEref, ...) 3521e71b7053SJung-uk Kim# $lineiterator is a CODEref that delivers one line at a time. 3522e71b7053SJung-uk Kim# All following arguments are regex/CODEref pairs, where the regexp detects a 3523e71b7053SJung-uk Kim# line and the CODEref does something with the result of the regexp. 3524e71b7053SJung-uk Kimsub collect_information { 3525e71b7053SJung-uk Kim my $lineiterator = shift; 3526e71b7053SJung-uk Kim my %collectors = @_; 3527e71b7053SJung-uk Kim 3528e71b7053SJung-uk Kim while(defined($_ = $lineiterator->())) { 3529e71b7053SJung-uk Kim s|\R$||; 3530e71b7053SJung-uk Kim my $found = 0; 3531e71b7053SJung-uk Kim if ($collectors{"BEFORE"}) { 3532e71b7053SJung-uk Kim $collectors{"BEFORE"}->($_); 3533e71b7053SJung-uk Kim } 3534e71b7053SJung-uk Kim foreach my $re (keys %collectors) { 3535e71b7053SJung-uk Kim if ($re !~ /^OTHERWISE|BEFORE|AFTER$/ && /$re/) { 3536e71b7053SJung-uk Kim $collectors{$re}->($lineiterator); 3537e71b7053SJung-uk Kim $found = 1; 3538e71b7053SJung-uk Kim }; 3539e71b7053SJung-uk Kim } 3540e71b7053SJung-uk Kim if ($collectors{"OTHERWISE"}) { 3541e71b7053SJung-uk Kim $collectors{"OTHERWISE"}->($lineiterator, $_) 3542e71b7053SJung-uk Kim unless $found || !defined $collectors{"OTHERWISE"}; 3543e71b7053SJung-uk Kim } 3544e71b7053SJung-uk Kim if ($collectors{"AFTER"}) { 3545e71b7053SJung-uk Kim $collectors{"AFTER"}->($_); 3546e71b7053SJung-uk Kim } 3547e71b7053SJung-uk Kim } 3548e71b7053SJung-uk Kim} 3549e71b7053SJung-uk Kim 3550e71b7053SJung-uk Kim# tokenize($line) 3551b077aed3SPierre Pronchery# tokenize($line,$separator) 3552e71b7053SJung-uk Kim# $line is a line of text to split up into tokens 3553b077aed3SPierre Pronchery# $separator [optional] is a regular expression that separates the tokens, 3554b077aed3SPierre Pronchery# the default being spaces. Do not use quotes of any kind as separators, 3555b077aed3SPierre Pronchery# that will give undefined results. 3556b077aed3SPierre Pronchery# Returns a list of tokens. 3557e71b7053SJung-uk Kim# 3558b077aed3SPierre Pronchery# Tokens are divided by separator (spaces by default). If the tokens include 3559b077aed3SPierre Pronchery# the separators, they have to be quoted with single or double quotes. 3560b077aed3SPierre Pronchery# Double quotes inside a double quoted token must be escaped. Escaping is done 3561e71b7053SJung-uk Kim# with backslash. 3562e71b7053SJung-uk Kim# Basically, the same quoting rules apply for " and ' as in any 3563e71b7053SJung-uk Kim# Unix shell. 3564e71b7053SJung-uk Kimsub tokenize { 3565e71b7053SJung-uk Kim my $line = my $debug_line = shift; 3566b077aed3SPierre Pronchery my $separator = shift // qr|\s+|; 3567e71b7053SJung-uk Kim my @result = (); 3568e71b7053SJung-uk Kim 3569b077aed3SPierre Pronchery if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) { 3570b077aed3SPierre Pronchery print STDERR "DEBUG[tokenize]: \$separator = $separator\n"; 3571b077aed3SPierre Pronchery } 3572b077aed3SPierre Pronchery 3573b077aed3SPierre Pronchery while ($line =~ s|^${separator}||, $line ne "") { 3574e71b7053SJung-uk Kim my $token = ""; 3575b077aed3SPierre Pronchery again: 3576b077aed3SPierre Pronchery $line =~ m/^(.*?)(${separator}|"|'|$)/; 3577b077aed3SPierre Pronchery $token .= $1; 3578b077aed3SPierre Pronchery $line = $2.$'; 3579b077aed3SPierre Pronchery 3580e71b7053SJung-uk Kim if ($line =~ m/^"((?:[^"\\]+|\\.)*)"/) { 3581e71b7053SJung-uk Kim $token .= $1; 3582e71b7053SJung-uk Kim $line = $'; 3583b077aed3SPierre Pronchery goto again; 3584e71b7053SJung-uk Kim } elsif ($line =~ m/^'([^']*)'/) { 3585e71b7053SJung-uk Kim $token .= $1; 3586e71b7053SJung-uk Kim $line = $'; 3587b077aed3SPierre Pronchery goto again; 3588e71b7053SJung-uk Kim } 3589e71b7053SJung-uk Kim push @result, $token; 3590e71b7053SJung-uk Kim } 3591e71b7053SJung-uk Kim 3592e71b7053SJung-uk Kim if ($ENV{CONFIGURE_DEBUG_TOKENIZE}) { 3593e71b7053SJung-uk Kim print STDERR "DEBUG[tokenize]: Parsed '$debug_line' into:\n"; 3594e71b7053SJung-uk Kim print STDERR "DEBUG[tokenize]: ('", join("', '", @result), "')\n"; 3595e71b7053SJung-uk Kim } 3596e71b7053SJung-uk Kim return @result; 35976cf8931aSJung-uk Kim} 3598