#
# 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) 

# 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= -Lrwho

#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 = -Tpe -ap -c -Gn $(DEBUG_LFLAGS) $(INCLIBS)
INCS = -I. $(INCDIRS)

# 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) $(LFLAGS) $(BCC32STARTUP) $**, $<,, $(LIBS) $(RWHO_LIB)

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

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

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

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

$(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 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 -n$(@D) $<