1From 7b3a00cb0fc27c896dd85c9afc474bd9c2aea30d Mon Sep 17 00:00:00 2001
2From: Richard Purdie <richard.purdie@linuxfoundation.org>
3Date: Fri, 10 May 2019 14:23:55 +0800
4Subject: [PATCH] pkgconfig
5
6Update gpgme to use pkgconfig instead of -config files since its
7simpler and less error prone when cross compiling.
8
9Upstream-Status: Denied [Upstream not interested in pkg-config support]
10RP 2015/4/17
11
12Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
13
14Rebase to 1.13.0
15Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
16Rebase to 1.17.0
17Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
18
19---
20 configure.ac            |   1 +
21 src/Makefile.am         |   4 +-
22 src/gpgme-pthread.pc.in |  15 +++++
23 src/gpgme.m4            | 119 +++-------------------------------------
24 src/gpgme.pc.in         |   4 +-
25 5 files changed, 29 insertions(+), 114 deletions(-)
26 create mode 100644 src/gpgme-pthread.pc.in
27
28diff --git a/configure.ac b/configure.ac
29index ae4c7da..df892c9 100644
30--- a/configure.ac
31+++ b/configure.ac
32@@ -1112,6 +1112,7 @@ AC_CONFIG_FILES(Makefile src/Makefile
33                 src/gpgme-glib.pc
34                 src/gpgme.h)
35 AC_CONFIG_FILES(src/gpgme-config, chmod +x src/gpgme-config)
36+AC_CONFIG_FILES(src/gpgme-pthread.pc)
37 AC_CONFIG_FILES(lang/cpp/Makefile lang/cpp/src/Makefile)
38 AC_CONFIG_FILES(lang/cpp/tests/Makefile)
39 AC_CONFIG_FILES(lang/cpp/src/GpgmeppConfig-w32.cmake.in)
40diff --git a/src/Makefile.am b/src/Makefile.am
41index ca70950..bda5498 100644
42--- a/src/Makefile.am
43+++ b/src/Makefile.am
44@@ -20,11 +20,11 @@
45 ## Process this file with automake to produce Makefile.in
46
47 pkgconfigdir = $(libdir)/pkgconfig
48-pkgconfig_DATA = gpgme.pc gpgme-glib.pc
49+pkgconfig_DATA = gpgme.pc gpgme-glib.pc gpgme-pthread.pc
50
51 EXTRA_DIST = gpgme-config.in gpgme.m4 libgpgme.vers ChangeLog-2011 \
52 	     gpgme.h.in versioninfo.rc.in gpgme.def \
53-	     gpgme.pc.in gpgme-glib.pc.in
54+	     gpgme.pc.in gpgme-glib.pc.in gpgme-pthread.pc.in
55
56 if USE_GPGRT_CONFIG
57 noinst_SCRIPTS = gpgme-config
58diff --git a/src/gpgme-pthread.pc.in b/src/gpgme-pthread.pc.in
59new file mode 100644
60index 0000000..074bbf6
61--- /dev/null
62+++ b/src/gpgme-pthread.pc.in
63@@ -0,0 +1,15 @@
64+prefix=@prefix@
65+exec_prefix=@exec_prefix@
66+libdir=@libdir@
67+includedir=@includedir@
68+
69+# API info
70+api_version=@GPGME_CONFIG_API_VERSION@
71+host=@GPGME_CONFIG_HOST@
72+
73+Name: gpgme
74+Description: GnuPG Made Easy (GPGME) is a C language library that allows to addsupport for cryptography to a program (deprecated)
75+Version: @VERSION@
76+Libs: -L${libdir} -lgpgme -lpthread
77+Cflags: -I${includedir}
78+Requires: libassuan gpg-error
79diff --git a/src/gpgme.m4 b/src/gpgme.m4
80index 8cc2898..0ff550e 100644
81--- a/src/gpgme.m4
82+++ b/src/gpgme.m4
83@@ -168,7 +168,7 @@ dnl config script does not match the host specification the script
84 dnl is added to the gpg_config_script_warn variable.
85 dnl
86 AC_DEFUN([AM_PATH_GPGME],
87-[ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
88+[
89   tmp=ifelse([$1], ,1:0.4.2,$1)
90   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
91      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
92@@ -178,36 +178,12 @@ AC_DEFUN([AM_PATH_GPGME],
93      min_gpgme_version="$tmp"
94   fi
95
96-  AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
97-  ok=no
98-  if test "$GPGME_CONFIG" != "no" ; then
99-    req_major=`echo $min_gpgme_version | \
100-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
101-    req_minor=`echo $min_gpgme_version | \
102-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
103-    req_micro=`echo $min_gpgme_version | \
104-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
105-    if test "$gpgme_version_major" -gt "$req_major"; then
106-        ok=yes
107-    else
108-        if test "$gpgme_version_major" -eq "$req_major"; then
109-            if test "$gpgme_version_minor" -gt "$req_minor"; then
110-               ok=yes
111-            else
112-               if test "$gpgme_version_minor" -eq "$req_minor"; then
113-                   if test "$gpgme_version_micro" -ge "$req_micro"; then
114-                     ok=yes
115-                   fi
116-               fi
117-            fi
118-        fi
119-    fi
120-  fi
121+  PKG_CHECK_MODULES(GPGME, [gpgme >= $min_gpgme_version], [ok=yes], [ok=no])
122   if test $ok = yes; then
123      # If we have a recent GPGME, we should also check that the
124      # API is compatible.
125      if test "$req_gpgme_api" -gt 0 ; then
126-        tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
127+        tmp=`$PKG_CONFIG --variable=api_version gpgme 2>/dev/null || echo 0`
128         if test "$tmp" -gt 0 ; then
129            if test "$req_gpgme_api" -ne "$tmp" ; then
130              ok=no
131@@ -216,19 +192,11 @@ AC_DEFUN([AM_PATH_GPGME],
132      fi
133   fi
134   if test $ok = yes; then
135-    GPGME_CFLAGS=`$GPGME_CONFIG --cflags`
136-    GPGME_LIBS=`$GPGME_CONFIG --libs`
137-    AC_MSG_RESULT(yes)
138     ifelse([$2], , :, [$2])
139     _AM_PATH_GPGME_CONFIG_HOST_CHECK
140   else
141-    GPGME_CFLAGS=""
142-    GPGME_LIBS=""
143-    AC_MSG_RESULT(no)
144     ifelse([$3], , :, [$3])
145   fi
146-  AC_SUBST(GPGME_CFLAGS)
147-  AC_SUBST(GPGME_LIBS)
148 ])
149
150 dnl AM_PATH_GPGME_PTHREAD([MINIMUM-VERSION,
151@@ -236,9 +204,8 @@ dnl                       [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
152 dnl Test for libgpgme and define GPGME_PTHREAD_CFLAGS
153 dnl  and GPGME_PTHREAD_LIBS.
154 dnl
155-AC_DEFUN([AM_PATH_GPGME_PTHREAD],[
156-  AC_OBSOLETE([$0], [; use AM_PATH_GPGME instead to use GPGME_CFLAGS and GPGME_LIBS])dnl
157-  AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
158+AC_DEFUN([AM_PATH_GPGME_PTHREAD],
159+[
160   tmp=ifelse([$1], ,1:0.4.2,$1)
161   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
162      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
163@@ -248,40 +215,12 @@ AC_DEFUN([AM_PATH_GPGME_PTHREAD],[
164      min_gpgme_version="$tmp"
165   fi
166
167-  AC_MSG_CHECKING(for GPGME pthread - version >= $min_gpgme_version)
168-  ok=no
169-  if test "$GPGME_CONFIG" != "no" ; then
170-    req_major=`echo $min_gpgme_version | \
171-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
172-    req_minor=`echo $min_gpgme_version | \
173-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
174-    req_micro=`echo $min_gpgme_version | \
175-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
176-    if test "$gpgme_version_major" -gt "$req_major"; then
177-        ok=yes
178-    else
179-        if test "$gpgme_version_major" -eq "$req_major"; then
180-            if test "$gpgme_version_minor" -gt "$req_minor"; then
181-               ok=yes
182-            else
183-               if test "$gpgme_version_minor" -eq "$req_minor"; then
184-                   if test "$gpgme_version_micro" -ge "$req_micro"; then
185-                     ok=yes
186-                   fi
187-               fi
188-            fi
189-        fi
190-    fi
191-  fi
192+  PKG_CHECK_MODULES(GPGME_PTHREAD, [gpgme-pthread >= $min_gpgme_version], [ok=yes], [ok=no])
193   if test $ok = yes; then
194      # If we have a recent GPGME, we should also check that the
195      # API is compatible.
196      if test "$req_gpgme_api" -gt 0 ; then
197-        if test -z "$use_gpgrt_config"; then
198-          tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
199-        else
200-          tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
201-        fi
202+        tmp=`$PKG_CONFIG --variable=api_version gpgme-pthread 2>/dev/null || echo 0`
203         if test "$tmp" -gt 0 ; then
204            if test "$req_gpgme_api" -ne "$tmp" ; then
205              ok=no
206@@ -290,19 +229,11 @@ AC_DEFUN([AM_PATH_GPGME_PTHREAD],[
207      fi
208   fi
209   if test $ok = yes; then
210-    GPGME_PTHREAD_CFLAGS=`$GPGME_CONFIG --cflags`
211-    GPGME_PTHREAD_LIBS=`$GPGME_CONFIG --libs`
212-    AC_MSG_RESULT(yes)
213     ifelse([$2], , :, [$2])
214     _AM_PATH_GPGME_CONFIG_HOST_CHECK
215   else
216-    GPGME_PTHREAD_CFLAGS=""
217-    GPGME_PTHREAD_LIBS=""
218-    AC_MSG_RESULT(no)
219     ifelse([$3], , :, [$3])
220   fi
221-  AC_SUBST(GPGME_PTHREAD_CFLAGS)
222-  AC_SUBST(GPGME_PTHREAD_LIBS)
223 ])
224
225
226@@ -321,36 +252,12 @@ AC_DEFUN([AM_PATH_GPGME_GLIB],
227      min_gpgme_version="$tmp"
228   fi
229
230-  AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
231-  ok=no
232-  if test "$GPGME_CONFIG" != "no" ; then
233-    req_major=`echo $min_gpgme_version | \
234-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
235-    req_minor=`echo $min_gpgme_version | \
236-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
237-    req_micro=`echo $min_gpgme_version | \
238-               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
239-    if test "$gpgme_version_major" -gt "$req_major"; then
240-        ok=yes
241-    else
242-        if test "$gpgme_version_major" -eq "$req_major"; then
243-            if test "$gpgme_version_minor" -gt "$req_minor"; then
244-               ok=yes
245-            else
246-               if test "$gpgme_version_minor" -eq "$req_minor"; then
247-                   if test "$gpgme_version_micro" -ge "$req_micro"; then
248-                     ok=yes
249-                   fi
250-               fi
251-            fi
252-        fi
253-    fi
254-  fi
255+  PKG_CHECK_MODULES(GPGME_GLIB, [gpgme >= $min_gpgme_version glib-2.0], [ok=yes], [ok=no])
256   if test $ok = yes; then
257      # If we have a recent GPGME, we should also check that the
258      # API is compatible.
259      if test "$req_gpgme_api" -gt 0 ; then
260-        tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
261+        tmp=`$PKG_CONFIG --variable=api_version gpgme 2>/dev/null || echo 0`
262         if test "$tmp" -gt 0 ; then
263            if test "$req_gpgme_api" -ne "$tmp" ; then
264              ok=no
265@@ -359,17 +266,9 @@ AC_DEFUN([AM_PATH_GPGME_GLIB],
266      fi
267   fi
268   if test $ok = yes; then
269-    GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --glib --cflags`
270-    GPGME_GLIB_LIBS=`$GPGME_CONFIG --glib --libs`
271-    AC_MSG_RESULT(yes)
272     ifelse([$2], , :, [$2])
273     _AM_PATH_GPGME_CONFIG_HOST_CHECK
274   else
275-    GPGME_GLIB_CFLAGS=""
276-    GPGME_GLIB_LIBS=""
277-    AC_MSG_RESULT(no)
278     ifelse([$3], , :, [$3])
279   fi
280-  AC_SUBST(GPGME_GLIB_CFLAGS)
281-  AC_SUBST(GPGME_GLIB_LIBS)
282 ])
283diff --git a/src/gpgme.pc.in b/src/gpgme.pc.in
284index 9ddef5c..932645b 100644
285--- a/src/gpgme.pc.in
286+++ b/src/gpgme.pc.in
287@@ -9,6 +9,6 @@ Name: gpgme
288 Description: GnuPG Made Easy to access GnuPG
289 Requires.private: gpg-error, libassuan
290 Version: @PACKAGE_VERSION@
291-Cflags: @GPGME_CONFIG_CFLAGS@
292-Libs: @GPGME_CONFIG_LIBS@
293+Cflags: -I${includedir}
294+Libs: -L${libdir} -lgpgme
295 URL: https://www.gnupg.org/software/gpgme/index.html
296