[Libguestfs] [PATCH] Fix out-of-tree builds of OCaml components

Hilko Bengen bengen at hilluzination.de
Mon Apr 9 14:22:48 UTC 2018


- Add $(srcdir), $(builddir) to Makefiles where required
- Post-process ocamldep output
- generate ocaml/.depends
---
 builder/Makefile.am           |  7 ++++---
 common/mlgettext/Makefile.am  |  2 +-
 common/mlpcre/Makefile.am     |  2 +-
 common/mlprogress/Makefile.am |  2 +-
 common/mlstdutils/Makefile.am |  2 +-
 common/mltools/Makefile.am    |  2 +-
 common/mlutils/Makefile.am    |  2 +-
 common/mlvisit/Makefile.am    |  2 +-
 common/mlxml/Makefile.am      |  2 +-
 customize/Makefile.am         |  2 +-
 daemon/Makefile.am            | 10 +++++-----
 generator/Makefile.am         |  2 +-
 get-kernel/Makefile.am        |  2 +-
 ocaml-dep.sh.in               | 18 ++++++++++++++++--
 ocaml/Makefile.am             |  3 +--
 resize/Makefile.am            |  2 +-
 sparsify/Makefile.am          |  2 +-
 subdir-rules.mk               |  6 +++---
 v2v/Makefile.am               |  2 +-
 v2v/test-harness/Makefile.am  |  2 +-
 20 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/builder/Makefile.am b/builder/Makefile.am
index a17a2aa6d6..c7b50778a1 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -142,11 +142,12 @@ bin_PROGRAMS += virt-builder virt-builder-repository
 
 virt_builder_SOURCES = $(SOURCES_C)
 virt_builder_CPPFLAGS = \
-	-I. \
+	-I$(builddir) -I$(srcdir) \
 	-I$(top_builddir) \
 	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
 	-I$(shell $(OCAMLC) -where) \
 	-I$(top_srcdir)/gnulib/lib \
+	-I$(top_builddir)/common/utils \
 	-I$(top_srcdir)/common/utils \
 	-I$(top_srcdir)/lib
 virt_builder_CFLAGS = \
@@ -163,7 +164,7 @@ XOBJECTS = $(BOBJECTS:.cmo=.cmx)
 
 virt_builder_repository_SOURCES = $(REPOSITORY_SOURCES_C)
 virt_builder_repository_CPPFLAGS = \
-	-I. \
+	-I$(builddir) -I$(srcdir) \
 	-I$(top_builddir) \
 	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
 	-I$(shell $(OCAMLC) -where) \
@@ -446,7 +447,7 @@ CLEANFILES += \
 	console-*.out
 
 # OCaml dependencies.
