#
# Makefile for to make stuffs
# created Prickle-Prickle, the 54th day of Chaos in the YOLD 3173
#

# cross compiler
# CHANGE THIS TO YOUR COMPILER'S BINARY DIRECTORY AND CROSS COMPILER PREFIX
MN10200_PATH = ../../mn10200/ruputer
MN10200_COMPILE_PATH = $(MN10200_PATH)/bin/
MN10200_COMPILE_PREFIX = mn10200-elf-

# what files to use for each section.
CFILES = backendJackd.o loop.o
ASMFILES =
REQHDRS = mn10200-wii.h

#Set the build dir to where im gonna use this
BUILDDIR =../$(chip)/

OUTNAME = mn10200
BINNAME = $(BUILDDIR)$(OUTNAME)-$(drive).bin
ELFNAME = $(BUILDDIR)$(OUTNAME)-$(drive).elf

#Only change these addresses if you NEED to..
TEXT = 0x408000
START = 0x408000

#linker script and symbols filenames
LDSCRIPT = wiidvdfw.lds

SYMFILE = ../symtbls/$(drive).jsym

#any extra options to send to c compiler
AUXFLAGS = -save-temps

#If your compilers are called something different change these...
LD = $(MN10200_COMPILE_PATH)$(MN10200_COMPILE_PREFIX)ld
CC = $(MN10200_COMPILE_PATH)$(MN10200_COMPILE_PREFIX)gcc
AS = $(MN10200_COMPILE_PATH)$(MN10200_COMPILE_PREFIX)as

# compiler flags for C compiler and assembler..
CFLAGS = $(AUXFLAGS) -fpic -Wall -fno-builtin -O2
AFLAGS =
LDFLAGS = -Ttext $(TEXT) -e $(START) -T$(LDSCRIPT) -lc -L$(MN10200_PATH)/lib/gcc-lib/mn10200-elf/2.95.3-2/

# This defines how to handle the various file types in/out
#.S.s:
#	$(AS) $(AFLAGS) $< -o $*.s
.S.o:
	$(AS) $(AFLAGS) $< -o $*.o
.c.o:
	$(CC) $(CFLAGS) -c $< -o $*.o
%.elf:
	$(LD) $(LDFLAGS) --just-symbols $(SYMFILE) $(ASMFILES) $(CFILES) -o $@
%.bin:
	$(LD) $(LDFLAGS) --just-symbols $(SYMFILE) $(ELFNAME) --oformat binary -o $@

#These sections below define the different make types
# for instance make sys will only make the system files, make ram only makes the
# ram files, make clean will erase all compiled files

# make everythng
all : link

#link it all together
link: $(BINNAME)

#.bin needs openwii.elf as a prerequisite
$(BINNAME): $(ELFNAME)

#.elf needs these prerequisites
$(ELFNAME): $(CFILES) $(ASMFILES) $(SYMFILE)

#CFILES requires these prerequisites
$(CFILES): $(REQHDRS)

#stuff thats coded in asm
asm: $(ASMFILES)

#Stuff thats coded in c
c: $(CFILES)

# ofc a make clean, very handy
clean:
	rm -f *.o *.elf *.bin
