1dnl macros to configure Libgcrypt
2dnl Copyright (C) 1998, 1999, 2000, 2001, 2002,
3dnl               2003 Free Software Foundation, Inc.
4dnl
5dnl This file is part of Libgcrypt.
6dnl
7dnl Libgcrypt is free software; you can redistribute it and/or modify
8dnl it under the terms of the GNU Lesser General Public License as
9dnl published by the Free Software Foundation; either version 2.1 of
10dnl the License, or (at your option) any later version.
11dnl
12dnl Libgcrypt is distributed in the hope that it will be useful,
13dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15dnl GNU Lesser General Public License for more details.
16dnl
17dnl You should have received a copy of the GNU Lesser General Public
18dnl License along with this program; if not, write to the Free Software
19dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20
21dnl GNUPG_MSG_PRINT(STRING)
22dnl print a message
23dnl
24define([GNUPG_MSG_PRINT],
25  [ echo $ac_n "$1"" $ac_c" 1>&AS_MESSAGE_FD([])
26  ])
27
28dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME)
29dnl Check whether a typedef exists and create a #define $2 if it exists
30dnl
31AC_DEFUN([GNUPG_CHECK_TYPEDEF],
32  [ AC_MSG_CHECKING(for $1 typedef)
33    AC_CACHE_VAL(gnupg_cv_typedef_$1,
34    [AC_TRY_COMPILE([#define _GNU_SOURCE 1
35    #include <stdlib.h>
36    #include <sys/types.h>], [
37    #undef $1
38    int a = sizeof($1);
39    ], gnupg_cv_typedef_$1=yes, gnupg_cv_typedef_$1=no )])
40    AC_MSG_RESULT($gnupg_cv_typedef_$1)
41    if test "$gnupg_cv_typedef_$1" = yes; then
42        AC_DEFINE($2,1,[Defined if a `]$1[' is typedef'd])
43    fi
44  ])
45
46
47dnl GNUPG_CHECK_GNUMAKE
48dnl
49AC_DEFUN([GNUPG_CHECK_GNUMAKE],
50  [
51    if ${MAKE-make} --version 2>/dev/null | grep '^GNU ' >/dev/null 2>&1; then
52        :
53    else
54        AC_MSG_WARN([[
55***
56*** It seems that you are not using GNU make.  Some make tools have serious
57*** flaws and you may not be able to build this software at all. Before you
58*** complain, please try GNU make:  GNU make is easy to build and available
59*** at all GNU archives.  It is always available from ftp.gnu.org:/gnu/make.
60***]])
61    fi
62  ])
63
64
65#
66# GNUPG_SYS_SYMBOL_UNDERSCORE
67# Does the compiler prefix global symbols with an underscore?
68#
69# Taken from GnuPG 1.2 and modified to use the libtool macros.
70AC_DEFUN([GNUPG_SYS_SYMBOL_UNDERSCORE],
71[tmp_do_check="no"
72case "${host}" in
73    *-mingw32msvc*)
74        ac_cv_sys_symbol_underscore=yes
75        ;;
76    i386-emx-os2 | i[3456]86-pc-os2*emx | i386-pc-msdosdjgpp)
77        ac_cv_sys_symbol_underscore=yes
78        ;;
79    *)
80      if test "$cross_compiling" = yes; then
81        if test "x$ac_cv_sys_symbol_underscore" = x ; then
82           ac_cv_sys_symbol_underscore=yes
83        fi
84      else
85         tmp_do_check="yes"
86      fi
87       ;;
88esac
89if test "$tmp_do_check" = "yes"; then
90  AC_REQUIRE([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])
91  AC_MSG_CHECKING([for _ prefix in compiled symbols])
92  AC_CACHE_VAL(ac_cv_sys_symbol_underscore,
93  [ac_cv_sys_symbol_underscore=no
94   cat > conftest.$ac_ext <<EOF
95      void nm_test_func(){}
96      int main(){nm_test_func;return 0;}
97EOF
98  if AC_TRY_EVAL(ac_compile); then
99    # Now try to grab the symbols.
100    ac_nlist=conftest.nm
101    if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \| cut -d \' \' -f 2 \> $ac_nlist) && test -s "$ac_nlist"; then
102      # See whether the symbols have a leading underscore.
103      if egrep '^_nm_test_func' "$ac_nlist" >/dev/null; then
104        ac_cv_sys_symbol_underscore=yes
105      else
106        if egrep '^nm_test_func ' "$ac_nlist" >/dev/null; then
107          :
108        else
109          echo "configure: cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
110        fi
111      fi
112    else
113      echo "configure: cannot run $lt_cv_sys_global_symbol_pipe" >&AC_FD_CC
114    fi
115  else
116    echo "configure: failed program was:" >&AC_FD_CC
117    cat conftest.c >&AC_FD_CC
118  fi
119  rm -rf conftest*
120  ])
121  else
122  AC_MSG_CHECKING([for _ prefix in compiled symbols])
123  fi
124AC_MSG_RESULT($ac_cv_sys_symbol_underscore)
125if test x$ac_cv_sys_symbol_underscore = xyes; then
126  AC_DEFINE(WITH_SYMBOL_UNDERSCORE,1,
127            [Defined if compiled symbols have a leading underscore])
128fi
129])
130
131
132######################################################################
133# Check whether mlock is broken (hpux 10.20 raises a SIGBUS if mlock
134# is not called from uid 0 (not tested whether uid 0 works)
135# For DECs Tru64 we have also to check whether mlock is in librt
136# mlock is there a macro using memlk()
137######################################################################
138dnl GNUPG_CHECK_MLOCK
139dnl
140define(GNUPG_CHECK_MLOCK,
141  [ AC_CHECK_FUNCS(mlock)
142    if test "$ac_cv_func_mlock" = "no"; then
143        AC_CHECK_HEADERS(sys/mman.h)
144        if test "$ac_cv_header_sys_mman_h" = "yes"; then
145            # Add librt to LIBS:
146            AC_CHECK_LIB(rt, memlk)
147            AC_CACHE_CHECK([whether mlock is in sys/mman.h],
148                            gnupg_cv_mlock_is_in_sys_mman,
149                [AC_TRY_LINK([
150                    #include <assert.h>
151                    #ifdef HAVE_SYS_MMAN_H
152                    #include <sys/mman.h>
153                    #endif
154                ], [
155int i;
156
157/* glibc defines this for functions which it implements
158 * to always fail with ENOSYS.  Some functions are actually
159 * named something starting with __ and the normal name
160 * is an alias.  */
161#if defined (__stub_mlock) || defined (__stub___mlock)
162choke me
163#else
164mlock(&i, 4);
165#endif
166; return 0;
167                ],
168                gnupg_cv_mlock_is_in_sys_mman=yes,
169                gnupg_cv_mlock_is_in_sys_mman=no)])
170            if test "$gnupg_cv_mlock_is_in_sys_mman" = "yes"; then
171                AC_DEFINE(HAVE_MLOCK,1,
172                          [Defined if the system supports an mlock() call])
173            fi
174        fi
175    fi
176    if test "$ac_cv_func_mlock" = "yes"; then
177        AC_CHECK_FUNCS(sysconf getpagesize)
178        AC_MSG_CHECKING(whether mlock is broken)
179          AC_CACHE_VAL(gnupg_cv_have_broken_mlock,
180             AC_TRY_RUN([
181#include <stdlib.h>
182#include <unistd.h>
183#include <errno.h>
184#include <sys/mman.h>
185#include <sys/types.h>
186#include <fcntl.h>
187
188int main()
189{
190    char *pool;
191    int err;
192    long int pgsize;
193
194#if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
195    pgsize = sysconf (_SC_PAGESIZE);
196#elif defined (HAVE_GETPAGESIZE)
197    pgsize = getpagesize();
198#else
199    pgsize = -1;
200#endif
201
202    if (pgsize == -1)
203      pgsize = 4096;
204
205    pool = malloc( 4096 + pgsize );
206    if( !pool )
207        return 2;
208    pool += (pgsize - ((long int)pool % pgsize));
209
210    err = mlock( pool, 4096 );
211    if( !err || errno == EPERM )
212        return 0; /* okay */
213
214    return 1;  /* hmmm */
215}
216
217            ],
218            gnupg_cv_have_broken_mlock="no",
219            gnupg_cv_have_broken_mlock="yes",
220            gnupg_cv_have_broken_mlock="assume-no"
221           )
222         )
223         if test "$gnupg_cv_have_broken_mlock" = "yes"; then
224             AC_DEFINE(HAVE_BROKEN_MLOCK,1,
225                       [Defined if the mlock() call does not work])
226             AC_MSG_RESULT(yes)
227         else
228            if test "$gnupg_cv_have_broken_mlock" = "no"; then
229                AC_MSG_RESULT(no)
230            else
231                AC_MSG_RESULT(assuming no)
232            fi
233         fi
234    fi
235  ])
236
237# GNUPG_SYS_LIBTOOL_CYGWIN32 - find tools needed on cygwin32
238AC_DEFUN([GNUPG_SYS_LIBTOOL_CYGWIN32],
239[AC_CHECK_TOOL(DLLTOOL, dlltool, false)
240AC_CHECK_TOOL(AS, as, false)
241])
242
243dnl LIST_MEMBER()
244dnl Check wether an element ist contained in a list.  Set `found' to
245dnl `1' if the element is found in the list, to `0' otherwise.
246AC_DEFUN([LIST_MEMBER],
247[
248name=$1
249list=$2
250found=0
251
252for n in $list; do
253  if test "x$name" = "x$n"; then
254    found=1
255  fi
256done
257])
258
259
260dnl Check for socklen_t: historically on BSD it is an int, and in
261dnl POSIX 1g it is a type of its own, but some platforms use different
262dnl types for the argument to getsockopt, getpeername, etc.  So we
263dnl have to test to find something that will work.
264AC_DEFUN([TYPE_SOCKLEN_T],
265[
266   AC_CHECK_TYPE([socklen_t], ,[
267      AC_MSG_CHECKING([for socklen_t equivalent])
268      AC_CACHE_VAL([socklen_t_equiv],
269      [
270         # Systems have either "struct sockaddr *" or
271         # "void *" as the second argument to getpeername
272         socklen_t_equiv=
273         for arg2 in "struct sockaddr" void; do
274            for t in int size_t unsigned long "unsigned long"; do
275               AC_TRY_COMPILE([
276#include <sys/types.h>
277#include <sys/socket.h>
278
279int getpeername (int, $arg2 *, $t *);
280               ],[
281                  $t len;
282                  getpeername(0,0,&len);
283               ],[
284                  socklen_t_equiv="$t"
285                  break
286               ])
287            done
288         done
289
290         if test "x$socklen_t_equiv" = x; then
291            AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
292         fi
293      ])
294      AC_MSG_RESULT($socklen_t_equiv)
295      AC_DEFINE_UNQUOTED(socklen_t, $socklen_t_equiv,
296			[type to use in place of socklen_t if not defined])],
297      [#include <sys/types.h>
298#include <sys/socket.h>])
299])
300
301
302# GNUPG_PTH_VERSION_CHECK(REQUIRED)
303#
304# If the version is sufficient, HAVE_PTH will be set to yes.
305#
306# Taken form the m4 macros which come with Pth
307AC_DEFUN([GNUPG_PTH_VERSION_CHECK],
308  [
309    _pth_version=`$PTH_CONFIG --version | awk 'NR==1 {print [$]3}'`
310    _req_version="ifelse([$1],,1.2.0,$1)"
311
312    AC_MSG_CHECKING(for PTH - version >= $_req_version)
313    for _var in _pth_version _req_version; do
314        eval "_val=\"\$${_var}\""
315        _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
316        _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
317        _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
318        _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
319        case $_rtype in
320            "a" ) _rtype=0 ;;
321            "b" ) _rtype=1 ;;
322            "." ) _rtype=2 ;;
323        esac
324        _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
325              "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
326        eval "${_var}_hex=\"\$_hex\""
327    done
328    have_pth=no
329    if test ".$_pth_version_hex" != .; then
330        if test ".$_req_version_hex" != .; then
331            if test $_pth_version_hex -ge $_req_version_hex; then
332                have_pth=yes
333            fi
334        fi
335    fi
336    if test $have_pth = yes; then
337       AC_MSG_RESULT(yes)
338       AC_MSG_CHECKING([whether PTH installation is sane])
339       AC_CACHE_VAL(gnupg_cv_pth_is_sane,[
340         _gnupg_pth_save_cflags=$CFLAGS
341         _gnupg_pth_save_ldflags=$LDFLAGS
342         _gnupg_pth_save_libs=$LIBS
343         CFLAGS="$CFLAGS `$PTH_CONFIG --cflags`"
344         LDFLAGS="$LDFLAGS `$PTH_CONFIG --ldflags`"
345         LIBS="$LIBS `$PTH_CONFIG --libs`"
346         AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pth.h>
347                                         ],
348                                         [[ pth_init ();]])],
349                        gnupg_cv_pth_is_sane=yes,
350                        gnupg_cv_pth_is_sane=no)
351         CFLAGS=$_gnupg_pth_save_cflags
352         LDFLAGS=$_gnupg_pth_save_ldflags
353         LIBS=$_gnupg_pth_save_libs
354       ])
355       if test $gnupg_cv_pth_is_sane != yes; then
356          have_pth=no
357       fi
358       AC_MSG_RESULT($gnupg_cv_pth_is_sane)
359    else
360       AC_MSG_RESULT(no)
361    fi
362  ])
363