Add ftp and git URLs to AUTHORS.
[gpgme.git] / src / gpgme.m4
1 # gpgme.m4 - autoconf macro to detect GPGME.
2 # Copyright (C) 2002, 2003, 2004 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
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)
22
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/'`
32 ])
33
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
48
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)
99 ])
100
101 dnl AM_PATH_GPGME_PTHREAD([MINIMUM-VERSION,
102 dnl                       [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
103 dnl Test for libgpgme and define GPGME_PTHREAD_CFLAGS
104 dnl  and GPGME_PTHREAD_LIBS.
105 dnl
106 AC_DEFUN([AM_PATH_GPGME_PTHREAD],
107 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
108   tmp=ifelse([$1], ,1:0.4.2,$1)
109   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
110      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
111      min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
112   else
113      req_gpgme_api=0
114      min_gpgme_version="$tmp"
115   fi
116
117   AC_MSG_CHECKING(for GPGME pthread - version >= $min_gpgme_version)
118   ok=no
119   if test "$GPGME_CONFIG" != "no" ; then
120     if `$GPGME_CONFIG --thread=pthread 2> /dev/null` ; then
121       req_major=`echo $min_gpgme_version | \
122                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
123       req_minor=`echo $min_gpgme_version | \
124                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
125       req_micro=`echo $min_gpgme_version | \
126                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
127       if test "$gpgme_version_major" -gt "$req_major"; then
128         ok=yes
129       else 
130         if test "$gpgme_version_major" -eq "$req_major"; then
131           if test "$gpgme_version_minor" -gt "$req_minor"; then
132             ok=yes
133           else
134             if test "$gpgme_version_minor" -eq "$req_minor"; then
135               if test "$gpgme_version_micro" -ge "$req_micro"; then
136                 ok=yes
137               fi
138             fi
139           fi
140         fi
141       fi
142     fi
143   fi
144   if test $ok = yes; then
145      # If we have a recent GPGME, we should also check that the
146      # API is compatible.
147      if test "$req_gpgme_api" -gt 0 ; then
148         tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
149         if test "$tmp" -gt 0 ; then
150            if test "$req_gpgme_api" -ne "$tmp" ; then
151              ok=no
152            fi
153         fi
154      fi
155   fi
156   if test $ok = yes; then
157     GPGME_PTHREAD_CFLAGS=`$GPGME_CONFIG --thread=pthread --cflags`
158     GPGME_PTHREAD_LIBS=`$GPGME_CONFIG --thread=pthread --libs`
159     AC_MSG_RESULT(yes)
160     ifelse([$2], , :, [$2])
161   else
162     GPGME_PTHREAD_CFLAGS=""
163     GPGME_PTHREAD_LIBS=""
164     AC_MSG_RESULT(no)
165     ifelse([$3], , :, [$3])
166   fi
167   AC_SUBST(GPGME_PTHREAD_CFLAGS)
168   AC_SUBST(GPGME_PTHREAD_LIBS)
169 ])
170
171
172 dnl AM_PATH_GPGME_GLIB([MINIMUM-VERSION,
173 dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
174 dnl Test for libgpgme-glib and define GPGME_GLIB_CFLAGS and GPGME_GLIB_LIBS.
175 dnl
176 AC_DEFUN([AM_PATH_GPGME_GLIB],
177 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
178   tmp=ifelse([$1], ,1:0.4.2,$1)
179   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
180      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
181      min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
182   else
183      req_gpgme_api=0
184      min_gpgme_version="$tmp"
185   fi
186
187   AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
188   ok=no
189   if test "$GPGME_CONFIG" != "no" ; 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   if test $ok = yes; then
213      # If we have a recent GPGME, we should also check that the
214      # API is compatible.
215      if test "$req_gpgme_api" -gt 0 ; then
216         tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
217         if test "$tmp" -gt 0 ; then
218            if test "$req_gpgme_api" -ne "$tmp" ; then
219              ok=no
220            fi
221         fi
222      fi
223   fi
224   if test $ok = yes; then
225     GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --glib --cflags`
226     GPGME_GLIB_LIBS=`$GPGME_CONFIG --glib --libs`
227     AC_MSG_RESULT(yes)
228     ifelse([$2], , :, [$2])
229   else
230     GPGME_GLIB_CFLAGS=""
231     GPGME_GLIB_LIBS=""
232     AC_MSG_RESULT(no)
233     ifelse([$3], , :, [$3])
234   fi
235   AC_SUBST(GPGME_GLIB_CFLAGS)
236   AC_SUBST(GPGME_GLIB_LIBS)
237 ])
238