TARGET=snesgp2x

SOUNDOBJ=obj/spc700.o obj/soundux.o obj/apu.o
SOUNDDEFINES=-DSPC700_C
CPUOBJ=obj/cpuops.o obj/cpuexec.o
CPUOBJ+=obj/arm/os9x_65c816.o obj/arm/os9x_asm_cpu.o obj/arm/spc_decode.o
#obj/arm/os9x_func.o 

OBJECTS=$(CPUOBJ) $(FXOBJ) $(C4OBJ) \
	obj/cpu.o obj/tile.o obj/gfx.o obj/clip.o \
	obj/memmap.o obj/ppu.o obj/dma.o \
	$(SOUNDOBJ) obj/dsp1.o \
	obj/fxemu.o obj/fxinst.o \
	obj/sdd1.o \
	obj/srtc.o \
	obj/c4emu.o obj/c4.o \
	obj/cheats.o obj/cheats2.o \
	obj/snapshot.o obj/snaporig.o \
	obj/snes9x.o obj/data.o obj/globals.o \
	obj/sa1.o obj/sa1cpu.o \
	obj/spc7110.o \
	obj/obc1.o \
	obj/movie.o obj/screenshot.o \
	obj/seta.o obj/seta010.o obj/seta011.o obj/seta018.o \
	obj/gp2x/sdl.o obj/gp2x/main.o obj/gp2x/filer.o

# if unzip need...
OBJECTS += obj/loadzip.o obj/unzip/unzip.o obj/unzip/explode.o obj/unzip/unreduce.o obj/unzip/unshrink.o
UNZIPDEFINES=-DUNZIP_SUPPORT

FXDEFINES=-DEXECUTE_SUPERFX_PER_LINE
FXDEPENDS=c_fx

CCC = arm-gp2x-linux-g++
CC = arm-gp2x-linux-gcc
LD = arm-gp2x-linux-g++
MKDIR= @mkdir -p

INCLUDES=

OPTIMISE= -Os -fomit-frame-pointer -ffast-math -fstrict-aliasing
CCFLAGS = -shared $(OPTIMISE) `sdl-config --cflags` \
-I./src \
-I./src/arm \
-I./src/unzip \
-D__GP2X__ \
-D__linux \
-DZLIB \
-DVAR_CYCLES \
-DCPU_SHUTDOWN \
-DSPC700_SHUTDOWN \
$(FXDEFINES) \
$(C4DEFINES) \
$(CPUDEFINES) \
$(SOUNDDEFINES) \
$(NETPLAYDEFINES) \
$(UNZIPDEFINES) \
$(GUIDEFINES) \
$(KREEDDEFINES)

# -DJOYSTICK_SUPPORT \
# -DNO_INLINE_SET_GET

#-DDEBUGGER
#-D_ZAURUS \

CFLAGS=$(CCFLAGS)

all: mkdir $(TARGET).gpe

.SUFFIXES: .o .cpp .c .cc .h .m .i .S .obj

# Rules to manage files
mkdir:
	$(MKDIR) obj
	$(MKDIR) obj/arm
	$(MKDIR) obj/gp2x
	$(MKDIR) obj/unzip

install:
	cp $(TARGET).gpe /cygdrive/f/

$(FXDEPENDS):
	touch $(FXDEPENDS)
	$(RM) $(FXNO_DEPENDS)

$(C4DEPENDS):
	touch $(C4DEPENDS)
	$(RM) $(C4_NODEPENDS)

$(GLIDEDEPENDS):
	touch $(GLIDEDEPENDS)
	$(RM) $(GLIDENO_DEPENDS)

$(TARGET).gpe: $(OBJECTS) 
	$(LD) $(INCLUDES) $(OBJECTS) $(CLAGS) $(EXTRALIBS) `sdl-config --libs` -lz -ldl -lSDL_image -lunicodefont --static-libgcc -o $@

