Use the new ICONV_CONST definition.
[rsync/rsync.git] / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2
3 AC_INIT()
4 AC_CONFIG_SRCDIR([byteorder.h])
5 AC_CONFIG_HEADER(config.h)
6 AC_PREREQ(2.59)
7
8 RSYNC_VERSION=3.0.0cvs
9 AC_SUBST(RSYNC_VERSION)
10 AC_MSG_NOTICE([Configuring rsync $RSYNC_VERSION])
11
12 AC_DEFINE_UNQUOTED(RSYNC_VERSION, ["$RSYNC_VERSION"], [rsync release version])
13
14 LDFLAGS=${LDFLAGS-""}
15
16 AC_CANONICAL_TARGET([])
17
18 dnl Checks for programs.
19 AC_PROG_CC
20 AC_PROG_CPP
21 AC_PROG_EGREP
22 AC_PROG_INSTALL
23 AC_PROG_CC_STDC
24 AC_SUBST(SHELL)
25
26 AC_DEFINE([_GNU_SOURCE], 1,
27           [Define _GNU_SOURCE so that we get all necessary prototypes])
28
29 if test x"$ac_cv_prog_cc_stdc" = x"no"; then
30         AC_MSG_WARN([rsync requires an ANSI C compiler and you don't seem to have one])
31 fi
32
33 # We must decide this before testing the compiler.
34
35 # Please allow this to default to yes, so that your users have more
36 # chance of getting a useful stack trace if problems occur.
37
38 AC_MSG_CHECKING([whether to include debugging symbols])
39 AC_ARG_ENABLE(debug,
40         AC_HELP_STRING([--disable-debug],
41                 [turn off debugging symbols and features]))
42
43 if test x"$enable_debug" = x"no"; then
44     AC_MSG_RESULT(no)
45     CFLAGS=${CFLAGS-"-O"}
46 else
47     AC_MSG_RESULT([yes])
48     # leave CFLAGS alone; AC_PROG_CC will try to include -g if it can
49     dnl AC_DEFINE(DEBUG, 1, [Define to turn on debugging code that may slow normal operation])
50     dnl CFLAGS=${CFLAGS-"-g"}
51 fi
52
53
54 AC_ARG_ENABLE(profile,
55         AC_HELP_STRING([--enable-profile],
56                 [turn on CPU profiling]))
57 if test x"$enable_profile" = x"yes"; then
58         CFLAGS="$CFLAGS -pg"
59 fi
60
61
62 # Specifically, this turns on panic_action handling.
63 AC_ARG_ENABLE(maintainer-mode,
64         AC_HELP_STRING([--enable-maintainer-mode],
65                 [turn on extra debug features]))
66 if test x"$enable_maintainer_mode" = x"yes"; then
67         CFLAGS="$CFLAGS -DMAINTAINER_MODE"
68 fi
69
70
71 # This is needed for our included version of popt.  Kind of silly, but
72 # I don't want our version too far out of sync.
73 CFLAGS="$CFLAGS -DHAVE_CONFIG_H"
74
75 # If GCC, turn on warnings.
76 if test x"$GCC" = x"yes"; then
77         CFLAGS="$CFLAGS -Wall -W"
78 fi
79
80 AC_ARG_WITH(included-popt,
81         AC_HELP_STRING([--with-included-popt], [use bundled popt library, not from system]))
82
83 AC_ARG_WITH(rsync-path,
84         AC_HELP_STRING([--with-rsync-path=PATH], [set default --rsync-path to PATH (default: rsync)]),
85         [ RSYNC_PATH="$with_rsync_path" ],
86         [ RSYNC_PATH="rsync" ])
87
88 AC_DEFINE_UNQUOTED(RSYNC_PATH, "$RSYNC_PATH", [location of rsync on remote machine])
89
90 AC_ARG_WITH(rsyncd-conf,
91         AC_HELP_STRING([--with-rsyncd-conf=PATH], [set configuration file for rsync server to PATH (default: /etc/rsyncd.conf)]),
92         [ if test ! -z "$with_rsyncd_conf" ; then
93                 case $with_rsyncd_conf in
94                         yes|no)
95                                 RSYNCD_SYSCONF="/etc/rsyncd.conf"
96                                 ;;
97                         /*)
98                                 RSYNCD_SYSCONF="$with_rsyncd_conf"
99                                 ;;
100                         *)
101                                 AC_MSG_ERROR(You must specify an absolute path to --with-rsyncd-conf=PATH)
102                                 ;;
103                 esac
104         else
105                 RSYNCD_SYSCONF="/etc/rsyncd.conf"
106         fi ],
107         [ RSYNCD_SYSCONF="/etc/rsyncd.conf" ])
108
109 AC_DEFINE_UNQUOTED(RSYNCD_SYSCONF, "$RSYNCD_SYSCONF", [location of configuration file for rsync server])
110
111 AC_ARG_WITH(rsh,
112         AC_HELP_STRING([--with-rsh=CMD], [set remote shell command to CMD (default: ssh)]))
113
114 AC_CHECK_PROG(HAVE_REMSH, remsh, 1, 0)
115 if test x$HAVE_REMSH = x1; then
116         AC_DEFINE(HAVE_REMSH, 1, [Define to 1 if remote shell is remsh, not rsh])
117 fi
118
119 if test x"$with_rsh" != x; then
120         RSYNC_RSH="$with_rsh"
121 else
122         RSYNC_RSH="ssh"
123 fi
124 AC_DEFINE_UNQUOTED(RSYNC_RSH, "$RSYNC_RSH", [default -e command])
125
126 AC_ARG_WITH(nobody-group,
127     AC_HELP_STRING([--with-nobody-group=GROUP],
128                    [set the default unprivileged group (default nobody or nogroup)]),
129     [ NOBODY_GROUP="$with_nobody_group" ])
130
131 if test x"$with_nobody_group" = x; then
132     AC_MSG_CHECKING([the group for user "nobody"])
133     if grep '^nobody:' /etc/group >/dev/null 2>&1; then
134         NOBODY_GROUP=nobody
135     elif grep '^nogroup:' /etc/group >/dev/null 2>&1; then
136         NOBODY_GROUP=nogroup
137     else
138         NOBODY_GROUP=nobody # test for others?
139     fi
140     AC_MSG_RESULT($NOBODY_GROUP)
141 fi
142
143 AC_DEFINE_UNQUOTED(NOBODY_USER, "nobody", [unprivileged user--e.g. nobody])
144 AC_DEFINE_UNQUOTED(NOBODY_GROUP, "$NOBODY_GROUP", [unprivileged group for unprivileged user])
145
146 # arrgh. libc in some old debian version screwed up the largefile
147 # stuff, getting byte range locking wrong
148 AC_CACHE_CHECK([for broken largefile support],rsync_cv_HAVE_BROKEN_LARGEFILE,[
149 AC_TRY_RUN([
150 #define _FILE_OFFSET_BITS 64
151 #include <stdio.h>
152 #include <fcntl.h>
153 #include <sys/types.h>
154 #include <sys/wait.h>
155
156 int main(void)
157 {
158         struct flock lock;
159         int status;
160         char tpl[32] = "/tmp/locktest.XXXXXX";
161         int fd = mkstemp(tpl);
162         if (fd < 0) {
163                 strcpy(tpl, "conftest.dat");
164                 fd = open(tpl, O_CREAT|O_RDWR, 0600);
165         }
166
167         lock.l_type = F_WRLCK;
168         lock.l_whence = SEEK_SET;
169         lock.l_start = 0;
170         lock.l_len = 1;
171         lock.l_pid = 0;
172         fcntl(fd,F_SETLK,&lock);
173         if (fork() == 0) {
174                 lock.l_start = 1;
175                 _exit(fcntl(fd,F_SETLK,&lock) == 0);
176         }
177         wait(&status);
178         unlink(tpl);
179         exit(WEXITSTATUS(status));
180 }
181 ],
182 rsync_cv_HAVE_BROKEN_LARGEFILE=yes,rsync_cv_HAVE_BROKEN_LARGEFILE=no,rsync_cv_HAVE_BROKEN_LARGEFILE=cross)])
183 if test x"$rsync_cv_HAVE_BROKEN_LARGEFILE" != x"yes"; then
184    AC_SYS_LARGEFILE
185 fi
186
187 ipv6type=unknown
188 ipv6lib=none
189 ipv6trylibc=yes
190
191 AC_ARG_ENABLE(ipv6,
192         AC_HELP_STRING([--disable-ipv6],
193                 [don't even try to use IPv6]))
194 if test x"$enable_ipv6" != x"no"; then
195         AC_MSG_CHECKING([ipv6 stack type])
196         for i in inria kame linux-glibc linux-inet6 toshiba v6d zeta; do
197                 case $i in
198                 inria)
199                         # http://www.kame.net/
200                         AC_EGREP_CPP(yes, [
201 #include <netinet/in.h>
202 #ifdef IPV6_INRIA_VERSION
203 yes
204 #endif],
205                                 [ipv6type=$i;
206                                 AC_DEFINE(INET6, 1, [true if you have IPv6])
207                                 ])
208                         ;;
209                 kame)
210                         # http://www.kame.net/
211                         AC_EGREP_CPP(yes, [
212 #include <netinet/in.h>
213 #ifdef __KAME__
214 yes
215 #endif],
216                                 [ipv6type=$i;
217                                 AC_DEFINE(INET6, 1, [true if you have IPv6])])
218                         ;;
219                 linux-glibc)
220                         # http://www.v6.linux.or.jp/
221                         AC_EGREP_CPP(yes, [
222 #include <features.h>
223 #if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
224 yes
225 #endif],
226                                 [ipv6type=$i;
227 AC_DEFINE(INET6, 1, [true if you have IPv6])])
228                         ;;
229                 linux-inet6)
230                         # http://www.v6.linux.or.jp/
231                         if test -d /usr/inet6 -o -f /usr/inet6/lib/libinet6.a; then
232                                 ipv6type=$i
233                                 ipv6lib=inet6
234                                 ipv6libdir=/usr/inet6/lib
235                                 ipv6trylibc=yes;
236                                 AC_DEFINE(INET6, 1, [true if you have IPv6])
237                                 CFLAGS="-I/usr/inet6/include $CFLAGS"
238                         fi
239                         ;;
240                 toshiba)
241                         AC_EGREP_CPP(yes, [
242 #include <sys/param.h>
243 #ifdef _TOSHIBA_INET6
244 yes
245 #endif],
246                                 [ipv6type=$i;
247                                 ipv6lib=inet6;
248                                 ipv6libdir=/usr/local/v6/lib;
249                                 AC_DEFINE(INET6, 1, [true if you have IPv6])])
250                         ;;
251                 v6d)
252                         AC_EGREP_CPP(yes, [
253 #include </usr/local/v6/include/sys/v6config.h>
254 #ifdef __V6D__
255 yes
256 #endif],
257                                 [ipv6type=$i;
258                                 ipv6lib=v6;
259                                 ipv6libdir=/usr/local/v6/lib;
260                                 AC_DEFINE(INET6, 1, [true if you have IPv6])])
261                         ;;
262                 zeta)
263                         AC_EGREP_CPP(yes, [
264 #include <sys/param.h>
265 #ifdef _ZETA_MINAMI_INET6
266 yes
267 #endif],
268                                 [ipv6type=$i;
269                                 ipv6lib=inet6;
270                                 ipv6libdir=/usr/local/v6/lib;
271                                 AC_DEFINE(INET6, 1, [true if you have IPv6])])
272                         ;;
273                 esac
274                 if test "$ipv6type" != "unknown"; then
275                         break
276                 fi
277         done
278         AC_MSG_RESULT($ipv6type)
279
280         AC_SEARCH_LIBS(getaddrinfo, inet6)
281 fi
282
283 dnl Do you want to disable use of locale functions
284 AC_ARG_ENABLE([locale],
285         AC_HELP_STRING([--disable-locale],
286                 [turn off locale features]))
287 AH_TEMPLATE([CONFIG_LOCALE],
288 [Undefine if you don't want locale features.  By default this is defined.])
289 if test x"$enable_locale" != x"no"; then
290         AC_DEFINE(CONFIG_LOCALE)
291 fi
292
293 AC_MSG_CHECKING([whether to call shutdown on all sockets])
294 case $host_os in
295         *cygwin* ) AC_MSG_RESULT(yes)
296                    AC_DEFINE(SHUTDOWN_ALL_SOCKETS, 1,
297                             [Define to 1 if sockets need to be shutdown])
298                    ;;
299                * ) AC_MSG_RESULT(no);;
300 esac
301
302 AC_C_BIGENDIAN
303 AC_HEADER_DIRENT
304 AC_HEADER_TIME
305 AC_HEADER_SYS_WAIT
306 AC_CHECK_HEADERS(sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h \
307     unistd.h utime.h grp.h compat.h sys/param.h ctype.h sys/wait.h \
308     sys/ioctl.h sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h \
309     sys/un.h glob.h mcheck.h arpa/inet.h arpa/nameser.h locale.h \
310     netdb.h malloc.h float.h limits.h iconv.h libcharset.h langinfo.h)
311 AC_HEADER_MAJOR
312
313 AC_CACHE_CHECK([if makedev takes 3 args],rsync_cv_MAKEDEV_TAKES_3_ARGS,[
314 AC_TRY_RUN([
315 #include <sys/types.h>
316 #ifdef MAJOR_IN_MKDEV
317 #include <sys/mkdev.h>
318 # if !defined makedev && (defined mkdev || defined _WIN32 || defined __WIN32__)
319 #  define makedev mkdev
320 # endif
321 #elif defined MAJOR_IN_SYSMACROS
322 #include <sys/sysmacros.h>
323 #endif
324
325 int main(void)
326 {
327         dev_t dev = makedev(0, 5, 7);
328         if (major(dev) != 5 || minor(dev) != 7)
329                 exit(1);
330         return 0;
331 }
332 ],
333 rsync_cv_MAKEDEV_TAKES_3_ARGS=yes,rsync_cv_MAKEDEV_TAKES_3_ARGS=no,rsync_cv_MAKEDEV_TAKES_3_ARGS=no)])
334 if test x"$rsync_cv_MAKEDEV_TAKES_3_ARGS" = x"yes"; then
335    AC_DEFINE(MAKEDEV_TAKES_3_ARGS, 1, [Define to 1 if makedev() takes 3 args])
336 fi
337
338 AC_CHECK_SIZEOF(int)
339 AC_CHECK_SIZEOF(long)
340 AC_CHECK_SIZEOF(long long)
341 AC_CHECK_SIZEOF(short)
342 AC_CHECK_SIZEOF(off_t)
343 AC_CHECK_SIZEOF(off64_t)
344
345 AC_C_INLINE
346 AC_C_LONG_DOUBLE
347
348 AC_TYPE_SIGNAL
349 AC_TYPE_UID_T
350 AC_TYPE_MODE_T
351 AC_TYPE_OFF_T
352 AC_TYPE_SIZE_T
353 AC_TYPE_PID_T
354 AC_TYPE_GETGROUPS
355 AC_CHECK_MEMBERS([struct stat.st_rdev])
356
357 TYPE_SOCKLEN_T
358
359 AC_CACHE_CHECK([for errno in errno.h],rsync_cv_errno, [
360     AC_TRY_COMPILE([#include <errno.h>],[int i = errno],
361         rsync_cv_errno=yes,rsync_cv_have_errno_decl=no)])
362 if test x"$rsync_cv_errno" = x"yes"; then
363    AC_DEFINE(HAVE_ERRNO_DECL, 1, [Define to 1 if errno is declared in errno.h])
364 fi
365
366 # The following test taken from the cvs sources
367 # If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
368 # These need checks to be before checks for any other functions that
369 #    might be in the same libraries.
370 # The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
371 # libsocket.so which has a bad implementation of gethostbyname (it
372 # only looks in /etc/hosts), so we only look for -lsocket if we need
373 # it.
374 AC_CHECK_FUNCS(connect)
375 if test x"$ac_cv_func_connect" = x"no"; then
376     case "$LIBS" in
377     *-lnsl*) ;;
378     *) AC_CHECK_LIB(nsl_s, printf) ;;
379     esac
380     case "$LIBS" in
381     *-lnsl*) ;;
382     *) AC_CHECK_LIB(nsl, printf) ;;
383     esac
384     case "$LIBS" in
385     *-lsocket*) ;;
386     *) AC_CHECK_LIB(socket, connect) ;;
387     esac
388     case "$LIBS" in
389     *-linet*) ;;
390     *) AC_CHECK_LIB(inet, connect) ;;
391     esac
392     dnl We can't just call AC_CHECK_FUNCS(connect) here, because the value
393     dnl has been cached.
394     if test x"$ac_cv_lib_socket_connect" = x"yes" ||
395        test x"$ac_cv_lib_inet_connect" = x"yes"; then
396         # ac_cv_func_connect=yes
397         # don't!  it would cause AC_CHECK_FUNC to succeed next time configure is run
398         AC_DEFINE(HAVE_CONNECT, 1, [Define to 1 if you have the "connect" function])
399     fi
400 fi
401
402 AC_SEARCH_LIBS(inet_ntop, resolv)
403
404 # Solaris and HP-UX weirdness:
405 # Search for libiconv_open (not iconv_open) to discover if -liconv is needed!
406 AC_SEARCH_LIBS(libiconv_open, iconv)
407
408 if test "$am_cv_func_iconv" = yes; then
409     AC_MSG_CHECKING([for iconv declaration])
410     AC_CACHE_VAL(am_cv_proto_iconv, [
411       AC_TRY_COMPILE([
412 #include <stdlib.h>
413 #include <iconv.h>
414 extern
415 #ifdef __cplusplus
416 "C"
417 #endif
418 #if defined(__STDC__) || defined(__cplusplus)
419 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
420 #else
421 size_t iconv();
422 #endif
423 ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
424       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);"])
425     am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
426     AC_MSG_RESULT([$]{ac_t:-
427          }[$]am_cv_proto_iconv)
428     AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
429       [Define as const if the declaration of iconv() needs const.])
430 fi
431
432 dnl AC_MSG_NOTICE([Looking in libraries: $LIBS])
433
434 AC_CHECK_FUNCS(inet_ntop, , [AC_LIBOBJ(lib/inet_ntop)])
435 AC_CHECK_FUNCS(inet_pton, , [AC_LIBOBJ(lib/inet_pton)])
436
437 # Irix 6.5 has getaddrinfo but not the corresponding defines, so use
438 #   builtin getaddrinfo if one of the defines don't exist
439 AC_CACHE_CHECK([whether defines needed by getaddrinfo exist],
440                rsync_cv_HAVE_GETADDR_DEFINES,[
441                         AC_EGREP_CPP(yes, [
442                         #include <sys/types.h>
443                         #include <sys/socket.h>
444                         #include <netdb.h>
445                         #ifdef AI_PASSIVE
446                         yes
447                         #endif],
448                         rsync_cv_HAVE_GETADDR_DEFINES=yes,
449                         rsync_cv_HAVE_GETADDR_DEFINES=no)])
450 if test x"$rsync_cv_HAVE_GETADDR_DEFINES" = x"yes"; then
451         # Tru64 UNIX has getaddrinfo() but has it renamed in libc as
452         # something else so we must include <netdb.h> to get the
453         # redefinition.
454         AC_CHECK_FUNCS(getaddrinfo, ,
455                 [AC_MSG_CHECKING([for getaddrinfo by including <netdb.h>])
456                 AC_TRY_LINK([#include <sys/types.h>
457                 #include <sys/socket.h>
458                 #include <netdb.h>],[getaddrinfo(NULL, NULL, NULL, NULL);],
459                         [AC_MSG_RESULT([yes])
460                         AC_DEFINE(HAVE_GETADDRINFO, 1,
461                                 [Define to 1 if you have the "getaddrinfo" function.])],
462                         [AC_MSG_RESULT([no])
463                         AC_LIBOBJ(lib/getaddrinfo)])])
464         AC_CHECK_FUNCS(getnameinfo, , [AC_LIBOBJ(lib/getnameinfo)])
465 else
466         AC_LIBOBJ(lib/getaddrinfo)
467         AC_LIBOBJ(lib/getnameinfo)
468 fi
469
470 AC_CHECK_MEMBER([struct sockaddr.sa_len],
471                 [ AC_DEFINE(HAVE_SOCKADDR_LEN, 1, [Do we have sockaddr.sa_len?]) ],
472                 [],
473                 [
474 #include <sys/types.h>
475 #include <sys/socket.h>
476 ])
477
478 AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
479                 [ AC_DEFINE(HAVE_SOCKADDR_IN_LEN, 1, [Do we have sockaddr_in.sin_len?]) ],
480                 [],
481                 [
482 #include <sys/types.h>
483 #include <sys/socket.h>
484 #include <netinet/in.h>
485 ])
486
487 AC_CHECK_MEMBER([struct sockaddr_un.sun_len],
488                 [ AC_DEFINE(HAVE_SOCKADDR_UN_LEN, 1, [Do we have sockaddr_un.sun_len?]) ],
489                 [],
490                 [
491 #include <sys/types.h>
492 #include <sys/socket.h>
493 #include <netinet/in.h>
494 ])
495
496 AC_MSG_CHECKING(struct sockaddr_storage)
497 AC_TRY_COMPILE([#include <sys/types.h>
498 #include <sys/socket.h>],
499 [struct sockaddr_storage x;],
500         AC_MSG_RESULT(yes)
501         AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1,
502                 [Define to 1 if you have struct sockaddr_storage.] ),
503         AC_MSG_RESULT(no))
504
505 AC_CHECK_MEMBER([struct sockaddr_in6.sin6_scope_id],
506                 [ AC_DEFINE(HAVE_SOCKADDR_IN6_SCOPE_ID, 1, [Do we have sockaddr_in6.sin6_scope_id?]) ],
507                 [],
508                 [
509 #include <sys/types.h>
510 #include <sys/socket.h>
511 #include <netinet/in.h>
512 ])
513
514 AC_MSG_CHECKING(struct stat64)
515 AC_TRY_COMPILE([#include <stdio.h>
516 #if HAVE_SYS_TYPES_H
517 # include <sys/types.h>
518 #endif
519 #if HAVE_SYS_STAT_H
520 # include <sys/stat.h>
521 #endif
522 #if STDC_HEADERS
523 # include <stdlib.h>
524 # include <stddef.h>
525 #else
526 # if HAVE_STDLIB_H
527 #  include <stdlib.h>
528 # endif
529 #endif
530 ],[struct stat64 st;],
531     AC_MSG_RESULT(yes)
532         AC_DEFINE(HAVE_STRUCT_STAT64,1,[Define to 1 if you have struct stat64.]),
533     AC_MSG_RESULT(no))
534
535 # if we can't find strcasecmp, look in -lresolv (for Unixware at least)
536 #
537 AC_CHECK_FUNCS(strcasecmp)
538 if test x"$ac_cv_func_strcasecmp" = x"no"; then
539     AC_CHECK_LIB(resolv, strcasecmp)
540 fi
541
542 dnl At the moment we don't test for a broken memcmp(), because all we
543 dnl need to do is test for equality, not comparison, and it seems that
544 dnl every platform has a memcmp that can do at least that.
545 dnl AC_FUNC_MEMCMP
546
547 AC_FUNC_UTIME_NULL
548 AC_FUNC_ALLOCA
549 AC_CHECK_FUNCS(waitpid wait4 getcwd strdup chown chmod lchmod mknod mkfifo \
550     fchmod fstat ftruncate strchr readlink link utime utimes lutimes strftime \
551     memmove lchown vsnprintf snprintf vasprintf asprintf setsid glob strpbrk \
552     strlcat strlcpy strtol mallinfo getgroups setgroups geteuid getegid \
553     setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \
554     strerror putenv iconv_open locale_charset nl_langinfo \
555     sigaction sigprocmask)
556
557 AC_CHECK_FUNCS(getpgrp tcgetpgrp)
558 if test $ac_cv_func_getpgrp = yes; then
559     AC_FUNC_GETPGRP
560 fi
561
562 AC_CACHE_CHECK([whether chown() modifies symlinks],rsync_cv_chown_modifies_symlink,[
563   AC_TRY_RUN([
564 #if HAVE_UNISTD_H
565 # include <unistd.h>
566 #endif
567 #include <stdlib.h>
568 #include <errno.h>
569     main() {
570         char const *dangling_symlink = "conftest.dangle";
571         unlink(dangling_symlink);
572         if (symlink("conftest.no-such", dangling_symlink) < 0) abort();
573         if (chown(dangling_symlink, getuid(), getgid()) < 0 && errno == ENOENT) exit(1);
574         exit(0);
575     }],
576   rsync_cv_chown_modifies_symlink=yes,rsync_cv_chown_modifies_symlink=no,rsync_cv_chown_modifies_symlink=no)])
577 if test $rsync_cv_chown_modifies_symlink = yes; then
578   AC_DEFINE(CHOWN_MODIFIES_SYMLINK, 1, [Define to 1 if chown modifies symlinks.])
579 fi
580
581 AC_CACHE_CHECK([whether link() can hard-link symlinks],rsync_cv_can_hardlink_symlink,[
582   AC_TRY_RUN([
583 #if HAVE_UNISTD_H
584 # include <unistd.h>
585 #endif
586 #include <stdlib.h>
587 #include <errno.h>
588 #define FILENAME "conftest.dangle"
589     main() {
590         unlink(FILENAME);
591         if (symlink("conftest.no-such", FILENAME) < 0) abort();
592         if (link(FILENAME, FILENAME "2") < 0) exit(1);
593         exit(0);
594     }],
595   rsync_cv_can_hardlink_symlink=yes,rsync_cv_can_hardlink_symlink=no,rsync_cv_can_hardlink_symlink=no)])
596 if test $rsync_cv_can_hardlink_symlink = yes; then
597   AC_DEFINE(CAN_HARDLINK_SYMLINK, 1, [Define to 1 if link() can hard-link symlinks.])
598 fi
599
600 AC_CACHE_CHECK([whether link() can hard-link special files],rsync_cv_can_hardlink_special,[
601   AC_TRY_RUN([
602 #if HAVE_UNISTD_H
603 # include <unistd.h>
604 #endif
605 #include <stdlib.h>
606 #include <errno.h>
607 #define FILENAME "conftest.fifi"
608     main() {
609         unlink(FILENAME);
610         if (mkfifo(FILENAME, 0777) < 0) abort();
611         if (link(FILENAME, FILENAME "2") < 0) exit(1);
612         exit(0);
613     }],
614   rsync_cv_can_hardlink_special=yes,rsync_cv_can_hardlink_special=no,rsync_cv_can_hardlink_special=no)])
615 if test $rsync_cv_can_hardlink_special = yes; then
616     AC_DEFINE(CAN_HARDLINK_SPECIAL, 1, [Define to 1 if link() can hard-link special files.])
617 fi
618
619 AC_CACHE_CHECK([for working socketpair],rsync_cv_HAVE_SOCKETPAIR,[
620 AC_TRY_RUN([
621 #include <sys/types.h>
622 #include <sys/socket.h>
623
624 main() {
625        int fd[2];
626        exit((socketpair(AF_UNIX, SOCK_STREAM, 0, fd) != -1) ? 0 : 1);
627 }],
628 rsync_cv_HAVE_SOCKETPAIR=yes,rsync_cv_HAVE_SOCKETPAIR=no,rsync_cv_HAVE_SOCKETPAIR=cross)])
629 if test x"$rsync_cv_HAVE_SOCKETPAIR" = x"yes"; then
630     AC_DEFINE(HAVE_SOCKETPAIR, 1, [Define to 1 if you have the "socketpair" function])
631 fi
632
633 if test x"$with_included_popt" != x"yes"; then
634     AC_CHECK_LIB(popt, poptGetContext, , [with_included_popt=yes])
635 fi
636
637 AC_MSG_CHECKING([whether to use included libpopt])
638 if test x"$with_included_popt" = x"yes"; then
639     AC_MSG_RESULT($srcdir/popt)
640     BUILD_POPT='$(popt_OBJS)'
641     CFLAGS="$CFLAGS -I$srcdir/popt"
642     if test x"$ALLOCA" != x
643     then
644         # this can be removed when/if we add an included alloca.c;
645         #  see autoconf documentation on AC_FUNC_ALLOCA
646         AC_MSG_WARN([included libpopt will use malloc, not alloca (which wastes a small amount of memory)])
647     fi
648 else
649     AC_MSG_RESULT(no)
650 fi
651
652 AC_CACHE_CHECK([for unsigned char],rsync_cv_SIGNED_CHAR_OK,[
653 AC_TRY_COMPILE([],[signed char *s = ""],
654 rsync_cv_SIGNED_CHAR_OK=yes,rsync_cv_SIGNED_CHAR_OK=no)])
655 if test x"$rsync_cv_SIGNED_CHAR_OK" = x"yes"; then
656     AC_DEFINE(SIGNED_CHAR_OK, 1, [Define to 1 if "signed char" is a valid type])
657 fi
658
659 AC_CACHE_CHECK([for broken readdir],rsync_cv_HAVE_BROKEN_READDIR,[
660 AC_TRY_RUN([#include <sys/types.h>
661 #include <dirent.h>
662 main() { struct dirent *di; DIR *d = opendir("."); di = readdir(d);
663 if (di && di->d_name[-2] == '.' && di->d_name[-1] == 0 &&
664 di->d_name[0] == 0) exit(0); exit(1);} ],
665 rsync_cv_HAVE_BROKEN_READDIR=yes,rsync_cv_HAVE_BROKEN_READDIR=no,rsync_cv_HAVE_BROKEN_READDIR=cross)])
666 if test x"$rsync_cv_HAVE_BROKEN_READDIR" = x"yes"; then
667     AC_DEFINE(HAVE_BROKEN_READDIR, 1, [Define to 1 if readdir() is broken])
668 fi
669
670 AC_CACHE_CHECK([for utimbuf],rsync_cv_HAVE_UTIMBUF,[
671 AC_TRY_COMPILE([#include <sys/types.h>
672 #include <utime.h>],
673 [struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));],
674 rsync_cv_HAVE_UTIMBUF=yes,rsync_cv_HAVE_UTIMBUF=no)])
675 if test x"$rsync_cv_HAVE_UTIMBUF" = x"yes"; then
676     AC_DEFINE(HAVE_UTIMBUF, 1, [Define to 1 if you have the "struct utimbuf" type])
677 fi
678
679 AC_CACHE_CHECK([if gettimeofday takes tz argument],rsync_cv_HAVE_GETTIMEOFDAY_TZ,[
680 AC_TRY_COMPILE([#include <sys/time.h>
681 #include <unistd.h>],
682 [struct timeval tv; exit(gettimeofday(&tv, NULL));],
683 rsync_cv_HAVE_GETTIMEOFDAY_TZ=yes,rsync_cv_HAVE_GETTIMEOFDAY_TZ=no)])
684 if test x"$rsync_cv_HAVE_GETTIMEOFDAY_TZ" != x"no"; then
685     AC_DEFINE(HAVE_GETTIMEOFDAY_TZ, 1, [Define to 1 if gettimeofday() takes a time-zone arg])
686 fi
687
688 AC_CACHE_CHECK([for C99 vsnprintf],rsync_cv_HAVE_C99_VSNPRINTF,[
689 AC_TRY_RUN([
690 #include <sys/types.h>
691 #include <stdarg.h>
692 void foo(const char *format, ...) {
693        va_list ap;
694        int len;
695        char buf[5];
696
697        va_start(ap, format);
698        len = vsnprintf(0, 0, format, ap);
699        va_end(ap);
700        if (len != 5) exit(1);
701
702        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
703
704        exit(0);
705 }
706 main() { foo("hello"); }
707 ],
708 rsync_cv_HAVE_C99_VSNPRINTF=yes,rsync_cv_HAVE_C99_VSNPRINTF=no,rsync_cv_HAVE_C99_VSNPRINTF=cross)])
709 if test x"$rsync_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
710     AC_DEFINE(HAVE_C99_VSNPRINTF, 1, [Define to 1 if vsprintf has a C99-compatible return value])
711 fi
712
713
714 AC_CACHE_CHECK([for secure mkstemp],rsync_cv_HAVE_SECURE_MKSTEMP,[
715 AC_TRY_RUN([#include <stdlib.h>
716 #include <sys/types.h>
717 #include <sys/stat.h>
718 #include <unistd.h>
719 main() {
720   struct stat st;
721   char tpl[20]="/tmp/test.XXXXXX";
722   int fd = mkstemp(tpl);
723   if (fd == -1) exit(1);
724   unlink(tpl);
725   if (fstat(fd, &st) != 0) exit(1);
726   if ((st.st_mode & 0777) != 0600) exit(1);
727   exit(0);
728 }],
729 rsync_cv_HAVE_SECURE_MKSTEMP=yes,
730 rsync_cv_HAVE_SECURE_MKSTEMP=no,
731 rsync_cv_HAVE_SECURE_MKSTEMP=cross)])
732 if test x"$rsync_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
733     case $target_os in
734     hpux*)
735         dnl HP-UX has a broken mkstemp() implementation they refuse to fix,
736         dnl so we noisily skip using it.  See HP change request JAGaf34426
737         dnl for details. (sbonds)
738         AC_MSG_WARN(Skipping broken HP-UX mkstemp() -- using mktemp() instead)
739         ;;
740     *)
741         AC_DEFINE(HAVE_SECURE_MKSTEMP, 1, [Define to 1 if mkstemp() is available and works right])
742         ;;
743     esac
744 fi
745
746
747 AC_CACHE_CHECK([if mknod creates FIFOs],rsync_cv_MKNOD_CREATES_FIFOS,[
748 AC_TRY_RUN([
749 #include <stdio.h>
750 #include <sys/stat.h>
751 #include <errno.h>
752 main() { int rc, ec; char *fn = "fifo-test";
753 unlink(fn); rc = mknod(fn,S_IFIFO,0600); ec = errno; unlink(fn);
754 if (rc) {printf("(%d %d) ",rc,ec); return ec;}
755 return 0;}],
756            rsync_cv_MKNOD_CREATES_FIFOS=yes,rsync_cv_MKNOD_CREATES_FIFOS=no,rsync_cv_MKNOD_CREATES_FIFOS=cross)])
757 if test x"$rsync_cv_MKNOD_CREATES_FIFOS" = x"yes"; then
758     AC_DEFINE(MKNOD_CREATES_FIFOS, 1, [Define to 1 if mknod() can create FIFOs.])
759 fi
760
761 AC_CACHE_CHECK([if mknod creates sockets],rsync_cv_MKNOD_CREATES_SOCKETS,[
762 AC_TRY_RUN([
763 #include <stdio.h>
764 #include <sys/stat.h>
765 #include <errno.h>
766 main() { int rc, ec; char *fn = "sock-test";
767 unlink(fn); rc = mknod(fn,S_IFSOCK,0600); ec = errno; unlink(fn);
768 if (rc) {printf("(%d %d) ",rc,ec); return ec;}
769 return 0;}],
770            rsync_cv_MKNOD_CREATES_SOCKETS=yes,rsync_cv_MKNOD_CREATES_SOCKETS=no,rsync_cv_MKNOD_CREATES_SOCKETS=cross)])
771 if test x"$rsync_cv_MKNOD_CREATES_SOCKETS" = x"yes"; then
772     AC_DEFINE(MKNOD_CREATES_SOCKETS, 1, [Define to 1 if mknod() can create sockets.])
773 fi
774
775 #
776 # The following test was mostly taken from the tcl/tk plus patches
777 #
778 AC_CACHE_CHECK([whether -c -o works],rsync_cv_DASHC_WORKS_WITH_DASHO,[
779 rm -rf conftest*
780 cat > conftest.$ac_ext <<EOF
781 int main() { return 0; }
782 EOF
783 ${CC-cc} -c -o conftest..o conftest.$ac_ext
784 if test -f conftest..o; then
785     rsync_cv_DASHC_WORKS_WITH_DASHO=yes
786 else
787     rsync_cv_DASHC_WORKS_WITH_DASHO=no
788 fi
789 rm -rf conftest*
790 ])
791 if test x"$rsync_cv_DASHC_WORKS_WITH_DASHO" = x"yes"; then
792     OBJ_SAVE="#"
793     OBJ_RESTORE="#"
794     CC_SHOBJ_FLAG='-o $@'
795 else
796     OBJ_SAVE='  @b=`basename $@ .o`;rm -f $$b.o.sav;if test -f $$b.o; then mv $$b.o $$b.o.sav;fi;'
797     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'
798     CC_SHOBJ_FLAG=""
799 fi
800
801 AC_SUBST(OBJ_SAVE)
802 AC_SUBST(OBJ_RESTORE)
803 AC_SUBST(CC_SHOBJ_FLAG)
804 AC_SUBST(BUILD_POPT)
805
806 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
807 AC_OUTPUT
808
809 AC_MSG_RESULT()
810 AC_MSG_RESULT([    rsync ${RSYNC_VERSION} configuration successful])
811 AC_MSG_RESULT()