PROJECT = cputest

SHELL := /bin/bash

SRC = cpu_test.sv cpu.v
CPUSRC = cpu_test.sv cpu.v

QUARTUS_SH = quartus_sh --64bit
QUARTUS_PGM = quartus_pgm

all: project wave

.PHONY: project
project: $(PROJECT).tcl
	$(QUARTUS_SH) -t $(PROJECT).tcl

.PHONY: lint
lint:
	verilator --lint-only $(SRC)

.PHONY: wave
wave: cpusim.vcd
	gtkwave cpusim.vcd

cpusim.vcd: obj_dir/Vcpu_test
	obj_dir/Vcpu_test

obj_dir/Vcpu_test: $(CPUSRC) cpusim.cpp
	verilator -Wno-fatal -trace --cc $(CPUSRC) --exe cpusim.cpp --top-module cpu_test
	pushd obj_dir && make -j -f Vcpu_test.mk && popd

.PHONY: clean
clean:
	rm -rf db incremental_db *.qpf *.qsf *.sof obj_dir *.vcd *.sdc
