#	PPC-IOP code-preparaion makefile.
#	

PREFIX=powerpc-none-eabi-
BINARY=p2mesac
FILES=p2mesac
OBJS=$(addsuffix .o, $(FILES))

#This passes the contents of PPC_PATCH_ADDR_VAL as value to PPC_PATCH_ADDR in the linker script.
LINKER_ARG=-Xlinker --defsym=PPC_PATCH_ADDR=$(PPC_PATCH_ADDR_VAL)

PPC_INCS=-I../include

all: $(BINARY).bin

clean:
	rm -f $(BINARY).s
	rm -f $(BINARY).bin
	rm -f $(BINARY).elf
	rm -f *.o

debug:
	$(PREFIX)objdump -d $(BINARY).elf

$(BINARY).bin: $(BINARY).elf
	$(PREFIX)objcopy -O binary $< $@

$(BINARY).elf: $(OBJS)
	$(PREFIX)gcc $(LINKER_ARG) -T linker.ld -o $@ -mcpu=405 -ffreestanding -O2 -nostdlib $^

%.o: %.c
	$(PREFIX)gcc $(PPC_INCS) -c $< -o $@ -mcpu=405 -ffreestanding -O2 -Wall

