### compilers and options
TOPDIR  := $(shell /bin/pwd)
CC      = gcc
INCLUDE = -I./include/ -I../xdk/include -I../Hermes
# XXX A lesson in linking with ld
# XXX if you have a library that depends on another library you must put the most independent library last
# XXX therefore if Hermes depends on xboxlibc then -lxboxlibc should come AFTER -lHermes
LIBS    = -L../xdk/lib/ -L../Hermes/ -lxboxusb -lxjpeg -lxvgalib -lHermes -lxboxlibc
CFLAGS  = -O2 -mcpu=pentium -W -Wall -Werror -nostdinc -nostdlib $(INCLUDE) -fno-leading-underscore 
LD      = ld
LDFLAGS =  -s -S -T ${TOPDIR}/../common/ldscript.ld $(LIBS)
OBJCOPY = objcopy
IMAGEBLD = ${TOPDIR}/../common/imagebld

### objects
OBJECTS = $(TOPDIR)/header.o
OBJECTS += $(TOPDIR)/src/boot.o
OBJECTS += $(TOPDIR)/src/biosloader.o
OBJECTS += $(TOPDIR)/src/config.o
OBJECTS += $(TOPDIR)/src/ntfile.o
OBJECTS += $(TOPDIR)/src/splash.o
OBJECTS += $(TOPDIR)/src/debug.o
OBJECTS += $(TOPDIR)/src/mmxmemcpy.o
OBJECTS += $(TOPDIR)/src/VideoHelpers.o
OBJECTS += $(TOPDIR)/src/bitmapfont.o
OBJECTS += $(TOPDIR)/src/Dash.o


#wtf?  Doesnt link properly without this here :-/
#OBJECTS += $(TOPDIR)/../xboxlibc/stdlib/_calloc.o


### rules:
default: clean default.xbe

default.xbe: image ${OBJECTS}
	${LD} -o default.xbe ${OBJECTS} ${LDFLAGS}
	${OBJCOPY} --output-format=binary default.xbe
	${IMAGEBLD}/image default.xbe

image:
	${MAKE} -C ${IMAGEBLD}

%.o: %.c
	${CC} ${CFLAGS} -o $@ -c $<

%.o: %.S
	${CC} -DASSEMBLER ${CFLAGS} -o $@ -c $<


.PHONY : clean image

clean :
	-rm -f image obj/* default.elf default.xbe
	-rm -rf *~ core *.core $(OBJECTS)
	${MAKE} -C ${IMAGEBLD} clean
