# Makefile for PennMUSH 1.50

#-----   System configuration    -----#

#    SunOS (and possibly Solaris)
# Your system has timelocal(), strdup(), log2(), and getrusage()
#
#SYSDEFS= -DSUN_OS -DHAS_RUSAGE

#    HP-UX
# Your system does not have timelocal(), strdup(), etc.  Also,
# despite what the man pages say, it does not have getrusage().
# It is System V-based.
#
#SYSDEFS= -DHPUX -DNEED_STRDUP -Drandom=rand -Dsrandom=srand

#    IRIX
# Another System V-derived UNIX. It's got both getrusage() and strdup().
#SYSDEFS= -DHPUX -D_HAS_RUSAGE -Drandom=rand -Dsrandom=srand

#    AIX
# Another mutant of System V.
#SYSDEFS= -DHPUX -DHAS_RUSAGE -D_BSD_INCLUDES

#    System V, Linux, BSD386
# UNIX flavors designed for Intel, and miscellaneous other System V flavors.
# If it doesn't work, try defining HPUX and/or some of the other defs
# given above.
SYSDEFS= -Di386 -Dsrand=srandom -Drand=random

#    Other UNIX flavors
# Ultrix, NeXT (Mach), and assorted others.
#SYSDEFS= -DNEED_STRDUP

# You should also take a look at the system options in options.h.


#-----  Compiler choice, defs, libraries and other fun stuff -----

# Whatever you put in for $(CC) should be able to grok at least a
# bit of 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.
#      gcc allows the use of the -g and -O flags simultaneously, so
#      you can turn on optimization without losing debugging info.
CC=gcc
# gcc versions before 2.0
#OPTIM= -W -Wreturn-type -Wunused -Wswitch -Wcomment -Wshadow -Wwrite-strings -fpcc-struct-return -g -O
# gcc version 2.0 and higher
OPTIM= -W -Wreturn-type -Wunused -Wswitch -Wcomment -Wshadow -Wwrite-strings -Wformat -Wparentheses -Wuninitialized -O6 -s

# Linux: use gcc. In the DEFS section below (near the malloc package, etc.)
#   add  -DNCARGS=0x100000
#   You will also need to remove the #ifndef SUN_OS / #endif  pair from
#   around the strdup() function in stringutil.c
# Bob Green (bob@inmos.co.uk) has managed to build PennMUSH under Linux
#   0.98p4 + gcc 2.2.2d7. I haven't worked with Linux at all. Caveat emptor.

# 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

# Generic C compiler. AIX and anything else that you get lucky with.
#CC=cc
#OPTIM= -g

# 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'`\""

# SGI compiler: use gcc instead, if possible.
#CC=cc
#OPTIM= -cckr -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 -DNCARGS=0x100000

# 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) $(SYSDEFS)

# 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
#OLD_OUTFILES = netmud mkindx dump extract $(CONC)
OUTFILES = netmud mkindx $(CONC)

# Use this OUTFILES if you WANT the RWHO stuff
#OLD_OUTFILES = rwho_made netmud mkindx dump extract $(CONC)
#OUTFILES = rwho_made netmud mkindx $(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 \
	 convdb.c atr_tab.c flags.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 flags.o $(DB_OFILES)

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

EXTRA_CFILES= bsd.c connect.c dump.c extract.c mkindx.c smalloc.c announce.c \
	     bigrams.c gmalloc.c

AUX_FILES = CHANGES-1 CHANGES-2 CHANGES-3 CHANGES-4 CHANGES-5 CHANGES-6 \
	    Makefile.dist README BIGRAMS

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

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

