1 # ksba.m4 - autoconf macro to detect ksba
2 # Copyright (C) 2002, 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-18
14 dnl AM_PATH_KSBA([MINIMUM-VERSION,
15 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
16 dnl Test for libksba and define KSBA_CFLAGS and KSBA_LIBS
17 dnl MINIMUN-VERSION is a string with the version number optionalliy prefixed
18 dnl with the API version to also check the API compatibility. Example:
19 dnl a MINIMUN-VERSION of 1:1.0.7 won't pass the test unless the installed
20 dnl version of libksba is at least 1.0.7 *and* the API number is 1. Using
21 dnl this features allows to prevent build against newer versions of libksba
22 dnl with a changed API.
24 AC_DEFUN([AM_PATH_KSBA],
25 [ AC_REQUIRE([AC_CANONICAL_HOST])
26 dnl --with-libksba-prefix=PFX is the preferred name for this option,
27 dnl since that is consistent with how our three siblings use the directory/
28 dnl package name in --with-$dir_name-prefix=PFX.
29 AC_ARG_WITH(libksba-prefix,
30 AS_HELP_STRING([--with-libksba-prefix=PFX],
31 [prefix where KSBA is installed (optional)]),
32 ksba_config_prefix="$withval", ksba_config_prefix="")
34 dnl Accept --with-ksba-prefix and make it work the same as
35 dnl --with-libksba-prefix above, for backwards compatibility,
36 dnl but do not document this old, inconsistently-named option.
37 AC_ARG_WITH(ksba-prefix,,
38 ksba_config_prefix="$withval", ksba_config_prefix="")
40 if test x$ksba_config_prefix != x ; then
41 if test x${KSBA_CONFIG+set} != xset ; then
42 KSBA_CONFIG=$ksba_config_prefix/bin/ksba-config
47 if test x"$KSBA_CONFIG" = x -a x"$GPGRT_CONFIG" != x -a "$GPGRT_CONFIG" != "no"; then
48 if $GPGRT_CONFIG ksba --exists; then
49 KSBA_CONFIG="$GPGRT_CONFIG ksba"
50 AC_MSG_NOTICE([Use gpgrt-config as ksba-config])
54 if test -z "$use_gpgrt_config"; then
55 AC_PATH_PROG(KSBA_CONFIG, ksba-config, no)
58 tmp=ifelse([$1], ,1:1.0.0,$1)
59 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
60 req_ksba_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
61 min_ksba_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
64 min_ksba_version="$tmp"
67 AC_MSG_CHECKING(for KSBA - version >= $min_ksba_version)
69 if test "$KSBA_CONFIG" != "no" ; then
70 req_major=`echo $min_ksba_version | \
71 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
72 req_minor=`echo $min_ksba_version | \
73 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
74 req_micro=`echo $min_ksba_version | \
75 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
76 if test -z "$use_gpgrt_config"; then
77 ksba_config_version=`$KSBA_CONFIG --version`
79 ksba_config_version=`$KSBA_CONFIG --modversion`
81 major=`echo $ksba_config_version | \
82 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
83 minor=`echo $ksba_config_version | \
84 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
85 micro=`echo $ksba_config_version | \
86 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
87 if test "$major" -gt "$req_major"; then
90 if test "$major" -eq "$req_major"; then
91 if test "$minor" -gt "$req_minor"; then
94 if test "$minor" -eq "$req_minor"; then
95 if test "$micro" -ge "$req_micro"; then
103 if test $ok = yes; then
104 AC_MSG_RESULT([yes ($ksba_config_version)])
108 if test $ok = yes; then
109 # Even if we have a recent libksba, we should check that the
111 if test "$req_ksba_api" -gt 0 ; then
112 if test -z "$use_gpgrt_config"; then
113 tmp=`$KSBA_CONFIG --api-version 2>/dev/null || echo 0`
115 tmp=`$KSBA_CONFIG --variable=api_version 2>/dev/null || echo 0`
117 if test "$tmp" -gt 0 ; then
118 AC_MSG_CHECKING([KSBA API version])
119 if test "$req_ksba_api" -eq "$tmp" ; then
123 AC_MSG_RESULT([does not match. want=$req_ksba_api got=$tmp.])
128 if test $ok = yes; then
129 KSBA_CFLAGS=`$KSBA_CONFIG --cflags`
130 KSBA_LIBS=`$KSBA_CONFIG --libs`
131 ifelse([$2], , :, [$2])
132 if test -z "$use_gpgrt_config"; then
133 libksba_config_host=`$KSBA_CONFIG --host 2>/dev/null || echo none`
135 libksba_config_host=`$KSBA_CONFIG --variable=host 2>/dev/null || echo none`
137 if test x"$libksba_config_host" != xnone ; then
138 if test x"$libksba_config_host" != x"$host" ; then
141 *** The config script "$KSBA_CONFIG" was
142 *** built for $libksba_config_host and thus may not match the
144 *** You may want to use the configure option --with-libksba-prefix
145 *** to specify a matching config script.
152 ifelse([$3], , :, [$3])
154 AC_SUBST(KSBA_CFLAGS)