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

DEFS = -DADPLUG_VERSION=\"2.0.1\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DHAVE_LIBSTDC__=1 -DHAVE_GETOPT_H=1

# Change these as required
OPTIMIZE = -O3
DEBUG = 
CFLAGS = $(OPTIMIZE) $(DEBUG) -Iinclude -Iadplug -I/SDK/Local/common/include/libbinio $(DEFS) #-DDEBUG
CXXFLAGS = $(CFLAGS)

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

# Additional linker libraries
LIBS =

# Name of the "thing" to build
TARGET  = TN_AdPlug.tnplug
PLAYER  = TN_AdPlug.bin
VERSION = 1

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

OBJS = init.o initplayer.o announceplayer.o openplayer.o \
	decodeframeplayer.o donotify.o

PLOBJS = playerproc.o \
	adplug/adplug.o adplug/fmopl.o adplug/emuopl.o adplug/debug.o \
	adplug/database.o adplug/fprovide.o adplug/player.o adplug/players.o \
	adplug/hsc.o adplug/sng.o adplug/imf.o adplug/protrack.o adplug/a2m.o \
	adplug/adtrack.o adplug/amd.o adplug/bam.o adplug/d00.o adplug/dfm.o \
	adplug/hsp.o adplug/ksm.o adplug/mad.o adplug/mid.o adplug/mkj.o \
	adplug/cff.o adplug/dmo.o adplug/s3m.o adplug/dtm.o adplug/fmc.o \
	adplug/mtk.o adplug/rad.o adplug/raw.o adplug/sa2.o adplug/xad.o \
	adplug/flash.o adplug/bmf.o adplug/hybrid.o adplug/hyp.o adplug/psi.o \
	adplug/rat.o adplug/u6m.o adplug/rol.o adplug/adlibemu.o adplug/dro.o \
	adplug/lds.o adplug/msc.o adplug/rix.o adplug/xsm.o

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

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

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

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

data/$(PLAYER): $(PLOBJS)
	$(CXX) $(LINK) -o $@ $^ -lbinio

playerproc.o: $(PLAYER)_rev.h

.PHONY: install
install: $(TARGET) data/$(PLAYER)
	$(CP) $(TARGET) Apps:TuneNet/Plugins/
	$(CP) data/$(PLAYER) data/adplug.db Apps:TuneNet/Plugins/data/

.PHONY: dist
dist: distclean
	$(RM) tuneadplug_plug.lha
	lha u -r tuneadplug_plug.lha #?

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

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

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