| 1 |
# gpg-error.m4 - autoconf macro to detect libgpg-error. |
| 2 |
# Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018, 2020, 2021, 2022, 2024, |
| 3 |
# 2025 g10 Code GmbH |
| 4 |
# |
| 5 |
# This file is free software; as a special exception the author gives |
| 6 |
# unlimited permission to copy and/or distribute it, with or without |
| 7 |
# modifications, as long as this notice is preserved. |
| 8 |
# |
| 9 |
# This file is distributed in the hope that it will be useful, but |
| 10 |
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the |
| 11 |
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
# |
| 13 |
# Last-changed: 2025-09-24 |
| 14 |
|
| 15 |
dnl |
| 16 |
dnl Find gpg-error-config, for backward compatibility |
| 17 |
dnl |
| 18 |
dnl _AM_PATH_POSSIBLE_GPG_ERROR_CONFIG |
| 19 |
AC_DEFUN([_AM_PATH_POSSIBLE_GPG_ERROR_CONFIG],[dnl |
| 20 |
gpg_error_config_prefix="" |
| 21 |
dnl --with-libgpg-error-prefix=PFX is the preferred name for this option, |
| 22 |
dnl since that is consistent with how our three siblings use the directory/ |
| 23 |
dnl package name in --with-$dir_name-prefix=PFX. |
| 24 |
AC_ARG_WITH(libgpg-error-prefix, |
| 25 |
AS_HELP_STRING([--with-libgpg-error-prefix=PFX], |
| 26 |
[prefix where GPG Error is installed (optional)]), |
| 27 |
[gpg_error_config_prefix="$withval"]) |
| 28 |
|
| 29 |
dnl Accept --with-gpg-error-prefix and make it work the same as |
| 30 |
dnl --with-libgpg-error-prefix above, for backwards compatibility, |
| 31 |
dnl but do not document this old, inconsistently-named option. |
| 32 |
AC_ARG_WITH(gpg-error-prefix,, |
| 33 |
[gpg_error_config_prefix="$withval"]) |
| 34 |
|
| 35 |
if test x"${GPG_ERROR_CONFIG}" = x ; then |
| 36 |
if test x"${gpg_error_config_prefix}" != x ; then |
| 37 |
GPG_ERROR_CONFIG="${gpg_error_config_prefix}/bin/gpg-error-config" |
| 38 |
else |
| 39 |
case "${SYSROOT}" in |
| 40 |
/*) |
| 41 |
if test -x "${SYSROOT}/bin/gpg-error-config" ; then |
| 42 |
GPG_ERROR_CONFIG="${SYSROOT}/bin/gpg-error-config" |
| 43 |
fi |
| 44 |
;; |
| 45 |
'') |
| 46 |
;; |
| 47 |
*) |
| 48 |
AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.]) |
| 49 |
;; |
| 50 |
esac |
| 51 |
fi |
| 52 |
fi |
| 53 |
|
| 54 |
AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no) |
| 55 |
]) |
| 56 |
|
| 57 |
dnl |
| 58 |
dnl Find gpgrt-config, which uses .pc file |
| 59 |
dnl (minimum pkg-config functionality, supporting cross build) |
| 60 |
dnl |
| 61 |
dnl _AM_PATH_GPGRT_CONFIG |
| 62 |
AC_DEFUN([_AM_PATH_GPGRT_CONFIG],[dnl |
| 63 |
AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH]) |
| 64 |
if test "$GPGRT_CONFIG" != "no"; then |
| 65 |
# Determine gpgrt_libdir |
| 66 |
# |
| 67 |
# Get the prefix of gpgrt-config assuming it's something like: |
| 68 |
# <PREFIX>/bin/gpgrt-config |
| 69 |
gpgrt_prefix=${GPGRT_CONFIG%/*/*} |
| 70 |
possible_libdir1=${gpgrt_prefix}/lib |
| 71 |
# Determine by using system libdir-format with CC, it's like: |
| 72 |
# Normal style: /usr/lib |
| 73 |
# GNU cross style: /usr/<triplet>/lib |
| 74 |
# Debian style: /usr/lib/<multiarch-name> |
| 75 |
# Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64 |
| 76 |
# It is assumed that CC is specified to the one of host on cross build. |
| 77 |
if libdir_candidates=$(${CC:-cc} -print-search-dirs | \ |
| 78 |
sed -n -e "/^libraries/{s/libraries: =//;s/:/\\ |
| 79 |
/g;p;}"); then |
| 80 |
# From the output of -print-search-dirs, select valid pkgconfig dirs. |
| 81 |
libdir_candidates=$(for dir in $libdir_candidates; do |
| 82 |
if p=$(cd $dir 2>/dev/null && pwd); then |
| 83 |
test -d "$p/pkgconfig" && echo $p; |
| 84 |
fi |
| 85 |
done) |
| 86 |
|
| 87 |
for possible_libdir0 in $libdir_candidates; do |
| 88 |
# possible_libdir0: |
| 89 |
# Fallback candidate, the one of system-installed (by $CC) |
| 90 |
# (/usr/<triplet>/lib, /usr/lib/<multiarch-name> or /usr/lib32) |
| 91 |
# possible_libdir1: |
| 92 |
# Another candidate, user-locally-installed |
| 93 |
# (<gpgrt_prefix>/lib) |
| 94 |
# possible_libdir2 |
| 95 |
# Most preferred |
| 96 |
# (<gpgrt_prefix>/<triplet>/lib, |
| 97 |
# <gpgrt_prefix>/lib/<multiarch-name> or <gpgrt_prefix>/lib32) |
| 98 |
if test "${possible_libdir0##*/}" = "lib"; then |
| 99 |
possible_prefix0=${possible_libdir0%/lib} |
| 100 |
possible_prefix0_triplet=${possible_prefix0##*/} |
| 101 |
if test -z "$possible_prefix0_triplet"; then |
| 102 |
continue |
| 103 |
fi |
| 104 |
possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib |
| 105 |
else |
| 106 |
possible_prefix0=${possible_libdir0%%/lib*} |
| 107 |
possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0} |
| 108 |
fi |
| 109 |
if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then |
| 110 |
gpgrt_libdir=${possible_libdir2} |
| 111 |
elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then |
| 112 |
gpgrt_libdir=${possible_libdir1} |
| 113 |
elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then |
| 114 |
gpgrt_libdir=${possible_libdir0} |
| 115 |
fi |
| 116 |
if test -n "$gpgrt_libdir"; then break; fi |
| 117 |
done |
| 118 |
fi |
| 119 |
if test -z "$gpgrt_libdir"; then |
| 120 |
# No valid pkgconfig dir in any of the system directories, fallback |
| 121 |
gpgrt_libdir=${possible_libdir1} |
| 122 |
fi |
| 123 |
else |
| 124 |
unset GPGRT_CONFIG |
| 125 |
fi |
| 126 |
|
| 127 |
if test -n "$gpgrt_libdir"; then |
| 128 |
# Add the --libdir option to GPGRT_CONFIG |
| 129 |
GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir" |
| 130 |
# Make sure if gpgrt-config really works, by testing config gpg-error |
| 131 |
if ! $GPGRT_CONFIG gpg-error --exists; then |
| 132 |
# If it doesn't work, clear the GPGRT_CONFIG variable. |
| 133 |
unset GPGRT_CONFIG |
| 134 |
fi |
| 135 |
else |
| 136 |
# GPGRT_CONFIG found but no suitable dir for --libdir found. |
| 137 |
# This is a failure. Clear the GPGRT_CONFIG variable. |
| 138 |
unset GPGRT_CONFIG |
| 139 |
fi |
| 140 |
]) |
| 141 |
|
| 142 |
dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION, |
| 143 |
dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) |
| 144 |
dnl |
| 145 |
dnl Test for libgpg-error and define GPG_ERROR_CFLAGS, GPG_ERROR_LIBS, |
| 146 |
dnl GPG_ERROR_MT_CFLAGS, and GPG_ERROR_MT_LIBS. The _MT_ variants are |
| 147 |
dnl used for programs requiring real multi thread support. |
| 148 |
dnl |
| 149 |
dnl If a prefix option is not used, the config script is first |
| 150 |
dnl searched in $SYSROOT/bin and then along $PATH. If the used |
| 151 |
dnl config script does not match the host specification the script |
| 152 |
dnl is added to the gpg_config_script_warn variable. |
| 153 |
dnl |
| 154 |
AC_DEFUN([AM_PATH_GPG_ERROR], |
| 155 |
[ AC_REQUIRE([AC_CANONICAL_HOST])dnl |
| 156 |
AC_REQUIRE([_AM_PATH_POSSIBLE_GPG_ERROR_CONFIG])dnl |
| 157 |
AC_REQUIRE([_AM_PATH_GPGRT_CONFIG])dnl |
| 158 |
if test x"$GPGRT_CONFIG" != x && test "$GPGRT_CONFIG" != "no"; then |
| 159 |
GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error" |
| 160 |
AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config]) |
| 161 |
gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion` |
| 162 |
elif test x"$GPG_ERROR_CONFIG" != x && test "$GPG_ERROR_CONFIG" != "no"; then |
| 163 |
gpg_error_config_version=`$GPG_ERROR_CONFIG --version` |
| 164 |
else |
| 165 |
gpg_error_config_version="0.0" |
| 166 |
fi |
| 167 |
|
| 168 |
min_gpg_error_version=ifelse([$1], ,1.33,$1) |
| 169 |
ok=no |
| 170 |
if test "$GPG_ERROR_CONFIG" != "no"; then |
| 171 |
req_major=`echo $min_gpg_error_version | \ |
| 172 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` |
| 173 |
req_minor=`echo $min_gpg_error_version | \ |
| 174 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` |
| 175 |
major=`echo $gpg_error_config_version | \ |
| 176 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` |
| 177 |
minor=`echo $gpg_error_config_version | \ |
| 178 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` |
| 179 |
if test "$major" -gt "$req_major"; then |
| 180 |
ok=yes |
| 181 |
else |
| 182 |
if test "$major" -eq "$req_major"; then |
| 183 |
if test "$minor" -ge "$req_minor"; then |
| 184 |
ok=yes |
| 185 |
fi |
| 186 |
fi |
| 187 |
fi |
| 188 |
fi |
| 189 |
AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version) |
| 190 |
if test $ok = yes; then |
| 191 |
GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG --cflags` |
| 192 |
GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG --libs` |
| 193 |
if test -z "$GPGRT_CONFIG"; then |
| 194 |
GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --mt --cflags 2>/dev/null` |
| 195 |
GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --mt --libs 2>/dev/null` |
| 196 |
else |
| 197 |
GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --variable=mtcflags 2>/dev/null` |
| 198 |
GPG_ERROR_MT_CFLAGS="$GPG_ERROR_CFLAGS${GPG_ERROR_CFLAGS:+ }$GPG_ERROR_MT_CFLAGS" |
| 199 |
GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --variable=mtlibs 2>/dev/null` |
| 200 |
GPG_ERROR_MT_LIBS="$GPG_ERROR_LIBS${GPG_ERROR_LIBS:+ }$GPG_ERROR_MT_LIBS" |
| 201 |
fi |
| 202 |
AC_MSG_RESULT([yes ($gpg_error_config_version)]) |
| 203 |
ifelse([$2], , :, [$2]) |
| 204 |
if test -z "$GPGRT_CONFIG"; then |
| 205 |
gpg_error_config_host=`$GPG_ERROR_CONFIG --host 2>/dev/null || echo none` |
| 206 |
else |
| 207 |
gpg_error_config_host=`$GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none` |
| 208 |
fi |
| 209 |
if test x"$gpg_error_config_host" != xnone ; then |
| 210 |
if test x"$gpg_error_config_host" != x"$host" ; then |
| 211 |
AC_MSG_WARN([[ |
| 212 |
*** |
| 213 |
*** The config script "$GPG_ERROR_CONFIG" was |
| 214 |
*** built for $gpg_error_config_host and thus may not match the |
| 215 |
*** used host $host. |
| 216 |
*** You may want to use the configure option --with-libgpg-error-prefix |
| 217 |
*** to specify a matching config script or use \$SYSROOT. |
| 218 |
***]]) |
| 219 |
gpg_config_script_warn="$gpg_config_script_warn libgpg-error" |
| 220 |
fi |
| 221 |
fi |
| 222 |
else |
| 223 |
GPG_ERROR_CFLAGS="" |
| 224 |
GPG_ERROR_LIBS="" |
| 225 |
GPG_ERROR_MT_CFLAGS="" |
| 226 |
GPG_ERROR_MT_LIBS="" |
| 227 |
AC_MSG_RESULT(no) |
| 228 |
ifelse([$3], , :, [$3]) |
| 229 |
fi |
| 230 |
AC_SUBST(GPG_ERROR_CFLAGS) |
| 231 |
AC_SUBST(GPG_ERROR_LIBS) |
| 232 |
AC_SUBST(GPG_ERROR_MT_CFLAGS) |
| 233 |
AC_SUBST(GPG_ERROR_MT_LIBS) |
| 234 |
]) |