-.depend: *.mli *.ml osinfo_config.mli osinfo_config.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml osinfo_config.mli osinfo_config.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlgettext/Makefile.am b/common/mlgettext/Makefile.am
index 4cca6b4db0..cdcea33ec5 100644
--- a/common/mlgettext/Makefile.am
+++ b/common/mlgettext/Makefile.am
@@ -79,7 +79,7 @@ mlgettext.cmxa: $(XOBJECTS)
 endif
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlpcre/Makefile.am b/common/mlpcre/Makefile.am
index 4ff74cf972..f9699f5922 100644
--- a/common/mlpcre/Makefile.am
+++ b/common/mlpcre/Makefile.am
@@ -122,7 +122,7 @@ check-valgrind:
 	$(MAKE) VG="@VG@" check
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlprogress/Makefile.am b/common/mlprogress/Makefile.am
index f031a5a69e..be88ef2dee 100644
--- a/common/mlprogress/Makefile.am
+++ b/common/mlprogress/Makefile.am
@@ -93,7 +93,7 @@ $(MLPROGRESS_CMA): $(OBJECTS) libmlprogress.a
 	    -o mlprogress
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlstdutils/Makefile.am b/common/mlstdutils/Makefile.am
index cc05c5a73f..e38230db8a 100644
--- a/common/mlstdutils/Makefile.am
+++ b/common/mlstdutils/Makefile.am
@@ -141,7 +141,7 @@ check-valgrind:
 	$(MAKE) VG="@VG@" check
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mltools/Makefile.am b/common/mltools/Makefile.am
index 2ea1fee8ff..66b18f5ded 100644
--- a/common/mltools/Makefile.am
+++ b/common/mltools/Makefile.am
@@ -253,7 +253,7 @@ check-valgrind:
 	$(MAKE) VG="@VG@" check
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlutils/Makefile.am b/common/mlutils/Makefile.am
index 33d742f4c3..8627e5b10c 100644
--- a/common/mlutils/Makefile.am
+++ b/common/mlutils/Makefile.am
@@ -135,7 +135,7 @@ c_utils_unit_tests_LINK = \
 	  $(c_utils_unit_tests_THEOBJECTS) -o $@
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlvisit/Makefile.am b/common/mlvisit/Makefile.am
index 6902c9a2a9..add1fe56e8 100644
--- a/common/mlvisit/Makefile.am
+++ b/common/mlvisit/Makefile.am
@@ -139,7 +139,7 @@ check-valgrind:
 	$(MAKE) VG="@VG@" check
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlxml/Makefile.am b/common/mlxml/Makefile.am
index 083c7a64be..eab036b82f 100644
--- a/common/mlxml/Makefile.am
+++ b/common/mlxml/Makefile.am
@@ -88,7 +88,7 @@ $(MLXML_CMA): $(OBJECTS) libmlxml.a
 	    -o mlxml
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/customize/Makefile.am b/customize/Makefile.am
index 7f18b2fc34..efdd272275 100644
--- a/customize/Makefile.am
+++ b/customize/Makefile.am
@@ -312,7 +312,7 @@ CLEANFILES += \
 	settings-*.img
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 9dbd375f5d..506c880297 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -318,11 +318,11 @@ XOBJECTS = $(BOBJECTS:.cmo=.cmx)
 
 OCAMLPACKAGES = \
 	-package str,unix,hivex \
-	-I $(top_srcdir)/common/mlaugeas \
-	-I $(top_srcdir)/common/mlstdutils \
-	-I $(top_srcdir)/common/mlutils \
+	-I $(top_builddir)/common/mlaugeas \
+	-I $(top_builddir)/common/mlstdutils \
+	-I $(top_builddir)/common/mlutils \
 	-I $(top_builddir)/common/utils/.libs \
-	-I $(top_srcdir)/common/mlpcre \
+	-I $(top_builddir)/common/mlpcre \
 	-I $(top_builddir)/common/mlpcre/.libs \
 	-I $(top_builddir)/gnulib/lib/.libs
 
@@ -356,7 +356,7 @@ camldaemon.o: $(OBJECTS)
 	    $(OBJECTS)
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/generator/Makefile.am b/generator/Makefile.am
index fba807f18a..c2d10966aa 100644
--- a/generator/Makefile.am
+++ b/generator/Makefile.am
@@ -188,7 +188,7 @@ generator: $(objects)
 	    $^ -o $@
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/get-kernel/Makefile.am b/get-kernel/Makefile.am
index 03d4b9815f..81dfb48b42 100644
--- a/get-kernel/Makefile.am
+++ b/get-kernel/Makefile.am
@@ -135,7 +135,7 @@ stamp-virt-get-kernel.pod: virt-get-kernel.pod
 	touch $@
 
 # OCaml dependencies.
-.depend: *.ml *.mli
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/ocaml-dep.sh.in b/ocaml-dep.sh.in
index 92037b785f..bef14d488a 100755
--- a/ocaml-dep.sh.in
+++ b/ocaml-dep.sh.in
@@ -49,7 +49,12 @@ ocaml
 # Output file is always created in the current directory.
 output=.depend
 
