#
# CoolMud Digital Mars makefile
#
CC = dmc
LD = link
AR = lib
YACC = yacc
WINZIP = C:\apps\Winzip\wzzip
OPTIM = -o -5
DEFS = -DWIN32 -DWIN32_LEAN_AND_MEAN # -DMETHOD_DEBUG -DCACHE_DEBUG -DDBMCHUNK_DEBUG
CFLAGS = $(OPTIM) $(DEFS) -w2 -w7
LIBS = wsock32.lib

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

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

INCS = -I$(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 = $(N)\hash.obj $(N)\hash_bigkey.obj $(N)\hash_buf.obj $(N)\hash_func.obj \
	$(N)\hash_log2.obj $(N)\hash_page.obj $(N)\ndbm.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

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

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

RELEASE=dist

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

all: $(TARGETS)

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

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

$(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)\*.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 -o$@ $<