summaryrefslogtreecommitdiffstats
path: root/ocaml/Makefile.am
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-10-02 15:42:14 +0100
committerRichard Jones <rjones@redhat.com>2009-10-13 17:53:20 +0100
commitd37f69795396ec2354eb2d8480d64b9e5bdafacc (patch)
tree0685bb56dd3032d4e413930f23f93aac323b4cd9 /ocaml/Makefile.am
parentc6b8db6493dd633bf48b13daf72cdc9c078b5f9a (diff)
downloadlibguestfs-d37f69795396ec2354eb2d8480d64b9e5bdafacc.tar.gz
libguestfs-d37f69795396ec2354eb2d8480d64b9e5bdafacc.tar.xz
libguestfs-d37f69795396ec2354eb2d8480d64b9e5bdafacc.zip
inspector: Generate language bindings for OCaml.
This commit adds a generic mechanism for deriving language bindings for virt-inspector, and implements one concrete binding, for OCaml. The bindings are generated from the RELAX NG schema (virt-inspector.rng) which is supposed to be a correct and always up to date description of the XML that the virt-inspector program can generate. From the RNG we generate a set of types to describe the output of virt-inspector for the language, plus an XML parser, plus some glue code to actually run an external instance of virt-inspector and parse the resulting XML. At runtime, an external 'virt-inspector --xml <name>' command runs and the XML is parsed into language-specific structures. This has been tested on the four example files (inspector/example?.xml) The only particular difficulty about the OCaml binding is the use of Obj.magic, which is naughty but works because of the isomorphism between the representation of tuples and records in OCaml. This seems to cause no problems in my test program. Apart from this, the OCaml binding is straightforward and could be adapted easily for any other languages that want type-safe virt-inspector bindings. It's important to keep virt-inspector.rng up to date with changes to virt-inspector's XML output format.
Diffstat (limited to 'ocaml/Makefile.am')
-rw-r--r--ocaml/Makefile.am36
1 files changed, 23 insertions, 13 deletions
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index c89296b6..032a5517 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -18,6 +18,7 @@
EXTRA_DIST = \
guestfs.mli guestfs.ml \
guestfs_c.c guestfs_c.h guestfs_c_actions.c \
+ guestfs_inspector.mli guestfs_inspector.ml \
.depend META.in \
bindtests.ml \
run-bindtests \
@@ -31,13 +32,17 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(OCAMLLIB) -I$(top_srcdir)/ocaml \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
if HAVE_OCAML
+if HAVE_XML_LIGHT
noinst_DATA = mlguestfs.cma mlguestfs.cmxa META
-mlguestfs.cma: guestfs_c.o guestfs_c_actions.o guestfs.cmo
+OBJS = guestfs_c.o guestfs_c_actions.o guestfs.cmo guestfs_inspector.cmo
+XOBJS = $(OBJS:.cmo=.cmx)
+
+mlguestfs.cma: $(OBJS)
$(OCAMLMKLIB) -o mlguestfs $^ -L$(top_builddir)/src/.libs -lguestfs
-mlguestfs.cmxa: guestfs_c.o guestfs_c_actions.o guestfs.cmx
+mlguestfs.cmxa: $(XOBJS)
$(OCAMLMKLIB) -o mlguestfs $^ -L$(top_builddir)/src/.libs -lguestfs
guestfs_c.o: guestfs_c.c
@@ -53,42 +58,46 @@ TESTS_ENVIRONMENT = \
TESTS = run-bindtests \
t/guestfs_005_load t/guestfs_010_launch t/guestfs_050_lvcreate \
- t/guestfs_060_readdir
+ t/guestfs_060_readdir t/guestfs_500_inspect
noinst_DATA += bindtests \
t/guestfs_005_load t/guestfs_010_launch t/guestfs_050_lvcreate \
- t/guestfs_060_readdir
+ t/guestfs_060_readdir t/guestfs_500_inspect
bindtests: bindtests.cmx mlguestfs.cmxa
mkdir -p t
- $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
+ $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
t/guestfs_005_load: t/guestfs_005_load.cmx mlguestfs.cmxa
mkdir -p t
- $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
+ $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
t/guestfs_010_launch: t/guestfs_010_launch.cmx mlguestfs.cmxa
mkdir -p t
- $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
+ $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
t/guestfs_050_lvcreate: t/guestfs_050_lvcreate.cmx mlguestfs.cmxa
mkdir -p t
- $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
+ $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
t/guestfs_060_readdir: t/guestfs_060_readdir.cmx mlguestfs.cmxa
mkdir -p t
- $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
+ $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
+
+t/guestfs_500_inspect: t/guestfs_500_inspect.cmx mlguestfs.cmxa
+ mkdir -p t
+ $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . -package xml-light,unix -linkpkg mlguestfs.cmxa $< -o $@
# Need to rebuild the tests from source if the main library has
# changed at all, otherwise we get inconsistent assumptions.
t/%.cmx: t/%.ml mlguestfs.cmxa
- $(OCAMLFIND) ocamlopt -c $< -o $@
+ $(OCAMLFIND) ocamlopt -package xml-light,unix -linkpkg -c $< -o $@
.mli.cmi:
- $(OCAMLFIND) ocamlc -c $< -o $@
+ $(OCAMLFIND) ocamlc -package xml-light,unix -c $< -o $@
.ml.cmo:
- $(OCAMLFIND) ocamlc -c $< -o $@
+ $(OCAMLFIND) ocamlc -package xml-light,unix -c $< -o $@
.ml.cmx:
- $(OCAMLFIND) ocamlopt -c $< -o $@
+ $(OCAMLFIND) ocamlopt -package xml-light,unix -c $< -o $@
depend: .depend
@@ -113,6 +122,7 @@ install-data-hook:
CLEANFILES += $(noinst_DATA)
endif
+endif
# Tell version 3.79 and up of GNU make to not build goals in this
# directory in parallel. (Possible solution for RHBZ#502309).