SHELL=/bin/bash
NAME := {{ name }}
BITSTREAM := {{ bitstream }}
PART := {{ part }}

all: $(BITSTREAM)

{% if yosys %}
$(NAME).edif: $(NAME).mk
	$(MAKE) -f $<

synth: $(NAME).edif
{% else %}
$(NAME).runs/synth_1/__synthesis_is_complete__: $(NAME)_synth.tcl $(NAME).xpr
	$(EDALIZE_LAUNCHER) {{ vivado_command }} -notrace -mode batch -source $^

synth: $(NAME).runs/synth_1/__synthesis_is_complete__
{% endif %}

{% if yosys %}
$(BITSTREAM): $(NAME)_run.tcl $(NAME).xpr synth
{% else %}
$(BITSTREAM): $(NAME)_run.tcl $(NAME).xpr
{% endif %}
	$(EDALIZE_LAUNCHER) {{ vivado_command }} -notrace -mode batch -source $< $(NAME).xpr

$(NAME).xpr: $(NAME).tcl
	$(EDALIZE_LAUNCHER) {{ vivado_command }} -notrace -mode batch -source $<

build-gui: $(NAME).xpr
	$(EDALIZE_LAUNCHER) {{ vivado_command }} $<

pgm: $(NAME)_pgm.tcl $(BITSTREAM)
	export HW_TARGET=$(HW_TARGET); \
	export JTAG_FREQ=$(JTAG_FREQ); \
	$(EDALIZE_LAUNCHER) {{ vivado_command }} -quiet -nolog -notrace -mode batch -source $< -tclargs $(PART) $(BITSTREAM)
