################################################################################
#
# <t-sdk Sample Sha256 Trusted Application
#
################################################################################

# Set paths
TRUSTLET_DIR := Locals/Code
BUILD_DIR := Locals/Build

# output binary name without path or extension
OUTPUT_NAME := tlSem

#-------------------------------------------------------------------------------
# MobiConvert parameters, see manual for details
#-------------------------------------------------------------------------------
TRUSTLET_UUID := FFFFFFFFF0000000000000000000001B
TRUSTLET_MEMTYPE := 2
TRUSTLET_NO_OF_THREADS := 1
TRUSTLET_SERVICE_TYPE := 3 # 2: service provider trustlet; 3: system trustlet
TRUSTLET_KEYFILE := Locals/Build/pairVendorTltSig.pem #only valid for service provider trustlets.
TRUSTLET_FLAGS := 0
TRUSTLET_INSTANCES := 1

ifeq ($(USE_TBASE_API_LEVEL_11),True)
    HEAP_SIZE_INIT := 300000
    HEAP_SIZE_MAX := 300000
    HW_FLOATING_POINT := Y
    TBASE_API_LEVEL := 11
else
    ifeq ($(USE_SCRYPTO),True)
        HW_FLOATING_POINT := Y
        TBASE_API_LEVEL := 5
    else
        TBASE_API_LEVEL := 4
    endif
endif

ifeq ($(USE_QUICKBUILD_RBS),True)
    RUNTYPE := $(SIGN_RUN_TYPE)
    ifeq ($(HW_FLOATING_POINT),Y)
        TRUSTLET_SIGN_CONF := "\"-s 3 -n 1 -i 1 -m 2 -f 8 -sh 300000 -mh 300000\""    
    else
        TRUSTLET_SIGN_CONF := "\"-s 3 -n 1 -i 1 -m 2 -f 0\""
    endif

    $(warning RUNTYPE : $(RUNTYPE))
    $(warning TRUSTLET_SIGN_CONF : $(TRUSTLET_SIGN_CONF))
endif

ifeq ($(TOOLCHAIN),GNU)
    TRUSTLET_OPTS += -Werror
endif
ifeq ($(TOOLCHAIN),ARM)
   TRUSTLET_OPTS += --diag_error=warning
endif

# ARMCC_COMPILATION_FLAGS += --diag_error=warning # Should to enable '--diag_error=warning' after fix all warnings

ARMCC_COMPILATION_FLAGS += --diag_suppress=1301 # padding inserted in struct
ARMCC_COMPILATION_FLAGS += --diag_suppress=2530 # padding added to end of struct

$(warning *****************************)
$(warning TBASE_API_LEVEL : $(TBASE_API_LEVEL))
$(warning TZ_CHIPSET : $(TZ_CHIPSET))
$(warning CHIP_VENDOR : $(CHIP_VENDOR))
$(warning USE_SCRYPTO : $(USE_SCRYPTO))
$(warning SCRYPTO_VER : $(SCRYPTO_VER))
$(warning USE_QUICKBUILD_RBS : $(USE_QUICKBUILD_RBS))
$(warning SUPPORT_NEW_TA_BUILD : $(SUPPORT_NEW_TA_BUILD))
$(warning USE_TBASE_API_LEVEL_11 : $(USE_TBASE_API_LEVEL_11))
$(warning SKIP_STACK_CHK_FAIL : $(SKIP_STACK_CHK_FAIL))
$(warning *****************************)

#-------------------------------------------------------------------------------
# ISO7816
#-------------------------------------------------------------------------------
# Common
INCLUDE_DIRS += \
    $(SECDRIVER_DIR)/public \
    $(TRUSTLET_DIR)/include/iso7816

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/iso7816/sec_apdu.c \
    $(TRUSTLET_DIR)/src/common/iso7816/iso7816_self_test.c

ISO7816_LIB_C += \
    $(TRUSTLET_DIR)/src/common/iso7816/sec_apdu.c

