[Libguestfs] [hivex PATCH 8/8] build: allow OCaml programs using hivex to be compiled against build dir

Laszlo Ersek lersek at redhat.com
Wed Sep 8 13:27:58 UTC 2021


Port libguestfs commit bf61bf7355d3 ("build: Allow OCaml programs using
libguestfs to be compiled against build dir.", 2020-03-12) to hivex.

This allows C+OCaml programs, such as libguestfs itself, to find a just
built, but not installed, hivex tree:

> libguestfs$ ../hivex/run ./configure CFLAGS=-fPIC
> libguestfs$ ../hivex/run make -j $(getconf _NPROCESSORS_ONLN)
> libguestfs$ ../hivex/run make -j $(getconf _NPROCESSORS_ONLN) check

Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
 ocaml/Makefile.am | 19 ++++++++++++++++++-
 .gitignore        |  1 +
 run.in            |  2 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index 1ef0c194e212..ace3208ea309 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -112,7 +112,24 @@ install-data-hook:
 
 CLEANFILES += $(noinst_DATA)
 
-endif
+# This "tricks" ocamlfind into allowing us to compile other OCaml
+# programs against a locally compiled copy of the hivex sources.
+# ocamlfind needs to see a directory called ‘hivex’ which contains
+# ‘META’.  The current directory is called ‘ocaml’, but if we make
+# this symlink then we can create the required directory structure.
+#
+# Note if you just want to use this, make sure you use
+# ‘../hivex/run make’ in your other program and everything should
+# just work.
+CLEANFILES += hivex
+
+all-local: hivex
+
+hivex:
+	rm -f $@
+	$(LN_S) . $@
+
+endif HAVE_OCAML
 
 # Tell version 3.79 and up of GNU make to not build goals in this
 # directory in parallel.  (See RHBZ#502309).
diff --git a/.gitignore b/.gitignore
index 596030afe5cc..b856922c917b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -72,6 +72,7 @@ Makefile.in
 /m4/ltversion.m4
 /maint.mk
 /missing
+/ocaml/hivex
 /ocaml/hivex.ml
 /ocaml/hivex.mli
 /ocaml/hivex_c.c
diff --git a/run.in b/run.in
index e2563845f673..e166a9202248 100755
--- a/run.in
+++ b/run.in
@@ -90,6 +90,8 @@ export MALLOC_PERTURB_=$random_val
 # Allow dependent packages like libguestfs to be compiled against local hivex.
 prepend PKG_CONFIG_PATH "$b/lib/local"
 export PKG_CONFIG_PATH
+prepend OCAMLPATH "$b/ocaml"
+export OCAMLPATH
 
 # Do we have libtool?  If we have it then we can use it to make
 # running valgrind simpler.  However don't depend on it.
-- 
2.19.1.3.g30247aa5d201





More information about the Libguestfs mailing list