[Libguestfs] [PATCH v6 02/41] mllib: Move Progress OCaml bindings to common/mlprogress.

Richard W.M. Jones
Thu, 15 Jun 2017 17:05:52 -0000

The ‘Progress’ module is a self-contained library with the only
dependencies being:

 - the C ‘progress’ implementation

Move it to a separate ‘common/mlprogress’ directory.

This change is pure code refactoring.
---
 .gitignore                                |   1 +
 Makefile.am                               |   1 +
 common/mlprogress/Makefile.am             | 111 ++++++++++++++++++++++++++++++
 {mllib => common/mlprogress}/progress-c.c |   0
 {mllib => common/mlprogress}/progress.ml  |   0
 {mllib => common/mlprogress}/progress.mli |   0
 configure.ac                              |   1 +
 docs/C_SOURCE_FILES                       |   2 +-
 docs/guestfs-hacking.pod                  |   4 ++
 mllib/Makefile.am                         |   7 +-
 resize/Makefile.am                        |   9 ++-
 sparsify/Makefile.am                      |   9 ++-
 12 files changed, 136 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore
index 2367cddcb..ea245c49d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -124,6 +124,7 @@ Makefile.in
 /common/errnostring/errnostring-gperf.gperf
 /common/errnostring/errnostring.h
 /common/miniexpect/miniexpect.3
+/common/mlprogress/.depend
 /common/mlvisit/.depend
 /common/mlvisit/visit_tests
 /common/protocol/guestfs_protocol.c
diff --git a/Makefile.am b/Makefile.am
index 499a1d279..bd0fc94e7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -154,6 +154,7 @@ SUBDIRS += csharp
 # shared code used by other OCaml tools, so these must come first.
 if HAVE_OCAML
 SUBDIRS += \
+	common/mlprogress \
 	common/mlvisit \
 	mllib \
 	customize \
