CC=riscv64-unknown-elf-gcc
AS=riscv64-unknown-elf-as
ASFLAGS=-g -mabi=ilp32e -march=rv32ec
CFLAGS=$(ASFLAGS)
LD=riscv64-unknown-elf-ld
export JQ?=jaq
export QEMU?=qemu-riscv32

all: calc.elf

check: tests
	@tests/unittest

hello.elf: hello.o
	$(LD) -m elf32lriscv $^ -o $@

calc.elf: mem.o hex.o debug.o math.o calc.o
	$(LD) -m elf32lriscv -T link.ld $^ -o $@

tests: tests/btohex.elf tests/tohex.elf tests/math_add64.elf

tests/math_add64.elf: hex.o math.o tests/math_add64.o
	$(LD) -m elf32lriscv -T link.ld $^ -o $@

tests/btohex.elf: mem.o hex.o debug.o tests/btohex.o
	$(LD) -m elf32lriscv -T link.ld $^ -o $@

tests/tohex.elf: hex.o tests/tohex.o
	$(LD) -m elf32lriscv -T link.ld $^ -o $@

%.o : %.s
	$(AS) $(ASFLAGS) $< -o $@

.PHONY: check tests