# -*- mode: python; -*-
# NOTE: This file is auto-generated by "zstandard_get_sources.sh" - DO NOT EDIT

Import("env")
Import("get_option")

env = env.Clone()

# Enabling the function sanitizer (part of ubsan) references symbols defined in a separate file when compiled with
# dynamic linking in Clang. The C program definitions setup in SCons do not link this separate file.
# Disable function sanitizer to avoid triggering symbol resolution errors when libraries defined in this
# environment are used by C programs (in this case, wiredtiger).
if get_option("link-model") == "dynamic" and 'undefined' in (get_option('sanitize')
                                                             or '').split(','):
    if env.AddToCCFLAGSIfSupported("-fno-sanitize=function"):
        env.AppendUnique(LINKFLAGS=["-fno-sanitize=function"])

env.Prepend(CPPPATH=[
    'zstd/lib/common',
])

env.Library(
    target="zstd",
    source=[
        'zstd/lib/common/entropy_common.c',
        'zstd/lib/common/error_private.c',
        'zstd/lib/common/fse_decompress.c',
        'zstd/lib/common/pool.c',
        'zstd/lib/common/threading.c',
        'zstd/lib/common/xxhash.c',
        'zstd/lib/common/zstd_common.c',
        'zstd/lib/compress/fse_compress.c',
        'zstd/lib/compress/hist.c',
        'zstd/lib/compress/huf_compress.c',
        'zstd/lib/compress/zstd_compress.c',
        'zstd/lib/compress/zstd_compress_literals.c',
        'zstd/lib/compress/zstd_compress_sequences.c',
        'zstd/lib/compress/zstd_compress_superblock.c',
        'zstd/lib/compress/zstd_double_fast.c',
        'zstd/lib/compress/zstd_fast.c',
        'zstd/lib/compress/zstd_lazy.c',
        'zstd/lib/compress/zstd_ldm.c',
        'zstd/lib/compress/zstd_opt.c',
        'zstd/lib/compress/zstdmt_compress.c',
        'zstd/lib/decompress/huf_decompress.c',
        'zstd/lib/decompress/huf_decompress_amd64.S' if not env.TargetOSIs('windows') else [],
        'zstd/lib/decompress/zstd_ddict.c',
        'zstd/lib/decompress/zstd_decompress.c',
        'zstd/lib/decompress/zstd_decompress_block.c',
        'zstd/lib/deprecated/zbuff_common.c',
        'zstd/lib/deprecated/zbuff_compress.c',
        'zstd/lib/deprecated/zbuff_decompress.c',
        'zstd/lib/dictBuilder/cover.c',
        'zstd/lib/dictBuilder/divsufsort.c',
        'zstd/lib/dictBuilder/fastcover.c',
        'zstd/lib/dictBuilder/zdict.c',
    ],
    LIBDEPS_TAGS=[
        'init-no-global-side-effects',
    ],
)

if env.ToolchainIs('gcc'):
    env.Append(CCFLAGS=["-Wno-stringop-overflow"])
