1 # gpgme.m4 - autoconf macro to detect GPGME.
2 # Copyright (C) 2002, 2003, 2004, 2014, 2018, 2022 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: 2022-11-25
16 dnl Find gpgrt-config, which uses .pc file
17 dnl (minimum pkg-config functionality, supporting cross build)
19 dnl _AM_PATH_GPGRT_CONFIG
20 AC_DEFUN([_AM_PATH_GPGRT_CONFIG],[dnl
21 AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH])
22 if test "$GPGRT_CONFIG" != "no"; then
23 # Determine gpgrt_libdir
25 # Get the prefix of gpgrt-config assuming it's something like:
26 # <PREFIX>/bin/gpgrt-config
27 gpgrt_prefix=${GPGRT_CONFIG%/*/*}
28 possible_libdir1=${gpgrt_prefix}/lib
29 # Determine by using system libdir-format with CC, it's like:
30 # Normal style: /usr/lib
31 # GNU cross style: /usr/<triplet>/lib
32 # Debian style: /usr/lib/<multiarch-name>
33 # Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64
34 # It is assumed that CC is specified to the one of host on cross build.
35 if libdir_candidates=$(${CC:-cc} -print-search-dirs | \
36 sed -n -e "/^libraries/{s/libraries: =//;s/:/\\
38 # From the output of -print-search-dirs, select valid pkgconfig dirs.
39 libdir_candidates=$(for dir in $libdir_candidates; do
40 if p=$(cd $dir 2>/dev/null && pwd); then
41 test -d "$p/pkgconfig" && echo $p;
45 for possible_libdir0 in $libdir_candidates; do
47 # Fallback candidate, the one of system-installed (by $CC)
48 # (/usr/<triplet>/lib, /usr/lib/<multiarch-name> or /usr/lib32)
50 # Another candidate, user-locally-installed
51 # (<gpgrt_prefix>/lib)
54 # (<gpgrt_prefix>/<triplet>/lib,
55 # <gpgrt_prefix>/lib/<multiarch-name> or <gpgrt_prefix>/lib32)
56 if test "${possible_libdir0##*/}" = "lib"; then
57 possible_prefix0=${possible_libdir0%/lib}
58 possible_prefix0_triplet=${possible_prefix0##*/}
59 if test -z "$possible_prefix0_triplet"; then
62 possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib
64 possible_prefix0=${possible_libdir0%%/lib*}
65 possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0}
67 if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then
68 gpgrt_libdir=${possible_libdir2}
69 elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then
70 gpgrt_libdir=${possible_libdir1}
71 elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then
72 gpgrt_libdir=${possible_libdir0}
74 if test -n "$gpgrt_libdir"; then break; fi
76 if test -z "$libdir_candidates"; then
77 # No valid pkgconfig dir in any of the system directories, fallback
78 gpgrt_libdir=${possible_libdir1}
81 # When we cannot determine system libdir-format, use this:
82 gpgrt_libdir=${possible_libdir1}
88 if test -n "$gpgrt_libdir"; then
89 GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir"
90 if $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then
91 GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error"
92 AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config])
93 gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion`
97 elif test "$GPG_ERROR_CONFIG" != "no"; then
98 gpg_error_config_version=`$GPG_ERROR_CONFIG --version`
103 AC_DEFUN([_AM_PATH_GPGME_CONFIG],[dnl
104 AC_REQUIRE([_AM_PATH_GPGRT_CONFIG])dnl
105 AC_ARG_WITH(gpgme-prefix,
106 AS_HELP_STRING([--with-gpgme-prefix=PFX],
107 [prefix where GPGME is installed (optional)]),
108 gpgme_config_prefix="$withval", gpgme_config_prefix="")
109 if test x"${GPGME_CONFIG}" = x ; then
110 if test x"${gpgme_config_prefix}" != x ; then
111 GPGME_CONFIG="${gpgme_config_prefix}/bin/gpgme-config"
115 if test -x "${SYSROOT}/bin/gpgme-config" ; then
116 GPGME_CONFIG="${SYSROOT}/bin/gpgme-config"
122 AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
129 if test x"$GPGRT_CONFIG" != x -a "$GPGRT_CONFIG" != "no"; then
130 if $GPGRT_CONFIG gpgme --exists; then
131 GPGME_CONFIG="$GPGRT_CONFIG gpgme"
132 AC_MSG_NOTICE([Use gpgrt-config as gpgme-config])
136 if test -z "$use_gpgrt_config"; then
137 AC_PATH_PROG(GPGME_CONFIG, gpgme-config, no)
140 if test "$GPGME_CONFIG" != "no" ; then
141 if test -z "$use_gpgrt_config"; then
142 gpgme_version=`$GPGME_CONFIG --version`
144 gpgme_version=`$GPGME_CONFIG --modversion`
147 gpgme_version_major=`echo $gpgme_version | \
148 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
149 gpgme_version_minor=`echo $gpgme_version | \
150 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
151 gpgme_version_micro=`echo $gpgme_version | \
152 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
156 AC_DEFUN([_AM_PATH_GPGME_CONFIG_HOST_CHECK],
158 if test -z "$use_gpgrt_config"; then
159 gpgme_config_host=`$GPGME_CONFIG --host 2>/dev/null || echo none`
161 gpgme_config_host=`$GPGME_CONFIG --variable=host 2>/dev/null || echo none`
163 if test x"$gpgme_config_host" != xnone ; then
164 if test x"$gpgme_config_host" != x"$host" ; then
167 *** The config script "$GPGME_CONFIG" was
168 *** built for $gpgme_config_host and thus may not match the
170 *** You may want to use the configure option --with-gpgme-prefix
171 *** to specify a matching config script or use \$SYSROOT.
173 gpg_config_script_warn="$gpg_config_script_warn gpgme"
179 dnl AM_PATH_GPGME([MINIMUM-VERSION,
180 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
181 dnl Test for libgpgme and define GPGME_CFLAGS and GPGME_LIBS.
183 dnl If a prefix option is not used, the config script is first
184 dnl searched in $SYSROOT/bin and then along $PATH. If the used
185 dnl config script does not match the host specification the script
186 dnl is added to the gpg_config_script_warn variable.
188 AC_DEFUN([AM_PATH_GPGME],
189 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
190 tmp=ifelse([$1], ,1:0.4.2,$1)
191 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
192 req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
193 min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
196 min_gpgme_version="$tmp"
199 AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
201 if test "$GPGME_CONFIG" != "no" ; then
202 req_major=`echo $min_gpgme_version | \
203 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
204 req_minor=`echo $min_gpgme_version | \
205 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
206 req_micro=`echo $min_gpgme_version | \
207 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
208 if test "$gpgme_version_major" -gt "$req_major"; then
211 if test "$gpgme_version_major" -eq "$req_major"; then
212 if test "$gpgme_version_minor" -gt "$req_minor"; then
215 if test "$gpgme_version_minor" -eq "$req_minor"; then
216 if test "$gpgme_version_micro" -ge "$req_micro"; then
224 if test $ok = yes; then
225 # If we have a recent GPGME, we should also check that the
227 if test "$req_gpgme_api" -gt 0 ; then
228 if test -z "$use_gpgrt_config"; then
229 tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
231 tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
233 if test "$tmp" -gt 0 ; then
234 if test "$req_gpgme_api" -ne "$tmp" ; then
240 if test $ok = yes; then
241 GPGME_CFLAGS=`$GPGME_CONFIG --cflags`
242 GPGME_LIBS=`$GPGME_CONFIG --libs`
244 ifelse([$2], , :, [$2])
245 _AM_PATH_GPGME_CONFIG_HOST_CHECK
250 ifelse([$3], , :, [$3])
252 AC_SUBST(GPGME_CFLAGS)
256 dnl AM_PATH_GPGME_PTHREAD([MINIMUM-VERSION,
257 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
258 dnl Test for libgpgme and define GPGME_PTHREAD_CFLAGS
259 dnl and GPGME_PTHREAD_LIBS.
261 AC_DEFUN([AM_PATH_GPGME_PTHREAD],[
262 AC_OBSOLETE([$0], [; use AM_PATH_GPGME instead to use GPGME_CFLAGS and GPGME_LIBS])dnl
263 AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
264 tmp=ifelse([$1], ,1:0.4.2,$1)
265 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
266 req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
267 min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
270 min_gpgme_version="$tmp"
273 AC_MSG_CHECKING(for GPGME pthread - version >= $min_gpgme_version)
275 if test "$GPGME_CONFIG" != "no" ; then
276 req_major=`echo $min_gpgme_version | \
277 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
278 req_minor=`echo $min_gpgme_version | \
279 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
280 req_micro=`echo $min_gpgme_version | \
281 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
282 if test "$gpgme_version_major" -gt "$req_major"; then
285 if test "$gpgme_version_major" -eq "$req_major"; then
286 if test "$gpgme_version_minor" -gt "$req_minor"; then
289 if test "$gpgme_version_minor" -eq "$req_minor"; then
290 if test "$gpgme_version_micro" -ge "$req_micro"; then
298 if test $ok = yes; then
299 # If we have a recent GPGME, we should also check that the
301 if test "$req_gpgme_api" -gt 0 ; then
302 if test -z "$use_gpgrt_config"; then
303 tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
305 tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
307 if test "$tmp" -gt 0 ; then
308 if test "$req_gpgme_api" -ne "$tmp" ; then
314 if test $ok = yes; then
315 GPGME_PTHREAD_CFLAGS=`$GPGME_CONFIG --cflags`
316 GPGME_PTHREAD_LIBS=`$GPGME_CONFIG --libs`
318 ifelse([$2], , :, [$2])
319 _AM_PATH_GPGME_CONFIG_HOST_CHECK
321 GPGME_PTHREAD_CFLAGS=""
322 GPGME_PTHREAD_LIBS=""
324 ifelse([$3], , :, [$3])
326 AC_SUBST(GPGME_PTHREAD_CFLAGS)
327 AC_SUBST(GPGME_PTHREAD_LIBS)
331 dnl AM_PATH_GPGME_GLIB([MINIMUM-VERSION,
332 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
333 dnl Test for libgpgme-glib and define GPGME_GLIB_CFLAGS and GPGME_GLIB_LIBS.
335 AC_DEFUN([AM_PATH_GPGME_GLIB],
336 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
337 tmp=ifelse([$1], ,1:0.4.2,$1)
338 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
339 req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
340 min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
343 min_gpgme_version="$tmp"
346 AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
348 if test "$GPGME_CONFIG" != "no" ; then
349 req_major=`echo $min_gpgme_version | \
350 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
351 req_minor=`echo $min_gpgme_version | \
352 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
353 req_micro=`echo $min_gpgme_version | \
354 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
355 if test "$gpgme_version_major" -gt "$req_major"; then
358 if test "$gpgme_version_major" -eq "$req_major"; then
359 if test "$gpgme_version_minor" -gt "$req_minor"; then
362 if test "$gpgme_version_minor" -eq "$req_minor"; then
363 if test "$gpgme_version_micro" -ge "$req_micro"; then
371 if test $ok = yes; then
372 # If we have a recent GPGME, we should also check that the
374 if test "$req_gpgme_api" -gt 0 ; then
375 if test -z "$use_gpgrt_config"; then
376 tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
378 tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
380 if test "$tmp" -gt 0 ; then
381 if test "$req_gpgme_api" -ne "$tmp" ; then
387 if test $ok = yes; then
388 if test -z "$use_gpgrt_config"; then
389 GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --glib --cflags`
390 GPGME_GLIB_LIBS=`$GPGME_CONFIG --glib --libs`
392 if $GPGRT_CONFIG gpgme-glib --exists; then
393 GPGME_CONFIG="$GPGRT_CONFIG gpgme-glib"
394 GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --cflags`
395 GPGME_GLIB_LIBS=`$GPGME_CONFIG --libs`
401 if test $ok = yes; then
403 ifelse([$2], , :, [$2])
404 _AM_PATH_GPGME_CONFIG_HOST_CHECK
409 ifelse([$3], , :, [$3])
411 AC_SUBST(GPGME_GLIB_CFLAGS)
412 AC_SUBST(GPGME_GLIB_LIBS)