Hilko Bengen
2018-Apr-09 14:22 UTC
[Libguestfs] [PATCH] Fix out-of-tree builds of OCaml components
- 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 -@OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" >> $output-t + +# Rewrite paths for everything that is generated +@OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" \ + | sed -e "s,@abs_top_srcdir@/${subdir},.,g" \ + -e "s,@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_@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 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
Richard W.M. Jones
2018-Apr-10 11:54 UTC
Re: [Libguestfs] [PATCH] Fix out-of-tree builds of OCaml components
This breaks in-tree builds because it generates some strange-looking dependencies, eg: GObject.cmo : utils.cmi types.cmi structs.cmi .common/mlstdutils/std_utils.cmi pr.cmi events.cmi docstrings.cmi actions.cmi GObject.cmi GObject.ml so you get errors like: make[2]: *** No rule to make target '.common/mlstdutils/std_utils.cmi', needed by 'utils.cmo'. Stop. I tried to poke the ocaml-deps.sh.in script to fix this but I couldn't work out where those dots are coming from ... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Hilko Bengen
2018-Apr-11 14:38 UTC
[Libguestfs] [PATCH] Fix out-of-tree builds of OCaml components
- 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@/${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
Maybe Matching Threads
- [PATCH] Fix out-of-tree builds of OCaml components
- [PATCH] build: build C sources using OCaml API with CAML_NAME_SPACE
- [PATCH] po: reduce the list of extracted sources
- [PATCH 0/5] Miscellaneous refactoring of common/utils, create common/mltools
- [v2v PATCH] po: do not extract tests