Merged Top directory of NewPG with GnuPG.
[gnupg.git] / acinclude.m4
1 dnl macros to configure gnupg
2 dnl Copyright (C) 1998, 1999, 2000, 2001 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 # Check for the getsockopt SO_PEERCRED
40 AC_DEFUN(GNUPG_SYS_SO_PEERCRED,
41   [ AC_MSG_CHECKING(for SO_PEERCRED)
42     AC_CACHE_VAL(gnupg_cv_sys_so_peercred,
43       [AC_TRY_COMPILE([#include <sys/socket.h>], 
44                     [struct ucred cr; 
45                      int cl = sizeof cr;
46                      getsockopt (1, SOL_SOCKET, SO_PEERCRED, &cr, &cl);],
47                     gnupg_cv_sys_so_peercred=yes,
48                     gnupg_cv_sys_so_peercred=no)
49       ])
50     AC_MSG_RESULT($gnupg_cv_sys_so_peercred) 
51     if test $gnupg_cv_sys_so_peercred = yes; then
52          AC_DEFINE(HAVE_SO_PEERCRED, 1,
53                             [Defined if SO_PEERCRED is supported (Linux)])
54     fi
55   ])
56
57
58
59 # GNUPG_BUILD_PROGRAM(NAME,DEFAULT)
60 # Add a --enable-NAME option to configure an set the
61 # shell variable build_NAME either to "yes" or "no".  DEFAULT must
62 # either be "yes" or "no" and decided on the default value for
63 # build_NAME and whether --enable-NAME or --disable-NAME is shown with 
64 # ./configure --help
65 AC_DEFUN(GNUPG_BUILD_PROGRAM,
66   [build_$1=$2
67    m4_if([$2],[yes],[
68       AC_ARG_ENABLE([$1], AC_HELP_STRING([--disable-$1],
69                                          [do not build the $1 program]),
70                            build_$1=$enableval, build_$1=$2)
71     ],[
72       AC_ARG_ENABLE([$1], AC_HELP_STRING([--enable-$1],
73                                          [build the $1 program]),
74                            build_$1=$enableval, build_$1=$2)
75     ])
76    case "$build_$1" in
77          no|yes)
78            ;;
79          *) 
80            AC_MSG_ERROR([only yes or no allowed for feature --enable-$1])
81            ;;
82    esac
83   ])
84
85
86
87 # GNUPG_PTH_VERSION_CHECK(REQUIRED)
88
89 # If the version is sufficient, HAVE_PTH will be set to yes.
90 #
91 # Taken form the m4 macros which come with Pth
92 AC_DEFUN(GNUPG_PTH_VERSION_CHECK,
93   [
94     _pth_version=`$PTH_CONFIG --version | awk 'NR==1 {print [$]3}'`
95     _req_version="ifelse([$1],,1.2.0,$1)"
96     for _var in _pth_version _req_version; do
97         eval "_val=\"\$${_var}\""
98         _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
99         _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
100         _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
101         _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
102         case $_rtype in
103             "a" ) _rtype=0 ;;
104             "b" ) _rtype=1 ;;
105             "." ) _rtype=2 ;;
106         esac
107         _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
108               "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
109         eval "${_var}_hex=\"\$_hex\""
110     done
111     have_pth=no
112     if test ".$_pth_version_hex" != .; then
113         if test ".$_req_version_hex" != .; then
114             if test $_pth_version_hex -ge $_req_version_hex; then
115                 have_pth=yes
116             fi
117         fi
118     fi
119     if test $have_pth = no; then
120        AC_MSG_WARN([[
121 ***
122 *** Found Pth version $_pth_version, but require at least
123 *** version $_req_version.  Please upgrade Pth first.
124 ***]])
125     fi    
126   ])
127
128 ######################################################################
129 # Check whether mlock is broken (hpux 10.20 raises a SIGBUS if mlock
130 # is not called from uid 0 (not tested whether uid 0 works)
131 # For DECs Tru64 we have also to check whether mlock is in librt
132 # mlock is there a macro using memlk()
133 ######################################################################
134 dnl GNUPG_CHECK_MLOCK
135 dnl
136 define(GNUPG_CHECK_MLOCK,
137   [ AC_CHECK_FUNCS(mlock)
138     if test "$ac_cv_func_mlock" = "no"; then
139         AC_CHECK_HEADERS(sys/mman.h)
140         if test "$ac_cv_header_sys_mman_h" = "yes"; then
141             # Add librt to LIBS:
142             AC_CHECK_LIB(rt, memlk)
143             AC_CACHE_CHECK([whether mlock is in sys/mman.h],
144                             gnupg_cv_mlock_is_in_sys_mman,
145                 [AC_TRY_LINK([
146                     #include <assert.h>
147                     #ifdef HAVE_SYS_MMAN_H
148                     #include <sys/mman.h>
149                     #endif
150                 ], [
151                     int i;
152
153                     /* glibc defines this for functions which it implements
154                      * to always fail with ENOSYS.  Some functions are actually
155                      * named something starting with __ and the normal name
156                      * is an alias.  */
157                     #if defined (__stub_mlock) || defined (__stub___mlock)
158                     choke me
159                     #else
160                     mlock(&i, 4);
161                     #endif
162                     ; return 0;
163                 ],
164                 gnupg_cv_mlock_is_in_sys_mman=yes,
165                 gnupg_cv_mlock_is_in_sys_mman=no)])
166             if test "$gnupg_cv_mlock_is_in_sys_mman" = "yes"; then
167                 AC_DEFINE(HAVE_MLOCK,1,
168                           [Defined if the system supports an mlock() call])
169             fi
170         fi
171     fi
172     if test "$ac_cv_func_mlock" = "yes"; then
173         AC_MSG_CHECKING(whether mlock is broken)
174           AC_CACHE_VAL(gnupg_cv_have_broken_mlock,
175              AC_TRY_RUN([
176                 #include <stdlib.h>
177                 #include <unistd.h>
178                 #include <errno.h>
179                 #include <sys/mman.h>
180                 #include <sys/types.h>
181                 #include <fcntl.h>
182
183                 int main()
184                 {
185                     char *pool;
186                     int err;
187                     long int pgsize = getpagesize();
188
189                     pool = malloc( 4096 + pgsize );
190                     if( !pool )
191                         return 2;
192                     pool += (pgsize - ((long int)pool % pgsize));
193
194                     err = mlock( pool, 4096 );
195                     if( !err || errno == EPERM )
196                         return 0; /* okay */
197
198                     return 1;  /* hmmm */
199                 }
200
201             ],
202             gnupg_cv_have_broken_mlock="no",
203             gnupg_cv_have_broken_mlock="yes",
204             gnupg_cv_have_broken_mlock="assume-no"
205            )
206          )
207          if test "$gnupg_cv_have_broken_mlock" = "yes"; then
208              AC_DEFINE(HAVE_BROKEN_MLOCK,1,
209                        [Defined if the mlock() call does not work])
210              AC_MSG_RESULT(yes)
211              AC_CHECK_FUNCS(plock)
212          else
213             if test "$gnupg_cv_have_broken_mlock" = "no"; then
214                 AC_MSG_RESULT(no)
215             else
216                 AC_MSG_RESULT(assuming no)
217             fi
218          fi
219     fi
220   ])
221
222
223
224 dnl [copied from libgcrypt]
225 dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,
226 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
227 dnl Test for liblibgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS
228 dnl
229 AC_DEFUN(AM_PATH_LIBGCRYPT,
230 [ AC_ARG_WITH(libgcrypt-prefix,
231             AC_HELP_STRING([--with-libgcrypt-prefix=PFX],
232                            [prefix where LIBGCRYPT is installed (optional)]),
233      libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
234   if test x$libgcrypt_config_prefix != x ; then
235      libgcrypt_config_args="$libgcrypt_config_args --prefix=$libgcrypt_config_prefix"
236      if test x${LIBGCRYPT_CONFIG+set} != xset ; then
237         LIBGCRYPT_CONFIG=$libgcrypt_config_prefix/bin/libgcrypt-config
238      fi
239   fi
240
241   AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
242   min_libgcrypt_version=ifelse([$1], ,0.4.4,$1)
243   AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
244   ok=no
245   if test "$LIBGCRYPT_CONFIG" != "no" ; then
246     req_major=`echo $min_libgcrypt_version | \
247                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
248     req_minor=`echo $min_libgcrypt_version | \
249                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
250     req_micro=`echo $min_libgcrypt_version | \
251                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
252     libgcrypt_config_version=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --version`
253     major=`echo $libgcrypt_config_version | \
254                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
255     minor=`echo $libgcrypt_config_version | \
256                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
257     micro=`echo $libgcrypt_config_version | \
258                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
259     if test "$major" -gt "$req_major"; then
260         ok=yes
261     else 
262         if test "$major" -eq "$req_major"; then
263             if test "$minor" -gt "$req_minor"; then
264                ok=yes
265             else
266                if test "$minor" -eq "$req_minor"; then
267                    if test "$micro" -ge "$req_micro"; then
268                      ok=yes
269                    fi
270                fi
271             fi
272         fi
273     fi
274   fi
275   if test $ok = yes; then
276     LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --cflags`
277     LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --libs`
278     AC_MSG_RESULT(yes)
279     ifelse([$2], , :, [$2])
280   else
281     LIBGCRYPT_CFLAGS=""
282     LIBGCRYPT_LIBS=""
283     AC_MSG_RESULT(no)
284     ifelse([$3], , :, [$3])
285   fi
286   AC_SUBST(LIBGCRYPT_CFLAGS)
287   AC_SUBST(LIBGCRYPT_LIBS)
288 ])
289
290
291 dnl [Copied from libksba]
292 dnl AM_PATH_KSBA([MINIMUM-VERSION,
293 dnl              [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
294 dnl Test for libksba and define KSBA_CFLAGS and KSBA_LIBS
295 dnl
296 AC_DEFUN(AM_PATH_KSBA,
297 [ AC_ARG_WITH(ksba-prefix,
298             AC_HELP_STRING([--with-ksba-prefix=PFX],
299                            [prefix where KSBA is installed (optional)]),
300      ksba_config_prefix="$withval", ksba_config_prefix="")
301   if test x$ksba_config_prefix != x ; then
302      ksba_config_args="$ksba_config_args --prefix=$ksba_config_prefix"
303      if test x${KSBA_CONFIG+set} != xset ; then
304         KSBA_CONFIG=$ksba_config_prefix/bin/ksba-config
305      fi
306   fi
307
308   AC_PATH_PROG(KSBA_CONFIG, ksba-config, no)
309   min_ksba_version=ifelse([$1], ,0.4.4,$1)
310   AC_MSG_CHECKING(for KSBA - version >= $min_ksba_version)
311   ok=no
312   if test "$KSBA_CONFIG" != "no" ; then
313     req_major=`echo $min_ksba_version | \
314                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
315     req_minor=`echo $min_ksba_version | \
316                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
317     req_micro=`echo $min_ksba_version | \
318                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
319     ksba_config_version=`$KSBA_CONFIG $ksba_config_args --version`
320     major=`echo $ksba_config_version | \
321                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
322     minor=`echo $ksba_config_version | \
323                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
324     micro=`echo $ksba_config_version | \
325                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
326     if test "$major" -gt "$req_major"; then
327         ok=yes
328     else 
329         if test "$major" -eq "$req_major"; then
330             if test "$minor" -gt "$req_minor"; then
331                ok=yes
332             else
333                if test "$minor" -eq "$req_minor"; then
334                    if test "$micro" -ge "$req_micro"; then
335                      ok=yes
336                    fi
337                fi
338             fi
339         fi
340     fi
341   fi
342   if test $ok = yes; then
343     KSBA_CFLAGS=`$KSBA_CONFIG $ksba_config_args --cflags`
344     KSBA_LIBS=`$KSBA_CONFIG $ksba_config_args --libs`
345     AC_MSG_RESULT(yes)
346     ifelse([$2], , :, [$2])
347   else
348     KSBA_CFLAGS=""
349     KSBA_LIBS=""
350     AC_MSG_RESULT(no)
351     ifelse([$3], , :, [$3])
352   fi
353   AC_SUBST(KSBA_CFLAGS)
354   AC_SUBST(KSBA_LIBS)
355 ])
356
357
358
359 dnl AM_PATH_OPENSC([MINIMUM-VERSION,
360 dnl               [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
361 dnl Test for OpenSC and define OPENSC_CFLAGS and OPENSC_LIBS
362 dnl
363 AC_DEFUN(AM_PATH_OPENSC,
364 [ AC_ARG_WITH(opensc-prefix,
365             AC_HELP_STRING([--with-opensc-prefix=PFX],
366                            [prefix where OpenSC is installed (optional)]),
367      opensc_config_prefix="$withval", opensc_config_prefix="")
368   if test x$opensc_config_prefix != x ; then
369      opensc_config_args="$opensc_config_args --prefix=$opensc_config_prefix"
370      if test x${OPENSC_CONFIG+set} != xset ; then
371         OPENSC_CONFIG=$opensc_config_prefix/bin/opensc-config
372      fi
373   fi
374
375   AC_PATH_PROG(OPENSC_CONFIG, opensc-config, no)
376   min_opensc_version=ifelse([$1], ,0.7.0,$1)
377   AC_MSG_CHECKING(for OpenSC - version >= $min_opensc_version)
378   ok=no
379   if test "$OPENSC_CONFIG" != "no" ; then
380     req_major=`echo $min_opensc_version | \
381                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
382     req_minor=`echo $min_opensc_version | \
383                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
384     req_micro=`echo $min_opensc_version | \
385                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
386     opensc_config_version=`$OPENSC_CONFIG $opensc_config_args --version`
387     major=`echo $opensc_config_version | \
388                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
389     minor=`echo $opensc_config_version | \
390                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
391     micro=`echo $opensc_config_version | \
392                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
393     if test "$major" -gt "$req_major"; then
394         ok=yes
395     else 
396         if test "$major" -eq "$req_major"; then
397             if test "$minor" -gt "$req_minor"; then
398                ok=yes
399             else
400                if test "$minor" -eq "$req_minor"; then
401                    if test "$micro" -ge "$req_micro"; then
402                      ok=yes
403                    fi
404                fi
405             fi
406         fi
407     fi
408   fi
409   if test $ok = yes; then
410     OPENSC_CFLAGS=`$OPENSC_CONFIG $opensc_config_args --cflags`
411     OPENSC_LIBS=`$OPENSC_CONFIG $opensc_config_args --libs`
412     OPENSC_LIBS="$OPENSC_LIBS -lpcsclite -lpthread"
413     AC_MSG_RESULT(yes)
414     ifelse([$2], , :, [$2])
415   else
416     OPENSC_CFLAGS=""
417     OPENSC_LIBS=""
418     AC_MSG_RESULT(no)
419     ifelse([$3], , :, [$3])
420   fi
421   AC_SUBST(OPENSC_CFLAGS)
422   AC_SUBST(OPENSC_LIBS)
423 ])
424
425