#!/usr/bin/make -f
#
# Makefile for running Bluepsec tools
#

BSC=bsc
BSCFLAGS= -aggressive-conditions
SUFFIXES=

TOPMOD = mkTb
TOPMODV = mkTb.v
TOPMODB = mkTb.ba
TOPFILE = Tb.bsv
SIMULATOR = iverilog

SRCS = $(TOPFILE) 

# Create execuatable for Bluesim simulation
CMD1B =	$(BSC) $(BSCFLAGS) -sim -g $(TOPMOD) -u $(TOPFILE)
CMD2B =	$(BSC) $(BSCFLAGS) -sim -o $(TOPMOD) -e $(TOPMOD)  *.ba

# Create Verilog and executable for verilog simulator
CMD1V =	$(BSC) $(BSCFLAGS) -u -verilog -keep-fires -g $(TOPMOD) $(TOPFILE)
CMD2V =	$(BSC) -vsim $(SIMULATOR) -o $(TOPMOD) -e $(TOPMOD) $(TOPMOD).v

.PHONY: help
help:
	@echo "Possible targets:"
	@echo "  verilog       --  create Verilog RTL and simulator executable."
	@echo "  bluesim       --  build Bluesim executable"
	@echo "  runv          --  build and simulate using ($(SIMULATOR)) simulator"
	@echo "  runb          --  build and simulate using Bluesim simulator"
	@echo "  clean         --  remove binary, executable and temporary files"
	@echo "  help          --  display this message"

# ----------------------------------------------------------------

.PHONY: verilog
verilog: $(TOPMODV)

.PHONY: bluesim
bluesim: $(TOPMODB)

# compile and link for verilog
$(TOPMODV): $(SRCS) Makefile
	$(CMD1V)
	$(CMD2V)

# compile and link for Bluesim
$(TOPMODB): $(SRCS) Makefile
	$(CMD1B)
	$(CMD2B)

# run (simulate) the system
runv:	$(TOPMODV)
	./$(TOPMOD) +bsccycle+

# run (simulate) the system
runb:	$(TOPMODB)
	./$(TOPMOD) +bsccycle+ -cc -m 1500

.PHONY: clean
clean:
	rm -f  *.bi *.bo  *.c *.h *.o *.cxx  mk*  *~ $(TOPMOD) v95/* >/dev/null
