#SONGS = vgms/all/Shooting_Ristar.vgm vgms/all/Out_Run_-_Last_Wave.vgm vgms/all/Out_Run_-_Magical_Sound_Shower.vgm vgms/all/Out_Run_-_Passing_Breeze.vgm vgms/all/Out_Run_-_Splash_Wave.vgm
SONGS = test.vgm test.vgm.lzo

ARMGCC = arm-eabi-gcc
ARMOBJ = arm-eabi-objcopy
GBAEMU = "M:/My Documents/GBA/VisualBoyAdvance/VisualBoyAdvance.exe"
TOOLS = tools/

ROM_CFLAGS = -Wall -O2 -mthumb -mthumb-interwork
IWRAM_CFLAGS = -Wall -O2 -marm -mthumb-interwork
LDFLAGS = -Wall -mthumb -mthumb-interwork -specs=gba_mb.specs
RM = rm

.PHONY: songs run clean

run: test.gba
	$(GBAEMU) $^

test.vgm.lzo: test.vgm
	tools/lzo1x-999.exe test.vgm test.vgm.lzo

songs: vgmsongs.gbfs

vgmsongs.gbfs: $(SONGS)
	gbfs $@ $^

chr.s: 8x16.fnt.lz
	bin2s $^ > $@

%.lz: %
	gbalzss e $^ $@

%.o: %.c
	$(ARMGCC) $(ROM_CFLAGS) -c $^ -o $@

%.iwram.o: %.c
	$(ARMGCC) $(IWRAM_CFLAGS) -c $^ -o $@

%.ewram.o: %.c
	$(ARMGCC) $(ROM_CFLAGS) -c $^ -o $@

%.o: %.s
	$(ARMGCC) $(ROM_CFLAGS) -c $^ -o $@

%.iwram.o: %.s
	$(ARMGCC) $(IWRAM_CFLAGS) -c $^ -o $@

gbavgmplayer.elf: vgmplayer.o hud.o vgm.o sn76489.o isr.iwram.o chr.o asm.iwram.o libgbfs.o minilzo.107/minilzo.o reset.iwram.o
	$(ARMGCC) $(LDFLAGS) $^ -o $@

%.gba: %.elf
	$(ARMOBJ) -O binary $^ $@
	padbin 256 $@

test.gba: gbavgmplayer.gba vgmsongs.gbfs
	tools/catbin $^ $@

clean:
	$(RM) -f gbavgmplayer.gba
	$(RM) -f test.gba
	$(RM) -f gbavgmplayer.elf
	$(RM) -f *.o
	$(RM) -f vgmsongs.gbfs
	$(RM) -f chr.s
	make -C minilzo.107 clean

