1 # ksba.m4 - autoconf macro to detect ksba
2 # Copyright (C) 2002 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.
13 dnl AM_PATH_KSBA([MINIMUM-VERSION,
14 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
15 dnl Test for libksba and define KSBA_CFLAGS and KSBA_LIBS
16 dnl MINIMUM-VERSION is a string with the version number optionalliy prefixed
17 dnl with the API version to also check the API compatibility. Example:
18 dnl a MINIMUM-VERSION of 1:1.0.7 won't pass the test unless the installed
19 dnl version of libksba is at least 1.0.7 *and* the API number is 1. Using
20 dnl this feature prevents building against newer versions of libksba
21 dnl with a changed API.
23 AC_DEFUN([AM_PATH_KSBA],
24 [AC_REQUIRE([AC_CANONICAL_HOST])
25 AC_ARG_WITH(ksba-prefix,
26 AC_HELP_STRING([--with-ksba-prefix=PFX],
27 [prefix where KSBA is installed (optional)]),
28 ksba_config_prefix="$withval", ksba_config_prefix="")
29 if test x$ksba_config_prefix != x ; then
30 ksba_config_args="$ksba_config_args --prefix=$ksba_config_prefix"
31 if test x${KSBA_CONFIG+set} != xset ; then
32 KSBA_CONFIG=$ksba_config_prefix/bin/ksba-config
36 AC_PATH_PROG(KSBA_CONFIG, ksba-config, no)
37 tmp=ifelse([$1], ,1:1.0.0,$1)
38 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
39 req_ksba_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
40 min_ksba_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
43 min_ksba_version="$tmp"
46 AC_MSG_CHECKING(for KSBA - version >= $min_ksba_version)
48 if test "$KSBA_CONFIG" != "no" ; then
49 req_major=`echo $min_ksba_version | \
50 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
51 req_minor=`echo $min_ksba_version | \
52 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
53 req_micro=`echo $min_ksba_version | \
54 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
55 ksba_config_version=`$KSBA_CONFIG $ksba_config_args --version`
56 major=`echo $ksba_config_version | \
57 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
58 minor=`echo $ksba_config_version | \
59 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
60 micro=`echo $ksba_config_version | \
61 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
62 if test "$major" -gt "$req_major"; then
65 if test "$major" -eq "$req_major"; then
66 if test "$minor" -gt "$req_minor"; then
69 if test "$minor" -eq "$req_minor"; then
70 if test "$micro" -ge "$req_micro"; then
78 if test $ok = yes; then
79 AC_MSG_RESULT([yes ($ksba_config_version)])
83 if test $ok = yes; then
84 # Even if we have a recent libksba, we should check that the
86 if test "$req_ksba_api" -gt 0 ; then
87 tmp=`$KSBA_CONFIG --api-version 2>/dev/null || echo 0`
88 if test "$tmp" -gt 0 ; then
89 AC_MSG_CHECKING([KSBA API version])
90 if test "$req_ksba_api" -eq "$tmp" ; then
94 AC_MSG_RESULT([does not match. want=$req_ksba_api got=$tmp.])
99 if test $ok = yes; then
100 KSBA_CFLAGS=`$KSBA_CONFIG $ksba_config_args --cflags`
101 KSBA_LIBS=`$KSBA_CONFIG $ksba_config_args --libs`
102 ifelse([$2], , :, [$2])
103 libksba_config_host=`$LIBKSBA_CONFIG $ksba_config_args --host 2>/dev/null || echo none`
104 if test x"$libksba_config_host" != xnone ; then
105 if test x"$libksba_config_host" != x"$host" ; then
108 *** The config script $LIBKSBA_CONFIG was
109 *** built for $libksba_config_host and thus may not match the
111 *** You may want to use the configure option --with-libksba-prefix
112 *** to specify a matching config script.
119 ifelse([$3], , :, [$3])
121 AC_SUBST(KSBA_CFLAGS)