LOCAL_PATH := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
LOCAL_NAME := $(LOCAL_UUID)_$(LOCAL_CHIP)_tbase_drv_gp_entry

LOCAL_SRC_C := tee/tbase-driver/dr_main_stack_chk_init.c

include $(_sdk_dir)/../source/gp-api/tee-tbase-common.mk

# Disable stack check implementation if already present
_has_stack_check := $(shell nm $(LOCAL_SDK_PATH)/t-base-dev-kit/t-sdk/DrSdk/Out/Bin/DrEntry/DrEntry.lib | grep __stack_chk_fail)
# Check the same for Kinibi500
ifeq ($(_has_stack_check),)
  _has_stack_check := $(shell nm $(LOCAL_SDK_PATH)/t-base-dev-kit/t-sdk/TlSdk/Bin/ARM_V7A_STD/TlEntry/PIE/TlEntry.lib 2>/dev/null | grep __stack_chk_fail)
endif

ifneq ($(_has_stack_check),)
  LOCAL_CFLAGS += -DNO_STACK_CHK_IMPL
else
  ifeq ($(LOCAL_BUILD_TOOL),arm)
    LOCAL_CFLAGS += --no_protect_stack
  else
    LOCAL_CFLAGS += -fno-stack-protector
  endif
endif

include $(BUILD_TBASE_LIBRARY)
