#Makefile
#
# Whatever you put in for $(CC) must be able to grok ANSI C.
#

# GCC:
CC=gcc
OPTIM= -W -Wreturn-type -Wunused -Wswitch -Wcomment -Wshadow -Wwrite-strings -g

# IBM RT C compiler:
#CC=cc
#OPTIM=-g -Dconst=

# Dec 3100 C compiler
#CC=cc
#OPTIM= -g -Dconst=

# NeXT compiler:
#CC=cc
#OPTIM=-g

# Malloc package options *sigh*
# The smalloc.c package is preferred as it doesn't endlessly grow even though
# it has slightly (very slightly) more overhead.
MALLOC = smalloc.c
MALLOC_O = smalloc.o
MALLOC_D = -DUSE_SMALLOC
#
# the Nalloc package has the problem that it never frees off memory that it
# has allocated (though it does reuse memory).  However when you do a lot of
# allocs/unallocs the memory tends to grow at an abortive rate.
#MALLOC = nalloc.c
#MALLOC_O = nalloc.o
#MALLOC_D = -DUSE_NALLOC

# 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=  $(MALLOC_D)
LIBS=

#b) ONLY send info to an RWHO server
#DEFS= -DRWHO_SEND $(MALLOC_D)
#LIBS= -LRWHO -lrwho

#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 $(MALLOC_D)
#LIBS= -LRWHO -lrwho

CFLAGS= $(OPTIM) $(DEFS)

# stupid SYS V shell
SHELL=/bin/sh

# for lint target
LINT=lint
LINTFLAGS=-haz $(DEFINES)
LINTFILT=egrep -v '(possible pointer|long assign|not yet im|:$$)'

# uncomment the following line if you want to use the concentrator
#CONC = concentrate

# default: this is the output of make all if no RWHO server is used
OUTFILES = netmud mkindx dump extract $(CONC)

# Use this OUTFILES if you WANT the RWHO stuff
#OUTFILES = rwho_made netmud mkindx dump extract $(CONC)

###############################################################################
#         You shouldn't have to change anything below this line.              #
###############################################################################
SHARED_FILES  = db.c compress.c player_list.c stringutil.c attrib.c mem_check.c
SHARED_OFILES = db.o compress.o player_list.o stringutil.o attrib.o mem_check.o

DB_FILES  = destroy.c $(SHARED_FILES)
DB_OFILES = destroy.o $(SHARED_OFILES)

DUMP_FILES  = dump.c unparse.c $(SHARED_FILES)
DUMP_OFILES = dump.o unparse.o $(SHARED_OFILES)

# Everything except interface.c --- allows for multiple interfaces
C_FILES= 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 $(DB_FILES)

# .o versions of above
O_FILES= create.o game.o help.o look.o match.o move.o player.o predicates.o \
	 rob.o set.o speech.o utils.o wiz.o timer.o boolexp.o unparse.o \
	 cque.o eval.o wild.o interface.o mail.o $(DB_OFILES)

H_FILES = attrib.h config.h.dist copyright.h db.h externs.h fifo.h globals.h \
	  help.h interface.h match.h mem_check.h nalloc.h oldattrib.h \
	  version.h.dist

AUX_FILES = CHANGES OLDCHANGES Makefile.dist README conc.c bsd.c connect.c \
	    decompress.c dump.c extract.c fifo.c mkindx.c xenix.c \
	    xsocket.c smalloc.c nalloc.c bsdconc.c announce.c

RWHO_FILES = RWHO/HOW_TO RWHO/README RWHO/Makefile RWHO/clilib.c RWHO/mudwho.c

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/save game/data/minimal.db.Z

# Files in the standard distribution
DISTFILES= $(C_FILES) $(H_FILES) $(AUX_FILES) $(RWHO_FILES) $(GAME_FILES)

all: $(OUTFILES)

install_conc: $(CONC)
	-rm -f game/concentrate
	(cd game; ln -s ../concentrate concentrate)

install: $(OUTFILES)
	-rm -f game/netmush
	-rm -f game/mkindx
	(cd game; \
	ln -s ../netmud netmush; \
	ln -s ../mkindx mkindx)

concentrate: conc.c
	$(CC) $(CFLAGS) -o concentrate conc.c

rwho_made:
	(cd RWHO; make CC="$(CC)" CFLAGS="$(CFLAGS)")
	touch rwho_made

TAGS: *.c *.h
	etags *.c *.h

mkindx: mkindx.c config.h
	$(CC) -o mkindx mkindx.c
                        
netmud: $(O_FILES) $(MALLOC_O)
	-mv -f netmud netmud~
	$(CC) $(CFLAGS) -o netmud $(O_FILES) $(MALLOC_O) $(LIBS) -lm

saber:  $(O_FILES) $(MALLOC_O)
	#load $(CFLAGS) -o netmud $(C_FILES) $(MALLOC_O) $(LIBS)

