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

# Compiler directives for debugging
!ifdef DEBUG
DEBUG_CFLAGS = /MTd /ZI /Od /FD /GZ /D " DEBUG" 
DEBUG_LFLAGS = /DEBUG /PDBTYPE:SEPT 
LIBS      = libcmtd.lib kernel32.lib ws2_32.lib 
!else
DEBUG_CFLAGS = /MT /O2 /D "NDEBUG" 
DEBUG_LFLAGS = 
LIBS      = libcmt.lib kernel32.lib ws2_32.lib 
!endif

SYSDEFS= /D "WIN32" /D "WIN32_LEAN_AND_MEAN" /D "_CONSOLE" /D "_MBCS"   
OPTIM= /nologo /GX /W1 $(DEBUG_CFLAGS) /G$(PROCESSOR_LEVEL) 

# 
# To log failed commands (HUH's) to stderr, include -DLOG_FAILED_COMMANDS
# To restricted object-creating commands to users with the BUILDER bit,
#   include -DRESTRICTED_BUILDING
# To log all commands, include -DLOG_COMMANDS
#
DEFS= $(SYSDEFS) -DLOG_FAILED_COMMANDS 
CFLAGS= $(OPTIM) $(DEFS)
LFLAGS = /link /NOLOGO /NODEFAULTLIB /SUBSYSTEM:CONSOLE $(DEBUG_LFLAGS) 

# 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 stringutil.c utils.c wiz.c db.c

# .obj versions of above
OFILES= $(CFILES:.c=.obj)

# Files in the standard distribution
DISTFILES= $(CFILES) config.h db.h externs.h interface.h match.h \
	interface.c dump.c sanity-check.c extract.c paths.c \
	help.txt small.db minimal.db restart-cmu README small.db.README \
	Makefile Makefile.bor Makefile.dgm Makefile.vc6 Makefile.lcc \
	copyright.h MANIFEST NOTES CHANGELOG

!ifndef RELEASE
RELEASE=dist
!endif

OUTFILES= netmud.exe dump.exe paths.exe sanity-check.exe extract.exe

all: $(OUTFILES)

netmud.exe: interface.obj $(OFILES)
	-@copy netmud.exe netmud~.exe 2>NUL
	$(LD) interface.obj $(OFILES) $(LIBS) /Fe$@ $(LFLAGS)

dump.exe: dump.obj utils.obj db.obj
	$(LD) dump.obj utils.obj db.obj $(LIBS) /Fe$@ $(LFLAGS)

sanity-check.exe: sanity-check.obj utils.obj db.obj
	$(LD) sanity-check.obj utils.obj db.obj $(LIBS) /Fe$@ $(LFLAGS)

extract.exe: extract.obj utils.obj db.obj
	$(LD) extract.obj utils.obj db.obj $(LIBS) /Fe$@ $(LFLAGS)

paths.exe: paths.obj db.obj
	$(LD) paths.obj db.obj $(LIBS) /Fe$@ $(LFLAGS)

clean:
	-@del *.obj *.pdb *.idb *ilk $(OUTFILES) 2>NUL

dist : $(DISTFILES)
	@echo "Building distribution..."
	@-md tinymud-1.4.1
	@!copy /y $** tinymud-1.4.1 1>NUL
	@$(WINZIP) -Pr tinymud-1.4.1-$(RELEASE).zip tinymud-1.4.1 1>NUL 2>NUL
	@rd /s /q tinymud-1.4.1
	@echo "Done."

.c.obj:
	$(CC) $(CFLAGS) /c /Tc$(<:\=/)