#Makefile
#
# Whatever you put in for $(CC) should be able to grok ANSI C.
# However, some stuff has been pasted in to try to get it to work
# with compilers that don't.
#
# If you don't plan on doing any debugging, you might want to replace
# the -g with -O for optimization. Also, you may want to "strip" the
# final executable to reduce its size.
#

# GCC: if you use this, I _strongly_ recommend a version above 2.0, or
#      a version prior to 1.40. For some reason, this code interacts
#      poorly with some gcc versions.
CC=gcc
# gcc versions before 2.0
#OPTIM= -W -Wreturn-type -Wunused -Wswitch -Wcomment -Wshadow -Wwrite-strings -g
# gcc version 2.0 and higher
OPTIM= -W -Wreturn-type -Wswitch -Wcomment -Wshadow -Wwrite-strings -Wformat -Wparentheses

# NeXT compiler:
#CC=cc
#OPTIM= -W -Wreturn-type -Wunused -Wswitch -Wcomment -Wshadow -Wwrite-strings -g

# HP-UX compiler:
#CC=cc
#OPTIM= -w +Obb800 -Aa -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_HPUX_SOURCE -D_INCLUDE_XOPEN_SOURCE

# Sun cc (without ANSI libraries)
# Recommendation: go get gcc and use that to compile instead.
# You will need to do the following to convert the code to something
#   that's traditional C (and thus grokkable by Sun cc):
# 1. Replace all occurences of 'void *' in the code with 'char *' 
#    (the traditional C generic pointer type)
# 2. Comment out any "extern" declarations that are causing errors.
# 3. Comment out all MALLOC defs below, and set MALLOC_O=
#    This means you end up using whatever malloc your system provides.
#    Alternatively, you could go through, do the type replacement thing
#    as in step 1. above in smalloc.c, and tinker with it.
# 4. If your pre-processor is fussy, all pre-processor directives must
#    start at the beginning of the line (some of the ones in game.c do
#    not, for example).
#
#CC=cc
#OPTIM=-g -Dconst= -D__TIME__="\"`date +%T`\"" -D__DATE__="\"`date '+%h %d 19%y'`\""

# Other non-ANSI-compliant compilers: Dec C compiler, IBM RT C compiler, etc.
# If it doesn't compile, and the problems look similar to those mentioned
# above for Sun's cc, try making one or more of those changes and recompiling.
# If you need more help, send email to the author.
#CC=cc
#OPTIM=-g -Dconst= -D__TIME__="\"`date +%T`\"" -D__DATE__="\"`date '+%h %d 19%y'`\""

# 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.
# If you have problems with "illegal pointer combination"s or the like
# when compiling this, it is probably best just to comment out the
# MALLOC and MALLOC_D lines.
MALLOC = smalloc.c
MALLOC_O = smalloc.o
MALLOC_D = -DUSE_SMALLOC

# The nalloc package is no longer supported.

# The GNU malloc package is nice if it works on your machine. The version
# included here is virtually identical to that included with TinyMUSH 2.0.
# This is a fast, efficient memory allocator.
# This has not really been tested with 1.50. Don't use it unless you're 
# willing to tinker with it.
#MALLOC = gmalloc.c
#MALLOC_O = gmalloc.o
#MALLOC_D =

# 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 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 log.c conf.c mail.c rpage.c chat.c \
	 atr_tab.c $(DB_FILES)

# .o versions of above
O_FILES= create.o game.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 log.o conf.o mail.o rpage.o chat.o \
	 atr_tab.o $(DB_OFILES)

H_FILES = attrib.h config.h.dist copyright.h db.h externs.h globals.h \
	  help.h interface.h match.h mem_check.h oldattrib.h \
	  game.h atr_tab.h ansi.h chat.h version.h bigrams.h.dist

AUX_FILES = CHANGES-1 CHANGES-2 CHANGES-3 Makefile.dist README BIGRAMS \
            bsd.c connect.c dump.c extract.c mkindx.c smalloc.c announce.c \
	    bigrams.c gmalloc.c getpagesize.h

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

GAME_FILES = game/mush.conf game/sites.conf game/lockout.conf game/names.conf \
	     game/restart game/data/minimal.db.Z game/txt game/log game/save 

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

# Files in a quickie distribution
QUICKFILES = $(C_FILES) $(H_FILES) $(AUX_FILES) $(RWHO_FILES) game/txt/help.txt

all: $(OUTFILES)

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

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

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

announce: announce.c
	$(CC) $(CFLAGS) -o announce announce.c

bigrams: bigrams.c
	$(CC) $(CFLAGS) -o bigrams bigrams.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)

depend:
	makedepend -- $(CFLAGS) -- $(C_FILES)

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)

zap:
	(cd /tmp/$$USER; rm -f *.o *~)

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

qd.tar.Z: $(QUICKFILES)
	tar cvf - $(QUICKFILES) | compress -c > qd.tar.Z.NEW
	mv qd.tar.Z.NEW /tmp/$$USER/qd.tar.Z

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

atr_tab.o: atr_tab.h attrib.h
attrib.o: config.h copyright.h version.h db.h attrib.h externs.h interface.h
attrib.o: oldattrib.h
boolexp.o: copyright.h db.h attrib.h config.h version.h match.h externs.h
boolexp.o: interface.h
bsd.o: copyright.h config.h version.h db.h attrib.h interface.h externs.h 
bsd.o: globals.h help.h
chat.o: config.h copyright.h version.h
compress.o: copyright.h config.h version.h db.h attrib.h bigrams.h
conf.o: config.h copyright.h version.h interface.h db.h attrib.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
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 config.h version.h db.h attrib.h interface.h externs.h
eval.o: globals.h
extract.o: copyright.h config.h version.h db.h attrib.h
game.o: config.h copyright.h version.h db.h attrib.h game.h externs.h
game.o: interface.h match.h globals.h
gmalloc.o: getpagesize.h 
help.o: copyright.h config.h version.h db.h attrib.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 globals.h
log.o: config.h copyright.h version.h externs.h db.h attrib.h interface.h
look.o: copyright.h config.h version.h db.h attrib.h interface.h match.h
look.o: externs.h ansi.h
mail.o: config.h copyright.h version.h db.h attrib.h interface.h
match.o: copyright.h config.h version.h db.h attrib.h externs.h globals.h
match.o: match.h
mem_check.o: config.h copyright.h version.h
mkindx.o: help.h
move.o: copyright.h config.h version.h db.h attrib.h interface.h match.h 
move.o: externs.h globals.h
player.o: copyright.h config.h version.h db.h attrib.h interface.h externs.h
player_list.o: copyright.h config.h version.h db.h attrib.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 globals.h ansi.h
rob.o: copyright.h config.h version.h db.h attrib.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 config.h version.h externs.h db.h attrib.h
speech.o: interface.h match.h
stringutil.o: copyright.h config.h version.h interface.h db.h attrib.h
stringutil.o: globals.h
timer.o: copyright.h config.h version.h db.h attrib.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 config.h version.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
