Try various different types as replacements for socklen_t until we
[rsync/rsync.git] / aclocal.m4
1 dnl AC_VALIDATE_CACHE_SYSTEM_TYPE[(cmd)]
2 dnl if the cache file is inconsistent with the current host,
3 dnl target and build system types, execute CMD or print a default
4 dnl error message.
5 AC_DEFUN(AC_VALIDATE_CACHE_SYSTEM_TYPE, [
6     AC_REQUIRE([AC_CANONICAL_SYSTEM])
7     AC_MSG_CHECKING([config.cache system type])
8     if { test x"${ac_cv_host_system_type+set}" = x"set" &&
9          test x"$ac_cv_host_system_type" != x"$host"; } ||
10        { test x"${ac_cv_build_system_type+set}" = x"set" &&
11          test x"$ac_cv_build_system_type" != x"$build"; } ||
12        { test x"${ac_cv_target_system_type+set}" = x"set" &&
13          test x"$ac_cv_target_system_type" != x"$target"; }; then
14         AC_MSG_RESULT([different])
15         ifelse($#, 1, [$1],
16                 [AC_MSG_ERROR(["you must remove config.cache and restart configure"])])
17     else
18         AC_MSG_RESULT([same])
19     fi
20     ac_cv_host_system_type="$host"
21     ac_cv_build_system_type="$build"
22     ac_cv_target_system_type="$target"
23 ])
24
25 #serial 12
26
27 dnl By default, many hosts won't let programs access large files;
28 dnl one must use special compiler options to get large-file access to work.
29 dnl For more details about this brain damage please see:
30 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
31
32 dnl Written by Paul Eggert <eggert@twinsun.com>.
33
34 dnl Internal subroutine of AC_SYS_LARGEFILE.
35 dnl AC_SYS_LARGEFILE_TEST_INCLUDES
36 AC_DEFUN(AC_SYS_LARGEFILE_TEST_INCLUDES,
37   [[#include <sys/types.h>
38     int a[(off_t) 9223372036854775807 == 9223372036854775807 ? 1 : -1];
39   ]])
40
41 dnl Internal subroutine of AC_SYS_LARGEFILE.
42 dnl AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR, COMMENT, INCLUDES, FUNCTION-BODY)
43 AC_DEFUN([AC_SYS_LARGEFILE_MACRO_VALUE],
44   [AC_CACHE_CHECK([for $1 value needed for large files], $3,
45      [$3=no
46       AC_TRY_COMPILE(AC_SYS_LARGEFILE_TEST_INCLUDES
47 $5
48         ,
49         [$6],
50         ,
51         [AC_TRY_COMPILE([#define $1 $2]
52 AC_SYS_LARGEFILE_TEST_INCLUDES
53 $5
54            ,
55            [$6],
56            [$3=$2])])])
57    if test "[$]$3" != no; then
58      AC_DEFINE_UNQUOTED([$1], [$]$3, [$4])
59    fi])
60
61 AC_DEFUN([AC_SYS_LARGEFILE],
62   [AC_ARG_ENABLE(largefile,
63      [  --disable-largefile     omit support for large files])
64    if test "$enable_largefile" != no; then
65
66      AC_CACHE_CHECK([for special C compiler options needed for large files],
67        ac_cv_sys_largefile_CC,
68        [ac_cv_sys_largefile_CC=no
69         if test "$GCC" != yes; then
70           # IRIX 6.2 and later do not support large files by default,
71           # so use the C compiler's -n32 option if that helps.
72           AC_TRY_COMPILE(AC_SYS_LARGEFILE_TEST_INCLUDES, , ,
73             [ac_save_CC="$CC"
74              CC="$CC -n32"
75              AC_TRY_COMPILE(AC_SYS_LARGEFILE_TEST_INCLUDES, ,
76                ac_cv_sys_largefile_CC=' -n32')
77              CC="$ac_save_CC"])
78         fi])
79      if test "$ac_cv_sys_largefile_CC" != no; then
80        CC="$CC$ac_cv_sys_largefile_CC"
81      fi
82
83      AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
84        ac_cv_sys_file_offset_bits,
85        [Number of bits in a file offset, on hosts where this is settable.])
86      AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE, 1,
87        ac_cv_sys_largefile_source,
88        [Define to make ftello visible on some hosts (e.g. HP-UX 10.20).],
89        [#include <stdio.h>], [return !ftello;])
90      AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1,
91        ac_cv_sys_large_files,
92        [Define for large files, on AIX-style hosts.])
93      AC_SYS_LARGEFILE_MACRO_VALUE(_XOPEN_SOURCE, 500,
94        ac_cv_sys_xopen_source,
95        [Define to make ftello visible on some hosts (e.g. glibc 2.1.3).],
96        [#include <stdio.h>], [return !ftello;])
97    fi
98   ])
99
100 dnl Check for socklen_t: historically on BSD it is an int, and in
101 dnl POSIX 1g it is a type of its own, but some platforms use different
102 dnl types for the argument to getsockopt, getpeername, etc.  So we
103 dnl have to test to find something that will work.
104
105 dnl This test originally comes from lftp, by way of Albert Chin at The
106 dnl Written Word.  Thanks!
107
108 AC_DEFUN([TYPE_SOCKLEN_T],
109 [
110    AC_MSG_CHECKING([for socklen_t])
111    AC_CACHE_VAL([lftp_cv_socklen_t],
112    [
113       lftp_cv_socklen_t=no
114       AC_TRY_COMPILE([
115          #include <sys/types.h>
116          #include <sys/socket.h>
117       ],
118       [
119          socklen_t len;
120          getpeername(0,0,&len);
121       ],
122       [
123          lftp_cv_socklen_t=yes
124       ])
125    ])
126    AC_MSG_RESULT($lftp_cv_socklen_t)
127    if test $lftp_cv_socklen_t = no; then
128       AC_MSG_CHECKING([for socklen_t equivalent])
129       AC_CACHE_VAL([lftp_cv_socklen_t_equiv],
130       [
131          lftp_cv_socklen_t_equiv=int
132          AC_LANG_SAVE
133          for t in int size_t unsigned long "unsigned long"; do
134             AC_TRY_COMPILE([
135                #include <sys/types.h>
136                #include <sys/socket.h>
137             ],
138             [
139                $t len;
140                getpeername(0,0,&len);
141             ],
142             [
143                lftp_cv_socklen_t_equiv="$t"
144                break
145             ])
146          done
147       ])
148       AC_MSG_RESULT($lftp_cv_socklen_t_equiv)
149       AC_DEFINE_UNQUOTED(socklen_t, $lftp_cv_socklen_t_equiv,
150                         [type to use in place of socklen_t if not defined])
151    fi
152 ])
153