[pacman-dev] [PATCH] build: check for gpgme with pkg-config before gpgme-config

Eli Schwartz eschwartz at archlinux.org
Fri Mar 8 04:10:38 UTC 2019


gpgme in git master now supports pkg-config and with the next release we
can and should prefer its use. However, retain the legacy code that
enables building with older versions of gpgme, as a fallback.

Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
---

Since we seem headed for a release soon, I'd like to get this in now
even though gpgme is still unreleased.

 configure.ac              | 68 +++++++++++++++++++++------------------
 lib/libalpm/libalpm.pc.in |  4 +--
 meson.build               | 49 +++++++++++++++-------------
 3 files changed, 66 insertions(+), 55 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2f345b5d..74bf8c1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -268,37 +268,43 @@ AS_IF([test "x$with_gpgme" != "xno"],
 	[AC_MSG_RESULT([no])])
 
 have_gpgme=no
-AS_IF([test "x$with_gpgme" != "xno"],
-	[AM_PATH_GPGME([1.3.0],
-		[LIBS_save="$LIBS"
-		CPPFLAGS_save="$CPPFLAGS"
-		CFLAGS_save="$CFLAGS"
-
-		LIBS="$LIBS $GPGME_LIBS"
-		CPPFLAGS="$CPPFLAGS $GPGME_CPPFLAGS"
-		CFLAGS="$CFLAGS $GPGME_CFLAGS"
-
-		AC_MSG_CHECKING([for sane gpgme])
-		AC_LINK_IFELSE(
-			[AC_LANG_PROGRAM(
-				[[#include <gpgme.h>]],
-				[[return gpgme_check_version("1.3.0");]])],
-			[AC_MSG_RESULT([yes])
-			have_gpgme=yes
-			AC_DEFINE([HAVE_LIBGPGME], [1], [Define if gpgme should be used to provide GPG signature support.])],
-			[AC_MSG_RESULT([no])
-			have_gpgme=no
-			unset GPGME_LIBS
-			unset GPGME_CFLAGS]
-			AS_IF([test "x$with_gpgme" = "xyes"],
-				[AC_MSG_FAILURE([*** gpgme >= 1.3.0 is needed for GPG signature support])])
-			)
-
-		LIBS="$LIBS_save"
-		CPPFLAGS="$CPPFLAGS_save"
-		CFLAGS="$CFLAGS_save"
-		unset CPPFLAGS_save
-		unset CFLAGS_save],)])
+if test "x$with_gpgme" != "xno"; then
+	PKG_CHECK_MODULES(GPGME, [gpgme],
+		[AC_DEFINE([HAVE_LIBGPGME], [1], [Define if gpgme should be used to provide GPG signature support.])
+		AC_SUBST(pc_gpgme, [gpgme])
+		have_gpgme=yes],
+		[AM_PATH_GPGME([1.3.0],
+			[LIBS_save="$LIBS"
+			CPPFLAGS_save="$CPPFLAGS"
+			CFLAGS_save="$CFLAGS"
+
+			LIBS="$LIBS $GPGME_LIBS"
+			CPPFLAGS="$CPPFLAGS $GPGME_CPPFLAGS"
+			CFLAGS="$CFLAGS $GPGME_CFLAGS"
+
+			AC_MSG_CHECKING([for sane gpgme])
+			AC_LINK_IFELSE(
+				[AC_LANG_PROGRAM(
+					[[#include <gpgme.h>]],
+					[[return gpgme_check_version("1.3.0");]])],
+				[AC_MSG_RESULT([yes])
+				have_gpgme=yes
+				AC_DEFINE([HAVE_LIBGPGME], [1], [Define if gpgme should be used to provide GPG signature support.])
+				AC_SUBST(pc_gpgme_libs, ["$GPGME_LIBS"])],
+				[AC_MSG_RESULT([no])
+				have_gpgme=no
+				unset GPGME_LIBS
+				unset GPGME_CFLAGS]
+				AS_IF([test "x$with_gpgme" = "xyes"],
+					[AC_MSG_FAILURE([*** gpgme >= 1.3.0 is needed for GPG signature support])])
+				)
+
+			LIBS="$LIBS_save"
+			CPPFLAGS="$CPPFLAGS_save"
+			CFLAGS="$CFLAGS_save"
+			unset CPPFLAGS_save
+			unset CFLAGS_save],)])
+fi
 
 AS_IF([test "x$have_gpgme" = xno -a "x$with_gpgme" = xyes],
 	[AC_MSG_FAILURE([--with-gpgme was given, but gpgme was not found])])
diff --git a/lib/libalpm/libalpm.pc.in b/lib/libalpm/libalpm.pc.in
index 6b905747..126a6e6a 100644
--- a/lib/libalpm/libalpm.pc.in
+++ b/lib/libalpm/libalpm.pc.in
@@ -7,7 +7,7 @@ Name: libalpm
 Description: Arch Linux package management library
 URL: http://www.archlinux.org/pacman/
 Version: @LIB_VERSION@
-Requires.private: libarchive @pc_crypto@ @pc_libcurl@
+Requires.private: libarchive @pc_crypto@ @pc_libcurl@ @pc_gpgme@
 Cflags: -I${includedir} @LFS_CFLAGS@
 Libs: -L${libdir} -lalpm
-Libs.private: @LIBS@ @GPGME_LIBS@
+Libs.private: @LIBS@ @pc_gpgme_libs@
diff --git a/meson.build b/meson.build
index b810e2fb..5512913a 100644
--- a/meson.build
+++ b/meson.build
@@ -98,29 +98,34 @@ libcurl = dependency('libcurl',
 conf.set('HAVE_LIBCURL', libcurl.found())
 
 want_gpgme = get_option('gpgme')
-gpgme_config = find_program('gpgme-config', required : want_gpgme)
-if not want_gpgme.disabled() and gpgme_config.found()
-  gpgme_version = run_command(gpgme_config, '--version').stdout().strip()
-
-  needed_gpgme_version = '>=1.3.0'
-  have = gpgme_version.version_compare(needed_gpgme_version)
-  if want_gpgme.enabled() and not have
-    error('gpgme @0@ is needed for GPG signature support'.format(needed_gpgme_version))
+gpgme = dependency('gpgme',
+                   required : false,
+                   static : get_option('buildstatic'))
+# gpgme recently began providing a pkg-config file. Create a fake dependency
+# object if it cannot be found, by manually searching for libs.
+if not want_gpgme.disabled() and not gpgme.found()
+  gpgme_config = find_program('gpgme-config', required : want_gpgme)
+  if gpgme_config.found()
+    gpgme_version = run_command(gpgme_config, '--version').stdout().strip()
+
+    needed_gpgme_version = '>=1.3.0'
+    if gpgme_version.version_compare(needed_gpgme_version)
+      gpgme_libs = [
+        cc.find_library('gpgme',
+                        dirs : [get_option('gpgme-libdir')]),
+        cc.find_library('gpg-error',
+                        dirs : [get_option('gpgme-libdir')]),
+        cc.find_library('assuan',
+                        dirs : [get_option('gpgme-libdir')]),
+      ]
+      gpgme = declare_dependency(dependencies : gpgme_libs)
+    endif
   endif
+endif
 
-  gpgme_libs = [
-    cc.find_library('gpgme', required : have,
-                    dirs : [get_option('gpgme-libdir')]),
-    cc.find_library('gpg-error', required : have,
-                    dirs : [get_option('gpgme-libdir')]),
-    cc.find_library('assuan', required : have,
-                    dirs : [get_option('gpgme-libdir')]),
-  ]
-
-  conf.set('HAVE_LIBGPGME', have)
-else
-  gpgme_libs = []
-  conf.set('HAVE_LIBGPGME', false)
+conf.set('HAVE_LIBGPGME', gpgme.found())
+if want_gpgme.enabled() and not conf.get('HAVE_LIBGPGME')
+  error('gpgme @0@ is needed for GPG signature support'.format(needed_gpgme_version))
 endif
 
 want_crypto = get_option('crypto')
@@ -359,7 +364,7 @@ libalpm_a = static_library(
   'alpm',
   libalpm_sources,
   include_directories : includes,
-  dependencies : [crypto_provider, libarchive, libcurl] + gpgme_libs,
+  dependencies : [crypto_provider, libarchive, libcurl, gpgme],
   link_with : [libcommon],
   install : true)
 
-- 
2.21.0


More information about the pacman-dev mailing list