# Makefile for DAPHNE
# Written by Matt Ownby

# You need to symlink the set of variables that correspond to that platform
# that you are using.  For example, if you are compiling for linux, you would
# do "ln -s Makefile.vars.linux Makefile.vars"
include Makefile.vars

# send these to all the sub-Makefiles

export CXX = g++

# Platform specific cflags defined in the Makefile.vars file
export CFLAGS = ${PFLAGS} -Wall -Winline

# name of the executable
EXE = ../daphne

OBJS = ldp-out/*.o cpu/*.o game/*.o io/*.o timer/*.o ldp-in/*.o video/*.o \
	sound/*.o daphne.o

LOCAL_OBJS = daphne.o

.SUFFIXES:	.cpp

all:	${LOCAL_OBJS} sub
	${CXX} ${DFLAGS} ${OBJS} -o ${EXE} ${LIBS}

sub:
	cd ldp-out && $(MAKE)
	cd cpu && $(MAKE)
	cd game && $(MAKE)
	cd io && $(MAKE)
	cd timer && $(MAKE)
	cd ldp-in && $(MAKE)
	cd video && $(MAKE)
	cd sound && $(MAKE)

include $(LOCAL_OBJS:.o=.d)

.cpp.o:
	${CXX} ${CFLAGS} -c $< -o $@

clean_deps:
	find . -name "*.d" -exec rm {} \;

clean:	clean_deps
	find . -name "*.o" -exec rm {} \;
	rm -f ${EXE}

%.d : %.cpp
	set -e; $(CXX) -MM $(CFLAGS) $< \
                | sed 's^\($*\)\.o[ :]*^\1.o $@ : ^g' > $@; \
                [ -s $@ ] || rm -f $@
