RARCH_VERSION		= "0.9.9.3"

DEBUG			= 0
HAVE_LOGGER		= 0
HAVE_FILE_LOGGER	= 0

PC_DEVELOPMENT_IP_ADDRESS	= "192.168.1.7"
PC_DEVELOPMENT_UDP_PORT		= 3490

CC = $(PS3DEV)/ppu/bin/ppu-gcc
CXX = $(PS3DEV)/ppu/bin/ppu-g++
LD = $(PS3DEV)/ppu/bin/ppu-ld

CONTENT_ID_FULL		= UP0001-SSNE10000_00-0000000000000001

ELF_TARGET := retroarch_psl1ght.elf
EBOOT_PATH		= pkg/ps3/USRDIR/EBOOT.BIN
CORE_PATH		= pkg/ps3/USRDIR/cores/CORE.SELF

INCLUDE := -I. -I$(PS3DEV)/ppu/include -Ideps/zlib -Ips3/gcmgl/include/export -Ips3/include
LIBDIRS := -L$(PS3DEV)/ppu/lib -L$(PS3DEV)/portlibs/ppu/lib -L.

MACHDEP := -D__CELLOS_LV2__ -D__PSL1GHT__
CFLAGS += -Wall $(MACHDEP) $(INCLUDE)
LDFLAGS := $(MACHDEP)
LIBS := -lrgl_ps3 -lretro_psl1ght -laudio -lrsx -lgcm_sys -lnet -lio -lsysutil -lsysmodule  -lm -ljpgdec -lpngdec -llv2 -lnet -lnetctl

# system platform
system_platform = unix
ifeq ($(shell uname -a),)
EXE_EXT = .exe
   system_platform = win
else ifneq ($(findstring Darwin,$(shell uname -a)),)
   system_platform = osx
else ifneq ($(findstring MINGW,$(shell uname -a)),)
   system_platform = win
endif

PKG_SCRIPT		= tools/ps3/ps3py/pkg.py
ifeq ($(shell uname), Linux)
PKG_FINALIZE         	= package_finalize
MAKE_SELF_WC		= make_self_wc
MAKE_SELF		= make_self_npdrm
PYTHON2			= python2
GIT			= git
else
PKG_FINALIZE         	= package_finalize.exe
MAKE_SELF_WC		= make_self_wc.exe
MAKE_SELF		= make_self_npdrm.exe
PYTHON2			= python2.exe
GIT			= git.exe
endif
# system platform
system_platform = unix
ifeq ($(shell uname -a),)
EXE_EXT = .exe
   system_platform = win
else ifneq ($(findstring Darwin,$(shell uname -a)),)
   system_platform = osx
else ifneq ($(findstring MINGW,$(shell uname -a)),)
   system_platform = win
endif

PKG_SCRIPT		= tools/ps3/ps3py/pkg.py
ifeq ($(shell uname), Linux)
PKG_FINALIZE         	= package_finalize
MAKE_SELF_WC		= make_self_wc
MAKE_SELF		= make_self_npdrm
PYTHON2			= python2
GIT			= git
else
PKG_FINALIZE         	= package_finalize.exe
MAKE_SELF_WC		= make_self_wc.exe
MAKE_SELF		= make_self_npdrm.exe
PYTHON2			= python2.exe
GIT			= git.exe
endif

MAKE_FSELF_NPDRM = $(CELL_SDK)/host-win32/bin/make_fself_npdrm.exe
MAKE_PACKAGE_NPDRM = $(CELL_SDK)/host-win32/bin/make_package_npdrm.exe

OBJ = griffin/griffin.o

ifeq ($(HAVE_LOGGER), 1)
CFLAGS		+= -DHAVE_LOGGER
CFLAGS		+= -Ilogger/netlogger
endif

ifeq ($(HAVE_FILE_LOGGER), 1)
CFLAGS		+= -DHAVE_FILE_LOGGER
endif

SHARED_FLAGS := -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OVERLAY -DHAVE_HEADSET -DHAVE_OPENGLES -DHAVE_OPENGLES1 -DHAVE_PSGL -DHAVE_CG -DHAVE_CG_RUNTIME_COMPILER -DHAVE_GCMGL -DHAVE_FBO -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_MOUSE  -DHAVE_ZLIB -DHAVE_RPNG -DWANT_ZLIB   -DHAVE_GRIFFIN=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -Wno-char-subscripts
CFLAGS += -std=gnu99 $(SHARED_FLAGS)
CXXFLAGS += $(SHARED_FLAGS)

ifeq ($(DEBUG), 1)
   CFLAGS += -O0 -g
else
   CFLAGS += -O3 -g 
   CXXFLAGS += -03 -g
endif

all: $(ELF_TARGET)

$(ELF_TARGET): $(OBJ)
	$(CXX) -o $@ $(LDFLAGS) $(LIBDIRS) $(OBJ) $(LIBS)

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

%.o: %.cpp
	$(CXX) $(CFLAGS) -c -o $@ $<

create-npdrm-core:
	$(MAKE_FSELF_NPDRM) $(ELF_TARGET) $(CORE_PATH)

create-core:
	$(MAKE_SELF_WC) $(ELF_TARGET) $(CORE_PATH)

pkg: $(ELF_TARGET) create-npdrm-core
	$(MAKE_PACKAGE_NPDRM) pkg/ps3/package.conf ps3/pkg

pkg-signed: $(ELF_TARGET) create-core
	$(PYTHON2) $(PKG_SCRIPT) --contentid $(CONTENT_ID_FULL) pkg/ps3 retroarch-ps3-cfw-$(RARCH_VERSION).pkg

clean:
	rm -f $(ELF_TARGET)
	rm -f $(OBJ)

.PHONY: clean

