2006-01-08 Moritz Schulte <moritz@g10code.com>
[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
5 dnl This file is part of Libgcrypt.
6 dnl
7 dnl Libgcrypt is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU Lesser General Public License as
9 dnl published by the Free Software Foundation; either version 2.1 of
10 dnl the License, or (at your option) any later version.
11 dnl
12 dnl Libgcrypt is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 dnl GNU Lesser General Public License for more details.
16 dnl
17 dnl You should have received a copy of the GNU Lesser General Public
18 dnl License along with this program; if not, write to the Free Software
19 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20
21 dnl GNUPG_MSG_PRINT(STRING)
22 dnl print a message
23 dnl
24 define([GNUPG_MSG_PRINT],
25   [ echo $ac_n "$1"" $ac_c" 1>&AS_MESSAGE_FD([])
26   ])
27
28 dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME)
29 dnl Check whether a typedef exists and create a #define $2 if it exists
30 dnl
31 AC_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
47 dnl GNUPG_FIX_HDR_VERSION(FILE, NAME)
48 dnl Make the version number in gcrypt/gcrypt.h the same as the one here.
49 dnl (this is easier than to have a .in file just for one substitution)
50 dnl We must use a temp file in the current directory because make distcheck 
51 dnl install all sourcefiles RO.
52 dnl
53 AC_DEFUN([GNUPG_FIX_HDR_VERSION],
54   [ sed "s/^#define $2 \".*/#define $2 \"$VERSION\"/" $srcdir/$1 > fixhdr.tmp
55     if cmp -s $srcdir/$1 fixhdr.tmp 2>/dev/null; then
56         rm -f fixhdr.tmp
57     else
58         rm -f $srcdir/$1
59         if mv fixhdr.tmp $srcdir/$1 ; then
60             :
61         else
62             AC_MSG_ERROR([[
63 ***
64 *** Failed to fix the version string macro $2 in $1.
65 *** The old file has been saved as fixhdr.tmp
66 ***]])
67         fi
68         AC_MSG_WARN([fixed the $2 macro in $1])
69     fi
70   ])
71
72
73 dnl GNUPG_CHECK_GNUMAKE
74 dnl
75 AC_DEFUN([GNUPG_CHECK_GNUMAKE],
76   [
77     if ${MAKE-make} --version 2>/dev/null | grep '^GNU ' >/dev/null 2>&1; then
78         :
79     else
80         AC_MSG_WARN([[
81 ***
82 *** It seems that you are not using GNU make.  Some make tools have serious
83 *** flaws and you may not be able to build this software at all. Before you
84 *** complain, please try GNU make:  GNU make is easy to build and available
85 *** at all GNU archives.  It is always available from ftp.gnu.org:/gnu/make.
86 ***]])
87     fi
88   ])
89
90
91 #
92 # GNUPG_SYS_SYMBOL_UNDERSCORE
93 # Does the compiler prefix global symbols with an underscore?
94 #
95 # Taken from GnuPG 1.2 and modified to use the libtool macros.
96 AC_DEFUN([GNUPG_SYS_SYMBOL_UNDERSCORE],
97 [tmp_do_check="no"
98 case "${target}" in
99     i386-emx-os2 | i[3456]86-pc-os2*emx | i386-pc-msdosdjgpp)
100         ac_cv_sys_symbol_underscore=yes
101         ;;
102     *)
103       if test "$cross_compiling" = yes; then
104          ac_cv_sys_symbol_underscore=yes
105       else
106          tmp_do_check="yes"
107       fi
108        ;;
109 esac
110 if test "$tmp_do_check" = "yes"; then
111   AC_REQUIRE([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])
112   AC_MSG_CHECKING([for _ prefix in compiled symbols])
113   AC_CACHE_VAL(ac_cv_sys_symbol_underscore,
114   [ac_cv_sys_symbol_underscore=no
115    cat > conftest.$ac_ext <<EOF
116       void nm_test_func(){}
117       int main(){nm_test_func;return 0;
118 EOF
119   if AC_TRY_EVAL(ac_compile); then
120     # Now try to grab the symbols.
121     ac_nlist=conftest.nm
122     if AC_TRY_EVAL(NM conftest.$ac_objext \| $global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then
123       # See whether the symbols have a leading underscore.
124       if egrep '^_nm_test_func' "$ac_nlist" >/dev/null; then
125         ac_cv_sys_symbol_underscore=yes
126       else
127         if egrep '^nm_test_func ' "$ac_nlist" >/dev/null; then
128           :
129         else
130           echo "configure: cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
131         fi
132       fi
133     else
134       echo "configure: cannot run $global_symbol_pipe" >&AC_FD_CC
135     fi
136   else
137     echo "configure: failed program was:" >&AC_FD_CC
138     cat conftest.c >&AC_FD_CC
139   fi
140   rm -rf conftest*
141   ])
142   else
143   AC_MSG_CHECKING([for _ prefix in compiled symbols])
144   fi
145 AC_MSG_RESULT($ac_cv_sys_symbol_underscore)
146 if test x$ac_cv_sys_symbol_underscore = xyes; then
147   AC_DEFINE(WITH_SYMBOL_UNDERSCORE,1,
148             [Defined if compiled symbols have a leading underscore])
149 fi
150 ])
151
152
153 ######################################################################
154 # Check whether mlock is broken (hpux 10.20 raises a SIGBUS if mlock
155 # is not called from uid 0 (not tested whether uid 0 works)
156 # For DECs Tru64 we have also to check whether mlock is in librt
157 # mlock is there a macro using memlk()
158 ######################################################################
159 dnl GNUPG_CHECK_MLOCK
160 dnl
161 define(GNUPG_CHECK_MLOCK,
162   [ AC_CHECK_FUNCS(mlock)
163     if test "$ac_cv_func_mlock" = "no"; then
164         AC_CHECK_HEADERS(sys/mman.h)
165         if test "$ac_cv_header_sys_mman_h" = "yes"; then
166             # Add librt to LIBS:
167             AC_CHECK_LIB(rt, memlk)
168             AC_CACHE_CHECK([whether mlock is in sys/mman.h],
169                             gnupg_cv_mlock_is_in_sys_mman,
170                 [AC_TRY_LINK([
171                     #include <assert.h>
172                     #ifdef HAVE_SYS_MMAN_H
173                     #include <sys/mman.h>
174                     #endif
175                 ], [
176                     int i;
177                     
178                     /* glibc defines this for functions which it implements
179                      * to always fail with ENOSYS.  Some functions are actually
180                      * named something starting with __ and the normal name
181                      * is an alias.  */
182                     #if defined (__stub_mlock) || defined (__stub___mlock)
183                     choke me
184                     #else
185                     mlock(&i, 4);
186                     #endif
187                     ; return 0;
188                 ],
189                 gnupg_cv_mlock_is_in_sys_mman=yes,
190                 gnupg_cv_mlock_is_in_sys_mman=no)])
191             if test "$gnupg_cv_mlock_is_in_sys_mman" = "yes"; then
192                 AC_DEFINE(HAVE_MLOCK,1,
193                           [Defined if the system supports an mlock() call])
194             fi
195         fi
196     fi
197     if test "$ac_cv_func_mlock" = "yes"; then
198         AC_MSG_CHECKING(whether mlock is broken)
199           AC_CACHE_VAL(gnupg_cv_have_broken_mlock,
200              AC_TRY_RUN([
201                 #include <stdlib.h>
202                 #include <unistd.h>
203                 #include <errno.h>
204                 #include <sys/mman.h>
205                 #include <sys/types.h>
206                 #include <fcntl.h>
207
208                 int main()
209                 {
210                     char *pool;
211                     int err;
212                     long int pgsize = getpagesize();
213
214                     pool = malloc( 4096 + pgsize );
215                     if( !pool )
216                         return 2;
217                     pool += (pgsize - ((long int)pool % pgsize));
218
219                     err = mlock( pool, 4096 );
220                     if( !err || errno == EPERM )
221                         return 0; /* okay */
222
223                     return 1;  /* hmmm */
224                 }
225
226             ],
227             gnupg_cv_have_broken_mlock="no",
228             gnupg_cv_have_broken_mlock="yes",
229             gnupg_cv_have_broken_mlock="assume-no"
230            )
231          )
232          if test "$gnupg_cv_have_broken_mlock" = "yes"; then
233              AC_DEFINE(HAVE_BROKEN_MLOCK,1,
234                        [Defined if the mlock() call does not work])
235              AC_MSG_RESULT(yes)
236          else
237             if test "$gnupg_cv_have_broken_mlock" = "no"; then
238                 AC_MSG_RESULT(no)
239             else
240                 AC_MSG_RESULT(assuming no)
241             fi
242          fi
243     fi
244   ])
245
246 # GNUPG_SYS_LIBTOOL_CYGWIN32 - find tools needed on cygwin32
247 AC_DEFUN([GNUPG_SYS_LIBTOOL_CYGWIN32],
248 [AC_CHECK_TOOL(DLLTOOL, dlltool, false)
249 AC_CHECK_TOOL(AS, as, false)
250 ])
251
252 dnl LIST_MEMBER()
253 dnl Check wether an element ist contained in a list.  Set `found' to
254 dnl `1' if the element is found in the list, to `0' otherwise.
255 AC_DEFUN([LIST_MEMBER],
256 [
257 name=$1
258 list=$2
259 found=0
260
261 for n in $list; do
262   if test "x$name" = "x$n"; then
263     found=1
264   fi
265 done
266 ])
267
268 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
269 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
270 dnl Test for libgpg-error and define GPG_ERROR_CFLAGS and GPG_ERROR_LIBS
271 dnl
272 AC_DEFUN([AM_PATH_GPG_ERROR],
273 [ AC_ARG_WITH(gpg-error-prefix,
274             AC_HELP_STRING([--with-gpg-error-prefix=PFX],
275                            [prefix where GPG Error is installed (optional)]),
276      gpg_error_config_prefix="$withval", gpg_error_config_prefix="")
277   if test x$gpg_error_config_prefix != x ; then
278      if test x${GPG_ERROR_CONFIG+set} != xset ; then
279         GPG_ERROR_CONFIG=$gpg_error_config_prefix/bin/gpg-error-config
280      fi
281   fi
282
283   AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no)
284   min_gpg_error_version=ifelse([$1], ,0.0,$1)
285   AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
286   ok=no
287   if test "$GPG_ERROR_CONFIG" != "no" ; then
288     req_major=`echo $min_gpg_error_version | \
289                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
290     req_minor=`echo $min_gpg_error_version | \
291                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
292     gpg_error_config_version=`$GPG_ERROR_CONFIG $gpg_error_config_args --version`
293     if test "$gpg_error_config_version"; then
294       major=`echo $gpg_error_config_version | \
295                  sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
296       minor=`echo $gpg_error_config_version | \
297                  sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
298       if test "$major" -gt "$req_major"; then
299           ok=yes
300       else 
301           if test "$major" -eq "$req_major"; then
302               if test "$minor" -ge "$req_minor"; then
303                  ok=yes
304               fi
305           fi
306       fi
307     fi
308   fi
309   if test $ok = yes; then
310     GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG $gpg_error_config_args --cflags`
311     GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG $gpg_error_config_args --libs`
312     AC_MSG_RESULT(yes)
313     ifelse([$2], , :, [$2])
314   else
315     GPG_ERROR_CFLAGS=""
316     GPG_ERROR_LIBS=""
317     AC_MSG_RESULT(no)
318     ifelse([$3], , :, [$3])
319   fi
320   AC_SUBST(GPG_ERROR_CFLAGS)
321   AC_SUBST(GPG_ERROR_LIBS)
322 ])
323
324 dnl ##
325 dnl ##  GNU Pth - The GNU Portable Threads
326 dnl ##  Copyright (c) 1999-2002 Ralf S. Engelschall <rse@engelschall.com>
327 dnl ##
328 dnl ##  This file is part of GNU Pth, a non-preemptive thread scheduling
329 dnl ##  library which can be found at http://www.gnu.org/software/pth/.
330 dnl ##
331 dnl ##  This library is free software; you can redistribute it and/or
332 dnl ##  modify it under the terms of the GNU Lesser General Public
333 dnl ##  License as published by the Free Software Foundation; either
334 dnl ##  version 2.1 of the License, or (at your option) any later version.
335 dnl ##
336 dnl ##  This library is distributed in the hope that it will be useful,
337 dnl ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
338 dnl ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
339 dnl ##  Lesser General Public License for more details.
340 dnl ##
341 dnl ##  You should have received a copy of the GNU Lesser General Public
342 dnl ##  License along with this library; if not, write to the Free Software
343 dnl ##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
344 dnl ##  USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
345 dnl ##
346 dnl ##  pth.m4: Autoconf macro for locating GNU Pth from within
347 dnl ##          configure.in of third-party software packages
348 dnl ##
349
350 dnl ##
351 dnl ##  Synopsis:
352 dnl ##  AC_CHECK_PTH([MIN-VERSION [,          # minimum Pth version, e.g. 1.2.0
353 dnl ##                DEFAULT-WITH-PTH [,     # default value for --with-pth option
354 dnl ##                DEFAULT-WITH-PTH-TEST [,# default value for --with-pth-test option
355 dnl ##                EXTEND-VARS [,          # whether CFLAGS/LDFLAGS/etc are extended
356 dnl ##                ACTION-IF-FOUND [,      # action to perform if Pth was found
357 dnl ##                ACTION-IF-NOT-FOUND     # action to perform if Pth was not found
358 dnl ##                ]]]]]])
359 dnl ##  Examples:
360 dnl ##  AC_CHECK_PTH(1.2.0)
361 dnl ##  AC_CHECK_PTH(1.2.0,,,no,CFLAGS="$CFLAGS -DHAVE_PTH $PTH_CFLAGS")
362 dnl ##  AC_CHECK_PTH(1.2.0,yes,yes,yes,CFLAGS="$CFLAGS -DHAVE_PTH")
363 dnl ##
364 dnl
365 dnl #   auxilliary macros
366 AC_DEFUN([_AC_PTH_ERROR], [dnl
367 AC_MSG_RESULT([*FAILED*])
368 dnl define(_ac_pth_line,dnl
369 dnl "+------------------------------------------------------------------------+")
370 dnl echo " _ac_pth_line" 1>&2
371 cat <<EOT | sed -e 's/^[[       ]]*/ | /' -e 's/>>/  /' 1>&2
372 $1
373 EOT
374 dnl echo " _ac_pth_line" 1>&2
375 dnl undefine(_ac_pth_line)
376 exit 1
377 ])
378 AC_DEFUN([_AC_PTH_VERBOSE], [dnl
379 if test ".$verbose" = .yes; then
380     AC_MSG_RESULT([  $1])
381 fi
382 ])
383 dnl #   the user macro
384 AC_DEFUN([AC_CHECK_PTH], [dnl
385 dnl
386 dnl #   prerequisites
387 AC_REQUIRE([AC_PROG_CC])dnl
388 AC_REQUIRE([AC_PROG_CPP])dnl
389 dnl
390 PTH_CPPFLAGS=''
391 PTH_CFLAGS=''
392 PTH_LDFLAGS=''
393 PTH_LIBS=''
394 AC_SUBST(PTH_CPPFLAGS)
395 AC_SUBST(PTH_CFLAGS)
396 AC_SUBST(PTH_LDFLAGS)
397 AC_SUBST(PTH_LIBS)
398 dnl #   command line options
399 AC_MSG_CHECKING(for GNU Pth)
400 _AC_PTH_VERBOSE([])
401 AC_ARG_WITH(pth,dnl
402 [  --with-pth[=ARG]        Build with GNU Pth Library  (default=]ifelse([$2],,yes,$2)[)],dnl
403 ,dnl
404 with_pth="ifelse([$2],,yes,$2)"
405 )dnl
406 AC_ARG_WITH(pth-test,dnl
407 [  --with-pth-test         Perform GNU Pth Sanity Test (default=]ifelse([$3],,yes,$3)[)],dnl
408 ,dnl
409 with_pth_test="ifelse([$3],,yes,$3)"
410 )dnl
411 _AC_PTH_VERBOSE([+ Command Line Options:])
412 _AC_PTH_VERBOSE([    o --with-pth=$with_pth])
413 _AC_PTH_VERBOSE([    o --with-pth-test=$with_pth_test])
414 dnl
415 dnl #   configuration
416 if test ".$with_pth" != .no; then
417     _pth_subdir=no
418     _pth_subdir_opts=''
419     case "$with_pth" in
420         subdir:* )
421             _pth_subdir=yes
422             changequote(, )dnl
423             _pth_subdir_opts=`echo $with_pth | sed -e 's/^subdir:[^     ]*[     ]*//'`
424             with_pth=`echo $with_pth | sed -e 's/^subdir:\([^   ]*\).*$/\1/'`
425             changequote([, ])dnl
426             ;;
427     esac
428     _pth_version=""
429     _pth_location=""
430     _pth_type=""
431     _pth_cppflags=""
432     _pth_cflags=""
433     _pth_ldflags=""
434     _pth_libs=""
435     if test ".$with_pth" = .yes; then
436         #   via config script in $PATH
437         changequote(, )dnl
438         _pth_version=`(pth-config --version) 2>/dev/null |\
439                       sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
440         changequote([, ])dnl
441         if test ".$_pth_version" != .; then
442             _pth_location=`pth-config --prefix`
443             _pth_type='installed'
444             _pth_cppflags=`pth-config --cflags`
445             _pth_cflags=`pth-config --cflags`
446             _pth_ldflags=`pth-config --ldflags`
447             _pth_libs=`pth-config --libs`
448         fi
449     elif test -d "$with_pth"; then
450         with_pth=`echo $with_pth | sed -e 's;/*$;;'`
451         _pth_found=no
452         #   via locally included source tree
453         if test ".$_pth_subdir" = .yes; then
454             _pth_location="$with_pth"
455             _pth_type='local'
456             _pth_cppflags="-I$with_pth"
457             _pth_cflags="-I$with_pth"
458             if test -f "$with_pth/ltconfig"; then
459                 _pth_ldflags="-L$with_pth/.libs"
460             else
461                 _pth_ldflags="-L$with_pth"
462             fi
463             _pth_libs="-lpth"
464             changequote(, )dnl
465             _pth_version=`grep '^const char PTH_Hello' $with_pth/pth_vers.c |\
466                           sed -e 's;^.*Version[         ]*\([0-9]*\.[0-9]*[.ab][0-9]*\)[        ].*$;\1;'`
467             changequote([, ])dnl
468             _pth_found=yes
469             ac_configure_args="$ac_configure_args --enable-subdir $_pth_subdir_opts"
470             with_pth_test=no
471         fi
472         #   via config script under a specified directory
473         #   (a standard installation, but not a source tree)
474         if test ".$_pth_found" = .no; then
475             for _dir in $with_pth/bin $with_pth; do
476                 if test -f "$_dir/pth-config"; then
477                     test -f "$_dir/pth-config.in" && continue # pth-config in source tree!
478                     changequote(, )dnl
479                     _pth_version=`($_dir/pth-config --version) 2>/dev/null |\
480                                   sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
481                     changequote([, ])dnl
482                     if test ".$_pth_version" != .; then
483                         _pth_location=`$_dir/pth-config --prefix`
484                         _pth_type="installed"
485                         _pth_cppflags=`$_dir/pth-config --cflags`
486                         _pth_cflags=`$_dir/pth-config --cflags`
487                         _pth_ldflags=`$_dir/pth-config --ldflags`
488                         _pth_libs=`$_dir/pth-config --libs`
489                         _pth_found=yes
490                         break
491                     fi
492                 fi
493             done
494         fi
495         #   in any subarea under a specified directory
496         #   (either a special installation or a Pth source tree)
497         if test ".$_pth_found" = .no; then
498             changequote(, )dnl
499             _pth_found=0
500             for _file in x `find $with_pth -name "pth.h" -type f -print`; do
501                 test .$_file = .x && continue
502                 _dir=`echo $_file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
503                 _pth_version=`($_dir/pth-config --version) 2>/dev/null |\
504                               sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
505                 if test ".$_pth_version" = .; then
506                     _pth_version=`grep '^#define PTH_VERSION_STR' $_file |\
507                                   sed -e 's;^#define[   ]*PTH_VERSION_STR[      ]*"\([0-9]*\.[0-9]*[.ab][0-9]*\)[       ].*$;\1;'`
508                 fi
509                 _pth_cppflags="-I$_dir"
510                 _pth_cflags="-I$_dir"
511                 _pth_found=`expr $_pth_found + 1`
512             done
513             for _file in x `find $with_pth -name "libpth.[aso]" -type f -print`; do
514                 test .$_file = .x && continue
515                 _dir=`echo $_file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
516                 _pth_ldflags="-L$_dir"
517                 _pth_libs="-lpth"
518                 _pth_found=`expr $_pth_found + 1`
519             done
520             changequote([, ])dnl
521             if test ".$_pth_found" = .2; then
522                 _pth_location="$with_pth"
523                 _pth_type="uninstalled"
524             else
525                 _pth_version=''
526             fi
527         fi
528     fi
529     _AC_PTH_VERBOSE([+ Determined Location:])
530     _AC_PTH_VERBOSE([    o path: $_pth_location])
531     _AC_PTH_VERBOSE([    o type: $_pth_type])
532     if test ".$_pth_version" = .; then
533         with_pth=no
534     else
535 dnl        if test ".$with_pth" != .yes; then
536 dnl             _AC_PTH_ERROR([dnl
537 dnl             Unable to locate GNU Pth under $with_pth.
538 dnl             Please specify the correct path to either a GNU Pth installation tree
539 dnl             (use --with-pth=DIR if you used --prefix=DIR for installing GNU Pth in
540 dnl             the past) or to a GNU Pth source tree (use --with-pth=DIR if DIR is a
541 dnl             path to a pth-X.Y.Z/ directory; but make sure the package is already
542 dnl             built, i.e., the "configure; make" step was already performed there).])
543 dnl        else
544 dnl             _AC_PTH_ERROR([dnl
545 dnl             Unable to locate GNU Pth in any system-wide location (see \$PATH).
546 dnl             Please specify the correct path to either a GNU Pth installation tree
547 dnl             (use --with-pth=DIR if you used --prefix=DIR for installing GNU Pth in
548 dnl             the past) or to a GNU Pth source tree (use --with-pth=DIR if DIR is a
549 dnl             path to a pth-X.Y.Z/ directory; but make sure the package is already
550 dnl             built, i.e., the "configure; make" step was already performed there).])
551 dnl        fi
552 dnl    fi
553     dnl #
554     dnl #  Check whether the found version is sufficiently new
555     dnl #
556     _req_version="ifelse([$1],,1.0.0,$1)"
557     for _var in _pth_version _req_version; do
558         eval "_val=\"\$${_var}\""
559         _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
560         _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
561         _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
562         _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
563         case $_rtype in
564             "a" ) _rtype=0 ;;
565             "b" ) _rtype=1 ;;
566             "." ) _rtype=2 ;;
567         esac
568         _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
569               "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
570         eval "${_var}_hex=\"\$_hex\""
571     done
572     _AC_PTH_VERBOSE([+ Determined Versions:])
573     _AC_PTH_VERBOSE([    o existing: $_pth_version -> 0x$_pth_version_hex])
574     _AC_PTH_VERBOSE([    o required: $_req_version -> 0x$_req_version_hex])
575     _ok=0
576     if test ".$_pth_version_hex" != .; then
577         if test ".$_req_version_hex" != .; then
578             if test $_pth_version_hex -ge $_req_version_hex; then
579                 _ok=1
580             fi
581         fi
582     fi
583     if test ".$_ok" = .0; then
584         _AC_PTH_ERROR([dnl
585         Found Pth version $_pth_version, but required at least version $_req_version.
586         Upgrade Pth under $_pth_location to $_req_version or higher first, please.])
587     fi
588     dnl #
589     dnl #   Perform Pth Sanity Compile Check
590     dnl #
591     if test ".$with_pth_test" = .yes; then
592         _ac_save_CPPFLAGS="$CPPFLAGS"
593         _ac_save_CFLAGS="$CFLAGS"
594         _ac_save_LDFLAGS="$LDFLAGS"
595         _ac_save_LIBS="$LIBS"
596         CPPFLAGS="$CPPFLAGS $_pth_cppflags"
597         CFLAGS="$CFLAGS $_pth_cflags"
598         LDFLAGS="$LDFLAGS $_pth_ldflags"
599         LIBS="$LIBS $_pth_libs"
600         _AC_PTH_VERBOSE([+ Test Build Environment:])
601         _AC_PTH_VERBOSE([    o CPPFLAGS=\"$CPPFLAGS\"])
602         _AC_PTH_VERBOSE([    o CFLAGS=\"$CFLAGS\"])
603         _AC_PTH_VERBOSE([    o LDFLAGS=\"$LDFLAGS\"])
604         _AC_PTH_VERBOSE([    o LIBS=\"$LIBS\"])
605         cross_compile=no
606         define(_code1, [dnl
607         #include <stdio.h>
608         #include <pth.h>
609         ])
610         define(_code2, [dnl
611         int main(int argc, char *argv[])
612         {
613             FILE *fp;
614             if (!(fp = fopen("conftestval", "w")))
615                 exit(1);
616             fprintf(fp, "hmm");
617             fclose(fp);
618             pth_init();
619             pth_kill();
620             if (!(fp = fopen("conftestval", "w")))
621                 exit(1);
622             fprintf(fp, "yes");
623             fclose(fp);
624             exit(0);
625         }
626         ])
627         _AC_PTH_VERBOSE([+ Performing Sanity Checks:])
628         _AC_PTH_VERBOSE([    o pre-processor test])
629         AC_TRY_CPP(_code1, _ok=yes, _ok=no)
630         if test ".$_ok" != .yes; then
631             _AC_PTH_ERROR([dnl
632             Found GNU Pth $_pth_version under $_pth_location, but
633             was unable to perform a sanity pre-processor check. This means
634             the GNU Pth header pth.h was not found.
635             We used the following build environment:
636             >> CPP="$CPP"
637             >> CPPFLAGS="$CPPFLAGS"
638             See config.log for possibly more details.])
639         fi
640         _AC_PTH_VERBOSE([    o link check])
641         AC_TRY_LINK(_code1, _code2, _ok=yes, _ok=no)
642         if test ".$_ok" != .yes; then
643             _AC_PTH_ERROR([dnl
644             Found GNU Pth $_pth_version under $_pth_location, but
645             was unable to perform a sanity linker check. This means
646             the GNU Pth library libpth.a was not found.
647             We used the following build environment:
648             >> CC="$CC"
649             >> CFLAGS="$CFLAGS"
650             >> LDFLAGS="$LDFLAGS"
651             >> LIBS="$LIBS"
652             See config.log for possibly more details.])
653         fi
654         _AC_PTH_VERBOSE([    o run-time check])
655         AC_TRY_RUN(_code1 _code2, _ok=`cat conftestval`, _ok=no, _ok=no)
656         if test ".$_ok" != .yes; then
657             if test ".$_ok" = .no; then
658                 _AC_PTH_ERROR([dnl
659                 Found GNU Pth $_pth_version under $_pth_location, but
660                 was unable to perform a sanity execution check. This usually
661                 means that the GNU Pth shared library libpth.so is present
662                 but \$LD_LIBRARY_PATH is incomplete to execute a Pth test.
663                 In this case either disable this test via --without-pth-test,
664                 or extend \$LD_LIBRARY_PATH, or build GNU Pth as a static
665                 library only via its --disable-shared Autoconf option.
666                 We used the following build environment:
667                 >> CC="$CC"
668                 >> CFLAGS="$CFLAGS"
669                 >> LDFLAGS="$LDFLAGS"
670                 >> LIBS="$LIBS"
671                 See config.log for possibly more details.])
672             else
673                 _AC_PTH_ERROR([dnl
674                 Found GNU Pth $_pth_version under $_pth_location, but
675                 was unable to perform a sanity run-time check. This usually
676                 means that the GNU Pth library failed to work and possibly
677                 caused a core dump in the test program. In this case it
678                 is strongly recommended that you re-install GNU Pth and this
679                 time make sure that it really passes its "make test" procedure.
680                 We used the following build environment:
681                 >> CC="$CC"
682                 >> CFLAGS="$CFLAGS"
683                 >> LDFLAGS="$LDFLAGS"
684                 >> LIBS="$LIBS"
685                 See config.log for possibly more details.])
686             fi
687         fi
688         _extendvars="ifelse([$4],,yes,$4)"
689         if test ".$_extendvars" != .yes; then
690             CPPFLAGS="$_ac_save_CPPFLAGS"
691             CFLAGS="$_ac_save_CFLAGS"
692             LDFLAGS="$_ac_save_LDFLAGS"
693             LIBS="$_ac_save_LIBS"
694         fi
695     else
696         _extendvars="ifelse([$4],,yes,$4)"
697         if test ".$_extendvars" = .yes; then
698             if test ".$_pth_subdir" = .yes; then
699                 CPPFLAGS="$CPPFLAGS $_pth_cppflags"
700                 CFLAGS="$CFLAGS $_pth_cflags"
701                 LDFLAGS="$LDFLAGS $_pth_ldflags"
702                 LIBS="$LIBS $_pth_libs"
703             fi
704         fi
705     fi
706     PTH_CPPFLAGS="$_pth_cppflags"
707     PTH_CFLAGS="$_pth_cflags"
708     PTH_LDFLAGS="$_pth_ldflags"
709     PTH_LIBS="$_pth_libs"
710     AC_SUBST(PTH_CPPFLAGS)
711     AC_SUBST(PTH_CFLAGS)
712     AC_SUBST(PTH_LDFLAGS)
713     AC_SUBST(PTH_LIBS)
714     _AC_PTH_VERBOSE([+ Final Results:])
715     _AC_PTH_VERBOSE([    o PTH_CPPFLAGS=\"$PTH_CPPFLAGS\"])
716     _AC_PTH_VERBOSE([    o PTH_CFLAGS=\"$PTH_CFLAGS\"])
717     _AC_PTH_VERBOSE([    o PTH_LDFLAGS=\"$PTH_LDFLAGS\"])
718     _AC_PTH_VERBOSE([    o PTH_LIBS=\"$PTH_LIBS\"])
719 fi
720 fi
721 if test ".$with_pth" != .no; then
722     AC_MSG_RESULT([version $_pth_version, $_pth_type under $_pth_location])
723     ifelse([$5], , :, [$5])
724 else
725     AC_MSG_RESULT([no])
726     ifelse([$6], , :, [$6])
727 fi
728 ])
729
730 dnl Check for socklen_t: historically on BSD it is an int, and in
731 dnl POSIX 1g it is a type of its own, but some platforms use different
732 dnl types for the argument to getsockopt, getpeername, etc.  So we
733 dnl have to test to find something that will work.
734 AC_DEFUN([TYPE_SOCKLEN_T],
735 [
736    AC_CHECK_TYPE([socklen_t], ,[
737       AC_MSG_CHECKING([for socklen_t equivalent])
738       AC_CACHE_VAL([socklen_t_equiv],
739       [
740          # Systems have either "struct sockaddr *" or
741          # "void *" as the second argument to getpeername
742          socklen_t_equiv=
743          for arg2 in "struct sockaddr" void; do
744             for t in int size_t unsigned long "unsigned long"; do
745                AC_TRY_COMPILE([
746                   #include <sys/types.h>
747                   #include <sys/socket.h>
748
749                   int getpeername (int, $arg2 *, $t *);
750                ],[
751                   $t len;
752                   getpeername(0,0,&len);
753                ],[
754                   socklen_t_equiv="$t"
755                   break
756                ])
757             done
758          done
759
760          if test "x$socklen_t_equiv" = x; then
761             AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
762          fi
763       ])
764       AC_MSG_RESULT($socklen_t_equiv)
765       AC_DEFINE_UNQUOTED(socklen_t, $socklen_t_equiv,
766                         [type to use in place of socklen_t if not defined])],
767       [#include <sys/types.h>
768 #include <sys/socket.h>])
769 ])