
SUBDIRS = xsl xml include types basic core events . ocaml test

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

CLEANFILES = \
  mlgdome.cma mlgdome.cmxa mlgdome.a \
  iDOMImplementation.cmi iDOMImplementation.cmo iDOMImplementation.cmx iDOMImplementation.o

EXTRA_DIST = META.in iDOMImplementation.ml iDOMImplementation.mli .depend examples/ doc/

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

ocamllibdir = $(OCAML_LIB_PREFIX)/gdome2
ocamllib_LTLIBRARIES = libmlgdome.la

libmlgdome_la_LIBADD = \
  $(top_builddir)/src/gdome_caml/basic/libbasic.la \
  $(top_builddir)/src/gdome_caml/core/libcore.la \
  $(top_builddir)/src/gdome_caml/events/libevents.la \
  $(GDOME_LIBS)
libmlgdome_la_LDFLAGS = -version-info @GMETADOM_VERSION_INFO@

libmlgdome_la_SOURCES = \
  ml_DOMImplementation.c

mlgdome.cma : iDOMImplementation.cmo
	$(OCAMLC) -o $@ -a $^ -cclib "$(GDOME_LIBS)"

mlgdome.cmxa mlgdome.a : iDOMImplementation.cmx
	$(OCAMLOPT) -o $@ -a $^ -cclib "$(GDOME_LIBS)"

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

if HAVE_OCAMLOPT_COND
install-data-local: iDOMImplementation.cmi iDOMImplementation.ml iDOMImplementation.mli META mlgdome.cma mlgdome.cmxa mlgdome.a
else
install-data-local: iDOMImplementation.cmi iDOMImplementation.ml iDOMImplementation.mli META mlgdome.cma
endif
	$(mkinstalldirs) $(OCAMLINSTALLDIR)
	for i in $^; do \
		$(INSTALL_DATA) $$i $(OCAMLINSTALLDIR)/$$i; \
	done
	if [ "x$(OCAMLFIND)" != "x" ] ; \
         then \
	  if grep $(OCAMLINSTALLDIR) $(DESTDIR)/$(OCAML_LIB_PREFIX)/ld.conf ; \
          then \
	   echo "Hhhmm. The library is probably already installed." ; \
	   echo "I don't call ocamlfind install twice." ; \
	  else \
	   mv $(OCAMLINSTALLDIR) $(OCAMLINSTALLDIR).saved ; \
	   $(OCAMLFIND) install gdome2 META .libs/libmlgdome.so ; \
	   rm -rf $(OCAMLINSTALLDIR) ; \
	   mv $(OCAMLINSTALLDIR).saved $(OCAMLINSTALLDIR) ; \
	  fi ; \
         else \
          echo "Remember: to use the binding, you have to manually add $(OCAMLINSTALLDIR)" ; \
	  echo "to $(DESTDIR)/$(OCAML_LIB_PREFIX)/ld.conf." ; \
        fi

uninstall-local:
	if [ "x$(OCAMLFIND)" != "x" ] ; \
         then \
	  $(OCAMLFIND) remove gdome2 ; \
	 else \
	  rm -rf $(OCAMLINSTALLDIR) ; \
        fi

#### OCaml only stuff from now on

DEPOBJS = iDOMImplementation.ml iDOMImplementation.mli

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

