#
# CoolMud Borland compile
#
.AUTODEPEND
BCCROOT = $(MAKEDIR)\..
CC = $(BCCROOT)\bin\bcc32
CPP = $(BCCROOT)\bin\cpp32 -A -P- -Sk 
LD = $(BCCROOT)\bin\ilink32
AR = $(BCCROOT)\bin\tlib
YACC = yacc
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

# 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

DEFS= -DWIN32 -DWIN32_LEAN_AND_MEAN -D_NO_VCL # -DMETHOD_DEBUG -DCACHE_DEBUG -DDBMCHUNK_DEBUG
OPTIM= $(STATIC_CFLAGS) -tWC -w-pia -w-par -w-aus -w-rch $(DEBUG_CFLAGS) 

CFLAGS= $(OPTIM) $(DEFS)
LFLAGS = -Tpe -ap -c -Gn $(DEBUG_LFLAGS) 

# source and bin directories
S = src
N = src\ndbm
B = bin

INCS = -I$(BCCROOT)\include;$(N)

NDBM_SRC = $(N)\hash.c $(N)\hash_bigkey.c $(N)\hash_buf.c $(N)\hash_func.c \
	$(N)\hash_log2.c $(N)\hash_page.c $(N)\ndbm.c 
NDBM_OBJ = $(NDBM_SRC:.c=.obj)
NDBM_LIB = $(N)\ndbm.lib
NDBM_HDRS = $(N)\db.h $(N)\ndbm.h $(N)\hash.h $(N)\page.h $(N)\extern.h 
NDBM_DOC = $(N)\ndbm.html $(N)\README_Impt_License_Change.txt

CFILES = $(S)\perms.c $(S)\error.c $(S)\code.c $(S)\symbol.c \
	$(S)\utils.c $(S)\decode.c $(S)\list.c $(S)\map.c $(S)\var.c $(S)\verb.c \
	$(S)\method.c $(S)\compile.c $(S)\execute.c $(S)\opcode.c $(S)\opcodes1.c \
	$(S)\opcodes2.c $(S)\opcodes3.c $(S)\builtins.c $(S)\servers.c \
	$(S)\dispatch.c $(S)\message.c $(S)\storage.c $(S)\dbsize.c $(S)\dbpack.c \
	$(S)\dbunpack.c $(S)\hash.c $(S)\string.c $(S)\buf.c $(S)\netio.c \
	$(S)\playerio.c $(S)\serverio.c $(S)\cache.c $(S)\dbmchunk.c $(S)\os.c

OFILES= $(S)\cool.obj $(CFILES:.c=.obj) 

# Files in the standard distribution
DISTFILES= README CHANGES CHANGELOG COPYING COPYRIGHT CREDITS INSTALL_NOTES \
	Makefile Makefile.bor Makefile.vc Makefile.dgm 

!ifndef RELEASE
RELEASE=dist
!endif

TARGETS = $(NDBM_LIB) $(B)\cm$(EXE) $(B)\west.db $(B)\east.db 

all: $(TARGETS)

$(NDBM_LIB): $(NDBM_OBJ)
	-@del $< 2>NUL
	$(AR) $< /a $**

$(B)\cm$(EXE): $(NDBM_LIB) $(OFILES) 
	$(LD) $(LFLAGS) $(BCC32STARTUP) $**, $<,, $(LIBS) 

$(B)\west.db: $(B)\west.precompiled
	$(B)\cm$(EXE) $(B)\west -i -f $(B)\west.precompiled

$(B)\east.db: $(B)\east.precompiled
	$(B)\cm$(EXE) $(B)\east -i -f $(B)\east.precompiled

$(S)\cool.c $(S)\y.tab.h: $(S)\cool.y
	$(YACC) -l -d $**
	-move y.tab.c $(S)\cool.c
	-move y.tab.h $(S)\y.tab.h

clean:
	-@del $(B)\*.tds $(B)\*.map $(S)\y.tab.h $(S)\cool.c $(TARGETS) \
	$(OFILES) $(NDBM_OBJ) $(B)\west.db $(B)\east.db $(B)\west.chunk $(B)\east.chunk $(B)\*.log 2>NUL

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

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