Added framework for the language bindings.

This commit is contained in:
Richard Jones
2009-04-07 13:08:50 +01:00
parent dfb90f793a
commit acf9000252
10 changed files with 356 additions and 6 deletions

39
HACKING
View File

@@ -15,6 +15,9 @@ You will need to run src/generator.ml (from the top directory) which
regenerates all the auto-generated files, and then continue with the
ordinary build process.
PLEASE LOOK AT THE TOP OF EACH FILE BEFORE EDITING to see whether it
is automatically generated or not.
Formatting
----------------------------------------------------------------------
@@ -23,11 +26,45 @@ used elsewhere in the source.
Please make sure that the code compiles without warnings.
Please test any changes
Please test any changes.
Directories
----------------------------------------------------------------------
daemon/
The daemon that runs inside the guest and carries out actions.
examples/
The examples.
fish/
Guestfish (the command-line program / shell)
images/
Some guest images to test against. These are gzipped to save
space. You have to unzip them before use.
m4/
M4 macros used by autoconf.
ocaml/
OCaml bindings.
perl/
Perl bindings.
python/
Python bindings.
src/
Source code to the C library.
Also contains the crucial generator program.
Debugging
----------------------------------------------------------------------
It's a good idea to use guestfish to try out new commands.
Use 'guestfish -v', which will show error messages etc from the
daemon.

View File

@@ -17,7 +17,17 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src daemon fish examples
SUBDIRS = src daemon fish examples images
if HAVE_OCAML
SUBDIRS += ocaml
endif
if HAVE_PERL
SUBDIRS += perl
endif
if HAVE_PYTHON
SUBDIRS += python
endif
EXTRA_DIST = \
make-initramfs.sh update-initramfs.sh \

6
README
View File

@@ -39,10 +39,14 @@ Requirements
other documentation.
- (Optional) OCaml if you want to modify the code or rebuild certain
generated files.
generated files, and also to build the OCaml bindings
- (Optional) local Fedora mirror
- (Optional) Perl if you want to build the perl bindings
- (Optional) Python if you want to build the python bindings
Running ./configure will check you have all the requirements installed
on your machine.

View File

@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
AC_INIT([libguestfs],[0.4])
AC_INIT([libguestfs],[0.5])
AM_INIT_AUTOMAKE
AC_CONFIG_MACRO_DIR([m4])
@@ -40,7 +40,7 @@ AC_CHECK_HEADERS([errno.h sys/types.h sys/un.h sys/wait.h sys/socket.h])
dnl Check for rpcgen and XDR library. rpcgen is optional.
AC_CHECK_PROG([RPCGEN],[rpcgen],[rpcgen],[no])
AM_CONDITIONAL([RPCGEN],[test "x$RPCGEN" != "xno"])
AM_CONDITIONAL([HAVE_RPCGEN],[test "x$RPCGEN" != "xno"])
AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[
AC_SEARCH_LIBS([xdrmem_create],[rpc xdr nsl])
])
@@ -99,12 +99,28 @@ AC_ARG_WITH([mirror],
MIRROR="$with_mirror"
AC_SUBST(MIRROR)
dnl Check for OCaml (optional, for OCaml bindings).
AC_PROG_OCAML
AM_CONDITIONAL([HAVE_OCAML],[test "x$OCAMLC" != "xno"])
dnl Check for Perl (optional, for Perl bindings).
dnl XXX This isn't quite right, we should check for devel libraries.
AC_CHECK_PROG([PERL],[perl],[perl],[no])
AM_CONDITIONAL([HAVE_PERL],[test "x$PERL" != "xno"])
dnl Check for Python (optional, for Python bindings).
dnl XXX This isn't quite right, we should check for devel libraries.
AC_CHECK_PROG([PYTHON],[python],[python],[no])
AM_CONDITIONAL([HAVE_PYTHON],[test "x$PYTHON" != "xno"])
dnl Run in subdirs.
AC_CONFIG_SUBDIRS([daemon])
dnl Produce output files.
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile src/Makefile fish/Makefile examples/Makefile
images/Makefile ocaml/Makefile perl/Makefile
python/Makefile
make-initramfs.sh update-initramfs.sh
libguestfs.spec])
AC_OUTPUT

18
images/Makefile.am Normal file
View File

@@ -0,0 +1,18 @@
# libguestfs test images
# Copyright (C) 2009 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
EXTRA_DIST = mbr-ext2-empty.img.gz

