_sdk_dir := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

include $(_sdk_dir)/sign-qsee-common.mk
include $(_sdk_dir)/sign-locally-goal.mk


_tmp_nhlos_path := $(_local_output_base)/$(LOCAL_CHIP)_$(LOCAL_QSEE_PROC)_nhlos

# Link cpecific command line to the specific goal.
# This variable will be chosen automatically when executing rule.
ifeq ($(LOCAL_CHIP),$(filter $(LOCAL_CHIP),msm8998 msm8x26))
  _build_id := $(strip $(call get-qsee-swd-build-id,$(LOCAL_SDK_PATH),$(LOCAL_CHIP)))
  _source_dir := $(_tmp_nhlos_path)/trustzone_images/build/ms/bin/PIL_IMAGES/SPLITBINS_$(_build_id)/
  _destination_dir := $(dir $(_local_output))
  $(_local_input)_sign := \
      $(foreach _file,$(notdir $(shell ls $(_source_dir)/multibuild*)), \
        $(shell mkdir -p $(_destination_dir); \
        cp $(_source_dir)/$(_file) $(_destination_dir)/`echo $(_file) | sed "s/multibuild/$(LOCAL_NAME)/g"`))
else
  $(_local_input)_sign := python $(call get-qsee-sectools-script,$(_tmp_nhlos_path)) secimage \
                               -i $(_local_input) \
                               -o $(dir $(_local_output)) -g multibuild \
                               -c $(firstword $(call get-qsee-secimage-xml,$(_tmp_nhlos_path),$(_tmp_nhlos_path))) \
                               -sea \
                               && cp $(dir $(_local_output))/default/multibuild/$(LOCAL_NAME).mbn $(dir $(_local_output))
endif

##############
# Clear vars #
##############

include $(_sdk_dir)/clear-vars.mk
