# Copyright 2022 Unisoc (Shanghai) Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ROOT_PATH := $(shell cd ../../../.. && pwd)

# 定义变量
sign_base_dir := $(ROOT_PATH)/prebuilts/scripts/packimage_scripts
sign_script := $(sign_base_dir)/dynamicTA/signta.py
sign_key := $(sign_base_dir)/config/dynamic_ta_privatekey.pem
target_elf_dir :=  $(shell pwd)
src_elf_dir := $(ROOT_PATH)/source/unisoc/trusty/halo-elf
ta_uuid := 403d002191b44949a4f2e7d7071eb49c
ta_in_file := halo-ta.elf
ta := halo

# 定义签名命令
halo_sign_cmd := /usr/bin/python $(sign_script) --uuid $(ta_uuid) --key $(sign_key) --in $(src_elf_dir)/$(ta_in_file) --out $(target_elf_dir)/$(ta).elf

# 定义目标和依赖关系
$(target_elf_dir)/$(ta).elf : $(src_elf_dir)/$(ta_in_file) $(sign_key)
	@echo "sign halo ta begin:"
	@$(halo_sign_cmd)
	@echo "sign halo ta end."

# 如果 HALO_SUPPORT 不为空，则将目标文件添加到安装目标
ifneq ($(strip $(HALO_SUPPORT)),)
$(eval $(INSTALLED_ODMIMAGE_TARGET) : $(target_elf_dir)/$(ta).elf)
endif

# 定义默认目标
.PHONY: sign_halo_ta
sign_halo_ta : $(target_elf_dir)/$(ta).elf

# 打印 root_path 的值
print_root_path:
	@echo "root_path:  $(ROOT_PATH)"

clean:
