# Configdata stub template for the Bazel overlay.
# generate_constants.py reads this file and fills in @@PLACEHOLDER@@ values
# to produce per-platform configdata.pm stubs.
#
# Provides data for:
#   - util/dofile.pl template processing (all .h.in files)
#   - apps/progs.pl command table generation
#   - util/mkbuildinf.pl build info
#   - include/openssl/configuration.h.in (platform-specific values)
#   - include/crypto/bn_conf.h.in
#   - include/crypto/dso_conf.h.in

package configdata;
use strict;
use warnings;
use Exporter;
use File::Basename;

our @ISA = qw(Exporter);
our @EXPORT = qw(%config %target %withargs %unified_info %disabled @disablables);
our @EXPORT_OK = qw(@disablables %unified_info %disabled);

# This file lives at <repo_root>/configdata/<config>/configdata.pm.
# Resolve the repo root so paths work inside Bazel runfiles.
my $_repo_root = dirname(dirname(dirname(__FILE__)));

# Read version from VERSION.dat (relative to source root)
my %version_data;
open(my $fh, '<', "$_repo_root/VERSION.dat")
    or die "Cannot open $_repo_root/VERSION.dat: $!";
while (<$fh>) {
    chomp;
    if (/^(\w+)=(.*)$/) {
        my ($key, $val) = ($1, $2);
        $val =~ s/^"(.*)"$/$1/;
        $version_data{$key} = $val;
    }
}
close($fh);

for my $required (qw(MAJOR MINOR PATCH SHLIB_VERSION)) {
    defined $version_data{$required}
        or die "VERSION.dat missing required field: $required";
}

my $major = $version_data{MAJOR};
my $minor = $version_data{MINOR};
my $patch = $version_data{PATCH};
my $pre   = $version_data{PRE_RELEASE_TAG} // '';
my $build_meta = $version_data{BUILD_METADATA} // '';
my $release_date = $version_data{RELEASE_DATE} // '';
my $shlib_version = $version_data{SHLIB_VERSION};
my $version = "$major.$minor.$patch";
my $full_version = $version . ($pre ? "-$pre" : "") . ($build_meta ? "+$build_meta" : "");

our @autowarntext = (
    "WARNING: do not edit!",
    "Generated by configdata.pm (Bazel stub)",
);

our %config = (
    target          => "bazel",
    sourcedir       => $_repo_root,
    builddir        => $_repo_root,
    major           => $major,
    minor           => $minor,
    patch           => $patch,
    prerelease      => $pre,
    build_metadata  => $build_meta,
    version         => $version,
    full_version    => $full_version,
    release_date    => $release_date,
    shlib_version   => $shlib_version,

    b64l            => 0,
    b64             => 1,
    b32             => 0,
    bn_ll           => 0,
    rc4_int         => "unsigned int",
    processor       => "",

    openssl_sys_defines     => ["OPENSSL_SYS_WIN64A"],
    openssl_api_defines     => ["OPENSSL_CONFIGURED_API=30500"],
    openssl_feature_defines => [
        "OPENSSL_RAND_SEED_OS",
        "OPENSSL_THREADS",
        "OPENSSL_NO_ACVP_TESTS",
        "OPENSSL_NO_AFALGENG",
        "OPENSSL_NO_ASAN",
        "OPENSSL_NO_BROTLI",
        "OPENSSL_NO_BROTLI_DYNAMIC",
        "OPENSSL_NO_CRYPTO_MDEBUG",
        "OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE",
        "OPENSSL_NO_DEMOS",
        "OPENSSL_NO_DEVCRYPTOENG",
        "OPENSSL_NO_EC_NISTP_64_GCC_128",
        "OPENSSL_NO_EGD",
        "OPENSSL_NO_EXTERNAL_TESTS",
        "OPENSSL_NO_FIPS_JITTER",
        "OPENSSL_NO_FIPS_POST",
        "OPENSSL_NO_FIPS_SECURITYCHECKS",
        "OPENSSL_NO_FUZZ_AFL",
        "OPENSSL_NO_FUZZ_LIBFUZZER",
        "OPENSSL_NO_H3DEMO",
        "OPENSSL_NO_HQINTEROP",
        "OPENSSL_NO_JITTER",
        "OPENSSL_NO_KTLS",
        "OPENSSL_NO_LOADERENG",
        "OPENSSL_NO_MD2",
        "OPENSSL_NO_MSAN",
        "OPENSSL_NO_PIE",
        "OPENSSL_NO_RC5",
        "OPENSSL_NO_SCTP",
        "OPENSSL_NO_SSL3",
        "OPENSSL_NO_SSL3_METHOD",
        "OPENSSL_NO_SSLKEYLOG",
        "OPENSSL_NO_TFO",
        "OPENSSL_NO_TRACE",
        "OPENSSL_NO_UBSAN",
        "OPENSSL_NO_UNIT_TEST",
        "OPENSSL_NO_WEAK_SSL_CIPHERS",
        "OPENSSL_NO_WINSTORE",
        "OPENSSL_NO_ZLIB",
        "OPENSSL_NO_ZLIB_DYNAMIC",
        "OPENSSL_NO_ZSTD",
        "OPENSSL_NO_ZSTD_DYNAMIC",
        "OPENSSL_NO_DYNAMIC_ENGINE",
    ],

    FIPSKEY => "f4556650ac31d35461610bac4ed81b1a181b2d8a43ea2854cbae22ca74560813",
);

