.PHONY: clean

all:	netlist

PRJ := mips_sys
PREQ := ./project/$(PRJ).prj ./project/$(PRJ).xst ./project/$(PRJ).lso
DEVICE := "xc4vsx35-ff668-10"
DIRS := ./xst/tmp

netlist: $(PRJ).ngc
translate: $(PRJ).ngd
map: $(PRJ)_map.ncd
par: $(PRJ).ncd
bitfile: $(PRJ).bit

# Netlist
$(PRJ).ngc: $(DIRS) $(PREQ)
	xst -intstyle xflow -ifn ./project/$(PRJ).xst

# Translate
$(PRJ).ngd: $(PRJ).ngc ./project/$(PRJ).ucf
	ngdbuild -p $(DEVICE) -sd "../../../../lib/CPUs/MIPS/syn/ise101" -dd _ngo -nt timestamp -uc ./project/$(PRJ).ucf $(PRJ).ngc $(PRJ).ngd

# Map
$(PRJ)_map.ncd: $(PRJ).ngd
	map -intstyle xflow -p $(DEVICE) -timing -logic_opt on -ol high -xe n -t 1 -register_duplication -global_opt on	-retiming on -equivalent_register_removal on -cm area -pr b -k 4 -power off -o $(PRJ)_map.ncd $(PRJ).ngd $(PRJ).pcf

# PAR
$(PRJ).ncd: $(PRJ)_map.ncd
	par -w -intstyle xflow -ol high -xe n -t 1 $(PRJ)_map.ncd $(PRJ).ncd $(PRJ).pcf

# Bitgen
$(PRJ).bit: $(PRJ).ncd $(PRJ).ut
	bitgen -intstyle xflow -f $(PRJ).ut $(PRJ).ncd

$(DIRS):
	mkdir -p $(DIRS)

clean:
	rm -rf ./xst
	rm -rf ./xlnx_auto_0_xdb
	rm -f xlnx_auto_0.ise
	rm -f $(PRJ)*.*
	


