LOP/
LOP/area/
LOP/boards/
LOP/channels/
LOP/clans/
LOP/classes/
LOP/color/
LOP/councils/
LOP/deity/
LOP/races/
LOP/src/specials/
CC      = g++
#PROF    = -p

#Uncomment to compile in Cygwin
#CYGWIN = -DCYGWIN

#Uncomment the line below if you are getting undefined references to dlsym, dlopen, and dlclose.
#Comment it out if you get errors about ldl not being found.
NEED_DL = -ldl

#Some systems need this for dynamic linking to work.
EXPORT_SYMBOLS = -export-dynamic

# Uncomment the two lines below if compiling on a Solaris box
#SOLARIS_FLAG = -Dsun -DSYSV
#SOLARIS_LINK = -lnsl -lsocket

#IMC2 - Comment out to disable IMC2 support
IMC = 1

#W_FLAGS = -Wall -Werror -Wshadow -Wformat-security -Wpointer-arith -Wcast-align -Wredundant-decls -Wwrite-strings
W_FLAGS = -Wall -Werror -Wshadow -Wformat-security -Wpointer-arith -Wcast-align -Wredundant-decls

C_FLAGS = -g2 $(W_FLAGS) $(SOLARIS_FLAG) $(PROF) $(EXPORT_SYMBOLS)
L_FLAGS = $(PROF) $(SOLARIS_LINK) -lz $(NEED_DL)

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c areas.c \
          ban.c bank.c boards.c bti.c build.c \
          channels.c clans.c classes.c color.c comm.c commands.c const.c \
          db.c deity.c \
          exp.c \
          fight.c fish.c \
          handler.c hashstr.c helps.c highscore.c hint.c host.c hotboot.c \
          interp.c \
          lockers.c \
          magic.c makeobjs.c mapout.c mccp.c misc.c mpxset.c mud_comm.c mud_prog.c mwresets.c \
          news.c \
          player.c polymorph.c \
          quest.c \
          races.c reserved.c reset.c \
          save.c sha256.c shops.c skills.c socials.c special.c sudoku.c sysdata.c \
          tables.c timeinfo.c track.c transfer.c \
          update.c

ifdef IMC
   C_FILES := imc.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DIMC -DIMCSMAUG
endif

O_FILES := $(patsubst %.c,o/%.o,$(C_FILES))

H_FILES = $(wildcard h/*.h) 

all:
	$(MAKE) -s smaug

SPEC = specials/
ifdef CYGWIN
SMAUG = smaug.exe
SDEF = $(SPEC)smaug.def
SEXP = $(SPEC)smaug.exp
else
SMAUG = smaug
endif
DEP = $(SPEC)dependencies.d

# pull in dependency info for *existing* .o files
-include $(DEP)

dependency:
	echo "Generating dependency file...";
	$(CC) -MM $(C_FLAGS) $(C_FILES) > $(DEP)
	perl -pi -e 's.^([a-z]).o/$$1.g' $(DEP)

smaug: $(O_FILES)
	rm -f ../$(SMAUG)
ifdef CYGWIN
	dlltool --export-all --output-def $(SDEF) $(O_FILES)
	dlltool --dllname $(SMAUG) --output-exp $(SEXP) --def $(SDEF)
	$(CC) -o $(SMAUG) $(O_FILES) $(SEXP) $(L_FLAGS)
else
	$(CC) -export-dynamic -o $(SMAUG) $(O_FILES) $(L_FLAGS)
endif
	$(MAKE) -s dependency
	echo "Done compiling mud.";
	chmod g+w $(SMAUG)
	chmod a+x $(SMAUG)
	mv $(SMAUG) ../$(SMAUG)
	chmod g+w $(O_FILES)

purge:
	rm -f o/*.o ../$(SMAUG) *~ $(DEP)
	touch $(DEP)

clean:
	$(MAKE) -s purge
	$(MAKE) -s smaug

indent:
	indent -ts3 -nut -nsaf -nsai -nsaw -npcs -npsl -ncs -nbc -bls -prs -bap -cbi0 -cli3 -bli0 -l125 -lp -i3 -cdb -c1 -cd1 -sc -pmt $(C_FILES)
	indent -ts3 -nut -nsaf -nsai -nsaw -npcs -npsl -ncs -nbc -bls -prs -bap -cbi0 -cli3 -bli0 -l125 -lp -i3 -cdb -c1 -cd1 -sc -pmt $(H_FILES)

indentclean:
	rm *.c~ *h/.h~

o/%.o: %.c
	echo "  Compiling $@....";
	$(CC) -c $(C_FLAGS) $< -o $@

.c.o: h/mud.h
	$(CC) -c $(C_FLAGS) $<