# Makefile for mode5_scrolling.nds
# chris.double@double.co.nz
NDSLIB_INCLUDE=$(DEVKITPRO)/libnds/include
NDSLIB_LIB=$(DEVKITPRO)/libnds/lib

all: mode5_scrolling.nds.gba

arm7_main.o: arm7_main.cpp
	arm-elf-g++ -g -Wall -O2 -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM7 -c arm7_main.cpp -oarm7_main.o

arm7.elf: arm7_main.o
	arm-elf-g++ -g -mthumb-interwork -mno-fpu -specs=ds_arm7.specs arm7_main.o -L$(NDSLIB_LIB) -lnds7 -oarm7.elf

arm7.bin: arm7.elf
	arm-elf-objcopy -O binary arm7.elf arm7.bin

libgbfs.o: libgbfs.c
	arm-elf-g++ -g -Wall -O2 -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM9 -c libgbfs.c -olibgbfs.o

gba-jpeg-decode.o: gba-jpeg-decode.c
	arm-elf-g++ -g -Wall -O2 -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM9 -c gba-jpeg-decode.c -ogba-jpeg-decode.o

arm9_main.o: arm9_main.cpp
	arm-elf-g++ -g -Wall -O2 -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM9 -c arm9_main.cpp -oarm9_main.o

arm9.elf: arm9_main.o gba-jpeg-decode.o libgbfs.o
	arm-elf-g++ -g -mthumb-interwork -mno-fpu -specs=ds_arm9.specs arm9_main.o gba-jpeg-decode.o libgbfs.o -L$(NDSLIB_LIB) -lnds9 -o arm9.elf

arm9.bin: arm9.elf
	arm-elf-objcopy -O binary arm9.elf arm9.bin

images.gbfs: images/pitcairn_leaf.jpg images/duddie.jpg images/bell.jpg images/brave_bird.jpg
	gbfs images.gbfs images/pitcairn_leaf.jpg images/duddie.jpg images/bell.jpg images/brave_bird.jpg

mode5_scrolling.nds: arm7.bin arm9.bin images.gbfs
	ndstool -c mode5_scrolling.nds -9 arm9.bin -7 arm7.bin
	padbin 256 mode5_scrolling.nds
	cat mode5_scrolling.nds images.gbfs >mode5_scrolling_tmp.nds
	mv mode5_scrolling_tmp.nds mode5_scrolling.nds

mode5_scrolling.nds.gba: mode5_scrolling.nds
	dsbuild mode5_scrolling.nds -o mode5_scrolling.nds.gba

clean:
	rm -f *.bin
	rm -f *.elf
	rm -f *.o
	rm -f *~
	rm -f *.gbfs

