[Libguestfs] [PATCH libguestfs 1/2] build: Allow C programs using libguestfs to be compiled against build dir.

Richard W.M. Jones rjones at redhat.com
Tue Mar 10 15:05:18 UTC 2020


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




More information about the Libguestfs mailing list