# Reverie
# Copyright (C)2003 Dan Potter
#
# This Makefile is the basic KOS Makefile, plus some glue to allow us to
# generate real dependencies. Feel free to use any of this in your own
# Makefile.
#
#

TARGET = reverie.elf
SRCS = main.cpp starfield.cpp demo.cpp delaycube.cpp melter.cpp \
	amigasphere.cpp perfmeter.cpp phongspheres.cpp screenblinds.cpp \
	screenwave.cpp rotocube.cpp endscroller.cpp modplug.cpp \
	copperbars.cpp vmu.cpp screenshot.c

all: rm-elf $(TARGET)

KOS_ROMDISK_DIR = romdisk
include $(KOS_BASE)/Makefile.rules

# Dependency handling
DEPDIR = deps
df = $(DEPDIR)/$(*F)
OBJS := $(SRCS:%.cpp=%.o)
OBJS := $(OBJS:%.c=%.o)
CMP = $(KOS_CCPLUS) $(KOS_CFLAGS) $(KOS_CPPFLAGS)

%.o: %.cpp
	$(CMP) -MD -o $@ -c $<
	@cp $*.d $(df).P; \
	  sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
	      -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(df).P; \
	  rm -f $*.d
DEPFILES1 = $(SRCS:%.cpp=%.P)
DEPFILES2 = $(notdir $(DEPFILES1))
DEPFILES3 = $(addprefix $(DEPDIR)/,$(DEPFILES2))
-include $(DEPFILES3)

clean:
	-rm -f $(TARGET) $(OBJS) romdisk.* $(DEPDIR)/*

rm-elf:
	-rm -f $(TARGET) romdisk.*

$(TARGET): $(OBJS) romdisk.o
	$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \
		$(OBJS) romdisk.o $(OBJEXTRA) -ltsunami -lparallax -ljpeg -lkmg -lpng -lz -lkosutils -lmodplug -lk++ -lm $(KOS_LIBS)

run: $(TARGET)
	$(KOS_LOADER) $(TARGET)

dist:
	rm -f $(OBJS) romdisk.o romdisk.img
	$(KOS_STRIP) $(TARGET)

