# Makefile

# defaults
SIM ?= nvc
TOPLEVEL_LANG ?= vhdl
WAVES ?= 1

GHDL_BUILD=ghdl_build

# MODULE is the basename of the Python test file
MODULE   = test_system_top
TOPLEVEL = system_top

HDL_LIBRARY ?= -P$(PWD)/../work/xpm -P$(PWD)/../work/tich -P$(PWD)/../work/utils

RTL_FILES =  $(PWD)/../../src/pkg/system_pkg.vhd
RTL_FILES += $(PWD)/../../src/units/edge_detector.vhd
RTL_FILES += $(PWD)/../../src/spi/spi_rcv.vhd
RTL_FILES += $(PWD)/../wrappers/system_top.vhd

ANALYZE_ARGS   += --std=08 --work=tich --workdir=$(GHDL_BUILD)
ELABORATE_ARGS += --std=08 --work=tich --workdir=$(GHDL_BUILD)
RUN_ARGS       += --vpi=$(shell cocotb-config --lib-dir)/libcocotbvpi_ghdl.so
SIM_ARGS       += $(ELABORATE_ARGS)
VSIM_ARGS      = -t 1ps
VCD_ARGS       = --vcd=waveform.vcd --vcd-enums


COCOTB_HDL_TIMEUNIT=1ns
COCOTB_HDL_TIMEPRECISION=1ps

# GHDL commands
analyze:
	mkdir -p $(GHDL_BUILD)
	ghdl -a  $(ANALYZE_ARGS) $(RTL_FILES)

elaborate:
	ghdl -m $(ELABORATE_ARGS) $(TOPLEVEL)

simulate: analyze elaborate
	MODULE=$(MODULE) ghdl -r -v $(SIM_ARGS) $(TOPLEVEL) $(RUN_ARGS) $(VCD_ARGS)
	
