EM = /proj/em/Work
CEG = /usr/star/kaashoek/em/ceg

Em   = $(CEG)/EM_parser
AS   = $(CEG)/as_parser
EVAL = $(CEG)/as_parser/eval
DEF = $(CEG)/defaults

CC = cc

IFILES  = -I. -I.. -I$(AS) -I$(Em) -I$(EM)/h -I$(EM)/modules/h

CEG_LIBS = $(EM)/modules/lib/liballoc.a\
	   $(EM)/modules/lib/libprint.a\
	   $(EM)/modules/lib/libstring.a\
	   $(EM)/modules/lib/libsystem.a

.c.o : mach.h back/*h ; ( cd ce; $(CC) -c -O $(IFILES) ../$*.c)


install : ceg ce
	make ce.a

ce : ceg/ceg
	mkdir ce
	( cd ce; ../ceg/ceg -l < $(DEF)/not_impl/not_impl_table)
	(cd ce;co $(DEF)/RCS/*.c,v )
	(cd ce;co $(DEF)/*/RCS/*.c,v)
	(cd ce;chmod +w *.c)
	ln mach.c ce/mach.c
	@make EM_instr

ceg : 
	mkdir ceg



ce.a : ce/*.o
	ar r ce.a ce/*.o
	ranlib ce.a

ce/*.o : mach.h
	(cd ce;$(CC) -c -O $(IFILES) ../$*.c)

EM_instr : ceg/ceg EM_table mach.h
	( cd ce; $(CEG)/util/preproc ../EM_table| ../ceg/ceg -l)
	( cd ce; $(CEG)/util/create_ofiles)
	@make ce.a




ceg/ceg	: $(Em)/em_parser ceg/assemble.o ceg/as_instr.o ceg/eval_as.o
	$(CC) -o ceg/ceg $(Em)/*.o ceg/assemble.o ceg/as_instr.o ceg/eval_as.o\
       			 $(CEG_LIBS) -ll

ceg/assemble.o : as.h ceg/assemble.c ceg/*h
	(cd ceg;$(CC) -c $(IFILES) assemble.c)

ceg/as_instr.o : as.h ceg/*h ceg/as_instr.c
	(cd ceg;$(CC) -c $(IFILES) as_instr.c)

ceg/as_instr.c : as_table $(AS)/as_parser
	$(CEG)/util/preproc  as_table| $(AS)/as_parser > ceg/as_instr.c

ceg/eval_as.o : ceg/eval_as.c as.h $(AS)/as_parser.h $(Em)/arg_type.h
	(cd ceg;$(CC) -c $(IFILES) eval_as.c)

ceg/eval_as.c : as.c $(EVAL)/eval
	$(EVAL)/eval < as.c > ceg/eval_as.c
