#
# Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT
#
# Author: Stephen MacMahon
#    2023/15/11 - rs - initial based on QEMU support files created by Stephen MacMahon

SHELL := /bin/bash
VERSION ?= 2023.2
TOOLS ?= /opt/amd/Vitis
INSTALL ?= $(TOOLS)/$(VERSION)
APP ?= "NULL"
MULTI ?= 1
COSIM ?= 0
TMP_DIR ?= /tmp/tmp_dir
REPO ?= ./repo
PROC ?= "NULL"
XSA ?= "NULL"
FORCE_LINKER ?= 0

all: build_qemu_dts generate_apps generate_qemu_scripts

build_qemu_dts:
	$(RM) -rf qemu-devicetrees
	export PATH=$$PATH:$(TOOLS)/$(VERSION)/bin/dtc; \
	$(TOOLS)/$(VERSION)/bin/xsct -eval "source xsct_script.tcl; build_qemu_dts -install $(TOOLS)/$(VERSION)"
	$(MAKE) -C qemu-devicetrees

supported_apps:
	$(TOOLS)/$(VERSION)/bin/xsct -eval "source xsct_script.tcl; generate_apps -repo $(REPO) -xsa $(XSA) -list_apps"

supported_procs:
	$(TOOLS)/$(VERSION)/bin/xsct -eval "source xsct_script.tcl; get_supported_procs -xsa $(XSA) -open_xsa 1"
	
generate_apps:
	$(RM) -rf plm_files
	mkdir plm_files
	$(TOOLS)/$(VERSION)/bin/xsct -eval "source xsct_script.tcl; generate_apps -repo $(REPO) -xsa $(XSA) -app $(APP) -multi $(MULTI) -proc $(PROC) -force_linker $(FORCE_LINKER)"

generate_qemu_scripts:
	$(RM) -rf *.sh
	$(TOOLS)/$(VERSION)/bin/xsct -eval "source xsct_script.tcl; generate_qemu_scripts -install $(TOOLS)/$(VERSION) -xsa $(XSA) -multi $(MULTI) -cosim $(COSIM) -tmp_dir $(TMP_DIR)"

run_qemu:
	$(RM) -r $(TMP_DIR)
	mkdir $(TMP_DIR)
	source run_qemu.sh

kill_qemu:
	ps -aef | grep  qemu  | awk '{ print $2 }' | xargs kill -9

qemu_clean:
	$(RM) -rf $(APP) *.log drivers .Xil plm_files tmp_dir versal_plm *.sh zynqmp_pmufw psu_init.tcl *.c *.h *.html logs _ide compile_commands.json _xsa *.pdi *.json $(APP)* *.txt a72* r5* qemu-devicetrees

clean_all:
	$(RM) -rf $(APP) dtc repo qemu-devicetrees *.log drivers .Xil plm_files tmp_dir versal_plm *.sh zynqmp_pmufw psu_init.tcl *.c *.h *.html logs _ide compile_commands.json
#<copyright-disclaimer-start>
#<copyright-disclaimer-start>
#  **************************************************************************************************************
#  * © 2024 Advanced Micro Devices, Inc. All rights reserved.                                                   *
#  * DISCLAIMER                                                                                                 *
#  * The information contained herein is for informational purposes only, and is subject to change              *
#  * without notice. While every precaution has been taken in the preparation of this document, it              *
#  * may contain technical inaccuracies, omissions and typographical errors, and AMD is under no                *
#  * obligation to update or otherwise correct this information.  Advanced Micro Devices, Inc. makes            *
#  * no representations or warranties with respect to the accuracy or completeness of the contents of           *
#  * this document, and assumes no liability of any kind, including the implied warranties of noninfringement,  *
#  * merchantability or fitness for particular purposes, with respect to the operation or use of AMD            *
#  * hardware, software or other products described herein.  No license, including implied or                   *
#  * arising by estoppel, to any intellectual property rights is granted by this document.  Terms and           *
#  * limitations applicable to the purchase or use of AMD’s products are as set forth in a signed agreement     *
#  * between the parties or in AMD's Standard Terms and Conditions of Sale. GD-18                               *
#  *                                                                                                            *
#  **************************************************************************************************************
#<copyright-disclaimer-end>
#<copyright-disclaimer-end>
