#
# Whatever you put in for $(CC) must be able to grok ANSI C.
#
CC = cl
LD = cl
AR = link /LIB
WINZIP = C:\apps\Winzip\wzzip

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

# Compiler directives for debugging
!ifdef DEBUG
DEBUG_CFLAGS = /MTd /ZI /Od /EHsc /DDEBUG 
DEBUG_LFLAGS = /DEBUG /PDBTYPE:SEPT 
LIBS      = libcmtd.lib kernel32.lib ws2_32.lib 
!else
DEBUG_CFLAGS = /MT /Ot /Oy /Ob2 /Gs /GF /Gy /EHsc /DNDEBUG   
DEBUG_LFLAGS = 
LIBS      = libcmt.lib kernel32.lib ws2_32.lib 
!endif

SYSDEFS= -DWIN32 -DWIN32_LEAN_AND_MEAN -D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_USE_32BIT_TIME_T 
OPTIM= /nologo /W1 $(DEBUG_CFLAGS) 


# 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=  
INCLIBS= /LIBPATH:rwho

#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)
LFLAGS = /link /NOLOGO /NODEFAULTLIB /SUBSYSTEM:CONSOLE $(DEBUG_LFLAGS) $(INCLIBS)
INCS = /I.

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

DB_FILES  = destroy.c 
DB_OFILES = $(DB_FILES:.c=.obj)

DUMP_FILES  = dump.c unparse.c 
DUMP_OFILES = $(DUMP_FILES:.c=.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 = $(CFILES:.c=.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_FILES:.c=.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 

!ifndef RELEASE
RELEASE=dist
!endif

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) $** $(LIBS)  /Fe$@ $(LFLAGS) $(RWHO_LIB)

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

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

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

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

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

clean:
	-del *.pdb *.ilk *.idb $(TARGETS) $(OBJDEPENDS) 2>NUL


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 /Tc$< /Fo$@