#
# Whatever you put in for $(CC) must be able to grok ANSI C.
#
.AUTODEPEND
BCCROOT = $(MAKEDIR)\..
CC = $(BCCROOT)\bin\bcc32
LD = $(BCCROOT)\bin\ilink32
AR = $(BCCROOT)\bin\tlib
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 = -v -y -Od -r- 
DEBUG_LFLAGS = -v 
!else
DEBUG_CFLAGS = -v- -O2 
DEBUG_LFLAGS = -v- 
!endif
INCDIRS = -I$(BCCROOT)\include

# Compiler/linker directives for linking static or dynamic
!ifdef STATIC
STATIC_CFLAGS =
LIBS      = import32.lib cw32.lib ws2_32.lib
!else
STATIC_CFLAGS = -tWR
LIBS      = import32.lib cw32i.lib ws2_32.lib
!endif
BCC32STARTUP = c0x32.obj

SYSDEFS= -DWIN32 -DWIN32_LEAN_AND_MEAN -D_NO_VCL  
OPTIM= $(STATIC_CFLAGS) -tWC -w-pia -w-par -w-aus -w-rch $(DEBUG_CFLAGS) -$(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
# To force fork_and_dump() to use vfork() instead of fork(), include 
#   -DUSE_VFORK.
# To force grow_database() to be clever about its memory management,
#   include -DDB_DOUBLING.  Use this only if your realloc does not allocate
#   in powers of 2 (if you already have a clever realloc, this option will
#   only cost you extra space).
# 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).
# To include code for keeping track of the number of blocks allocated,
#   include -DTEST_MALLOC.
# To include code which attempts to compress string data, include -DCOMPRESS.
# To eliminate the message third parties see when a player whispers, include
#   -DQUIET_WHISPER.
# To include gender flags and pronoun substitution code, 
#   include -DGENDER.
# To allow players to claim ownership of objects using @chown, 
#   include -DPLAYER_CHOWN.  This also adds the CHOWN_OK flag,
#   to indicate whether an object is @chownable.
# To include teleport-to-player destinations for exits,
#   include -DTELEPORT_TO_PLAYER.
# To make the ``examine'' command display full names for types and flags,
#   use -DVERBOSE_EXAMINE
# To display "has connected" and "has disconnected" messages, use
#   -DCONNECT_MESSAGES
# To allow players to set HAVEN flags, use -DHAVEN.
# To allow players to set ABODE flags, use -DABODE.
# To allow the game to dump core after PANIC dumps, use -DCOREDUMP.
# For the WHO list for wizards to show hostnames instead of addresses, use
# -DHOSTNAMES.
DEFS= -DGOD_PRIV -DGENDER -DVERBOSE_EXAMINE -DPLAYER_CHOWN \
      -DQUIET_WHISPER -DCONNECT_MESSAGES -DTELEPORT_TO_PLAYER \
      -DHAVEN -DABODE -DCOMPRESS -DRECYCLE -DCOREDUMP -DREGISTRATION \
      -DDB_DOUBLING

# This is required of mudwho.exe 
# Distributed seperately see wingdbm package.
GETOPTLIB = getopt.lib

CFLAGS= $(OPTIM) $(DEFS) $(SYSDEFS)
LFLAGS = -Tpe -ap -c -Gn $(DEBUG_LFLAGS) $(INCLIBS)
INCS = -I. $(INCDIRS)

# 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 boolexp.c \
	unparse.c compress.c property.c hashtab.c os.c
OFILES = $(CFILES:.c=.obj)

HFILES = config.h copyright.h db.h externs.h hashtab.h interface.h match.h os.h 

AUX_FILES = CHANGES README restart minimal.db small.db muck.doc help.txt \
    decompress.c interface.c sanity.c \
    Makefile Makefile.bor \
    CHANGELOG INSTALL_NOTES

RWHO_LIB = rwho\rwho.lib
RWHO_FILES = rwho\clilib.c rwho\mudwho.c rwho\mwhod.c rwho\mwhocmd.c 
RWHO_OFILES = $(RWHO_FILES:.c=.obj)
RWHO_AUXFILES = rwho\HOW_TO rwho\README \
    rwho\muds.dat rwho\rwhodoc rwho\rwhostart rwho\mwhod.doc

GAME_FILES = game\help.txt game\lockout.txt game\news.txt game\restart \
    game\restart.bat

# Files in the standard distribution
# currently missing sanity-check.c extract.c dump.c
# I have replaced sanity-check.c with sanity.c -- it's my own version
DISTFILES= $(CFILES) $(HFILES) $(AUX_FILES) 

OBJDEPENDS = $(OFILES) $(RWHO_OFILES) decompress.obj sanity.obj interface.obj

!ifndef RELEASE
RELEASE=dist
!endif

TARGETS= $(RWHO_LIB) netmuck$(EXE) decompress$(EXE) sanity$(EXE) \
  mudwho$(EXE) mwhod$(EXE) mwhocmd$(EXE)

all: $(TARGETS) 

netmuck$(EXE): interface.obj $(OFILES) $(RWHO_LIB)
	$(LD) $(LFLAGS) $(BCC32STARTUP) $**, $<,, $(LIBS) $(RWHO_LIB)

sanity$(EXE): sanity.obj utils.obj db.obj compress.obj
	$(LD) $(LFLAGS) $(BCC32STARTUP) $**, $<,, $(LIBS) 

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

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

mwhod$(EXE): rwho\mwhod.obj
	$(LD) $(LFLAGS) $(BCC32STARTUP) $**, $<,, $(LIBS) $(RWHO_LIB) $(GETOPTLIB)

mwhocmd$(EXE): rwho\mwhocmd.obj
	$(LD) $(LFLAGS) $(BCC32STARTUP) $**, $<,, $(LIBS) $(RWHO_LIB) $(GETOPTLIB)

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

clean:
	-del *.tds *.map $(TARGETS) $(OBJDEPENDS) 2>NUL

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

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