our %target = (
    build_file     => "Makefile",
    perl_platform  => "Windows",
    dso_scheme     => "WIN32",
    dso_extension  => ".dll",
);

our %withargs = ();

our %disabled = ();

# Discover app source files from the file system
my @app_c_files;
if (opendir(my $dh, "$_repo_root/apps")) {
    @app_c_files = map { "$_repo_root/apps/$_" }
                   sort
                   grep { /\.c$/ && $_ ne 'progs.c' && $_ ne 'openssl.c' }
                   readdir($dh);
    closedir($dh);
}

my %sources;
my @obj_files;
for my $src (@app_c_files) {
    (my $obj = $src) =~ s/\.c$/.o/;
    push @obj_files, $obj;
    $sources{$obj} = [$src];
}
$sources{"apps/openssl"} = \@obj_files;

our %unified_info = (
    sources    => \%sources,
    attributes => { sources => {} },
);

our @disablables = qw(acvp-tests afalgeng apps argon2 aria asan asm async atexit autoalginit autoerrinit autoload-config bf blake2 brotli brotli-dynamic buildtest-c++ bulk cached-fetch camellia capieng winstore cast chacha cmac cmp cms comp crypto-mdebug ct default-thread-pool demos h3demo hqinterop deprecated des devcryptoeng dgram dh docs dsa dso dtls dynamic-engine ec ec2m ec_nistp_64_gcc_128 ecdh ecdsa ecx egd engine err external-tests filenames fips fips-securitychecks fips-post fips-jitter fuzz-afl fuzz-libfuzzer gost http idea integrity-only-ciphers jitter ktls legacy loadereng makedepend md2 md4 mdc2 ml-dsa ml-kem module msan multiblock nextprotoneg ocb ocsp padlockeng pic pie pinshared poly1305 posix-io psk quic unstable-qlog rc2 rc4 rc5 rdrand rfc3779 rmd160 scrypt sctp secure-memory seed shared siphash siv slh-dsa sm2 sm2-precomp sm3 sm4 sock srp srtp sse2 ssl ssl-trace static-engine stdio sslkeylog tests tfo thread-pool threads tls tls-deprecated-ec trace ts ubsan ui-console unit-test uplink weak-ssl-ciphers whirlpool zlib zlib-dynamic zstd zstd-dynamic ssl3 ssl3-method tls1 tls1-method tls1_1 tls1_1-method tls1_2 tls1_2-method tls1_3 dtls1 dtls1-method dtls1_2 dtls1_2-method);

1;
