EM = ../../../..
CEG = $(EM)/lib/ceg

Em   = $(CEG)/EM_parser/obj_EM_pars
ASMAIN = $(CEG)/assemble/obj_assemble
AS   = $(CEG)/as_parser
EVAL = $(CEG)/as_parser/eval
DEF = $(CEG)/defaults

CC = cc
CFLAGS = -O
AR = ar
LEXLIB = -ll

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

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 $(CFLAGS) $(IFILES) ../$*.c)

all:    back ceg ce
	make -f ce_makefile ce.a

install:	all
	../../install ce.a
	../../install back.a

clean:
	rm -rf ce ceg ce.a back.a Out 

dclean:
	rm -rf ce ceg Out

ce : ceg/ceg EM_table mach.h
	-mkdir ce
	( cd ce; ../ceg/ceg -l < $(DEF)/not_impl/not_impl_table)
	(cd ce;cp $(DEF)/*.c .)
	(cd ce;cp $(DEF)/*/*.c .)
	-ln mach.c ce/mach.c
	@make -f ce_makefile EM_instr

ceg : 
	-mkdir ceg
	(cd ceg; cp $(ASMAIN)/* .) 
	(cd ceg;$(CC) -c $(IFILES) *.c; $(AR) r as_lib.a *.o )
	-(cd ceg; ranlib as_lib.a)


ce.a : ce/*.o
	$(AR) r ce.a ce/*.o
	-ranlib ce.a

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

EM_instr : ceg/ceg EM_table mach.h
	( cd ce; $(EM)/lib/cpp -P ../EM_table| ../ceg/ceg -l)
	( cd ce; $(CEG)/util/create_ofiles)
	@make -f ce_makefile ce.a




ceg/ceg	: ceg/assemble.o ceg/as_instr.o ceg/eval_as.o # $(Em)/em_parser 
	(cd ceg ; $(CC) -o ceg $(Em)/*.o assemble.o as_instr.o eval_as.o as_lib.a\
			 $(CEG_LIBS) $(LEXLIB) )

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
	(cd ceg ; $(EM)/lib/cpp -P ../as_table| $(AS)/as_parser > 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
	( cd ceg ; $(EVAL)/eval < ../as.c > eval_as.c )
