Try to fix LIBOBJ detection of ntop/pton.
[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.52)
7
8 LDFLAGS=${LDFLAGS-""}
9
10 AC_CANONICAL_TARGET([])
11
12 dnl Checks for programs.
13 AC_PROG_CC
14 AC_PROG_CPP
15 AC_PROG_INSTALL
16 AC_SUBST(SHELL)
17
18 RSYNC_VERSION=2.4.7pre3
19 AC_SUBST(RSYNC_VERSION)
20 AC_DEFINE_UNQUOTED(RSYNC_VERSION, ["$RSYNC_VERSION"], [rsync release version])
21
22 # compile with optimisation and without debugging by default, unless
23 # --debug is given.  We must decide this before testing the compiler.
24
25 AC_MSG_CHECKING([whether to include debugging symbols])
26 AC_ARG_ENABLE(debug,
27         AC_HELP_STRING([--enable-debug],
28                 [including debugging symbols and features (default yes)]),
29                 [], [])
30
31 if test x"$enable_debug" = x"no"
32 then
33     AC_MSG_RESULT(no)
34     CFLAGS=${CFLAGS-"-O"}
35 else
36     AC_MSG_RESULT([yes])
37     # leave CFLAGS alone; AC_PROG_CC will try to include -g if it can
38     AC_DEFINE(DEBUG, 1, [Define to turn on debugging code that may slow normal operation])
39     dnl CFLAGS=${CFLAGS-"-g"}
40 fi
41
42 CFLAGS="$CFLAGS -DHAVE_CONFIG_H"
43
44 AC_ARG_WITH(included-popt,
45         [  --with-included-popt    use bundled popt library, not from system])
46
47 AC_ARG_WITH(rsync-path,
48         [  --with-rsync-path=PATH  set default --rsync-path to PATH (default: \"rsync\")],
49         [ RSYNC_PATH="$with_rsync_path" ],
50         [ RSYNC_PATH="rsync" ])
51 AC_DEFINE_UNQUOTED(RSYNC_PATH, "$RSYNC_PATH", [ ])
52
53 AC_CHECK_PROG(HAVE_REMSH, remsh, 1, 0)
54 AC_DEFINE_UNQUOTED(HAVE_REMSH, $HAVE_REMSH, [ ])
55
56
57 # arrgh. libc in the current debian stable screws up the largefile
58 # stuff, getting byte range locking wrong
59 AC_CACHE_CHECK([for broken largefile support],rsync_cv_HAVE_BROKEN_LARGEFILE,[
60 AC_TRY_RUN([
61 #define _FILE_OFFSET_BITS 64
62 #include <stdio.h>
63 #include <fcntl.h>
64 #include <sys/types.h>
65 #include <sys/wait.h>
66
67 int main(void) 
68 {
69         struct flock lock;
70         int status;
71         int fd = open("conftest.dat", O_CREAT|O_RDWR, 0600);
72         lock.l_type = F_WRLCK;
73         lock.l_whence = SEEK_SET;
74         lock.l_start = 0;
75         lock.l_len = 1;
76         lock.l_pid = 0;
77         
78         fcntl(fd,F_SETLK,&lock);
79         if (fork() == 0) {
80                 lock.l_start = 1;               
81                 exit(fcntl(fd,F_SETLK,&lock) == 0);
82         }
83         wait(&status);
84         unlink("conftest.dat");
85         exit(WEXITSTATUS(status));
86 }
87 ],
88 rsync_cv_HAVE_BROKEN_LARGEFILE=yes,rsync_cv_HAVE_BROKEN_LARGEFILE=no,rsync_cv_HAVE_BROKEN_LARGEFILE=cross)])
89 if test x"$rsync_cv_HAVE_BROKEN_LARGEFILE" != x"yes"; then
90    AC_SYS_LARGEFILE
91 fi
92
93 ipv6type=unknown
94 ipv6lib=none
95 ipv6trylibc=yes
96
97         AC_MSG_CHECKING([ipv6 stack type])
98         for i in inria kame linux-glibc linux-inet6 toshiba v6d zeta; do
99                 case $i in
100                 inria)
101                         # http://www.kame.net/
102                         AC_EGREP_CPP(yes, [
103 #include <netinet/in.h>
104 #ifdef IPV6_INRIA_VERSION
105 yes
106 #endif],
107                                 [ipv6type=$i;
108                                 AC_DEFINE(INET6, 1, [true if you have IPv6])
109                                 ])
110                         ;;
111                 kame)
112                         # http://www.kame.net/
113                         AC_EGREP_CPP(yes, [
114 #include <netinet/in.h>
115 #ifdef __KAME__
116 yes
117 #endif],
118                                 [ipv6type=$i; 
119                                 AC_DEFINE(INET6, 1, [true if you have IPv6])])
120                         ;;
121                 linux-glibc)
122                         # http://www.v6.linux.or.jp/
123                         AC_EGREP_CPP(yes, [
124 #include <features.h>
125 #if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
126 yes
127 #endif],
128                                 [ipv6type=$i;
129 AC_DEFINE(INET6, 1, [true if you have IPv6])])
130                         ;;
131                 linux-inet6)
132                         # http://www.v6.linux.or.jp/
133                         if test -d /usr/inet6 -o -f /usr/inet6/lib/libinet6.a; then
134                                 ipv6type=$i
135                                 ipv6lib=inet6
136                                 ipv6libdir=/usr/inet6/lib
137                                 ipv6trylibc=yes;
138                                 AC_DEFINE(INET6, 1, [true if you have IPv6])
139                                 CFLAGS="-I/usr/inet6/include $CFLAGS"
140                         fi
141                         ;;
142                 toshiba)
143                         AC_EGREP_CPP(yes, [
144 #include <sys/param.h>
145 #ifdef _TOSHIBA_INET6
146 yes
147 #endif],
148                                 [ipv6type=$i;
149                                 ipv6lib=inet6;
150                                 ipv6libdir=/usr/local/v6/lib;
151                                 AC_DEFINE(INET6, 1, [true if you have IPv6])])
152                         ;;
153                 v6d)
154                         AC_EGREP_CPP(yes, [
155 #include </usr/local/v6/include/sys/v6config.h>
156 #ifdef __V6D__
157 yes
158 #endif],
159                                 [ipv6type=$i;
160                                 ipv6lib=v6;
161                                 ipv6libdir=/usr/local/v6/lib;
162                                 AC_DEFINE(INET6, 1, [true if you have IPv6])])
163                         ;;
164                 zeta)
165                         AC_EGREP_CPP(yes, [
166 #include <sys/param.h>
167 #ifdef _ZETA_MINAMI_INET6
168 yes
169 #endif],
170                                 [ipv6type=$i;
171                                 ipv6lib=inet6;
172                                 ipv6libdir=/usr/local/v6/lib;
173                                 AC_DEFINE(INET6, 1, [true if you have IPv6])])
174                         ;;
175                 esac
176                 if test "$ipv6type" != "unknown"; then
177                         break
178                 fi
179         done
180         AC_MSG_RESULT($ipv6type)
181
182 AC_SEARCH_LIBS(getaddrinfo, inet6)
183
184 AC_C_BIGENDIAN
185 AC_HEADER_DIRENT
186 AC_HEADER_TIME
187 AC_HEADER_SYS_WAIT
188 AC_CHECK_HEADERS(sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h unistd.h utime.h grp.h)
189 AC_CHECK_HEADERS(compat.h sys/param.h ctype.h sys/wait.h sys/ioctl.h)
190 AC_CHECK_HEADERS(sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h)
191 AC_CHECK_HEADERS(glob.h alloca.h mcheck.h sys/sysctl.h arpa/inet.h arpa/nameser.h)
192 AC_CHECK_HEADERS(netdb.h)
193
194 AC_CHECK_SIZEOF(int)
195 AC_CHECK_SIZEOF(long)
196 AC_CHECK_SIZEOF(short)
197
198 AC_C_INLINE
199
200 AC_TYPE_SIGNAL
201 AC_TYPE_UID_T
202 AC_TYPE_MODE_T
203 AC_TYPE_OFF_T
204 AC_TYPE_SIZE_T
205 AC_TYPE_PID_T
206 AC_TYPE_GETGROUPS
207 AC_CHECK_MEMBERS([struct stat.st_rdev])
208
209 AC_CHECK_TYPE([ino_t], [unsigned])
210 TYPE_SOCKLEN_T
211
212 AC_CACHE_CHECK([for errno in errno.h],rsync_cv_errno, [
213     AC_TRY_COMPILE([#include <errno.h>],[int i = errno],
214         rsync_cv_errno=yes,rsync_cv_have_errno_decl=no)])
215 if test x"$rsync_cv_errno" = x"yes"; then
216    AC_DEFINE(HAVE_ERRNO_DECL, 1, [ ])
217 fi
218
219 # The following test taken from the cvs sources
220 # If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
221 # These need checks to be before checks for any other functions that
222 #    might be in the same libraries.
223 # The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
224 # libsocket.so which has a bad implementation of gethostbyname (it
225 # only looks in /etc/hosts), so we only look for -lsocket if we need
226 # it.
227 AC_CHECK_FUNCS(connect)
228 if test x"$ac_cv_func_connect" = x"no"; then
229     case "$LIBS" in
230     *-lnsl*) ;;
231     *) AC_CHECK_LIB(nsl_s, printf) ;;
232     esac
233     case "$LIBS" in
234     *-lnsl*) ;;
235     *) AC_CHECK_LIB(nsl, printf) ;;
236     esac
237     case "$LIBS" in
238     *-lsocket*) ;;
239     *) AC_CHECK_LIB(socket, connect) ;;
240     esac
241     case "$LIBS" in
242     *-linet*) ;;
243     *) AC_CHECK_LIB(inet, connect) ;;
244     esac
245     dnl We can't just call AC_CHECK_FUNCS(connect) here, because the value
246     dnl has been cached.
247     if test x"$ac_cv_lib_socket_connect" = x"yes" || 
248        test x"$ac_cv_lib_inet_connect" = x"yes"; then
249         # ac_cv_func_connect=yes
250         # don't!  it would cause AC_CHECK_FUNC to succeed next time configure is run
251         AC_DEFINE(HAVE_CONNECT, 1, [ ])
252     fi
253 fi
254
255 AC_CHECK_LIB(resolv, inet_ntop)
256
257 AC_MSG_NOTICE([Looking in libraries: $LIBS])
258 AC_REPLACE_FUNCS(getaddrinfo getnameinfo)
259
260 AC_CHECK_FUNC(inet_ntop, , AC_LIBOBJ(lib/inet_ntop)) 
261 AC_CHECK_FUNC(inet_pton, , AC_LIBOBJ(lib/inet_pton))
262
263 AC_CHECK_MEMBER([struct sockaddr.sa_len], 
264                 [ AC_DEFINE(HAVE_SOCKADDR_LEN) ],
265                 [],
266                 [
267 #include <sys/types.h>
268 #include <sys/socket.h>
269 ])
270
271 # if we can't find strcasecmp, look in -lresolv (for Unixware at least)
272 #
273 AC_CHECK_FUNCS(strcasecmp)
274 if test x"$ac_cv_func_strcasecmp" = x"no"; then
275     AC_CHECK_LIB(resolv, strcasecmp)
276 fi
277
278 AC_FUNC_MEMCMP
279 AC_FUNC_UTIME_NULL
280 AC_CHECK_FUNCS(waitpid wait4 getcwd strdup strerror chown chmod mknod)
281 AC_CHECK_FUNCS(fchmod fstat strchr readlink link utime utimes strftime)
282 AC_CHECK_FUNCS(memmove lchown vsnprintf snprintf asprintf setsid glob strpbrk)
283 AC_CHECK_FUNCS(strlcat strlcpy mtrace)
284
285 AC_CACHE_CHECK([for working socketpair],rsync_cv_HAVE_SOCKETPAIR,[
286 AC_TRY_RUN([#include <sys/types.h>
287             #include <sys/socket.h>
288             main() {
289                 int fd[2];
290                 exit((socketpair(AF_UNIX, SOCK_STREAM, 0, fd) != -1) ? 0 : 1);
291             }],
292 rsync_cv_HAVE_SOCKETPAIR=yes,rsync_cv_HAVE_SOCKETPAIR=no,rsync_cv_HAVE_SOCKETPAIR=cross)])
293 if test x"$rsync_cv_HAVE_SOCKETPAIR" = x"yes"; then
294     AC_DEFINE(HAVE_SOCKETPAIR, 1, [ ])
295 fi
296
297 AC_CACHE_CHECK([for working fnmatch],rsync_cv_HAVE_FNMATCH,[
298 AC_TRY_RUN([#include <fnmatch.h>
299 main() { exit((fnmatch("*.o", "x.o", FNM_PATHNAME) == 0 &&
300                fnmatch("a/b/*", "a/b/c/d", FNM_PATHNAME) != 0) ? 0: 1); }],
301 rsync_cv_HAVE_FNMATCH=yes,rsync_cv_HAVE_FNMATCH=no,rsync_cv_HAVE_FNMATCH=cross)])
302 if test x"$rsync_cv_HAVE_FNMATCH" = x"yes"; then
303     AC_DEFINE(HAVE_FNMATCH, 1, [ ])
304 fi
305
306 if test x"$with_included_popt" != x"yes"
307 then
308     AC_CHECK_LIB(popt, poptGetContext, , [with_included_popt=yes])
309 fi
310
311 AC_MSG_CHECKING([whether to use included libpopt])
312 if test x"$with_included_popt" = x"yes"
313 then
314     AC_MSG_RESULT($srcdir/popt)
315     BUILD_POPT='$(popt_OBJS)'
316     CFLAGS="$CFLAGS -I$srcdir/popt"
317 else
318     AC_MSG_RESULT(no)
319 fi
320
321 AC_CACHE_CHECK([for long long],rsync_cv_HAVE_LONGLONG,[
322 AC_TRY_RUN([#include <stdio.h>
323 main() { long long x = 1000000; x *= x; exit(((x/1000000) == 1000000)? 0: 1); }],
324 rsync_cv_HAVE_LONGLONG=yes,rsync_cv_HAVE_LONGLONG=no,rsync_cv_HAVE_LONGLONG=cross)])
325 if test x"$rsync_cv_HAVE_LONGLONG" = x"yes"; then
326     AC_DEFINE(HAVE_LONGLONG, 1, [ ])
327 fi
328
329 AC_CACHE_CHECK([for off64_t],rsync_cv_HAVE_OFF64_T,[
330 AC_TRY_RUN([#include <stdio.h>
331 #include <sys/stat.h>
332 main() { struct stat64 st; off64_t s; if (sizeof(off_t) == sizeof(off64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
333 rsync_cv_HAVE_OFF64_T=yes,rsync_cv_HAVE_OFF64_T=no,rsync_cv_HAVE_OFF64_T=cross)])
334 if test x"$rsync_cv_HAVE_OFF64_T" = x"yes"; then
335     AC_DEFINE(HAVE_OFF64_T, 1, [ ])
336 fi
337
338 AC_CACHE_CHECK([for short ino_t],rsync_cv_HAVE_SHORT_INO_T,[
339 AC_TRY_RUN([#include <stdio.h>
340 #include <sys/types.h>
341 #include <sys/stat.h>
342 main() { if (sizeof(ino_t) < sizeof(unsigned int)) return 0; return 1; }],
343 rsync_cv_HAVE_SHORT_INO_T=yes,rsync_cv_HAVE_SHORT_INO_T=no,rsync_cv_HAVE_SHORT_INO_T=cross)])
344 if test x"$rsync_cv_HAVE_SHORT_INO_T" = x"yes"; then
345     AC_DEFINE(HAVE_SHORT_INO_T, 1, [ ])
346 fi
347
348 AC_CACHE_CHECK([for unsigned char],rsync_cv_HAVE_UNSIGNED_CHAR,[
349 AC_TRY_RUN([#include <stdio.h>
350 main() { char c; c=250; exit((c > 0)?0:1); }],
351 rsync_cv_HAVE_UNSIGNED_CHAR=yes,rsync_cv_HAVE_UNSIGNED_CHAR=no,rsync_cv_HAVE_UNSIGNED_CHAR=cross)])
352 if test x"$rsync_cv_HAVE_UNSIGNED_CHAR" = x"yes"; then
353     AC_DEFINE(HAVE_UNSIGNED_CHAR, 1, [ ])
354 fi
355
356 AC_CACHE_CHECK([for broken readdir],rsync_cv_HAVE_BROKEN_READDIR,[
357 AC_TRY_RUN([#include <sys/types.h>
358 #include <dirent.h>
359 main() { struct dirent *di; DIR *d = opendir("."); di = readdir(d);
360 if (di && di->d_name[-2] == '.' && di->d_name[-1] == 0 &&
361 di->d_name[0] == 0) exit(0); exit(1);} ],
362 rsync_cv_HAVE_BROKEN_READDIR=yes,rsync_cv_HAVE_BROKEN_READDIR=no,rsync_cv_HAVE_BROKEN_READDIR=cross)])
363 if test x"$rsync_cv_HAVE_BROKEN_READDIR" = x"yes"; then
364     AC_DEFINE(HAVE_BROKEN_READDIR, 1, [ ])
365 fi
366
367 AC_CACHE_CHECK([for utimbuf],rsync_cv_HAVE_UTIMBUF,[
368 AC_TRY_COMPILE([#include <sys/types.h>
369 #include <utime.h>],
370 [struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));],
371 rsync_cv_HAVE_UTIMBUF=yes,rsync_cv_HAVE_UTIMBUF=no,rsync_cv_HAVE_UTIMBUF=cross)])
372 if test x"$rsync_cv_HAVE_UTIMBUF" = x"yes"; then
373     AC_DEFINE(HAVE_UTIMBUF, 1, [ ])
374 fi
375
376 AC_CACHE_CHECK([if gettimeofday takes tz argument],rsync_cv_HAVE_GETTIMEOFDAY_TZ,[
377 AC_TRY_RUN([
378 #include <sys/time.h>
379 #include <unistd.h>
380 main() { struct timeval tv; exit(gettimeofday(&tv, NULL));}],
381            rsync_cv_HAVE_GETTIMEOFDAY_TZ=yes,rsync_cv_HAVE_GETTIMEOFDAY_TZ=no,rsync_cv_HAVE_GETTIMEOFDAY_TZ=cross)])
382 if test x"$rsync_cv_HAVE_GETTIMEOFDAY_TZ" = x"yes"; then
383     AC_DEFINE(HAVE_GETTIMEOFDAY_TZ, 1, [ ])
384 fi
385
386 AC_CACHE_CHECK([for C99 vsnprintf],rsync_cv_HAVE_C99_VSNPRINTF,[
387 AC_TRY_RUN([
388 #include <sys/types.h>
389 #include <stdarg.h>
390 void foo(const char *format, ...) { 
391        va_list ap;
392        int len;
393        char buf[5];
394
395        va_start(ap, format);
396        len = vsnprintf(0, 0, format, ap);
397        va_end(ap);
398        if (len != 5) exit(1);
399
400        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
401
402        exit(0);
403 }
404 main() { foo("hello"); }
405 ],
406 rsync_cv_HAVE_C99_VSNPRINTF=yes,rsync_cv_HAVE_C99_VSNPRINTF=no,rsync_cv_HAVE_C99_VSNPRINTF=cross)])
407 if test x"$rsync_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
408     AC_DEFINE(HAVE_C99_VSNPRINTF, 1, [ ])
409 fi
410
411
412 AC_CACHE_CHECK([for secure mkstemp],rsync_cv_HAVE_SECURE_MKSTEMP,[
413 AC_TRY_RUN([#include <stdlib.h>
414 #include <sys/types.h>
415 #include <sys/stat.h>
416 #include <unistd.h>
417 main() { 
418   struct stat st;
419   char tpl[20]="/tmp/test.XXXXXX"; 
420   int fd = mkstemp(tpl); 
421   if (fd == -1) exit(1);
422   unlink(tpl);
423   if (fstat(fd, &st) != 0) exit(1);
424   if ((st.st_mode & 0777) != 0600) exit(1);
425   exit(0);
426 }],
427 rsync_cv_HAVE_SECURE_MKSTEMP=yes,
428 rsync_cv_HAVE_SECURE_MKSTEMP=no,
429 rsync_cv_HAVE_SECURE_MKSTEMP=cross)])
430 if test x"$rsync_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
431     AC_DEFINE(HAVE_SECURE_MKSTEMP, 1, [ ])
432 fi
433
434
435 AC_CACHE_CHECK([for broken inet_ntoa],rsync_cv_REPLACE_INET_NTOA,[
436 AC_TRY_RUN([
437 #include <stdio.h>
438 #include <sys/types.h>
439 #include <netinet/in.h>
440 #include <arpa/inet.h>
441 main() { struct in_addr ip; ip.s_addr = 0x12345678;
442 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
443     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(1); } 
444 exit(0);}],
445            rsync_cv_REPLACE_INET_NTOA=no,rsync_cv_REPLACE_INET_NTOA=yes,rsync_cv_REPLACE_INET_NTOA=cross)])
446 if test x"$rsync_cv_REPLACE_INET_NTOA" = x"yes"; then
447     AC_DEFINE(REPLACE_INET_NTOA, 1, [ ])
448 fi
449
450
451 AC_CACHE_CHECK([for broken inet_aton],rsync_cv_REPLACE_INET_ATON,[
452 AC_TRY_RUN([
453 #include <stdio.h>
454 #include <sys/types.h>
455 #include <netinet/in.h>
456 #include <arpa/inet.h>
457 main() { struct in_addr ip; 
458 if (inet_aton("example", &ip) == 0) exit(0); exit(1);}],
459            rsync_cv_REPLACE_INET_ATON=no,rsync_cv_REPLACE_INET_ATON=yes,rsync_cv_REPLACE_INET_ATON=cross)])
460 if test x"$rsync_cv_REPLACE_INET_ATON" = x"yes"; then
461     AC_DEFINE(REPLACE_INET_ATON, 1, [ ])
462 fi
463
464 #
465 # The following test was mostly taken from the tcl/tk plus patches
466 #
467 AC_CACHE_CHECK([whether -c -o works],rsync_cv_DASHC_WORKS_WITH_DASHO,[
468 rm -rf conftest*
469 cat > conftest.$ac_ext <<EOF
470 int main() { return 0; }
471 EOF
472 ${CC-cc} -c -o conftest..o conftest.$ac_ext
473 if test -f conftest..o; then
474     rsync_cv_DASHC_WORKS_WITH_DASHO=yes
475 else
476     rsync_cv_DASHC_WORKS_WITH_DASHO=no
477 fi
478 rm -rf conftest*
479 ])
480 if test x"$rsync_cv_DASHC_WORKS_WITH_DASHO" = x"yes"; then
481     OBJ_SAVE="#"
482     OBJ_RESTORE="#"
483     CC_SHOBJ_FLAG='-o $@'
484 else
485     OBJ_SAVE='  @b=`basename $@ .o`;rm -f $$b.o.sav;if test -f $$b.o; then mv $$b.o $$b.o.sav;fi;'
486     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'
487     CC_SHOBJ_FLAG=""
488 fi
489
490 AC_SUBST(OBJ_SAVE)
491 AC_SUBST(OBJ_RESTORE)
492 AC_SUBST(CC_SHOBJ_FLAG)
493 AC_SUBST(BUILD_POPT)
494
495 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
496 AC_OUTPUT