obj/%.o:	src/%.cpp
	$(CCC) $(INCLUDES) -c $(CCFLAGS) $< -o $@

obj/%.o:	src/%.c
	$(CC) $(INCLUDES) -c $(CFLAGS) $< -o $@

obj/%.o:	src/%.S
	$(CC) $(INCLUDES) -c $(CFLAGS) $< -o $@

clean:
	rm -f $(OBJECTS) $(TARGET).gpe
	rm -rf ./obj/

release: clean all

ppu.o: $(FXDEPENDS)
cpu.o: $(FXDEPENDS)
memmap.o: $(FXDEPENDS)
globals.o: $(FXDEPENDS)
i386/cpuexec.o: $(FXDEPENDS)
snapshot.o: $(FXDEPENDS)
snaporig.o: $(FXDEPENDS)

i386/cpuexec.o: i386/asmstruc.h i386/offsets.h
i386/cpuops.o: i386/asmstruc.h i386/asmops.h i386/getset.S i386/asmaddr.h i386/offsets.h
i386/spc700.o: i386/asmstruc.h i386/spcops.h i386/offsets.h
cpuexec.o: cpuexec.h cpuops.h snes9x.h snapshot.h gfx.h \
	memmap.h ppu.h debug.h port.h display.h apu.h spc700.h apu.h
debug.o: cpuops.h cpuexec.h snes9x.h \
	memmap.h ppu.h debug.h missing.h port.h display.h apu.h
ppu.o: snes9x.h memmap.h ppu.h missing.h port.h cpuexec.h \
	apu.h spc700.h fxemu.h fxinst.h
dsp1.o: snes9x.h port.h dsp1.h
snapshot.o: snapshot.h memmap.h snes9x.h 65c816.h ppu.h \
	cpuexec.h display.h apu.h spc700.h soundux.h
snes96.o: port.h snes9x.h memmap.h
memmap.o: cpuexec.h snes9x.h memmap.h ppu.h port.h cheats.h getset.h apu.h \
	  spc700.h
unix.o: cpuexec.h snes9x.h port.h snapshot.h display.h apu.h gfx.h cheats.h
x11.o: display.h snes9x.h memmap.h debug.h ppu.h snapshot.h gfx.h
ggi.o: display.h snes9x.h memmap.h debug.h ppu.h snapshot.h gfx.h 
svga.o: display.h snes9x.h memmap.h debug.h ppu.h snapshot.h gfx.h soundux.h
gfx.o: memmap.h snes9x.h ppu.h gfx.h display.h port.h
tile.o: memmap.h snes9x.h ppu.h display.h gfx.h tile.h
spc700.o: spc700.h apu.h apumem.h snes9x.h memmap.h
apu.o: spc700.h apu.h apumem.h snes9x.h soundux.h
soundux.o: snes9x.h soundux.h apu.h
dma.o: ppu.h dma.h memmap.h getset.h snes9x.h port.h apu.h spc700.h
cheats.o: cheats.h snes9x.h port.h memmap.h
fxemu.o: fxemu.h fxinst.h
fxinst.o: fxemu.h fxinst.h
fxdbg.o: fxemu.h fxinst.h
offsets.o: port.h snes9x.h memmap.h ppu.h apu.h cpuexec.h 65c816.h
globals.o: memmap.h spc700.h apu.h cpuexec.h ppu.h cheats.h snes9x.h gfx.h \
	   missing.h dma.h dsp1.h soundux.h
xf86.o: display.h snes9x.h memmap.h debug.h ppu.h snapshot.h gfx.h
server.o: snes9x.h port.h memmap.h netplay.h
netplay.o: snes9x.h port.h memmap.h netplay.h
snaporig.o: cpuexec.h
os9x_65c816.o: src/arm/os9x_65c816_def.h src/arm/os9x_65c816_mac_gen.h \
	       src/arm/os9x_65c816_mac_mem.h \
	       src/arm/os9x_65c816_mac_op.h src/arm/os9x_asm_cpu.h
