#  Copyright (c) 2020, The OpenThread Authors.
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions are met:
#  1. Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#  3. Neither the name of the copyright holder nor the
#     names of its contributors may be used to endorse or promote products
#     derived from this software without specific prior written permission.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#  POSSIBILITY OF SUCH DAMAGE.
#

declare_args() {
  # Configuration file for MbedTLS.
  mbedtls_config_file = "mbedtls-config.h"

  # Extra dependencies for MbedTLS
  mbedtls_deps = [ "../../src/core:libopenthread_core_config" ]
}

config("mbedtls_config") {
  include_dirs = [
    ".",
    "repo/include",
    "repo/library",
  ]

  defines = [ "MBEDTLS_CONFIG_FILE=\"${mbedtls_config_file}\"" ]
}

config("warnings_fix_config") {
  cflags = [
    "-Wno-conversion",
    "-Wno-undef",
  ]
}

group("warnings_fix") {
  public_configs = [
    ":warnings_fix_config",
  ]
}

static_library("mbedtls") {
  sources = [
    "repo/include/mbedtls/aes.h",
    "repo/include/mbedtls/aria.h",
    "repo/include/mbedtls/asn1.h",
    "repo/include/mbedtls/asn1write.h",
    "repo/include/mbedtls/base64.h",
    "repo/include/mbedtls/bignum.h",
    "repo/include/mbedtls/block_cipher.h",
    "repo/include/mbedtls/build_info.h",
    "repo/include/mbedtls/camellia.h",
    "repo/include/mbedtls/ccm.h",
    "repo/include/mbedtls/chacha20.h",
    "repo/include/mbedtls/chachapoly.h",
    "repo/include/mbedtls/check_config.h",
    "repo/include/mbedtls/cipher.h",
    "repo/include/mbedtls/cmac.h",
    "repo/include/mbedtls/compat-2.x.h",
    "repo/include/mbedtls/config_adjust_legacy_crypto.h",
    "repo/include/mbedtls/config_adjust_legacy_from_psa.h",
    "repo/include/mbedtls/config_adjust_psa_from_legacy.h",
    "repo/include/mbedtls/config_adjust_psa_superset_legacy.h",
    "repo/include/mbedtls/config_adjust_ssl.h",
    "repo/include/mbedtls/config_adjust_x509.h",
    "repo/include/mbedtls/config_psa.h",
    "repo/include/mbedtls/constant_time.h",
    "repo/include/mbedtls/ctr_drbg.h",
    "repo/include/mbedtls/debug.h",
    "repo/include/mbedtls/des.h",
    "repo/include/mbedtls/dhm.h",
    "repo/include/mbedtls/ecdh.h",
    "repo/include/mbedtls/ecdsa.h",
    "repo/include/mbedtls/ecjpake.h",
    "repo/include/mbedtls/ecp.h",
    "repo/include/mbedtls/entropy.h",
    "repo/include/mbedtls/error.h",
    "repo/include/mbedtls/gcm.h",
    "repo/include/mbedtls/hkdf.h",
    "repo/include/mbedtls/hmac_drbg.h",
    "repo/include/mbedtls/lms.h",
    "repo/include/mbedtls/mbedtls_config.h",
    "repo/include/mbedtls/md5.h",
    "repo/include/mbedtls/md.h",
    "repo/include/mbedtls/memory_buffer_alloc.h",
    "repo/include/mbedtls/net_sockets.h",
    "repo/include/mbedtls/nist_kw.h",
    "repo/include/mbedtls/oid.h",
    "repo/include/mbedtls/pem.h",
    "repo/include/mbedtls/pkcs12.h",
    "repo/include/mbedtls/pkcs5.h",
    "repo/include/mbedtls/pkcs7.h",
    "repo/include/mbedtls/pk.h",
    "repo/include/mbedtls/platform.h",
    "repo/include/mbedtls/platform_time.h",
    "repo/include/mbedtls/platform_util.h",
    "repo/include/mbedtls/poly1305.h",
    "repo/include/mbedtls/private_access.h",
    "repo/include/mbedtls/psa_util.h",
    "repo/include/mbedtls/ripemd160.h",
    "repo/include/mbedtls/rsa.h",
    "repo/include/mbedtls/sha1.h",
    "repo/include/mbedtls/sha256.h",
    "repo/include/mbedtls/sha3.h",
    "repo/include/mbedtls/sha512.h",
    "repo/include/mbedtls/ssl_cache.h",
    "repo/include/mbedtls/ssl_ciphersuites.h",
    "repo/include/mbedtls/ssl_cookie.h",
    "repo/include/mbedtls/ssl.h",
    "repo/include/mbedtls/ssl_ticket.h",
    "repo/include/mbedtls/threading.h",
    "repo/include/mbedtls/timing.h",
    "repo/include/mbedtls/version.h",
    "repo/include/mbedtls/x509_crl.h",
    "repo/include/mbedtls/x509_crt.h",
    "repo/include/mbedtls/x509_csr.h",
    "repo/include/mbedtls/x509.h",
    "repo/include/psa/build_info.h",
    "repo/include/psa/crypto_adjust_auto_enabled.h",
    "repo/include/psa/crypto_adjust_config_dependencies.h",
    "repo/include/psa/crypto_adjust_config_key_pair_types.h",
    "repo/include/psa/crypto_adjust_config_synonyms.h",
    "repo/include/psa/crypto_builtin_composites.h",
    "repo/include/psa/crypto_builtin_key_derivation.h",
    "repo/include/psa/crypto_builtin_primitives.h",
    "repo/include/psa/crypto_compat.h",
    "repo/include/psa/crypto_config.h",
    "repo/include/psa/crypto_driver_common.h",
    "repo/include/psa/crypto_driver_contexts_composites.h",
    "repo/include/psa/crypto_driver_contexts_key_derivation.h",
    "repo/include/psa/crypto_driver_contexts_primitives.h",
    "repo/include/psa/crypto_extra.h",
    "repo/include/psa/crypto.h",
    "repo/include/psa/crypto_legacy.h",
    "repo/include/psa/crypto_platform.h",
    "repo/include/psa/crypto_se_driver.h",
    "repo/include/psa/crypto_sizes.h",
    "repo/include/psa/crypto_struct.h",
    "repo/include/psa/crypto_types.h",
    "repo/include/psa/crypto_values.h",
    "repo/library/aes.c",
    "repo/library/aesce.c",
    "repo/library/aesce.h",
    "repo/library/aesni.c",
    "repo/library/aesni.h",
    "repo/library/alignment.h",
    "repo/library/aria.c",
    "repo/library/asn1parse.c",
    "repo/library/asn1write.c",
    "repo/library/base64.c",
    "repo/library/base64_internal.h",
    "repo/library/bignum.c",
    "repo/library/bignum_core.c",
    "repo/library/bignum_core.h",
    "repo/library/bignum_core_invasive.h",
    "repo/library/bignum_internal.h",
    "repo/library/bignum_mod.c",
    "repo/library/bignum_mod.h",
    "repo/library/bignum_mod_raw.c",
    "repo/library/bignum_mod_raw.h",
    "repo/library/bignum_mod_raw_invasive.h",
    "repo/library/block_cipher.c",
    "repo/library/block_cipher_internal.h",
    "repo/library/bn_mul.h",
    "repo/library/camellia.c",
    "repo/library/ccm.c",
    "repo/library/chacha20.c",
    "repo/library/chachapoly.c",
    "repo/library/check_crypto_config.h",
    "repo/library/cipher.c",
    "repo/library/cipher_invasive.h",
    "repo/library/cipher_wrap.c",
    "repo/library/cipher_wrap.h",
    "repo/library/cmac.c",
    "repo/library/common.h",
    "repo/library/constant_time.c",
    "repo/library/constant_time_impl.h",
    "repo/library/constant_time_internal.h",
    "repo/library/ctr_drbg.c",
    "repo/library/ctr.h",
    "repo/library/debug.c",
    "repo/library/debug_internal.h",
    "repo/library/des.c",
    "repo/library/dhm.c",
    "repo/library/ecdh.c",
    "repo/library/ecdsa.c",
    "repo/library/ecjpake.c",
    "repo/library/ecp.c",
    "repo/library/ecp_curves.c",
    "repo/library/ecp_curves_new.c",
    "repo/library/ecp_internal_alt.h",
    "repo/library/ecp_invasive.h",
    "repo/library/entropy.c",
    "repo/library/entropy_poll.c",
    "repo/library/entropy_poll.h",
    "repo/library/error.c",
    "repo/library/gcm.c",
    "repo/library/hkdf.c",
    "repo/library/hmac_drbg.c",
    "repo/library/lmots.c",
    "repo/library/lmots.h",
    "repo/library/lms.c",
    "repo/library/md5.c",
    "repo/library/md.c",
    "repo/library/md_psa.h",
    "repo/library/md_wrap.h",
    "repo/library/memory_buffer_alloc.c",
    "repo/library/mps_common.h",
    "repo/library/mps_error.h",
    "repo/library/mps_reader.c",
    "repo/library/mps_reader.h",
    "repo/library/mps_trace.c",
    "repo/library/mps_trace.h",
    "repo/library/net_sockets.c",
    "repo/library/nist_kw.c",
    "repo/library/oid.c",
    "repo/library/padlock.c",
    "repo/library/padlock.h",
    "repo/library/pem.c",
    "repo/library/pk.c",
    "repo/library/pkcs12.c",
    "repo/library/pkcs5.c",
    "repo/library/pkcs7.c",
    "repo/library/pk_ecc.c",
    "repo/library/pk_internal.h",
    "repo/library/pkparse.c",
    "repo/library/pk_wrap.c",
    "repo/library/pk_wrap.h",
    "repo/library/pkwrite.c",
    "repo/library/pkwrite.h",
    "repo/library/platform.c",
    "repo/library/platform_util.c",
    "repo/library/poly1305.c",
    "repo/library/psa_crypto_aead.c",
    "repo/library/psa_crypto_aead.h",
    "repo/library/psa_crypto.c",
    "repo/library/psa_crypto_cipher.c",
    "repo/library/psa_crypto_cipher.h",
    "repo/library/psa_crypto_client.c",
    "repo/library/psa_crypto_core_common.h",
    "repo/library/psa_crypto_core.h",
    "repo/library/psa_crypto_driver_wrappers.h",
    "repo/library/psa_crypto_driver_wrappers_no_static.c",
    "repo/library/psa_crypto_driver_wrappers_no_static.h",
    "repo/library/psa_crypto_ecp.c",
    "repo/library/psa_crypto_ecp.h",
    "repo/library/psa_crypto_ffdh.c",
    "repo/library/psa_crypto_ffdh.h",
    "repo/library/psa_crypto_hash.c",
    "repo/library/psa_crypto_hash.h",
    "repo/library/psa_crypto_invasive.h",
    "repo/library/psa_crypto_its.h",
    "repo/library/psa_crypto_mac.c",
    "repo/library/psa_crypto_mac.h",
    "repo/library/psa_crypto_pake.c",
    "repo/library/psa_crypto_pake.h",
    "repo/library/psa_crypto_random_impl.h",
    "repo/library/psa_crypto_rsa.c",
    "repo/library/psa_crypto_rsa.h",
    "repo/library/psa_crypto_se.c",
    "repo/library/psa_crypto_se.h",
    "repo/library/psa_crypto_slot_management.c",
    "repo/library/psa_crypto_slot_management.h",
    "repo/library/psa_crypto_storage.c",
    "repo/library/psa_crypto_storage.h",
    "repo/library/psa_its_file.c",
    "repo/library/psa_util.c",
    "repo/library/psa_util_internal.h",
    "repo/library/ripemd160.c",
    "repo/library/rsa_alt_helpers.c",
    "repo/library/rsa_alt_helpers.h",
    "repo/library/rsa.c",
    "repo/library/rsa_internal.h",
    "repo/library/sha1.c",
    "repo/library/sha256.c",
    "repo/library/sha3.c",
    "repo/library/sha512.c",
    "repo/library/ssl_cache.c",
    "repo/library/ssl_ciphersuites.c",
    "repo/library/ssl_ciphersuites_internal.h",
    "repo/library/ssl_client.c",
    "repo/library/ssl_client.h",
    "repo/library/ssl_cookie.c",
    "repo/library/ssl_debug_helpers_generated.c",
    "repo/library/ssl_debug_helpers.h",
    "repo/library/ssl_misc.h",
    "repo/library/ssl_msg.c",
    "repo/library/ssl_ticket.c",
    "repo/library/ssl_tls12_client.c",
    "repo/library/ssl_tls12_server.c",
    "repo/library/ssl_tls13_client.c",
    "repo/library/ssl_tls13_generic.c",
    "repo/library/ssl_tls13_invasive.h",
    "repo/library/ssl_tls13_keys.c",
    "repo/library/ssl_tls13_keys.h",
    "repo/library/ssl_tls13_server.c",
    "repo/library/ssl_tls.c",
    "repo/library/threading.c",
    "repo/library/threading_internal.h",
    "repo/library/timing.c",
    "repo/library/version.c",
    "repo/library/version_features.c",
    "repo/library/x509.c",
    "repo/library/x509_create.c",
    "repo/library/x509_crl.c",
    "repo/library/x509_crt.c",
    "repo/library/x509_csr.c",
    "repo/library/x509_internal.h",
    "repo/library/x509write.c",
    "repo/library/x509write_crt.c",
    "repo/library/x509write_csr.c"
  ]

  public_deps = mbedtls_deps
  public_deps += [ ":warnings_fix" ]

  public_configs = [ ":mbedtls_config" ]
}