217
m4/ocaml.m4 Normal file
View File

@@ -0,0 +1,217 @@
dnl autoconf macros for OCaml
dnl
dnl Copyright © 2009 Richard W.M. Jones
dnl Copyright © 2009 Stefano Zacchiroli
dnl Copyright © 2000-2005 Olivier Andrieu
dnl Copyright © 2000-2005 Jean-Christophe Filliâtre
dnl Copyright © 2000-2005 Georges Mariano
dnl
dnl For documentation, please read the ocaml.m4 man page.
AC_DEFUN([AC_PROG_OCAML],
[dnl
# checking for ocamlc
AC_CHECK_TOOL([OCAMLC],[ocamlc],[no])
if test "$OCAMLC" != "no"; then
OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p'`
AC_MSG_RESULT([OCaml version is $OCAMLVERSION])
OCAMLLIB=`$OCAMLC -where 2>/dev/null || $OCAMLC -v|tail -1|cut -d ' ' -f 4`
AC_MSG_RESULT([OCaml library path is $OCAMLLIB])
AC_SUBST([OCAMLVERSION])
AC_SUBST([OCAMLLIB])
# checking for ocamlopt
AC_CHECK_TOOL([OCAMLOPT],[ocamlopt],[no])
OCAMLBEST=byte
if test "$OCAMLOPT" = "no"; then
AC_MSG_WARN([Cannot find ocamlopt; bytecode compilation only.])
else
TMPVERSION=`$OCAMLOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
if test "$TMPVERSION" != "$OCAMLVERSION" ; then
AC_MSG_RESULT([versions differs from ocamlc; ocamlopt discarded.])
OCAMLOPT=no
else
OCAMLBEST=opt
fi
fi
AC_SUBST([OCAMLBEST])
# checking for ocamlc.opt
AC_CHECK_TOOL([OCAMLCDOTOPT],[ocamlc.opt],[no])
if test "$OCAMLCDOTOPT" != "no"; then
TMPVERSION=`$OCAMLCDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
if test "$TMPVERSION" != "$OCAMLVERSION" ; then
AC_MSG_RESULT([versions differs from ocamlc; ocamlc.opt discarded.])
else
OCAMLC=$OCAMLCDOTOPT
fi
fi
# checking for ocamlopt.opt
if test "$OCAMLOPT" != "no" ; then
AC_CHECK_TOOL([OCAMLOPTDOTOPT],[ocamlopt.opt],[no])
if test "$OCAMLOPTDOTOPT" != "no"; then
TMPVERSION=`$OCAMLOPTDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
if test "$TMPVERSION" != "$OCAMLVERSION" ; then
AC_MSG_RESULT([version differs from ocamlc; ocamlopt.opt discarded.])
else
OCAMLOPT=$OCAMLOPTDOTOPT
fi
fi
fi
AC_SUBST([OCAMLOPT])
fi
AC_SUBST([OCAMLC])
# checking for ocamldep
AC_CHECK_TOOL([OCAMLDEP],[ocamldep],[no])
# checking for ocamlmktop
AC_CHECK_TOOL([OCAMLMKTOP],[ocamlmktop],[no])
# checking for ocamlmklib
AC_CHECK_TOOL([OCAMLMKLIB],[ocamlmklib],[no])
# checking for ocamldoc
AC_CHECK_TOOL([OCAMLDOC],[ocamldoc],[no])
# checking for ocamlbuild
AC_CHECK_TOOL([OCAMLBUILD],[ocamlbuild],[no])
])
AC_DEFUN([AC_PROG_OCAMLLEX],
[dnl
# checking for ocamllex
AC_CHECK_TOOL([OCAMLLEX],[ocamllex],[no])
if test "$OCAMLLEX" != "no"; then
AC_CHECK_TOOL([OCAMLLEXDOTOPT],[ocamllex.opt],[no])
if test "$OCAMLLEXDOTOPT" != "no"; then
OCAMLLEX=$OCAMLLEXDOTOPT
fi
fi
AC_SUBST([OCAMLLEX])
])
AC_DEFUN([AC_PROG_OCAMLYACC],
[dnl
AC_CHECK_TOOL([OCAMLYACC],[ocamlyacc],[no])
AC_SUBST([OCAMLYACC])
])
AC_DEFUN([AC_PROG_CAMLP4],
[dnl
AC_REQUIRE([AC_PROG_OCAML])dnl
# checking for camlp4
AC_CHECK_TOOL([CAMLP4],[camlp4],[no])
if test "$CAMLP4" != "no"; then
TMPVERSION=`$CAMLP4 -v 2>&1| sed -n -e 's|.*version *\(.*\)$|\1|p'`
if test "$TMPVERSION" != "$OCAMLVERSION" ; then
AC_MSG_RESULT([versions differs from ocamlc])
CAMLP4=no
fi
fi
AC_SUBST([CAMLP4])
# checking for companion tools
AC_CHECK_TOOL([CAMLP4BOOT],[camlp4boot],[no])
AC_CHECK_TOOL([CAMLP4O],[camlp4o],[no])
AC_CHECK_TOOL([CAMLP4OF],[camlp4of],[no])
AC_CHECK_TOOL([CAMLP4OOF],[camlp4oof],[no])
AC_CHECK_TOOL([CAMLP4ORF],[camlp4orf],[no])
AC_CHECK_TOOL([CAMLP4PROF],[camlp4prof],[no])
AC_CHECK_TOOL([CAMLP4R],[camlp4r],[no])
AC_CHECK_TOOL([CAMLP4RF],[camlp4rf],[no])
AC_SUBST([CAMLP4BOOT])
AC_SUBST([CAMLP4O])
AC_SUBST([CAMLP4OF])
AC_SUBST([CAMLP4OOF])
AC_SUBST([CAMLP4ORF])
AC_SUBST([CAMLP4PROF])
AC_SUBST([CAMLP4R])
AC_SUBST([CAMLP4RF])
])
AC_DEFUN([AC_PROG_FINDLIB],
[dnl
AC_REQUIRE([AC_PROG_OCAML])dnl
# checking for ocamlfind
AC_CHECK_TOOL([OCAMLFIND],[ocamlfind],[no])
AC_SUBST([OCAMLFIND])
])
dnl Thanks to Jim Meyering for working this next bit out for us.
dnl XXX We should define AS_TR_SH if it's not defined already
dnl (eg. for old autoconf).
AC_DEFUN([AC_CHECK_OCAML_PKG],
[dnl
AC_REQUIRE([AC_PROG_FINDLIB])dnl
AC_MSG_CHECKING([for OCaml findlib package $1])
unset found
unset pkg
found=no
for pkg in $1 $2 ; do
if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then
AC_MSG_RESULT([found])
AS_TR_SH([OCAML_PKG_$1])=$pkg
found=yes
break
fi
done
if test "$found" = "no" ; then
AC_MSG_RESULT([not found])
AS_TR_SH([OCAML_PKG_$1])=no
fi
AC_SUBST(AS_TR_SH([OCAML_PKG_$1]))
])
AC_DEFUN([AC_CHECK_OCAML_MODULE],
[dnl
AC_MSG_CHECKING([for OCaml module $2])
cat > conftest.ml <<EOF
open $3
EOF
unset found
for $1 in $$1 $4 ; do
if $OCAMLC -c -I "$$1" conftest.ml >&5 2>&5 ; then
found=yes
break
fi
done
if test "$found" ; then
AC_MSG_RESULT([$$1])
else
AC_MSG_RESULT([not found])
$1=no
fi
AC_SUBST([$1])
])
dnl XXX Cross-compiling
AC_DEFUN([AC_CHECK_OCAML_WORD_SIZE],
[dnl
AC_MSG_CHECKING([for OCaml compiler word size])
cat > conftest.ml <<EOF
print_endline (string_of_int Sys.word_size)
EOF
OCAML_WORD_SIZE=`ocaml conftest.ml`
AC_MSG_RESULT([$OCAML_WORD_SIZE])
AC_SUBST([OCAML_WORD_SIZE])
])

16
ocaml/Makefile.am Normal file
View File

@@ -0,0 +1,16 @@
# libguestfs OCaml bindings
# Copyright (C) 2009 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

16
perl/Makefile.am Normal file
View File

@@ -0,0 +1,16 @@
# libguestfs Perl bindings
# Copyright (C) 2009 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

16
python/Makefile.am Normal file
View File

@@ -0,0 +1,16 @@
# libguestfs Python bindings
# Copyright (C) 2009 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

View File

@@ -37,7 +37,7 @@ libguestfs_la_SOURCES = \
libguestfs_la_CFLAGS = -Wall -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"'
if RPCGEN
if HAVE_RPCGEN
guestfs_protocol.c: guestfs_protocol.x
rm -f $@-t
$(RPCGEN) -c -o $@-t $<