(reset_notify): Release the application context and
[gnupg.git] / acinclude.m4
1 dnl macros to configure gnupg
2 dnl Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
3 dnl
4 dnl This file is part of GnuPG.
5 dnl
6 dnl GnuPG is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 2 of the License, or
9 dnl (at your option) any later version.
10 dnl 
11 dnl GnuPG is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl 
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program; if not, write to the Free Software
18 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
20 dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME)
21 dnl Check whether a typedef exists and create a #define $2 if it exists
22 dnl
23 AC_DEFUN(GNUPG_CHECK_TYPEDEF,
24   [ AC_MSG_CHECKING(for $1 typedef)
25     AC_CACHE_VAL(gnupg_cv_typedef_$1,
26     [AC_TRY_COMPILE([#define _GNU_SOURCE 1
27     #include <stdlib.h>
28     #include <sys/types.h>], [
29     #undef $1
30     int a = sizeof($1);
31     ], gnupg_cv_typedef_$1=yes, gnupg_cv_typedef_$1=no )])
32     AC_MSG_RESULT($gnupg_cv_typedef_$1)
33     if test "$gnupg_cv_typedef_$1" = yes; then
34         AC_DEFINE($2,1,[Defined if a `]$1[' is typedef'd])
35     fi
36   ])
37
38
39 dnl GNUPG_CHECK_GNUMAKE
40 dnl
41 AC_DEFUN(GNUPG_CHECK_GNUMAKE,
42   [ 
43     if ${MAKE-make} --version 2>/dev/null | grep '^GNU ' >/dev/null 2>&1; then
44         :
45     else
46         AC_MSG_WARN([[
47 ***
48 *** It seems that you are not using GNU make.  Some make tools have serious
49 *** flaws and you may not be able to build this software at all. Before you
50 *** complain, please try GNU make:  GNU make is easy to build and available
51 *** at all GNU archives.  It is always available from ftp.gnu.org:/gnu/make.
52 ***]])
53     fi
54   ])
55
56 dnl GNUPG_CHECK_FAQPROG
57 dnl
58 AC_DEFUN(GNUPG_CHECK_FAQPROG,
59   [ AC_MSG_CHECKING(for faqprog.pl)
60     if faqprog.pl -V 2>/dev/null | grep '^faqprog.pl ' >/dev/null 2>&1; then
61         working_faqprog=yes
62         FAQPROG="faqprog.pl"
63     else 
64         working_faqprog=no
65         FAQPROG=": "
66     fi
67     AC_MSG_RESULT($working_faqprog)
68     AC_SUBST(FAQPROG)
69     AM_CONDITIONAL(WORKING_FAQPROG, test "$working_faqprog" = "yes" )
70
71 dnl     if test $working_faqprog = no; then
72 dnl         AC_MSG_WARN([[
73 dnl ***
74 dnl *** It seems that the faqprog.pl program is not installed;
75 dnl *** however it is only needed if you want to change the FAQ.
76 dnl ***  (faqprog.pl should be available at:
77 dnl ***    ftp://ftp.gnupg.org/gcrypt/contrib/faqprog.pl )
78 dnl *** No need to worry about this warning.
79 dnl ***]])
80 dnl     fi
81    ])       
82
83 dnl GNUPG_CHECK_DOCBOOK_TO_TEXI
84 dnl
85 AC_DEFUN(GNUPG_CHECK_DOCBOOK_TO_TEXI,
86   [
87     AC_CHECK_PROG(DOCBOOK_TO_TEXI, docbook2texi, yes, no)
88     AC_MSG_CHECKING(for sgml to texi tools)
89     working_sgmltotexi=no
90     if test "$ac_cv_prog_DOCBOOK_TO_TEXI" = yes; then
91       if sgml2xml -v /dev/null 2>&1 | grep 'SP version' >/dev/null 2>&1 ; then
92             working_sgmltotexi=yes
93       fi
94     fi
95     AC_MSG_RESULT($working_sgmltotexi)
96     AM_CONDITIONAL(HAVE_DOCBOOK_TO_TEXI, test "$working_sgmltotexi" = "yes" )
97    ])       
98
99
100
101 dnl GNUPG_CHECK_ENDIAN
102 dnl define either LITTLE_ENDIAN_HOST or BIG_ENDIAN_HOST
103 dnl
104 define(GNUPG_CHECK_ENDIAN,
105   [
106     tmp_assumed_endian=big
107     if test "$cross_compiling" = yes; then
108       case "$host_cpu" in
109          i@<:@345678@:>@* )
110             tmp_assumed_endian=little
111             ;;
112          *)
113             ;;
114       esac
115       AC_MSG_WARN(cross compiling; assuming $tmp_assumed_endian endianess)
116     fi
117     AC_MSG_CHECKING(endianess)
118     AC_CACHE_VAL(gnupg_cv_c_endian,
119       [ gnupg_cv_c_endian=unknown
120         # See if sys/param.h defines the BYTE_ORDER macro.
121         AC_TRY_COMPILE([#include <sys/types.h>
122         #include <sys/param.h>], [
123         #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
124          bogus endian macros
125         #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
126         AC_TRY_COMPILE([#include <sys/types.h>
127         #include <sys/param.h>], [
128         #if BYTE_ORDER != BIG_ENDIAN
129          not big endian
130         #endif], gnupg_cv_c_endian=big, gnupg_cv_c_endian=little)])
131         if test "$gnupg_cv_c_endian" = unknown; then
132             AC_TRY_RUN([main () {
133               /* Are we little or big endian?  From Harbison&Steele.  */
134               union
135               {
136                 long l;
137                 char c[sizeof (long)];
138               } u;
139               u.l = 1;
140               exit (u.c[sizeof (long) - 1] == 1);
141               }],
142               gnupg_cv_c_endian=little,
143               gnupg_cv_c_endian=big,
144               gnupg_cv_c_endian=$tmp_assumed_endian
145             )
146         fi
147       ])
148     AC_MSG_RESULT([$gnupg_cv_c_endian])
149     if test "$gnupg_cv_c_endian" = little; then
150       AC_DEFINE(LITTLE_ENDIAN_HOST,1,
151                 [Defined if the host has little endian byte ordering])
152     else
153       AC_DEFINE(BIG_ENDIAN_HOST,1,
154                 [Defined if the host has big endian byte ordering])
155     fi
156   ])
157
158
159
160 # Check for the getsockopt SO_PEERCRED
161 AC_DEFUN(GNUPG_SYS_SO_PEERCRED,
162   [ AC_MSG_CHECKING(for SO_PEERCRED)
163     AC_CACHE_VAL(gnupg_cv_sys_so_peercred,
164       [AC_TRY_COMPILE([#include <sys/socket.h>], 
165                     [struct ucred cr; 
166                      int cl = sizeof cr;
167                      getsockopt (1, SOL_SOCKET, SO_PEERCRED, &cr, &cl);],
168                     gnupg_cv_sys_so_peercred=yes,
169                     gnupg_cv_sys_so_peercred=no)
170       ])
171     AC_MSG_RESULT($gnupg_cv_sys_so_peercred) 
172     if test $gnupg_cv_sys_so_peercred = yes; then
173          AC_DEFINE(HAVE_SO_PEERCRED, 1,
174                             [Defined if SO_PEERCRED is supported (Linux)])
175     fi
176   ])
177
178
179
180 # GNUPG_BUILD_PROGRAM(NAME,DEFAULT)
181 # Add a --enable-NAME option to configure an set the
182 # shell variable build_NAME either to "yes" or "no".  DEFAULT must
183 # either be "yes" or "no" and decided on the default value for
184 # build_NAME and whether --enable-NAME or --disable-NAME is shown with 
185 # ./configure --help
186 AC_DEFUN(GNUPG_BUILD_PROGRAM,
187   [build_$1=$2
188    m4_if([$2],[yes],[
189       AC_ARG_ENABLE([$1], AC_HELP_STRING([--disable-$1],
190                                          [do not build the $1 program]),
191                            build_$1=$enableval, build_$1=$2)
192     ],[
193       AC_ARG_ENABLE([$1], AC_HELP_STRING([--enable-$1],
194                                          [build the $1 program]),
195                            build_$1=$enableval, build_$1=$2)
196     ])
197    case "$build_$1" in
198          no|yes)
199            ;;
200          *) 
201            AC_MSG_ERROR([only yes or no allowed for feature --enable-$1])
202            ;;
203    esac
204   ])
205
206
207
208 # GNUPG_PTH_VERSION_CHECK(REQUIRED)
209
210 # If the version is sufficient, HAVE_PTH will be set to yes.
211 #
212 # Taken form the m4 macros which come with Pth
213 AC_DEFUN(GNUPG_PTH_VERSION_CHECK,
214   [
215     _pth_version=`$PTH_CONFIG --version | awk 'NR==1 {print [$]3}'`
216     _req_version="ifelse([$1],,1.2.0,$1)"
217     for _var in _pth_version _req_version; do
218         eval "_val=\"\$${_var}\""
219         _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
220         _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
221         _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
222         _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
223         case $_rtype in
224             "a" ) _rtype=0 ;;
225             "b" ) _rtype=1 ;;
226             "." ) _rtype=2 ;;
227         esac
228         _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
229               "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
230         eval "${_var}_hex=\"\$_hex\""
231     done
232     have_pth=no
233     if test ".$_pth_version_hex" != .; then
234         if test ".$_req_version_hex" != .; then
235             if test $_pth_version_hex -ge $_req_version_hex; then
236                 have_pth=yes
237             fi
238         fi
239     fi
240     if test $have_pth = no; then
241        AC_MSG_WARN([[
242 ***
243 *** Found Pth version $_pth_version, but require at least
244 *** version $_req_version.  Please upgrade Pth first.
245 ***]])
246     fi    
247   ])
248
249
250 # Check whether mlock is broken (hpux 10.20 raises a SIGBUS if mlock
251 # is not called from uid 0 (not tested whether uid 0 works)
252 # For DECs Tru64 we have also to check whether mlock is in librt
253 # mlock is there a macro using memlk()
254 dnl GNUPG_CHECK_MLOCK
255 dnl
256 define(GNUPG_CHECK_MLOCK,
257   [ AC_CHECK_FUNCS(mlock)
258     if test "$ac_cv_func_mlock" = "no"; then
259         AC_CHECK_HEADERS(sys/mman.h)
260         if test "$ac_cv_header_sys_mman_h" = "yes"; then
261             # Add librt to LIBS:
262             AC_CHECK_LIB(rt, memlk)
263             AC_CACHE_CHECK([whether mlock is in sys/mman.h],
264                             gnupg_cv_mlock_is_in_sys_mman,
265                 [AC_TRY_LINK([
266                     #include <assert.h>
267                     #ifdef HAVE_SYS_MMAN_H
268                     #include <sys/mman.h>
269                     #endif
270                 ], [
271                     int i;
272
273                     /* glibc defines this for functions which it implements
274                      * to always fail with ENOSYS.  Some functions are actually
275                      * named something starting with __ and the normal name
276                      * is an alias.  */
277                     #if defined (__stub_mlock) || defined (__stub___mlock)
278                     choke me
279                     #else
280                     mlock(&i, 4);
281                     #endif
282                     ; return 0;
283                 ],
284                 gnupg_cv_mlock_is_in_sys_mman=yes,
285                 gnupg_cv_mlock_is_in_sys_mman=no)])
286             if test "$gnupg_cv_mlock_is_in_sys_mman" = "yes"; then
287                 AC_DEFINE(HAVE_MLOCK,1,
288                           [Defined if the system supports an mlock() call])
289             fi
290         fi
291     fi
292     if test "$ac_cv_func_mlock" = "yes"; then
293         AC_MSG_CHECKING(whether mlock is broken)
294           AC_CACHE_VAL(gnupg_cv_have_broken_mlock,
295              AC_TRY_RUN([
296                 #include <stdlib.h>
297                 #include <unistd.h>
298                 #include <errno.h>
299                 #include <sys/mman.h>
300                 #include <sys/types.h>
301                 #include <fcntl.h>
302
303                 int main()
304                 {
305                     char *pool;
306                     int err;
307                     long int pgsize = getpagesize();
308
309                     pool = malloc( 4096 + pgsize );
310                     if( !pool )
311                         return 2;
312                     pool += (pgsize - ((long int)pool % pgsize));
313
314                     err = mlock( pool, 4096 );
315                     if( !err || errno == EPERM )
316                         return 0; /* okay */
317
318                     return 1;  /* hmmm */
319                 }
320
321             ],
322             gnupg_cv_have_broken_mlock="no",
323             gnupg_cv_have_broken_mlock="yes",
324             gnupg_cv_have_broken_mlock="assume-no"
325            )
326          )
327          if test "$gnupg_cv_have_broken_mlock" = "yes"; then
328              AC_DEFINE(HAVE_BROKEN_MLOCK,1,
329                        [Defined if the mlock() call does not work])
330              AC_MSG_RESULT(yes)
331              AC_CHECK_FUNCS(plock)
332          else
333             if test "$gnupg_cv_have_broken_mlock" = "no"; then
334                 AC_MSG_RESULT(no)
335             else
336                 AC_MSG_RESULT(assuming no)
337             fi
338          fi
339     fi
340   ])
341
342
343 dnl Stolen from gcc
344 dnl Define MKDIR_TAKES_ONE_ARG if mkdir accepts only one argument instead
345 dnl of the usual 2.
346 AC_DEFUN(GNUPG_FUNC_MKDIR_TAKES_ONE_ARG,
347 [AC_CHECK_HEADERS(sys/stat.h unistd.h direct.h)
348 AC_CACHE_CHECK([if mkdir takes one argument], gnupg_cv_mkdir_takes_one_arg,
349 [AC_TRY_COMPILE([
350 #include <sys/types.h>
351 #ifdef HAVE_SYS_STAT_H
352 # include <sys/stat.h>
353 #endif
354 #ifdef HAVE_UNISTD_H
355 # include <unistd.h>
356 #endif
357 #ifdef HAVE_DIRECT_H
358 # include <direct.h>
359 #endif], [mkdir ("foo", 0);],
360         gnupg_cv_mkdir_takes_one_arg=no, gnupg_cv_mkdir_takes_one_arg=yes)])
361 if test $gnupg_cv_mkdir_takes_one_arg = yes ; then
362   AC_DEFINE(MKDIR_TAKES_ONE_ARG,1,
363             [Defined if mkdir() does not take permission flags])
364 fi
365 ])
366
367
368
369
370 dnl [copied from libgcrypt]
371 dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,
372 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
373 dnl Test for liblibgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS
374 dnl
375 AC_DEFUN(AM_PATH_LIBGCRYPT,
376 [ AC_ARG_WITH(libgcrypt-prefix,
377             AC_HELP_STRING([--with-libgcrypt-prefix=PFX],
378                            [prefix where LIBGCRYPT is installed (optional)]),
379      libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
380   if test x$libgcrypt_config_prefix != x ; then
381      libgcrypt_config_args="$libgcrypt_config_args --prefix=$libgcrypt_config_prefix"
382      if test x${LIBGCRYPT_CONFIG+set} != xset ; then
383         LIBGCRYPT_CONFIG=$libgcrypt_config_prefix/bin/libgcrypt-config
384      fi
385   fi
386
387   AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
388   min_libgcrypt_version=ifelse([$1], ,0.4.4,$1)
389   AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
390   ok=no
391   if test "$LIBGCRYPT_CONFIG" != "no" ; then
392     req_major=`echo $min_libgcrypt_version | \
393                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
394     req_minor=`echo $min_libgcrypt_version | \
395                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
396     req_micro=`echo $min_libgcrypt_version | \
397                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
398     libgcrypt_config_version=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --version`
399     major=`echo $libgcrypt_config_version | \
400                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
401     minor=`echo $libgcrypt_config_version | \
402                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
403     micro=`echo $libgcrypt_config_version | \
404                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
405     if test "$major" -gt "$req_major"; then
406         ok=yes
407     else 
408         if test "$major" -eq "$req_major"; then
409             if test "$minor" -gt "$req_minor"; then
410                ok=yes
411             else
412                if test "$minor" -eq "$req_minor"; then
413                    if test "$micro" -ge "$req_micro"; then
414                      ok=yes
415                    fi
416                fi
417             fi
418         fi
419     fi
420   fi
421   if test $ok = yes; then
422     LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --cflags`
423     LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --libs`
424     AC_MSG_RESULT(yes)
425     ifelse([$2], , :, [$2])
426   else
427     LIBGCRYPT_CFLAGS=""
428     LIBGCRYPT_LIBS=""
429     AC_MSG_RESULT(no)
430     ifelse([$3], , :, [$3])
431   fi
432   AC_SUBST(LIBGCRYPT_CFLAGS)
433   AC_SUBST(LIBGCRYPT_LIBS)
434 ])
435
436 dnl [copied from libassuan 0.0.1]
437 dnl AM_PATH_LIBASSUAN([MINIMUM-VERSION,
438 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
439 dnl Test for libassuan and define LIBASSUAN_CFLAGS and LIBASSUAN_LIBS
440 dnl
441 AC_DEFUN(AM_PATH_LIBASSUAN,
442 [ AC_ARG_WITH(libassuan-prefix,
443             AC_HELP_STRING([--with-libassuan-prefix=PFX],
444                            [prefix where LIBASSUAN is installed (optional)]),
445      libassuan_config_prefix="$withval", libassuan_config_prefix="")
446   if test x$libassuan_config_prefix != x ; then
447      libassuan_config_args="$libassuan_config_args --prefix=$libassuan_config_prefix"
448      if test x${LIBASSUAN_CONFIG+set} != xset ; then
449         LIBASSUAN_CONFIG=$libassuan_config_prefix/bin/libassuan-config
450      fi
451   fi
452
453   AC_PATH_PROG(LIBASSUAN_CONFIG, libassuan-config, no)
454   min_libassuan_version=ifelse([$1], ,0.0.1,$1)
455   AC_MSG_CHECKING(for LIBASSUAN - version >= $min_libassuan_version)
456   ok=no
457   if test "$LIBASSUAN_CONFIG" != "no" ; then
458     req_major=`echo $min_libassuan_version | \
459                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
460     req_minor=`echo $min_libassuan_version | \
461                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
462     req_micro=`echo $min_libassuan_version | \
463                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
464     libassuan_config_version=`$LIBASSUAN_CONFIG $libassuan_config_args --version`
465     major=`echo $libassuan_config_version | \
466                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
467     minor=`echo $libassuan_config_version | \
468                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
469     micro=`echo $libassuan_config_version | \
470                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
471     if test "$major" -gt "$req_major"; then
472         ok=yes
473     else 
474         if test "$major" -eq "$req_major"; then
475             if test "$minor" -gt "$req_minor"; then
476                ok=yes
477             else
478                if test "$minor" -eq "$req_minor"; then
479                    if test "$micro" -ge "$req_micro"; then
480                      ok=yes
481                    fi
482                fi
483             fi
484         fi
485     fi
486   fi
487   if test $ok = yes; then
488     LIBASSUAN_CFLAGS=`$LIBASSUAN_CONFIG $libassuan_config_args --cflags`
489     LIBASSUAN_LIBS=`$LIBASSUAN_CONFIG $libassuan_config_args --libs`
490     AC_MSG_RESULT(yes)
491     ifelse([$2], , :, [$2])
492   else
493     LIBASSUAN_CFLAGS=""
494     LIBASSUAN_LIBS=""
495     AC_MSG_RESULT(no)
496     ifelse([$3], , :, [$3])
497   fi
498   AC_SUBST(LIBASSUAN_CFLAGS)
499   AC_SUBST(LIBASSUAN_LIBS)
500 ])
501
502
503
504 dnl [Copied from libksba]
505 dnl AM_PATH_KSBA([MINIMUM-VERSION,
506 dnl              [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
507 dnl Test for libksba and define KSBA_CFLAGS and KSBA_LIBS
508 dnl
509 AC_DEFUN(AM_PATH_KSBA,
510 [ AC_ARG_WITH(ksba-prefix,
511             AC_HELP_STRING([--with-ksba-prefix=PFX],
512                            [prefix where KSBA is installed (optional)]),
513      ksba_config_prefix="$withval", ksba_config_prefix="")
514   if test x$ksba_config_prefix != x ; then
515      ksba_config_args="$ksba_config_args --prefix=$ksba_config_prefix"
516      if test x${KSBA_CONFIG+set} != xset ; then
517         KSBA_CONFIG=$ksba_config_prefix/bin/ksba-config
518      fi
519   fi
520
521   AC_PATH_PROG(KSBA_CONFIG, ksba-config, no)
522   min_ksba_version=ifelse([$1], ,0.4.4,$1)
523   AC_MSG_CHECKING(for KSBA - version >= $min_ksba_version)
524   ok=no
525   if test "$KSBA_CONFIG" != "no" ; then
526     req_major=`echo $min_ksba_version | \
527                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
528     req_minor=`echo $min_ksba_version | \
529                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
530     req_micro=`echo $min_ksba_version | \
531                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
532     ksba_config_version=`$KSBA_CONFIG $ksba_config_args --version`
533     major=`echo $ksba_config_version | \
534                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
535     minor=`echo $ksba_config_version | \
536                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
537     micro=`echo $ksba_config_version | \
538                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
539     if test "$major" -gt "$req_major"; then
540         ok=yes
541     else 
542         if test "$major" -eq "$req_major"; then
543             if test "$minor" -gt "$req_minor"; then
544                ok=yes
545             else
546                if test "$minor" -eq "$req_minor"; then
547                    if test "$micro" -ge "$req_micro"; then
548                      ok=yes
549                    fi
550                fi
551             fi
552         fi
553     fi
554   fi
555   if test $ok = yes; then
556     KSBA_CFLAGS=`$KSBA_CONFIG $ksba_config_args --cflags`
557     KSBA_LIBS=`$KSBA_CONFIG $ksba_config_args --libs`
558     AC_MSG_RESULT(yes)
559     ifelse([$2], , :, [$2])
560   else
561     KSBA_CFLAGS=""
562     KSBA_LIBS=""
563     AC_MSG_RESULT(no)
564     ifelse([$3], , :, [$3])
565   fi
566   AC_SUBST(KSBA_CFLAGS)
567   AC_SUBST(KSBA_LIBS)
568 ])
569
570
571
572 dnl AM_PATH_OPENSC([MINIMUM-VERSION,
573 dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
574 dnl Test for OpenSC and define OPENSC_CFLAGS and OPENSC_LIBS
575 dnl
576 AC_DEFUN(AM_PATH_OPENSC,
577 [ AC_ARG_WITH(opensc-prefix,
578             AC_HELP_STRING([--with-opensc-prefix=PFX],
579                            [prefix where OpenSC is installed (optional)]),
580      opensc_config_prefix="$withval", opensc_config_prefix="")
581   if test x$opensc_config_prefix != x ; then
582      opensc_config_args="$opensc_config_args --prefix=$opensc_config_prefix"
583      if test x${OPENSC_CONFIG+set} != xset ; then
584         OPENSC_CONFIG=$opensc_config_prefix/bin/opensc-config
585      fi
586   fi
587
588   AC_PATH_PROG(OPENSC_CONFIG, opensc-config, no)
589   min_opensc_version=ifelse([$1], ,0.7.0,$1)
590   AC_MSG_CHECKING(for OpenSC - version >= $min_opensc_version)
591   ok=no
592   if test "$OPENSC_CONFIG" != "no" ; then
593     req_major=`echo $min_opensc_version | \
594                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
595     req_minor=`echo $min_opensc_version | \
596                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
597     req_micro=`echo $min_opensc_version | \
598                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
599     opensc_config_version=`$OPENSC_CONFIG $opensc_config_args --version`
600     major=`echo $opensc_config_version | \
601                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
602     minor=`echo $opensc_config_version | \
603                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
604     micro=`echo $opensc_config_version | \
605                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
606     if test "$major" -gt "$req_major"; then
607         ok=yes
608     else 
609         if test "$major" -eq "$req_major"; then
610             if test "$minor" -gt "$req_minor"; then
611                ok=yes
612             else
613                if test "$minor" -eq "$req_minor"; then
614                    if test "$micro" -ge "$req_micro"; then
615                      ok=yes
616                    fi
617                fi
618             fi
619         fi
620     fi
621   fi
622   if test $ok = yes; then
623     OPENSC_CFLAGS=`$OPENSC_CONFIG $opensc_config_args --cflags`
624     OPENSC_LIBS=`$OPENSC_CONFIG $opensc_config_args --libs`
625     OPENSC_LIBS="$OPENSC_LIBS -lpcsclite -lpthread"
626     AC_MSG_RESULT(yes)
627     ifelse([$2], , :, [$2])
628   else
629     OPENSC_CFLAGS=""
630     OPENSC_LIBS=""
631     AC_MSG_RESULT(no)
632     ifelse([$3], , :, [$3])
633   fi
634   AC_SUBST(OPENSC_CFLAGS)
635   AC_SUBST(OPENSC_LIBS)
636 ])
637
638
639 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
640 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
641 dnl Test for libgpg-error and define GPG_ERROR_CFLAGS and GPG_ERROR_LIBS
642 dnl
643 AC_DEFUN(AM_PATH_GPG_ERROR,
644 [ AC_ARG_WITH(gpg-error-prefix,
645             AC_HELP_STRING([--with-gpg-error-prefix=PFX],
646                            [prefix where GPG Error is installed (optional)]),
647      gpg_error_config_prefix="$withval", gpg_error_config_prefix="")
648   if test x$gpg_error_config_prefix != x ; then
649      gpg_error_config_args="$gpg_error_config_args --prefix=$gpg_error_config_prefix"
650      if test x${GPG_ERROR_CONFIG+set} != xset ; then
651         GPG_ERROR_CONFIG=$gpg_error_config_prefix/bin/gpg-error-config
652      fi
653   fi
654
655   AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no)
656   min_gpg_error_version=ifelse([$1], ,0.0,$1)
657   AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
658   ok=no
659   if test "$GPG_ERROR_CONFIG" != "no" ; then
660     req_major=`echo $min_gpg_error_version | \
661                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
662     req_minor=`echo $min_gpg_error_version | \
663                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
664     gpg_error_config_version=`$GPG_ERROR_CONFIG $gpg_error_config_args --version`
665     major=`echo $gpg_error_config_version | \
666                sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
667     minor=`echo $gpg_error_config_version | \
668                sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
669     if test "$major" -gt "$req_major"; then
670         ok=yes
671     else 
672         if test "$major" -eq "$req_major"; then
673             if test "$minor" -ge "$req_minor"; then
674                ok=yes
675             fi
676         fi
677     fi
678   fi
679   if test $ok = yes; then
680     GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG $gpg_error_config_args --cflags`
681     GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG $gpg_error_config_args --libs`
682     AC_MSG_RESULT(yes)
683     ifelse([$2], , :, [$2])
684   else
685     GPG_ERROR_CFLAGS=""
686     GPG_ERROR_LIBS=""
687     AC_MSG_RESULT(no)
688     ifelse([$3], , :, [$3])
689   fi
690   AC_SUBST(GPG_ERROR_CFLAGS)
691   AC_SUBST(GPG_ERROR_LIBS)
692 ])
693
694