#Auto generated by Edalize
SHELL = bash

TOP	:= {{ top }}
VERILOG := {{ sources }}
PARTNAME:= {{ partname }}
DEVICE  := {{ part }}_{{ device_suffix }}
BITSTREAM_DEVICE := {{ bitstream_device }}
SDC	:= {{ sdc }}
PCF	:= {{ pcf }}
XDC	:= {{ xdc }}
TOOLCHAIN_PREFIX := {{ toolchain_prefix }}
{% if vendor == "xilinx" -%}
PARTNAME_OPT = -p "{{ partname }}"
{% else %}
PARTNAME_OPT = -P "{{ partname }}"
{%- endif %}

{% if vpr_options -%}
VPR_OPTIONS_OPTS = --additional_vpr_options "{{ vpr_options }}"
{%- endif %}

{% if pcf -%}
PCF_OPTS = -p ${PCF}
{%- endif %}

{% if xdc -%}
XDC_OPTS = -x ${XDC}
{%- endif %}

{% if sdc -%}
SDC_OPTS = -s ${SDC}
{%- endif %}

all: ${TOP}.bit

${TOP}.eblif:
	$(EDALIZE_LAUNCHER) ${TOOLCHAIN_PREFIX}synth -t ${TOP} -v ${VERILOG} -d ${BITSTREAM_DEVICE} ${PARTNAME_OPT} ${XDC_OPTS}

${TOP}.net: ${TOP}.eblif
	$(EDALIZE_LAUNCHER) ${TOOLCHAIN_PREFIX}pack -e ${TOP}.eblif -d ${DEVICE} ${SDC_OPTS} ${VPR_OPTIONS_OPTS}

${TOP}.place: ${TOP}.net
	$(EDALIZE_LAUNCHER) ${TOOLCHAIN_PREFIX}place -e ${TOP}.eblif -d ${DEVICE} -n ${TOP}.net -P ${PARTNAME} ${SDC_OPTS} ${PCF_OPTS} ${VPR_OPTIONS_OPTS}

${TOP}.route: ${TOP}.place
	$(EDALIZE_LAUNCHER) ${TOOLCHAIN_PREFIX}route -e ${TOP}.eblif -d ${DEVICE} ${SDC_OPTS} ${VPR_OPTIONS_OPTS}

${TOP}.fasm: ${TOP}.route
	$(EDALIZE_LAUNCHER) ${TOOLCHAIN_PREFIX}write_fasm -e ${TOP}.eblif -d ${DEVICE} ${SDC_OPTS} ${VPR_OPTIONS_OPTS}

${TOP}.bit: ${TOP}.fasm
	$(EDALIZE_LAUNCHER) ${TOOLCHAIN_PREFIX}write_bitstream -d ${BITSTREAM_DEVICE} -f ${TOP}.fasm ${PARTNAME_OPT} -b ${TOP}.bit

clean:
	$(EDALIZE_LAUNCHER) rm -rf *.log *.rpt *.place *.bit *.eblif *.fasm *.json *.ioplace *.net *.route

