PSPSDK=$(shell psp-config --pspsdk-path)
PSPDEV=$(shell psp-config --pspdev-path)
INCLUDE=$(PSPSDK)/include

all:    unstuck

clean:
	rm -rf *~ *.o *.elf *.bin *.s *.bin

CC       = psp-gcc
CFLAGS   := -D PSP -I $(INCLUDE) -W -Wall -O2 -G0 -fno-pic -mno-abicalls -w -fomit-frame-pointer

ASM      = psp-as

tiffsdk.o: tiffsdk.c
	# Optimisation level 2 (-O2) MUST be used.
	$(CC) $(CFLAGS) -O2 -S tiffsdk.c -o tiffsdk.s
	$(ASM) tiffsdk.s -o tiffsdk.o

gfx.o: gfx.c gfx.h
	$(CC) $(CFLAGS) -S gfx.c -o gfx.s
	$(ASM) gfx.s -o gfx.o

unstuck.o: unstuck.c gfx.h
	$(CC) $(CFLAGS) -S unstuck.c -o unstuck.s
	$(ASM) unstuck.s -o unstuck.o

unstuck: unstuck.o gfx.o tiffsdk.o tiffsdk.x
	$(PSPDEV)/bin/psp-ld -T tiffsdk.x -L$(PSPSDK)/lib unstuck.o gfx.o tiffsdk.o -o unstuck.elf
	$(PSPDEV)/bin/psp-strip -s unstuck.elf
	$(PSPDEV)/bin/psp-objcopy -O binary unstuck.elf Unstuck/Unstuck.bin
