CC=g++
#
# optimise: -O3
#
CCFLAGS=-g3 -Wall -w -pedantic -Wno-long-long -fmessage-length=0 

CPP_FILES = tinymudserver.cpp fight.cpp strings.cpp player.cpp load.cpp save.cpp \
          object.cpp commands.cpp states.cpp globals.cpp comms.cpp room.cpp  \
          thing.cpp xmlparse.cpp message.cpp entities.cpp regexp.cpp shops.cpp  \
          takedrop.cpp management.cpp building.cpp spells.cpp info.cpp basic.cpp \
          gameutils.cpp events.cpp eventhandler.cpp colour.cpp timer.cpp  \
          webclient.cpp webpages.cpp webeditor.cpp  \
          resets.cpp 

C_FILES = pcre.c chartables.c study.c get.c shs.c

O_FILES := $(patsubst %.cpp,o/%.o,$(CPP_FILES))  $(patsubst %.c,o/%.o,$(C_FILES))
D_FILES := $(patsubst %.cpp,d/%.d,$(CPP_FILES))  $(patsubst %.c,d/%.d,$(C_FILES))

tinymudserver : $(O_FILES)
	@ echo "Linking ...";
	@ $(CC) $(CCFLAGS) -o tinymudserver $(O_FILES)

# dependency stuff, see: http://www.cs.berkeley.edu/~smcpeak/autodepend/autodepend.html
# pull in dependency info for *existing* .o files
-include $(D_FILES)

.SUFFIXES : .o .cpp .c
  
o/%.o: %.cpp
	@ echo "Compiling $< ...";
	@ g++ -c $(CCFLAGS) $< -o $@
	@ echo -n "o/" > d/$*.d
	@ $(CC) -MM $< >> d/$*.d

o/%.o: %.c
	@ echo "Compiling $< ...";
	@ gcc -c $(CCFLAGS) $< -o $@
	@ echo -n "o/" > d/$*.d
	@ $(CC) -MM $< >> d/$*.d

clean:
	rm -f tinymudserver o/*.o d/*.d *.stackdump
