
OCAMLBUILDDIR = $(top_builddir)/src/gdome_caml
OCAMLINSTALLDIR = $(DESTDIR)$(OCAML_LIB_PREFIX)/gdome2
OCAMLFLAGS = -I $(OCAMLBUILDDIR)/types -I $(OCAMLBUILDDIR)/basic
OCAMLC = @OCAMLC@ ${OCAMLFLAGS}
OCAMLOPT = @OCAMLOPT@ ${OCAMLFLAGS}
OCAMLDEP = @OCAMLDEP@
OCAML_CFLAGS  = @OCAML_CFLAGS@

AUTO_C = \
  ml_Node.c \
  ml_NodeList.c \
  ml_NamedNodeMap.c \
  ml_CharacterData.c \
  ml_Attr.c \
  ml_Element.c \
  ml_Text.c \
  ml_Comment.c \
  ml_CDATASection.c \
  ml_DocumentType.c \
  ml_Notation.c \
  ml_Entity.c \
  ml_EntityReference.c \
  ml_ProcessingInstruction.c \
  ml_DocumentFragment.c \
  ml_Document.c

I_AUTO_ML = \
  iNode.ml \
  iNodeList.ml \
  iNamedNodeMap.ml \
  iCharacterData.ml \
  iAttr.ml \
  iElement.ml \
  iText.ml \
  iComment.ml \
  iCDATASection.ml \
  iDocumentType.ml \
  iNotation.ml \
  iEntity.ml \
  iEntityReference.ml \
  iProcessingInstruction.ml \
  iDocumentFragment.ml \
  iDocument.ml

# OCaml objects
OCAML_OBJECTS = $(I_AUTO_ML:%.ml=%.cmo) \
                $(I_AUTO_ML:%.ml=%.cmi) \
                $(I_AUTO_ML:%.ml=%.cmx) \
                $(I_AUTO_ML:%.ml=%.o)

BUILT_SOURCES = $(AUTO_C) $(I_AUTO_ML)

CLEANFILES = \
  $(AUTO_C) \
  $(I_AUTO_ML) \
  $(OCAML_OBJECTS) \
  mlcore.cma mlcore.cmxa mlcore.a

EXTRA_DIST = $(AUTO_C) $(I_AUTO_ML) .depend

XML2C = $(srcdir)/../xsl/xml2c.xsl
XML2MLI = $(srcdir)/../xsl/xml2mli.xsl

if HAVE_OCAMLOPT_COND
noinst_DATA = mlcore.cma mlcore.cmxa mlcore.a
else
noinst_DATA = mlcore.cma
endif

mlcore.cma : $(I_AUTO_ML:%.ml=%.cmo)
	$(OCAMLC) -o $@ -a $^

mlcore.cmxa mlcore.a : $(I_AUTO_ML:%.ml=%.cmx)
	$(OCAMLOPT) -o $@ -a $^

noinst_LTLIBRARIES = libcore.la

libcore_la_SOURCES = $(AUTO_C)

$(AUTO_C) : $(XML2C)
$(I_AUTO_ML) : $(XML2MLI)

if HAVE_XSLTPROC_COND

ml_%.c : $(top_srcdir)/xml/DOM/Core/%.xml
	$(XSLTPROC) --param uriprefix "'$(top_srcdir)/xml/DOM/Core'" --param annotations "'$(srcdir)/../xml/Core/$*.xml'" $(XML2C) $< >$@

i%.ml : $(top_srcdir)/xml/DOM/Core/%.xml $(srcdir)/../xml/Core/%.xml
	$(XSLTPROC) --param uriprefix "'$(top_srcdir)/xml/DOM/Core'" --param annotations "'$(srcdir)/../xml/Core/$*.xml'" $(XML2MLI) $< >$@

endif

INCLUDES = \
  $(OCAML_CFLAGS) \
  $(GDOME_CFLAGS) \
  -I$(srcdir)/../include

if HAVE_OCAMLOPT_COND
install-data-local: $(I_AUTO_ML:%.ml=%.cmi) mlcore.cma mlcore.cmxa mlcore.a
else
install-data-local: $(I_AUTO_ML:%.ml=%.cmi) mlcore.cma
endif
	$(mkinstalldirs) $(OCAMLINSTALLDIR)
	for i in $^; do \
		$(INSTALL_DATA) $$i $(OCAMLINSTALLDIR)/$$i; \
	done
	for i in $(I_AUTO_ML); do \
		$(INSTALL_DATA) $(srcdir)/$$i $(OCAMLINSTALLDIR)/$$i; \
	done

#### OCaml only stuff from now on

DEPOBJS = $(I_AUTO_ML)

depend:
	$(OCAMLDEP) $(DEPOBJS) > .depend

%.cmi : $(srcdir)/%.mli
	if test ! -e $(@:%.cmi=%.mli) -a "x$(srcdir)" != "x." ; then $(LN_S) $< . ; fi
	$(OCAMLC) -c $(@:%.cmi=%.mli)

%.cmo : $(srcdir)/%.ml
	if test ! -e $(@:%.cmo=%.ml) -a "x$(srcdir)" != "x." ; then $(LN_S) $< . ; fi
	$(OCAMLC) -c $(@:%.cmo=%.ml)

%.cmx %.o : $(srcdir)/%.ml
	if test ! -e $(@:%.cmx=%.ml) -a "x$(srcdir)" != "x." ; then $(LN_S) $< . ; fi
	$(OCAMLOPT) -c $(@:%.cmx=%.ml)

include .depend

