# gpSP makefile
# Gilead Kutnick - Exophase
# GP2X port(ion) - Z

# Global definitions

PREFIX  = /scratchbox/users/maemo/targets/FREMANTLE_ARMEL/
CC        = /scratchbox/compilers/bin/arm-linux-gnueabi-gcc
STRIP     = strip

OBJS      = main.o cpu.o memory.u video.o input.o sound.o gui.o               \
            cheats.o zip.o cpu_threaded.z arm_stub.o video_blend.o            \
	    warm.o upscale_aspect.o scale2x.o gp2x.o pnd.o linux/fbdev.o linux/xenv.o
BIN       = gpspm

# Platform specific definitions 

VPATH      += ..
CFLAGS     += -DARM_ARCH -DARM_BUILD
#CFLAGS    += -g
# NOTE: -funroll-loops will slow down compiling considerably
# 		-fno-common was required to get games to start
#		-finline-functions breaks cpu_threaded.c
#		-fno-strength-reduce is needed to save time compiling
#                 cpu_threaded.c
#CFLAGS     += -O3 -std=c99 -msoft-float -funsigned-char -fno-common           \
#              -fstrength-reduce -falign-functions -fomit-frame-pointer        \
#              -ffast-math -fexpensive-optimizations -finline                  \
#              -fstrict-aliasing -finline-functions -fweb -fno-builtin

CFLAGS     += -O3 -std=c99 -msoft-float -funsigned-char -fno-common -fsigned-char             \
              -fbranch-probabilities -ffast-math -fstrict-aliasing -falign-functions=32       \
              -fno-builtin -mfpu=vfp -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8          \
              -fexpensive-optimizations -falign-loops -falign-labels -falign-jumps            \
              -mfloat-abi=softfp -mfpu=neon -fsigned-char -fvar-tracking -fomit-frame-pointer \
              -ftree-vectorize -ftree-vectorizer-verbose=2                                    \

#INCLUDES   = `/scratchbox/users/maemo/home/maemo/workspace/gpsp/SDL/bin/sdl-config --cflags` -I/scratchbox/users/maemo/home/maemo/workspace/gpsp/SDL//include
#LIBS       = `/scratchbox/users/maemo/home/maemo/workspace/gpsp/SDL/bin/sdl-config --libs`                \
#              -lm -ldl -lpthread -lasound -lz

INCLUDES   = `/scratchbox/users/maemo/targets/FREMANTLE_ARMEL/usr/bin/sdl-config --cflags` -I/scratchbox/users/maemo/targets/FREMANTLE_ARMEL/usr//include
LIBS       = `/scratchbox/users/maemo/targets/FREMANTLE_ARMEL/usr//bin/sdl-config --libs`  -I/scratchbox/users/maemo/targets/FREMANTLE_ARMEL/usr//lib              \
               -lm -ldl -lpthread -lasound -lz -lSDL -lSDL_haa -lsprig -lEGL -lX11 -lGLESv2

#LIBS       += -static

#SDL_LIBS=-L/scratchbox/users/maemo/home/maemo/workspace/gpsp/SDL//lib -Wl,-rpath,/scratchbox/users/maemo/home/maemo/workspace/gpsp/SDL//lib -lSDL -lpthread -ldl -lasound -lm
#SDL_CFLAGS=-I/scratchbox/users/maemo/home/maemo/workspace/gpsp/SDL//include/SDL -D_GNU_SOURCE=1 -D_REENTRANT

# Compilation:

.SUFFIXES: .c

%.z: %.c
	$(CC) $(CFLAGS) $(NO_OPT_FLAGS) $(INCLUDES) -c -o $@ $<

%.u: %.c
	$(CC) $(CFLAGS) $(NO_OPT_FLAGS) $(INCLUDES) -c -o $@ $<

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

%.o: %.S
	$(CC) $(ASFLAGS) $(NO_OPT_FLAGS) $(INCLUDES) -c -o $@ $<

%.o: %.s
	$(CC) $(ASFLAGS) $(NO_OPT_FLAGS) $(INCLUDES) -c -o $@ $<

all:	$(OBJS)
	$(CC) -Wl,--allow-multiple-definition  $(OBJS) $(LIBS) -o $(BIN)
	$(STRIP) $(BIN)

clean:
	rm -f *.o *.u *.z $(BIN) 