# Exynos7880 CHIPSET dependency
ifeq ($(TZ_CHIPSET),exynos7880)
ARMCC_COMPILATION_FLAGS += -DSPI_PORT_NUM_0
    $(warning ########### DEFINED SPI_PORT_NUM_0 ########### )
endif

# Exynos7870 CHIPSET dependency
ifeq ($(TZ_CHIPSET),exynos7870)
ARMCC_COMPILATION_FLAGS += -DSPI_PORT_NUM_0
    $(warning ########### DEFINED SPI_PORT_NUM_0 ########### )
ARMCC_COMPILATION_FLAGS += -DCONFIG_TW
    $(warning ########### DEFINED CONFIG_TW ########### )
endif

# Exynos7570 CHIPSET dependency
ifeq ($(TZ_CHIPSET),exynos7570)
ARMCC_COMPILATION_FLAGS += -DSPI_PORT_NUM_0
    $(warning ########### DEFINED SPI_PORT_NUM_0 ########### )
endif

# Exynos7580 CHIPSET dependency
ifeq ($(TZ_CHIPSET),exynos7580)
ARMCC_COMPILATION_FLAGS += -DSPI_PORT_NUM_1
    $(warning ########### DEFINED SPI_PORT_NUM_1 ########### )
endif

# Exynos7885 CHIPSET dependency
ifeq ($(TZ_CHIPSET),exynos7885)
ARMCC_COMPILATION_FLAGS += -DSPI_PORT_NUM_0
    $(warning ########### DEFINED SPI_PORT_NUM_0 ########### )
ARMCC_COMPILATION_FLAGS += -DCONFIG_TW
    $(warning ########### DEFINED CONFIG_TW ########### )
ARMCC_COMPILATION_FLAGS += -DCONFIG_SPI_CS_MANUAL_MODE -DCONFIG_FOR_ESE
    $(warning ########### DEFINED CONFIG_SPI_CS_MANUAL_MODE CONFIG_FOR_ESE ########### )
ARMCC_COMPILATION_FLAGS += -DCONFIG_EXYNOS7885
    $(warning ########### DEFINED CONFIG_EXYNOS7885 ########### )
endif

# Exynos8895 CHIPSET dependency
ifeq ($(TZ_CHIPSET),exynos8895)
ARMCC_COMPILATION_FLAGS += -DSPI_PORT_NUM_6
    $(warning ########### DEFINED SPI_PORT_NUM_6 ########### )
ARMCC_COMPILATION_FLAGS += -DCONFIG_TW
    $(warning ########### DEFINED CONFIG_TW ########### )
endif

# Exynos9810 CHIPSET dependency
ifeq ($(TZ_CHIPSET),exynos9810)
ARMCC_COMPILATION_FLAGS += -DSPI_PORT_NUM_6
    $(warning ########### DEFINED SPI_PORT_NUM_6 ########### )
ARMCC_COMPILATION_FLAGS += -DCONFIG_TW
    $(warning ########### DEFINED CONFIG_TW ########### )
ARMCC_COMPILATION_FLAGS += -DCONFIG_SPI_CS_MANUAL_MODE -DCONFIG_FOR_ESE
    $(warning ########### DEFINED CONFIG_SPI_CS_MANUAL_MODE CONFIG_FOR_ESE ########### )
ARMCC_COMPILATION_FLAGS += -DCONFIG_EXYNOS9810
    $(warning ########### DEFINED CONFIG_EXYNOS9810 ########### )
ifeq ($(USE_TBASE_API_LEVEL_11),True)
ARMCC_COMPILATION_FLAGS += -DUSE_TBASE_API_LEVEL_11
    $(warning ########### DEFINED USE_TBASE_API_LEVEL_11 ########### )
endif
endif

# Exynos9910 CHIPSET dependency
ifeq ($(TZ_CHIPSET),exynos9110)
ARMCC_COMPILATION_FLAGS += -DSPI_PORT_NUM_0
    $(warning ########### DEFINED SPI_PORT_NUM_0 ########### )
endif

# OT dependencies
ifeq ($(CHIP_VENDOR),ot)
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/iso7816/ot \
    $(TRUSTLET_DIR)/src/common/iso7816/ot

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/crc.c \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/otse_spi_transcieve.c \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/spi_framing.c \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/spi_state.c \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/sec_mw.c

ISO7816_LIB_C += \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/crc.c \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/otse_spi_transcieve.c \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/spi_framing.c \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/spi_state.c \
    $(TRUSTLET_DIR)/src/common/iso7816/ot/sec_mw.c
endif

# OTv5 dependencies
ifeq ($(CHIP_VENDOR),otV5)
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/iso7816/otV5 \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5/lrc.c \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5/spi_communication.c \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5/spi_protocol.c \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5/sec_mw.c

ISO7816_LIB_C += \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5/lrc.c \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5/spi_communication.c \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5/spi_protocol.c \
    $(TRUSTLET_DIR)/src/common/iso7816/otV5/sec_mw.c
endif

# NXP dependencies
ifeq ($(CHIP_VENDOR),nxp)
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/iso7816/nxp/common \
    $(TRUSTLET_DIR)/include/iso7816/nxp/hal \
    $(TRUSTLET_DIR)/include/iso7816/nxp/inc \
    $(TRUSTLET_DIR)/include/iso7816/nxp/tml

SRC_CPP += \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/hal/phNxpEseHal.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/hal/phNxpEseHal_Apdu.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/hal/phNxpEseProtocol.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/hal/phNxpEseRecvMgr.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/tml/phTmlEse_spi.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/sec_mw.c

ISO7816_LIB_C += \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/hal/phNxpEseHal.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/hal/phNxpEseHal_Apdu.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/hal/phNxpEseProtocol.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/hal/phNxpEseRecvMgr.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/tml/phTmlEse_spi.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxp/sec_mw.c

endif

# NXP V4 dependencies
ifeq ($(CHIP_VENDOR),nxpV4)
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/iso7816/nxpV4/common \
    $(TRUSTLET_DIR)/include/iso7816/nxpV4/inc \
    $(TRUSTLET_DIR)/include/iso7816/nxpV4/include \
    $(TRUSTLET_DIR)/include/iso7816/nxpV4/lib \
    $(TRUSTLET_DIR)/include/iso7816/nxpV4/log \
    $(TRUSTLET_DIR)/include/iso7816/nxpV4/pal \
    $(TRUSTLET_DIR)/include/iso7816/nxpV4/pal/spi

SRC_CPP += \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/lib/phNxpEse_Apdu_Api.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/lib/phNxpEse_Api.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/lib/phNxpEseDataMgr.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/lib/phNxpEseProto7816_3.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/log/phNxpLog.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/pal/phNxpEsePal.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/pal/spi/phNxpEsePal_spi.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/sec_mw.c

ISO7816_LIB_C += \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/lib/phNxpEse_Apdu_Api.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/lib/phNxpEse_Api.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/lib/phNxpEseDataMgr.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/lib/phNxpEseProto7816_3.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/log/phNxpLog.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/pal/phNxpEsePal.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/pal/spi/phNxpEsePal_spi.c \
    ${TRUSTLET_DIR}/src/common/iso7816/nxpV4/sec_mw.c
endif

# GEMALTO dependencies
ifeq ($(CHIP_VENDOR),$(filter $(CHIP_VENDOR),gem gem51 gem60))
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/iso7816/gem \
    $(TRUSTLET_DIR)/src/common/iso7816/gem

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/checksum.c \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/gto-secese.c \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/iso7816_t1.c \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/transport.c \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/sec_mw.c

ISO7816_LIB_C += \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/checksum.c \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/gto-secese.c \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/iso7816_t1.c \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/transport.c \
    $(TRUSTLET_DIR)/src/common/iso7816/gem/sec_mw.c

endif

ISO7816_LIB_C += \
    $(TRUSTLET_DIR)/src/common/sem/debug.c \
    $(TRUSTLET_DIR)/src/common/sem/tz_utils.c

#-------------------------------------------------------------------------------
# CRYPTO
#-------------------------------------------------------------------------------
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/crypto

ifeq ($(USE_SCRYPTO),True)
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/crypto/scrypto/$(SCRYPTO_VER)

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/crypto/platform/mobicore.c \
    $(TRUSTLET_DIR)/src/common/crypto/crypto_module.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_print.c

CRYPTO_LIB_C += \
    $(TRUSTLET_DIR)/src/common/crypto/platform/mobicore.c \
    $(TRUSTLET_DIR)/src/common/crypto/crypto_module.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_print.c

else
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/crypto/cryptocore \
    ${TRUSTLET_DIR}/src/common/crypto \
    ${TRUSTLET_DIR}/src/common/crypto/libc_functions/portable/allocators

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/crypto/platform/mobicore.c \
    $(TRUSTLET_DIR)/src/common/crypto/crypto_module.c \
    $(TRUSTLET_DIR)/src/common/crypto/crypto_core_init.c \
    $(TRUSTLET_DIR)/src/common/crypto/cryptolib_init.c \
    $(TRUSTLET_DIR)/src/common/crypto/cryptolib_ver.c \
    $(TRUSTLET_DIR)/src/common/crypto/pd_rand/pd_rand.c \
    $(TRUSTLET_DIR)/src/common/crypto/rand/cc_rand.c \
    $(TRUSTLET_DIR)/src/common/crypto/drbg/ctr_drbg.c \
    $(TRUSTLET_DIR)/src/common/crypto/drbg/ctr_drbg_raw.c \
    $(TRUSTLET_DIR)/src/common/crypto/drbg/ctr_drbg_ossl.c \
    $(TRUSTLET_DIR)/src/common/crypto/libc_functions/libc_functions.c \
    $(TRUSTLET_DIR)/src/common/crypto/libc_functions/portable/allocators/memmgrs.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/mem_clr.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdh/ech_ossl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdh/ech_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdh/ech_key.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha256.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha512.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha1dgst.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha1_one.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha_one.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha_dgst.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/lhash/lhash.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/gcm128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/cfb128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/ofb128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/cts128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/ctr128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/cbc128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/ccm128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/xts128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_object.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_utl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_dec.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_dup.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_type.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_fre.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_enc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_typ.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/x_algor.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_int.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/x_attrib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/x_sig.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_bitstr.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/x_bignum.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/asn1_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_new.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_word.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_recp.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_mpi.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_mod.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_print.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_const.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_sqr.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_asm.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_div.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_prime.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_mul.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_add.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_mont.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_rand.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_gcd.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_exp.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_shift.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_nist.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_blind.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_kron.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_sqrt.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_ctx.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_ossl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_sign.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_vrf.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_asn1.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_cbc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_cfb.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_core.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_ctr.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_ecb.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_ige.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_misc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_ofb.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_wrap.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ex_data.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/m_sha1.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/e_aes.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/digest.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/c_all.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/c_allc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/names.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/p_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/evp_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/pmeth_gn.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/c_alld.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/pmeth_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/evp_enc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/hmac/hmac.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/stack/stack.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/buffer/buffer.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/objects/obj_dat.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/objects/o_names.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/objects/obj_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bio/b_print.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/cryptlib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rand/rand_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rand/rand_poll_target.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rand/md_rand.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/mem.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_pmeth.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_err.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_pk1.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_oaep.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_gen.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_x931.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_none.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_sign.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_crpt.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_ssl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_eay.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_saos.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_pss.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_chk.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_pmeth.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_oct.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_mult.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_key.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_oct.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_smpl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_cvt.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_curve.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_print.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_nist.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_nistputil.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_nistp256.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_mont.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/o_init.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/err/err.c

CRYPTO_LIB_C += \
    $(TRUSTLET_DIR)/src/common/crypto/platform/mobicore.c \
    $(TRUSTLET_DIR)/src/common/crypto/crypto_module.c \
    $(TRUSTLET_DIR)/src/common/crypto/crypto_core_init.c \
    $(TRUSTLET_DIR)/src/common/crypto/cryptolib_init.c \
    $(TRUSTLET_DIR)/src/common/crypto/cryptolib_ver.c \
    $(TRUSTLET_DIR)/src/common/crypto/pd_rand/pd_rand.c \
    $(TRUSTLET_DIR)/src/common/crypto/rand/cc_rand.c \
    $(TRUSTLET_DIR)/src/common/crypto/drbg/ctr_drbg.c \
    $(TRUSTLET_DIR)/src/common/crypto/drbg/ctr_drbg_raw.c \
    $(TRUSTLET_DIR)/src/common/crypto/drbg/ctr_drbg_ossl.c \
    $(TRUSTLET_DIR)/src/common/crypto/libc_functions/libc_functions.c \
    $(TRUSTLET_DIR)/src/common/crypto/libc_functions/portable/allocators/memmgrs.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/mem_clr.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdh/ech_ossl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdh/ech_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdh/ech_key.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha256.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha512.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha1dgst.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha1_one.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha_one.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/sha/sha_dgst.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/lhash/lhash.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/gcm128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/cfb128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/ofb128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/cts128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/ctr128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/cbc128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/ccm128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/modes/xts128.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_object.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_utl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_dec.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_dup.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_type.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_fre.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_enc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_typ.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/x_algor.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_int.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/x_attrib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/x_sig.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/a_bitstr.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/x_bignum.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/asn1_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/asn1/tasn_new.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_word.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_recp.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_mpi.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_mod.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_print.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_const.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_sqr.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_asm.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_div.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_prime.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_mul.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_add.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_mont.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_rand.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_gcd.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_exp.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_shift.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_nist.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_blind.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_kron.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_sqrt.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bn/bn_ctx.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_ossl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_sign.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_vrf.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ecdsa/ecs_asn1.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_cbc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_cfb.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_core.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_ctr.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_ecb.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_ige.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_misc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_ofb.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/aes/aes_wrap.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ex_data.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/m_sha1.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/e_aes.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/digest.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/c_all.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/c_allc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/names.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/p_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/evp_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/pmeth_gn.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/c_alld.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/pmeth_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/evp/evp_enc.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/hmac/hmac.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/stack/stack.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/buffer/buffer.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/objects/obj_dat.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/objects/o_names.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/objects/obj_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/bio/b_print.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/cryptlib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rand/rand_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rand/rand_poll_target.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rand/md_rand.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/mem.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_pmeth.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_err.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_pk1.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_oaep.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_gen.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_x931.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_none.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_sign.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_crpt.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_ssl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_eay.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_saos.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_pss.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_chk.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/rsa/rsa_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_pmeth.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_lib.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_oct.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_mult.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_key.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_oct.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_smpl.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_cvt.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_curve.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ec_print.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_nist.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_nistputil.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_nistp256.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/ec/ecp_mont.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/o_init.c \
    $(TRUSTLET_DIR)/src/common/crypto/openssl/err/err.c \
    $(TRUSTLET_DIR)/src/common/sem/debug.c \
    $(TRUSTLET_DIR)/src/common/sem/tz_utils.c
endif
#-------------------------------------------------------------------------------
# SSPM
#-------------------------------------------------------------------------------
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/sspm

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_apdu.c \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_service.c \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_session.c \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_util.c \
    $(TRUSTLET_DIR)/src/common/sspm/ssp.c \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_self_test.c

SSPM_LIB_C += \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_apdu.c \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_service.c \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_session.c \
    $(TRUSTLET_DIR)/src/common/sspm/ssp_util.c \
    $(TRUSTLET_DIR)/src/common/sem/debug.c \
    $(TRUSTLET_DIR)/src/common/sem/tz_utils.c

#-------------------------------------------------------------------------------
# SSEM
#-------------------------------------------------------------------------------
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/ssem

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/ssem/sse_entry_manage.c \
    $(TRUSTLET_DIR)/src/common/ssem/sse_entry_manage_util.c \
    $(TRUSTLET_DIR)/src/common/ssem/sse.c

SSEM_LIB_C += \
    $(TRUSTLET_DIR)/src/common/ssem/sse_entry_manage.c \
    $(TRUSTLET_DIR)/src/common/ssem/sse_entry_manage_util.c

#-------------------------------------------------------------------------------
# SCP03
#-------------------------------------------------------------------------------
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/scp03 \

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/scp03/GPCmd.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_cmdGenerator.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_crypto.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_kdf.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_rspParser.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_tools.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_transceive.c

SCP03_LIB_C += \
    $(TRUSTLET_DIR)/src/common/scp03/GPCmd.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_cmdGenerator.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_crypto.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_kdf.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_rspParser.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_tools.c \
    $(TRUSTLET_DIR)/src/common/scp03/SCP03_transceive.c \
    $(TRUSTLET_DIR)/src/common/sem/debug.c \
    $(TRUSTLET_DIR)/src/common/sem/tz_utils.c

#-------------------------------------------------------------------------------
# SCP11
#-------------------------------------------------------------------------------
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include/scp11 \

SRC_CPP += \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_main.c \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_crypto.c \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_transceive.c \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_tool.c \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_test.c

SCP11_LIB_C += \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_main.c \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_crypto.c \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_transceive.c \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_tool.c \
    $(TRUSTLET_DIR)/src/common/scp11/SCP11_test.c \
    $(TRUSTLET_DIR)/src/common/sem/debug.c \
    $(TRUSTLET_DIR)/src/common/sem/tz_utils.c

#-------------------------------------------------------------------------------
# SEM
#-------------------------------------------------------------------------------
INCLUDE_DIRS += \
    $(TRUSTLET_DIR)/include \
    $(TRUSTLET_DIR)/include/sem \
    $(TRUSTLET_DIR)/include/sem/mobicore

SRC_CPP += \
    $(TRUSTLET_DIR)/src/tlSem.c \
    $(TRUSTLET_DIR)/src/common/sem/cmd_handler.c \
    $(TRUSTLET_DIR)/src/stack_protection.c \
    $(TRUSTLET_DIR)/src/common/sem/sem.c \
    $(TRUSTLET_DIR)/src/common/sem/scpkm.c \
    $(TRUSTLET_DIR)/src/common/sem/service_key.c \
    $(TRUSTLET_DIR)/src/common/sem/scrs.c \
    $(TRUSTLET_DIR)/src/common/sem/factory.c \
    $(TRUSTLET_DIR)/src/common/sem/ccm.c \
    $(TRUSTLET_DIR)/src/common/sem/fra.c \
    $(TRUSTLET_DIR)/src/common/sem/debug.c \
    $(TRUSTLET_DIR)/src/common/sem/tz_utils.c

#-------------------------------------------------------------------------------

### Add source code files for C compiler here
SRC_C += # nothing

### Add source code files for assembler here
SRC_S += # nothing

# Add custom library
CUSTOMER_DRIVER_LIBS +=

ifeq ($(USE_SCRYPTO),True)
ARMCC_COMPILATION_FLAGS += \
    -DMOBICORE \
    -DOPENSSL_FIPS \
    -D_AEABI_PORTABILITY_LEVEL=1 \
    -D__ARMCC__ 

ARMCC_COMPILATION_FLAGS += --diag_remark=191

TA_LINK_OPTS += --diag_suppress=L6367E
TA_LINK_OPTS += --diag_suppress=L6366E
TA_LINK_OPTS += --diag_suppress=L6242E

else
ARMCC_COMPILATION_FLAGS += \
	-DOPENSSL_NO_LOCKING \
	-DNO_SYS_TYPES_H \
	-DOPENSSL_NO_DSA \
	-DOPENSSL_NO_DH \
	-DOPENSSL_NO_ENGINE \
	-DOPENSSL_NO_STDIO \
	-DGETPID_IS_MEANINGLESS \
	-DOPENSSL_NO_CMS \
	-DOPENSSL_EXPORT_VAR_AS_FUNCTION \
	-DOWN_ALLOCATOR \
	-DOPENSSL_NO_ASM \
	-DMOBICORE \
	-DOPENSSL_NO_SHA512

endif

ARMCC_COMPILATION_FLAGS += --protect_stack --protect_stack_all
#-------------------------------------------------------------------------------
include $(TLSDK_DIR_SRC)/trustlet.mk

# Add library scrypto
ifeq ($(USE_SCRYPTO),True)
CC_OPTS += -DUSE_SCRYPTO
LIBS += $(SCRYPTO_LIB_FILE)

run_fips_tools: $(TA_AXF)
	$(FIPS_TOOLS_SCRIPT) $<

all: run_fips_tools
endif

# Add library TZ_CHIPSET=exynos8890
ifeq ($(TZ_CHIPSET),exynos7420)
LIBS +=  \
    $(TRUSTLET_DIR)/lib/secxxxdrv_$(CHIP_VENDOR).lib
else
ifeq ($(KINIBI_VER),500)
$(warning ########### KINIBI_VER 500 - secxxxdrv_500.lib ########### )
LIBS +=  \
    $(TRUSTLET_DIR)/lib/secxxxdrv_500.lib
else
LIBS +=  \
    $(TRUSTLET_DIR)/lib/secxxxdrv.lib
endif
endif

ifeq ($(SKIP_STACK_CHK_FAIL),True)
CC_OPTS += \
    -DSKIP_STACK_CHK_FAIL
endif

#-------------------------------------------------------------------------------
# Make libraries
#-------------------------------------------------------------------------------
ifneq ($(USE_QUICKBUILD_RBS),True)
ISO7816_LIB := $(OUTPUT_PATH)/iso7816_$(CHIP_VENDOR).lib

$(info ISO7816_LIB $(ISO7816_LIB))

ifneq ($(strip $(ISO7816_LIB_C)),)
ISO7816_LIB_OBJ = $(addprefix $(OUTPUT_OBJ_PATH)/,$(join $(dir $(ISO7816_LIB_C)), $(addsuffix .o,$(notdir $(basename $(ISO7816_LIB_C))))))
endif

ifdef ISO7816_LIB_OBJ
all : $(ISO7816_LIB)
endif

ifeq ($(TZ_CHIPSET),exynos7420)
$(ISO7816_LIB) : $(ISO7816_LIB_OBJ)
	$(ARM_RVCT_PATH_BIN)/armar $(ISO7816_LIB) --create -v $(ISO7816_LIB_OBJ) $(TRUSTLET_DIR)/lib/secxxxdrv_$(CHIP_VENDOR).lib
else
ifeq ($(KINIBI_VER),500)
$(warning ########### KINIBI_VER 500 - secxxxdrv_500.lib ########### )
$(ISO7816_LIB) : $(ISO7816_LIB_OBJ)
	$(ARM_RVCT_PATH_BIN)/armar $(ISO7816_LIB) --create -v $(ISO7816_LIB_OBJ) $(TRUSTLET_DIR)/lib/secxxxdrv_500.lib
else
$(ISO7816_LIB) : $(ISO7816_LIB_OBJ)
	$(ARM_RVCT_PATH_BIN)/armar $(ISO7816_LIB) --create -v $(ISO7816_LIB_OBJ) $(TRUSTLET_DIR)/lib/secxxxdrv.lib
endif
endif

#-------------------------------------------------------------------------------
CRYPTO_LIB := $(OUTPUT_PATH)/crypto_$(CHIP_VENDOR).lib

$(info CRYPTO_LIB $(CRYPTO_LIB))

ifneq ($(strip $(CRYPTO_LIB_C)),)
CRYPTO_LIB_OBJ = $(addprefix $(OUTPUT_OBJ_PATH)/,$(join $(dir $(CRYPTO_LIB_C)), $(addsuffix .o,$(notdir $(basename $(CRYPTO_LIB_C))))))
endif

ifdef CRYPTO_LIB_OBJ
all : $(CRYPTO_LIB)
endif

$(CRYPTO_LIB) : $(CRYPTO_LIB_OBJ)
	$(ARM_RVCT_PATH_BIN)/armar $(CRYPTO_LIB) --create -v $(CRYPTO_LIB_OBJ)
#-------------------------------------------------------------------------------
SSPM_LIB := $(OUTPUT_PATH)/sspm_$(CHIP_VENDOR).lib

$(info SSPM_LIB $(SSPM_LIB))

ifneq ($(strip $(SSPM_LIB_C)),)
SSPM_LIB_OBJ = $(addprefix $(OUTPUT_OBJ_PATH)/,$(join $(dir $(SSPM_LIB_C)), $(addsuffix .o,$(notdir $(basename $(SSPM_LIB_C))))))
endif

ifdef SSPM_LIB_OBJ
all : $(SSPM_LIB)
endif

$(SSPM_LIB) : $(SSPM_LIB_OBJ)
	$(ARM_RVCT_PATH_BIN)/armar $(SSPM_LIB) --create -v $(ISO7816_LIB_OBJ) $(CRYPTO_LIB_OBJ) $(SSPM_LIB_OBJ)
#-------------------------------------------------------------------------------
SSEM_LIB := $(OUTPUT_PATH)/ssem_$(CHIP_VENDOR).lib

$(info SSEM_LIB $(SSEM_LIB))

ifneq ($(strip $(SSEM_LIB_C)),)
SSEM_LIB_OBJ = $(addprefix $(OUTPUT_OBJ_PATH)/,$(join $(dir $(SSEM_LIB_C)), $(addsuffix .o,$(notdir $(basename $(SSEM_LIB_C))))))
endif

ifdef SSEM_LIB_OBJ
all : $(SSEM_LIB)
endif

$(SSEM_LIB) : $(SSEM_LIB_OBJ)
	$(ARM_RVCT_PATH_BIN)/armar $(SSEM_LIB) --create -v $(ISO7816_LIB_OBJ) $(CRYPTO_LIB_OBJ) $(SSPM_LIB_OBJ) $(SSEM_LIB_OBJ)
#-------------------------------------------------------------------------------
SCP03_LIB := $(OUTPUT_PATH)/scp03_$(CHIP_VENDOR).lib

$(info SCP03_LIB $(SCP03_LIB))

ifneq ($(strip $(SCP03_LIB_C)),)
SCP03_LIB_OBJ = $(addprefix $(OUTPUT_OBJ_PATH)/,$(join $(dir $(SCP03_LIB_C)), $(addsuffix .o,$(notdir $(basename $(SCP03_LIB_C))))))
endif

ifdef SCP03_LIB_OBJ
all : $(SCP03_LIB)
endif

$(SCP03_LIB) : $(SCP03_LIB_OBJ)
	$(ARM_RVCT_PATH_BIN)/armar $(SCP03_LIB) --create -v $(SCP03_LIB_OBJ) $(CRYPTO_LIB_OBJ)
#-------------------------------------------------------------------------------
SCP11_LIB := $(OUTPUT_PATH)/scp11_$(CHIP_VENDOR).lib

$(info SCP11_LIB $(SCP11_LIB))

ifneq ($(strip $(SCP11_LIB_C)),)
SCP11_LIB_OBJ = $(addprefix $(OUTPUT_OBJ_PATH)/,$(join $(dir $(SCP11_LIB_C)), $(addsuffix .o,$(notdir $(basename $(SCP11_LIB_C))))))
endif

ifdef SCP11_LIB_OBJ
all : $(SCP11_LIB)
endif

$(SCP11_LIB) : $(SCP11_LIB_OBJ)
	$(ARM_RVCT_PATH_BIN)/armar $(SCP11_LIB) --create -v $(SCP11_LIB_OBJ) $(SCP03_LIB_OBJ) $(CRYPTO_LIB_OBJ)
endif
#-------------------------------------------------------------------------------

#CC_OPTS += -DDEBUG_LOW
#CC_OPTS += -DSCP11_ENABLE
#CC_OPTS += -DLOW_SPI_TEST
#CC_OPTS += -DEXTENDED_APDU

# CONFIG
CC_OPTS += \
    -DUSE_MOBICORE \
    -DDEBUG

ifeq ($(TZ_CHIPSET),exynos3250)
$(warning ########### EXYNOS_3250 ########### )
CC_OPTS += \
    -DEXYNOS_3250
endif

ifeq ($(TZ_CHIPSET),exynos7420)
$(warning ########### EXYNOS_7420 ########### )
CC_OPTS += \
    -DEXYNOS_7420
endif

ifeq ($(TZ_CHIPSET),exynos7570)
$(warning ########### EXYNOS_7570 ########### )
CC_OPTS += \
    -DEXYNOS_7570
    # Not used now according current SPI driver lib in Tzen device repo
    # -DCONFIG_FOR_ESE
endif

ifeq ($(TZ_CHIPSET),exynos7580)
$(warning ########### EXYNOS_7580 ########### )
CC_OPTS += \
    -DEXYNOS_7580
endif

ifeq ($(TZ_CHIPSET),exynos7880)
$(warning ########### EXYNOS_7880 ########### )
CC_OPTS += \
    -DEXYNOS_7880 -DCONFIG_FOR_ESE
endif

ifeq ($(TZ_CHIPSET),exynos7870)
$(warning ########### EXYNOS_7870 ########### )
CC_OPTS += \
    -DEXYNOS_7870 -DCONFIG_FOR_ESE
endif

ifeq ($(TZ_CHIPSET),exynos7885)
$(warning ########### EXYNOS_7885 ########### )
CC_OPTS += \
    -DEXYNOS_7885 -DCONFIG_FOR_ESE -DCONFIG_SPI_CS_MANUAL_MODE
endif

ifeq ($(TZ_CHIPSET),$(filter $(TZ_CHIPSET), exynos8890 exynos8890_310B))
$(warning ########### EXYNOS_8890 / EXYNOS_8890_310B ########### )
CC_OPTS += \
    -DEXYNOS_8890 -DCONFIG_FOR_ESE
endif

ifeq ($(TZ_CHIPSET),exynos8895)
$(warning ########### EXYNOS_8895 ########### )
CC_OPTS += \
    -DEXYNOS_8895 -DCONFIG_FOR_ESE
endif

ifeq ($(TZ_CHIPSET),$(filter $(TZ_CHIPSET), exynos9810 exynos9810_400A))
$(warning ########### EXYNOS_9810 ########### )
CC_OPTS += \
    -DEXYNOS_9810 -DCONFIG_SPI_CS_MANUAL_MODE -DCONFIG_FOR_ESE
endif

ifeq ($(TZ_CHIPSET),exynos9110)
$(warning ########### EXYNOS_9110 ########### )
CC_OPTS += \
    -DEXYNOS_9110 -DCONFIG_FOR_ESE
endif

#CC_OPTS += -DFACTORY_RESET

ifeq ($(CHIP_VENDOR),ot)
CC_OPTS += \
    -DOT
endif

ifeq ($(CHIP_VENDOR),otV5)
CC_OPTS += \
    -DOT \
    -DOTV5
endif

ifeq ($(CHIP_VENDOR),gem)
CC_OPTS += \
    -DGEM
endif

ifeq ($(CHIP_VENDOR),gem51)
CC_OPTS += \
    -DGEM \
    -DGEM51
endif

ifeq ($(CHIP_VENDOR),gem60)
CC_OPTS += \
    -DGEM \
    -DGEM60
endif

ifeq ($(CHIP_VENDOR),nxp)
CC_OPTS += \
    -DNXP
endif

ifeq ($(CHIP_VENDOR),nxpV4)
CC_OPTS += \
    -DNXP \
    -DNXPV4
endif
