Include a test for a working getopt_long because the one on some versions
[rsync.git] / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT(byteorder.h)
3 AC_CONFIG_HEADER(config.h)
4
5 # compile with optimisation and without debugging by default
6 CFLAGS=${CFLAGS-"-O"}
7
8 AC_CANONICAL_SYSTEM
9 AC_VALIDATE_CACHE_SYSTEM_TYPE
10
11 dnl Checks for programs.
12 AC_PROG_CC
13 AC_PROG_INSTALL
14 AC_SUBST(SHELL)
15
16 AC_CHECK_PROG(HAVE_REMSH, remsh, 1, 0)
17 AC_DEFINE_UNQUOTED(HAVE_REMSH, $HAVE_REMSH)
18
19 AC_C_BIGENDIAN
20 AC_HEADER_DIRENT
21 AC_HEADER_TIME
22 AC_HEADER_SYS_WAIT
23 AC_CHECK_HEADERS(sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h unistd.h utime.h grp.h)
24 AC_CHECK_HEADERS(compat.h sys/param.h ctype.h sys/wait.h sys/ioctl.h)
25 AC_CHECK_HEADERS(sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h)
26 AC_CHECK_HEADERS(glob.h)
27
28 AC_CHECK_SIZEOF(int)
29 AC_CHECK_SIZEOF(long)
30 AC_CHECK_SIZEOF(short)
31
32 AC_C_INLINE
33
34 AC_TYPE_SIGNAL
35 AC_TYPE_UID_T
36 AC_TYPE_MODE_T
37 AC_TYPE_OFF_T
38 AC_TYPE_SIZE_T
39 AC_TYPE_PID_T
40 AC_TYPE_GETGROUPS
41 AC_STRUCT_ST_RDEV
42 AC_CHECK_TYPE(ino_t,unsigned)
43
44 AC_CACHE_CHECK([for errno in errno.h],rsync_cv_errno, [
45     AC_TRY_COMPILE([#include <errno.h>],[int i = errno],
46         rsync_cv_errno=yes,rsync_cv_have_errno_decl=no)])
47 if test x"$rsync_cv_errno" = x"yes"; then
48    AC_DEFINE(HAVE_ERRNO_DECL)
49 fi
50
51 AC_FUNC_MEMCMP
52 AC_FUNC_UTIME_NULL
53 AC_CHECK_FUNCS(waitpid wait4 getcwd strdup strerror chown chmod mknod)
54 AC_CHECK_FUNCS(fchmod fstat strchr readlink link utime utimes strftime)
55 AC_CHECK_FUNCS(memmove lchown vsnprintf snprintf setsid glob strpbrk)
56 AC_CHECK_FUNCS(strlcat strlcpy)
57
58 AC_CACHE_CHECK([for working fnmatch],rsync_cv_HAVE_FNMATCH,[
59 AC_TRY_RUN([#include <fnmatch.h>
60 main() { exit(fnmatch("*.o", "x.o", FNM_PATHNAME) == 0? 0: 1); }],
61 rsync_cv_HAVE_FNMATCH=yes,rsync_cv_HAVE_FNMATCH=no,rsync_cv_HAVE_FNMATCH=cross)])
62 if test x"$rsync_cv_HAVE_FNMATCH" = x"yes"; then
63     AC_DEFINE(HAVE_FNMATCH)
64 fi
65
66 # sometimes getopt_long cannot parse same arguments twice
67 # e.g. on certain versions of CygWin32
68 AC_CACHE_CHECK([for working getopt_long],rsync_cv_HAVE_GETOPT_LONG,[
69 AC_TRY_RUN([#include <getopt.h>
70 main() {
71     int i, x = 0; char *argv[] = { "x", "--xx" };
72     struct option o[] = {{"xx", 0, 0, 1}, {0,0,0,0}};
73     getopt_long(2, argv, "x", o, &i) == 1 ? x++ : 0; optind = 0;
74     getopt_long(2, argv, "x", o, &i) == 1 ? x++ : 0;
75     exit(x == 2 ? 0 : 1);
76 }], rsync_cv_HAVE_GETOPT_LONG=yes,rsync_cv_HAVE_GETOPT_LONG=no,
77     rsync_cv_HAVE_GETOPT_LONG=cross)])
78 if test x"$rsync_cv_HAVE_GETOPT_LONG" = x"yes"; then
79     AC_DEFINE(HAVE_GETOPT_LONG)
80 fi
81
82 AC_CACHE_CHECK([for long long],rsync_cv_HAVE_LONGLONG,[
83 AC_TRY_RUN([#include <stdio.h>
84 main() { long long x = 1000000; x *= x; exit(((x/1000000) == 1000000)? 0: 1); }],
85 rsync_cv_HAVE_LONGLONG=yes,rsync_cv_HAVE_LONGLONG=no,rsync_cv_HAVE_LONGLONG=cross)])
86 if test x"$rsync_cv_HAVE_LONGLONG" = x"yes"; then
87     AC_DEFINE(HAVE_LONGLONG)
88 fi
89
90 AC_CACHE_CHECK([for off64_t],rsync_cv_HAVE_OFF64_T,[
91 AC_TRY_RUN([#include <stdio.h>
92 #include <sys/stat.h>
93 main() { struct stat64 st; off64_t s; if (sizeof(off_t) == sizeof(off64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
94 rsync_cv_HAVE_OFF64_T=yes,rsync_cv_HAVE_OFF64_T=no,rsync_cv_HAVE_OFF64_T=cross)])
95 if test x"$rsync_cv_HAVE_OFF64_T" = x"yes"; then
96     AC_DEFINE(HAVE_OFF64_T)
97 fi
98
99 AC_CACHE_CHECK([for short ino_t],rsync_cv_HAVE_SHORT_INO_T,[
100 AC_TRY_RUN([#include <stdio.h>
101 #include <sys/types.h>
102 #include <sys/stat.h>
103 main() { if (sizeof(ino_t) < sizeof(unsigned int)) return 0; return 1; }],
104 rsync_cv_HAVE_SHORT_INO_T=yes,rsync_cv_HAVE_SHORT_INO_T=no,rsync_cv_HAVE_SHORT_INO_T=cross)])
105 if test x"$rsync_cv_HAVE_SHORT_INO_T" = x"yes"; then
106     AC_DEFINE(HAVE_SHORT_INO_T)
107 fi
108
109 AC_CACHE_CHECK([for unsigned char],rsync_cv_HAVE_UNSIGNED_CHAR,[
110 AC_TRY_RUN([#include <stdio.h>
111 main() { char c; c=250; exit((c > 0)?0:1); }],
112 rsync_cv_HAVE_UNSIGNED_CHAR=yes,rsync_cv_HAVE_UNSIGNED_CHAR=no,rsync_cv_HAVE_UNSIGNED_CHAR=cross)])
113 if test x"$rsync_cv_HAVE_UNSIGNED_CHAR" = x"yes"; then
114     AC_DEFINE(HAVE_UNSIGNED_CHAR)
115 fi
116
117 AC_CACHE_CHECK([for broken readdir],rsync_cv_HAVE_BROKEN_READDIR,[
118 AC_TRY_RUN([#include <sys/types.h>
119 #include <dirent.h>
120 main() { struct dirent *di; DIR *d = opendir("."); di = readdir(d);
121 if (di && di->d_name[-2] == '.' && di->d_name[-1] == 0 &&
122 di->d_name[0] == 0) exit(0); exit(1);} ],
123 rsync_cv_HAVE_BROKEN_READDIR=yes,rsync_cv_HAVE_BROKEN_READDIR=no,rsync_cv_HAVE_BROKEN_READDIR=cross)])
124 if test x"$rsync_cv_HAVE_BROKEN_READDIR" = x"yes"; then
125     AC_DEFINE(HAVE_BROKEN_READDIR)
126 fi
127
128 AC_CACHE_CHECK([for utimbuf],rsync_cv_HAVE_UTIMBUF,[
129 AC_TRY_COMPILE([#include <sys/types.h>
130 #include <utime.h>],
131 [struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));],
132 rsync_cv_HAVE_UTIMBUF=yes,rsync_cv_HAVE_UTIMBUF=no,rsync_cv_HAVE_UTIMBUF=cross)])
133 if test x"$rsync_cv_HAVE_UTIMBUF" = x"yes"; then
134     AC_DEFINE(HAVE_UTIMBUF)
135 fi
136
137 AC_CACHE_CHECK([for broken inet_ntoa],rsync_cv_REPLACE_INET_NTOA,[
138 AC_TRY_RUN([
139 #include <stdio.h>
140 #include <sys/types.h>
141 #include <netinet/in.h>
142 #include <arpa/inet.h>
143 main() { struct in_addr ip; ip.s_addr = 0x12345678;
144 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
145     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
146 exit(1);}],
147            rsync_cv_REPLACE_INET_NTOA=yes,rsync_cv_REPLACE_INET_NTOA=no,rsync_cv_REPLACE_INET_NTOA=cross)])
148 if test x"$rsync_cv_REPLACE_INET_NTOA" = x"yes"; then
149     AC_DEFINE(REPLACE_INET_NTOA)
150 fi
151
152 # The following test taken from the cvs sources
153 # If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
154 # The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
155 # libsocket.so which has a bad implementation of gethostbyname (it
156 # only looks in /etc/hosts), so we only look for -lsocket if we need
157 # it.
158 AC_CHECK_FUNCS(connect)
159 if test x"$ac_cv_func_connect" = x"no"; then
160     case "$LIBS" in
161     *-lnsl*) ;;
162     *) AC_CHECK_LIB(nsl_s, printf) ;;
163     esac
164     case "$LIBS" in
165     *-lnsl*) ;;
166     *) AC_CHECK_LIB(nsl, printf) ;;
167     esac
168     case "$LIBS" in
169     *-lsocket*) ;;
170     *) AC_CHECK_LIB(socket, connect) ;;
171     esac
172     case "$LIBS" in
173     *-linet*) ;;
174     *) AC_CHECK_LIB(inet, connect) ;;
175     esac
176     dnl We can't just call AC_CHECK_FUNCS(connect) here, because the value
177     dnl has been cached.
178     if test x"$ac_cv_lib_socket_connect" = x"yes" || 
179        test x"$ac_cv_lib_inet_connect" = x"yes"; then
180         # ac_cv_func_connect=yes
181         # don't!  it would cause AC_CHECK_FUNC to succeed next time configure is run
182         AC_DEFINE(HAVE_CONNECT)
183     fi
184 fi
185
186
187 # if we can't find strcasecmp, look in -lresolv (for Unixware at least)
188 #
189 AC_CHECK_FUNCS(strcasecmp)
190 if test x"$ac_cv_func_strcasecmp" = x"no"; then
191     AC_CHECK_LIB(resolv, strcasecmp)
192 fi
193
194 #
195 # The following test was mostly taken from the tcl/tk plus patches
196 #
197 AC_CACHE_CHECK([whether -c -o works],rsync_cv_DASHC_WORKS_WITH_DASHO,[
198 rm -rf conftest*
199 cat > conftest.$ac_ext <<EOF
200 int main() { return 0; }
201 EOF
202 ${CC-cc} -c -o conftest..o conftest.$ac_ext
203 if test -f conftest..o; then
204     rsync_cv_DASHC_WORKS_WITH_DASHO=yes
205 else
206     rsync_cv_DASHC_WORKS_WITH_DASHO=no
207 fi
208 rm -rf conftest*
209 ])
210 if test x"$rsync_cv_DASHC_WORKS_WITH_DASHO" = x"yes"; then
211     OBJ_SAVE="#"
212     OBJ_RESTORE="#"
213     CC_SHOBJ_FLAG='-o $@'
214 else
215     OBJ_SAVE='  @b=`basename $@ .o`;rm -f $$b.o.sav;if test -f $$b.o; then mv $$b.o $$b.o.sav;fi;'
216     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'
217     CC_SHOBJ_FLAG=""
218 fi
219
220 AC_SUBST(OBJ_SAVE)
221 AC_SUBST(OBJ_RESTORE)
222 AC_SUBST(CC_SHOBJ_FLAG)
223
224
225 AC_OUTPUT(Makefile lib/dummy zlib/dummy)