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