# -------------------------------------------------
# Global options
# -------------------------------------------------
LANG_STD := 93c
IEEE_STD := standard
WORK_PATH := work
SOURCE_PATH := src
LIB_PATH := ../lib

# -------------------------------------------------
# Target options
# -------------------------------------------------
TARGET := tb_mac_top

SOURCES :=	src/mac_top.vhd \
			src/tb_mac_top.vhd 
			

# -------------------------------------------------
GHDL_SRC := /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.1/vhdl/src
GHDL_OPT := --workdir=$(WORK_PATH) --std=$(LANG_STD) --ieee=$(IEEE_STD)

# -------------------------------------------------
	
all: elaborate

.PHONY : skel
skel : 
	@mkdir -p ./$(WORK_PATH)

.PHONY: xref
xref: 
	ghdl --xref-html $(LIB_PATH)/*.vhd $(SOURCES)

.PHONY: syntax
syntax: skel xref
	ghdl -s $(GHDL_OPT) $(SOURCES)

.PHONY: import
import: skel xref
	ghdl -i $(GHDL_OPT) $(LIB_PATH)/*.vhd

.PHONY: analyze
analyze: skel import
	ghdl -a $(GHDL_OPT) $(LIB_PATH)/*.vhd $(SOURCES)

.PHONY: anaborate
anaborate: skel import
	ghdl -c $(GHDL_OPT) $(LIB_PATH)/*.vhd $(SOURCES) -e $(TARGET)

.PHONY: makeunit
makeunit: skel import
	ghdl -m $(GHDL_OPT) $(TARGET)

.PHONY: elaborate
elaborate: skel analyze
	ghdl -e $(GHDL_OPT) $(TARGET)

.PHONY: run
run: skel elaborate
	ghdl -r $(GHDL_OPT) $(TARGET) --vcd=$(TARGET).vcd --assert-level=error 

.PHONY: show
show:  $(TARGET).vcd 
	@gtkwave $(TARGET).vcd $(TARGET).sav 2>/dev/null

# -------------------------------------------------
.PHONY: clean
clean:
	rm -rf $(TARGET)
	rm -rf ./html
	cd $(WORK_PATH); rm -rf *.o *.cf
	
# -------------------------------------------------
