# This line is needed on some machines.
MAKE=make
#
# Uncomment the next line if you are on a NeXT machine
#NEXT=-DNeXT -bsd 
#
# Choose one of the following for your lexical analyzer
#
# This one is the old one that uses the C preprocessor.  uses .i files
#
#LEXICAL=lexical
#
# This one is faster, but can't handle complex #if's
#
LEXICAL=lex
#
# Chose one of these mallocs. 
# This malloc is based on Lars', but faster.  It was written by
# Satoria, of Darker Realms
#
MALLOC=smalloc
#
# Gnu malloc, fastest but uses most memory.
#
#MALLOC=gmalloc
#
# Boehm-Demers Garbage Collecting malloc package.
#
#MALLOC=gcmalloc
#
# Lars special malloc for LPmud. Uses least memory, but has an inefficient
# recombination scheme that may slow down the game after long uptimes.
#
#MALLOC=malloc
#
# Use this "malloc" package if you are on a NeXT, or want to use the
# system malloc.  sysmalloc.c is an empty file.
#
#MALLOC=sysmalloc
#
# Set MUD_LIB to the directory which contains the mud data. 
#
MUD_LIB = /worf/lpmud/mudlib
#
# Set BINDIR to the directory where you want to install the executables.
#
BINDIR = /worf/lpmud
#
# Define what random number generator to use.
# If no one is specified, a guaranteed bad one will be used.
# RANDOM (to use the random() system call) and DRAND48 (to use
# the drand48() system call) are available.  For a NeXT, use
# RANDOM.  If in doubt, do a 'man random' or a 'man drand48'
# and see which is defined.
# 
RAND=DRAND48
#
# Flags to yacc.  probably don't need to be changed, but if you use 
# bison, then take out the -d.
#
YFLAGS=-d
#
# Profiling information
#
PROFIL=
#PROFIL=-p -DMARK
#PROFIL=-pg
#
# Enable warnings from the compiler, if wanted.
#
WARN=
#WARN= -Wall -Wshadow -Dlint
#
#  This is used for debugging, and unless you are trying to 
#  debug code, don't define this. (It prints a trace of every
#  instruction, so it's not feasible to have this to play the
#  game with).
#
TRACE=
#TRACE=-DTRACE_CODE
#
# Enable run time debugging. It will use more time and space.
# When the flag is changed, be sure to recompile everything.
# Simple comment out this line if not wanted.
#
DEBUG=
#DEBUG=-DDEBUG
#
# These are the compiler flags.  The first is for cc, the second
# is for gcc.
#
#FLAGS=-g
FLAGS=-O -g -fstrength-reduce 
#
# Any extra compiler flags you wish to declare, put here.
#
#EXTRA=-DPORTNO=3000
#
MPATH=-DMUD_LIB='"$(MUD_LIB)"' 
#
# If you don't have 'strchr', then add next flag to CFLAGS.
# -Dstrchr=index -Dstrrchr=rindex
#
# The BUG_FREE is for the stralloc package, and assumes that the
# hashing functions are bug free.   -DSLOW_STATISTICS is for smalloc.c,
# and should be taken out if you don't want the debugging information that
# it provides.
#
CFLAGS= $(FLAGS) -D$(RAND) -DMALLOC_$(MALLOC) $(WARN) $(TRACE) $(PROFIL) $(DEBUG) $(MPATH) -DLEX_$(LEXICAL) -DBINDIR='"$(BINDIR)"' -DBUG_FREE $(EXTRA) $(NEXT) -DSLOW_STATISTICS
#
# Your compiler.  Use gcc if you have it, cc if you don't.
#
CC=gcc
#CC=cc
#
# Add extra libraries here.
#
LIBS= -lm
MFLAGS = "BINDIR = $(BINDIR)" "MUD_LIB = $(MUD_LIB)" "MUDDIR = $(MUDDIR)"
#
# Add str.c here if you don't have memcpy() or strtol()
# Uncomment the alloca.c if your system does not have alloca
#
SRC=$(LEXICAL).c main.c interpret.c simulate.c object.c backend.c\
    comm1.c ed.c regexp.c wiz_list.c swap.c $(MALLOC).c call_out.c array.c \
    parse.c otable.c dumpstat.c stralloc.c hash.c indentp.c port.c \
    text.c memused.c vpopen.c access_check.c clilib.c mapping.c \
    prelang.y postlang.y simul_efun.c bellow.c alloca.c
