MAKE = make
CC   = gcc -mcrt=newlib
CP	 = copy
RM   = delete

# Change these as required
OPTIMIZE = -O3
DEBUG =
CFLAGS = $(OPTIMIZE) $(DEBUG) -Iinclude -DWORDS_BIGENDIAN #-DDEBUG

# Flags passed to gcc during linking
LINK = $(OPTIMIZE) $(DEBUG)

# Additional linker libraries
LIBS = 

# Name of the "thing" to build
TARGET  = TN_2SF.tnplug
VERSION = 1
XSFBIN  = TN_2SF.bin

# Source code files used in this project
# Add any additional files to this line

SRCS = init.c initplayer.c announceplayer.c openplayer.c decodeframeplayer.c donotify.c

XSF_SRCS = 2sfbin.c vio2sf/vio2sf.c \
	vio2sf/desmume/thumb_instructions.c vio2sf/desmume/SPU.c vio2sf/desmume/NDSSystem.c \
	vio2sf/desmume/MMU.c vio2sf/desmume/mc.c vio2sf/desmume/matrix.c vio2sf/desmume/GPU.c \
	vio2sf/desmume/FIFO.c vio2sf/desmume/cp15.c vio2sf/desmume/bios.c \
	vio2sf/desmume/arm_instructions.c vio2sf/desmume/armcpu.c \
	vio2sf/zlib/zutil.c vio2sf/zlib/uncompr.c vio2sf/zlib/inftrees.c vio2sf/zlib/inflate.c \
	vio2sf/zlib/inffast.c vio2sf/zlib/infback.c vio2sf/zlib/crc32.c vio2sf/zlib/adler32.c

# -------------------------------------------------------------
# Nothing should need changing below this line

OBJS = $(SRCS:.c=.o)

XSF_OBJS = $(XSF_SRCS:.c=.o)

all: $(TARGET) data/$(XSFBIN)

# Rules for building
$(TARGET): $(OBJS)
	$(CC) $(LINK) -nostartfiles -o $@ $^ $(LIBS)

init.o announceplayer.o: $(TARGET)_rev.h

data/$(XSFBIN): $(XSF_OBJS)
	$(CC) $(LINK) -nostartfiles -o $@ $^ $(LIBS)

2sfbin.o: $(XSFBIN)_rev.h

.PHONY: install
install: $(TARGET) data/$(XSFBIN)
	$(CP) $(TARGET) Apps:TuneNet/Plugins/
	$(CP) data/$(XSFBIN) Apps:TuneNet/Plugins/data/

.PHONY: clean
clean: distclean
	$(RM) $(TARGET) data/$(XSFBIN)

.PHONY: distclean
distclean:
	$(RM) $(OBJS) $(XSF_OBJS)

.PHONY: revision
revision:
	bumprev $(VERSION) $(TARGET)
	bumprev $(VERSION) $(XSFBIN)
