
all: process

process:
	arm-none-eabi-as -I asm -o main.o main.s
	arm-none-eabi-ld --no-undefined main.o -Map kernel.map -o output.elf -T kernel.ld
	arm-none-eabi-objcopy output.elf -O binary kernel.img

#arm-none-eabi-ld --no-undefined rust_kernel.o -Map kernel.map -o rust_kernel.elf -T kernel.ld
#rust_kernel: rust_kernel.rs
#	rustc --target arm-unknown-linux-gnueabihf --emit=obj rust_kernel.rs
#	arm-none-eabi-gcc -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles rust_kernel.o -o rust_kernel.elf
#	arm-none-eabi-objcopy rust_kernel.elf -O binary kernel.img

rust_loader.o: rust_loader.s
	arm-none-eabi-gcc -mcpu=arm1176jzf-s -fpic -ffreestanding -c rust_loader.s -o rust_loader.o

#rust_kernel.o: rust_kernel.rs
#	rustc --target ./arm-none-eabihf.json --emit=obj -Cpanic=abort -C lto rust_kernel.rs

rust_kernel.o: src/lib.rs
	~/.cargo/bin/xargo build

kernel.elf: rust_kernel.o rust_loader.o
	arm-none-eabi-gcc -T rust_linker_script.ld -o rust_kernel.elf -ffreestanding -nostdlib rust_loader.o target/arm-none-eabihf/debug/libraspi_xargo.rlib

kernel: kernel.elf
	arm-none-eabi-objcopy rust_kernel.elf -O binary kernel.img

.PHONY: clean
clean:
	rm -f *.o
	rm -f *.elf
	rm -f *.a
	rm -f kernel.img
	rm -f kernel.map
