| 1 |
# ksba.m4 - autoconf macro to detect ksba |
| 2 |
# Copyright (C) 2002, 2018, 2024 g10 Code GmbH |
| 3 |
# |
| 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. |
| 7 |
# |
| 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. |
| 11 |
# |
| 12 |
# Last-changed: 2025-09-25 |
| 13 |
|
| 14 |
dnl |
| 15 |
dnl Find gpgrt-config, which uses .pc file |
| 16 |
dnl (minimum pkg-config functionality, supporting cross build) |
| 17 |
dnl |
| 18 |
dnl _AM_PATH_GPGRT_CONFIG |
| 19 |
AC_DEFUN([_AM_PATH_GPGRT_CONFIG],[dnl |
| 20 |
AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH]) |
| 21 |
if test "$GPGRT_CONFIG" != "no"; then |
| 22 |
# Determine gpgrt_libdir |
| 23 |
# |
| 24 |
# Get the prefix of gpgrt-config assuming it's something like: |
| 25 |
# <PREFIX>/bin/gpgrt-config |
| 26 |
gpgrt_prefix=${GPGRT_CONFIG%/*/*} |
| 27 |
possible_libdir1=${gpgrt_prefix}/lib |
| 28 |
# Determine by using system libdir-format with CC, it's like: |
| 29 |
# Normal style: /usr/lib |
| 30 |
# GNU cross style: /usr/<triplet>/lib |
| 31 |
# Debian style: /usr/lib/<multiarch-name> |
| 32 |
# Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64 |
| 33 |
# It is assumed that CC is specified to the one of host on cross build. |
| 34 |
if libdir_candidates=$(${CC:-cc} -print-search-dirs | \ |
| 35 |
sed -n -e "/^libraries/{s/libraries: =//;s/:/\\ |
| 36 |
/g;p;}"); then |
| 37 |
# From the output of -print-search-dirs, select valid pkgconfig dirs. |
| 38 |
libdir_candidates=$(for dir in $libdir_candidates; do |
| 39 |
if p=$(cd $dir 2>/dev/null && pwd); then |
| 40 |
test -d "$p/pkgconfig" && echo $p; |
| 41 |
fi |
| 42 |
done) |
| 43 |
|
| 44 |
for possible_libdir0 in $libdir_candidates; do |
| 45 |
# possible_libdir0: |
| 46 |
# Fallback candidate, the one of system-installed (by $CC) |
| 47 |
# (/usr/<triplet>/lib, /usr/lib/<multiarch-name> or /usr/lib32) |
| 48 |
# possible_libdir1: |
| 49 |
# Another candidate, user-locally-installed |
| 50 |
# (<gpgrt_prefix>/lib) |
| 51 |
# possible_libdir2 |
| 52 |
# Most preferred |
| 53 |
# (<gpgrt_prefix>/<triplet>/lib, |
| 54 |
# <gpgrt_prefix>/lib/<multiarch-name> or <gpgrt_prefix>/lib32) |
| 55 |
if test "${possible_libdir0##*/}" = "lib"; then |
| 56 |
possible_prefix0=${possible_libdir0%/lib} |
| 57 |
possible_prefix0_triplet=${possible_prefix0##*/} |
| 58 |
if test -z "$possible_prefix0_triplet"; then |
| 59 |
continue |
| 60 |
fi |
| 61 |
possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib |
| 62 |
else |
| 63 |
possible_prefix0=${possible_libdir0%%/lib*} |
| 64 |
possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0} |
| 65 |
fi |
| 66 |
if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then |
| 67 |
gpgrt_libdir=${possible_libdir2} |
| 68 |
elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then |
| 69 |
gpgrt_libdir=${possible_libdir1} |
| 70 |
elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then |
| 71 |
gpgrt_libdir=${possible_libdir0} |
| 72 |
fi |
| 73 |
if test -n "$gpgrt_libdir"; then break; fi |
| 74 |
done |
| 75 |
fi |
| 76 |
if test -z "$gpgrt_libdir"; then |
| 77 |
# No valid pkgconfig dir in any of the system directories, fallback |
| 78 |
gpgrt_libdir=${possible_libdir1} |
| 79 |
fi |
| 80 |
else |
| 81 |
unset GPGRT_CONFIG |
| 82 |
fi |
| 83 |
|
| 84 |
if test -n "$gpgrt_libdir"; then |
| 85 |
# Add the --libdir option to GPGRT_CONFIG |
| 86 |
GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir" |
| 87 |
# Make sure if gpgrt-config really works, by testing config gpg-error |
| 88 |
if ! $GPGRT_CONFIG gpg-error --exists; then |
| 89 |
# If it doesn't work, clear the GPGRT_CONFIG variable. |
| 90 |
unset GPGRT_CONFIG |
| 91 |
fi |
| 92 |
else |
| 93 |
# GPGRT_CONFIG found but no suitable dir for --libdir found. |
| 94 |
# This is a failure. Clear the GPGRT_CONFIG variable. |
| 95 |
unset GPGRT_CONFIG |
| 96 |
fi |
| 97 |
]) |
| 98 |
|
| 99 |
dnl AM_PATH_KSBA([MINIMUM-VERSION, |
| 100 |
dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) |
| 101 |
dnl Test for libksba and define KSBA_CFLAGS and KSBA_LIBS |
| 102 |
dnl MINIMUM-VERSION is a string with the version number optionally prefixed |
| 103 |
dnl with the API version to also check the API compatibility. Example: |
| 104 |
dnl a MINIMUM-VERSION of 1:1.0.7 won't pass the test unless the installed |
| 105 |
dnl version of libksba is at least 1.0.7 *and* the API number is 1. Using |
| 106 |
dnl this features allows to prevent build against newer versions of libksba |
| 107 |
dnl with a changed API. |
| 108 |
dnl |
| 109 |
AC_DEFUN([AM_PATH_KSBA], |
| 110 |
[ AC_REQUIRE([AC_CANONICAL_HOST])dnl |
| 111 |
AC_REQUIRE([_AM_PATH_GPGRT_CONFIG])dnl |
| 112 |
dnl --with-libksba-prefix=PFX is the preferred name for this option, |
| 113 |
dnl since that is consistent with how our three siblings use the directory/ |
| 114 |
dnl package name in --with-$dir_name-prefix=PFX. |
| 115 |
AC_ARG_WITH(libksba-prefix, |
| 116 |
AS_HELP_STRING([--with-libksba-prefix=PFX], |
| 117 |
[prefix where KSBA is installed (optional)]), |
| 118 |
ksba_config_prefix="$withval", ksba_config_prefix="") |
| 119 |
|
| 120 |
dnl Accept --with-ksba-prefix and make it work the same as |
| 121 |
dnl --with-libksba-prefix above, for backwards compatibility, |
| 122 |
dnl but do not document this old, inconsistently-named option. |
| 123 |
AC_ARG_WITH(ksba-prefix,, |
| 124 |
ksba_config_prefix="$withval", ksba_config_prefix="") |
| 125 |
|
| 126 |
if test x$ksba_config_prefix != x ; then |
| 127 |
if test x${KSBA_CONFIG+set} != xset ; then |
| 128 |
KSBA_CONFIG=$ksba_config_prefix/bin/ksba-config |
| 129 |
fi |
| 130 |
fi |
| 131 |
|
| 132 |
use_gpgrt_config="" |
| 133 |
if test x"$GPGRT_CONFIG" != x && test "$GPGRT_CONFIG" != "no"; then |
| 134 |
if $GPGRT_CONFIG ksba --exists; then |
| 135 |
KSBA_CONFIG="$GPGRT_CONFIG ksba" |
| 136 |
AC_MSG_NOTICE([Use gpgrt-config as ksba-config]) |
| 137 |
use_gpgrt_config=yes |
| 138 |
fi |
| 139 |
fi |
| 140 |
if test -z "$use_gpgrt_config"; then |
| 141 |
AC_PATH_PROG(KSBA_CONFIG, ksba-config, no) |
| 142 |
fi |
| 143 |
|
| 144 |
tmp=ifelse([$1], ,1:1.0.0,$1) |
| 145 |
if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then |
| 146 |
req_ksba_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'` |
| 147 |
min_ksba_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'` |
| 148 |
else |
| 149 |
req_ksba_api=0 |
| 150 |
min_ksba_version="$tmp" |
| 151 |
fi |
| 152 |
|
| 153 |
AC_MSG_CHECKING(for KSBA - version >= $min_ksba_version) |
| 154 |
ok=no |
| 155 |
if test "$KSBA_CONFIG" != "no" ; then |
| 156 |
req_major=`echo $min_ksba_version | \ |
| 157 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` |
| 158 |
req_minor=`echo $min_ksba_version | \ |
| 159 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` |
| 160 |
req_micro=`echo $min_ksba_version | \ |
| 161 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'` |
| 162 |
if test -z "$use_gpgrt_config"; then |
| 163 |
ksba_config_version=`$KSBA_CONFIG --version` |
| 164 |
else |
| 165 |
ksba_config_version=`$KSBA_CONFIG --modversion` |
| 166 |
fi |
| 167 |
major=`echo $ksba_config_version | \ |
| 168 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` |
| 169 |
minor=`echo $ksba_config_version | \ |
| 170 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` |
| 171 |
micro=`echo $ksba_config_version | \ |
| 172 |
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'` |
| 173 |
if test "$major" -gt "$req_major"; then |
| 174 |
ok=yes |
| 175 |
else |
| 176 |
if test "$major" -eq "$req_major"; then |
| 177 |
if test "$minor" -gt "$req_minor"; then |
| 178 |
ok=yes |
| 179 |
else |
| 180 |
if test "$minor" -eq "$req_minor"; then |
| 181 |
if test "$micro" -ge "$req_micro"; then |
| 182 |
ok=yes |
| 183 |
fi |
| 184 |
fi |
| 185 |
fi |
| 186 |
fi |
| 187 |
fi |
| 188 |
fi |
| 189 |
if test $ok = yes; then |
| 190 |
AC_MSG_RESULT([yes ($ksba_config_version)]) |
| 191 |
else |
| 192 |
AC_MSG_RESULT(no) |
| 193 |
fi |
| 194 |
if test $ok = yes; then |
| 195 |
# Even if we have a recent libksba, we should check that the |
| 196 |
# API is compatible. |
| 197 |
if test "$req_ksba_api" -gt 0 ; then |
| 198 |
if test -z "$use_gpgrt_config"; then |
| 199 |
tmp=`$KSBA_CONFIG --api-version 2>/dev/null || echo 0` |
| 200 |
else |
| 201 |
tmp=`$KSBA_CONFIG --variable=api_version 2>/dev/null || echo 0` |
| 202 |
fi |
| 203 |
if test "$tmp" -gt 0 ; then |
| 204 |
AC_MSG_CHECKING([KSBA API version]) |
| 205 |
if test "$req_ksba_api" -eq "$tmp" ; then |
| 206 |
AC_MSG_RESULT(okay) |
| 207 |
else |
| 208 |
ok=no |
| 209 |
AC_MSG_RESULT([does not match. want=$req_ksba_api got=$tmp.]) |
| 210 |
fi |
| 211 |
fi |
| 212 |
fi |
| 213 |
fi |
| 214 |
if test $ok = yes; then |
| 215 |
KSBA_CFLAGS=`$KSBA_CONFIG --cflags` |
| 216 |
KSBA_LIBS=`$KSBA_CONFIG --libs` |
| 217 |
ifelse([$2], , :, [$2]) |
| 218 |
if test -z "$use_gpgrt_config"; then |
| 219 |
libksba_config_host=`$KSBA_CONFIG --host 2>/dev/null || echo none` |
| 220 |
else |
| 221 |
libksba_config_host=`$KSBA_CONFIG --variable=host 2>/dev/null || echo none` |
| 222 |
fi |
| 223 |
if test x"$libksba_config_host" != xnone ; then |
| 224 |
if test x"$libksba_config_host" != x"$host" ; then |
| 225 |
AC_MSG_WARN([[ |
| 226 |
*** |
| 227 |
*** The config script "$KSBA_CONFIG" was |
| 228 |
*** built for $libksba_config_host and thus may not match the |
| 229 |
*** used host $host. |
| 230 |
*** You may want to use the configure option --with-libksba-prefix |
| 231 |
*** to specify a matching config script. |
| 232 |
***]]) |
| 233 |
fi |
| 234 |
fi |
| 235 |
else |
| 236 |
KSBA_CFLAGS="" |
| 237 |
KSBA_LIBS="" |
| 238 |
ifelse([$3], , :, [$3]) |
| 239 |
fi |
| 240 |
AC_SUBST(KSBA_CFLAGS) |
| 241 |
AC_SUBST(KSBA_LIBS) |
| 242 |
]) |