#
# Makefile for to make stuffs
# WiiP! AT90S2313 Version
# OpenWii - YOLD 3173
#

# cross compiler
# CHANGE THIS TO YOUR COMPILER'S BINARY DIRECTORY AND CROSS COMPILER PREFIX
CROSS_COMPILE_PATH = 
CROSS_COMPILE_PREFIX = avr-

#what chip are we using
CHIP = at90s2313

# what files to use for each section.
CFILES = ../common/serial.o ../common/main.o archdep.o
ASMFILES =

#what to name the intermediate .elf and output .bin file
BINNAME = openwii

#linker script and symbols filenames
LDSCRIPT = openwii.lds

#any extra options to send to c compiler
AUXFLAGS = 

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

# compiler flags for C compiler and assembler..
CFLAGS = $(AUXFLAGS) -O2 -fpic -mmcu=$(CHIP) -DWIIP -Wall
AFLAGS = -mmcu=at90s2313
LDFLAGS = #-T$(LDSCRIPT)

# 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
.o.elf:
	$(LD) $(LDFLAGS) $< -o *.elf
.elf.bin:
	$(LD) $(LDFLAGS) $< -o *.bin --oformat binary

#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 : asm c link

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

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

#link it all together
link: 
	$(LD) $(LDFLAGS) /usr/avr/lib/crts2313.o $(ASMFILES) $(CFILES) -o $(BINNAME).elf
	$(LD) $(LDFLAGS) --oformat ihex $(BINNAME).elf -o $(BINNAME).hex
	$(LD) $(LDFLAGS) --oformat binary $(BINNAME).elf -o $(BINNAME).bin

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