#
# Whatever you put in for $(CC) must be able to grok ANSI C.
#
CC = dmc
LD = link
AR = lib
WINZIP = C:\apps\Winzip\wzzip
OPTIM = -o -5
SYSDEFS = -DWIN32 -DWIN32_LEAN_AND_MEAN 

# The suffix appended to executables.  
# This should be set for Cygwin and Windows.
EXE = .exe
#EXE =

# By default, db.c initially allocates enough space for 10000 objects, then
#   grows the space if needed.  To change this value, include
#   -DDB_INITIAL_SIZE=xxxx where xxxx is the new value (minimum 1).
# Choose ONE of the following based on how you want the mud to handle RWHO
#a) Defualt: do not use the RWHO server at all.
DEFS=  

#b) ONLY send info to an RWHO server
#DEFS= -DRWHO_SEND 

#c) READ rwho info as well as send it.  This is dangerous UNLESS the RWHO
#   server is on the same machine, or on another locally connected one.  The
#   danger being that it could freeze the mud if the connection timed out.
#DEFS= -DRWHO_SEND -DFULL_RWHO 

CFLAGS = $(OPTIM) $(DEFS) $(SYSDEFS) -w2 -w7 
LIBS= wsock32.lib
INCS = -I.
LFLAGS = 

# Everything needed to use db.c
SHARED_FILES  = db.c compress.c player_list.c stringutil.c attrib.c mem_check.c
SHARED_OFILES  = db.obj compress.obj player_list.obj stringutil.obj attrib.obj mem_check.obj

DB_FILES  = destroy.c 
DB_OFILES = destroy.obj

DUMP_FILES  = dump.c unparse.c 
DUMP_OFILES  = dump.obj unparse.obj

# Everything except interface.c --- allows for multiple interfaces
CFILES= create.c game.c help.c look.c match.c move.c player.c predicates.c \
	 rob.c set.c speech.c utils.c wiz.c timer.c boolexp.c unparse.c \
	 cque.c eval.c wild.c interface.c mail.c os.c
OFILES= create.obj game.obj help.obj look.obj match.obj move.obj player.obj predicates.obj \
	 rob.obj set.obj speech.obj utils.obj wiz.obj timer.obj boolexp.obj unparse.obj \
	 cque.obj eval.obj wild.obj interface.obj mail.obj os.obj

HFILES = attrib.h config.h copyright.h db.h externs.h globals.h \
	  help.h interface.h match.h mem_check.h oldattrib.h \
	  version.h

AUX_FILES = CHANGES OLDCHANGES README \
    decompress.c extract.c mkindx.c announce.c \
    Makefile Makefile.bor Makefile.dgm Makefile.vc Makefile.lcc \
  	CHANGELOG os.h INSTALL_NOTES

RWHO_LIB = rwho\rwho.lib
RWHO_FILES = rwho\clilib.c rwho\mudwho.c
RWHO_OFILES = rwho\clilib.obj rwho\mudwho.obj
RWHO_AUXFILES = rwho\HOW_TO rwho\README 

GAME_FILES = game\connect.txt game\create.txt game\disable.txt game\helptext \
	     game\leave.txt game\news.txt game\register.txt game\restart \
	     game\welcome.txt game\wizard.txt game\data\minimal.db.Z

# Files in the standard distribution
DISTFILES= $(CFILES) $(SHARED_FILES) $(DB_FILES) $(DUMP_FILES) \
  $(HFILES) $(AUX_FILES) 

OBJDEPENDS = $(OFILES) $(DB_OFILES) $(DUMP_OFILES) $(SHARED_OFILES) \
  $(RWHO_OFILES) decompress.obj extract.obj mkindx.obj announce.obj 

RELEASE = dist

TARGETS= extract$(EXE) dump$(EXE) mkindx$(EXE) netmush$(EXE) decompress$(EXE) \
  announce$(EXE) mudwho$(EXE) $(RWHO_LIB)

all: $(TARGETS) 

netmush$(EXE) : $(OFILES) $(DB_OFILES) $(SHARED_OFILES) $(RWHO_LIB)
	$(LD) $(LFLAGS) $**, $@,, $(LIBS) $(RWHO_LIB)

mkindx$(EXE): mkindx.obj
	$(LD) $(LFLAGS) $**, $@,, $(LIBS)
                        
dump$(EXE): $(DUMP_OFILES) $(SHARED_OFILES)
	$(LD) $(LFLAGS) $**, $@,, $(LIBS)
 
extract$(EXE): extract.obj utils.obj $(SHARED_OFILES) 
	$(LD) $(LFLAGS) $**, $@,, $(LIBS)

decompress$(EXE): decompress.obj compress.obj
	$(LD) $(LFLAGS) $**, $@,, $(LIBS)

announce$(EXE): announce.obj 
	$(LD) $(LFLAGS) $**, $@,, $(LIBS)

mudwho$(EXE): rwho\mudwho.obj
	$(LD) $(LFLAGS) $**, $@,, $(LIBS) $(RWHO_LIB)

$(RWHO_LIB) : rwho\clilib.obj
	@echo "making RWHO library..."
	-@del $< 2>NUL
	$(AR) -c $@ $**

clean:
	-@del *.map $(TARGETS) $(OBJDEPENDS)

dist: $(DISTFILES)
	@echo "Building distribution..."
	@-md pernmush
	@&copy /y $** pernmush 1>NUL
	@echo .svn > ex.tmp
        @xcopy game pernmush\game /I /E /Y /Q /EXCLUDE:ex.tmp 
        @xcopy rwho pernmush\rwho /I /E /Y /Q /EXCLUDE:ex.tmp 
        @del ex.tmp
	@$(WINZIP) -Pr pernmush-1.17-$(RELEASE).zip pernmush 1>NUL 2>NUL
	@rd /s /q pernmush
	@echo "Done."

.c.obj:
	$(CC) $(CFLAGS) $(INCS) -c -o$@ $<