diff --git a/common/mlprogress/Makefile.am b/common/mlprogress/Makefile.am
new file mode 100644
index 000000000..d4a229451
--- /dev/null
+++ b/common/mlprogress/Makefile.am
@@ -0,0 +1,111 @@
+# libguestfs OCaml tools common code
+# Copyright (C) 2011-2017 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+include $(top_srcdir)/subdir-rules.mk
+
+EXTRA_DIST = \
+	$(SOURCES_MLI) \
+	$(SOURCES_ML) \
+	$(SOURCES_C)
+
+SOURCES_MLI = \
+	progress.mli
+
+SOURCES_ML = \
+	progress.ml
+
+SOURCES_C = \
+	progress-c.c
+
+if HAVE_OCAML
+
+# We pretend that we're building a C library.  automake handles the
+# compilation of the C sources for us.  At the end we take the C
+# objects and OCaml objects and link them into the OCaml library.
+# This C library is never used.
+
+noinst_LIBRARIES = libmlprogress.a
+
+if !HAVE_OCAMLOPT
+MLPROGRESS_CMA = mlprogress.cma
+else
+MLPROGRESS_CMA = mlprogress.cmxa
+endif
+
+noinst_DATA = $(MLPROGRESS_CMA)
+
+libmlprogress_a_SOURCES = $(SOURCES_C)
+libmlprogress_a_CPPFLAGS = \
+	-I. \
+	-I$(top_builddir) \
+	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
+	-I$(shell $(OCAMLC) -where) \
+	-I$(top_srcdir)/common/utils \
+	-I$(top_srcdir)/lib \
+	-I$(top_srcdir)/common/progress
+libmlprogress_a_CFLAGS = \
+	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
+	$(LIBVIRT_CFLAGS) $(LIBXML2_CFLAGS) \
+	-fPIC
+
+BOBJECTS = $(SOURCES_ML:.ml=.cmo)
+XOBJECTS = $(BOBJECTS:.cmo=.cmx)
+
+# -I $(top_builddir)/lib/.libs is a hack which forces corresponding -L
+# option to be passed to gcc, so we don't try linking against an
+# installed copy of libguestfs.
+OCAMLPACKAGES = \
+	-package str,unix \
+	-I $(top_builddir)/common/utils/.libs \
+	-I $(top_builddir)/lib/.libs \
+	-I $(top_builddir)/gnulib/lib/.libs \
+	-I $(top_builddir)/ocaml \
+	-I $(builddir)
+
+OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR)
+
+if !HAVE_OCAMLOPT
+OBJECTS = $(BOBJECTS)
+else
+OBJECTS = $(XOBJECTS)
+endif
+
+libmlprogress_a_DEPENDENCIES = $(OBJECTS)
+
+$(MLPROGRESS_CMA): $(OBJECTS) libmlprogress.a
+	$(OCAMLFIND) mklib $(OCAMLPACKAGES) \
+	    $(OBJECTS) $(libmlprogress_a_OBJECTS) \
+	    -cclib -lprogress \
+	    -o mlprogress
+
+# Dependencies.
+depend: .depend
+
+.depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
+	rm -f $@ $@-t
+	$(OCAMLFIND) ocamldep -I ../../ocaml -I $(abs_srcdir) $^ | \
+	  $(SED) 's/ *$$//' | \
+	  $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
+	  $(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \
+	  sort > $@-t
+	mv $@-t $@
+
+-include .depend
+
+endif
+
+.PHONY: depend docs
diff --git a/mllib/progress-c.c b/common/mlprogress/progress-c.c
similarity index 100%
rename from mllib/progress-c.c
rename to common/mlprogress/progress-c.c
diff --git a/mllib/progress.ml b/common/mlprogress/progress.ml
similarity index 100%
rename from mllib/progress.ml
rename to common/mlprogress/progress.ml
diff --git a/mllib/progress.mli b/common/mlprogress/progress.mli
similarity index 100%
rename from mllib/progress.mli
rename to common/mlprogress/progress.mli
diff --git a/configure.ac b/configure.ac
index 4fc226123..1abb72671 100644
--- a/configure.ac
+++ b/configure.ac
@@ -185,6 +185,7 @@ AC_CONFIG_FILES([Makefile
                  common/errnostring/Makefile
                  common/edit/Makefile
                  common/miniexpect/Makefile
+                 common/mlprogress/Makefile
                  common/mlvisit/Makefile
                  common/options/Makefile
                  common/parallel/Makefile
diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES
index 578126403..1e2a99e7e 100644
--- a/docs/C_SOURCE_FILES
+++ b/docs/C_SOURCE_FILES
@@ -15,6 +15,7 @@ common/edit/file-edit.c
 common/edit/file-edit.h
 common/miniexpect/miniexpect.c
 common/miniexpect/miniexpect.h
+common/mlprogress/progress-c.c
 common/mlvisit/dummy.c
 common/mlvisit/visit-c.c
 common/options/config.c
@@ -339,7 +340,6 @@ make-fs/make-fs.c
 mllib/common_utils-c.c
 mllib/dummy.c
 mllib/getopt-c.c
-mllib/progress-c.c
 mllib/unix_utils-c.c
 mllib/uri-c.c
 mllib/xml-c.c
diff --git a/docs/guestfs-hacking.pod b/docs/guestfs-hacking.pod
index ac6d1ccbf..f9cb88f05 100644
--- a/docs/guestfs-hacking.pod
+++ b/docs/guestfs-hacking.pod
@@ -100,6 +100,10 @@ A copy of the miniexpect library from
 L<http://git.annexia.org/?p=miniexpect.git;a=summary>.  This is used
 in virt-p2v.

+=item F<common/mlprogress>
+
+OCaml bindings for the progress bar functions (see F<common/progress>).
+
 =item F<common/mlvisit>

 OCaml bindings for the visit functions (see F<common/visit>).
diff --git a/mllib/Makefile.am b/mllib/Makefile.am
index cb79f50f5..42f450323 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -36,7 +36,6 @@ SOURCES_MLI = \
 	getopt.mli \
 	JSON.mli \
 	planner.mli \
-	progress.mli \
 	regedit.mli \
 	registry.mli \
 	stringMap.mli \
@@ -51,7 +50,6 @@ SOURCES_ML = \
 	getopt.ml \
 	unix_utils.ml \
 	common_utils.ml \
-	progress.ml \
 	URI.ml \
 	planner.ml \
 	registry.ml \
@@ -66,10 +64,8 @@ SOURCES_C = \
 	../common/options/decrypt.c \
 	../common/options/keys.c \
 	../common/options/uri.c \
-	../common/progress/progress.c \
 	common_utils-c.c \
 	getopt-c.c \
-	progress-c.c \
 	unix_utils-c.c \
 	uri-c.c \
 	xml-c.c
@@ -99,8 +95,7 @@ libmllib_a_CPPFLAGS = \
 	-I$(shell $(OCAMLC) -where) \
 	-I$(top_srcdir)/common/utils \
 	-I$(top_srcdir)/lib \
-	-I$(top_srcdir)/common/options \
-	-I$(top_srcdir)/common/progress
+	-I$(top_srcdir)/common/options
 libmllib_a_CFLAGS = \
 	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
 	$(LIBVIRT_CFLAGS) $(LIBXML2_CFLAGS) \
diff --git a/resize/Makefile.am b/resize/Makefile.am
index e097dd611..c35c3a78a 100644
--- a/resize/Makefile.am
+++ b/resize/Makefile.am
@@ -57,15 +57,18 @@ XOBJECTS = $(BOBJECTS:.cmo=.cmx)
 OCAMLPACKAGES = \
 	-package str,unix \
 	-I $(top_builddir)/common/utils/.libs \
+	-I $(top_builddir)/common/progress/.libs \
 	-I $(top_builddir)/lib/.libs \
 	-I $(top_builddir)/gnulib/lib/.libs \
 	-I $(top_builddir)/ocaml \
+	-I $(top_builddir)/common/mlprogress \
 	-I $(top_builddir)/mllib
 if HAVE_OCAML_PKG_GETTEXT
 OCAMLPACKAGES += -package gettext-stub
 endif

 OCAMLCLIBS = \
+	-lprogress \
 	-lutils \
 	$(LIBTINFO_LIBS) \
 	$(LIBXML2_LIBS) \
@@ -80,7 +83,11 @@ else
 OBJECTS = $(XOBJECTS)
 endif

-OCAMLLINKFLAGS = mlguestfs.$(MLARCHIVE) mllib.$(MLARCHIVE)
$(LINK_CUSTOM_OCAMLC_ONLY)
+OCAMLLINKFLAGS = \
+	mlguestfs.$(MLARCHIVE) \
+	mlprogress.$(MLARCHIVE) \
+	mllib.$(MLARCHIVE) \
+	$(LINK_CUSTOM_OCAMLC_ONLY)

 virt_resize_DEPENDENCIES = \
 	$(OBJECTS) \
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
index b7229ffdd..97236829e 100644
--- a/sparsify/Makefile.am
+++ b/sparsify/Makefile.am
@@ -62,15 +62,18 @@ XOBJECTS = $(BOBJECTS:.cmo=.cmx)
 OCAMLPACKAGES = \
 	-package str,unix \
 	-I $(top_builddir)/common/utils/.libs \
+	-I $(top_builddir)/common/progress/.libs \
 	-I $(top_builddir)/lib/.libs \
 	-I $(top_builddir)/gnulib/lib/.libs \
 	-I $(top_builddir)/ocaml \
+	-I $(top_builddir)/common/mlprogress \
 	-I $(top_builddir)/mllib
 if HAVE_OCAML_PKG_GETTEXT
 OCAMLPACKAGES += -package gettext-stub
 endif

 OCAMLCLIBS = \
+	-lprogress \
 	-lutils \
 	$(LIBTINFO_LIBS) \
 	$(LIBXML2_LIBS) \
@@ -85,7 +88,11 @@ else
 OBJECTS = $(XOBJECTS)
 endif

-OCAMLLINKFLAGS = mlguestfs.$(MLARCHIVE) mllib.$(MLARCHIVE)
$(LINK_CUSTOM_OCAMLC_ONLY)
+OCAMLLINKFLAGS = \
+	mlguestfs.$(MLARCHIVE) \
+	mlprogress.$(MLARCHIVE) \
+	mllib.$(MLARCHIVE) \
+	$(LINK_CUSTOM_OCAMLC_ONLY)

 virt_sparsify_DEPENDENCIES = \
 	$(OBJECTS) \
--
2.13.0