sima/autoconf/
sima/hosts/i386/
sima/mudlib/
sima/mudlib/kernel/
sima/mudlib/obj/
sima/mudlib/sys/
sima/synhash/mips/
MAKE=make
SHELL=/bin/sh
#
CC=gcc
#
YACC = byacc
YACCTAB = y.tab.
#
RM = rm -f
MV = mv
CP = cp

# -fforce-mem : it makes a mess of decrement instruction. We can do cse by hand.
# -finline-functions: it makes unnecessary register push or even makes register
#  allocation fail for important values. We explicitly name functions to be
#  inlined
#OPTIMIZE = -O4 -g -fstrength-reduce -fomit-frame-pointer # high optimization
#OPTIMIZE= -O4 -g -fstrength-reduce # for better debugging
#OPTIMIZE= -O4 -g # for better debugging
OPTIMIZE= -g -Wall -Wno-parentheses -b i486-linuxaout -static # no optimization; for frequent recompilations.
#ASOPT= -O4 -g -fomit-frame-pointer -fno-force-mem -fomit-default-branch \
	-b i486-linuxaout -fno-inline-functions -S
ASOPT= -O4 -g -fomit-frame-pointer -fno-force-mem \
	-b i486-linuxaout -S -DINLINE=inline --save-temps

CFLAGS=  $(OPTIMIZE) $(DEBUG) -DYYDEBUG=1
#
LIBS= -lm
#
LDFLAGS= -Wl,-qmagic

OBJ= interpret.o lex.o hash.o string.o alloc.o object.o uid.o file.o \
	array.o statistics.o main.o schedule.o swap.o port.o lang.o \
	comm.o access_check.o closure.o call_out.o gcollect.o compiler.o \
	stub.o mapping.o simul_efun.o sprintf.o

all: driver

interpret.o: interpret.c instrs.h interpret.h object.h uid.h exec.h alloc.h

instrs.h: make_func

make_func.c: make_func.y
	$(YACC) make_func.y
	$(MV) $(YACCTAB)c make_func.c


make_func: make_func.o hash.c
	$(CC) $(OPTIMIZE) $(LDFLAGS) -DMAKE_FUNC make_func.o hash.c -o make_func

make_func.o : make_func.c common.h config.h machine.h
	$(CC) $(CFLAGS) -DYACC='"$(YACC)"' -c make_func.c

lang.y efun_defs.c instrs.h: func_spec make_func prolang.y config.h
	$(RM) efun_defs.c
	$(RM) lang.y
	./make_func > efun_defs.c

lang.c lang.h: lang.y
	$(YACC) -d -v lang.y
	$(MV) $(YACCTAB)c lang.c
	$(MV) $(YACCTAB)h lang.h

lang.o: lang.c lex.h compiler.h
compiler.o: compiler.c compiler.h instrs.h

lex.o : lex.c common.h config.h machine.h alloc.h lang.h exec.h lex.h \
  instrs.h patchlevel.h efun_defs.c interpret.h

lang.s: lang.o
	$(CC) $(CFLAGS) -O4 -S lang.c

lex.s: lex.o
	$(CC) $(CFLAGS) -O4 -S lex.c

interpret.s: interpret.o
	$(CC) $(ASOPT) interpret.c

object.o: object.c common.h alloc.h object.h exec.h interpret.h \
	mudlib/sys/driver_hook.h uid.h schedule.h

object.s: object.o
	$(CC) $(CFLAGS) -O4 -fomit-frame-pointer -S object.c

schedule.o: schedule.c common.h object.h comm.h schedule.h

schedule.s: schedule.o
	$(CC) $(CFLAGS) -O4 -fomit-frame-pointer -S schedule.c

port.s: port.o
	$(CC) $(CFLAGS) -O4 -fomit-frame-pointer -S port.c

string.s: string.o
	$(CC) $(CFLAGS) -O4 -fomit-frame-pointer -S string.c

string.o: string.c common.h alloc.h

uid.o: uid.c alloc.h uid.h object.h

port.o: port.c common.h

closure.o: closure.c common.h alloc.h instrs.h object.h switch.h exec.h

closure.s: closure.o
	$(CC) $(ASOPT) closure.c

main.o: main.c common.h config.h

alloc.o: alloc.c common.h alloc.h object.h uid.h schedule.h config.h

alloc.s: alloc.o
	$(CC) $(ASOPT) alloc.c

statistics.o: statistics.c alloc.h

comm.o: comm.c common.h comm.h exec.h object.h interpret.h schedule.h

hash.o: hosts/i386/hash.S
	$(CC) $(CFLAGS) -c hosts/i386/hash.S

access_check.o: access_check.c config.h common.h comm.h

call_out.o: call_out.c common.h

mapping.o: alloc.h

driver: $(OBJ)
	$(CC) $(OPTIMIZE) $(LDFLAGS) $(OBJ) -o driver

clean:
	rm -f *.o *.s *.i lang.c lang.y lang.h y.output driver
	rm -f make_func make_func.c efun_defs.c instrs.h