From 839f38e5ecc22b7f1b837284bbbffac8cb32ab1e Mon Sep 17 00:00:00 2001
From: Trevor Gamblin <trevor.gamblin@windriver.com>
Date: Tue, 29 Oct 2019 14:08:32 -0400
Subject: [PATCH] libgcrypt: fix m4 file for oe-core

Modify libgcrypt pkgconfig specifically for oe-core. Changes
are based on a previous patch from RP, using wiggle to
incorporate the parts that aren't in the upstream pkgconfig
settings.

Upstream-Status: Inappropriate [oe-specific]

Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com>

---
 src/libgcrypt.m4 | 90 +++---------------------------------------------
 1 file changed, 4 insertions(+), 86 deletions(-)

diff --git a/src/libgcrypt.m4 b/src/libgcrypt.m4
index 19d514f..21125c7 100644
--- a/src/libgcrypt.m4
+++ b/src/libgcrypt.m4
@@ -29,41 +29,6 @@ dnl is added to the gpg_config_script_warn variable.
 dnl
 AC_DEFUN([AM_PATH_LIBGCRYPT],
 [ AC_REQUIRE([AC_CANONICAL_HOST])
-  AC_ARG_WITH(libgcrypt-prefix,
-            AS_HELP_STRING([--with-libgcrypt-prefix=PFX],
-                           [prefix where LIBGCRYPT is installed (optional)]),
-     libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
-  if test x"${LIBGCRYPT_CONFIG}" = x ; then
-     if test x"${libgcrypt_config_prefix}" != x ; then
-        LIBGCRYPT_CONFIG="${libgcrypt_config_prefix}/bin/libgcrypt-config"
-     fi
-  fi
-
-  use_gpgrt_config=""
-  if test x"${LIBGCRYPT_CONFIG}" = x -a x"$GPGRT_CONFIG" != x -a "$GPGRT_CONFIG" != "no"; then
-    if $GPGRT_CONFIG libgcrypt --exists; then
-      LIBGCRYPT_CONFIG="$GPGRT_CONFIG libgcrypt"
-      AC_MSG_NOTICE([Use gpgrt-config as libgcrypt-config])
-      use_gpgrt_config=yes
-    fi
-  fi
-  if test -z "$use_gpgrt_config"; then
-    if test x"${LIBGCRYPT_CONFIG}" = x ; then
-      case "${SYSROOT}" in
-         /*)
-           if test -x "${SYSROOT}/bin/libgcrypt-config" ; then
-             LIBGCRYPT_CONFIG="${SYSROOT}/bin/libgcrypt-config"
-           fi
-           ;;
-         '')
-           ;;
-          *)
-           AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
-           ;;
-      esac
-    fi
-    AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
-  fi
 
   tmp=ifelse([$1], ,1:1.2.0,$1)
   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
@@ -74,56 +39,13 @@ AC_DEFUN([AM_PATH_LIBGCRYPT],
      min_libgcrypt_version="$tmp"
   fi
 
-  AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
-  ok=no
-  if test "$LIBGCRYPT_CONFIG" != "no" ; then
-    req_major=`echo $min_libgcrypt_version | \
-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
-    req_minor=`echo $min_libgcrypt_version | \
-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
-    req_micro=`echo $min_libgcrypt_version | \
-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
-    if test -z "$use_gpgrt_config"; then
-      libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
-    else
-      libgcrypt_config_version=`$LIBGCRYPT_CONFIG --modversion`
-    fi
-    major=`echo $libgcrypt_config_version | \
-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
-    minor=`echo $libgcrypt_config_version | \
-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
-    micro=`echo $libgcrypt_config_version | \
-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
-    if test "$major" -gt "$req_major"; then
-        ok=yes
-    else
-        if test "$major" -eq "$req_major"; then
-            if test "$minor" -gt "$req_minor"; then
-               ok=yes
-            else
-               if test "$minor" -eq "$req_minor"; then
-                   if test "$micro" -ge "$req_micro"; then
-                     ok=yes
-                   fi
-               fi
-            fi
-        fi
-    fi
-  fi
-  if test $ok = yes; then
-    AC_MSG_RESULT([yes ($libgcrypt_config_version)])
-  else
-    AC_MSG_RESULT(no)
-  fi
+  PKG_CHECK_MODULES(LIBGCRYPT, [libgcrypt >= $min_libgcrypt_version], [ok=yes], [ok=no])
+
   if test $ok = yes; then
      # If we have a recent libgcrypt, we should also check that the
      # API is compatible
      if test "$req_libgcrypt_api" -gt 0 ; then
-        if test -z "$use_gpgrt_config"; then
-           tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
-	else
-           tmp=`$LIBGCRYPT_CONFIG --variable=api_version 2>/dev/null || echo 0`
-	fi
+        tmp=`$PKG_CONFIG --variable=api_version libgcrypt`
         if test "$tmp" -gt 0 ; then
            AC_MSG_CHECKING([LIBGCRYPT API version])
            if test "$req_libgcrypt_api" -eq "$tmp" ; then
@@ -136,11 +58,9 @@ AC_DEFUN([AM_PATH_LIBGCRYPT],
      fi
   fi
   if test $ok = yes; then
-    LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
-    LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
     ifelse([$2], , :, [$2])
     if test -z "$use_gpgrt_config"; then
-      libgcrypt_config_host=`$LIBGCRYPT_CONFIG --host 2>/dev/null || echo none`
+      libgcrypt_config_host=`$PKG_CONFIG --variable=host libgcrypt`
     else
       libgcrypt_config_host=`$LIBGCRYPT_CONFIG --variable=host 2>/dev/null || echo none`
     fi
@@ -158,8 +78,6 @@ AC_DEFUN([AM_PATH_LIBGCRYPT],
       fi
     fi
   else
-    LIBGCRYPT_CFLAGS=""
-    LIBGCRYPT_LIBS=""
     ifelse([$3], , :, [$3])
   fi
   AC_SUBST(LIBGCRYPT_CFLAGS)
