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