LOCAL_PATH := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

LOCAL_NAME := $(LOCAL_UUID)_$(LOCAL_CHIP)_tbase_gp_tee

include $(_sdk_dir)/../source/gp-api/tee-tbase-common.mk

include $(_sdk_dir)/../source/gp-api/crypto.mk

LOCAL_SRC_C := tee/tbase/tl_main.c \
               tee/tbase/tee_sys.c \
               tee/tbase/tee_time.c \
               tee/tbase/tees_mem.c \
               tee/tbase/tees_log.c \
               tee/tbase/tees_secure_object.c \
               tee/tbase/persistent_object.c \
               uuid_utils/uuid_utils.c \
               protocol/tee_param_utils.c \
               persistent_object/persistent_object_api.c \
               persistent_object/serialise_attr.c \
               persistent_time/tee_persistent_time.c \
               log_utils/log_utils.c \
               cancellation_func/tee_cancel.c \
               tee/tbase/tee_cancel.c \
               crypto/kdf/tees_kdf_tbase.c \
               $(CRYPTO_SRC)

# gp-api properties
_gpapi_include_dirs := prop/src \
                       prop/tee \
                       prop/inc \
                       prop/tee/non-blowfish-include \
                       ../../include/gp-ext \
                       $(CRYPTO_INCLUDE_DIRS)

LOCAL_SRC_C += prop/src/property.c \
               prop/src/tee_string.c \
               prop/src/uuid.c

include $(_sdk_dir)/uuid-utils.mk
TA_UUID_STRUCT = $(strip $(call get-local-uuid-as-struct,$(LOCAL_UUID)))
TA_GROUP_ID = $(LOCAL_GROUP_ID)
LOCAL_CFLAGS += -DYOUR_TA_UUID='$(TA_UUID_STRUCT)' -DYOUR_GROUP_ID=\"$(TA_GROUP_ID)\" \
                -DTBASE_APP_NAME=\"$(LOCAL_TBASE_APP_NAME)\" $(CRYPTO_CFLAGS)

ifeq ($(LOCAL_FIPS_CRYPTO),y)
    LOCAL_CFLAGS += -DBORING_SSL
else
    _gpapi_include_dirs += ../../prebuilt/arm/cryptocore/include
endif

#RPMB FLAGS which is were found by empirical way for exynos8895 and exynos8890 chips.
#For other chips RPMB API implenentation may be switched on only after investigation.
#Stubs are used by default for other chips.
ifneq (,$(filter $(LOCAL_CHIP),exynos8895 exynos8890 exynos9810))
    LOCAL_SRC_C += tee/tbase/tees_rpmb.c
else
    LOCAL_SRC_C += tee/stubs/tees_rpmb.c
endif

LOCAL_CFLAGS += -DRPMB_BLOCK_SIZE=256 \
                -DRPMB_PART_NUM=8 \
                -DRPMB_MIN_PARTITION_ID=0 \
                -DRPMB_MAX_PARTITION_ID=32

ifneq ($(filter $(LOCAL_CHIP),exynos9810 exynos8895),)
    LOCAL_CFLAGS += -DRPMB_MAX_ADDRESS_NUM=512 \
                    -DRPMB_MAX_BLOCK_NUM=32
endif

ifeq ($(LOCAL_CHIP),exynos8890)
    LOCAL_CFLAGS += -DRPMB_MAX_ADDRESS_NUM=2048 \
                    -DRPMB_MAX_BLOCK_NUM=1
endif

_import_include_dirs := $(LOCAL_INCLUDE_DIRS)
LOCAL_INCLUDE_DIRS := $(_gpapi_include_dirs) $(_import_include_dirs)

# clang
ifeq ($(LOCAL_BUILD_TOOL),llvm)
    LOCAL_CFLAGS += -Wall -Werror -Wno-gnu-folding-constant
endif

include $(BUILD_TBASE_LIBRARY)
