Cleanup INIT_SIGNAL.
[libpwmd.git] / m4 / gpgme.m4
blob6c2be44251e50974bd16e18f65037e63fac9e31a
1 # gpgme.m4 - autoconf macro to detect GPGME.
2 # Copyright (C) 2002, 2003, 2004, 2014 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.
12 # Last-changed: 2014-10-02
15 AC_DEFUN([_AM_PATH_GPGME_CONFIG],
16 [ AC_ARG_WITH(gpgme-prefix,
17             AC_HELP_STRING([--with-gpgme-prefix=PFX],
18                            [prefix where GPGME is installed (optional)]),
19      gpgme_config_prefix="$withval", gpgme_config_prefix="")
20   if test x"${GPGME_CONFIG}" = x ; then
21      if test x"${gpgme_config_prefix}" != x ; then
22         GPGME_CONFIG="${gpgme_config_prefix}/bin/gpgme-config"
23      else
24        case "${SYSROOT}" in
25          /*)
26            if test -x "${SYSROOT}/bin/gpgme-config" ; then
27              GPGME_CONFIG="${SYSROOT}/bin/gpgme-config"
28            fi
29            ;;
30          '')
31            ;;
32           *)
33            AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
34            ;;
35        esac
36      fi
37   fi
39   AC_PATH_PROG(GPGME_CONFIG, gpgme-config, no)
41   if test "$GPGME_CONFIG" != "no" ; then
42     gpgme_version=`$GPGME_CONFIG --version`
43   fi
44   gpgme_version_major=`echo $gpgme_version | \
45                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
46   gpgme_version_minor=`echo $gpgme_version | \
47                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
48   gpgme_version_micro=`echo $gpgme_version | \
49                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
53 AC_DEFUN([_AM_PATH_GPGME_CONFIG_HOST_CHECK],
55     gpgme_config_host=`$GPGME_CONFIG --host 2>/dev/null || echo none`
56     if test x"$gpgme_config_host" != xnone ; then
57       if test x"$gpgme_config_host" != x"$host" ; then
58   AC_MSG_WARN([[
59 ***
60 *** The config script $GPGME_CONFIG was
61 *** built for $gpgme_config_host and thus may not match the
62 *** used host $host.
63 *** You may want to use the configure option --with-gpgme-prefix
64 *** to specify a matching config script or use \$SYSROOT.
65 ***]])
66         gpg_config_script_warn="$gpg_config_script_warn gpgme"
67       fi
68     fi
72 dnl AM_PATH_GPGME([MINIMUM-VERSION,
73 dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
74 dnl Test for libgpgme and define GPGME_CFLAGS and GPGME_LIBS.
75 dnl
76 dnl If a prefix option is not used, the config script is first
77 dnl searched in $SYSROOT/bin and then along $PATH.  If the used
78 dnl config script does not match the host specification the script
79 dnl is added to the gpg_config_script_warn variable.
80 dnl
81 AC_DEFUN([AM_PATH_GPGME],
82 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
83   tmp=ifelse([$1], ,1:0.4.2,$1)
84   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
85      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
86      min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
87   else
88      req_gpgme_api=0
89      min_gpgme_version="$tmp"
90   fi
92   AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
93   ok=no
94   if test "$GPGME_CONFIG" != "no" ; then
95     req_major=`echo $min_gpgme_version | \
96                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
97     req_minor=`echo $min_gpgme_version | \
98                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
99     req_micro=`echo $min_gpgme_version | \
100                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
101     if test "$gpgme_version_major" -gt "$req_major"; then
102         ok=yes
103     else
104         if test "$gpgme_version_major" -eq "$req_major"; then
105             if test "$gpgme_version_minor" -gt "$req_minor"; then
106                ok=yes
107             else
108                if test "$gpgme_version_minor" -eq "$req_minor"; then
109                    if test "$gpgme_version_micro" -ge "$req_micro"; then
110                      ok=yes
111                    fi
112                fi
113             fi
114         fi
115     fi
116   fi
117   if test $ok = yes; then
118      # If we have a recent GPGME, we should also check that the
119      # API is compatible.
120      if test "$req_gpgme_api" -gt 0 ; then
121         tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
122         if test "$tmp" -gt 0 ; then
123            if test "$req_gpgme_api" -ne "$tmp" ; then
124              ok=no
125            fi
126         fi
127      fi
128   fi
129   if test $ok = yes; then
130     GPGME_CFLAGS=`$GPGME_CONFIG --cflags`
131     GPGME_LIBS=`$GPGME_CONFIG --libs`
132     AC_MSG_RESULT(yes)
133     ifelse([$2], , :, [$2])
134     _AM_PATH_GPGME_CONFIG_HOST_CHECK
135   else
136     GPGME_CFLAGS=""
137     GPGME_LIBS=""
138     AC_MSG_RESULT(no)
139     ifelse([$3], , :, [$3])
140   fi
141   AC_SUBST(GPGME_CFLAGS)
142   AC_SUBST(GPGME_LIBS)
145 dnl AM_PATH_GPGME_PTHREAD([MINIMUM-VERSION,
146 dnl                       [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
147 dnl Test for libgpgme and define GPGME_PTHREAD_CFLAGS
148 dnl  and GPGME_PTHREAD_LIBS.
150 AC_DEFUN([AM_PATH_GPGME_PTHREAD],
151 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
152   tmp=ifelse([$1], ,1:0.4.2,$1)
153   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
154      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
155      min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
156   else
157      req_gpgme_api=0
158      min_gpgme_version="$tmp"
159   fi
161   AC_MSG_CHECKING(for GPGME pthread - version >= $min_gpgme_version)
162   ok=no
163   if test "$GPGME_CONFIG" != "no" ; then
164     if `$GPGME_CONFIG --thread=pthread 2> /dev/null` ; then
165       req_major=`echo $min_gpgme_version | \
166                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
167       req_minor=`echo $min_gpgme_version | \
168                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
169       req_micro=`echo $min_gpgme_version | \
170                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
171       if test "$gpgme_version_major" -gt "$req_major"; then
172         ok=yes
173       else
174         if test "$gpgme_version_major" -eq "$req_major"; then
175           if test "$gpgme_version_minor" -gt "$req_minor"; then
176             ok=yes
177           else
178             if test "$gpgme_version_minor" -eq "$req_minor"; then
179               if test "$gpgme_version_micro" -ge "$req_micro"; then
180                 ok=yes
181               fi
182             fi
183           fi
184         fi
185       fi
186     fi
187   fi
188   if test $ok = yes; then
189      # If we have a recent GPGME, we should also check that the
190      # API is compatible.
191      if test "$req_gpgme_api" -gt 0 ; then
192         tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
193         if test "$tmp" -gt 0 ; then
194            if test "$req_gpgme_api" -ne "$tmp" ; then
195              ok=no
196            fi
197         fi
198      fi
199   fi
200   if test $ok = yes; then
201     GPGME_PTHREAD_CFLAGS=`$GPGME_CONFIG --thread=pthread --cflags`
202     GPGME_PTHREAD_LIBS=`$GPGME_CONFIG --thread=pthread --libs`
203     AC_MSG_RESULT(yes)
204     ifelse([$2], , :, [$2])
205     _AM_PATH_GPGME_CONFIG_HOST_CHECK
206   else
207     GPGME_PTHREAD_CFLAGS=""
208     GPGME_PTHREAD_LIBS=""
209     AC_MSG_RESULT(no)
210     ifelse([$3], , :, [$3])
211   fi
212   AC_SUBST(GPGME_PTHREAD_CFLAGS)
213   AC_SUBST(GPGME_PTHREAD_LIBS)
217 dnl AM_PATH_GPGME_GLIB([MINIMUM-VERSION,
218 dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
219 dnl Test for libgpgme-glib and define GPGME_GLIB_CFLAGS and GPGME_GLIB_LIBS.
221 AC_DEFUN([AM_PATH_GPGME_GLIB],
222 [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
223   tmp=ifelse([$1], ,1:0.4.2,$1)
224   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
225      req_gpgme_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
226      min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
227   else
228      req_gpgme_api=0
229      min_gpgme_version="$tmp"
230   fi
232   AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
233   ok=no
234   if test "$GPGME_CONFIG" != "no" ; then
235     req_major=`echo $min_gpgme_version | \
236                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
237     req_minor=`echo $min_gpgme_version | \
238                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
239     req_micro=`echo $min_gpgme_version | \
240                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
241     if test "$gpgme_version_major" -gt "$req_major"; then
242         ok=yes
243     else
244         if test "$gpgme_version_major" -eq "$req_major"; then
245             if test "$gpgme_version_minor" -gt "$req_minor"; then
246                ok=yes
247             else
248                if test "$gpgme_version_minor" -eq "$req_minor"; then
249                    if test "$gpgme_version_micro" -ge "$req_micro"; then
250                      ok=yes
251                    fi
252                fi
253             fi
254         fi
255     fi
256   fi
257   if test $ok = yes; then
258      # If we have a recent GPGME, we should also check that the
259      # API is compatible.
260      if test "$req_gpgme_api" -gt 0 ; then
261         tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
262         if test "$tmp" -gt 0 ; then
263            if test "$req_gpgme_api" -ne "$tmp" ; then
264              ok=no
265            fi
266         fi
267      fi
268   fi
269   if test $ok = yes; then
270     GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --glib --cflags`
271     GPGME_GLIB_LIBS=`$GPGME_CONFIG --glib --libs`
272     AC_MSG_RESULT(yes)
273     ifelse([$2], , :, [$2])
274     _AM_PATH_GPGME_CONFIG_HOST_CHECK
275   else
276     GPGME_GLIB_CFLAGS=""
277     GPGME_GLIB_LIBS=""
278     AC_MSG_RESULT(no)
279     ifelse([$3], , :, [$3])
280   fi
281   AC_SUBST(GPGME_GLIB_CFLAGS)
282   AC_SUBST(GPGME_GLIB_LIBS)