From: Richard Jones Date: Tue, 23 Feb 2010 10:36:51 +0000 (+0000) Subject: Add build framework for OCaml, Perl, Python bindings. X-Git-Tag: 1.2.0~11 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;ds=inline;h=aa5d6c138b55e25994ac723e94f32b009366927c;p=hivex.git Add build framework for OCaml, Perl, Python bindings. (No bindings are actually built, this just adds the build, test and generator framework for them). --- diff --git a/.gitignore b/.gitignore index df2cf09..5ecefaa 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,21 @@ Makefile Makefile.in missing *.o +ocaml/hivex.ml +ocaml/hivex.mli +ocaml/hivex_c.c +ocaml/META +ocaml/*.so +ocaml/t/hivex_005_load +perl/blib +perl/Hivex.bs +perl/Hivex.c +perl/Hivex.xs +perl/lib/Win/Hivex.pm +perl/Makefile-pl +perl/Makefile-pl.old +perl/Makefile.PL +perl/pm_to_blib pod2htm?.tmp po/*.gmo po/Makevars.template @@ -71,6 +86,9 @@ po/en@quot.header po/insert-header.sin po/quot.sed po/remove-potcdate.sin +python/*.pyc +python/hivex-py.c +python/hivex.py sh/*.1 sh/hivexsh stamp-h1 diff --git a/Makefile.am b/Makefile.am index 87ac656..16fe5ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,18 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = gnulib/lib lib images gnulib/tests sh xml po +if HAVE_OCAML +SUBDIRS += ocaml +endif + +if HAVE_PERL +SUBDIRS += perl +endif + +if HAVE_PYTHON +SUBDIRS += python +endif + EXTRA_DIST = hivex.pc hivex.pc.in README LICENSE # Generate the ChangeLog automatically from the gitlog. diff --git a/autogen.sh b/autogen.sh index 0d08b4c..ae68052 100755 --- a/autogen.sh +++ b/autogen.sh @@ -46,6 +46,7 @@ fi # anything that is required at configure-time when configure is run # from a distribution tarball. From those, nothing ocaml-related is # required. +mkdir -p perl/lib/Win ./generator/generator.ml # If no arguments were specified and configure has run before, use the previous diff --git a/configure.ac b/configure.ac index fecf85b..18cbd90 100644 --- a/configure.ac +++ b/configure.ac @@ -401,7 +401,10 @@ AC_CONFIG_FILES([Makefile images/Makefile lib/Makefile lib/tools/Makefile + ocaml/Makefile ocaml/META + perl/Makefile perl/Makefile.PL po/Makefile.in + python/Makefile sh/Makefile xml/Makefile]) AC_OUTPUT diff --git a/generator/generator.ml b/generator/generator.ml index 7a326db..87afde3 100755 --- a/generator/generator.ml +++ b/generator/generator.ml @@ -1301,6 +1301,29 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. " +and generate_ocaml_interface () = + generate_header OCamlStyle LGPLv2plus; + pr "val open_file : unit\n" + +and generate_ocaml_implementation () = + generate_header OCamlStyle LGPLv2plus; + pr "let open_file = ()\n" + +and generate_ocaml_c () = + generate_header CStyle LGPLv2plus + +and generate_perl_pm () = + generate_header HashStyle LGPLv2plus + +and generate_perl_xs () = + generate_header CStyle LGPLv2plus + +and generate_python_py () = + generate_header HashStyle LGPLv2plus + +and generate_python_c () = + generate_header CStyle LGPLv2plus + let output_to filename k = let filename_new = filename ^ ".new" in chan := open_out filename_new; @@ -1356,6 +1379,16 @@ Run it from the top source directory using the command output_to "lib/hivex.h" generate_c_header; output_to "lib/hivex.pod" generate_c_pod; + output_to "ocaml/hivex.mli" generate_ocaml_interface; + output_to "ocaml/hivex.ml" generate_ocaml_implementation; + output_to "ocaml/hivex_c.c" generate_ocaml_c; + + output_to "perl/lib/Win/Hivex.pm" generate_perl_pm; + output_to "perl/Hivex.xs" generate_perl_xs; + + output_to "python/hivex.py" generate_python_py; + output_to "python/hivex-py.c" generate_python_c; + (* Always generate this file last, and unconditionally. It's used * by the Makefile to know when we must re-run the generator. *) diff --git a/ocaml/.depend b/ocaml/.depend new file mode 100644 index 0000000..64a531f --- /dev/null +++ b/ocaml/.depend @@ -0,0 +1,3 @@ +hivex.cmi: +hivex.cmo: hivex.cmi +hivex.cmx: hivex.cmi diff --git a/ocaml/META.in b/ocaml/META.in new file mode 100644 index 0000000..45b0a92 --- /dev/null +++ b/ocaml/META.in @@ -0,0 +1,6 @@ +name="hivex" +version="@PACKAGE_VERSION@" +description="Windows Registry hive file bindings for OCaml" +requires="unix" +archive(byte)="mlhivex.cma" +archive(native)="mlhivex.cmxa" diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am new file mode 100644 index 0000000..f7d26ce --- /dev/null +++ b/ocaml/Makefile.am @@ -0,0 +1,97 @@ +# hivex OCaml bindings +# Copyright (C) 2009-2010 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 = \ + .depend META.in \ + hivex.mli hivex.ml \ + hivex_c.c \ + t/*.ml + +CLEANFILES = *.cmi *.cmo *.cmx *.cma *.cmxa *.o *.a *.so +CLEANFILES += t/*.cmi t/*.cmo t/*.cmx t/*.o t/*.a t/*.so + +AM_CPPFLAGS = \ + -I$(top_builddir) -I$(OCAMLLIB) -I$(top_srcdir)/ocaml \ + -I$(top_srcdir)/lib \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) + +if HAVE_OCAML + +noinst_DATA = mlhivex.cma mlhivex.cmxa META + +OBJS = hivex_c.o hivex.cmo +XOBJS = $(OBJS:.cmo=.cmx) + +mlhivex.cma: $(OBJS) + $(OCAMLMKLIB) -o mlhivex $^ -L$(top_builddir)/lib/.libs -lhivex + +mlhivex.cmxa: $(XOBJS) + $(OCAMLMKLIB) -o mlhivex $^ -L$(top_builddir)/lib/.libs -lhivex + +hivex_c.o: hivex_c.c + $(CC) $(AM_CPPFLAGS) $(CFLAGS) -fPIC -Wall -c $< + +TESTS_ENVIRONMENT = \ + LD_LIBRARY_PATH=$(top_builddir)/lib/.libs \ + $(VG) + +TESTS = t/hivex_005_load +noinst_DATA += $(TESTS) + +t/hivex_005_load: t/hivex_005_load.cmx mlhivex.cmxa + mkdir -p t + $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/lib/.libs -I . -package unix -linkpkg mlhivex.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 mlhivex.cmxa + $(OCAMLFIND) ocamlopt -package unix -linkpkg -c $< -o $@ + +.mli.cmi: + $(OCAMLFIND) ocamlc -package unix -c $< -o $@ +.ml.cmo: + $(OCAMLFIND) ocamlc -package unix -c $< -o $@ +.ml.cmx: + $(OCAMLFIND) ocamlopt -package unix -c $< -o $@ + +depend: .depend + +.depend: $(wildcard *.mli) $(wildcard *.ml) + rm -f $@ $@-t + $(OCAMLFIND) ocamldep $^ | sed 's/ *$$//' | sort > $@-t + mv $@-t $@ + +include .depend + +SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly + +# Do the installation by hand, because we want to run ocamlfind. +install-data-hook: + mkdir -p $(DESTDIR)$(OCAMLLIB) + mkdir -p $(DESTDIR)$(OCAMLLIB)/stublibs + $(OCAMLFIND) install \ + -ldconf ignore -destdir $(DESTDIR)$(OCAMLLIB) \ + hivex \ + META *.so *.a *.cma *.cmx *.cmxa *.cmi *.mli + +CLEANFILES += $(noinst_DATA) + +endif + +# Tell version 3.79 and up of GNU make to not build goals in this +# directory in parallel. (See RHBZ#502309). +.NOTPARALLEL: diff --git a/ocaml/t/hivex_005_load.ml b/ocaml/t/hivex_005_load.ml new file mode 100644 index 0000000..704dc0b --- /dev/null +++ b/ocaml/t/hivex_005_load.ml @@ -0,0 +1,20 @@ +(* hivex OCaml bindings + * Copyright (C) 2009-2010 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. + *) + +(* Just links with the library, doesn't run anything. *) +let _ = Hivex.open_file diff --git a/perl/Makefile.PL.in b/perl/Makefile.PL.in new file mode 100644 index 0000000..e6e3d72 --- /dev/null +++ b/perl/Makefile.PL.in @@ -0,0 +1,30 @@ +# hivex Perl bindings +# Copyright (C) 2009-2010 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. + +use ExtUtils::MakeMaker; + +WriteMakefile ( + FIRST_MAKEFILE => 'Makefile-pl', + + NAME => 'Win::Hivex', + VERSION => '@PACKAGE_VERSION@', + + LIBS => '-L@top_builddir@/lib/.libs -lhivex', + INC => '-I@top_builddir@/lib -I@top_srcdir@/lib', + TYPEMAPS => [ '@srcdir@/typemap' ], + CCFLAGS => '@CFLAGS@', + ); diff --git a/perl/Makefile.am b/perl/Makefile.am new file mode 100644 index 0000000..9d5b692 --- /dev/null +++ b/perl/Makefile.am @@ -0,0 +1,60 @@ +# hivex Perl bindings +# Copyright (C) 2009-2010 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 = \ + Makefile.PL.in \ + run-perl-tests \ + lib/Win/Hivex.pm \ + Hivex.xs \ + t/*.t \ + typemap + +if HAVE_PERL + +# Interfacing automake and ExtUtils::MakeMaker known to be +# a nightmare, news at 11. + +# hivex source dependencies +.PHONY: src_deps +src_deps: $(top_builddir)/lib/libhivex.la + +TESTS = run-perl-tests + +$(TESTS): src_deps all + +TESTS_ENVIRONMENT = \ + LD_LIBRARY_PATH=$(top_builddir)/lib/.libs + +INSTALLDIRS = site + +all: Makefile-pl src_deps + $(MAKE) -f Makefile-pl + +Makefile-pl: Makefile.PL + perl Makefile.PL INSTALLDIRS=$(INSTALLDIRS) PREFIX=$(prefix) + +# No! Otherwise it is deleted before the clean-local rule runs. +#CLEANFILES = Makefile-pl + +clean-local: + -$(MAKE) -f Makefile-pl clean + rm -f Makefile-pl + +install-data-hook: + $(MAKE) -f Makefile-pl DESTDIR=$(DESTDIR) install + +endif diff --git a/perl/run-perl-tests b/perl/run-perl-tests new file mode 100755 index 0000000..770df94 --- /dev/null +++ b/perl/run-perl-tests @@ -0,0 +1,21 @@ +#!/bin/sh - +# hivex Perl bindings +# Copyright (C) 2009-2010 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. + +set -e + +make -f Makefile-pl test "$@" diff --git a/perl/typemap b/perl/typemap new file mode 100644 index 0000000..752ca0d --- /dev/null +++ b/perl/typemap @@ -0,0 +1,18 @@ +TYPEMAP +char * T_PV +const char * T_PV +guestfs_h * O_OBJECT_guestfs_h +int64_t T_IV + +INPUT +O_OBJECT_guestfs_h + if (sv_isobject ($arg) && SvTYPE (SvRV ($arg)) == SVt_PVMG) + $var = ($type) SvIV ((SV *) SvRV ($arg)); + else { + warn (\"${Package}::$func_name(): $var is not a blessed SV reference\"); + XSRETURN_UNDEF; + } + +OUTPUT +O_OBJECT_guestfs_h + sv_setref_pv ($arg, "Sys::Guestfs", (void *) $var); diff --git a/po/POTFILES.in b/po/POTFILES.in index 34718af..31ae02d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,9 @@ images/mklarge.c lib/hivex.c +ocaml/hivex_c.c +perl/Hivex.c +perl/blib/lib/Win/Hivex.pm +perl/lib/Win/Hivex.pm +python/hivex-py.c sh/hivexsh.c xml/hivexml.c diff --git a/python/Makefile.am b/python/Makefile.am new file mode 100644 index 0000000..bc9ce7c --- /dev/null +++ b/python/Makefile.am @@ -0,0 +1,45 @@ +# hivex Python bindings +# Copyright (C) 2009-2010 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. + +# Old RHEL 5 autoconf doesn't have builddir. +builddir ?= $(top_builddir)/python + +EXTRA_DIST = \ + run-python-tests \ + hivex.py \ + hivex-py.c \ + t/*.py + +if HAVE_PYTHON + +pythondir = $(PYTHON_SITE_PACKAGES) + +python_DATA = hivex.py + +python_LTLIBRARIES = libhivexmod.la + +libhivexmod_la_SOURCES = hivex-py.c +libhivexmod_la_CFLAGS = -Wall -I$(PYTHON_INCLUDEDIR) \ + -I$(top_srcdir)/lib -I$(top_builddir)/lib +libhivexmod_la_LIBADD = $(top_builddir)/lib/libhivex.la + +TESTS_ENVIRONMENT = \ + PYTHONPATH=$(builddir):$(builddir)/.libs + +TESTS = run-python-tests + +endif diff --git a/python/run-python-tests b/python/run-python-tests new file mode 100755 index 0000000..b305db7 --- /dev/null +++ b/python/run-python-tests @@ -0,0 +1,24 @@ +#!/bin/sh - +# hivex Python bindings +# Copyright (C) 2009-2010 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. + +set -e +shopt -s nullglob + +for f in t/*.py; do + python $f +done