From 604bb7fd7b7087d8002cfbf5392a546819278943 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 12 Dec 2014 22:25:47 +0000 Subject: [PATCH] mllib: Use automake to build the library. --- .gitignore | 1 + configure.ac | 2 + mllib/Makefile.am | 159 +++++++++++++++++++++------------------------- mllib/link.sh.in | 22 +++++++ 4 files changed, 96 insertions(+), 88 deletions(-) create mode 100644 mllib/link.sh.in diff --git a/.gitignore b/.gitignore index 4ef8b373d..299df541d 100644 --- a/.gitignore +++ b/.gitignore @@ -309,6 +309,7 @@ Makefile.in /mllib/config.ml /mllib/dummy /mllib/libdir.ml +/mllib/link.sh /ocaml/bindtests.bc /ocaml/bindtests.opt /ocaml/bindtests.ml diff --git a/configure.ac b/configure.ac index fd4462881..01886ee68 100644 --- a/configure.ac +++ b/configure.ac @@ -1671,6 +1671,8 @@ AC_CONFIG_FILES([customize/link.sh], [chmod +x,-w customize/link.sh]) AC_CONFIG_FILES([inspector/test-xmllint.sh], [chmod +x,-w inspector/test-xmllint.sh]) +AC_CONFIG_FILES([mllib/link.sh], + [chmod +x,-w mllib/link.sh]) AC_CONFIG_FILES([p2v/virt-p2v-make-disk], [chmod +x,-w p2v/virt-p2v-make-disk]) AC_CONFIG_FILES([p2v/virt-p2v-make-kickstart], diff --git a/mllib/Makefile.am b/mllib/Makefile.am index b2b3271b6..e7180e43b 100644 --- a/mllib/Makefile.am +++ b/mllib/Makefile.am @@ -18,107 +18,103 @@ include $(top_srcdir)/subdir-rules.mk EXTRA_DIST = \ - $(filter-out config.ml,$(SOURCES)) + $(SOURCES_MLI) \ + $(filter-out config.ml libdir.ml,$(SOURCES_ML)) \ + $(SOURCES_C) \ + common_utils_tests.ml CLEANFILES = *~ *.annot *.cmi *.cmo *.cmx *.cmxa *.o -# Alphabetical order. -SOURCES = \ +SOURCES_MLI = \ + common_utils.mli \ + fsync.mli \ + JSON.mli \ + mkdtemp.mli \ + planner.mli \ + progress.mli \ + regedit.mli \ + uRI.mli + +SOURCES_ML = \ + config.ml \ + libdir.ml \ common_gettext.ml \ common_utils.ml \ - common_utils.mli \ - common_utils_tests.ml \ - config.ml \ - fsync-c.c \ - fsync.mli \ fsync.ml \ - JSON.mli \ - JSON.ml \ - mkdtemp.mli \ - mkdtemp.ml \ - mkdtemp-c.c \ - planner.mli \ - planner.ml \ - progress-c.c \ - progress.mli \ progress.ml \ - regedit.mli \ + uRI.ml \ + mkdtemp.ml \ + planner.ml \ regedit.ml \ - uri-c.c \ - uRI.mli \ - uRI.ml + JSON.ml + +SOURCES_C = \ + $(top_srcdir)/fish/progress.c \ + $(top_srcdir)/fish/uri.c \ + fsync-c.c \ + mkdtemp-c.c \ + progress-c.c \ + uri-c.c if HAVE_OCAML -# Notes: -# - We're not actually building a functioning program here, we're just -# linking everything together to check all the modules build OK. -# - This list must be in dependency order. -ocaml_modules = config \ - libdir \ - common_gettext \ - common_utils \ - fsync \ - progress \ - uRI \ - mkdtemp \ - planner \ - regedit \ - JSON +# Note - we're not actually building a functioning program here, we're +# just linking everything together to check all the modules build OK. -OBJECTS = \ - $(top_builddir)/fish/guestfish-progress.o \ - $(top_builddir)/fish/guestfish-uri.o \ - fsync-c.o \ - progress-c.o \ - uri-c.o \ - mkdtemp-c.o +noinst_PROGRAMS = dummy -if HAVE_OCAMLOPT -OBJECTS += $(patsubst %,%.cmx,$(ocaml_modules)) -else -OBJECTS += $(patsubst %,%.cmo,$(ocaml_modules)) -endif +dummy_SOURCES = $(SOURCES_C) +dummy_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 = \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ + $(LIBVIRT_CFLAGS) $(LIBXML2_CFLAGS) -noinst_SCRIPTS = dummy +BOBJECTS = $(SOURCES_ML:.ml=.cmo) +XOBJECTS = $(BOBJECTS:.cmo=.cmx) # -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. -OCAMLPACKAGES = -package str,unix -I $(top_builddir)/src/.libs -I ../ocaml +OCAMLPACKAGES = \ + -package str,unix \ + -I $(top_builddir)/src/.libs \ + -I $(top_builddir)/gnulib/lib/.libs \ + -I $(top_builddir)/ocaml if HAVE_OCAML_PKG_GETTEXT OCAMLPACKAGES += -package gettext-stub endif -OCAMLCFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) $(OCAMLPACKAGES) -OCAMLOPTFLAGS = $(OCAMLCFLAGS) +OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) -OCAMLCLIBS = \ - $(LIBXML2_LIBS) $(LIBINTL) $(LIBTINFO_LIBS) -lcrypt \ - -L../src/.libs -lutils \ - -L../gnulib/lib/.libs -lgnu - -dummy: $(OBJECTS) -if HAVE_OCAMLOPT - $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \ - mlguestfs.cmxa -linkpkg $^ \ - -cclib '$(OCAMLCLIBS)' \ - -o $@ +if !HAVE_OCAMLOPT +OBJECTS = $(BOBJECTS) +BEST = c +OCAMLLINKFLAGS = mlguestfs.cma -custom else - $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \ - mlguestfs.cma -linkpkg $^ \ - -cclib '$(OCAMLCLIBS)' \ - -custom \ - -o $@ +OBJECTS = $(XOBJECTS) +BEST = opt +OCAMLLINKFLAGS = mlguestfs.cmxa endif +dummy_DEPENDENCIES = $(OBJECTS) +dummy_LINK = \ + ./link.sh \ + $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \ + $(OBJECTS) -o $@ + .mli.cmi: - $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@ + $(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@ .ml.cmo: - $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@ + $(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@ if HAVE_OCAMLOPT .ml.cmx: - $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -c $< -o $@ + $(OCAMLFIND) ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@ endif # This OCaml module has to be generated by make (configure will put @@ -128,31 +124,18 @@ libdir.ml: Makefile echo 'let libdir = "$(libdir)"' > $@-t mv $@-t $@ -# automake will decide we don't need C support in this file. Really -# we do, so we have to provide it ourselves. - -DEFAULT_INCLUDES = \ - $(LIBVIRT_CFLAGS) \ - -I. \ - -I$(top_builddir) \ - -I$(shell $(OCAMLC) -where) \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/fish - -.c.o: - $(CC) $(CFLAGS) $(PROF_CFLAGS) $(DEFAULT_INCLUDES) -c $< -o $@ - # Tests. -check_SCRIPTS = common_utils_tests +check_SCRIPTS = \ + common_utils_tests if HAVE_OCAMLOPT common_utils_tests: common_gettext.cmx common_utils.cmx common_utils_tests.cmx - $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \ + $(OCAMLFIND) ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) \ mlguestfs.cmxa -linkpkg $^ -cclib '$(LIBTINFO_LIBS)' -o $@ else common_utils_tests: common_gettext.cmo common_utils.cmo common_utils_tests.cmo - $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \ + $(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) \ mlguestfs.cma -linkpkg $^ -cclib '$(LIBTINFO_LIBS)' -custom -o $@ endif diff --git a/mllib/link.sh.in b/mllib/link.sh.in new file mode 100644 index 000000000..79dc84763 --- /dev/null +++ b/mllib/link.sh.in @@ -0,0 +1,22 @@ +# libguestfs Makefile.am +# @configure_input@ +# (C) Copyright 2014 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +# Hack automake to link binary properly. There is no other way to add +# the -cclib parameter to the end of the command line. + +exec "$@" -linkpkg -cclib '-lutils @LIBTINFO_LIBS@ -lcrypt @LIBVIRT_LIBS@ @LIBXML2_LIBS@ @LIBINTL@ -lgnu'