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

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

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

# Additional linker libraries
LIBS = 

# Name of the "thing" to build
TARGET  = TN_QSF.tnplug
VERSION = 1
SSFBIN = TN_QSF.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

SSF_SRCS = qsfbin.c ao.c corlett.c \
	eng_qsf/eng_qsf.c eng_qsf/kabuki.c eng_qsf/qsound.c eng_qsf/z80.c eng_qsf/z80dasm.c \
	zlib/adler32.c zlib/compress.c zlib/crc32.c zlib/gzio.c zlib/uncompr.c \
	zlib/deflate.c zlib/trees.c zlib/zutil.c zlib/inflate.c zlib/infback.c \
	zlib/inftrees.c zlib/inffast.c

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

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

SSF_OBJS = $(SSF_SRCS:.c=.o)

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

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

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

data/$(SSFBIN): $(SSF_OBJS)
	$(CC) $(LINK) -nostartfiles -o $@ $^ $(LIBS)

ssfbin.o: $(SSFBIN)_rev.h

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

.PHONY: clean
clean:
	$(RM) $(TARGET) $(SSFBIN) $(OBJS) $(SSF_OBJS)

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

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