# Makefile for TinyMUSH 2.2
#
# Search for the text 'CONFIGURATION SECTION' and make any changes needed
# there.

SHELL=/bin/sh
srcdir = @srcdir@
VPATH = @srcdir@
CC = @CC@
CPP = @CPP@
LIBS = @LIBS@
LIBOBJS = @LIBOBJS@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@

# UnterMUD database layer.
UDBA_SRC = $(srcdir)/udb_acache.c $(srcdir)/udb_achunk.c $(srcdir)/udb_attr.c
UDBA_OBJ = udb_acache.o udb_achunk.o udb_attr.o
UDBA_FLG = -DCACHE_ATTRS

UDBO_SRC = $(srcdir)/udb_ocache.c $(srcdir)/udb_ochunk.c $(srcdir)/udb_obj.c
UDBO_OBJ = udb_ocache.o udb_ochunk.o udb_obj.o
UDBO_FLG = -DCACHE_OBJS

UDB_SRC = $(srcdir)/udb_misc.c
UDB_OBJ = udb_misc.o
UDB_INC	= $(srcdir)/udb.h $(srcdir)/udb_defs.h

# Everything needed to use the database in standalone mode.
SA_OBJ	= sa-boolexp.o sa-conf.o sa-db.o sa-db_rw.o \
	  sa-flags.o sa-htab.o sa-log.o sa-object.o sa-player_c.o \
	  sa-predicates.o sa-stringutil.o sa-unparse.o sa-vattr.o

# Distribution source files
D_SRC	= $(srcdir)/alloc.c $(srcdir)/boolexp.c $(srcdir)/bsd.c \
	  $(srcdir)/command.c $(srcdir)/compat.c $(srcdir)/conf.c \
	  $(srcdir)/cque.c $(srcdir)/create.c $(srcdir)/db.c \
	  $(srcdir)/db_rw.c $(srcdir)/eval.c $(srcdir)/file_c.c \
	  $(srcdir)/flags.c $(srcdir)/functions.c $(srcdir)/game.c \
	  $(srcdir)/help.c $(srcdir)/htab.c $(srcdir)/log.c $(srcdir)/look.c \
	  $(srcdir)/match.c $(srcdir)/move.c $(srcdir)/netcommon.c \
	  $(srcdir)/object.c $(srcdir)/player.c $(srcdir)/player_c.c \
	  $(srcdir)/predicates.c $(srcdir)/quota.c $(srcdir)/rob.c \
	  $(srcdir)/set.c $(srcdir)/speech.c $(srcdir)/stringutil.c \
	  $(srcdir)/timer.c $(srcdir)/unparse.c $(srcdir)/vattr.c \
	  $(srcdir)/walkdb.c $(srcdir)/wild.c $(srcdir)/wiz.c 
D_OBJ	= alloc.o boolexp.o bsd.o command.o compat.o conf.o \
	  cque.o create.o db.o db_rw.o eval.o file_c.o flags.o \
	  functions.o game.o help.o htab.o log.o look.o match.o move.o \
	  netcommon.o object.o player.o player_c.o predicates.o quota.o \
	  rob.o set.o speech.o stringutil.o timer.o unparse.o vattr.o \
	  walkdb.o wild.o wiz.o 
D_INC	= $(srcdir)/alloc.h $(srcdir)/attrs.h $(srcdir)/command.h \
	  $(srcdir)/config.h $(srcdir)/copyright.h $(srcdir)/mushdb.h \
	  $(srcdir)/externs.h $(srcdir)/fifo.h $(srcdir)/file_c.h \
	  $(srcdir)/flags.h $(srcdir)/functions.h $(srcdir)/help.h \
	  $(srcdir)/htab.h $(srcdir)/interface.h $(srcdir)/match.h \
	  $(srcdir)/misc.h $(srcdir)/mudconf.h $(srcdir)/rwho_clilib.h \
	  $(srcdir)/vattr.h

# RWHO source files
WHO_SRC	= $(srcdir)/rwho_clilib.c
WHO_OBJ	= rwho_clilib.o
WHO_FLG	= -DRWHO_IN_USE
RWHO_FL	= -DLOCAL_RWHO_SERVER

# Version number routine
VER_SRC	= $(srcdir)/version.c
VER_OBJ	= version.o
VER_INC	= $(srcdir)/patchlevel.h
VER_FLG	= -DMUSH_BUILD_DATE="\"`date`\"" \
	  -DMUSH_BUILD_NUM="\"`sh ./buildnum.sh`\""

# ===================== CONFIGURATION SECTION ====================
#
# Select the correct C compiler.  Whatever you choose, it must be able
# to grok ANSI C (function prototypes)
#
#-----CC or GCC (must be able to grok function prototypes)
#
DEFS = -I. -I@srcdir@
#
#-----GCC if the libraries were built for a pcc-derived cc compiler
#     (most systems)
#
#DEFS = -fpcc-struct-return -Wall -I. -I@srcdir@
#
#-----GCC with GCC-compatible libraries if you want verbose error messages
#
#DEFS = -Wall -I. -I@srcdir@
#
#-----HP-UX C compiler
#
#DEFS = -w +Obb800 -Aa -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_HPUX_SOURCE -D_INCLUDE_XOPEN_SOURCE -I. -I@srcdir@
#
#-----MIPS C compiler (also DEC 3xxx, Prime EXL7xxx)
#
#DEFS = -signed -I. -I@srcdir@

