DESIGN = tms-pupe
HDL_SRC = ../pupe-wrapper/*.vhd ../tms-processing/*.vhd ../ddr2_memory_interface/*.vhd ../ddr2_memory_interface/MigCore_Small/*.vhd
DEVICE = xc4vfx100
SPEED  = 10
PKG    = ff1517

BUILDDIR = ../builds/tms_pupe

PARTTYPE=$(DEVICE)-$(SPEED)-$(PKG)

CONSTRAINTS=tms_top_pupe1.ucf
BUILDNAME=$(BUILDDIR)/$(DESIGN)
NETLIST = $(BUILDDIR)/tms-pupe.ngc


all: $(BUILDNAME).twr $(BUILDNAME).bit


$(NETLIST): $(HDL_SRC)
#	@if not exist $(BUILDDIR) mkdir $(BUILDDIR)
	xst -ifn GNUtms_pupe_xst.scr


$(BUILDNAME).ngd: $(NETLIST) $(CONSTRAINTS)
#	@if not exist $(BUILDDIR) mkdir $(BUILDDIR)
	ngdbuild -quiet -aul -nt on -uc $(CONSTRAINTS) -p $(PARTTYPE) $(NETLIST) -dd $(BUILDDIR) $(BUILDNAME).ngd
#	@if exist $(DESIGN)_ngdbuild.nav del $(DESIGN)_ngdbuild.nav
	
$(BUILDNAME)_map.ncd: $(BUILDNAME).ngd
	map -ol high  -xe n -timing -cm speed -pr b -o $(BUILDNAME)_map.ncd $(BUILDNAME).ngd $(BUILDNAME).pcf

$(BUILDNAME).ncd: $(BUILDNAME)_map.ncd
	par -ol high -xe n -p -w $(BUILDNAME)_map.ncd $(BUILDNAME).ncd $(BUILDNAME).pcf

$(BUILDNAME).twr: $(BUILDNAME).ncd
	trce -e 3 -o $(BUILDNAME).twr $(BUILDNAME).ncd $(BUILDNAME).pcf

$(BUILDNAME).bit: $(BUILDNAME).ncd
	bitgen -w -g drivedone:yes -g UnusedPin:Pullnone $(BUILDNAME).ncd $(BUILDNAME).bit
	rm -fr $(BUILDNAME).zip
	zip $(BUILDNAME).zip $(BUILDNAME).bit

