#//<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>

#################################################################################
##     Directories
#################################################################################
AIE_DIR := $(PWD)/aie
#################################################################################
## Project Parameters
#################################################################################

# Optimization
OPT ?= 0

# hw_emu|hw

TARGET   ?= hw_emu
PFM_NAME := xilinx_vek280_base_202510_1
PFM_NAME := $(strip $(PFM_NAME))
PLATFORM_REPO_PATHS := /opt/amd/2025.1/Vitis/base_platforms

PLATFORM := $(PLATFORM_REPO_PATHS)/xilinx_vek280_base_202510_1/xilinx_vek280_base_202510_1.xpfm
##PLATFORM:= xcve2802-vsvh1760-2MP-e-S

LIBADF  := $(AIE_DIR)/libadf$(OPT).a

# Default values for A, B, C matrix sizes
# A:MxK    B:KxN    C:MxN
sizeM ?= 64
sizeK ?= 64
sizeN ?= 64

# Default for A, B and C sub matrices
# 4x16x8
subM ?= 4
subK ?= 16
subN ?= 8

#Default Number of iterations
NIterations ?= 4

# Width of the PLIOs
PLIOW ?= 128

SIZES := sizeM=$(sizeM) sizeK=$(sizeK) sizeN=$(sizeN) subM=$(subM) subK=$(subK) subN=$(subN) NIterations=$(NIterations) PLIOW=$(PLIOW)

FREQ_HZ := 250000000 # PL Frequency (PL kernels)

##########################################################################################################################################################
### DO NOT MODIFY BELOW THIS LINE UNLESS NECESSARY
################################################################################################################################################

#AIE_FLAGS :=  $(SIZES) OPT=$(OPT) PLATFORM=$(PLATFORM)
AIE_FLAGS :=  $(SIZES) OPT=$(OPT)

###
# Guarding Checks. Do not modify.
###
check_defined = \
	$(strip $(foreach 1,$1, \
		$(call __check_defined,$1,$(strip $(value 2)))))

__check_defined = \
	$(if $(value $1),, \
		$(error Undefined $1$(if $2, ($2))))

guard-PLATFORM_REPO_PATHS:
	$(call check_defined, PLATFORM_REPO_PATHS, Set your where you downloaded your platform)

.PHONY: all_hw all_hw_emu run upd_host_hw aie postaie data aiesim aieviz aiesim-fifo compareaie x86 x86sim comparex86

data:
	make -C aie data
	
x86:
	make -C $(AIE_DIR) x86 $(AIE_FLAGS)

x86sim:
	make -C $(AIE_DIR) OPT=$(OPT) x86sim

comparex86:
	make -C $(AIE_DIR) OPT=$(OPT) comparex86

aie:
	make -C $(AIE_DIR) aie $(AIE_FLAGS)

aiesim:
	make -C $(AIE_DIR) $(AIE_FLAGS) aiesim

aieviz:
	make -C $(AIE_DIR) $(AIE_FLAGS) aieviz

compareaie:
	make -C $(AIE_DIR) OPT=$(OPT) compareaie

clean:
	rm -rf _x v++_* ${XOS} ${OS} ${LIBADF} *.o.* *.o *.xpe *.xo.*  \
	       vek280*.xclbin* *.xsa *.log *.jou xnwOut Work Map_Report.csv \
	       ilpProblem* sol.db drivers .Xil *bin *BIN *.bif launch_hw_emu.sh cfg emu_qemu_scripts \
				 [!d]*.json  *.txt *.wdb *.wcfg *.pdi v++.package_summary sim qemu_dts_files sd_card sd_card.img \
				 dtb_creation.sh .ipcache *summary *.sh .AIE_SIM_CMD_LINE_OPTIONS .crashReporter
	make -C ${AIE_DIR} clean
	
clean-all:
	make clean
	make -C ${AIE_DIR} clean-all

soft-clean:
	make -C ${AIE_DIR} soft-clean
