2009-07-03 [paul] 3.7.1cvs85
[claws.git] / m4 / gpgme.m4
blob10ee13f9473a5a7dd8ad644cbc12ac4d4e729c43
1 # gpgme.m4 - autoconf macro to detect GPGME.
2 # Copyright (C) 2002, 2003, 2004 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 AC_DEFUN([_AM_PATH_GPGME_CONFIG],
14 [ AC_ARG_WITH(gpgme-prefix,
15             AC_HELP_STRING([--with-gpgme-prefix=PFX],
16                            [prefix where GPGME is installed (optional)]),
17      gpgme_config_prefix="$withval", gpgme_config_prefix="")
18   if test "x$gpgme_config_prefix" != x ; then
19       GPGME_CONFIG="$gpgme_config_prefix/bin/gpgme-config"
20   fi
21   AC_PATH_PROG(GPGME_CONFIG, gpgme-config, no)
23   if test "$GPGME_CONFIG" != "no" ; then
24     gpgme_version=`$GPGME_CONFIG --version`
25   fi
26   gpgme_version_major=`echo $gpgme_version | \
27                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
28   gpgme_version_minor=`echo $gpgme_version | \
29                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
30   gpgme_version_micro=`echo $gpgme_version | \
31                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
34 dnl AM_PATH_GPGME([MINIMUM-VERSION,
35 dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
36 dnl Test for libgpgme and define GPGME_CFLAGS and GPGME_LIBS.
37 dnl
38 AC_DEFUN([AM_PATH_GPGME],
39 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
40   tmp=ifelse([$1], ,1:0.4.2,$1)
41   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
42      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
43      min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
44   else
45      req_gpgme_api=0
46      min_gpgme_version="$tmp"
47   fi
49   AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
50   ok=no
51   if test "$GPGME_CONFIG" != "no" ; then
52     req_major=`echo $min_gpgme_version | \
53                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
54     req_minor=`echo $min_gpgme_version | \
55                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
56     req_micro=`echo $min_gpgme_version | \
57                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
58     if test "$gpgme_version_major" -gt "$req_major"; then
59         ok=yes
60     else 
61         if test "$gpgme_version_major" -eq "$req_major"; then
62             if test "$gpgme_version_minor" -gt "$req_minor"; then
63                ok=yes
64             else
65                if test "$gpgme_version_minor" -eq "$req_minor"; then
66                    if test "$gpgme_version_micro" -ge "$req_micro"; then
67                      ok=yes
68                    fi
69                fi
70             fi
71         fi
72     fi
73   fi
74   if test $ok = yes; then
75      # If we have a recent GPGME, we should also check that the
76      # API is compatible.
77      if test "$req_gpgme_api" -gt 0 ; then
78         tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
79         if test "$tmp" -gt 0 ; then
80            if test "$req_gpgme_api" -ne "$tmp" ; then
81              ok=no
82            fi
83         fi
84      fi
85   fi
86   if test $ok = yes; then
87     GPGME_CFLAGS=`$GPGME_CONFIG --cflags`
88     GPGME_LIBS=`$GPGME_CONFIG --libs`
89     AC_MSG_RESULT(yes)
90     ifelse([$2], , :, [$2])
91   else
92     GPGME_CFLAGS=""
93     GPGME_LIBS=""
94     AC_MSG_RESULT(no)
95     ifelse([$3], , :, [$3])
96   fi
97   AC_SUBST(GPGME_CFLAGS)
98   AC_SUBST(GPGME_LIBS)
101 dnl AM_PATH_GPGME_PTH([MINIMUM-VERSION,
102 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
103 dnl Test for libgpgme and define GPGME_PTH_CFLAGS and GPGME_PTH_LIBS.
105 AC_DEFUN([AM_PATH_GPGME_PTH],
106 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
107   tmp=ifelse([$1], ,1:0.4.2,$1)
108   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
109      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
110      min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
111   else
112      req_gpgme_api=0
113      min_gpgme_version="$tmp"
114   fi
116   AC_MSG_CHECKING(for GPGME Pth - version >= $min_gpgme_version)
117   ok=no
118   if test "$GPGME_CONFIG" != "no" ; then
119     if `$GPGME_CONFIG --thread=pth 2> /dev/null` ; then
120       req_major=`echo $min_gpgme_version | \
121                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
122       req_minor=`echo $min_gpgme_version | \
123                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
124       req_micro=`echo $min_gpgme_version | \
125                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
126       if test "$gpgme_version_major" -gt "$req_major"; then
127         ok=yes
128       else 
129         if test "$gpgme_version_major" -eq "$req_major"; then
130           if test "$gpgme_version_minor" -gt "$req_minor"; then
131             ok=yes
132           else
133             if test "$gpgme_version_minor" -eq "$req_minor"; then
134               if test "$gpgme_version_micro" -ge "$req_micro"; then
135                 ok=yes
136               fi
137             fi
138           fi
139         fi
140       fi
141     fi
142   fi
143   if test $ok = yes; then
144      # If we have a recent GPGME, we should also check that the
145      # API is compatible.
146      if test "$req_gpgme_api" -gt 0 ; then
147         tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
148         if test "$tmp" -gt 0 ; then
149            if test "$req_gpgme_api" -ne "$tmp" ; then
150              ok=no
151            fi
152         fi
153      fi
154   fi
155   if test $ok = yes; then
156     GPGME_PTH_CFLAGS=`$GPGME_CONFIG --thread=pth --cflags`
157     GPGME_PTH_LIBS=`$GPGME_CONFIG --thread=pth --libs`
158     AC_MSG_RESULT(yes)
159     ifelse([$2], , :, [$2])
160   else
161     GPGME_PTH_CFLAGS=""
162     GPGME_PTH_LIBS=""
163     AC_MSG_RESULT(no)
164     ifelse([$3], , :, [$3])
165   fi
166   AC_SUBST(GPGME_PTH_CFLAGS)
167   AC_SUBST(GPGME_PTH_LIBS)
170 dnl AM_PATH_GPGME_PTHREAD([MINIMUM-VERSION,
171 dnl                       [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
172 dnl Test for libgpgme and define GPGME_PTHREAD_CFLAGS
173 dnl  and GPGME_PTHREAD_LIBS.
175 AC_DEFUN([AM_PATH_GPGME_PTHREAD],
176 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
177   tmp=ifelse([$1], ,1:0.4.2,$1)
178   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
179      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
180      min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
181   else
182      req_gpgme_api=0
183      min_gpgme_version="$tmp"
184   fi
186   AC_MSG_CHECKING(for GPGME pthread - version >= $min_gpgme_version)
187   ok=no
188   if test "$GPGME_CONFIG" != "no" ; then
189     if `$GPGME_CONFIG --thread=pthread 2> /dev/null` ; then
190       req_major=`echo $min_gpgme_version | \
191                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
192       req_minor=`echo $min_gpgme_version | \
193                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
194       req_micro=`echo $min_gpgme_version | \
195                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
196       if test "$gpgme_version_major" -gt "$req_major"; then
197         ok=yes
198       else 
199         if test "$gpgme_version_major" -eq "$req_major"; then
200           if test "$gpgme_version_minor" -gt "$req_minor"; then
201             ok=yes
202           else
203             if test "$gpgme_version_minor" -eq "$req_minor"; then
204               if test "$gpgme_version_micro" -ge "$req_micro"; then
205                 ok=yes
206               fi
207             fi
208           fi
209         fi
210       fi
211     fi
212   fi
213   if test $ok = yes; then
214      # If we have a recent GPGME, we should also check that the
215      # API is compatible.
216      if test "$req_gpgme_api" -gt 0 ; then
217         tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
218         if test "$tmp" -gt 0 ; then
219            if test "$req_gpgme_api" -ne "$tmp" ; then
220              ok=no
221            fi
222         fi
223      fi
224   fi
225   if test $ok = yes; then
226     GPGME_PTHREAD_CFLAGS=`$GPGME_CONFIG --thread=pthread --cflags`
227     GPGME_PTHREAD_LIBS=`$GPGME_CONFIG --thread=pthread --libs`
228     AC_MSG_RESULT(yes)
229     ifelse([$2], , :, [$2])
230   else
231     GPGME_PTHREAD_CFLAGS=""
232     GPGME_PTHREAD_LIBS=""
233     AC_MSG_RESULT(no)
234     ifelse([$3], , :, [$3])
235   fi
236   AC_SUBST(GPGME_PTHREAD_CFLAGS)
237   AC_SUBST(GPGME_PTHREAD_LIBS)