1 # gpgme.m4 - autoconf macro to detect GPGME.
2 # Copyright (C) 2002, 2003, 2004, 2014, 2018 g10 Code GmbH
4 # This file is free software; as a special exception the author gives
5 # unlimited permission to copy and/or distribute it, with or without
6 # modifications, as long as this notice is preserved.
8 # This file is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
10 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # Last-changed: 2020-11-20
15 AC_DEFUN([_AM_PATH_GPGME_CONFIG],
16 [ AC_ARG_WITH(gpgme-prefix,
17 AS_HELP_STRING([--with-gpgme-prefix=PFX],
18 [prefix where GPGME is installed (optional)]),
19 gpgme_config_prefix="$withval", gpgme_config_prefix="")
20 if test x"${GPGME_CONFIG}" = x ; then
21 if test x"${gpgme_config_prefix}" != x ; then
22 GPGME_CONFIG="${gpgme_config_prefix}/bin/gpgme-config"
26 if test -x "${SYSROOT}/bin/gpgme-config" ; then
27 GPGME_CONFIG="${SYSROOT}/bin/gpgme-config"
33 AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
40 if test x"${GPGME_CONFIG}" = x -a x"$GPGRT_CONFIG" != x -a "$GPGRT_CONFIG" != "no"; then
41 if $GPGRT_CONFIG gpgme --exists; then
42 GPGME_CONFIG="$GPGRT_CONFIG gpgme"
43 AC_MSG_NOTICE([Use gpgrt-config as gpgme-config])
47 if test -z "$use_gpgrt_config"; then
48 AC_PATH_PROG(GPGME_CONFIG, gpgme-config, no)
51 if test "$GPGME_CONFIG" != "no" ; then
52 if test -z "$use_gpgrt_config"; then
53 gpgme_version=`$GPGME_CONFIG --version`
55 gpgme_version=`$GPGME_CONFIG --modversion`
58 gpgme_version_major=`echo $gpgme_version | \
59 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
60 gpgme_version_minor=`echo $gpgme_version | \
61 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
62 gpgme_version_micro=`echo $gpgme_version | \
63 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
67 AC_DEFUN([_AM_PATH_GPGME_CONFIG_HOST_CHECK],
69 if test -z "$use_gpgrt_config"; then
70 gpgme_config_host=`$GPGME_CONFIG --host 2>/dev/null || echo none`
72 gpgme_config_host=`$GPGME_CONFIG --variable=host 2>/dev/null || echo none`
74 if test x"$gpgme_config_host" != xnone ; then
75 if test x"$gpgme_config_host" != x"$host" ; then
78 *** The config script "$GPGME_CONFIG" was
79 *** built for $gpgme_config_host and thus may not match the
81 *** You may want to use the configure option --with-gpgme-prefix
82 *** to specify a matching config script or use \$SYSROOT.
84 gpg_config_script_warn="$gpg_config_script_warn gpgme"
90 dnl AM_PATH_GPGME([MINIMUM-VERSION,
91 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
92 dnl Test for libgpgme and define GPGME_CFLAGS and GPGME_LIBS.
94 dnl If a prefix option is not used, the config script is first
95 dnl searched in $SYSROOT/bin and then along $PATH. If the used
96 dnl config script does not match the host specification the script
97 dnl is added to the gpg_config_script_warn variable.
99 AC_DEFUN([AM_PATH_GPGME],
100 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
101 tmp=ifelse([$1], ,1:0.4.2,$1)
102 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
103 req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
104 min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
107 min_gpgme_version="$tmp"
110 AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
112 if test "$GPGME_CONFIG" != "no" ; then
113 req_major=`echo $min_gpgme_version | \
114 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
115 req_minor=`echo $min_gpgme_version | \
116 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
117 req_micro=`echo $min_gpgme_version | \
118 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
119 if test "$gpgme_version_major" -gt "$req_major"; then
122 if test "$gpgme_version_major" -eq "$req_major"; then
123 if test "$gpgme_version_minor" -gt "$req_minor"; then
126 if test "$gpgme_version_minor" -eq "$req_minor"; then
127 if test "$gpgme_version_micro" -ge "$req_micro"; then
135 if test $ok = yes; then
136 # If we have a recent GPGME, we should also check that the
138 if test "$req_gpgme_api" -gt 0 ; then
139 if test -z "$use_gpgrt_config"; then
140 tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
142 tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
144 if test "$tmp" -gt 0 ; then
145 if test "$req_gpgme_api" -ne "$tmp" ; then
151 if test $ok = yes; then
152 GPGME_CFLAGS=`$GPGME_CONFIG --cflags`
153 GPGME_LIBS=`$GPGME_CONFIG --libs`
155 ifelse([$2], , :, [$2])
156 _AM_PATH_GPGME_CONFIG_HOST_CHECK
161 ifelse([$3], , :, [$3])
163 AC_SUBST(GPGME_CFLAGS)
167 dnl AM_PATH_GPGME_PTHREAD([MINIMUM-VERSION,
168 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
169 dnl Test for libgpgme and define GPGME_PTHREAD_CFLAGS
170 dnl and GPGME_PTHREAD_LIBS.
172 AC_DEFUN([AM_PATH_GPGME_PTHREAD],
173 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
174 tmp=ifelse([$1], ,1:0.4.2,$1)
175 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
176 req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
177 min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
180 min_gpgme_version="$tmp"
183 AC_MSG_CHECKING(for GPGME pthread - version >= $min_gpgme_version)
185 if test "$GPGME_CONFIG" != "no" ; then
186 if `$GPGME_CONFIG --thread=pthread 2> /dev/null` ; then
187 req_major=`echo $min_gpgme_version | \
188 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
189 req_minor=`echo $min_gpgme_version | \
190 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
191 req_micro=`echo $min_gpgme_version | \
192 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
193 if test "$gpgme_version_major" -gt "$req_major"; then
196 if test "$gpgme_version_major" -eq "$req_major"; then
197 if test "$gpgme_version_minor" -gt "$req_minor"; then
200 if test "$gpgme_version_minor" -eq "$req_minor"; then
201 if test "$gpgme_version_micro" -ge "$req_micro"; then
210 if test $ok = yes; then
211 # If we have a recent GPGME, we should also check that the
213 if test "$req_gpgme_api" -gt 0 ; then
214 tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
215 if test "$tmp" -gt 0 ; then
216 if test "$req_gpgme_api" -ne "$tmp" ; then
222 if test $ok = yes; then
223 GPGME_PTHREAD_CFLAGS=`$GPGME_CONFIG --thread=pthread --cflags`
224 GPGME_PTHREAD_LIBS=`$GPGME_CONFIG --thread=pthread --libs`
226 ifelse([$2], , :, [$2])
227 _AM_PATH_GPGME_CONFIG_HOST_CHECK
229 GPGME_PTHREAD_CFLAGS=""
230 GPGME_PTHREAD_LIBS=""
232 ifelse([$3], , :, [$3])
234 AC_SUBST(GPGME_PTHREAD_CFLAGS)
235 AC_SUBST(GPGME_PTHREAD_LIBS)
239 dnl AM_PATH_GPGME_GLIB([MINIMUM-VERSION,
240 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
241 dnl Test for libgpgme-glib and define GPGME_GLIB_CFLAGS and GPGME_GLIB_LIBS.
243 AC_DEFUN([AM_PATH_GPGME_GLIB],
244 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
245 tmp=ifelse([$1], ,1:0.4.2,$1)
246 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
247 req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
248 min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
251 min_gpgme_version="$tmp"
254 AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
256 if test "$GPGME_CONFIG" != "no" ; then
257 req_major=`echo $min_gpgme_version | \
258 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
259 req_minor=`echo $min_gpgme_version | \
260 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
261 req_micro=`echo $min_gpgme_version | \
262 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
263 if test "$gpgme_version_major" -gt "$req_major"; then
266 if test "$gpgme_version_major" -eq "$req_major"; then
267 if test "$gpgme_version_minor" -gt "$req_minor"; then
270 if test "$gpgme_version_minor" -eq "$req_minor"; then
271 if test "$gpgme_version_micro" -ge "$req_micro"; then
279 if test $ok = yes; then
280 # If we have a recent GPGME, we should also check that the
282 if test "$req_gpgme_api" -gt 0 ; then
283 if test -z "$use_gpgrt_config"; then
284 tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
286 tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
288 if test "$tmp" -gt 0 ; then
289 if test "$req_gpgme_api" -ne "$tmp" ; then
295 if test $ok = yes; then
296 if test -z "$use_gpgrt_config"; then
297 GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --glib --cflags`
298 GPGME_GLIB_LIBS=`$GPGME_CONFIG --glib --libs`
300 if $GPGRT_CONFIG gpgme-glib --exists; then
301 GPGME_CONFIG="$GPGRT_CONFIG gpgme-glib"
302 GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --cflags`
303 GPGME_GLIB_LIBS=`$GPGME_CONFIG --libs`
309 if test $ok = yes; then
311 ifelse([$2], , :, [$2])
312 _AM_PATH_GPGME_CONFIG_HOST_CHECK
317 ifelse([$3], , :, [$3])
319 AC_SUBST(GPGME_GLIB_CFLAGS)
320 AC_SUBST(GPGME_GLIB_LIBS)