- Add $(srcdir), $(builddir) to Makefiles where required
- Post-process ocamldep output
- generate ocaml/.depends
Gbp-Pq: Name 0012-Fix-out-of-tree-builds-of-OCaml-components.patch
---
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 | 24 ++++++++++++++++++++++--
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, 50 insertions(+), 30 deletions(-)
diff --git a/builder/Makefile.am b/builder/Makefile.am
index ceb3bce68..e5872bdd9 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 4cca6b4db..cdcea33ec 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 4ff74cf97..f9699f592 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 f031a5a69..be88ef2de 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 cc05c5a73..e38230db8 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 2ea1fee8f..66b18f5de 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 33d742f4c..8627e5b10 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 6902c9a2a..add1fe56e 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 083c7a64b..eab036b82 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 7f18b2fc3..efdd27227 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 c534baab0..94ee866a0 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 fba807f18..c2d10966a 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 03d4b9815..81dfb48b4 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 92037b785..9bd35ba27 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,22 @@ rm -f $output $output-t
echo "# OCaml dependencies generated by $0" > $output-t
echo >> $output-t
-@OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" >>
$output-t
+
+# Rewrite paths
+# 1. Normalize absolute srcdir to relative path
+# 2. Object files (*.cm*, *.o), in srcdir: Rewrite to builddir
+# 3. Generated _config.ml in srcdir: Rewrite to builddir
+# 4. Other object files below abs_top_srcdir: rewrite to corresponding builddir
+# 5. Eliminate "./" prefix
+@OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" \
+ | sed \
+ -e "s,@abs_top_srcdir(a)/${subdir},.,g" \
+ -e "s,\B${srcdir_re}/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),\\1\\2,g" \
+ -e "s,\B${srcdir_re}/\\([^ /]*_config[.]ml\\),\\1,g" \
+ -e "s,@abs_top_srcdir@/\\([^ ]*[.]\\)\\(cm[^
]*\\|o\\),${top_builddir}/\\1\\2,g" \
+ -e 's,\(^\| \)./,\1,g' \
+ >> $output-t
+
chmod -w $output-t
mv $output-t $output
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index b2af7d7e2..b0f2900f2 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 e599e1142..847fb313a 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 2f73f97a6..2ab357a68 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 a2382aa08..ef3ba0941 100644
--- a/subdir-rules.mk
+++ b/subdir-rules.mk
@@ -79,12 +79,12 @@ guestfs_am_v_jar = $(guestfs_am_v_jar_@AM_V@)
guestfs_am_v_jar_ = $(guestfs_am_v_jar_@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 3a978d727..341a735ab 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -536,7 +536,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 5c38a7266..d69188969 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.11.0