release: all
	cp PARAM.SFO.271 PARAM.SFO
	pack-pbp EBOOT.PBP PARAM.SFO img/ICON0_pochi.png NULL NULL NULL NULL pspvnc.prx NULL

GCC = psp-gcc
PSP_LD = psp-ld

CFLAGS=-DDEVHOOK -Ilibnet -Ilibvnc -O1 -G0 -Wall -g -mgp32 -mlong32 -DVERSIONSTRING="\"PSPVNC v1.2.1\""
ASFLAGS=$(CFLAGS)
LIBS= -lpspwlan -lpspgu -lpsppower

BUILD_PRX = 1

TARGET=pspvnc
OBJS = main.o menu.o pspvnc.o vncdbg.o dialog.o pg.o nlh.o loadutil.o
# OBJS+= libnet/pspnet.o libnet/sceNetApctl.o libnet/sceUtility.o
# OBJS+= libnet/sceNet.o libnet/sceNetInet.o libnet/sceNetAdhoc.o
# OBJS+= libnet/sceNetResolver.o libnet/sceNetAdhocctl.o

OBJS+= libvnc/d3des.o libvnc/vncauth.o libvnc/sockets.o libvnc/rfbproto.o
OBJS+= libvnc/rawencoding.o libvnc/ultravnc.o libvnc/corre.o libvnc/rre.o
OBJS+= lzo/minilzo.o

OBJS+= tmp/newicon.o tmp/unkicon.o tmp/tuxicon.o tmp/xbxicon.o
OBJS+= tmp/macicon.o tmp/winicon.o tmp/buttons.o tmp/font.o tmp/font2.o
OBJS+= tmp/plugbmp.o tmp/menubmp.o tmp/splashbmp.o
OBJS+= tmp/check.o tmp/nocheck.o tmp/opticon.o tmp/neticon.o tmp/homeicon.o
OBJS+= tmp/five.o tmp/ten.o tmp/fifteen.o tmp/twenty.o tmp/menusel.o
OBJS+= tmp/gauge1.o tmp/gauge2.o tmp/gauge3.o tmp/gauge4.o tmp/gauge5.o 
OBJS+= tmp/scrollicon.o tmp/mouseicon.o tmp/vkbicon.o tmp/disicon.o tmp/dpadicon.o

BINS= ./bin/1_0/$(TARGET)/EBOOT.PBP ./bin/1_5/$(TARGET)/EBOOT.PBP ./bin/1_5/$(TARGET)%/EBOOT.PBP

#EXTRA_TARGETS=$(BINS)

PSP_EBOOT_TITLE = Portable VNC Viewer

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

install: kxploit
	cp __SCE__pspvnc/EBOOT.PBP /mnt/sda1/psp/game/__SCE__pspvnc/
	cp %__SCE__pspvnc/EBOOT.PBP /mnt/sda1/psp/game/%__SCE__pspvnc/

$(TARGET)_strip.elf: $(TARGET).elf
	$(STRIP) $(TARGET).elf -o $(TARGET)_strip.elf

./bin/1_0/$(TARGET)/EBOOT.PBP: $(TARGET)_strip.elf $(PSP_EBOOT_SFO)
	pack-pbp ./bin/1_0/$(TARGET)/EBOOT.PBP PARAM.SFO img/ICON0_pochi.png NULL NULL NULL NULL  $(TARGET)_strip.elf NULL

./bin/1_5/$(TARGET)%/EBOOT.PBP: $(PSP_EBOOT_SFO)
	pack-pbp ./bin/1_5/$(TARGET)%/EBOOT.PBP PARAM.SFO img/ICON0_pochi.png NULL NULL NULL NULL NULL NULL

./bin/1_5/$(TARGET)/EBOOT.PBP: $(TARGET)_strip.elf
	cp $(TARGET)_strip.elf ./bin/1_5/$(TARGET)/EBOOT.PBP

tmp/%.16: img/%.8888.png
	tools/pngtxr img/$*.8888.png tmp/$*.16 8888

tmp/%.16: img/%.4444.png
	tools/pngtxr img/$*.4444.png tmp/$*.16 4444

tmp/%.16: img/%.565.png
	tools/pngtxr img/$*.565.png tmp/$*.16 5650
	
tmp/%.ld:
	echo "OUTPUT_ARCH(mips:allegrex) SECTIONS { .rodata ALIGN(64): { _$* = .; *(.data); _$*_end = .; } }" > tmp/$*.ld

tmp/%.ct: tmp/%.16
	bin2c tmp/$*.16 tmp/$*.ct _$*

tmp/%.c: tmp/%.ct
	sed tmp/$*.ct -e "s/static//g" > tmp/$*.c

#%.o: fonts/%.16 tmp/%.ld
#	$(PSP_LD) --no-warn-mismatch --format binary --oformat elf32-littlemips -mips2 fonts/$*.16 -o $*.o -r -EL -T tmp/$*.ld
