#/<copyright-disclaimer-start>
#/  **************************************************************************************************************
#/  * © 2026 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>


AIE_SIM_ONLY      ?= true

PLATFORM_REPO_PATHS := /opt/amd/2025.2/Vitis/base_platforms
PLATFORM_USE	  := xilinx_vck190_base_202520_1
PLATFORM          := ${PLATFORM_REPO_PATHS}/${PLATFORM_USE}/${PLATFORM_USE}.xpfm

MY_APP             = duc_app.cpp
MY_SOURCES         = ./aie/${MY_APP} ./aie/duc_graph.h ./aie/resamp_coeff.h 
LOG_FILE           = log
OTHER_OPTS         = --aie.pl-freq=625.0 --aie.Xchess="-std=c++17"
ALL_INCLUDE       := --include=${PWD}/aie
AIE_FLAGS         := --aie.verbose ${ALL_INCLUDE} ./aie/${MY_APP} ${OTHER_OPTS} --platform=${PLATFORM} --aie.Xmapper=BufferOptLevel9 --aie.xlopt=1
DSPLIB_INCLUDE 	:= --include=${DSPLIB_ROOT}/L2/include/aie \
		     --include=${DSPLIB_ROOT}/L1/include/aie \
		     --include=${DSPLIB_ROOT}/L1/src/aie

ifeq (${AIE_SIM_ONLY},true)
	AIE_FLAGS := ${AIE_FLAGS} --aie.Xpreproc="-DAIE_SIM_ONLY"
endif

.PHONY: clean help compile sim

help::
	@echo "Makefile Usage:"
	@echo "  make all"
	@echo "      Command to generate everything for this design"
	@echo ""
	@echo "  make compile"
	@echo "      Run AIE compiler and build the design"
	@echo ""
	@echo "  make sim"
	@echo "      Run AIE simulator"
	@echo ""
	@echo "  make clean"
	@echo "      Command to remove all the generated files."

all          : compile sim get_II check_sim_output_aie

x86all       : x86compile x86sim check_sim_output_x86


x86compile:
	v++ -c --mode aie --target=x86sim ${DSPLIB_INCLUDE} ${AIE_FLAGS} 2>&1 | tee ${LOG_FILE}

x86sim:
	x86simulator 2>&1 | tee -a ${LOG_FILE} 
	
check_sim_output_x86:
	matlab -batch "check_sim_output('x86sim')"

aiecompile:	${MY_SOURCES}
	v++ -c --mode aie --target=hw ${DSPLIB_INCLUDE} ${AIE_FLAGS} 2>&1 | tee ${LOG_FILE}
	
aiesim:
	aiesimulator --profile -wdb -text 2>&1 | tee -a ${LOG_FILE}

check_sim_output_aie:
	matlab -batch "check_sim_output('hw')"

throughput:
	@../support/scripts/throughput.py aiesimulator_output/data/sig_o.txt --iscomplex

get_II:
	@../support/scripts/get_loop_II.py Work/aie/

clean:
	@rm -rf Work* .Xil function_wdb_dir .crashReporter .AIE_SIM_CMD_LINE_OPTIONS AIECompiler.log xcd.log log aiesimulator_output x86simulator_output diff_output pl_sample_count* tmp vitis_analyzer.* xsc_report.log diag_report.log libadf.a sol.db t.txt Map_Report.csv AIESimulator.log
	@rm -rf ISS_RPC_SERVER_PORT system_flat.wcfg system.wcfg system.wdb tmp.vcd.vcd trdata.aiesim vcdanalyze.log vitis_analyzer_pid* logs VCDAnalyze.log
