LIB_ENGINE_PL = @LIB_ENGINE_PL@
GPLC          = @GPLC@
RANLIB        = @RANLIB@
CC            = @CC@
CFLAGS        = @CFLAGS@
EXEEXT        = @EXEEXT@

LIBNAME = $(LIB_ENGINE_PL)
OBJLIB  = machine.o mem_alloc.o misc.o hash.o main.o obj_chain.o \
          engine.o engine1.o wam_inst.o atom.o pred.o oper.o if_no_fd.o

all: sys_conf.h obj_begin.o obj_end.o $(LIBNAME)


$(LIBNAME): $(OBJLIB)
	rm -f $(LIBNAME) 
	ar rc $(LIBNAME) $(OBJLIB)
	$(RANLIB) $(LIBNAME)


.c.o:
	$(GPLC) -c -C '$(CFLAGS)' $*.c



# Configuration

config: pl_config$(EXEEXT) sys_conf.h

pl_config$(EXEEXT): pl_config.c config.h machine.h wam_archi.def
	$(CC) $(CFLAGS) $(LFLAGS) -o pl_config$(EXEEXT) pl_config.c


sys_conf.h: pl_config$(EXEEXT) machine.h wam_archi.def 
	./pl_config$(EXEEXT)
	(cd ../TopComp; $(MAKE) $(GPLC)$(EXEEXT))


config.h:
	echo '*** run ./configure before make please ***'
	exit 1



# General core


machine.o: machine.h machine.c config.h sys_conf.h 

mem_alloc.o: mem_alloc.h mem_alloc.c

misc.o: misc.h misc.c machine.h 

hash.o: hash.h hash.c

main.o: main.c

obj_chain.o: obj_chain.h obj_chain.c

obj_begin.o: obj_chain.h obj_begin.c

obj_end.o: obj_chain.h obj_end.c



# Prolog engine


engine.o: engine.h engine.c 

                                          # warning: no C optim for engine1.c
engine1.o: engine1.c 
	$(GPLC) -c engine1.c

wam_inst.o: wam_archi.h wam_inst.h wam_inst.c unify.c

atom.o: atom.h atom.c config.h

pred.o: pred.h pred.c

oper.o: oper.h oper.c

if_no_fd.o: if_no_fd.h if_no_fd.c


clean:
	rm -f pl_config$(EXEEXT) *.o $(LIBNAME)

 
distclean: clean
	rm -f wam_archi.h config.h
