_local_path := $(call my-dir)

# _local_module should be initialized only when old non-target build is used,
# because it breaks  new target build. In order to detect old non-target build
# LOCAL_TARGET_NAME variable is checked - it is not initialized in case of old
# non-target build.
ifeq ($(LOCAL_TARGET_NAME),)
  _local_module := $(LOCAL_MODULE)
endif

include $(CLEAR_VARS)
LOCAL_MODULE := $(_local_module:%=%_)solib_gp_client
LOCAL_SRC_FILES += \
  $(_local_path)/../source/gp-api/client/tees_client_log_android.c \
  $(_local_path)/../source/gp-api/client/teec_common_solib.c \
  $(_local_path)/../source/gp-api/client/tee_client_api.c \
  $(_local_path)/../source/gp-api/client/teec_callback_handler.c \
  $(_local_path)/../source/gp-api/protocol/teec_param_utils.c \
  $(_local_path)/../source/gp-api/filesystem/fs_po.c \
  $(_local_path)/../source/gp-api/filesystem/fs_utils.c

LOCAL_C_INCLUDES += \
  $(_local_path)/../include/gp-api \
  $(_local_path)/../include/gp-mb \
  $(_local_path)/../source/gp-api/client \
  $(_local_path)/../source/gp-api/protocol \
  $(_local_path)/../source/gp-api/filesystem \
  $(_local_path)/../source/gp-api/tee/emulator \
  $(call get-tbase-include-paths,$(LOCAL_SDK_PATH))

LOCAL_CFLAGS += -Wall -Werror

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)

ifeq ($(LOCAL_SHRINK_PROTOCOL_BUFFER),y)
  LOCAL_CFLAGS += -DSHRINK_PROTOCOL_BUFFER
endif

ifeq ($(_global_$(TARGET_ARCH_ABI)_$(LOCAL_MODULE)_solib_a),)
  _global_$(TARGET_ARCH_ABI)_$(LOCAL_MODULE)_solib_a := included
else
  $(error IMPORT_SOLIB_GP_CLIENT was manually included more than once. \
          In order to fix this error set variable LOCAL_MODULE before the \
          include or use new target build.)
endif

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := $(_local_module:%=%_)solib_gp_client

# in case of old non-target build it is needed to restore original value 
# of LOCAL_MODULE and reset _local_module
ifneq ($(_local_module),)
  LOCAL_MODULE := $(_local_module)
  _local_module :=
endif

LOCAL_LDLIBS := -llog
# WARNING: Below client's Android module will start. Don't clear variables after this line.
