# vim: sts=2 ts=8 sw=2 tw=99 et ft=python:
import os

builder.SetBuildFolder('libmbedtls')

rvalue = {}
for cxx in builder.targets:
  binary = Extension.StaticLibrary(builder, cxx, 'mbedtls')
  binary.compiler.includes += [
    os.path.join(builder.sourcePath, 'mbedtls', 'include'),
    os.path.join(builder.sourcePath, 'mbedtls', 'library'),
  ]

  if binary.compiler.family == 'gcc' or binary.compiler.family == 'clang':
    binary.compiler.cflags += ['-std=c11']

  if binary.compiler.family == 'clang':
    # https://llvm.org/bugs/show_bug.cgi?id=16428
    binary.compiler.cflags += ['-Wno-attributes']

  # Defined in mbedtls/library/CMakeLists.txt
  binary.sources += [
    # src_crypto
    'aes.c',
    'aesni.c',
    'arc4.c',
    'aria.c',
    'asn1parse.c',
    'asn1write.c',
    'base64.c',
    'bignum.c',
    'blowfish.c',
    'camellia.c',
    'ccm.c',
    'chacha20.c',
    'chachapoly.c',
    'cipher.c',
    'cipher_wrap.c',
    'cmac.c',
    'ctr_drbg.c',
    'des.c',
    'dhm.c',
    'ecdh.c',
    'ecdsa.c',
    'ecjpake.c',
    'ecp.c',
    'ecp_curves.c',
    'entropy.c',
    'entropy_poll.c',
    'error.c',
    'gcm.c',
    'havege.c',
    'hkdf.c',
    'hmac_drbg.c',
    'md.c',
    'md2.c',
    'md4.c',
    'md5.c',
    'memory_buffer_alloc.c',
    'nist_kw.c',
    'oid.c',
    'padlock.c',
    'pem.c',
    'pk.c',
    'pk_wrap.c',
    'pkcs12.c',
    'pkcs5.c',
    'pkparse.c',
    'pkwrite.c',
    'platform.c',
    'platform_util.c',
    'poly1305.c',
    'psa_crypto.c',
    'psa_crypto_driver_wrappers.c',
    'psa_crypto_se.c',
    'psa_crypto_slot_management.c',
    'psa_crypto_storage.c',
    'psa_its_file.c',
    'ripemd160.c',
    'rsa.c',
    'rsa_internal.c',
    'sha1.c',
    'sha256.c',
    'sha512.c',
    'threading.c',
    'timing.c',
    'version.c',
    'version_features.c',
    'xtea.c',

    # src_x509
    'certs.c',
    'pkcs11.c',
    'x509.c',
    'x509_create.c',
    'x509_crl.c',
    'x509_crt.c',
    'x509_csr.c',
    'x509write_crt.c',
    'x509write_csr.c',

    # src_tls
    'debug.c',
    'net_sockets.c',
    'ssl_cache.c',
    'ssl_ciphersuites.c',
    'ssl_cli.c',
    'ssl_cookie.c',
    'ssl_msg.c',
    'ssl_srv.c',
    'ssl_ticket.c',
    'ssl_tls.c',
    'ssl_tls13_keys.c',
  ]

  rvalue[binary.compiler.target.arch] = builder.Add(binary)
