Richard W.M. Jones
2020-Mar-10 15:05 UTC
[Libguestfs] [PATCH libguestfs 0/2] build: Allow programs using libguestfs to be compiled from against build dir.
These changes allow virt-v2v to be compiled against the build directory of a non-installed libguestfs. Note that some small changes are also required to common and virt-v2v itself. I will post those separately. Rich.
Richard W.M. Jones
2020-Mar-10 15:05 UTC
[Libguestfs] [PATCH libguestfs 1/2] build: Allow C programs using libguestfs to be compiled against build dir.
We use a similar trick to libvirt to allow external C programs that use libguestfs to be compiled against the built (but not installed) libguestfs with: ../libguestfs/run ./configure make What actually happens is we have a second pkg-config file (lib/local/libguestfs.pc) which points to the locally built libguestfs. The ./run script sets up PKG_CONFIG_PATH to point to this directory. Assuming that ./configure is using pkg-config/pkgconf and not some other half-baked solution it will pick up the libguestfs.pc file from here which will set CFLAGS and LIBS appropriately. --- .gitignore | 1 + configure.ac | 1 + lib/Makefile.am | 1 + lib/local/libguestfs.pc.in | 36 ++++++++++++++++++++++++++++++++++++ run.in | 5 +++++ 5 files changed, 44 insertions(+) diff --git a/.gitignore b/.gitignore index 1abb1c8b7..1ebc5421f 100644 --- a/.gitignore +++ b/.gitignore @@ -337,6 +337,7 @@ Makefile.in /lib/libguestfs.syms /lib/.libs/libguestfs.so /lib/libvirt-is-version +/lib/local/libguestfs.pc /lib/stamp-guestfs.pod /lib/structs-compare.c /lib/structs-copy.c diff --git a/configure.ac b/configure.ac index 3a4d6c931..3971d30f6 100644 --- a/configure.ac +++ b/configure.ac @@ -276,6 +276,7 @@ AC_CONFIG_FILES([Makefile java/examples/Makefile lib/Makefile lib/libguestfs.pc + lib/local/libguestfs.pc lua/Makefile lua/examples/Makefile make-fs/Makefile diff --git a/lib/Makefile.am b/lib/Makefile.am index e5df96fe2..4fef46826 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -47,6 +47,7 @@ EXTRA_DIST = \ $(BUILT_SOURCES) \ MAX_PROC_NR \ libguestfs.pc.in \ + local/libguestfs.pc.in \ guestfs.pod include_HEADERS = guestfs.h diff --git a/lib/local/libguestfs.pc.in b/lib/local/libguestfs.pc.in new file mode 100644 index 000000000..b736cd671 --- /dev/null +++ b/lib/local/libguestfs.pc.in @@ -0,0 +1,36 @@ +# @configure_input@ +# Copyright (C) 2020 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. + + +# Dummy pkg-config file which is used to allow out of tree packages to +# be configured against the libguestfs tree without libguestfs needing +# to be installed. +# +# Note if you are using the ./run script then you don't need to worry +# about this because the script sets PKG_CONFIG_PATH correctly. + +prefix=@abs_top_builddir@ +exec_prefix=@abs_top_builddir@ +libdir=@abs_top_builddir@/lib/.libs +includedir=@abs_top_srcdir@/lib + +Name: libguestfs +Version: @VERSION@ +Description: libguestfs library for accessing and modifying VM images +Requires: +Cflags: -I${includedir} +Libs: -L${libdir} -lguestfs @LIBS@ diff --git a/run.in b/run.in index c734612fc..6896d5a2c 100755 --- a/run.in +++ b/run.in @@ -223,6 +223,11 @@ export G_DEBUG=gc-friendly random_val="$(@AWK@ 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)" export MALLOC_PERTURB_=$random_val +# Allow dependent packages like virt-v2v to be compiled against +# local libguestfs. +prepend PKG_CONFIG_PATH "$b/lib/local" +export PKG_CONFIG_PATH + # Do we have libtool? If we have it then we can use it to make # running valgrind simpler. However don't depend on it. if libtool --help >/dev/null 2>&1; then -- 2.24.1
Richard W.M. Jones
2020-Mar-10 15:05 UTC
[Libguestfs] [PATCH libguestfs 2/2] build: Allow OCaml programs using libguestfs to be compiled against build dir.
You have to use: ../libguestfs/run ./configure ../libguestfs/run make Use of the second ../libguestfs/run against make is unfortunate but I believe it's unavoidable due to the way that ocamlfind works. --- .gitignore | 1 + ocaml/Makefile.am | 19 ++++++++++++++++++- run.in | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1ebc5421f..cdc90453c 100644 --- a/.gitignore +++ b/.gitignore @@ -379,6 +379,7 @@ Makefile.in /ocaml/examples/guestfs-ocaml.3 /ocaml/examples/inspect_vm /ocaml/examples/stamp-guestfs-ocaml.pod +/ocaml/guestfs /ocaml/guestfs-c-actions.c /ocaml/guestfs-c-errnos.c /ocaml/guestfs.ml diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am index c85efee64..c02246270 100644 --- a/ocaml/Makefile.am +++ b/ocaml/Makefile.am @@ -197,4 +197,21 @@ install-data-hook: CLEANFILES += $(noinst_DATA) $(check_DATA) -endif +# This "tricks" ocamlfind into allowing us to compile other OCaml +# programs against a locally compiled copy of the libguestfs sources. +# ocamlfind needs to see a directory called ‘guestfs’ which contains +# ‘META’. The current directory is called ‘ocaml’, but if we make +# this symlink then we can create the required directory structure. +# +# Note if you just want to use this, make sure you use +# ‘../libguestfs/run make’ in your other program and everything should +# just work. +CLEANFILES += guestfs + +all-local: guestfs + +guestfs: + rm -f $@ + ln -sf . $@ + +endif HAVE_OCAML diff --git a/run.in b/run.in index 6896d5a2c..90552fb04 100755 --- a/run.in +++ b/run.in @@ -227,6 +227,8 @@ export MALLOC_PERTURB_=$random_val # local libguestfs. prepend PKG_CONFIG_PATH "$b/lib/local" export PKG_CONFIG_PATH +prepend OCAMLPATH "$b/ocaml" +export OCAMLPATH # Do we have libtool? If we have it then we can use it to make # running valgrind simpler. However don't depend on it. -- 2.24.1
Eric Blake
2020-Mar-11 11:52 UTC
Re: [Libguestfs] [PATCH libguestfs 1/2] build: Allow C programs using libguestfs to be compiled against build dir.
On 3/10/20 10:05 AM, Richard W.M. Jones wrote:> We use a similar trick to libvirt to allow external C programs that > use libguestfs to be compiled against the built (but not installed) > libguestfs with: > > ../libguestfs/run ./configure > make > > What actually happens is we have a second pkg-config file > (lib/local/libguestfs.pc) which points to the locally built > libguestfs. The ./run script sets up PKG_CONFIG_PATH to point to this > directory. Assuming that ./configure is using pkg-config/pkgconf and > not some other half-baked solution it will pick up the libguestfs.pc > file from here which will set CFLAGS and LIBS appropriately. > --- > .gitignore | 1 + > configure.ac | 1 + > lib/Makefile.am | 1 + > lib/local/libguestfs.pc.in | 36 ++++++++++++++++++++++++++++++++++++ > run.in | 5 +++++ > 5 files changed, 44 insertions(+) >I like it. Should we do the same for libnbd's run script? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Eric Blake
2020-Mar-11 11:54 UTC
Re: [Libguestfs] [PATCH libguestfs 2/2] build: Allow OCaml programs using libguestfs to be compiled against build dir.
On 3/10/20 10:05 AM, Richard W.M. Jones wrote:> You have to use: > ../libguestfs/run ./configure > ../libguestfs/run make > > Use of the second ../libguestfs/run against make is unfortunate but I > believe it's unavoidable due to the way that ocamlfind works.Or even: ../libguestfs/run sh -c './configure && make' But yes, the need to set the environment multiple times makes sense, even if it is unfortunate that 'make' is unable to rely solely on what was learned at configure-time.> --- > .gitignore | 1 + > ocaml/Makefile.am | 19 ++++++++++++++++++- > run.in | 2 ++ > 3 files changed, 21 insertions(+), 1 deletion(-) >-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Pino Toscano
2020-Mar-11 12:20 UTC
Re: [Libguestfs] [PATCH libguestfs 1/2] build: Allow C programs using libguestfs to be compiled against build dir.
On Tuesday, 10 March 2020 16:05:18 CET Richard W.M. Jones wrote:> We use a similar trick to libvirt to allow external C programs that > use libguestfs to be compiled against the built (but not installed) > libguestfs with: > > ../libguestfs/run ./configure > makeOr even more easily, covering also the OCaml usage: $ /path/to/libguestfs/run bash -i $ ./configure $ make $ [etc]> What actually happens is we have a second pkg-config file > (lib/local/libguestfs.pc) which points to the locally built > libguestfs. The ./run script sets up PKG_CONFIG_PATH to point to this > directory. Assuming that ./configure is using pkg-config/pkgconf and > not some other half-baked solution it will pick up the libguestfs.pc > file from here which will set CFLAGS and LIBS appropriately. > ---Seems OK, just one thing:> +Name: libguestfs > +Version: @VERSION@ > +Description: libguestfs library for accessing and modifying VM images > +Requires: > +Cflags: -I${includedir} > +Libs: -L${libdir} -lguestfs @LIBS@Not sure where this $LIBS variable comes from, as it is empty (even the installed libguestfs.pc has this). I'd drop it from this patch, and I will send a patch for the installed libguestfs.pc.in. -- Pino Toscano
Pino Toscano
2020-Mar-11 17:02 UTC
Re: [Libguestfs] [PATCH libguestfs 2/2] build: Allow OCaml programs using libguestfs to be compiled against build dir.
On Tuesday, 10 March 2020 16:05:19 CET Richard W.M. Jones wrote:> You have to use: > ../libguestfs/run ./configure > ../libguestfs/run make > > Use of the second ../libguestfs/run against make is unfortunate but I > believe it's unavoidable due to the way that ocamlfind works.Or a simplier: $ /path/to/libguestfs/run bash -i $ ./configure $ make $ [etc]> --- > .gitignore | 1 + > ocaml/Makefile.am | 19 ++++++++++++++++++- > run.in | 2 ++ > 3 files changed, 21 insertions(+), 1 deletion(-) > > diff --git a/.gitignore b/.gitignore > index 1ebc5421f..cdc90453c 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -379,6 +379,7 @@ Makefile.in > /ocaml/examples/guestfs-ocaml.3 > /ocaml/examples/inspect_vm > /ocaml/examples/stamp-guestfs-ocaml.pod > +/ocaml/guestfs > /ocaml/guestfs-c-actions.c > /ocaml/guestfs-c-errnos.c > /ocaml/guestfs.ml > diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am > index c85efee64..c02246270 100644 > --- a/ocaml/Makefile.am > +++ b/ocaml/Makefile.am > @@ -197,4 +197,21 @@ install-data-hook: > > CLEANFILES += $(noinst_DATA) $(check_DATA) > > -endif > +# This "tricks" ocamlfind into allowing us to compile other OCaml > +# programs against a locally compiled copy of the libguestfs sources. > +# ocamlfind needs to see a directory called ‘guestfs’ which contains > +# ‘META’. The current directory is called ‘ocaml’, but if we make > +# this symlink then we can create the required directory structure. > +# > +# Note if you just want to use this, make sure you use > +# ‘../libguestfs/run make’ in your other program and everything should > +# just work. > +CLEANFILES += guestfs > + > +all-local: guestfs > + > +guestfs: > + rm -f $@ > + ln -sf . $@The '.' might be better replaced by $(srcdir) instead, although it will only matter when building libguestfs with builddir!=srcdir, and then anything against that uninstalled libguestfs. The rest LGTM. -- Pino Toscano
Maybe Matching Threads
- [PATCH libguestfs 2/2] build: Allow OCaml programs using libguestfs to be compiled against build dir.
- [PATCH libnbd 1/3] tests: Don't use <config.h> in simple compile tests.
- Various fixes from building libguestfs for Debian
- Re: Continuing the split (was: Let's split up the libguestfs git repo and tarballs)
- Ocamlfind can't find hivex