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

SMC		= /mnt/flash

# Change the line below to the name of your program
PROGRAM =    quake

# If you have any directories with include files, add them here with -I on
# the front of each
INCLUDES = -I../WinQuake
#INCLUDES = -I../WinQuake -I/usr/local/open2x/gcc-4.0.2-glibc-2.3.5/arm-open2x-linux/include/

# list all .c files here
CFILES	=				hacks_gp2x.c \
					cd_null.c \
						minimal.c \
						in_gp2x.c \
						vid_sdl.c \
						snd_sdl.c \
						sys_gp2x.c \
						../WinQuake/chase.c \
						../WinQuake/cl_demo.c \
						../WinQuake/cl_input.c \
						../WinQuake/cl_main.c \
						../WinQuake/cl_parse.c \
						../WinQuake/cl_tent.c \
						../WinQuake/cmd.c \
						../WinQuake/common.c \
						../WinQuake/console.c \
						../WinQuake/crc.c \
						../WinQuake/cvar.c \
						../WinQuake/d_edge.c \
						../WinQuake/d_fill.c \
						../WinQuake/d_init.c \
						../WinQuake/d_modech.c \
						../WinQuake/d_part.c \
						../WinQuake/d_polyse.c \
						../WinQuake/d_scan.c \
						../WinQuake/d_sky.c \
						../WinQuake/d_sprite.c \
						../WinQuake/d_surf.c \
						../WinQuake/d_vars.c \
						../WinQuake/d_zpoint.c \
						../WinQuake/draw.c \
						../WinQuake/FixedPointMath.c \
						../WinQuake/host.c \
						../WinQuake/host_cmd.c \
						../WinQuake/keys.c \
						../WinQuake/mathlib.c \
						../WinQuake/menu.c \
						../WinQuake/model.c \
						../WinQuake/net_dgrm.c \
						../WinQuake/net_loop.c \
						../WinQuake/net_main.c \
						../WinQuake/net_vcr.c \
						../WinQuake/net_udp.c \
						../WinQuake/net_bsd.c \
						../WinQuake/nonintel.c \
						../WinQuake/pr_cmds.c \
						../WinQuake/pr_edict.c \
						../WinQuake/pr_exec.c \
						../WinQuake/r_aclip.c \
						../WinQuake/r_alias.c \
						../WinQuake/r_bsp.c \
						../WinQuake/r_draw.c \
						../WinQuake/r_edge.c \
						../WinQuake/r_efrag.c \
						../WinQuake/r_light.c \
						../WinQuake/r_main.c \
						../WinQuake/r_misc.c \
						../WinQuake/r_part.c \
						../WinQuake/r_sky.c \
						../WinQuake/r_sprite.c \
						../WinQuake/r_surf.c \
						../WinQuake/r_vars.c \
						../WinQuake/sbar.c \
						../WinQuake/screen.c \
						../WinQuake/snd_dma.c \
						../WinQuake/snd_mix.c \
						../WinQuake/sv_main.c \
						../WinQuake/sv_move.c \
						../WinQuake/sv_phys.c \
						../WinQuake/sv_user.c \
						../WinQuake/snd_mem.c \
						../WinQuake/view.c \
						../WinQuake/wad.c \
						../WinQuake/world.c \
						../WinQuake/zone.c


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

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

BASEFILES = $(GPSDK_HOME)/basefiles

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

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

#CFLAGS     =	-c -march=armv4t -mtune=arm920t -marm -mthumb-interwork -msoft-float -O1 -ffast-math
CFLAGS     =	-Wall -pipe -c -O6 -msoft-float -mcpu=arm9 -mtune=arm920t -ffast-math -funroll-loops -falign-loops=2 -falign-jumps=2 -falign-functions=2 -fno-strict-aliasing $(shell /c/devkitGP2X/bin/sdl-config --cflags)

LDFLAGS = -s -lSDL_mixer -lvorbisidec -lmikmod -lm $(shell /c/devkitGP2X/bin/sdl-config --libs)

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

CC = /c/devkitGP2X/bin/arm-linux-gcc.exe

$(PROGRAM): $(OFILES)
	$(CC) -static $(OFILES) $(LDFLAGS) $(LIBDIRS) $(ALL_LIBS) -o $@

.PHONY: all clean

all:		$(PROGRAM)

%.o:	%.c
	$(CC) $(ALL_INCLUDES) $(CFLAGS) -c $< -o $@

%.o:	%.S
	$(CC) $(ALL_INCLUDES) $(CFLAGS) -c $< -o $@

clean:
	-rm -f $(OFILES) $(MAPFILE) $(PROGRAM)

install: all
	/c/devkitGP2X/bin/arm-linux-strip.exe -o $(PROGRAM).gpe $(PROGRAM)
#	mount $(SMC)
	cp $(PROGRAM).gpe \\gp2x\gp2x\mnt\sd\quake\
#	umount $(SMC)