# Libraries.
# Use the second line if you're running on a SysV-ish system and BSD
# support isn't built in to the standard libc.
#
#MORELIBS	= -L/usr/ucblib -lucb	# Mips

# Set this to the directory where the MUSH game lives.
GAME	= /tmp

# If you want to be able to transmit RWHO data, uncomment these lines:
WHO_S	= $(WHO_SRC)
WHO_O	= $(WHO_OBJ)
WHO_F	= $(WHO_FLG)

# If you want to allow the local RWHO command (only recommended if you are on
# the same machine or subnet as the RWHO server), uncomment these lines:
#RWHO_F	= $(RWHO_FL)

# You might want to change the size of the attribute hash table.
# Recommended: 8192, 16384, 32768, or 65536. See the README for details.
#VSIZE_F = -DVHASH_SIZE=16384

# Select the level at which you want cacheing to be performed.  Prior releases
# of MUSH only supported attribute-level cacheing.
# 
# ----- Attribute-level cacheing.
#UDB_S	= $(UDBA_SRC) $(UDB_SRC)
#UDB_O	= $(UDBA_OBJ) $(UDB_OBJ)
#UDB_F	= $(UDBA_FLG) $(VSIZE_F)

# ----- Object-level cacheing.
UDB_S	= $(UDBO_SRC) $(UDB_SRC)
UDB_O	= $(UDBO_OBJ) $(UDB_OBJ)
UDB_F	= $(UDBO_FLG) $(VSIZE_F)

# Select the networking support you have.  Currently only BSD networking
# is supported.
#
# ----- BSD networking
NET_S	= $(srcdir)/bsd.c
NET_O	= bsd.o

# Look at the very bottom if you have an old make that doesn't understand
# pattern rules.  There's a few lines that need to be commented out and
# one other that needs to be added.

# ================== END OF CONFIGURATION SECTION =================

# Auxiliary source files: only used by offline utilities.
AUX_SRC	= $(srcdir)/dbconvert.c $(srcdir)/mkindx.c $(srcdir)/unsplit.c
LIB_SRC = $(srcdir)/myndbm.c
LIB_INC = $(srcdir)/myndbm.h

DEBUG	= $(OPTIM)
ALLCFLAGS = $(CFLAGS) $(DEBUG) $(DEFS) $(WHO_F) $(RWHO_F) $(RLIM_F) $(UDB_F)

#Auxiliary files
A_INST	= README NOTES HIGHLIGHTS-2.0 NOTES-2.0 \
	  CREDITS CHANGES README-2.0 CHANGES-2.0 \
	  COMPRESSION TOOLS
A_TXT	= text/badsite.txt text/connect.txt text/htmlconn.txt \
	  text/create_reg.txt text/down.txt \
	  text/guest.txt text/help.txt \
	  text/motd.txt text/news.txt \
	  text/newuser.txt text/quit.txt \
	  text/register.txt text/wizhelp.txt \
	  text/wizmotd.txt text/full.txt
A_SH	= scripts/db_load scripts/db_unload \
	  scripts/db_check ./buildnum.sh
A_RT	= scripts/Startmush scripts/Backup scripts/mush.config
A_CONF	= conf/netmush.conf conf/alias.conf \
	  conf/compat.conf
A_MISC	= ./buildnum.data ./TAGS tools radixlib
A_VMS	= $(srcdir)/vms_dbm.c $(srcdir)/vms_dbm.h \
	  vms/startmush.com vms/compile.com \
	  vms/link.com 
A_AUTO	= ./configure ./configure.in \
	  $(srcdir)/autoconf.h.in $(srcdir)/Makefile.in \
	  $(srcdir)/.depend
AUXIL	= $(A_INST) $(A_TXT) $(A_SH) $(A_CONF) $(A_MISC) $(A_RT) $(A_VMS) \
	  $(A_AUTO)

#Installation files
INSTALL_PROG	= netmush dbconvert mkindx scripts/db_load \
		  scripts/db_unload scripts/db_check
