# This line is needed on some machines. 
MAKE=make

SRC=lex.c main.c interpret.c simulate.c object.c backend.c array.c\
    comm1.c ed.c regexp.c swap.c $(MALLOC).c\
    call_out.c otable.c dumpstat.c stralloc.c hash.c indentp.c port.c\
    parse.c simul_efun.c mapping.c sprintf.c mudstat.c \
    debug.c binaries.c super_snoop.c interface.c ualarm.c signals.c

CSRC=${SRC} lang.c

HEADERS = config.h comm.h exec.h getpagesize.h incralloc.h instrs.h interpret.h \
    master.h mapping.h mudstat.h object.h patchlevel.h regexp.h sent.h switch.h\
    interface.h master.t
#
# Add str.o here if you don't have memcpy() or strtol().
# Add alloca.o if you don't have alloca() on your machine.
#
OBJ=lang.o lex.o main.o interpret.o simulate.o object.o backend.o array.o\
    comm1.o ed.o regexp.o swap.o $(MALLOC).o\
    call_out.o otable.o dumpstat.o stralloc.o hash.o indentp.o port.o\
    parse.o simul_efun.o mapping.o sprintf.o mudstat.o \
    debug.o binaries.o super_snoop.o interface.o ualarm.o signals.o

MPATH=-DMUD_LIB=\"$(MUD_LIB)\"
BINPATH=-DBINDIR=\"$(BINDIR)\"

.c.o:
	$(CC) $(CFLAGS) $(MPATH) $(BINPATH) -o $@ -c $<

driver: $(OBJ) ${IOBJ}
	-mv driver driver.old
	$(CC) $(CFLAGS) $(OBJ) ${IOBJ} -o driver $(LIBS)

func_spec.i: func_spec.c
	$(CC) -E $(CFLAGS) func_spec.c > func_spec.i

master.t master.h: master.n genfkntab
	genfkntab m master <master.n

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_table: make_table.o
	$(CC) make_table.o -o make_table

efun_table.h: lang.h make_table
	./make_table lang.h efun_table.h

lang.y efun_defs.c: func_spec.i make_func prelang.y postlang.y config.h
	./make_func > tmp_efun_defs
	sed -e "s/,,/,T_STRING|T_NUMBER|T_POINTER|T_OBJECT|T_MAPPING|T_FLOAT,/" tmp_efun_defs > efun_defs.c
	rm tmp_efun_defs

lint: *.c
	lint *.c

lang.c lang.h: lang.y
	$(YACC) -d lang.y
	mv y.tab.c lang.c
	mv y.tab.h lang.h

clean:
	-rm -f *.o lang.h lang.c lexical.c mon.out *.ln tags
	-rm -f parse core TAGS 
	-rm -f config.status lpmud.log
	-rm -f clib/*.o
	-rm -f driver driver.old
	-rm -f efun_defs.c efun_table.h
	-rm -f lang.y
	-rm -f make_func make_func.c make_table func_spec.i
	-rm -f master.t
	(cd util ; echo "Cleaning in util." ; $(MAKE) clean)

tags: $(SRC)
	ctags prelang.y postlang.y $(SRC)

TAGS: $(SRC) $(HEADERS)
	etags -t prelang.y postlang.y $(SRC) $(HEADERS)

depend: $(CSRC) ${ISRC} make_func.c
	sed '/^# DO NOT DELETE THIS LINE/q' Makefile.distrib > makefile.tmp
	gcc -MM ${CSRC} ${ISRC} make_func.c >> makefile.tmp
	mv makefile.tmp Makefile.distrib
# DO NOT DELETE THIS LINE -- make depend depends on it.
lex.o : lex.c config.h instrs.h lint.h master.h lang.h interpret.h exec.h \
	lex.h mudstat.h efun_defs.c 
main.o : main.c config.h lint.h master.h interpret.h object.h lex.h exec.h 
interpret.o : interpret.c config.h lint.h master.h lang.h exec.h interpret.h \
	object.h instrs.h patchlevel.h comm.h switch.h mapping.h mudstat.h \
	lex.h efun_table.h master.t 
simulate.o : simulate.c config.h lint.h master.h interpret.h object.h sent.h \
	exec.h comm.h mudstat.h incralloc.h 
object.o : object.c config.h lint.h master.h interpret.h object.h sent.h \
	exec.h mapping.h mudstat.h 
backend.o : backend.c config.h lint.h master.h interpret.h object.h exec.h \
	comm.h mudstat.h 
array.o : array.c config.h lint.h master.h interpret.h object.h regexp.h \
	mapping.h exec.h 
comm1.o : comm1.c config.h lint.h master.h interpret.h comm.h object.h sent.h \
	patchlevel.h 
ed.o : ed.c config.h lint.h master.h regexp.h interpret.h object.h exec.h \
	comm.h 
regexp.o : regexp.c config.h regexp.h lint.h master.h 
swap.o : swap.c config.h lint.h master.h interpret.h object.h exec.h \
	mudstat.h mapping.h 
bibopmalloc.o : bibopmalloc.c config.h 
call_out.o : call_out.c config.h lint.h master.h interpret.h exec.h object.h \
	mudstat.h 
otable.o : otable.c config.h lint.h master.h interpret.h object.h 
dumpstat.o : dumpstat.c config.h lint.h master.h interpret.h object.h exec.h 
stralloc.o : stralloc.c config.h lint.h master.h 
hash.o : hash.c 
indentp.o : indentp.c 
port.o : port.c config.h lint.h master.h 
parse.o : parse.c config.h lint.h master.h interpret.h object.h exec.h 
simul_efun.o : simul_efun.c config.h lint.h master.h interpret.h object.h \
	exec.h 
mapping.o : mapping.c config.h lint.h master.h exec.h interpret.h object.h \
	instrs.h patchlevel.h comm.h switch.h mapping.h 
sprintf.o : sprintf.c config.h lint.h master.h interpret.h mapping.h object.h \
	sent.h 
mudstat.o : mudstat.c config.h lint.h master.h mudstat.h 
debug.o : debug.c config.h lint.h master.h exec.h interpret.h object.h \
	instrs.h patchlevel.h comm.h switch.h mapping.h mudstat.h 
binaries.o : binaries.c config.h patchlevel.h lint.h master.h interpret.h \
	object.h exec.h 
super_snoop.o : super_snoop.c 
interface.o : interface.c interface.h config.h exec.h interpret.h 
ualarm.o : ualarm.c 
lang.o : lang.c config.h lint.h master.h interface.h exec.h interpret.h \
	object.h instrs.h incralloc.h switch.h 
efun.o : clib/efun.c clib/../lint.h clib/../master.h clib/../interface.h \
	clib/../config.h clib/../exec.h clib/../interpret.h clib/../object.h 
make_func.o : make_func.c config.h lint.h master.h