[libvirt] [ocaml PATCH 4/4] build: use pkg-config to find libvirt

Pino Toscano ptoscano at redhat.com
Mon Oct 15 14:02:35 UTC 2018


Rely on pkg-config to detect libvirt, and use its variables to locate
it.  The version required is taken from the API documentation.

Signed-off-by: Pino Toscano <ptoscano at redhat.com>
---
 configure.ac        | 20 ++------------------
 libvirt/Makefile.in | 14 ++++++++------
 2 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/configure.ac b/configure.ac
index 11ff2bf..7d923bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,24 +55,8 @@ if test "x$PERL" = "xno"; then
 fi
 
 dnl Check for libvirt development environment.
-AC_ARG_WITH(libvirt,
-	AC_HELP_STRING([--with-libvirt=PATH],[Set path to installed libvirt]),
-	[if test "x$withval" != "x"; then
-	   CFLAGS="$CFLAGS -I$withval/include"
-	   LDFLAGS="$LDFLAGS -L$withval/lib"
-	 fi
-	])
-AC_CHECK_LIB(virt,virConnectOpen,
-	[],
-	AC_MSG_ERROR([You must install libvirt library]))
-AC_CHECK_HEADER([libvirt/libvirt.h],
-	[],
-	AC_MSG_ERROR([You must install libvirt development package]))
-
-dnl We also use <libvirt/virterror.h>
-AC_CHECK_HEADER([libvirt/virterror.h],
-	[],
-	AC_MSG_ERROR([You must install libvirt development package]))
+PKG_PROG_PKG_CONFIG
+PKG_CHECK_MODULES([LIBVIRT], [libvirt >= 1.0.2])
 
 dnl Check for basic OCaml environment & findlib.
 AC_PROG_OCAML
diff --git a/libvirt/Makefile.in b/libvirt/Makefile.in
index faca5ee..3a68aed 100644
--- a/libvirt/Makefile.in
+++ b/libvirt/Makefile.in
@@ -18,10 +18,12 @@
 WIN32		= @WIN32@
 
 CFLAGS		= @CFLAGS@ \
+		   @LIBVIRT_CFLAGS@ \
 		   -I.. \
 		   -I"$(shell ocamlc -where)" \
 		   @DEBUG@ @WARNINGS@ @CFLAGS_FPIC@
-LDFLAGS		= @LDFLAGS@
+LDFLAGS		= @LDFLAGS@ \
+		   @LIBVIRT_LIBS@
 #		   -L"$(shell ocamlc -where)"
 
 OCAMLC		= @OCAMLC@
@@ -62,10 +64,10 @@ OPTOBJS := libvirt.cmx libvirt_version.cmx
 ifneq ($(OCAMLMKLIB),)
 # Good, we can just use ocamlmklib
 mllibvirt.cma: libvirt_c.o $(COBJS)
-	$(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) -lvirt
+	$(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS)
 
 mllibvirt.cmxa: libvirt_c.o $(OPTOBJS)
-	$(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) -lvirt
+	$(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS)
 
 else
 ifeq ($(WIN32),yes)
@@ -74,15 +76,15 @@ ifeq ($(WIN32),yes)
 
 mllibvirt.cma: dllmllibvirt.dll libmllibvirt.a $(COBJS)
 	$(OCAMLC) -a -linkall -o $@ $(COBJS) \
-	  -dllib -lmllibvirt -cclib -lmllibvirt -cclib "$(LDFLAGS) -lvirt"
+	  -dllib -lmllibvirt -cclib -lmllibvirt -cclib "$(LDFLAGS)"
 
 mllibvirt.cmxa: libmllibvirt.a $(OPTOBJS)
 	$(OCAMLOPT) -a -linkall -o $@ $(OPTOBJS) \
-	  -cclib -lmllibvirt -cclib "$(LDFLAGS) -lvirt"
+	  -cclib -lmllibvirt -cclib "$(LDFLAGS)"
 
 dllmllibvirt.dll: libvirt_c.o
 	$(CC) -shared -o $@ $^ \
-	  $(LDFLAGS) "$(shell ocamlc -where)"/ocamlrun.a -lvirt
+	  $(LDFLAGS) "$(shell ocamlc -where)"/ocamlrun.a
 
 libmllibvirt.a: libvirt_c.o
 	ar rc $@ $^
-- 
2.17.2




More information about the libvir-list mailing list