# Files in a quickie distribution
QUICKFILES = $(C_FILES) $(H_FILES) $(EXTRA_CFILES) \
	     $(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/netmush
	-rm -f game/mkindx
	(cd game; \
	ln -s ../netmud netmush; \
	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
	$(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)
dist.tar.Z:
	tar -cvf /tmp/dist.tar $(AUX_FILES) $(RWHO_FILES) $(GAME_FILES)
	(cd src; tar -uvf /tmp/dist.tar $(C_FILES) $(EXTRA_CFILES))
	(cd hdrs; tar -uvf /tmp/dist.tar $(H_FILES))
	(compress /tmp/dist.tar)

#qd.tar.Z: $(QUICKFILES)
qd.tar.Z:
	tar -cvf /tmp/$$USER/qd.tar $(RWHO_FILES)
	(cd src; tar -uvf /tmp/$$USER/qd.tar $(C_FILES) $(EXTRA_CFILES))
	(cd hdrs; tar -uvf /tmp/$$USER/qd.tar $(H_FILES))

# 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 flags.h attrib.h externs.h
attrib.o: oldattrib.h interface.h options.h dbdefs.h
boolexp.o: copyright.h db.h flags.h attrib.h config.h version.h match.h
boolexp.o: interface.h externs.h options.h dbdefs.h
bsd.o: copyright.h config.h version.h db.h flags.h attrib.h interface.h
bsd.o: globals.h help.h externs.h options.h dbdefs.h
chat.o: config.h copyright.h version.h options.h
compress.o: copyright.h config.h version.h db.h flags.h attrib.h bigrams.h
compress.o: options.h dbdefs.h
conf.o: config.h copyright.h version.h interface.h db.h flags.h attrib.h
conf.o: options.h dbdefs.h
cque.o: config.h copyright.h version.h db.h flags.h attrib.h interface.h
cque.o: externs.h match.h options.h dbdefs.h
create.o: config.h copyright.h version.h db.h flags.h attrib.h interface.h
create.o: externs.h options.h dbdefs.h
db.o: copyright.h config.h version.h interface.h db.h flags.h attrib.h
db.o: externs.h options.h dbdefs.h
destroy.o: copyright.h config.h version.h db.h flags.h attrib.h externs.h
destroy.o: globals.h options.h dbdefs.h
dump.o: copyright.h config.h version.h db.h flags.h attrib.h options.h dbdefs.h
eval.o: copyright.h config.h version.h db.h flags.h attrib.h interface.h
eval.o: globals.h externs.h options.h dbdefs.h
extract.o: copyright.h config.h version.h db.h flags.h attrib.h options.h
extract.o: dbdefs.h
flags.o: copyright.h attrib.h flags.h config.h dbdefs.h db.h externs.h
flags.o: options.h version.h interface.h
game.o: config.h copyright.h version.h db.h flags.h attrib.h game.h externs.h
game.o: interface.h match.h globals.h options.h dbdefs.h
gmalloc.o: getpagesize.h 
interface.o: config.h copyright.h version.h bsd.c db.h flags.h attrib.h
interface.o: externs.h globals.h interface.h options.h dbdefs.h
log.o: config.h copyright.h version.h externs.h db.h flags.h attrib.h
log.o: interface.h options.h dbdefs.h
look.o: copyright.h config.h version.h db.h flags.h attrib.h interface.h 
look.o: externs.h ansi.h match.h options.h dbdefs.h
mail.o: config.h copyright.h version.h db.h flags.h attrib.h interface.h
mail.o: options.h dbdefs.h
match.o: copyright.h config.h version.h db.h flags.h attrib.h externs.h
match.o: match.h globals.h options.h dbdefs.h
mem_check.o: config.h copyright.h version.h options.h
mkindx.o: help.h
move.o: copyright.h config.h version.h db.h flags.h attrib.h interface.h
move.o: externs.h globals.h match.h options.h dbdefs.h
player.o: copyright.h config.h version.h db.h flags.h attrib.h interface.h
player.o: externs.h options.h dbdefs.h
player_list.o: copyright.h config.h version.h db.h flags.h attrib.h
player_list.o: globals.h externs.h interface.h options.h dbdefs.h
predicates.o: copyright.h config.h version.h externs.h db.h flags.h attrib.h 
predicates.o: interface.h globals.h ansi.h options.h dbdefs.h
rob.o: copyright.h config.h version.h db.h flags.h attrib.h interface.h
rob.o: externs.h match.h options.h
set.o: copyright.h config.h version.h db.h flags.h attrib.h match.h dbdefs.h
set.o: externs.h interface.h options.h
speech.o: copyright.h config.h version.h externs.h db.h flags.h attrib.h
speech.o: interface.h match.h options.h dbdefs.h
stringutil.o: copyright.h config.h version.h interface.h db.h flags.h attrib.h
stringutil.o: globals.h options.h dbdefs.h
timer.o: copyright.h config.h version.h db.h flags.h attrib.h interface.h
timer.o: externs.h match.h options.h dbdefs.h
unparse.o: config.h copyright.h version.h db.h flags.h attrib.h externs.h
unparse.o: interface.h options.h dbdefs.h
utils.o: copyright.h config.h version.h interface.h db.h flags.h attrib.h
utils.o: options.h dbdefs.h
wild.o: config.h copyright.h version.h interface.h db.h flags.h attrib.h
wild.o: globals.h options.h dbdefs.h
wiz.o: copyright.h config.h version.h db.h flags.h attrib.h interface.h match.h
wiz.o: externs.h options.h dbdefs.h
