Imported Upstream version 2.2.37
[platform/upstream/gpg2.git] / m4 / ksba.m4
1 # ksba.m4 - autoconf macro to detect ksba
2 #       Copyright (C) 2002, 2018 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: 2020-11-18
13
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.
23 dnl
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="")
33
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="")
39
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
43     fi
44   fi
45
46   use_gpgrt_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])
51       use_gpgrt_config=yes
52     fi
53   fi
54   if test -z "$use_gpgrt_config"; then
55     AC_PATH_PROG(KSBA_CONFIG, ksba-config, no)
56   fi
57
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/'`
62   else
63      req_ksba_api=0
64      min_ksba_version="$tmp"
65   fi
66
67   AC_MSG_CHECKING(for KSBA - version >= $min_ksba_version)
68   ok=no
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`
78     else
79       ksba_config_version=`$KSBA_CONFIG --modversion`
80     fi
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
88         ok=yes
89     else
90         if test "$major" -eq "$req_major"; then
91             if test "$minor" -gt "$req_minor"; then
92                ok=yes
93             else
94                if test "$minor" -eq "$req_minor"; then
95                    if test "$micro" -ge "$req_micro"; then
96                      ok=yes
97                    fi
98                fi
99             fi
100         fi
101     fi
102   fi
103   if test $ok = yes; then
104     AC_MSG_RESULT([yes ($ksba_config_version)])
105   else
106     AC_MSG_RESULT(no)
107   fi
108   if test $ok = yes; then
109      # Even if we have a recent libksba, we should check that the
110      # API is compatible.
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`
114         else
115           tmp=`$KSBA_CONFIG --variable=api_version 2>/dev/null || echo 0`
116         fi
117         if test "$tmp" -gt 0 ; then
118            AC_MSG_CHECKING([KSBA API version])
119            if test "$req_ksba_api" -eq "$tmp" ; then
120              AC_MSG_RESULT(okay)
121            else
122              ok=no
123              AC_MSG_RESULT([does not match.  want=$req_ksba_api got=$tmp.])
124            fi
125         fi
126      fi
127   fi
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`
134     else
135       libksba_config_host=`$KSBA_CONFIG --variable=host 2>/dev/null || echo none`
136     fi
137     if test x"$libksba_config_host" != xnone ; then
138       if test x"$libksba_config_host" != x"$host" ; then
139   AC_MSG_WARN([[
140 ***
141 *** The config script "$KSBA_CONFIG" was
142 *** built for $libksba_config_host and thus may not match the
143 *** used host $host.
144 *** You may want to use the configure option --with-libksba-prefix
145 *** to specify a matching config script.
146 ***]])
147       fi
148     fi
149   else
150     KSBA_CFLAGS=""
151     KSBA_LIBS=""
152     ifelse([$3], , :, [$3])
153   fi
154   AC_SUBST(KSBA_CFLAGS)
155   AC_SUBST(KSBA_LIBS)
156 ])