[Libguestfs] [libnbd PATCH] build: allow OCaml programs using libnbd to be compiled against build dir

Laszlo Ersek lersek at redhat.com
Mon Sep 27 06:24:42 UTC 2021

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

This allows C+OCaml programs, such as virt-v2v, to find a just built, but
not installed, libnbd tree.

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

diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index 1c7397a9da7a..b1ab80dd5fa5 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -161,4 +161,21 @@ install-data-hook:
 	rm $(DESTDIR)$(OCAMLLIB)/nbd/libnbdocaml.a
+# This "tricks" ocamlfind into allowing us to compile other OCaml
+# programs against a locally compiled copy of the libnbd sources.
+# ocamlfind needs to see a directory called ‘nbd’ 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
+# ‘../libnbd/run make’ in your other program and everything should
+# just work.
+all-local: nbd
+	rm -f $@
+	$(LN_S) . $@
diff --git a/.gitignore b/.gitignore
index 5fc596773ed4..55a5449a70e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -141,6 +141,7 @@ Makefile.in
diff --git a/run.in b/run.in
index 99c1f7ff0ff6..dda49228f949 100755
--- a/run.in
+++ b/run.in
@@ -100,6 +100,8 @@ export GODEBUG=cgocheck=2
 # Allow dependent packages to be compiled against local libnbd.
 prepend PKG_CONFIG_PATH "$b/lib/local"
+prepend OCAMLPATH "$b/ocaml"
 # Do we have libtool?  If we have it then we can use it to make
 # running valgrind simpler.  However don't depend on it.

More information about the Libguestfs mailing list