################################################################################
#
# MobiCore Makefile Template
#
################################################################################


### this is our home dir
TRUSTLET_DIR := ../../common
BUILD_DIR := ../build

### Secure Driver ###
SECDRIVER_DIR := ../driver/$(SUB_CHIPSET)

CUSTOMER_DRIVER_LIBS += $(SECDRIVER_DIR)/secdrv.lib
ifeq ($(USE_FCDRV), true)
CUSTOMER_DRIVER_LIBS += $(SECDRIVER_DIR)/fcdrv.lib
endif

#-------------------------------------------------------------------------------
# Output
#-------------------------------------------------------------------------------
### output name without path or extension
OUTPUT_NAME := tl_km_agent

### Mobiconvert parameters
TRUSTLET_UUID := ffffffff000000000000000000000017
TRUSTLET_MEMTYPE := 2 # 2: ERAM
TRUSTLET_NO_OF_THREADS := 1 # min =1; max =8
TRUSTLET_SERVICE_TYPE := 3 # 1: driver; 2: service provider trustlet; 3: system trustlet
TRUSTLET_INSTANCES := 1
TRUSTLET_FLAGS := 0
TRUSTLET_KEYFILE := $(BUILD_DIR)/pairVendorTltSig.pem

#-------------------------------------------------------------------------------
# Files and include paths - Add your files here
#-------------------------------------------------------------------------------

### A simple scatter file and set SCATTER_FILE.
### Uncomment this to use a custom scatter file $(OUTPUT_NAME).sct
# SCATTER_FILE := $(TRUSTLET_DIR)/$(OUTPUT_NAME).sct

### Enable Stack_protection
ARMCC_COMPILATION_FLAGS += --protect_stack --protect_stack_all

### Add include path here
INCLUDE_DIRS += \
    $(COMP_PATH_ROOT)/AndroidIntegration/mobicore/daemon/ClientLib/public \
    $(TRUSTLET_DIR) \
    $(SECDRIVER_DIR) \
    $(TRUSTLET_DIR)/crypto/include \
    $(TRUSTLET_DIR)/x509 \
    $(TRUSTLET_DIR)/wb \
    $(TRUSTLET_DIR)/base64 \
    $(TRUSTLET_DIR)/../kinibi/src \
    $(TRUSTLET_DIR)/../kinibi/src/public \
    $(TRUSTLET_DIR)/../../nwd/common/include \
    $(COMP_PATH_ROOT)/$(COMP_PATH_DrSdk)/Public/MobiCore/inc \
    $(COMP_PATH_ROOT)/$(COMP_PATH_DrSdk)/Public \
    $(COMP_PATH_ROOT)/$(COMP_PATH_TlSdk)/Out/Public \
    $(COMP_PATH_ROOT)/$(COMP_PATH_TlSdk)/Public \
    $(COMP_PATH_ROOT)/$(COMP_PATH_TlSdk)/Out/Public/MobiCore/inc

### Add source code files for C++ compiler here
SRC_CPP += \
    $(TRUSTLET_DIR)/CryptoPlatform.c \
    $(TRUSTLET_DIR)/CommandHandler.c \
    $(TRUSTLET_DIR)/x509/asn1.c \
    $(TRUSTLET_DIR)/x509/asn1gen.c \
    $(TRUSTLET_DIR)/x509/asn1rsa.c \
    $(TRUSTLET_DIR)/x509/asn1ec.c \
    $(TRUSTLET_DIR)/x509/da_cert_gencer.c \
    $(TRUSTLET_DIR)/x509/da_cert_parcer.c \
    $(TRUSTLET_DIR)/x509/x509v3.c \
    $(TRUSTLET_DIR)/crypto/sec_alloc.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_wrapper.c \
    $(TRUSTLET_DIR)/crypto/rsa/rsa_wrapper.c \
    $(TRUSTLET_DIR)/crypto/mem_clr.c \
    $(TRUSTLET_DIR)/../kinibi/src/CryptoPlatformMC.c \
    $(TRUSTLET_DIR)/../kinibi/src/mobicore_utils.c \
    $(TRUSTLET_DIR)/../kinibi/src/mobicore_agent_main.c \
    $(TRUSTLET_DIR)/../../nwd/common/ServiceName.c \
    $(TRUSTLET_DIR)/../../nwd/common/TLV.c \
    $(TRUSTLET_DIR)/base64/base64.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_ctx.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_rand.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_asm.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_word.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_add.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_mul.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_mod.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_div.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_exp.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_sqr.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_shift.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_mont.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_recp.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_gcd.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_prime.c \
    $(TRUSTLET_DIR)/crypto/bn/bn_lib.c \
    $(TRUSTLET_DIR)/crypto/ec/ec_key.c \
    $(TRUSTLET_DIR)/crypto/ec/ec_lib.c \
    $(TRUSTLET_DIR)/crypto/ec/ec_curve.c \
    $(TRUSTLET_DIR)/crypto/ec/ec_cvt.c \
    $(TRUSTLET_DIR)/crypto/ec/ec_mult.c \
    $(TRUSTLET_DIR)/crypto/ec/ecp_mont.c \
    $(TRUSTLET_DIR)/crypto/ec/ecp_smpl.c \
    $(TRUSTLET_DIR)/crypto/rsa/rsa_gen.c \
    $(TRUSTLET_DIR)/crypto/rsa/rsa.c \
    $(TRUSTLET_DIR)/crypto/rand/rand_lib.c \
    $(TRUSTLET_DIR)/crypto/hash/sha512.c

### Add source code files for C compiler here
SRC_C += #nothing

### Add source code files for assembler here
SRC_S += #nothing

#-------------------------------------------------------------------------------
ifeq ($(USE_MC32), true) 
include $(BUILD_DIR)/trustlet_MC32.mk
endif

ifeq ($(USE_MC310), true)
include $(BUILD_DIR)/trustlet_MC310.mk
endif

ifeq ($(USE_MC311), true)
include $(BUILD_DIR)/trustlet_MC311.mk
endif

ifeq ($(USE_MC400), true)
include $(BUILD_DIR)/trustlet_MC400.mk
endif

#-------------------------------------------------------------------------------
# CONFIG
CC_OPTS += \
    -DUSE_MOBICORE -DSWD -DUSE_DRK_SERVICE

ifeq ($(MODE), Debug)
CC_OPTS += \
    -DSWD_DEBUG
endif

ifeq ($(USE_FCDRV), true)
CC_OPTS += -DUSE_FCDRV
endif

ifeq ($(USE_DRKV2), TRUE)
CC_OPTS += \
    -DUSE_DRKV2
endif

ifneq ($(USE_PREDEFINED_STACK_CHECK), true)
CC_OPTS += \
    -DCONFIG_USE_STACK_CHECK_FUNC
endif
