# ScummVM - Scumm Interpreter
# Copyright (C) 2001  Ludvig Strigeus
# Copyright (C) 2001/2004 The ScummVM project
# Copyright (C) 2002 ph0x - GP32 port
# Copyright (C) 2003-4 DJWillis - GP32 port
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Module Details	-	ScummVM for the GP32
#						Build.Rules for GP32 Backend.
#
# Port Maintainer	-	DJWillis <gp32@distant-earth.co.uk>

# GPSDK (SDK, Includes and Startup Files) base dir
GPSDK			=	/usr/compat/gp32/share/sdk

# Outputs
EXEEXT			=	.elf
MAPFILE			=	scummvm.map
BIN			=	scummvm.gxb
FXE			=	scummvm.fxe

# Stripped Build? (Smaller ELF, Minimal debug symbol information).
# You MUST comment this out with a # if you wish to debug your code.
# STRIP_DEBUG		=	-Wl,--strip-debug

# Plugins hack
srcdir			=	./

# GP32 Direct Execute Tool (i.e. pclink -e on Windows, gplink run on Linux)
EXECUTE_TOOL	=	pclink -e

# GCC Tool-chain
CC			=	arm-elf-gcc
CXX			=	arm-elf-g++
LD			=	arm-elf-g++
AS			=	arm-elf-as
OBJCOPY			=	arm-elf-objcopy
FXETOOL			=	b2fxec

CFLAGS  		=	-marm \
				-march=armv4t \
	       			-mapcs \
	       			-finline-functions \
	       			-fshort-enums \
	       			-ffast-math \
	       			-fshort-double \
	       			-mstructure-size-boundary=32 \
	       			-mno-thumb-interwork \
				-I$(GPSDK)/include \
				-g \
				#-Wno-multichar \
	       			#-O3 \
	       			#-fomit-frame-pointer			
					
				# Remove the below from the above flags for Debug.
	       			#-O3 \
	       			#-fomit-frame-pointer

CPPFLAGS		=	$(CFLAGS)

DEFINES 		= 	-D__GP32__
DEFINES			+=	-DNONSTANDARD_PORT

# Support Vorbis Tremor Patches.
#DEFINES		+=	-DUSE_TREMOR

# Support LIBMAD Patches.
#DEFINES		+=	-DGP32_MADMP3

# Support for 8:3 save files names (The GP32 uses FAT12/16 (no vFAT) for the file system).
DEFINES			+=	-DSHORT_SAVENAMES

# Support for the unsigned sound mixer.
DEFINES			+=	-DOUTPUT_UNSIGNED_AUDIO

# Support for the GP32 (fmOPL derived) MIDI engine.
#	-	NOT fully implemented yet.
DEFINES			+=	-DUSE_GP32_FMOPL

LDSPECS			=	-specs=gp32_gpsdk.specs

LDFLAGS 		= 	$(STRIP_DEBUG) \
					-Wl,-Map,$(MAPFILE) \
					$(LDSPECS) -Wl,--no-warn-mismatch
				
LIBS			+=	-L$(GPSDK)/lib \
					-lgpmem -lgpos -lgpstdio -lgpstdlib -lgpsound -lgpgraphic  -lgpgraphic16 -lgpfont -lgpfont16 \
					-lm -lc -lgcc

INCLUDES 		+=	-Ibackends/gp32 -I$(GPSDK)/include

MODULES			+=	backends/gp32

#GP32 Debug - Remove from Release builds
#	This builds in the GP32 GDB USB Stub. Don't use it unless you know what your doing.
#	You also need to remove ANY optemisation from the compiler flags.
DEFINES			+=	-DGP32_GDB
OBJS			+=	backends/gp32/debug-gdbstub-usb.o

#GamePark SDK startup.
OBJS			+=	backends/gp32/startup.o

#Main ScummVM for the GP32 Backend
OBJS			+=	backends/gp32/gp32.o \
				backends/gp32/gp-fs.o \
				backends/gp32/cpuspeed.o \
					
				#backends/gp32/dmaaudio_asm.o \
				#backends/gp32/dmaaudio.o \

#install: all
					#$(EXECUTE_TOOL) $(BIN)

$(FXE): $(BIN)
					$(FXETOOL) -f -a "DJWillis/ScummVM Team" -t "ScummVM for the GP32" -b scummvm.bmp $< $@
	
$(BIN): scummvm$(EXEEXT)
					$(OBJCOPY) -O binary $< $@