lint: $(DISTFILES)
	$(LINT) $(LINTFLAGS) $(C_FILES) $(LLIBS) 2>&1 | $(LINTFILT)
lint-p: $(DISTFILES)
	$(LINT) $(LINTFLAGS) -p $(C_FILES) $(LLIBS) 2>&1 | $(LINTFILT)

tags: $(DISTFILES)
	etags *.c *.h

dump: $(DUMP_OFILES) $(MALLOC_O)
	-rm -f dump
	$(CC) $(CFLAGS) -o dump $(DUMP_OFILES) $(MALLOC_O) $(LIBS)
 
extract: extract.o utils.o $(SHARED_OFILES) $(MALLOC_O)
	-rm -f extract
	$(CC) $(CFLAGS) -o extract extract.o utils.o $(SHARED_OFILES) \
	      $(MALLOC_O) $(LIBS)

decompress: decompress.o compress.o
	-rm -f decompress
	$(CC) $(CFLAGS) -o decompress decompress.o compress.o $(LIBS)

clean:
	-rm -f *.o *~ *.orig *.rej
	-rm -f a.out core gmon.out $(OUTFILES) 
	(cd game; rm -f *.log netmush mkindx)
	(cd RWHO; make clean)

dist.tar.Z: $(DISTFILES)
	tar cvf - $(DISTFILES) | compress -c > dist.tar.Z.NEW
	mv dist.tar.Z.NEW dist.tar.Z

# DO NOT DELETE THIS LINE -- make depend depends on it.

attrib.o: config.h copyright.h version.h db.h attrib.h oldattrib.h externs.h
attrib.o: interface.h
boolexp.o: copyright.h db.h attrib.h match.h externs.h config.h version.h
boolexp.o: interface.h
bsd.o: copyright.h db.h attrib.h interface.h externs.h config.h version.h
compress.o: copyright.h config.h version.h db.h attrib.h
conc.o: config.h copyright.h version.h
cque.o: config.h copyright.h version.h db.h attrib.h interface.h match.h
cque.o: externs.h
create.o: config.h copyright.h version.h db.h attrib.h interface.h externs.h
db.o: copyright.h config.h version.h interface.h db.h attrib.h externs.h
decompress.o: copyright.h config.h version.h
destroy.o: copyright.h config.h version.h db.h attrib.h externs.h globals.h
dump.o: copyright.h config.h version.h db.h attrib.h
eval.o: copyright.h db.h attrib.h interface.h config.h version.h externs.h
extract.o: copyright.h config.h version.h db.h attrib.h
fifo.o: fifo.h nalloc.h
game.o: config.h copyright.h version.h externs.h db.h attrib.h interface.h
game.o: match.h
help.o: copyright.h db.h attrib.h config.h version.h interface.h externs.h
help.o: help.h
interface.o: config.h copyright.h version.h bsd.c db.h attrib.h interface.h
interface.o: externs.h
look.o: copyright.h config.h version.h db.h attrib.h interface.h match.h
look.o: externs.h
match.o: copyright.h db.h attrib.h config.h version.h externs.h globals.h
match.o: match.h
mem_check.o: config.h copyright.h version.h
mkindx.o: help.h
mail.o: copyright.h config.h version.h db.h attrib.h externs.h globals.h
mail.o: match.h
move.o: copyright.h config.h version.h db.h attrib.h interface.h match.h
move.o: externs.h globals.h
nalloc.o: nalloc.h
onconc.o: config.h copyright.h version.h
player.o: copyright.h config.h version.h db.h attrib.h interface.h externs.h
player_list.o: copyright.h db.h attrib.h config.h version.h interface.h
player_list.o: globals.h externs.h
predicates.o: copyright.h config.h version.h externs.h db.h attrib.h
predicates.o: interface.h
rob.o: copyright.h db.h attrib.h config.h version.h interface.h match.h
rob.o: externs.h
set.o: copyright.h config.h version.h db.h attrib.h match.h interface.h
set.o: externs.h
speech.o: copyright.h db.h attrib.h interface.h match.h config.h version.h
speech.o: externs.h
stringutil.o: copyright.h interface.h db.h attrib.h globals.h
timer.o: copyright.h db.h attrib.h config.h version.h interface.h match.h
timer.o: externs.h
unparse.o: config.h copyright.h version.h db.h attrib.h externs.h interface.h
utils.o: copyright.h interface.h db.h attrib.h
wild.o: config.h copyright.h version.h interface.h db.h attrib.h globals.h
wiz.o: copyright.h config.h version.h db.h attrib.h interface.h match.h
wiz.o: externs.h
xenix.o: copyright.h db.h attrib.h interface.h config.h version.h fifo.h
xsocket.o: copyright.h db.h attrib.h interface.h config.h version.h