###################################################################
# Makefile for serialiser testcode in Modelsim
#
# Copyright (c) 2018 Global Inkjet Systems
#
###################################################################

# User files to build, passed in to vproc makefile build
USERCODE    = VUserMain0.cpp utils.cpp runTest.cpp

MODELSIMDIR = c:\altera_18_1\ver\modelsim_ae
FWDEVTOOLS  = e:/git/fw_development_tools
VPROCDIR    = ${FWDEVTOOLS}/verification/vproc

# Name of gnu-make executable
MAKE_EXE    = mingw32-make

# Pick single target files for two auto-generations---UUT and test. 
# The core.h file is always presentfor the UUT, and the test package
# for the test bench
TBAUTOFILE  = test_pkg_auto.vhd

JSONFILES   = doc/*.json 

# If no external code directory (e.g. a HAL) set this to local source directory, else set to code directory
EXTINCLDIR  = ${CURDIR}/src
# Add -DVPROC_VHDL to this variable if using the VHDL models for VProc and memory model
HALCOPTS    = -DVPROC_VHDL

VSIMARGS    = 

#------------------------------------------------------
# BUILD RULES
#------------------------------------------------------

# Build is dependant on generating the auto-gen file and 
# processing makefile in vproc
all: ${TBAUTOFILE} vproc

# Make test bench auto-gen code dependant on all the JSON files to 
# call the batch file if any have changed
${TBAUTOFILE}: ${JSONFILES}
	@cmd /c autogen.bat

# Call the vproc make file for it to determine if anything
# needs building.
.PHONY : vproc
vproc:
	@${MAKE_EXE} -C ${VPROCDIR}                \
                  TESTDIR=${CURDIR}            \
                  USER_C="${USERCODE}"         \
                  MODELSIMDIR="${MODELSIMDIR}" \
                  EXTINCLDIR="${EXTINCLDIR}"   \
                  HALCOPTS="${HALCOPTS}"

#------------------------------------------------------
# EXECUTION RULES
#------------------------------------------------------

run: all
	@${MODELSIMDIR}\win32aloem\vsim -c -do sim.do ${VSIMARGS}

rungui: all
	@${MODELSIMDIR}\\win32aloem\\vsim -gui -do simg.do ${VSIMARGS}
    
compile:
	@${MODELSIMDIR}\\win32aloem\\vsim -c -do compile.do -do quit

gui: rungui

sim: run

#------------------------------------------------------
# CLEANING RULES
#------------------------------------------------------

clean:
	@${MAKE_EXE} -C ${VPROCDIR} USER_C="${USERCODE}" TESTDIR="${CURDIR}" clean
	@rm -rf "wlf*"
	@rm -rf "work"
	@rm -rf  *_auto.vhd

