chiark / gitweb /
gnupg2 (2.1.17-3) unstable; urgency=medium
[gnupg2.git] / m4 / gnupg-pth.m4
1 dnl GnuPG's check for Pth.
2 dnl       Copyright (C) 2003 Free Software Foundation, Inc.
3 dnl
4 dnl This file is free software; as a special exception the author gives
5 dnl unlimited permission to copy and/or distribute it, with or without
6 dnl modifications, as long as this notice is preserved.
7 dnl
8 dnl This file is distributed in the hope that it will be useful, but
9 dnl WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
10 dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
12
13 # GNUPG_PTH_VERSION_CHECK(REQUIRED)
14
15 # If the version is sufficient, HAVE_PTH will be set to yes.
16 #
17 # Taken and modified from the m4 macros which come with Pth.
18 AC_DEFUN([GNUPG_PTH_VERSION_CHECK],
19   [
20     _pth_version=`$PTH_CONFIG --version | awk 'NR==1 {print [$]3}'`
21     _req_version="ifelse([$1],,1.2.0,$1)"
22
23     AC_MSG_CHECKING(for PTH - version >= $_req_version)
24     for _var in _pth_version _req_version; do
25         eval "_val=\"\$${_var}\""
26         _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
27         _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
28         _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
29         _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
30         case $_rtype in
31             "a" ) _rtype=0 ;;
32             "b" ) _rtype=1 ;;
33             "." ) _rtype=2 ;;
34         esac
35         _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
36               "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
37         eval "${_var}_hex=\"\$_hex\""
38     done
39     have_pth=no
40     if test ".$_pth_version_hex" != .; then
41         if test ".$_req_version_hex" != .; then
42             if test $_pth_version_hex -ge $_req_version_hex; then
43                 have_pth=yes
44             fi
45         fi
46     fi
47     if test $have_pth = yes; then
48        AC_MSG_RESULT(yes)
49        AC_MSG_CHECKING([whether PTH installation is sane])
50        AC_CACHE_VAL(gnupg_cv_pth_is_sane,[
51          _gnupg_pth_save_cflags=$CFLAGS
52          _gnupg_pth_save_ldflags=$LDFLAGS
53          _gnupg_pth_save_libs=$LIBS
54          CFLAGS="$CFLAGS `$PTH_CONFIG --cflags`"
55          LDFLAGS="$LDFLAGS `$PTH_CONFIG --ldflags`"
56          LIBS="$LIBS `$PTH_CONFIG --libs --all`"
57          AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pth.h>
58                                          ],
59                                          [[ pth_init ();]])],
60                         gnupg_cv_pth_is_sane=yes,
61                         gnupg_cv_pth_is_sane=no)
62          CFLAGS=$_gnupg_pth_save_cflags
63          LDFLAGS=$_gnupg_pth_save_ldflags
64          LIBS=$_gnupg_pth_save_libs
65        ])
66        if test $gnupg_cv_pth_is_sane != yes; then
67           have_pth=no
68        fi
69        AC_MSG_RESULT($gnupg_cv_pth_is_sane)
70     else
71        AC_MSG_RESULT(no)
72     fi    
73   ])
74
75
76
77 # GNUPG_PATH_PTH([MINIMUM_VERSION])
78 #
79 # On return $have_pth is set as well as HAVE_PTH is defined and
80 # PTH_CLFAGS and PTH_LIBS are AS_SUBST.
81 #
82 AC_DEFUN([GNUPG_PATH_PTH],
83 [ AC_ARG_WITH(pth-prefix,
84              AC_HELP_STRING([--with-pth-prefix=PFX],
85                            [prefix where GNU Pth is installed (optional)]),
86      pth_config_prefix="$withval", pth_config_prefix="")
87   if test x$pth_config_prefix != x ; then
88      PTH_CONFIG="$pth_config_prefix/bin/pth-config"
89   fi
90   AC_PATH_PROG(PTH_CONFIG, pth-config, no)
91   tmp=ifelse([$1], ,1.3.7,$1)
92   if test "$PTH_CONFIG" != "no"; then
93     GNUPG_PTH_VERSION_CHECK($tmp)
94     if test $have_pth = yes; then      
95        PTH_CFLAGS=`$PTH_CONFIG --cflags`
96        PTH_LIBS=`$PTH_CONFIG --ldflags`
97        PTH_LIBS="$PTH_LIBS `$PTH_CONFIG --libs --all`"
98        AC_DEFINE(HAVE_PTH, 1,
99                 [Defined if the GNU Pth is available])
100     fi
101   fi
102   AC_SUBST(PTH_CFLAGS)
103   AC_SUBST(PTH_LIBS)
104 ])
105