#
# Add str.o here if you don't have memcpy() or strtol()
# Uncomment the alloca.o if your system does not have alloca
#
OBJ=lang.o $(LEXICAL).o main.o interpret.o simulate.o object.o backend.o\
    comm1.o ed.o regexp.o wiz_list.o swap.o $(MALLOC).o call_out.o array.o \
    parse.o otable.o dumpstat.o stralloc.o hash.o indentp.o port.o bellow.o \
    text.o memused.o vpopen.o access_check.o clilib.o simul_efun.o alloca.o \
    mapping.o

driver: $(OBJ) make_func 
	$(CC) $(CFLAGS) $(OBJ) -o driver $(LIBS)

all:	driver utils 

list_funcs:
	@$(CC) -E $(CFLAGS) func_spec.c

make_func.c: make_func.y
	yacc make_func.y
	mv y.tab.c make_func.c

make_func: make_func.o
	$(CC) make_func.o -o make_func

make_func.o: config.h

install: driver 
	install -c $? $(BINDIR)/parse

install.utils:
	(cd util; $(MAKE) $(MFLAGS) install)

utils:	
	(cd util; $(MAKE) $(MFLAGS))

parse: driver
	-mv parse parse.old
	cp driver parse

LPmud.doc: LPmud.doc.me		# Does also depend on lfun_efun.me
	nroff -me LPmud.doc.me > LPmud.doc

lfun_efun.me:: make_docs

lfun_efun.me::
	make_docs lfun_efun.me

make_docs: make_docs.o
	$(CC) make_docs.o -o make_docs

lint: *.c
	lint *.c

gcmalloc.o:
	cd gc; make "CFLAGS=-g -DLPMUD" gc.a
	rm -f gcmalloc.o
	ln -s gc/gc.a gcmalloc.o

call_out.o: object.h interpret.h

swap.o: swap.c object.h config.h interpret.h exec.h

lang.o: lang.c config.h object.h interpret.h exec.h instrs.h switch.h

lang.c lang.h: lang.y
	yacc -d lang.y
	mv y.tab.c lang.c
	mv y.tab.h lang.h

lexical.o: lexical.c config.h

lexical.c: lexical.l

interpret.o: interpret.h config.h object.h instrs.h exec.h patchlevel.h\
	switch.h lang.h

simulate.o: interpret.h object.h config.h sent.h wiz_list.h exec.h lang.h

wiz_list.o: wiz_list.h interpret.h

main.o: config.h object.h interpret.h lex.h

clean:
	-rm -f *.o lang.h lang.c lexical.c mon.out *.ln tags
	-rm -f parse driver core frontend mudlib/core TAGS 
	-rm -f config.status lpmud.log
	(cd util ; echo "Cleaning in util." ; $(MAKE) clean)

frontend: comm2.o frontend.o
	$(CC) $(CFLAGS) comm2.o frontend.o -o frontend $(LIBS)

tags: $(SRC)
	ctags $(SRC)

TAGS: $(SRC)
	etags $(SRC)

count_active: count_active.o
	$(CC) count_active.o -o count_active

object.o: interpret.h object.h sent.h config.h wiz_list.h exec.h

backend.o: object.h config.h interpret.h wiz_list.h exec.h

comm1.o: comm.h sent.h interpret.h object.h config.h mudwho.h patchlevel.h

clilib.o: config.h

comm2.o: config.h comm.h

frontend.o: frontend.c config.h comm.h

ed.o: regexp.h object.h config.h interpret.h exec.h

regexp.o: regexp.h

otable.o: config.h object.h interpret.h

dumpstat.o: object.h interpret.h exec.h

parse_old.o: interpret.h config.h object.h wiz_list.h

parse.o: interpret.h config.h object.h wiz_list.h

stralloc.o: config.h

lex.o: config.h instrs.h interpret.h exec.h efun_defs.c lang.h lex.h

array.o: interpret.h object.h config.h wiz_list.h regexp.h exec.h

bellow.o: interpret.h lint.h

access_check.o: config.h

lang.y efun_defs.c: func_spec.c make_func prelang.y postlang.y config.h
	./make_func > efun_defs.c

simul_efun.o: interpret.h object.h exec.h