[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [common PATCH] mlv2v: build as OCaml library



On Fri, Dec 13, 2019 at 11:08:34AM +0100, Pino Toscano wrote:
> While there is only one OCaml source, build it as small library: this
> way it is easier to use, and there is no need to copy the sources from
> here.
> ---
>  .gitignore        |  1 +
>  mlv2v/Makefile.am | 71 ++++++++++++++++++++++++++++++++++++++++++++---
>  mlv2v/dummy.c     |  2 ++
>  3 files changed, 70 insertions(+), 4 deletions(-)
>  create mode 100644 mlv2v/dummy.c
> 
> diff --git a/.gitignore b/.gitignore
> index 88c1c63..a788c55 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -60,6 +60,7 @@ Makefile.in
>  /mlutils/.depend
>  /mlutils/c_utils_unit_tests
>  /mlutils/oUnit-*
> +/mlv2v/.depend
>  /mlvisit/.depend
>  /mlvisit/visit_tests
>  /mlxml/.depend
> diff --git a/mlv2v/Makefile.am b/mlv2v/Makefile.am
> index 9e82148..945f981 100644
> --- a/mlv2v/Makefile.am
> +++ b/mlv2v/Makefile.am
> @@ -18,11 +18,74 @@
>  include $(top_srcdir)/subdir-rules.mk
>  
>  EXTRA_DIST = \
> -	$(generator_built)
> +	$(generator_built) \
> +	$(SOURCES_MLI) \
> +	$(SOURCES_ML) \
> +	$(SOURCES_C)
>  
> -# Note: These are not compiled into a library.  They are used directly
> -# by virt-v2v and are only located here because the files are
> -# generated (since the split).
>  generator_built = \
>  	uefi.mli \
>  	uefi.ml
> +
> +SOURCES_MLI = \
> +	uefi.mli
> +
> +SOURCES_ML = \
> +	uefi.ml
> +
> +SOURCES_C = \
> +	dummy.c
> +
> +# 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 = libmlv2v.a
> +
> +if !HAVE_OCAMLOPT
> +MLV2V_CMA = mlv2v.cma
> +else
> +MLV2V_CMA = mlv2v.cmxa
> +endif
> +
> +noinst_DATA = $(MLV2V_CMA)
> +
> +libmlv2v_a_SOURCES = $(SOURCES_C)
> +libmlv2v_a_CPPFLAGS = \
> +	-DCAML_NAME_SPACE \
> +	-I. \
> +	-I$(top_builddir) \
> +	-I$(shell $(OCAMLC) -where)
> +libmlv2v_a_CFLAGS = \
> +	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
> +	-fPIC
> +
> +BOBJECTS = $(SOURCES_ML:.ml=.cmo)
> +XOBJECTS = $(BOBJECTS:.cmo=.cmx)
> +
> +OCAMLPACKAGES = \
> +	-package str,unix \
> +	-I $(builddir)
> +OCAMLPACKAGES_TESTS = $(MLV2V_CMA)
> +
> +OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) -ccopt '$(CFLAGS)'
> +
> +if !HAVE_OCAMLOPT
> +OBJECTS = $(BOBJECTS)
> +else
> +OBJECTS = $(XOBJECTS)
> +endif
> +
> +libmlv2v_a_DEPENDENCIES = $(OBJECTS)
> +
> +$(MLV2V_CMA): $(OBJECTS) libmlv2v.a
> +	$(OCAMLFIND) mklib $(OCAMLPACKAGES) \
> +	    $(OBJECTS) $(libmlv2v_a_OBJECTS) -o mlv2v
> +
> +# OCaml dependencies.
> +.depend: $(srcdir)/*.mli $(srcdir)/*.ml
> +	$(top_builddir)/ocaml-dep.sh $^
> +-include .depend
> +
> +.PHONY: docs
> diff --git a/mlv2v/dummy.c b/mlv2v/dummy.c
> new file mode 100644
> index 0000000..ebab619
> --- /dev/null
> +++ b/mlv2v/dummy.c
> @@ -0,0 +1,2 @@
> +/* Dummy source, to be used for OCaml-based tools with no C sources. */
> +enum { foo = 1 };
> -- 

Makes sense, ACK, thanks.

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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]