TARGET_SIM   ?= riscv_sim_RV32
TARGET_FLAGS ?= $(RISCV_TARGET_FLAGS)

ifeq ($(shell command -v $(TARGET_SIM) 2> /dev/null),)
    $(error Target simulator executable '$(TARGET_SIM)` not found)
endif

RUN_TARGET=\
    $(TARGET_SIM) $(TARGET_FLAGS) \
        --test-signature=$(*).signature.output \
        $(<) 1>&2 2> $@

RISCV_PREFIX   ?= riscv32-unknown-elf-
RISCV_GCC      ?= $(RISCV_PREFIX)gcc
RISCV_OBJDUMP  ?= $(RISCV_PREFIX)objdump
RISCV_GCC_OPTS ?= -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles $(RVTEST_DEFINES)

COMPILE_TARGET=\
    $$(RISCV_GCC) $(1) $$(RISCV_GCC_OPTS) \
        -I$(ROOTDIR)/riscv-test-env/ \
        -I$(ROOTDIR)/riscv-test-env/p/ \
        -I$(TARGETDIR)/$(RISCV_TARGET)/ \
        -T$(ROOTDIR)/riscv-test-env/p/link.ld $$(<) \
        -o $$(@); \
    $$(RISCV_OBJDUMP) -D $$(@) > $$(@).objdump