INSTALL_TARG	= $(INSTALL_PROG) text/*.txt conf/*.conf scripts/Startmush \
		  scripts/Backup scripts/mush.config
REINSTALL_TARG	= $(INSTALL_PROG) text/help.txt text/wizhelp.txt \
		  conf/alias.conf conf/compat.conf

#compiliation source files
ALLSRC	= $(D_SRC) $(UDB_SRC) $(UDBA_SRC) $(UDBO_SRC) $(VER_SRC) \
	  $(WHO_SRC) $(AUX_SRC) $(LIB_SRC)
ALLINC	= $(D_INC) $(UDB_INC) $(VER_INC) $(NET_INC) $(LIB_INC)
SRC	= $(D_SRC) $(UDB_S) $(WHO_S)
OBJ	= $(D_OBJ) $(UDB_O) $(WHO_O)

# Files in the standard distribution
DIST	= $(ALLSRC) $(ALLINC) $(AUXIL)

OUT	= netmush mkindx dbconvert

all: $(OUT) TAGS

new-install: $(INSTALL_TARG)
	-mkdir $(GAME)
	cp $(INSTALL_TARG) $(GAME)

install: $(REINSTALL_TARG)
	cp $(REINSTALL_TARG) $(GAME)

TAGS: $(srcdir)/*.c $(srcdir)/*.h
	-etags -o ./TAGS *.h $(srcdir)/*.c $(srcdir)/*.h

mkindx: mkindx.o
	$(CC) $(ALLCFLAGS) -o mkindx mkindx.o

unsplit: unsplit.o
	$(CC) $(ALLCFLAGS) -o unsplit unsplit.o

dbconvert: dbconvert.o $(SA_OBJ) $(UDB_O) $(ALLOC_O)$(LIBOBJS)
	$(CC) $(ALLCFLAGS) -o dbconvert dbconvert.o $(SA_OBJ) $(UDB_O) \
	$(ALLOC_O) $(LIBS) $(MORELIBS) $(LIBOBJS)

saber:	$(SRC)
	#load $(SRC)

saber-o: $(OBJ) $(LIBOBJS)
	#load $(OBJ) $(VER_OBJ) $(LIBS) $(MORELIBS)

$(VER_OBJ):
	$(CC) $(ALLCFLAGS) $(VER_FLG) -c $(VER_SRC)

netmush: $(OBJ) $(LIBOBJS) $(VER_OBJ)
	-rm -f netmush
	$(CC) $(ALLCFLAGS) -o netmush $(OBJ) $(LIBOBJS) $(VER_OBJ) \
	$(LIBS) $(MORELIBS)

dist.tar.Z: $(DIST)
	-rm -f buildnum.data
	echo 0 > buildnum.data
	tar cvhf -  `echo $(DIST) | sed 's/\.\.\///g'` | compress -c > dist.tar.Z.NEW
	mv dist.tar.Z.NEW dist.tar.Z

dist.tar.gz: $(DIST)
	-rm -f buildnum.data
	echo 0 > buildnum.data
	tar cvhf - `echo $(DIST) | sed 's/\.\.\///g'` | gzip -c > dist.tar.gz.NEW
	mv dist.tar.gz.NEW dist.tar.gz

depend: $(ALLSRC) unsplit
	for i in $(ALLSRC); do $(CPP) $(ALLCFLAGS) -M $$i; \
	done | sed -e 's:/usr[^ ]* ::g' | \
	unsplit > $(srcdir)/.depend~
	mv $(srcdir)/.depend~ $(srcdir)/.depend

index: help.indx news.indx wizhelp.indx

help.indx: help.txt
	./mkindx help.txt help.indx

news.indx: news.txt
	./mkindx news.txt news.indx

wizhelp.indx: wizhelp.txt
	./mkindx wizhelp.txt wizhelp.indx

verify:
	runtest --tool mush --src ./testsuite

realclean:
	-rm -f *.o a.out core gmon.out mush.*log mush.*sum $(OUT) \
	unsplit config.log config.cache patrules

clean:
	-rm -f *.o a.out core gmon.out mush.*log mush.*sum $(OUT) config.log

patrules:
	for file in $(srcdir)/*.c ; \
	do \
	    echo $$file | sed -e 's,$(srcdir)/\(.*\)\.c,\1.o:	&,';\
	    echo $$file | sed -e 's,$(srcdir)/\(.*\)\.c,	$$(CC) $$(ALLCFLAGS) -c &,';\
	    echo $$file | sed -e 's,$(srcdir)/\(.*\)\.c,sa-\1.o:	&,';\
	    echo $$file | sed -e 's,$(srcdir)/\(.*\)\.c,	$$(CC) $$(ALLCFLAGS) -DSTANDALONE -c & -o sa-\1.o,';\
	done > patrules


# EXTRA CONFIGURATION STUFF HERE
#
# These are pattern rules for make targets.  They will only work properly
# if your make understands VPATH and pattern rules.
# If you have an old version of make, we recommend getting GNU make and
# using that (it's much nicer).  Failing that, comment out these lines:
#
.c.o:
	$(CC) $(ALLCFLAGS) -c $<

sa-%.o: %.c
	$(CC) $(ALLCFLAGS) -DSTANDALONE -c $< -o $@
#
# and either uncomment this line:
#

#include patrules

#
# Or, if your make doesn't understand "include", just textually include
# the file patrules into this file right here.

#
# This is the list of dependency rules.  If your make doesn't understand
# "include", you can just comment out the include and textually include
# it if you want.
# Just commenting out this line won't hurt anything for a virgin build,
# but may cause problems should you make any changes and recompile.
#
include $(srcdir)/.depend
