# -*- Makefile -*-
#
# Makefile.PSP - Makefile rules for Sony Play Station Portable Firmware version 1.0
#   Thanks Shiikuru-san
#

PSPPRE = $(shell psp-config --psp-prefix)
PSPDEV = $(shell psp-config --pspdev-path)
PSPSDK = $(shell psp-config --pspsdk-path)

INCS  = $(shell $(PSPDEV)/bin/sdl-config --cflags) $(shell $(PSPDEV)/bin/freetype-config --cflags)
LIBS  = $(shell $(PSPDEV)/bin/sdl-config --libs)
LIBS += -lSDL_ttf -lSDL_image -lSDL_mixer -lSDL -lSDLmain -lfreetype -lbz2 -lm -ljpeg -lpng -lz -lmad -lvorbisidec

# Include PSPSDK and Libc Headers
INCS += -I$(PSPSDK)/include -I$(PSPDEV)/include -I$(PSPPRE)/include

# Link PSPSDK and Libc Libraries
LIBS += -L$(PSPSDK)/lib -L$(PSPDEV)/lib -lpspsdk -lpspgu -lpspdebug -lpspdisplay -lpsphprm -lpspaudio -lpspge -lpspctrl -lc -lpspuser -lpspkernel


# with OggVorbis (Tremor) in PDA size (QVGA)
#DEFS = -DPSP -DPDA -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS
# with OggVorbis (Tremor) in PSP size (360x270)
DEFS = -DPSP -DPDA -DPDA_PSP -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS
# with OggVorbis (Tremor) in PSP size (384x288)
#DEFS = -DPSP -DPDA -DPDA_PSP2 -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS

EXESUFFIX = .elf
OBJSUFFIX = .o

.SUFFIXES:
.SUFFIXES: $(OBJSUFFIX) .cpp .h

CC = psp-g++ 
LD = psp-g++ -o 

CFLAGS = -g -G0 -O2 -Wall -Wpointer-arith -fno-exceptions -fno-rtti -fno-check-new -pipe -c $(INCS) $(DEFS)
RM = rm -f

TARGET = EBOOT.PBP
EXT_OBJS = MadWrapper$(OBJSUFFIX)


# onscripter.elf -> EBOOT.PBP for PSP Firmware version 1.0

STRIP    = psp-strip
MKSFO    = mksfo
PACK_PBP = pack-pbp

PSP_TARGET       = onscripter$(EXESUFFIX)
PSP_TARGET_STRIP = onscripter_strip$(EXESUFFIX)
PSP_EBOOT_TITLE  = ONScripter for PSP
PSP_EBOOT_SFO    = PARAM.SFO
PSP_EBOOT_ICON   = NULL
PSP_EBOOT_ICON1  = NULL
PSP_EBOOT_UNKPNG = NULL
PSP_EBOOT_PIC1   = NULL
PSP_EBOOT_SND0   = NULL
PSP_EBOOT_PSAR   = NULL

EBOOT.PBP : $(PSP_TARGET_STRIP) $(PSP_EBOOT_SFO)
	$(PACK_PBP) EBOOT.PBP $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON)  \
		$(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1)  \
		$(PSP_EBOOT_SND0)  $(PSP_TARGET_STRIP) $(PSP_EBOOT_PSAR)

$(PSP_EBOOT_SFO) :
	$(MKSFO) '$(PSP_EBOOT_TITLE)' $(PSP_EBOOT_SFO)

$(PSP_TARGET_STRIP) : $(PSP_TARGET)
	$(STRIP) $(PSP_TARGET) -o $(PSP_TARGET_STRIP)

include Makefile.onscripter

# overriding
clean :
	$(RM) $(TARGET)
	$(RM) $(PSP_TARGET) $(PSP_TARGET_STRIP) $(PSP_EBOOT_SFO)
	$(RM) *.o
