#
# Whatever you put in for $(CC) must be able to grok ANSI C.
#
.AUTODEPEND
BCCROOT = $(MAKEDIR)\..
CC = $(BCCROOT)\bin\bcc32
LD = $(BCCROOT)\bin\ilink32
WINZIP = C:\apps\Winzip\wzzip

# Compiler directives for debugging
!ifdef DEBUG
DEBUG_CFLAGS = -v -y -Od -r- 
!else
DEBUG_CFLAGS = -v- -O2 
!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
#
DEFS= $(SYSDEFS) -DLOG_FAILED_COMMANDS 
CFLAGS= $(OPTIM) $(DEFS)
LFLAGS = -Tpe -ap -c -Gn $(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) $(LFLAGS) $(BCC32STARTUP) interface.obj $(OFILES), $<,, $(LIBS)

dump.exe: dump.obj utils.obj db.obj
	$(LD) $(LFLAGS) $(BCC32STARTUP) dump.obj utils.obj db.obj, $<,, $(LIBS)

sanity-check.exe: sanity-check.obj utils.obj db.obj
	$(LD) $(LFLAGS) $(BCC32STARTUP) sanity-check.obj utils.obj db.obj, $<,, $(LIBS)

extract.exe: extract.obj utils.obj db.obj
	$(LD) $(LFLAGS) $(BCC32STARTUP) extract.obj utils.obj db.obj, $<,, $(LIBS)

paths.exe: paths.obj db.obj
	$(LD) $(LFLAGS) $(BCC32STARTUP) paths.obj db.obj, $<,, $(LIBS)

clean:
	-@del *.obj *.tds *.map $(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) $(INCDIRS) -c $<