ROOT_DIR1     = @ROOT_DIR1@
LIB_ENGINE_PL = @LIB_ENGINE_PL@
GPLC          = @GPLC@
CC            = @CC@ @CFLAGS_MACHINE@
CFLAGS        = @CFLAGS@
AR_RC         = @AR_RC@
RANLIB        = @RANLIB@


LIBNAME = $(LIB_ENGINE_PL)
OBJLIB  = machine@OBJ_SUFFIX@ machine1@OBJ_SUFFIX@ stacks_sigsegv@OBJ_SUFFIX@ mem_alloc@OBJ_SUFFIX@ \
          misc@OBJ_SUFFIX@ hash_fct@OBJ_SUFFIX@ hash@OBJ_SUFFIX@ obj_chain@OBJ_SUFFIX@ \
          engine@OBJ_SUFFIX@ engine1@OBJ_SUFFIX@ wam_inst@OBJ_SUFFIX@ \
          atom@OBJ_SUFFIX@ pred@OBJ_SUFFIX@ oper@OBJ_SUFFIX@ \
          if_no_fd@OBJ_SUFFIX@ main@OBJ_SUFFIX@

all: config wam_regs.h cpp_headers@EXE_SUFFIX@ $(LIBNAME)


$(LIBNAME): $(OBJLIB)
	rm -f $(LIBNAME)
	$(AR_RC)@AR_SEP@$(LIBNAME) $(OBJLIB)
	$(RANLIB) $(LIBNAME)


.SUFFIXES:
.SUFFIXES: @OBJ_SUFFIX@ .c $(SUFFIXES)

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



# Configuration

config: pl_config@EXE_SUFFIX@ wam_regs.h

pl_config@EXE_SUFFIX@: pl_config.c gp_config.h machine.h stacks_sigsegv.h wam_archi.def
	$(CC) $(CFLAGS) $(LFLAGS) @CC_EXE_NAME_OPT@pl_config@EXE_SUFFIX@ pl_config.c


wam_regs.h: pl_config@EXE_SUFFIX@ machine.h stacks_sigsegv.h wam_archi.def
	./pl_config@EXE_SUFFIX@
	(cd ../TopComp; $(MAKE) $(GPLC)@EXE_SUFFIX@)


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


cpp_headers@EXE_SUFFIX@: cpp_headers.c
	$(CC) $(CFLAGS) $(LFLAGS) @CC_EXE_NAME_OPT@cpp_headers@EXE_SUFFIX@ cpp_headers.c

try_sigaction@EXE_SUFFIX@: try_sigaction.c
	$(CC) $(CFLAGS) $(LFLAGS) @CC_EXE_NAME_OPT@try_sigaction@EXE_SUFFIX@ try_sigaction.c



# General core


machine@OBJ_SUFFIX@: machine.h machine.c gp_config.h wam_regs.h

stacks_sigsegv@OBJ_SUFFIX@: stacks_sigsegv.h stacks_sigsegv.c gp_config.h wam_regs.h

mem_alloc@OBJ_SUFFIX@: mem_alloc.c

misc@OBJ_SUFFIX@: misc.h misc.c machine.h

hash@OBJ_SUFFIX@: hash.h hash.c

main@OBJ_SUFFIX@: main.c

obj_chain@OBJ_SUFFIX@: obj_chain.h obj_chain.c



# Prolog engine

# engine1.c should be compiled without optimizations (or else it is a .s)

engine1@OBJ_SUFFIX@: @MAKE_ENGINE1_SRC@
	$(GPLC) -c -o engine1@OBJ_SUFFIX@ @MAKE_ENGINE1_SRC@

engine@OBJ_SUFFIX@: engine.h engine.c

wam_inst@OBJ_SUFFIX@: wam_archi.h wam_inst.h wam_inst.c unify.c

hash_fct@OBJ_SUFFIX@: hash_fct.h hash_fct1.c

atom@OBJ_SUFFIX@: atom.h atom.c gp_config.h

pred@OBJ_SUFFIX@: pred.h pred.c

oper@OBJ_SUFFIX@: oper.h oper.c

if_no_fd@OBJ_SUFFIX@: if_no_fd.h if_no_fd.c


clean:
	rm -f pl_config@EXE_SUFFIX@ cpp_headers@EXE_SUFFIX@ try_sigaction@EXE_SUFFIX@ *@OBJ_SUFFIX@ *.ilk *.pdb *.pch *.idb *.exp $(LIBNAME)

distclean: clean clean-test_oc
	rm -f wam_archi.h wam_regs.h gp_config.h




check:	test_oc@EXE_SUFFIX@
	./test_oc@EXE_SUFFIX@

clean-check: clean-test_oc

# test obj chain utility

TEST_OC_SRC=obj_chain.c test_oc.c

test_oc@EXE_SUFFIX@: obj_chain.c obj_chain.h test_oc.c test_oc_defs.h
	for i in 1 2 3 4 5; do \
	  (echo "#define OBJ_NO $$i" && \
	   echo "#include \"test_oc_defs.h\"") >test_oc_m$$i.c || exit; \
	done
	$(CC) $(CFLAGS) @CC_EXE_NAME_OPT@test_oc@EXE_SUFFIX@ test_oc.c obj_chain.c -I. test_oc_m[1-5].c
	rm -f test_oc_m* test_oc*@OBJ_SUFFIX@

clean-test_oc:
	rm -f test_oc@EXE_SUFFIX@ test_oc_m*

