Richard W.M. Jones
2016-Jul-14 13:30 UTC
[Libguestfs] [PATCH 0/2] Build mllib and customize into libraries.
Simplifies the build a bit. This is on top of the previous SELinux relabelling patch set, although not related to it. Rich.
Richard W.M. Jones
2016-Jul-14 13:30 UTC
[Libguestfs] [PATCH 1/2] mllib: Build a mllib.cma/mllib.cmxa library.
Instead of linking with individual objects, which is very tedious, build a proper library and link the other tools with it. This doesn't make the resulting binaries any larger. --- .gitignore | 2 +- builder/Makefile.am | 26 ++----------- customize/Makefile.am | 20 ++-------- dib/Makefile.am | 17 ++------- dib/dummy.c | 2 + get-kernel/Makefile.am | 21 ++--------- get-kernel/dummy.c | 2 + mllib/Makefile.am | 88 ++++++++++++++++++++++---------------------- resize/Makefile.am | 25 ++----------- resize/dummy.c | 2 + sparsify/Makefile.am | 22 ++--------- sparsify/dummy.c | 2 + sysprep/Makefile.am | 19 +--------- v2v/Makefile.am | 41 +-------------------- v2v/test-harness/Makefile.am | 7 ---- 15 files changed, 79 insertions(+), 217 deletions(-) create mode 100644 dib/dummy.c create mode 100644 get-kernel/dummy.c create mode 100644 resize/dummy.c create mode 100644 sparsify/dummy.c diff --git a/.gitignore b/.gitignore index 7f1919d..000e984 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ bindtests.tmp cscope.out .deps .dirstamp +dll*.so .gdb_history .libs Makefile @@ -590,7 +591,6 @@ Makefile.in /v2v/stamp-virt-v2v-copy-to-local.pod /v2v/test-harness/.depend /v2v/test-harness/META -/v2v/test-harness/dllv2v_test_harness.so /v2v/test-harness/stamp-virt-v2v-test-harness.pod /v2v/test-harness/virt-v2v-test-harness.1 /v2v/v2v_unit_tests diff --git a/builder/Makefile.am b/builder/Makefile.am index 71f3f4c..d95ab29 100644 --- a/builder/Makefile.am +++ b/builder/Makefile.am @@ -89,15 +89,10 @@ SOURCES_ML = \ builder.ml SOURCES_C = \ - ../mllib/dev_t-c.c \ - ../mllib/fsync-c.c \ - ../mllib/getopt-c.c \ - ../mllib/uri-c.c \ - ../mllib/mkdtemp-c.c \ ../customize/perl_edit-c.c \ ../customize/crypt-c.c \ - ../fish/uri.c \ ../fish/file-edit.c \ + ../fish/file-edit.h \ index-scan.c \ index-struct.c \ index-parse.c \ @@ -133,21 +128,6 @@ virt_builder_CFLAGS = \ $(YAJL_CFLAGS) BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/libdir.cmo \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/fsync.cmo \ - $(top_builddir)/mllib/planner.cmo \ - $(top_builddir)/mllib/regedit.cmo \ - $(top_builddir)/mllib/JSON.cmo \ - $(top_builddir)/mllib/URI.cmo \ - $(top_builddir)/mllib/mkdtemp.cmo \ - $(top_builddir)/mllib/curl.cmo \ $(top_builddir)/customize/customize_utils.cmo \ $(top_builddir)/customize/urandom.cmo \ $(top_builddir)/customize/random_seed.cmo \ @@ -199,11 +179,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa endif virt_builder_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/customize/Makefile.am b/customize/Makefile.am index b8f8357..39547e9 100644 --- a/customize/Makefile.am +++ b/customize/Makefile.am @@ -68,12 +68,8 @@ SOURCES_ML = \ customize_main.ml SOURCES_C = \ - ../fish/uri.c \ ../fish/file-edit.c \ ../fish/file-edit.h \ - ../mllib/dev_t-c.c \ - ../mllib/getopt-c.c \ - ../mllib/uri-c.c \ crypt-c.c \ perl_edit-c.c @@ -94,17 +90,7 @@ virt_customize_CFLAGS = \ $(LIBVIRT_CFLAGS) \ $(LIBXML2_CFLAGS) -BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/regedit.cmo \ - $(top_builddir)/mllib/URI.cmo \ - $(SOURCES_ML:.ml=.cmo) +BOBJECTS = $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) # -I $(top_builddir)/src/.libs is a hack which forces corresponding -L @@ -134,11 +120,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa endif virt_customize_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/dib/Makefile.am b/dib/Makefile.am index 9ff93ff..4cf052f 100644 --- a/dib/Makefile.am +++ b/dib/Makefile.am @@ -33,9 +33,7 @@ SOURCES_ML = \ dib.ml SOURCES_C = \ - ../mllib/dev_t-c.c \ - ../mllib/getopt-c.c \ - ../mllib/mkdtemp-c.c + dummy.c bin_PROGRAMS @@ -56,15 +54,6 @@ virt_dib_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/libdir.cmo \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/mkdtemp.cmo \ $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) @@ -93,11 +82,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa endif virt_dib_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/dib/dummy.c b/dib/dummy.c new file mode 100644 index 0000000..ebab619 --- /dev/null +++ b/dib/dummy.c @@ -0,0 +1,2 @@ +/* Dummy source, to be used for OCaml-based tools with no C sources. */ +enum { foo = 1 }; diff --git a/get-kernel/Makefile.am b/get-kernel/Makefile.am index f384016..2ad3ad0 100644 --- a/get-kernel/Makefile.am +++ b/get-kernel/Makefile.am @@ -27,10 +27,7 @@ SOURCES_ML = \ get_kernel.ml SOURCES_C = \ - ../mllib/dev_t-c.c \ - ../mllib/getopt-c.c \ - ../mllib/uri-c.c \ - ../fish/uri.c + dummy.c man_MANS noinst_DATA @@ -54,17 +51,7 @@ virt_get_kernel_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ $(LIBXML2_CFLAGS) -BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/libdir.cmo \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/URI.cmo \ - $(SOURCES_ML:.ml=.cmo) +BOBJECTS = $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) # -I $(top_builddir)/src/.libs is a hack which forces corresponding -L @@ -92,11 +79,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa endif virt_get_kernel_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/get-kernel/dummy.c b/get-kernel/dummy.c new file mode 100644 index 0000000..ebab619 --- /dev/null +++ b/get-kernel/dummy.c @@ -0,0 +1,2 @@ +/* Dummy source, to be used for OCaml-based tools with no C sources. */ +enum { foo = 1 }; diff --git a/mllib/Makefile.am b/mllib/Makefile.am index 6052663..4f50c52 100644 --- a/mllib/Makefile.am +++ b/mllib/Makefile.am @@ -24,7 +24,7 @@ EXTRA_DIST = \ common_utils_tests.ml \ JSON_tests.ml -CLEANFILES = *~ *.annot *.cmi *.cmo *.cmx *.cmxa *.o +CLEANFILES = *~ *.annot *.cmi *.cmo *.cmx *.cmxa *.o dll*.so SOURCES_MLI = \ common_utils.mli \ @@ -73,22 +73,33 @@ SOURCES_C = \ if HAVE_OCAML -# Note - we're not actually building a functioning program here, we're -# just linking everything together to check all the modules build OK. +# 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_PROGRAMS = dummy +noinst_LIBRARIES = libmllib.a -dummy_SOURCES = $(SOURCES_C) -dummy_CPPFLAGS = \ +if !HAVE_OCAMLOPT +MLLIB_CMA = mllib.cma +else +MLLIB_CMA = mllib.cmxa +endif + +noinst_DATA = $(MLLIB_CMA) + +libmllib_a_SOURCES = $(SOURCES_C) +libmllib_a_CPPFLAGS = \ -I. \ -I$(top_builddir) \ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \ -I$(shell $(OCAMLC) -where) \ -I$(top_srcdir)/src \ -I$(top_srcdir)/fish -dummy_CFLAGS = \ +libmllib_a_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ - $(LIBVIRT_CFLAGS) $(LIBXML2_CFLAGS) + $(LIBVIRT_CFLAGS) $(LIBXML2_CFLAGS) \ + -fPIC BOBJECTS = $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) @@ -100,8 +111,9 @@ OCAMLPACKAGES = \ -package str,unix \ -I $(top_builddir)/src/.libs \ -I $(top_builddir)/gnulib/lib/.libs \ - -I $(top_builddir)/ocaml -OCAMLPACKAGES_TESTS + -I $(top_builddir)/ocaml \ + -I $(builddir) +OCAMLPACKAGES_TESTS = $(MLLIB_CMA) if HAVE_OCAML_PKG_GETTEXT OCAMLPACKAGES += -package gettext-stub endif @@ -122,19 +134,15 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) -BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom else OBJECTS = $(XOBJECTS) -BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa endif -dummy_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh -dummy_LINK = \ - $(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \ - $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \ - $(OBJECTS) -o $@ +libmllib_a_DEPENDENCIES = $(OBJECTS) + +$(MLLIB_CMA): $(OBJECTS) libmllib.a + $(OCAMLFIND) mklib -g $(OCAMLPACKAGES) \ + $(OBJECTS) $(libmllib_a_OBJECTS) -o mllib # This OCaml module has to be generated by make (configure will put # unexpanded prefix macro in). @@ -145,56 +153,50 @@ libdir.ml: Makefile # Tests. -common_utils_tests_SOURCES = \ - dev_t-c.c \ - getopt-c.c \ - dummy.c +common_utils_tests_SOURCES = dummy.c common_utils_tests_CPPFLAGS = \ -I. \ -I$(top_builddir) \ -I$(shell $(OCAMLC) -where) \ -I$(top_srcdir)/src -common_utils_tests_BOBJECTS = \ - guestfs_config.cmo \ - common_gettext.cmo \ - dev_t.cmo \ - stringMap.cmo \ - getopt.cmo \ - common_utils.cmo \ - common_utils_tests.cmo +common_utils_tests_BOBJECTS = common_utils_tests.cmo common_utils_tests_XOBJECTS = $(common_utils_tests_BOBJECTS:.cmo=.cmx) JSON_tests_SOURCES = dummy.c -JSON_tests_BOBJECTS = \ - JSON.cmo \ - JSON_tests.cmo +JSON_tests_BOBJECTS = JSON_tests.cmo JSON_tests_XOBJECTS = $(JSON_tests_BOBJECTS:.cmo=.cmx) # Can't call the following as <test>_OBJECTS because automake gets confused. -if HAVE_OCAMLOPT -common_utils_tests_THEOBJECTS = $(common_utils_tests_XOBJECTS) -common_utils_tests.cmx: OCAMLPACKAGES += $(OCAMLPACKAGES_TESTS) - -JSON_tests_THEOBJECTS = $(JSON_tests_XOBJECTS) -JSON_tests.cmx: OCAMLPACKAGES += $(OCAMLPACKAGES_TESTS) -else +if !HAVE_OCAMLOPT common_utils_tests_THEOBJECTS = $(common_utils_tests_BOBJECTS) common_utils_tests.cmo: OCAMLPACKAGES += $(OCAMLPACKAGES_TESTS) JSON_tests_THEOBJECTS = $(JSON_tests_BOBJECTS) JSON_tests.cmo: OCAMLPACKAGES += $(OCAMLPACKAGES_TESTS) +BEST = c +OCAMLLINKFLAGS = mlguestfs.cma -custom +else +common_utils_tests_THEOBJECTS = $(common_utils_tests_XOBJECTS) +common_utils_tests.cmx: OCAMLPACKAGES += $(OCAMLPACKAGES_TESTS) + +JSON_tests_THEOBJECTS = $(JSON_tests_XOBJECTS) +JSON_tests.cmx: OCAMLPACKAGES += $(OCAMLPACKAGES_TESTS) +BEST = opt +OCAMLLINKFLAGS = mlguestfs.cmxa endif common_utils_tests_DEPENDENCIES = $(common_utils_tests_THEOBJECTS) $(top_srcdir)/ocaml-link.sh common_utils_tests_LINK = \ $(top_srcdir)/ocaml-link.sh -cclib '-lutils $(LIBXML2_LIBS) -lgnu' -- \ - $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLPACKAGES_TESTS) $(OCAMLLINKFLAGS) \ + $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLLINKFLAGS) \ + $(OCAMLPACKAGES) $(OCAMLPACKAGES_TESTS) \ $(common_utils_tests_THEOBJECTS) -o $@ JSON_tests_DEPENDENCIES = $(JSON_tests_THEOBJECTS) $(top_srcdir)/ocaml-link.sh JSON_tests_LINK = \ $(top_srcdir)/ocaml-link.sh -- \ - $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLPACKAGES_TESTS) $(OCAMLLINKFLAGS) \ + $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLLINKFLAGS) \ + $(OCAMLPACKAGES) $(OCAMLPACKAGES_TESTS) \ $(JSON_tests_THEOBJECTS) -o $@ TESTS_ENVIRONMENT = $(top_builddir)/run --test diff --git a/resize/Makefile.am b/resize/Makefile.am index f2d6ec0..20d264b 100644 --- a/resize/Makefile.am +++ b/resize/Makefile.am @@ -30,13 +30,7 @@ SOURCES_ML = \ resize.ml SOURCES_C = \ - ../mllib/dev_t-c.c \ - ../mllib/fsync-c.c \ - ../mllib/getopt-c.c \ - ../fish/progress.c \ - ../mllib/progress-c.c \ - ../fish/uri.c \ - ../mllib/uri-c.c + dummy.c if HAVE_OCAML @@ -54,18 +48,7 @@ virt_resize_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ $(LIBXML2_CFLAGS) -BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/fsync.cmo \ - $(top_builddir)/mllib/progress.cmo \ - $(top_builddir)/mllib/URI.cmo \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(SOURCES_ML:.ml=.cmo) +BOBJECTS = $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) # -I $(top_builddir)/src/.libs is a hack which forces corresponding -L @@ -93,11 +76,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa endif virt_resize_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/resize/dummy.c b/resize/dummy.c new file mode 100644 index 0000000..ebab619 --- /dev/null +++ b/resize/dummy.c @@ -0,0 +1,2 @@ +/* Dummy source, to be used for OCaml-based tools with no C sources. */ +enum { foo = 1 }; diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am index 82fbc39..5c03394 100644 --- a/sparsify/Makefile.am +++ b/sparsify/Makefile.am @@ -36,11 +36,7 @@ SOURCES_ML = \ sparsify.ml SOURCES_C = \ - ../fish/progress.c \ - ../mllib/dev_t-c.c \ - ../mllib/getopt-c.c \ - ../mllib/progress-c.c \ - ../mllib/statvfs-c.c + dummy.c if HAVE_OCAML @@ -56,17 +52,7 @@ virt_sparsify_CPPFLAGS = \ virt_sparsify_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) -BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/progress.cmo \ - $(top_builddir)/mllib/StatVFS.cmo \ - $(SOURCES_ML:.ml=.cmo) +BOBJECTS = $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) # -I $(top_builddir)/src/.libs is a hack which forces corresponding -L @@ -94,11 +80,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa endif virt_sparsify_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/sparsify/dummy.c b/sparsify/dummy.c new file mode 100644 index 0000000..ebab619 --- /dev/null +++ b/sparsify/dummy.c @@ -0,0 +1,2 @@ +/* Dummy source, to be used for OCaml-based tools with no C sources. */ +enum { foo = 1 }; diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index ca49188..b4072f7 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -80,13 +80,8 @@ SOURCES_ML = \ main.ml SOURCES_C = \ - ../mllib/dev_t-c.c \ - ../mllib/getopt-c.c \ - ../mllib/uri-c.c \ - ../mllib/mkdtemp-c.c \ ../customize/crypt-c.c \ ../customize/perl_edit-c.c \ - ../fish/uri.c \ ../fish/file-edit.c if HAVE_OCAML @@ -106,16 +101,6 @@ virt_sysprep_CFLAGS = \ $(LIBXML2_CFLAGS) BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/URI.cmo \ - $(top_builddir)/mllib/mkdtemp.cmo \ - $(top_builddir)/mllib/regedit.cmo \ $(top_builddir)/customize/customize_utils.cmo \ $(top_builddir)/customize/crypt.cmo \ $(top_builddir)/customize/urandom.cmo \ @@ -160,11 +145,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa endif virt_sysprep_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/v2v/Makefile.am b/v2v/Makefile.am index e7ccbf5..d5d4c04 100644 --- a/v2v/Makefile.am +++ b/v2v/Makefile.am @@ -94,10 +94,6 @@ SOURCES_ML = \ v2v.ml SOURCES_C = \ - ../mllib/dev_t-c.c \ - ../mllib/getopt-c.c \ - ../mllib/mkdtemp-c.c \ - ../mllib/statvfs-c.c \ domainxml-c.c \ changeuid-c.c \ utils-c.c \ @@ -119,18 +115,6 @@ virt_v2v_CFLAGS = \ $(LIBVIRT_CFLAGS) BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/regedit.cmo \ - $(top_builddir)/mllib/mkdtemp.cmo \ - $(top_builddir)/mllib/JSON.cmo \ - $(top_builddir)/mllib/StatVFS.cmo \ - $(top_builddir)/mllib/curl.cmo \ $(top_builddir)/customize/customize_utils.cmo \ $(top_builddir)/customize/firstboot.cmo \ $(top_builddir)/customize/SELinux_relabel.cmo \ @@ -163,11 +147,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa endif virt_v2v_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh @@ -177,9 +161,6 @@ virt_v2v_LINK = \ $(OBJECTS) -o $@ virt_v2v_copy_to_local_SOURCES = \ - ../mllib/dev_t-c.c \ - ../mllib/statvfs-c.c \ - ../mllib/getopt-c.c \ domainxml-c.c \ utils-c.c \ xml-c.c @@ -194,16 +175,6 @@ virt_v2v_copy_to_local_CFLAGS = \ $(LIBVIRT_CFLAGS) COPY_TO_LOCAL_BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/JSON.cmo \ - $(top_builddir)/mllib/StatVFS.cmo \ - $(top_builddir)/mllib/curl.cmo \ xml.cmo \ utils.cmo \ vCenter.cmo \ @@ -410,14 +381,6 @@ check_PROGRAMS += v2v_unit_tests endif v2v_unit_tests_BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/getopt.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ - $(top_builddir)/mllib/regedit.cmo \ types.cmo \ xml.cmo \ utils.cmo \ diff --git a/v2v/test-harness/Makefile.am b/v2v/test-harness/Makefile.am index dcbe884..55cd108 100644 --- a/v2v/test-harness/Makefile.am +++ b/v2v/test-harness/Makefile.am @@ -58,12 +58,6 @@ OCAMLPACKAGES = \ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) BOBJECTS = \ - $(OCAML_BYTES_COMPAT_CMO) \ - $(top_builddir)/mllib/guestfs_config.cmo \ - $(top_builddir)/mllib/common_gettext.cmo \ - $(top_builddir)/mllib/dev_t.cmo \ - $(top_builddir)/mllib/stringMap.cmo \ - $(top_builddir)/mllib/common_utils.cmo \ $(top_builddir)/v2v/xml.cmo \ $(SOURCES_ML:.ml=.cmo) \ $(libv2vth_a_OBJECTS) @@ -97,7 +91,6 @@ libv2vth_a_CFLAGS = \ -fPIC libv2vth_a_SOURCES = \ - ../../mllib/dev_t-c.c \ ../xml-c.c v2v_test_harness.cmi: $(top_builddir)/ocaml/guestfs.cmi -- 2.7.4
Richard W.M. Jones
2016-Jul-14 13:30 UTC
[Libguestfs] [PATCH 2/2] customize: Build a customize.cma/customize.cmxa library.
Instead of linking with individual objects, which is very tedious, build a proper library and link virt-builder, virt-customize and virt-sysprep to it. This makes the binaries a tiny bit smaller because .cmxa/.a files allow unused code to be removed by the linker, whereas explicitly linking .cmx/.o files does not. --- builder/Makefile.am | 25 ++-------------- customize/Makefile.am | 81 +++++++++++++++++++++++++++++++++++++-------------- customize/dummy.c | 2 ++ sysprep/Makefile.am | 25 +++------------- sysprep/dummy.c | 2 ++ 5 files changed, 70 insertions(+), 65 deletions(-) create mode 100644 customize/dummy.c create mode 100644 sysprep/dummy.c diff --git a/builder/Makefile.am b/builder/Makefile.am index d95ab29..4e77f52 100644 --- a/builder/Makefile.am +++ b/builder/Makefile.am @@ -89,10 +89,6 @@ SOURCES_ML = \ builder.ml SOURCES_C = \ - ../customize/perl_edit-c.c \ - ../customize/crypt-c.c \ - ../fish/file-edit.c \ - ../fish/file-edit.h \ index-scan.c \ index-struct.c \ index-parse.c \ @@ -127,22 +123,7 @@ virt_builder_CFLAGS = \ $(LIBXML2_CFLAGS) \ $(YAJL_CFLAGS) -BOBJECTS = \ - $(top_builddir)/customize/customize_utils.cmo \ - $(top_builddir)/customize/urandom.cmo \ - $(top_builddir)/customize/random_seed.cmo \ - $(top_builddir)/customize/hostname.cmo \ - $(top_builddir)/customize/timezone.cmo \ - $(top_builddir)/customize/firstboot.cmo \ - $(top_builddir)/customize/perl_edit.cmo \ - $(top_builddir)/customize/crypt.cmo \ - $(top_builddir)/customize/password.cmo \ - $(top_builddir)/customize/SELinux_relabel.cmo \ - $(top_builddir)/customize/ssh_key.cmo \ - $(top_builddir)/customize/subscription_manager.cmo \ - $(top_builddir)/customize/customize_cmdline.cmo \ - $(top_builddir)/customize/customize_run.cmo \ - $(SOURCES_ML:.ml=.cmo) +BOBJECTS = $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) # -I $(top_builddir)/src/.libs is a hack which forces corresponding -L @@ -179,11 +160,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma customize.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa customize.cmxa endif virt_builder_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/customize/Makefile.am b/customize/Makefile.am index 39547e9..9c0d3c7 100644 --- a/customize/Makefile.am +++ b/customize/Makefile.am @@ -24,7 +24,7 @@ EXTRA_DIST = \ virt-customize.pod CLEANFILES = \ - *~ *.annot *.cmi *.cmo *.cmx *.cmxa *.o \ + *~ *.annot *.cmi *.cmo *.cmx *.cmxa *.o dll*.so \ stamp-virt-customize.pod \ virt-customize virt-customize.1 @@ -64,8 +64,7 @@ SOURCES_ML = \ subscription_manager.ml \ timezone.ml \ customize_cmdline.ml \ - customize_run.ml \ - customize_main.ml + customize_run.ml SOURCES_C = \ ../fish/file-edit.c \ @@ -75,24 +74,44 @@ SOURCES_C = \ if HAVE_OCAML -bin_PROGRAMS = virt-customize +# Build the virt-customize objects into a library, since these are +# reused by virt-builder and virt-sysprep. We pretend we are building +# a C library. automake handles the compilation of 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 = libcustomize.a -virt_customize_SOURCES = $(SOURCES_C) -virt_customize_CPPFLAGS = \ +if !HAVE_OCAMLOPT +CUSTOMIZE_CMA = customize.cma +else +CUSTOMIZE_CMA = customize.cmxa +endif + +noinst_DATA = $(CUSTOMIZE_CMA) + +libcustomize_a_SOURCES = $(SOURCES_C) +libcustomize_a_CPPFLAGS = \ -I. \ -I$(top_builddir) \ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \ -I$(shell $(OCAMLC) -where) \ -I$(top_srcdir)/src \ -I$(top_srcdir)/fish -virt_customize_CFLAGS = \ +libcustomize_a_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ $(LIBVIRT_CFLAGS) \ - $(LIBXML2_CFLAGS) + $(LIBXML2_CFLAGS) \ + -fPIC BOBJECTS = $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) +if !HAVE_OCAMLOPT +OBJECTS = $(BOBJECTS) +else +OBJECTS = $(XOBJECTS) +endif + # -I $(top_builddir)/src/.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. @@ -101,11 +120,36 @@ OCAMLPACKAGES = \ -I $(top_builddir)/src/.libs \ -I $(top_builddir)/gnulib/lib/.libs \ -I $(top_builddir)/ocaml \ - -I $(top_builddir)/mllib + -I $(top_builddir)/mllib \ + -I $(builddir) if HAVE_OCAML_PKG_GETTEXT OCAMLPACKAGES += -package gettext-stub endif +libcustomize_a_DEPENDENCIES = $(OBJECTS) + +$(CUSTOMIZE_CMA): $(OBJECTS) libcustomize.a + $(OCAMLFIND) mklib -g $(OCAMLPACKAGES) \ + $(OBJECTS) $(libcustomize_a_OBJECTS) -o customize + +# Build the virt-customize program. +bin_PROGRAMS = virt-customize + +virt_customize_SOURCES = dummy.c + +CUSTOMIZE_BOBJECTS = customize_main.cmo +CUSTOMIZE_XOBJECTS = $(BOBJECTS:.cmo=.cmx) + +if !HAVE_OCAMLOPT +CUSTOMIZE_THEOBJECTS = $(CUSTOMIZE_BOBJECTS) +BEST = c +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma customize.cma -custom +else +CUSTOMIZE_THEOBJECTS = $(CUSTOMIZE_XOBJECTS) +BEST = opt +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa customize.cmxa +endif + OCAMLCLIBS = \ -lutils \ $(LIBTINFO_LIBS) \ @@ -117,25 +161,18 @@ OCAMLCLIBS = \ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) -if !HAVE_OCAMLOPT -OBJECTS = $(BOBJECTS) -BEST = c -OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom -else -OBJECTS = $(XOBJECTS) -BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa -endif - -virt_customize_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh +virt_customize_DEPENDENCIES = \ + $(top_srcdir)/ocaml-link.sh \ + $(CUSTOMIZE_THEOBJECTS) \ + $(CUSTOMIZE_CMA) virt_customize_LINK = \ $(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \ $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \ - $(OBJECTS) -o $@ + $(CUSTOMIZE_THEOBJECTS) -o $@ # Manual pages and HTML files for the website. man_MANS = virt-customize.1 -noinst_DATA = $(top_builddir)/website/virt-customize.1.html +noinst_DATA += $(top_builddir)/website/virt-customize.1.html virt-customize.1 $(top_builddir)/website/virt-customize.1.html: stamp-virt-customize.pod diff --git a/customize/dummy.c b/customize/dummy.c new file mode 100644 index 0000000..ebab619 --- /dev/null +++ b/customize/dummy.c @@ -0,0 +1,2 @@ +/* Dummy source, to be used for OCaml-based tools with no C sources. */ +enum { foo = 1 }; diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index b4072f7..25193b2 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -80,9 +80,7 @@ SOURCES_ML = \ main.ml SOURCES_C = \ - ../customize/crypt-c.c \ - ../customize/perl_edit-c.c \ - ../fish/file-edit.c + dummy.c if HAVE_OCAML @@ -100,22 +98,7 @@ virt_sysprep_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ $(LIBXML2_CFLAGS) -BOBJECTS = \ - $(top_builddir)/customize/customize_utils.cmo \ - $(top_builddir)/customize/crypt.cmo \ - $(top_builddir)/customize/urandom.cmo \ - $(top_builddir)/customize/password.cmo \ - $(top_builddir)/customize/random_seed.cmo \ - $(top_builddir)/customize/hostname.cmo \ - $(top_builddir)/customize/timezone.cmo \ - $(top_builddir)/customize/firstboot.cmo \ - $(top_builddir)/customize/perl_edit.cmo \ - $(top_builddir)/customize/SELinux_relabel.cmo \ - $(top_builddir)/customize/ssh_key.cmo \ - $(top_builddir)/customize/subscription_manager.cmo \ - $(top_builddir)/customize/customize_cmdline.cmo \ - $(top_builddir)/customize/customize_run.cmo \ - $(SOURCES_ML:.ml=.cmo) +BOBJECTS = $(SOURCES_ML:.ml=.cmo) XOBJECTS = $(BOBJECTS:.cmo=.cmx) # -I $(top_builddir)/src/.libs is a hack which forces corresponding -L @@ -145,11 +128,11 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) if !HAVE_OCAMLOPT OBJECTS = $(BOBJECTS) BEST = c -OCAMLLINKFLAGS = mlguestfs.cma mllib.cma -custom +OCAMLLINKFLAGS = mlguestfs.cma mllib.cma customize.cma -custom else OBJECTS = $(XOBJECTS) BEST = opt -OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa +OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa customize.cmxa endif virt_sysprep_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh diff --git a/sysprep/dummy.c b/sysprep/dummy.c new file mode 100644 index 0000000..ebab619 --- /dev/null +++ b/sysprep/dummy.c @@ -0,0 +1,2 @@ +/* Dummy source, to be used for OCaml-based tools with no C sources. */ +enum { foo = 1 }; -- 2.7.4
Seemingly Similar Threads
- [PATCH 1/2] build: Fix dependencies on mllib and customize.
- [PATCH 0/5] Miscellaneous refactoring of common/utils, create common/mltools
- [PATCH 1/2] build: factor out the OCaml link.sh scripts
- [PATCH 1/2] mllib: tests: add tests for string_lines_split
- [PATCH 00/12] Refactor utility functions.