Update package version to 1.8.3
[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         if test "x$ac_cv_sys_symbol_underscore" = x ; then
116            ac_cv_sys_symbol_underscore=yes
117         fi
118       else
119          tmp_do_check="yes"
120       fi
121        ;;
122 esac
123 if test "$tmp_do_check" = "yes"; then
124   AC_REQUIRE([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])
125   AC_MSG_CHECKING([for _ prefix in compiled symbols])
126   AC_CACHE_VAL(ac_cv_sys_symbol_underscore,
127   [ac_cv_sys_symbol_underscore=no
128    cat > conftest.$ac_ext <<EOF
129       void nm_test_func(){}
130       int main(){nm_test_func;return 0;}
131 EOF
132   if AC_TRY_EVAL(ac_compile); then
133     # Now try to grab the symbols.
134     ac_nlist=conftest.nm
135     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
136       # See whether the symbols have a leading underscore.
137       if egrep '^_nm_test_func' "$ac_nlist" >/dev/null; then
138         ac_cv_sys_symbol_underscore=yes
139       else
140         if egrep '^nm_test_func ' "$ac_nlist" >/dev/null; then
141           :
142         else
143           echo "configure: cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
144         fi
145       fi
146     else
147       echo "configure: cannot run $lt_cv_sys_global_symbol_pipe" >&AC_FD_CC
148     fi
149   else
150     echo "configure: failed program was:" >&AC_FD_CC
151     cat conftest.c >&AC_FD_CC
152   fi
153   rm -rf conftest*
154   ])
155   else
156   AC_MSG_CHECKING([for _ prefix in compiled symbols])
157   fi
158 AC_MSG_RESULT($ac_cv_sys_symbol_underscore)
159 if test x$ac_cv_sys_symbol_underscore = xyes; then
160   AC_DEFINE(WITH_SYMBOL_UNDERSCORE,1,
161             [Defined if compiled symbols have a leading underscore])
162 fi
163 ])
164
165
166 ######################################################################
167 # Check whether mlock is broken (hpux 10.20 raises a SIGBUS if mlock
168 # is not called from uid 0 (not tested whether uid 0 works)
169 # For DECs Tru64 we have also to check whether mlock is in librt
170 # mlock is there a macro using memlk()
171 ######################################################################
172 dnl GNUPG_CHECK_MLOCK
173 dnl
174 define(GNUPG_CHECK_MLOCK,
175   [ AC_CHECK_FUNCS(mlock)
176     if test "$ac_cv_func_mlock" = "no"; then
177         AC_CHECK_HEADERS(sys/mman.h)
178         if test "$ac_cv_header_sys_mman_h" = "yes"; then
179             # Add librt to LIBS:
180             AC_CHECK_LIB(rt, memlk)
181             AC_CACHE_CHECK([whether mlock is in sys/mman.h],
182                             gnupg_cv_mlock_is_in_sys_mman,
183                 [AC_TRY_LINK([
184                     #include <assert.h>
185                     #ifdef HAVE_SYS_MMAN_H
186                     #include <sys/mman.h>
187                     #endif
188                 ], [
189 int i;
190
191 /* glibc defines this for functions which it implements
192  * to always fail with ENOSYS.  Some functions are actually
193  * named something starting with __ and the normal name
194  * is an alias.  */
195 #if defined (__stub_mlock) || defined (__stub___mlock)
196 choke me
197 #else
198 mlock(&i, 4);
199 #endif
200 ; return 0;
201                 ],
202                 gnupg_cv_mlock_is_in_sys_mman=yes,
203                 gnupg_cv_mlock_is_in_sys_mman=no)])
204             if test "$gnupg_cv_mlock_is_in_sys_mman" = "yes"; then
205                 AC_DEFINE(HAVE_MLOCK,1,
206                           [Defined if the system supports an mlock() call])
207             fi
208         fi
209     fi
210     if test "$ac_cv_func_mlock" = "yes"; then
211         AC_CHECK_FUNCS(sysconf getpagesize)
212         AC_MSG_CHECKING(whether mlock is broken)
213           AC_CACHE_VAL(gnupg_cv_have_broken_mlock,
214              AC_TRY_RUN([
215 #include <stdlib.h>
216 #include <unistd.h>
217 #include <errno.h>
218 #include <sys/mman.h>
219 #include <sys/types.h>
220 #include <fcntl.h>
221
222 int main()
223 {
224     char *pool;
225     int err;
226     long int pgsize;
227
228 #if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
229     pgsize = sysconf (_SC_PAGESIZE);
230 #elif defined (HAVE_GETPAGESIZE)
231     pgsize = getpagesize();
232 #else
233     pgsize = -1;
234 #endif
235
236     if (pgsize == -1)
237       pgsize = 4096;
238
239     pool = malloc( 4096 + pgsize );
240     if( !pool )
241         return 2;
242     pool += (pgsize - ((long int)pool % pgsize));
243
244     err = mlock( pool, 4096 );
245     if( !err || errno == EPERM || errno == EAGAIN)
246         return 0; /* okay */
247
248     return 1;  /* hmmm */
249 }
250
251             ],
252             gnupg_cv_have_broken_mlock="no",
253             gnupg_cv_have_broken_mlock="yes",
254             gnupg_cv_have_broken_mlock="assume-no"
255            )
256          )
257          if test "$gnupg_cv_have_broken_mlock" = "yes"; then
258              AC_DEFINE(HAVE_BROKEN_MLOCK,1,
259                        [Defined if the mlock() call does not work])
260              AC_MSG_RESULT(yes)
261          else
262             if test "$gnupg_cv_have_broken_mlock" = "no"; then
263                 AC_MSG_RESULT(no)
264             else
265                 AC_MSG_RESULT(assuming no)
266             fi
267          fi
268     fi
269   ])
270
271 # GNUPG_SYS_LIBTOOL_CYGWIN32 - find tools needed on cygwin32
272 AC_DEFUN([GNUPG_SYS_LIBTOOL_CYGWIN32],
273 [AC_CHECK_TOOL(DLLTOOL, dlltool, false)
274 AC_CHECK_TOOL(AS, as, false)
275 ])
276
277 dnl LIST_MEMBER()
278 dnl Check whether an element ist contained in a list.  Set `found' to
279 dnl `1' if the element is found in the list, to `0' otherwise.
280 AC_DEFUN([LIST_MEMBER],
281 [
282 name=$1
283 list=$2
284 found=0
285
286 for n in $list; do
287   if test "x$name" = "x$n"; then
288     found=1
289   fi
290 done
291 ])
292
293
294 dnl Check for socklen_t: historically on BSD it is an int, and in
295 dnl POSIX 1g it is a type of its own, but some platforms use different
296 dnl types for the argument to getsockopt, getpeername, etc.  So we
297 dnl have to test to find something that will work.
298 AC_DEFUN([TYPE_SOCKLEN_T],
299 [
300    AC_CHECK_TYPE([socklen_t], ,[
301       AC_MSG_CHECKING([for socklen_t equivalent])
302       AC_CACHE_VAL([socklen_t_equiv],
303       [
304          # Systems have either "struct sockaddr *" or
305          # "void *" as the second argument to getpeername
306          socklen_t_equiv=
307          for arg2 in "struct sockaddr" void; do
308             for t in int size_t unsigned long "unsigned long"; do
309                AC_TRY_COMPILE([
310 #include <sys/types.h>
311 #include <sys/socket.h>
312
313 int getpeername (int, $arg2 *, $t *);
314                ],[
315                   $t len;
316                   getpeername(0,0,&len);
317                ],[
318                   socklen_t_equiv="$t"
319                   break
320                ])
321             done
322          done
323
324          if test "x$socklen_t_equiv" = x; then
325             AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
326          fi
327       ])
328       AC_MSG_RESULT($socklen_t_equiv)
329       AC_DEFINE_UNQUOTED(socklen_t, $socklen_t_equiv,
330                         [type to use in place of socklen_t if not defined])],
331       [#include <sys/types.h>
332 #include <sys/socket.h>])
333 ])
334
335
336 # GNUPG_PTH_VERSION_CHECK(REQUIRED)
337 #
338 # If the version is sufficient, HAVE_PTH will be set to yes.
339 #
340 # Taken form the m4 macros which come with Pth
341 AC_DEFUN([GNUPG_PTH_VERSION_CHECK],
342   [
343     _pth_version=`$PTH_CONFIG --version | awk 'NR==1 {print [$]3}'`
344     _req_version="ifelse([$1],,1.2.0,$1)"
345
346     AC_MSG_CHECKING(for PTH - version >= $_req_version)
347     for _var in _pth_version _req_version; do
348         eval "_val=\"\$${_var}\""
349         _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
350         _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
351         _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
352         _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
353         case $_rtype in
354             "a" ) _rtype=0 ;;
355             "b" ) _rtype=1 ;;
356             "." ) _rtype=2 ;;
357         esac
358         _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
359               "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
360         eval "${_var}_hex=\"\$_hex\""
361     done
362     have_pth=no
363     if test ".$_pth_version_hex" != .; then
364         if test ".$_req_version_hex" != .; then
365             if test $_pth_version_hex -ge $_req_version_hex; then
366                 have_pth=yes
367             fi
368         fi
369     fi
370     if test $have_pth = yes; then
371        AC_MSG_RESULT(yes)
372        AC_MSG_CHECKING([whether PTH installation is sane])
373        AC_CACHE_VAL(gnupg_cv_pth_is_sane,[
374          _gnupg_pth_save_cflags=$CFLAGS
375          _gnupg_pth_save_ldflags=$LDFLAGS
376          _gnupg_pth_save_libs=$LIBS
377          CFLAGS="$CFLAGS `$PTH_CONFIG --cflags`"
378          LDFLAGS="$LDFLAGS `$PTH_CONFIG --ldflags`"
379          LIBS="$LIBS `$PTH_CONFIG --libs`"
380          AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pth.h>
381                                          ],
382                                          [[ pth_init ();]])],
383                         gnupg_cv_pth_is_sane=yes,
384                         gnupg_cv_pth_is_sane=no)
385          CFLAGS=$_gnupg_pth_save_cflags
386          LDFLAGS=$_gnupg_pth_save_ldflags
387          LIBS=$_gnupg_pth_save_libs
388        ])
389        if test $gnupg_cv_pth_is_sane != yes; then
390           have_pth=no
391        fi
392        AC_MSG_RESULT($gnupg_cv_pth_is_sane)
393     else
394        AC_MSG_RESULT(no)
395     fi
396   ])