all: elevator.hex

elevator.o: elevator.c
	clang -target riscv32-none-elf -I../rvcontroller-libraries -march=rv32imacb_zicntr_zicond_zicsr_zifencei_zihintpause_zilsd_zclsd_zabha_zacas_zbkb_zbkx_zcb_zcmp_zcmt -ffreestanding -O3 -c -o elevator.o elevator.c

elevator.elf: ../rvcontroller-libraries/rvcontroller-init.o ../rvcontroller-libraries/rvcontroller-ecalls.o elevator.o
	clang -target riscv32-none-elf -T rvcontroller.ld -nostdlib -nostartfiles -Xlinker --no-warn-rwx-segments -o elevator.elf ../rvcontroller-libraries/rvcontroller-init.o elevator.o ../rvcontroller-libraries/rvcontroller-ecalls.o

dump: elevator.elf
	riscv32-none-elf-objdump -d elevator.elf

elevator.hex: elevator.elf
	riscv32-none-elf-objcopy -O ihex elevator.elf elevator.hex

load: elevator.hex
	bash -c "wl-copy < elevator.hex"

clean:
	rm -f elevator.bin elevator.elf elevator.o init.o

