#--------------------------------------------------------------------------
# InfoNES-GP32
# Makefile for GP32 port of InfoNES
#--------------------------------------------------------------------------

GPDIR =	c:/gp32

CC = gcc
AS = as
LD = ld

.SFILES	=	crt0.s \
		enablecache.s

.CFILES	=	gpstart.c \
		InfoNES_System_GP32.c \
		fileselect.c \
		./../InfoNES.c \
		./../InfoNES_Mapper.c \
		./../InfoNES_pAPU.c \
		./../K6502.c



.OFILES	=	$(.SFILES:.s=.o) $(.CFILES:.c=.o)

CFLAGS	=	-g -I$(GPDIR)/include -O3 -mtune=arm920 -funroll-loops \
			-Wuninitialized -Wno-import -Wchar-subscripts -Wformat -Wimplicit-int \
			-Wimplicit-function-declaration \
			-Wmultichar -Wreturn-type -Wswitch -Wunused -Wuninitialized -Wsign-compare

LDFLAGS	=	-T$(LDSCRIPT) -L$(GPDIR)/libs \
			-lgpmem -lgpos -lgpstdio -lgpstdlib -lgpsound -lm -lc -lgcc -lgpgraphic -lgpfont

DEPENDFILE	=	Makedepend
MAPFILE		=	infones.map
TARGET_ELF	=	infones.elf
TARGET_BIN	=	infones.gxb
TARGET_FXE	=	infones.fxe
LDSCRIPT	=	lnkscript


$(TARGET_FXE): $(TARGET_BIN)
	b2fxe -a "Anders Granlund" -t "InfoNES-GP32" $< $@

$(TARGET_BIN): $(TARGET_ELF)
	objcopy -O binary $< $@

$(TARGET_ELF): $(.OFILES) Makefile $(DEPENDFILE)
	$(LD) -g -o $@ $(.OFILES) $(LDFLAGS)

.PHONY: all clean depend

all:    clean depend $(TARGET_BIN)

tags:	$(DEPENDFILE)
	ctags -e *.c *.s *.h *.S

clean:
	-rm $(.OFILES) $(DEPENDFILE) $(MAPFILE) $(TARGET_ELF) $(TARGET_BIN) TAGS

depend:
	$(CC) $(CFLAGS) -M $(.CFILES) > $(DEPENDFILE)

$(DEPENDFILE):
	$(CC) $(CFLAGS) -M $(.CFILES) > $(DEPENDFILE)

include $(DEPENDFILE)
