# -*- mode: python -*-

Import("env")
Import("endian")
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"])

if env.TargetOSIs('windows'):
    # C4018: '<': signed/unsigned mismatch
    env.Append(CCFLAGS=['/wd4018'])

env.Append(CPPDEFINES=[
    "HAVE_CONFIG_H",
])

if env.ToolchainIs('clang', 'GCC'):
    # -Wno-error=ignored-attributes is set because clang and gcc both discard the algined and may_alias
    # attributes for typedefs passed as template arguments, which triggers a compiler warning when we use
    # templates with SIMD types. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97222 and
    # https://bugs.llvm.org/show_bug.cgi?id=47674 for more details.
    env.Append(
        CCFLAGS=['-Wno-sign-compare', '-Wno-unused-function', '-Wno-error=ignored-attributes'])

env.Library(
    target='snappy',
    source=[
        'dist/snappy-c.cc',
        'dist/snappy.cc',
        'dist/snappy-sinksource.cc',
    ],
)