-includes=""
+subdir=$(realpath --relative-to=@abs_top_builddir@ .)
+srcdir=$(realpath --relative-to=. @abs_top_srcdir@/${subdir})
+srcdir_re=$(realpath --relative-to=. @abs_top_srcdir@/${subdir} | sed 's/\./[.]/g')
+top_builddir=$(realpath --relative-to=. @abs_top_builddir@)
+
+includes="-I @abs_top_srcdir@/$subdir -I @abs_top_builddir@/$subdir"
 for i in $include_dirs; do
     includes="$includes -I @abs_top_srcdir@/$i -I @abs_top_builddir@/$i"
 done
@@ -58,7 +63,16 @@ rm -f $output $output-t
 
 echo "# OCaml dependencies generated by $0" > $output-t
 echo >> $output-t
- at OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" >> $output-t
+
+# Rewrite paths for everything that is generated
+ at OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" \
+    | sed -e "s, at abs_top_srcdir@/${subdir},.,g" \
+          -e "s, at abs_top_srcdir@/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),${top_builddir}/\\1\\2,g" \
+          -e "s,${srcdir_re}/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),\\1\\2,g" \
+          -e 's, ./, ,g' \
+          -e "s,${srcdir_re}/\\([^ /]*_config[.]ml\\),\\1,g" \
+    >> $output-t
+
 chmod -w $output-t
 
 mv $output-t $output
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index b2af7d7e2d..b0f2900f2e 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -26,7 +26,6 @@ generator_built = \
 
 EXTRA_DIST = \
 	$(generator_built) \
-	.depend \
 	guestfs-c.c guestfs-c.h \
 	html/.gitignore \
 	META.in \
@@ -171,7 +170,7 @@ check-valgrind:
 	$(MAKE) VG="@VG@" TESTS="$(test_progs_all)" check
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/resize/Makefile.am b/resize/Makefile.am
index e599e1142f..847fb313a7 100644
--- a/resize/Makefile.am
+++ b/resize/Makefile.am
@@ -144,7 +144,7 @@ check-valgrind:
 	$(MAKE) VG="@VG@" check
 
 # Dependencies.
-.depend: *.ml *.mli
+.depend: $(srcdir)/*.ml $(srcdir)/*.mli
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
index 2f73f97a67..2ab357a685 100644
--- a/sparsify/Makefile.am
+++ b/sparsify/Makefile.am
@@ -154,7 +154,7 @@ check-valgrind:
 	$(MAKE) VG="@VG@" check
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/subdir-rules.mk b/subdir-rules.mk
index a2382aa08c..ef3ba0941f 100644
--- a/subdir-rules.mk
+++ b/subdir-rules.mk
@@ -79,12 +79,12 @@ guestfs_am_v_jar = $(guestfs_am_v_jar_ at AM_V@)
 guestfs_am_v_jar_ = $(guestfs_am_v_jar_ at AM_DEFAULT_V@)
 guestfs_am_v_jar_0 = @echo "  JAR     " $@;
 
-%.cmi: %.mli
+%.cmi: $(srcdir)/%.mli
 	$(guestfs_am_v_ocamlcmi)$(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
-%.cmo: %.ml
+%.cmo: $(srcdir)/%.ml
 	$(guestfs_am_v_ocamlc)$(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
 if HAVE_OCAMLOPT
-%.cmx: %.ml
+%.cmx: $(srcdir)/%.ml
 	$(guestfs_am_v_ocamlopt)$(OCAMLFIND) ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
 endif
 
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 50611e7d2e..da34dd2645 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -542,7 +542,7 @@ v2v_unit_tests_LINK = \
 	  $(v2v_unit_tests_THEOBJECTS) -o $@
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/v2v/test-harness/Makefile.am b/v2v/test-harness/Makefile.am
index 5c38a7266b..d69188969e 100644
--- a/v2v/test-harness/Makefile.am
+++ b/v2v/test-harness/Makefile.am
@@ -126,7 +126,7 @@ stamp-virt-v2v-test-harness.pod: virt-v2v-test-harness.pod
 	touch $@
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
 	$(top_builddir)/ocaml-dep.sh -I .. $^
 -include .depend
 
-- 
2.17.0




More information about the Libguestfs mailing list