configure.ac: Test IPv6 compatibility instead of relying on library probes (#206)
[rsync.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2
3 AC_INIT([rsync],[ ],[https://rsync.samba.org/bug-tracking.html])
4
5 AC_C_BIGENDIAN
6 AC_HEADER_DIRENT
7 AC_HEADER_TIME
8 AC_HEADER_SYS_WAIT
9 AC_CHECK_HEADERS(sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h \
10     unistd.h utime.h compat.h sys/param.h ctype.h sys/wait.h sys/stat.h \
11     sys/ioctl.h sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h grp.h \
12     sys/un.h sys/attr.h arpa/inet.h arpa/nameser.h locale.h sys/types.h \
13     netdb.h malloc.h float.h limits.h iconv.h libcharset.h langinfo.h mcheck.h \
14     sys/acl.h acl/libacl.h attr/xattr.h sys/xattr.h sys/extattr.h dl.h \
15     popt.h popt/popt.h linux/falloc.h netinet/in_systm.h netgroup.h \
16     zlib.h xxhash.h openssl/md4.h openssl/md5.h zstd.h lz4.h sys/file.h)
17 AC_CHECK_HEADERS([netinet/ip.h], [], [], [[#include <netinet/in.h>]])
18 AC_HEADER_MAJOR_FIXED
19
20 AC_CONFIG_MACRO_DIR([m4])
21 AC_CONFIG_SRCDIR([byteorder.h])
22 AC_CONFIG_HEADER(config.h)
23 AC_PREREQ([2.69])
24
25 PACKAGE_VERSION=`sed 's/.*"\(.*\)".*/\1/' <$srcdir/version.h`
26
27 AC_MSG_NOTICE([Configuring rsync $PACKAGE_VERSION])
28
29 LDFLAGS=${LDFLAGS-""}
30
31 AC_CANONICAL_HOST
32
33 dnl define the directory for replacement function since AC_LIBOBJ does not
34 dnl officially support subdirs and fails with automake
35 AC_CONFIG_LIBOBJ_DIR([lib])
36
37 # We must decide this before testing the compiler.
38
39 # Please allow this to default to yes, so that your users have more
40 # chance of getting a useful stack trace if problems occur.
41
42 AC_MSG_CHECKING([whether to include debugging symbols])
43 AC_ARG_ENABLE(debug,
44         AS_HELP_STRING([--disable-debug],[disable debugging symbols and features]))
45
46 if test x"$enable_debug" = x"no"; then
47     AC_MSG_RESULT(no)
48     ac_cv_prog_cc_g=no
49 else
50     AC_MSG_RESULT([yes])
51     dnl AC_DEFINE(DEBUG, 1, [Define to turn on debugging code that may slow normal operation])
52     # leave ac_cv_prog_cc_g alone; AC_PROG_CC will try to include -g if it can
53 fi
54
55 dnl Checks for programs.
56 AC_PROG_CC
57 AC_PROG_CPP
58 AC_PROG_CXX
59 AC_PROG_AWK
60 AC_PROG_EGREP
61 AC_PROG_INSTALL
62 AC_PROG_MKDIR_P
63 AC_PROG_CC_STDC
64 AC_SUBST(SHELL)
65 AC_PATH_PROG([PERL], [perl])
66 AC_PATH_PROG([PYTHON3], [python3])
67
68 AC_DEFINE([_GNU_SOURCE], 1,
69           [Define _GNU_SOURCE so that we get all necessary prototypes])
70
71 if test x"$ac_cv_prog_cc_stdc" = x"no"; then
72         AC_MSG_WARN([rsync requires an ANSI C compiler and you do not seem to have one])
73 fi
74
75 no_lib=''
76 err_msg=''
77 nl='
78 '
79
80 AC_ARG_ENABLE(profile,
81         AS_HELP_STRING([--enable-profile],[turn on CPU profiling]))
82 if test x"$enable_profile" = x"yes"; then
83         CFLAGS="$CFLAGS -pg"
84 fi
85
86 AC_MSG_CHECKING([if md2man can create man pages])
87 if test x"$ac_cv_path_PYTHON3" = x; then
88     AC_MSG_RESULT(no - python3 not found)
89     md2man_works=no
90 else
91     md2man_out=`"$srcdir/md2man" --test "$srcdir/rsync-ssl.1.md" 2>&1`
92     if test $? = 0; then
93         AC_MSG_RESULT(yes)
94         md2man_works=yes
95     else
96         AC_MSG_RESULT(no)
97         md2man_works=no
98         echo "$md2man_out"
99     fi
100 fi
101
102 AC_MSG_CHECKING([if we require man-page building])
103 AC_ARG_ENABLE([md2man],
104         AS_HELP_STRING([--disable-md2man],[disable md2man for man page creation]))
105 if test x"$enable_md2man" != x"no"; then
106     if test -f "$srcdir/rsync.1"; then
107         AC_MSG_RESULT(optional)
108     else
109         AC_MSG_RESULT(required)
110         if test x"$md2man_works" = x"no"; then
111             err_msg="$err_msg$nl- You need python3 and either the cmarkgfm OR commonmark python3 lib in order"
112             err_msg="$err_msg$nl  to build man pages based on the git source (man pages are included in the"
113             err_msg="$err_msg$nl  official release tar files)."
114             no_lib="$no_lib md2man"
115         fi
116     fi
117     MAKE_MAN=man
118 else
119     AC_MSG_RESULT(no)
120     MAKE_MAN=''
121 fi
122
123 # Specifically, this turns on panic_action handling.
124 AC_ARG_ENABLE(maintainer-mode,
125         AS_HELP_STRING([--enable-maintainer-mode],[turn on extra debug features]))
126 if test x"$enable_maintainer_mode" = x"yes"; then
127         CFLAGS="$CFLAGS -DMAINTAINER_MODE"
128 fi
129
130 # This is needed for our included version of popt.  Kind of silly, but
131 # I don't want our version too far out of sync.
132 CFLAGS="$CFLAGS -DHAVE_CONFIG_H"
133
134 # If GCC, turn on warnings.
135 if test x"$GCC" = x"yes"; then
136         CFLAGS="$CFLAGS -Wall -W"
137 fi
138
139 AC_ARG_WITH(included-popt,
140         AS_HELP_STRING([--with-included-popt],[use bundled popt library, not from system]))
141
142 AC_ARG_WITH(included-zlib,
143         AS_HELP_STRING([--with-included-zlib],[use bundled zlib library, not from system]))
144
145 AC_ARG_WITH(protected-args,
146         AS_HELP_STRING([--with-protected-args],[make --protected-args option the default]))
147 if test x"$with_protected_args" = x"yes"; then
148         AC_DEFINE_UNQUOTED(RSYNC_USE_PROTECTED_ARGS, 1, [Define to 1 if --protected-args should be the default])
149 fi
150
151 AC_ARG_WITH(rsync-path,
152         AS_HELP_STRING([--with-rsync-path=PATH],[set default --rsync-path to PATH (default: rsync)]),
153         [ RSYNC_PATH="$with_rsync_path" ],
154         [ RSYNC_PATH="rsync" ])
155
156 AC_DEFINE_UNQUOTED(RSYNC_PATH, "$RSYNC_PATH", [location of rsync on remote machine])
157
158 AC_ARG_WITH(rsyncd-conf,
159         AS_HELP_STRING([--with-rsyncd-conf=PATH],[set configuration file for rsync server to PATH (default: /etc/rsyncd.conf)]),
160         [ if test ! -z "$with_rsyncd_conf" ; then
161                 case $with_rsyncd_conf in
162                         yes|no)
163                                 RSYNCD_SYSCONF="/etc/rsyncd.conf"
164                                 ;;
165                         /*)
166                                 RSYNCD_SYSCONF="$with_rsyncd_conf"
167                                 ;;
168                         *)
169                                 AC_MSG_ERROR(You must specify an absolute path to --with-rsyncd-conf=PATH)
170                                 ;;
171                 esac
172         else
173                 RSYNCD_SYSCONF="/etc/rsyncd.conf"
174         fi ],
175         [ RSYNCD_SYSCONF="/etc/rsyncd.conf" ])
176
177 AC_DEFINE_UNQUOTED(RSYNCD_SYSCONF, "$RSYNCD_SYSCONF", [location of configuration file for rsync server])
178
179 AC_ARG_WITH(rsh,
180         AS_HELP_STRING([--with-rsh=CMD],[set remote shell command to CMD (default: ssh)]))
181
182 AC_CHECK_PROG(HAVE_REMSH, remsh, 1, 0)
183 if test x$HAVE_REMSH = x1; then
184         AC_DEFINE(HAVE_REMSH, 1, [Define to 1 if remote shell is remsh, not rsh])
185 fi
186
187 if test x"$with_rsh" != x; then
188         RSYNC_RSH="$with_rsh"
189 else
190         RSYNC_RSH="ssh"
191 fi
192 AC_DEFINE_UNQUOTED(RSYNC_RSH, "$RSYNC_RSH", [default -e command])
193
194 # Some programs on solaris are only found in /usr/xpg4/bin (or work better than others versions).
195 AC_PATH_PROG(SHELL_PATH, sh, /bin/sh, [/usr/xpg4/bin$PATH_SEPARATOR$PATH])
196 AC_PATH_PROG(FAKEROOT_PATH, fakeroot, /usr/bin/fakeroot, [/usr/xpg4/bin$PATH_SEPARATOR$PATH])
197
198 AC_ARG_WITH(nobody-user,
199     AS_HELP_STRING([--with-nobody-user=USER],[set the default unprivileged user (default nobody)]),
200     [ NOBODY_USER="$with_nobody_user" ],
201     [ NOBODY_USER="nobody" ])
202
203 AC_ARG_WITH(nobody-group,
204     AS_HELP_STRING([--with-nobody-group=GROUP],[set the default unprivileged group (default nobody or nogroup)]),
205     [ NOBODY_GROUP="$with_nobody_group" ])
206
207 if test x"$with_nobody_group" = x; then
208     AC_MSG_CHECKING([the group for user "nobody"])
209     if grep '^nobody:' /etc/group >/dev/null 2>&1; then
210         NOBODY_GROUP=nobody
211     elif grep '^nogroup:' /etc/group >/dev/null 2>&1; then
212         NOBODY_GROUP=nogroup
213     else
214         NOBODY_GROUP=nobody # test for others?
215     fi
216     AC_MSG_RESULT($NOBODY_GROUP)
217 fi
218
219 AC_DEFINE_UNQUOTED(NOBODY_USER, "$NOBODY_USER", [unprivileged user--e.g. nobody])
220 AC_DEFINE_UNQUOTED(NOBODY_GROUP, "$NOBODY_GROUP", [unprivileged group for unprivileged user])
221
222 # SIMD optimizations
223 SIMD=
224
225 AC_MSG_CHECKING([whether to enable SIMD optimizations])
226 AC_ARG_ENABLE(simd,
227     AS_HELP_STRING([--disable-simd],[disable SIMD optimizations (requires c++)]))
228
229 # Clag is crashing with -g -O2, so we'll get rid of -g for now.
230 CXXFLAGS=`echo "$CXXFLAGS" | sed 's/-g //'`
231 m4_define(SIMD_X86_64_TEST, [[#include <stdio.h>
232 #if HAVE_STDLIB_H
233 #include <stdlib.h>
234 #endif
235 #include <immintrin.h>
236 __attribute__ ((target("default"))) int test_ssse3(int x) { return x; }
237 __attribute__ ((target("default"))) int test_sse2(int x) { return x; }
238 __attribute__ ((target("default"))) int test_avx2(int x) { return x; }
239 __attribute__ ((target("ssse3"))) int test_ssse3(int x) { return x; }
240 __attribute__ ((target("sse2"))) int test_sse2(int x) { return x; }
241 __attribute__ ((target("avx2"))) int test_avx2(int x) { return x; }
242 typedef long long __m128i_u __attribute__((__vector_size__(16), __may_alias__, __aligned__(1)));
243 typedef long long __m256i_u __attribute__((__vector_size__(32), __may_alias__, __aligned__(1)));
244 __attribute__ ((target("default"))) void more_testing(char* buf, int len) { }
245 __attribute__ ((target("ssse3"))) void more_testing(char* buf, int len)
246 {
247     int i;
248     for (i = 0; i < (len-32); i+=32) {
249         __m128i in8_1, in8_2;
250         in8_1 = _mm_lddqu_si128((__m128i_u*)&buf[i]);
251         in8_2 = _mm_lddqu_si128((__m128i_u*)&buf[i + 16]);
252     }
253 }
254 ]])
255
256 if test x"$enable_simd" != x"no"; then
257     # For x86-64 SIMD, g++ >=5 or clang++ >=7 is required
258     if test x"$host_cpu" = x"x86_64"; then
259         AC_LANG(C++)
260         if test x"$host_cpu" = x"$build_cpu"; then
261             AC_RUN_IFELSE([AC_LANG_PROGRAM([SIMD_X86_64_TEST],[[if (test_ssse3(42) != 42 || test_sse2(42) != 42 || test_avx2(42) != 42) exit(1);]])],
262                 [CXX_OK=yes],[CXX_OK=no])
263         else
264             AC_COMPILE_IFELSE([AC_LANG_PROGRAM([SIMD_X86_64_TEST])],[CXX_OK=yes],[CXX_OK=no])
265         fi
266         AC_LANG(C)
267         if test x"$CXX_OK" = x"yes"; then
268             # AC_MSG_RESULT() is called below.
269             SIMD="x86_64"
270         elif test x"$enable_simd" = x"yes"; then
271             AC_MSG_RESULT(error)
272             AC_MSG_ERROR(The SIMD compilation test failed.
273 Omit --enable-simd to continue without it.)
274         fi
275     elif test x"$enable_simd" = x"yes"; then
276         AC_MSG_RESULT(unavailable)
277         AC_MSG_ERROR(The SIMD optimizations are currently x86_64 only.
278 Omit --enable-simd to continue without it.)
279     fi
280 fi
281
282 if test x"$SIMD" != x""; then
283     AC_MSG_RESULT([yes ($SIMD)])
284     AC_DEFINE(HAVE_SIMD, 1, [Define to 1 to enable SIMD optimizations])
285     SIMD='$(SIMD_'"$SIMD)"
286     # We only use c++ for its target attribute dispatching, disable unneeded bulky features
287     CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-rtti"
288     # Apple often has "g++" as a symlink for clang. Try to find out the truth.
289     CXX_VERSION=`$CXX --version 2>/dev/null | head -n 2`
290     case "$CXX_VERSION" in
291     *clang*) CXXFLAGS="$CXXFLAGS -fno-slp-vectorize" ;; # avoid a performance hit
292     esac
293 else
294     AC_MSG_RESULT(no)
295 fi
296
297 AC_SUBST(SIMD)
298
299 AC_MSG_CHECKING([if assembler accepts noexecstack])
300 OLD_CFLAGS="$CFLAGS"
301 CFLAGS="$CFLAGS -Wa,--noexecstack"
302 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[return 0;]])],
303 [ NOEXECSTACK='-Wa,--noexecstack' ; AC_MSG_RESULT(yes) ],
304 [ NOEXECSTACK='' ; AC_MSG_RESULT(no) ])
305 CFLAGS="$OLD_CFLAGS"
306 AC_SUBST(NOEXECSTACK)
307
308 ASM=
309
310 AC_MSG_CHECKING([whether to enable ASM optimizations])
311 AC_ARG_ENABLE(asm,
312     AS_HELP_STRING([--disable-asm],[disable ASM optimizations]))
313
314 if test x"$enable_asm" != x"no"; then
315     if test x"$host_cpu" = x"x86_64"; then
316         ASM="$host_cpu"
317     elif test x"$enable_asm" = x"yes"; then
318         AC_MSG_RESULT(unavailable)
319         AC_MSG_ERROR(The ASM optimizations are currently x86_64 only.
320 Omit --enable-asm to continue without it.)
321     fi
322 fi
323
324 if test x"$ASM" != x""; then
325     AC_MSG_RESULT([yes ($ASM)])
326     AC_DEFINE(HAVE_ASM, 1, [Define to 1 to enable ASM optimizations])
327     ASM='$(ASM_'"$ASM)"
328 else
329     AC_MSG_RESULT(no)
330 fi
331
332 AC_SUBST(ASM)
333
334 # arrgh. libc in some old debian version screwed up the largefile
335 # stuff, getting byte range locking wrong
336 AC_CACHE_CHECK([for broken largefile support],rsync_cv_HAVE_BROKEN_LARGEFILE,[
337 AC_RUN_IFELSE([AC_LANG_SOURCE([[
338 #define _FILE_OFFSET_BITS 64
339 #include <stdio.h>
340 #include <fcntl.h>
341 #ifdef HAVE_SYS_TYPES_H
342 #include <sys/types.h>
343 #endif
344 #include <sys/wait.h>
345 #if HAVE_UNISTD_H
346 #include <unistd.h>
347 #endif
348
349 int main(void)
350 {
351         struct flock lock;
352         int status;
353         char tpl[32] = "/tmp/locktest.XXXXXX";
354         int fd = mkstemp(tpl);
355         if (fd < 0) {
356                 strcpy(tpl, "conftest.dat");
357                 fd = open(tpl, O_CREAT|O_RDWR, 0600);
358         }
359
360         lock.l_type = F_WRLCK;
361         lock.l_whence = SEEK_SET;
362         lock.l_start = 0;
363         lock.l_len = 1;
364         lock.l_pid = 0;
365         fcntl(fd,F_SETLK,&lock);
366         if (fork() == 0) {
367                 lock.l_start = 1;
368                 _exit(fcntl(fd,F_SETLK,&lock) == 0);
369         }
370         wait(&status);
371         unlink(tpl);
372         return WEXITSTATUS(status);
373 }
374 ]])],[rsync_cv_HAVE_BROKEN_LARGEFILE=yes],[rsync_cv_HAVE_BROKEN_LARGEFILE=no],[rsync_cv_HAVE_BROKEN_LARGEFILE=cross])])
375 if test x"$rsync_cv_HAVE_BROKEN_LARGEFILE" != x"yes"; then
376    AC_SYS_LARGEFILE
377 fi
378
379 AC_MSG_CHECKING([whether to enable ipv6])
380 AC_ARG_ENABLE(ipv6,
381 [  --disable-ipv6          disable ipv6 support],
382 [ case "$enableval" in
383   no)
384         AC_MSG_RESULT(no)
385         ;;
386   *)    AC_MSG_RESULT(yes)
387         AC_DEFINE(INET6, 1, [true if you have IPv6])
388         ;;
389   esac ],
390
391   AC_TRY_RUN([ /* AF_INET6 avalable check */
392 #include <stdlib.h>
393 #include <sys/types.h>
394 #include <sys/socket.h>
395 main()
396 {
397    if (socket(AF_INET6, SOCK_STREAM, 0) < 0)
398      exit(1);
399    else
400      exit(0);
401 }
402 ],
403   AC_MSG_RESULT(yes)
404   AC_DEFINE(INET6, 1, [true if you have IPv6]),
405   AC_MSG_RESULT(no),
406   AC_MSG_RESULT(no)
407 ))
408
409 dnl Do you want to disable use of locale functions
410 AC_ARG_ENABLE([locale],
411         AS_HELP_STRING([--disable-locale],[disable locale features]))
412 AH_TEMPLATE([CONFIG_LOCALE],
413 [Undefine if you do not want locale features.  By default this is defined.])
414 if test x"$enable_locale" != x"no"; then
415         AC_DEFINE(CONFIG_LOCALE)
416 fi
417
418 AC_MSG_CHECKING([whether to call shutdown on all sockets])
419 case $host_os in
420         *cygwin* ) AC_MSG_RESULT(yes)
421                    AC_DEFINE(SHUTDOWN_ALL_SOCKETS, 1,
422                             [Define to 1 if sockets need to be shutdown])
423                    ;;
424                * ) AC_MSG_RESULT(no);;
425 esac
426
427 AC_MSG_CHECKING([whether to enable use of openssl crypto library])
428 AC_ARG_ENABLE([openssl],
429         AS_HELP_STRING([--disable-openssl],[disable openssl crypto library]))
430 AH_TEMPLATE([USE_OPENSSL],
431 [Undefine if you do not want to use openssl crypto library.  By default this is defined.])
432 if test x"$enable_openssl" != x"no"; then
433     if test x"$ac_cv_header_openssl_md4_h" = x"yes" && test x"$ac_cv_header_openssl_md5_h" = x"yes"; then
434       AC_MSG_RESULT(yes)
435       AC_SEARCH_LIBS(MD5_Init, crypto,
436           [AC_DEFINE(USE_OPENSSL)],
437           [err_msg="$err_msg$nl- Failed to find MD5_Init function in openssl crypto lib.";
438            no_lib="$no_lib openssl"])
439     else
440         AC_MSG_RESULT(no)
441         err_msg="$err_msg$nl- Failed to find openssl/md4.h and openssl/md5.h for openssl crypto lib support."
442         no_lib="$no_lib openssl"
443     fi
444 else
445     AC_MSG_RESULT(no)
446 fi
447
448 AC_MSG_CHECKING([whether to enable xxhash checksum support])
449 AC_ARG_ENABLE([xxhash],
450         AS_HELP_STRING([--disable-xxhash],[disable xxhash checksums]))
451 AH_TEMPLATE([SUPPORT_XXHASH],
452 [Undefine if you do not want xxhash checksums.  By default this is defined.])
453 if test x"$enable_xxhash" != x"no"; then
454     if test x"$ac_cv_header_xxhash_h" = x"yes"; then
455         AC_MSG_RESULT(yes)
456         AC_SEARCH_LIBS(XXH64_createState, xxhash,
457             [AC_DEFINE(SUPPORT_XXHASH)],
458             [err_msg="$err_msg$nl- Failed to find XXH64_createState function in xxhash lib.";
459              no_lib="$no_lib xxhash"])
460     else
461         AC_MSG_RESULT(no)
462         err_msg="$err_msg$nl- Failed to find xxhash.h for xxhash checksum support.";
463         no_lib="$no_lib xxhash"
464     fi
465 else
466     AC_MSG_RESULT(no)
467 fi
468
469 AC_MSG_CHECKING([whether to enable zstd compression])
470 AC_ARG_ENABLE([zstd],
471         AC_HELP_STRING([--disable-zstd], [disable zstd compression]))
472 AH_TEMPLATE([SUPPORT_ZSTD],
473 [Undefine if you do not want zstd compression.  By default this is defined.])
474 if test x"$enable_zstd" != x"no"; then
475     if test x"$ac_cv_header_zstd_h" = x"yes"; then
476         AC_MSG_RESULT(yes)
477         AC_SEARCH_LIBS(ZSTD_minCLevel, zstd,
478             [AC_DEFINE(SUPPORT_ZSTD)],
479             [err_msg="$err_msg$nl- Failed to find ZSTD_minCLevel function in zstd lib.";
480              no_lib="$no_lib zstd"])
481     else
482         AC_MSG_RESULT(no)
483         err_msg="$err_msg$nl- Failed to find zstd.h for zstd compression support.";
484         no_lib="$no_lib zstd"
485     fi
486 else
487     AC_MSG_RESULT(no)
488 fi
489
490 AC_MSG_CHECKING([whether to enable LZ4 compression])
491 AC_ARG_ENABLE([lz4],
492         AC_HELP_STRING([--disable-lz4], [disable LZ4 compression]))
493 AH_TEMPLATE([SUPPORT_LZ4],
494 [Undefine if you do not want LZ4 compression.  By default this is defined.])
495 if test x"$enable_lz4" != x"no"; then
496     if test x"$ac_cv_header_lz4_h" = x"yes"; then
497         AC_MSG_RESULT(yes)
498         AC_SEARCH_LIBS(LZ4_compress_default, lz4,
499             [AC_DEFINE(SUPPORT_LZ4)],
500             [err_msg="$err_msg$nl- Failed to find LZ4_compress_default function in lz4 lib.";
501              no_lib="$no_lib lz4"])
502     else
503         AC_MSG_RESULT(no)
504         err_msg="$err_msg$nl- Failed to find lz4.h for lz4 compression support."
505         no_lib="$no_lib lz4"
506     fi
507 else
508     AC_MSG_RESULT(no)
509 fi
510
511 if test x"$no_lib" != x; then
512     echo ""
513     echo "Configure found the following issues:"
514     echo "$err_msg"
515     echo ""
516     echo "See the INSTALL file for hints on how to install the missing libraries and/or"
517     echo "how to generate (or fetch) man pages:"
518     echo "    https://github.com/WayneD/rsync/blob/master/INSTALL.md"
519     echo ""
520     echo "To disable one or more features, the relevant configure options are:"
521     for lib in $no_lib; do
522         echo "    --disable-$lib"
523     done
524     echo ""
525     AC_MSG_ERROR(Aborting configure run)
526 fi
527
528 AC_CACHE_CHECK([if makedev takes 3 args],rsync_cv_MAKEDEV_TAKES_3_ARGS,[
529 AC_RUN_IFELSE([AC_LANG_SOURCE([[
530 #ifdef HAVE_SYS_TYPES_H
531 #include <sys/types.h>
532 #endif
533 #ifdef MAJOR_IN_MKDEV
534 #include <sys/mkdev.h>
535 # if !defined makedev && (defined mkdev || defined _WIN32 || defined __WIN32__)
536 #  define makedev mkdev
537 # endif
538 #elif defined MAJOR_IN_SYSMACROS
539 #include <sys/sysmacros.h>
540 #endif
541
542 int main(void)
543 {
544         dev_t dev = makedev(0, 5, 7);
545         if (major(dev) != 5 || minor(dev) != 7)
546                 return 1;
547         return 0;
548 }
549 ]])],[rsync_cv_MAKEDEV_TAKES_3_ARGS=yes],[rsync_cv_MAKEDEV_TAKES_3_ARGS=no],[rsync_cv_MAKEDEV_TAKES_3_ARGS=no])])
550 if test x"$rsync_cv_MAKEDEV_TAKES_3_ARGS" = x"yes"; then
551    AC_DEFINE(MAKEDEV_TAKES_3_ARGS, 1, [Define to 1 if makedev() takes 3 args])
552 fi
553
554 AC_CHECK_SIZEOF(int)
555 AC_CHECK_SIZEOF(long)
556 AC_CHECK_SIZEOF(long long)
557 AC_CHECK_SIZEOF(short)
558 AC_CHECK_SIZEOF(int16_t)
559 AC_CHECK_SIZEOF(uint16_t)
560 AC_CHECK_SIZEOF(int32_t)
561 AC_CHECK_SIZEOF(uint32_t)
562 AC_CHECK_SIZEOF(int64_t)
563 AC_CHECK_SIZEOF(off_t)
564 AC_CHECK_SIZEOF(off64_t)
565 AC_CHECK_SIZEOF(time_t)
566 AC_CHECK_SIZEOF(char*)
567
568 AC_C_INLINE
569
570 AC_TYPE_LONG_DOUBLE_WIDER
571 ac_cv_c_long_double=$ac_cv_type_long_double_wider
572 if test $ac_cv_c_long_double = yes; then
573   AC_DEFINE([HAVE_LONG_DOUBLE],[1],[Define to 1 if the type `long double' works and has more range or precision than `double'.])
574 fi
575
576 AC_TYPE_UID_T
577 AC_CHECK_TYPES([mode_t,off_t,size_t,pid_t,id_t])
578 AC_TYPE_GETGROUPS
579 AC_CHECK_MEMBERS([struct stat.st_rdev,
580                   struct stat.st_mtimensec,
581                   struct stat.st_mtimespec.tv_nsec,
582                   struct stat.st_mtim.tv_nsec],,,[
583 #ifdef HAVE_SYS_TYPES_H
584 #include <sys/types.h>
585 #endif
586 #ifdef HAVE_SYS_STAT_H
587 #include <sys/stat.h>
588 #endif
589 #ifdef HAVE_UNISTD_H
590 #include <unistd.h>
591 #endif])
592
593 TYPE_SOCKLEN_T
594
595 AC_CACHE_CHECK([for errno in errno.h],rsync_cv_errno, [
596     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <errno.h>]], [[int i = errno]])],[rsync_cv_errno=yes],[rsync_cv_have_errno_decl=no])])
597 if test x"$rsync_cv_errno" = x"yes"; then
598    AC_DEFINE(HAVE_ERRNO_DECL, 1, [Define to 1 if errno is declared in errno.h])
599 fi
600
601 # The following test taken from the cvs sources
602 # If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
603 # These need checks to be before checks for any other functions that
604 #    might be in the same libraries.
605 # The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
606 # libsocket.so which has a bad implementation of gethostbyname (it
607 # only looks in /etc/hosts), so we only look for -lsocket if we need
608 # it.
609 AC_CHECK_FUNCS(connect)
610 if test x"$ac_cv_func_connect" = x"no"; then
611     case "$LIBS" in
612     *-lnsl*) ;;
613     *) AC_CHECK_LIB(nsl_s, printf) ;;
614     esac
615     case "$LIBS" in
616     *-lnsl*) ;;
617     *) AC_CHECK_LIB(nsl, printf) ;;
618     esac
619     case "$LIBS" in
620     *-lsocket*) ;;
621     *) AC_CHECK_LIB(socket, connect) ;;
622     esac
623     case "$LIBS" in
624     *-linet*) ;;
625     *) AC_CHECK_LIB(inet, connect) ;;
626     esac
627     dnl We can't just call AC_CHECK_FUNCS(connect) here, because the value
628     dnl has been cached.
629     if test x"$ac_cv_lib_socket_connect" = x"yes" ||
630        test x"$ac_cv_lib_inet_connect" = x"yes"; then
631         # ac_cv_func_connect=yes
632         # don't!  it would cause AC_CHECK_FUNC to succeed next time configure is run
633         AC_DEFINE(HAVE_CONNECT, 1, [Define to 1 if you have the "connect" function])
634     fi
635 fi
636
637 AC_SEARCH_LIBS(inet_ntop, resolv)
638
639 # For OS X, Solaris, HP-UX, etc.: figure out if -liconv is needed.  We'll
640 # accept either iconv_open or libiconv_open, since some include files map
641 # the former to the latter.
642 AC_SEARCH_LIBS(iconv_open, iconv)
643 AC_SEARCH_LIBS(libiconv_open, iconv)
644
645 AC_MSG_CHECKING([for iconv declaration])
646 AC_CACHE_VAL(am_cv_proto_iconv, [
647     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
648 #if HAVE_STDLIB_H
649 #include <stdlib.h>
650 #endif
651 #include <iconv.h>
652 extern
653 #ifdef __cplusplus
654 "C"
655 #endif
656 #if defined(__STDC__) || defined(__cplusplus)
657 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
658 #else
659 size_t iconv();
660 #endif
661 ]], [[]])],[am_cv_proto_iconv_arg1=""],[am_cv_proto_iconv_arg1="const"])
662       am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
663     am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed 's/( /(/'`
664 AC_MSG_RESULT([$]{ac_t:-
665          }[$]am_cv_proto_iconv)
666 AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
667                    [Define as const if the declaration of iconv() needs const.])
668
669 dnl AC_MSG_NOTICE([Looking in libraries: $LIBS])
670
671 AC_REPLACE_FUNCS([inet_ntop inet_pton])
672
673 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
674 AC_HAVE_TYPE([struct sockaddr_storage], [
675 #ifdef HAVE_SYS_TYPES_H
676 #include <sys/types.h>
677 #endif
678 #ifdef HAVE_SYS_SOCKET_H
679 #include <sys/socket.h>
680 #endif])
681
682 # Irix 6.5 has getaddrinfo but not the corresponding defines, so use
683 #   builtin getaddrinfo if one of the defines don't exist
684 AC_CACHE_CHECK([whether defines needed by getaddrinfo exist],
685                rsync_cv_HAVE_GETADDR_DEFINES,[
686                         AC_EGREP_CPP(yes, [
687 #ifdef HAVE_SYS_TYPES_H
688 #include <sys/types.h>
689 #endif
690 #ifdef HAVE_SYS_SOCKET_H
691 #include <sys/socket.h>
692 #endif
693 #ifdef HAVE_NETDB_H
694 #include <netdb.h>
695 #endif
696 #ifdef AI_PASSIVE
697 yes
698 #endif],
699                         rsync_cv_HAVE_GETADDR_DEFINES=yes,
700                         rsync_cv_HAVE_GETADDR_DEFINES=no)])
701 AS_IF([test x"$rsync_cv_HAVE_GETADDR_DEFINES" = x"yes" -a x"$ac_cv_type_struct_addrinfo" = x"yes"],[
702         # Tru64 UNIX has getaddrinfo() but has it renamed in libc as
703         # something else so we must include <netdb.h> to get the
704         # redefinition.
705         AC_CHECK_FUNCS(getaddrinfo, ,
706                 [AC_MSG_CHECKING([for getaddrinfo by including <netdb.h>])
707                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
708 #ifdef HAVE_SYS_TYPES_H
709 #include <sys/types.h>
710 #endif
711 #ifdef HAVE_SYS_SOCKET_H
712 #include <sys/socket.h>
713 #endif
714 #include <netdb.h>]], [[getaddrinfo(NULL, NULL, NULL, NULL);]])],[AC_MSG_RESULT([yes])
715                         AC_DEFINE(HAVE_GETADDRINFO, 1,
716                                 [Define to 1 if you have the "getaddrinfo" function and required types.])],[AC_MSG_RESULT([no])
717                         AC_LIBOBJ([getaddrinfo])])])
718     ],[AC_LIBOBJ([getaddrinfo])])
719
720 AC_CHECK_MEMBER([struct sockaddr.sa_len],
721                 [ AC_DEFINE(HAVE_SOCKADDR_LEN, 1, [Do we have sockaddr.sa_len?]) ],
722                 [],
723                 [
724 #ifdef HAVE_SYS_TYPES_H
725 #include <sys/types.h>
726 #endif
727 #ifdef HAVE_SYS_SOCKET_H
728 #include <sys/socket.h>
729 #endif
730 ])
731
732 AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
733                 [ AC_DEFINE(HAVE_SOCKADDR_IN_LEN, 1, [Do we have sockaddr_in.sin_len?]) ],
734                 [],
735                 [
736 #ifdef HAVE_SYS_TYPES_H
737 #include <sys/types.h>
738 #endif
739 #ifdef HAVE_SYS_SOCKET_H
740 #include <sys/socket.h>
741 #endif
742 #include <netinet/in.h>
743 ])
744
745 AC_CHECK_MEMBER([struct sockaddr_un.sun_len],
746                 [ AC_DEFINE(HAVE_SOCKADDR_UN_LEN, 1, [Do we have sockaddr_un.sun_len?]) ],
747                 [],
748                 [
749 #ifdef HAVE_SYS_TYPES_H
750 #include <sys/types.h>
751 #endif
752 #ifdef HAVE_SYS_SOCKET_H
753 #include <sys/socket.h>
754 #endif
755 #include <netinet/in.h>
756 ])
757
758 AC_CHECK_MEMBER([struct sockaddr_in6.sin6_scope_id],
759                 [ AC_DEFINE(HAVE_SOCKADDR_IN6_SCOPE_ID, 1, [Do we have sockaddr_in6.sin6_scope_id?]) ],
760                 [],
761                 [
762 #ifdef HAVE_SYS_TYPES_H
763 #include <sys/types.h>
764 #endif
765 #ifdef HAVE_SYS_SOCKET_H
766 #include <sys/socket.h>
767 #endif
768 #include <netinet/in.h>
769 ])
770
771 AC_HAVE_TYPE([struct stat64], [#include <stdio.h>
772 #if HAVE_SYS_TYPES_H
773 # include <sys/types.h>
774 #endif
775 #if HAVE_SYS_STAT_H
776 # include <sys/stat.h>
777 #endif
778 #if STDC_HEADERS
779 # include <stdlib.h>
780 # include <stddef.h>
781 #else
782 # if HAVE_STDLIB_H
783 #  include <stdlib.h>
784 # endif
785 #endif
786 ])
787
788 # if we can't find strcasecmp, look in -lresolv (for Unixware at least)
789 #
790 AC_CHECK_FUNCS(strcasecmp)
791 if test x"$ac_cv_func_strcasecmp" = x"no"; then
792     AC_CHECK_LIB(resolv, strcasecmp)
793 fi
794
795 AC_CHECK_FUNCS(aclsort)
796 if test x"$ac_cv_func_aclsort" = x"no"; then
797     AC_CHECK_LIB(sec, aclsort)
798 fi
799
800 dnl At the moment we don't test for a broken memcmp(), because all we
801 dnl need to do is test for equality, not comparison, and it seems that
802 dnl every platform has a memcmp that can do at least that.
803 dnl AC_FUNC_MEMCMP
804
805 AC_FUNC_UTIME_NULL
806 AC_FUNC_ALLOCA
807 AC_CHECK_FUNCS(waitpid wait4 getcwd chown chmod lchmod mknod mkfifo \
808     fchmod fstat ftruncate strchr readlink link utime utimes lutimes strftime \
809     chflags getattrlist mktime innetgr linkat \
810     memmove lchown vsnprintf snprintf vasprintf asprintf setsid strpbrk \
811     strlcat strlcpy strtol mallinfo getgroups setgroups geteuid getegid \
812     setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \
813     seteuid strerror putenv iconv_open locale_charset nl_langinfo getxattr \
814     extattr_get_link sigaction sigprocmask setattrlist getgrouplist \
815     initgroups utimensat posix_fallocate attropen setvbuf nanosleep usleep \
816     setenv unsetenv)
817
818 dnl cygwin iconv.h defines iconv_open as libiconv_open
819 if test x"$ac_cv_func_iconv_open" != x"yes"; then
820     AC_CHECK_FUNC(libiconv_open, [ac_cv_func_iconv_open=yes; AC_DEFINE(HAVE_ICONV_OPEN, 1)])
821 fi
822
823 dnl Preallocation stuff (also fallocate, posix_fallocate function tests above):
824
825 AC_CACHE_CHECK([for useable fallocate],rsync_cv_have_fallocate,[
826 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <fcntl.h>
827 #ifdef HAVE_SYS_TYPES_H
828 #include <sys/types.h>
829 #endif]], [[fallocate(0, 0, 0, 0);]])],[rsync_cv_have_fallocate=yes],[rsync_cv_have_fallocate=no])])
830 if test x"$rsync_cv_have_fallocate" = x"yes"; then
831     AC_DEFINE(HAVE_FALLOCATE, 1, [Define to 1 if you have the fallocate function and it compiles and links without error])
832 fi
833
834 AC_MSG_CHECKING([for FALLOC_FL_PUNCH_HOLE])
835 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
836         #define _GNU_SOURCE 1
837         #include <linux/falloc.h>
838         #ifndef FALLOC_FL_PUNCH_HOLE
839         #error FALLOC_FL_PUNCH_HOLE is missing
840         #endif
841     ]])], [
842         AC_MSG_RESULT([yes])
843         AC_DEFINE([HAVE_FALLOC_FL_PUNCH_HOLE], [1], [Define if FALLOC_FL_PUNCH_HOLE is available.])
844     ], [
845         AC_MSG_RESULT([no])
846     ]
847 )
848
849 AC_MSG_CHECKING([for FALLOC_FL_ZERO_RANGE])
850 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
851         #define _GNU_SOURCE 1
852         #include <linux/falloc.h>
853         #ifndef FALLOC_FL_ZERO_RANGE
854         #error FALLOC_FL_ZERO_RANGE is missing
855         #endif
856     ]])], [
857         AC_MSG_RESULT([yes])
858         AC_DEFINE([HAVE_FALLOC_FL_ZERO_RANGE], [1], [Define if FALLOC_FL_ZERO_RANGE is available.])
859     ], [
860         AC_MSG_RESULT([no])
861     ]
862 )
863
864 AC_CACHE_CHECK([for SYS_fallocate],rsync_cv_have_sys_fallocate,[
865 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/syscall.h>
866 #ifdef HAVE_UNISTD_H
867 #include <unistd.h>
868 #endif
869 #ifdef HAVE_SYS_TYPES_H
870 #include <sys/types.h>
871 #endif]], [[syscall(SYS_fallocate, 0, 0, (loff_t)0, (loff_t)0);]])],[rsync_cv_have_sys_fallocate=yes],[rsync_cv_have_sys_fallocate=no])])
872 if test x"$rsync_cv_have_sys_fallocate" = x"yes"; then
873     AC_DEFINE(HAVE_SYS_FALLOCATE, 1, [Define to 1 if you have the SYS_fallocate syscall number])
874 fi
875
876 if test x"$ac_cv_func_posix_fallocate" = x"yes"; then
877     AC_MSG_CHECKING([whether posix_fallocate is efficient])
878     case $host_os in
879     *cygwin*)
880         AC_MSG_RESULT(yes)
881         AC_DEFINE(HAVE_EFFICIENT_POSIX_FALLOCATE, 1,
882                   [Define if posix_fallocate is efficient (Cygwin)])
883         ;;
884     *)
885         AC_MSG_RESULT(no)
886         ;;
887     esac
888 fi
889
890 dnl End of preallocation stuff
891
892 AC_CHECK_FUNCS(getpgrp tcgetpgrp)
893 if test $ac_cv_func_getpgrp = yes; then
894     AC_FUNC_GETPGRP
895 fi
896
897 AC_ARG_ENABLE(iconv-open,
898     AS_HELP_STRING([--disable-iconv-open],[disable all use of iconv_open() function]),
899     [], [enable_iconv_open=$ac_cv_func_iconv_open])
900
901 if test x"$enable_iconv_open" != x"no"; then
902     AC_DEFINE(USE_ICONV_OPEN, 1, [Define to 1 if you want rsync to make use of iconv_open()])
903 fi
904
905 AC_ARG_ENABLE(iconv,
906     AS_HELP_STRING([--disable-iconv],[disable rsync's --iconv option]),
907     [], [enable_iconv=$enable_iconv_open])
908 AH_TEMPLATE([ICONV_OPTION],
909 [Define if you want the --iconv option.  Specifying a value will set the
910 default iconv setting (a NULL means no --iconv processing by default).])
911 if test x"$enable_iconv" != x"no"; then
912         if test x"$enable_iconv" = x"yes"; then
913                 AC_DEFINE(ICONV_OPTION, NULL)
914         else
915                 AC_DEFINE_UNQUOTED(ICONV_OPTION, "$enable_iconv")
916         fi
917         AC_DEFINE(UTF8_CHARSET, "UTF-8", [String to pass to iconv() for the UTF-8 charset.])
918 fi
919
920 AC_CACHE_CHECK([whether chown() modifies symlinks],rsync_cv_chown_modifies_symlink,[
921   AC_RUN_IFELSE([AC_LANG_SOURCE([[
922 #if HAVE_UNISTD_H
923 # include <unistd.h>
924 #endif
925 #include <stdlib.h>
926 #include <errno.h>
927 int main(void) {
928         char const *dangling_symlink = "conftest.dangle";
929         unlink(dangling_symlink);
930         if (symlink("conftest.no-such", dangling_symlink) < 0) abort();
931         if (chown(dangling_symlink, getuid(), getgid()) < 0 && errno == ENOENT) return 1;
932         return 0;
933     }]])],[rsync_cv_chown_modifies_symlink=yes],[rsync_cv_chown_modifies_symlink=no],[rsync_cv_chown_modifies_symlink=no])])
934 if test $rsync_cv_chown_modifies_symlink = yes; then
935   AC_DEFINE(CHOWN_MODIFIES_SYMLINK, 1, [Define to 1 if chown modifies symlinks.])
936 fi
937
938 AC_CACHE_CHECK([whether link() can hard-link symlinks],rsync_cv_can_hardlink_symlink,[
939   AC_RUN_IFELSE([AC_LANG_SOURCE([[
940 #ifdef HAVE_FCNTL_H
941 # include <fcntl.h>
942 #elif defined HAVE_SYS_FCNTL_H
943 # include <sys/fcntl.h>
944 #endif
945 #if HAVE_UNISTD_H
946 # include <unistd.h>
947 #endif
948 #include <stdlib.h>
949 #include <errno.h>
950 #define FILENAME "conftest.dangle"
951 int main(void) {
952         unlink(FILENAME);
953         if (symlink("conftest.no-such", FILENAME) < 0) abort();
954         unlink(FILENAME "2");
955 #ifdef HAVE_LINKAT
956         if (linkat(AT_FDCWD, FILENAME, AT_FDCWD, FILENAME "2", 0) < 0) return 1;
957 #else
958         if (link(FILENAME, FILENAME "2") < 0) return 1;
959 #endif
960         return 0;
961     }]])],[rsync_cv_can_hardlink_symlink=yes],[rsync_cv_can_hardlink_symlink=no],[rsync_cv_can_hardlink_symlink=no])])
962 if test $rsync_cv_can_hardlink_symlink = yes; then
963   AC_DEFINE(CAN_HARDLINK_SYMLINK, 1, [Define to 1 if link() can hard-link symlinks.])
964 fi
965
966 AC_CACHE_CHECK([whether link() can hard-link special files],rsync_cv_can_hardlink_special,[
967   AC_RUN_IFELSE([AC_LANG_SOURCE([[
968 #if HAVE_UNISTD_H
969 # include <unistd.h>
970 #endif
971 #ifdef HAVE_SYS_STAT_H
972 #include <sys/stat.h>
973 #endif
974 #include <stdlib.h>
975 #include <errno.h>
976 #define FILENAME "conftest.fifi"
977 int main(void) {
978         unlink(FILENAME);
979         if (mkfifo(FILENAME, 0777) < 0) abort();
980         unlink(FILENAME "2");
981         if (link(FILENAME, FILENAME "2") < 0) return 1;
982         return 0;
983     }]])],[rsync_cv_can_hardlink_special=yes],[rsync_cv_can_hardlink_special=no],[rsync_cv_can_hardlink_special=no])])
984 if test $rsync_cv_can_hardlink_special = yes; then
985     AC_DEFINE(CAN_HARDLINK_SPECIAL, 1, [Define to 1 if link() can hard-link special files.])
986 fi
987
988 AC_CACHE_CHECK([for working socketpair],rsync_cv_HAVE_SOCKETPAIR,[
989 AC_RUN_IFELSE([AC_LANG_SOURCE([[
990 #ifdef HAVE_SYS_TYPES_H
991 #include <sys/types.h>
992 #endif
993 #ifdef HAVE_SYS_SOCKET_H
994 #include <sys/socket.h>
995 #endif
996
997 int main(void) {
998        int fd[2];
999        return (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) != -1) ? 0 : 1;
1000 }]])],[rsync_cv_HAVE_SOCKETPAIR=yes],[rsync_cv_HAVE_SOCKETPAIR=no],[rsync_cv_HAVE_SOCKETPAIR=cross])])
1001 if test x"$rsync_cv_HAVE_SOCKETPAIR" = x"yes"; then
1002     AC_DEFINE(HAVE_SOCKETPAIR, 1, [Define to 1 if you have the "socketpair" function])
1003 fi
1004
1005 AC_REPLACE_FUNCS([getpass])
1006
1007 if test x"$with_included_popt" != x"yes"; then
1008     AC_CHECK_LIB(popt, poptGetContext, , [with_included_popt=yes])
1009 fi
1010 if test x"$ac_cv_header_popt_popt_h" = x"yes"; then
1011     # If the system has /usr/include/popt/popt.h, we enable the
1012     # included popt because an attempt to "#include <popt/popt.h>"
1013     # would use our included header file anyway (due to -I.), and
1014     # might conflict with the system popt.
1015     with_included_popt=yes
1016 elif test x"$ac_cv_header_popt_h" != x"yes"; then
1017     with_included_popt=yes
1018 fi
1019
1020 if test x"$GCC" = x"yes"; then
1021     if test x"$with_included_popt" != x"yes"; then
1022         # Turn pedantic warnings into errors to ensure an array-init overflow is an error.
1023         CFLAGS="$CFLAGS -pedantic-errors"
1024     else
1025         # Our internal popt code cannot be compiled with pedantic warnings as errors, so try to
1026         # turn off pedantic warnings (which will not lose the error for array-init overflow).
1027         # Older gcc versions don't understand -Wno-pedantic, so check if --help=warnings lists
1028         # -Wpedantic and use that as a flag.
1029         case `$CC --help=warnings 2>/dev/null | grep Wpedantic` in
1030             *-Wpedantic*) CFLAGS="$CFLAGS -pedantic-errors -Wno-pedantic" ;;
1031         esac
1032     fi
1033 fi
1034
1035 AC_MSG_CHECKING([whether to use included libpopt])
1036 if test x"$with_included_popt" = x"yes"; then
1037     AC_MSG_RESULT($srcdir/popt)
1038     BUILD_POPT='$(popt_OBJS)'
1039     CFLAGS="-I$srcdir/popt $CFLAGS"
1040     if test x"$ALLOCA" != x
1041     then
1042         # this can be removed when/if we add an included alloca.c;
1043         #  see autoconf documentation on AC_FUNC_ALLOCA
1044         AC_MSG_WARN([included libpopt will use malloc, not alloca (which wastes a small amount of memory)])
1045     fi
1046 else
1047     AC_MSG_RESULT(no)
1048 fi
1049
1050 # We default to using our zlib unless --with-included-zlib=no is given.
1051 if test x"$with_included_zlib" != x"no"; then
1052     with_included_zlib=yes
1053 elif test x"$ac_cv_header_zlib_h" != x"yes"; then
1054     with_included_zlib=yes
1055 fi
1056 if test x"$with_included_zlib" != x"yes"; then
1057     AC_CHECK_LIB(z, deflateParams, , [with_included_zlib=yes])
1058 fi
1059
1060 AC_MSG_CHECKING([whether to use included zlib])
1061 if test x"$with_included_zlib" = x"yes"; then
1062     AC_MSG_RESULT($srcdir/zlib)
1063     BUILD_ZLIB='$(zlib_OBJS)'
1064     CFLAGS="-I$srcdir/zlib $CFLAGS"
1065 else
1066     AC_DEFINE(EXTERNAL_ZLIB, 1, [Define to 1 if using external zlib])
1067     AC_MSG_RESULT(no)
1068 fi
1069
1070 AC_CACHE_CHECK([for unsigned char],rsync_cv_SIGNED_CHAR_OK,[
1071 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[signed char *s = ""]])],[rsync_cv_SIGNED_CHAR_OK=yes],[rsync_cv_SIGNED_CHAR_OK=no])])
1072 if test x"$rsync_cv_SIGNED_CHAR_OK" = x"yes"; then
1073     AC_DEFINE(SIGNED_CHAR_OK, 1, [Define to 1 if "signed char" is a valid type])
1074 fi
1075
1076 AC_CACHE_CHECK([for broken readdir],rsync_cv_HAVE_BROKEN_READDIR,[
1077 AC_RUN_IFELSE([AC_LANG_SOURCE([[
1078 #ifdef HAVE_SYS_TYPES_H
1079 #include <sys/types.h>
1080 #endif
1081 #include <dirent.h>
1082 int main(void) { struct dirent *di; DIR *d = opendir("."); di = readdir(d);
1083 if (di && di->d_name[-2] == '.' && di->d_name[-1] == 0 &&
1084 di->d_name[0] == 0) return 0; return 1;} ]])],[rsync_cv_HAVE_BROKEN_READDIR=yes],[rsync_cv_HAVE_BROKEN_READDIR=no],[rsync_cv_HAVE_BROKEN_READDIR=cross])])
1085 if test x"$rsync_cv_HAVE_BROKEN_READDIR" = x"yes"; then
1086     AC_DEFINE(HAVE_BROKEN_READDIR, 1, [Define to 1 if readdir() is broken])
1087 fi
1088
1089 AC_CACHE_CHECK([for utimbuf],rsync_cv_HAVE_STRUCT_UTIMBUF,[
1090 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1091 #ifdef HAVE_SYS_TYPES_H
1092 #include <sys/types.h>
1093 #endif
1094 #include <utime.h>]], [[struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; return utime("foo.c",&tbuf);]])],[rsync_cv_HAVE_STRUCT_UTIMBUF=yes],[rsync_cv_HAVE_STRUCT_UTIMBUF=no])])
1095 if test x"$rsync_cv_HAVE_STRUCT_UTIMBUF" = x"yes"; then
1096     AC_DEFINE(HAVE_STRUCT_UTIMBUF, 1, [Define to 1 if you have the "struct utimbuf" type])
1097 fi
1098
1099 AC_CACHE_CHECK([if gettimeofday takes tz argument],rsync_cv_HAVE_GETTIMEOFDAY_TZ,[
1100 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/time.h>
1101 #ifdef HAVE_UNISTD_H
1102 #include <unistd.h>
1103 #endif]], [[struct timeval tv; return gettimeofday(&tv, NULL);]])],[rsync_cv_HAVE_GETTIMEOFDAY_TZ=yes],[rsync_cv_HAVE_GETTIMEOFDAY_TZ=no])])
1104 if test x"$rsync_cv_HAVE_GETTIMEOFDAY_TZ" != x"no"; then
1105     AC_DEFINE(HAVE_GETTIMEOFDAY_TZ, 1, [Define to 1 if gettimeofday() takes a time-zone arg])
1106 fi
1107
1108 AC_CACHE_CHECK([for C99 vsnprintf],rsync_cv_HAVE_C99_VSNPRINTF,[
1109 AC_RUN_IFELSE([AC_LANG_SOURCE([[
1110 #ifdef HAVE_SYS_TYPES_H
1111 #include <sys/types.h>
1112 #endif
1113 #include <stdarg.h>
1114 #include <stdio.h>
1115 #if HAVE_STDLIB_H
1116 #include <stdlib.h>
1117 #endif
1118 #include <string.h>
1119 void foo(const char *format, ...) {
1120        va_list ap;
1121        int len;
1122        static char buf[] = "12345678901234567890";
1123
1124        va_start(ap, format);
1125        len = vsnprintf(0, 0, format, ap);
1126        va_end(ap);
1127        if (len != 5) exit(1);
1128
1129        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
1130 }
1131 int main(void) { foo("hello"); return 0; }
1132 ]])],[rsync_cv_HAVE_C99_VSNPRINTF=yes],[rsync_cv_HAVE_C99_VSNPRINTF=no],[rsync_cv_HAVE_C99_VSNPRINTF=cross])])
1133 if test x"$rsync_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
1134     AC_DEFINE(HAVE_C99_VSNPRINTF, 1, [Define to 1 if vsprintf has a C99-compatible return value])
1135 fi
1136
1137
1138 AC_CACHE_CHECK([for secure mkstemp],rsync_cv_HAVE_SECURE_MKSTEMP,[
1139 AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
1140 #ifdef HAVE_SYS_TYPES_H
1141 #include <sys/types.h>
1142 #endif
1143 #include <sys/stat.h>
1144 #ifdef HAVE_UNISTD_H
1145 #include <unistd.h>
1146 #endif
1147 int main(void) {
1148   struct stat st;
1149   char tpl[20]="/tmp/test.XXXXXX";
1150   int fd = mkstemp(tpl);
1151   if (fd == -1) return 1;
1152   unlink(tpl);
1153   if (fstat(fd, &st) != 0) return 1;
1154   if ((st.st_mode & 0777) != 0600) return 1;
1155   return 0;
1156 }]])],[rsync_cv_HAVE_SECURE_MKSTEMP=yes],[rsync_cv_HAVE_SECURE_MKSTEMP=no],[rsync_cv_HAVE_SECURE_MKSTEMP=cross])])
1157 if test x"$rsync_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
1158     case $host_os in
1159     hpux*)
1160         dnl HP-UX has a broken mkstemp() implementation they refuse to fix,
1161         dnl so we noisily skip using it.  See HP change request JAGaf34426
1162         dnl for details. (sbonds)
1163         AC_MSG_WARN(Skipping broken HP-UX mkstemp() -- using mktemp() instead)
1164         ;;
1165     *)
1166         AC_DEFINE(HAVE_SECURE_MKSTEMP, 1, [Define to 1 if mkstemp() is available and works right])
1167         ;;
1168     esac
1169 fi
1170
1171
1172 AC_CACHE_CHECK([if mknod creates FIFOs],rsync_cv_MKNOD_CREATES_FIFOS,[
1173 AC_RUN_IFELSE([AC_LANG_SOURCE([[
1174 #include <stdio.h>
1175 #include <sys/stat.h>
1176 #include <errno.h>
1177 #if HAVE_UNISTD_H
1178 # include <unistd.h>
1179 #endif
1180 int main(void) { int rc, ec; char *fn = "fifo-test";
1181 unlink(fn); rc = mknod(fn,S_IFIFO,0600); ec = errno; unlink(fn);
1182 if (rc) {printf("(%d %d) ",rc,ec); return ec;}
1183 return 0;}]])],[rsync_cv_MKNOD_CREATES_FIFOS=yes],[rsync_cv_MKNOD_CREATES_FIFOS=no],[rsync_cv_MKNOD_CREATES_FIFOS=cross])])
1184 if test x"$rsync_cv_MKNOD_CREATES_FIFOS" = x"yes"; then
1185     AC_DEFINE(MKNOD_CREATES_FIFOS, 1, [Define to 1 if mknod() can create FIFOs.])
1186 fi
1187
1188 AC_CACHE_CHECK([if mknod creates sockets],rsync_cv_MKNOD_CREATES_SOCKETS,[
1189 AC_RUN_IFELSE([AC_LANG_SOURCE([[
1190 #include <stdio.h>
1191 #include <sys/stat.h>
1192 #include <errno.h>
1193 #if HAVE_UNISTD_H
1194 # include <unistd.h>
1195 #endif
1196 int main(void) { int rc, ec; char *fn = "sock-test";
1197 unlink(fn); rc = mknod(fn,S_IFSOCK,0600); ec = errno; unlink(fn);
1198 if (rc) {printf("(%d %d) ",rc,ec); return ec;}
1199 return 0;}]])],[rsync_cv_MKNOD_CREATES_SOCKETS=yes],[rsync_cv_MKNOD_CREATES_SOCKETS=no],[rsync_cv_MKNOD_CREATES_SOCKETS=cross])])
1200 if test x"$rsync_cv_MKNOD_CREATES_SOCKETS" = x"yes"; then
1201     AC_DEFINE(MKNOD_CREATES_SOCKETS, 1, [Define to 1 if mknod() can create sockets.])
1202 fi
1203
1204 #
1205 # The following test was mostly taken from the tcl/tk plus patches
1206 #
1207 AC_CACHE_CHECK([whether -c -o works],rsync_cv_DASHC_WORKS_WITH_DASHO,[
1208 rm -rf conftest*
1209 cat > conftest.$ac_ext <<EOF
1210 int main(void) { return 0; }
1211 EOF
1212 ${CC-cc} -c -o conftest..o conftest.$ac_ext
1213 if test -f conftest..o; then
1214     rsync_cv_DASHC_WORKS_WITH_DASHO=yes
1215 else
1216     rsync_cv_DASHC_WORKS_WITH_DASHO=no
1217 fi
1218 rm -rf conftest*
1219 ])
1220 if test x"$rsync_cv_DASHC_WORKS_WITH_DASHO" = x"yes"; then
1221     OBJ_SAVE="#"
1222     OBJ_RESTORE="#"
1223     CC_SHOBJ_FLAG='-o $@'
1224 else
1225     OBJ_SAVE='  @b=`basename $@ .o`;rm -f $$b.o.sav;if test -f $$b.o; then mv $$b.o $$b.o.sav;fi;'
1226     OBJ_RESTORE='       @b=`basename $@ .o`;if test "$$b.o" != "$@"; then mv $$b.o $@; if test -f $$b.o.sav; then mv $$b.o.sav $$b.o; fi; fi'
1227     CC_SHOBJ_FLAG=""
1228 fi
1229
1230 AC_SUBST(OBJ_SAVE)
1231 AC_SUBST(OBJ_RESTORE)
1232 AC_SUBST(CC_SHOBJ_FLAG)
1233 AC_SUBST(BUILD_POPT)
1234 AC_SUBST(BUILD_ZLIB)
1235 AC_SUBST(MAKE_MAN)
1236
1237 AC_CHECK_FUNCS(_acl __acl _facl __facl)
1238 #################################################
1239 # check for ACL support
1240
1241 AC_MSG_CHECKING([whether to support ACLs])
1242 AC_ARG_ENABLE(acl-support,
1243         AS_HELP_STRING([--disable-acl-support],[disable ACL support]))
1244
1245 if test x"$enable_acl_support" = x"no"; then
1246     AC_MSG_RESULT(no)
1247 else
1248     case "$host_os" in
1249     *sysv5*)
1250         AC_MSG_RESULT(Using UnixWare ACLs)
1251         AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1252         AC_DEFINE(SUPPORT_ACLS, 1, [Define to 1 to add support for ACLs])
1253         ;;
1254     solaris*)
1255         AC_MSG_RESULT(Using solaris ACLs)
1256         AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1257         AC_DEFINE(SUPPORT_ACLS, 1)
1258         ;;
1259     *irix*)
1260         AC_MSG_RESULT(Using IRIX ACLs)
1261         AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1262         AC_DEFINE(SUPPORT_ACLS, 1)
1263         ;;
1264     *aix*)
1265         AC_MSG_RESULT(Using AIX ACLs)
1266         AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1267         AC_DEFINE(SUPPORT_ACLS, 1)
1268         ;;
1269     *osf*)
1270         AC_MSG_RESULT(Using Tru64 ACLs)
1271         AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1272         AC_DEFINE(SUPPORT_ACLS, 1)
1273         LIBS="$LIBS -lpacl"
1274         ;;
1275     darwin*)
1276         AC_MSG_RESULT(Using OS X ACLs)
1277         AC_DEFINE(HAVE_OSX_ACLS, 1, [true if you have Mac OS X ACLs])
1278         AC_DEFINE(SUPPORT_ACLS, 1)
1279         ;;
1280     *hpux*|*nsk*)
1281         AC_MSG_RESULT(Using HPUX ACLs)
1282         AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1283         AC_DEFINE(SUPPORT_ACLS, 1)
1284         ;;
1285     *)
1286         AC_MSG_RESULT(running tests:)
1287         AC_CHECK_LIB(acl,acl_get_file)
1288         AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1289             AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1290 #ifdef HAVE_SYS_TYPES_H
1291 #include <sys/types.h>
1292 #endif
1293 #ifdef HAVE_SYS_ACL_H
1294 #include <sys/acl.h>
1295 #endif]], [[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);]])],[samba_cv_HAVE_POSIX_ACLS=yes],[samba_cv_HAVE_POSIX_ACLS=no])])
1296         AC_MSG_CHECKING(ACL test results)
1297         if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1298             AC_MSG_RESULT(Using posix ACLs)
1299             AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1300             AC_DEFINE(SUPPORT_ACLS, 1)
1301             AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1302                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1303 #ifdef HAVE_SYS_TYPES_H
1304 #include <sys/types.h>
1305 #endif
1306 #ifdef HAVE_SYS_ACL_H
1307 #include <sys/acl.h>
1308 #endif]], [[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);]])],[samba_cv_HAVE_ACL_GET_PERM_NP=yes],[samba_cv_HAVE_ACL_GET_PERM_NP=no])])
1309             if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1310                 AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1311             fi
1312         else
1313             if test x"$enable_acl_support" = x"yes"; then
1314                 AC_MSG_ERROR(Failed to find ACL support)
1315             else
1316                 AC_MSG_RESULT(No ACL support found)
1317             fi
1318         fi
1319         ;;
1320     esac
1321 fi
1322
1323 #################################################
1324 # check for extended attribute support
1325 AC_MSG_CHECKING(whether to support extended attributes)
1326 AC_ARG_ENABLE(xattr-support,
1327     AS_HELP_STRING([--disable-xattr-support],[disable extended attributes]),
1328     [], [case "$ac_cv_func_getxattr$ac_cv_func_extattr_get_link$ac_cv_func_attropen" in
1329         *yes*) enable_xattr_support=maybe ;;
1330         *) enable_xattr_support=no ;;
1331         esac])
1332 AH_TEMPLATE([SUPPORT_XATTRS],
1333 [Define to 1 to add support for extended attributes])
1334 if test x"$enable_xattr_support" = x"no"; then
1335     AC_MSG_RESULT(no)
1336 else
1337     case "$host_os" in
1338     *linux*|*netbsd*|*cygwin*)
1339         AC_MSG_RESULT(Using Linux xattrs)
1340         AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs (or equivalent)])
1341         AC_DEFINE(SUPPORT_XATTRS, 1)
1342         AC_DEFINE(NO_SYMLINK_USER_XATTRS, 1, [True if symlinks do not support user xattrs])
1343         AC_CHECK_LIB(attr,getxattr)
1344         ;;
1345     darwin*)
1346         AC_MSG_RESULT(Using OS X xattrs)
1347         AC_DEFINE(HAVE_OSX_XATTRS, 1, [True if you have Mac OS X xattrs])
1348         AC_DEFINE(SUPPORT_XATTRS, 1)
1349         AC_DEFINE(NO_DEVICE_XATTRS, 1, [True if device files do not support xattrs])
1350         AC_DEFINE(NO_SPECIAL_XATTRS, 1, [True if special files do not support xattrs])
1351         ;;
1352     freebsd*)
1353         AC_MSG_RESULT(Using FreeBSD extattrs)
1354         AC_DEFINE(HAVE_FREEBSD_XATTRS, 1, [True if you have FreeBSD xattrs])
1355         AC_DEFINE(SUPPORT_XATTRS, 1)
1356         ;;
1357     solaris*)
1358         AC_MSG_RESULT(Using Solaris xattrs)
1359         AC_DEFINE(HAVE_SOLARIS_XATTRS, 1, [True if you have Solaris xattrs])
1360         AC_DEFINE(SUPPORT_XATTRS, 1)
1361         AC_DEFINE(NO_SYMLINK_XATTRS, 1, [True if symlinks do not support xattrs])
1362         ;;
1363     *)
1364         if test x"$enable_xattr_support" = x"yes"; then
1365             AC_MSG_ERROR(Failed to find extended attribute support)
1366         else
1367             AC_MSG_RESULT(No extended attribute support found)
1368         fi
1369         ;;
1370     esac
1371 fi
1372
1373 if test x"$enable_acl_support" = x"no" -o x"$enable_xattr_support" = x"no" -o x"$enable_iconv" = x"no"; then
1374     AC_MSG_CHECKING([whether $CC supports -Wno-unused-parameter])
1375     OLD_CFLAGS="$CFLAGS"
1376     CFLAGS="$CFLAGS -Wno-unused-parameter"
1377     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[printf("hello\n");]])],[rsync_warn_flag=yes],[rsync_warn_flag=no])
1378     AC_MSG_RESULT([$rsync_warn_flag])
1379     if test x"$rsync_warn_flag" = x"no"; then
1380         CFLAGS="$OLD_CFLAGS"
1381     fi
1382 fi
1383
1384 case "$CC" in
1385 ' checker'*|checker*)
1386     AC_DEFINE(FORCE_FD_ZERO_MEMSET, 1, [Used to make "checker" understand that FD_ZERO() clears memory.])
1387     ;;
1388 esac
1389
1390 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1391 AC_OUTPUT
1392
1393 AC_MSG_RESULT()
1394 AC_MSG_RESULT([    rsync $PACKAGE_VERSION configuration successful])
1395 AC_MSG_RESULT()