# Makefile -- the core alone under Verilator: hello.c (avr-gcc) on tb.cpp's zero-wait program and data memories.
#   make        build hello.bin and the simulator, run it (prints the text, the cycles and the instructions)
#   make clean
V   := ../ucore_avr_m328p.v ../ucore_avr_m328p_1_1_1_1.v ../gen_ram_8x16_r2_w1_d.v
OBJ := obj
run: $(OBJ)/Vucore_avr_m328p hello.bin
	./$(OBJ)/Vucore_avr_m328p hello.bin
$(OBJ)/Vucore_avr_m328p: $(V) tb.cpp
	verilator --cc --exe --build -O2 -Wno-fatal -Wno-WIDTH --top-module ucore_avr_m328p -Mdir $(OBJ) $(V) tb.cpp > build.log 2>&1 \
	  || { tail -20 build.log; exit 1; }
hello.elf: hello.c
	avr-gcc -mmcu=atmega328p -Os -o $@ $<
hello.bin: hello.elf
	avr-objcopy -O binary $< $@
clean:
	rm -rf $(OBJ) build.log hello.elf hello.bin
.PHONY: run clean
