#
# Caprice32 port on GP2X 
#
# Copyright (C) 2006 Ludovic Jacomme (ludovic.jacomme@gmail.com)
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
CAP32_VERSION=1.1.2

TARGET = cpcm
OBJS = gp2x_psp.o \
cpudingux.o \
cap32.o \
cpccat.o \
crtc.o \
fdc.o \
psg.o \
video.o \
z80.o \
psp_main.o \
psp_sdl.o \
psp_kbd.o \
psp_joy.o \
kbd.o \
psp_font.o \
psp_menu.o \
psp_run.o \
psp_menu_disk.o \
psp_danzeff.o \
psp_menu_set.o \
psp_menu_help.o \
psp_menu_joy.o \
psp_menu_kbd.o \
psp_menu_cheat.o \
psp_menu_list.o \
psp_editor.o \
miniunz.o \
unzip.o \
psp_fmgr.o \
osso.o


CC=gcc
STRIP=strip

DEFAULT_CFLAGS = $(shell pkg-config --cflags gconf-2.0) \
	$(shell pkg-config --cflags glib-2.0) \
	$(shell pkg-config --cflags gtk+-2.0)
MORE_CFLAGS = -DLSB_FIRST \
-I. -I/usr/include -I/usr/include/SDL \
 -DMPU_JZ4740 -O3 -fomit-frame-pointer -fsigned-char -ffast-math \
 -DNO_STDIO_REDIRECT -DMAEMO_MODE  \
 -DCAP32_VERSION=\"$(CAP32_VERSION)\" -pthread

# -fsigned-char -ffast-math -fomit-frame-pointer \
# -fexpensive-optimizations -fno-strength-reduce  \

#  -ffast-math -fomit-frame-pointer -fno-strength-reduce -fexpensive-optimizations \
# -msoft-float -O3  -G 0 

CFLAGS = $(DEFAULT_CFLAGS) $(MORE_CFLAGS) 
LDFLAGS = -s

LIBS += -L/usr/lib -lpng -lz -lm -lpthread -ldl -lSDL -lSDL_image -losso -lX11 \
	$(shell pkg-config --libs gconf-2.0) \
	$(shell pkg-config --libs glib-2.0) \
	$(shell pkg-config --libs gtk+-2.0)
	
all: $(TARGET)

.c.o:
	$(CC) $(CFLAGS) $(DEFAULT_CFLAGS) $(MORE_CFLAGS) -c $< -o $@

$(TARGET): $(OBJS)
	$(CC) $(LDFLAGS) $(CFLAGS) $(DEFAULT_CFLAGS) $(MORE_CFLAGS) $(OBJS) $(LIBS) -o $(TARGET) && $(STRIP) $(TARGET)

install: $(TARGET)
	install -D cpcm $(DESTDIR)/opt/cpcm/cpcm
	#install -D blank.dsk $(DESTDIR)/opt/cpcm/blank.dsk
	install -d $(DESTDIR)/opt/cpcm/rom
	install -m 644 rom/* $(DESTDIR)/opt/cpcm/rom

clean:
	rm -f $(OBJS) $(TARGET)

ctags: 
	ctags *[ch]
