###############################################################################
# Makefile for a GP32 application.
###############################################################################

# The folder where you extracted gp32libs.tar.bz2
GPSDK_HOME =	/home/slubman/gp32gcc/sdk

# Don't change this unless you changed the compiler location when you
# installed it.
GCC_HOME =	/home/slubman/gp32gcc
#GCC_HOME =   /mnt/stock/gp32/pc/linux/gp32_gcc

# Author name for the program
AUTHOR =	"Slubman DevSoft"

# Libraries to be included... this is all of the gpsdk libraries
#LIBS = -lgpos -lgpsound -lgpmem -lgpgraphic -lgpgraphic16 -lgpfont -lgpfont16 -lgpstdlib -lgpstdio
LIBS = -lgpos -lgpsound -lgpmem -lgpgraphic -lgpfont -lgpstdlib -lgpstdio

# If you have any directories with include files, add them here with -I on
# the front of each
# e.g. INCLUDES = -I/home/rfbrown/gp32/prog/include -I/usr/src/include
INCLUDES = -I.. -I../common -I../libfxe -I../libfileop -I../libplg

# list all .c files here
CFILES	=	filelist.c graphics.c gpsys.c intro.c langue.c pictures.c sound.c speed.c window.c type.c version.c\
			../common/version.c\
			../main/pictures.c\
			../options/options.c
#CFILES	=	background.c filelist.c graphics.c gpsys.c intro.c langue.c pictures.c sound.c window.c type.c version.c
#CFILES	=	menu.c

# list all assembler (.s) files here
SFILES	=

##############################################################################
# You shouldn't need to change anything below here, really
##############################################################################

BASEFILES = $(GPSDK_HOME)/basefiles

ALL_INCLUDES = -I$(GPSDK_HOME)/include $(INCLUDES)
ALL_LIBS = $(LIBS) -lm -lc -lgcc

LIBDIRS = -L $(GCC_HOME)/arm-elf/lib \
			 -L $(GCC_HOME)/lib/gcc/arm-elf/3.4.2\
			 -L $(GPSDK_HOME)/lib\
			 -L ../libfxe\
			 -L ../libfileop\
			 -L ../libplg

# LIBDIRS = -L $(GCC_HOME)/arm-elf/lib \
# 			 -L $(GCC_HOME)/lib/gcc-lib/arm-elf/3.3.3\
# 			 -L $(GPSDK_HOME)/lib\
# 			 -L ../libfxe\
# 			 -L ../libfileop\
# 			 -L ../libplg
#
LDSCRIPT = $(BASEFILES)/lnkscript

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

CFLAGS  =		-c -march=armv4t -marm -mthumb-interwork -msoft-float \
					-ffast-math -fshort-enums -nostdlib -fno-common -ffreestanding \
					-fno-builtin -fno-exceptions -mstructure-size-boundary=8 -O2 \
					-fomit-frame-pointer -Wall
#CFLAGS	=		-DTAG_CFLAGS_FOR_TARGET -s -march=armv4t -mtune=arm920t -mno-thumb-interwork -marm -finline-functions -ffast-math -fshort-enums -mstructure-size-boundary=8 -O2

LDFLAGS	=	--script $(LDSCRIPT) -nostartfiles -Map $(PROGRAM).map

CC = arm-elf-gcc
AS = arm-elf-as
LD = arm-elf-ld
OBJCOPY = arm-elf-objcopy

.PHONY: all clean

all:		$(OFILES)

crt0.o:	$(BASEFILES)/crt0.s
	$(CC) $(ALL_INCLUDES) $(CFLAGS) -c $< -o $@

gpstart.o:	../common/gpstart.c
	$(CC) $(ALL_INCLUDES) $(CFLAGS) -c $< -o $@

%.o:	%.c ../common/langue.h
	$(CC) $(ALL_INCLUDES) $(CFLAGS) -c $< -o $@

clean:
	-rm -f $(OFILES) $(MAPFILE) $(TARGET_ELF) $(TARGET_BIN)

clean-all:
	-rm -f $(OFILES) $(MAPFILE) $(TARGET_ELF) $(TARGET_BIN) $(TARGET_FXE)
