1 dnl Check for how to set a socket to non-blocking state. There seems to exist
2 dnl four known different ways, with the one used almost everywhere being POSIX
3 dnl and XPG3, while the other different ways for different systems (old BSD,
4 dnl Windows and Amiga).
6 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
7 dnl O_NONBLOCK define is found but does not work. This condition is attempted
8 dnl to get caught in this script by using an excessive number of #ifdefs...
10 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
12 AC_MSG_CHECKING([non-blocking sockets style])
15 /* headers for O_NONBLOCK test */
16 #include <sys/types.h>
20 /* try to compile O_NONBLOCK */
22 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
23 # if defined(__SVR4) || defined(__srv4__)
24 # define PLATFORM_SOLARIS
26 # define PLATFORM_SUNOS4
29 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
30 # define PLATFORM_AIX_V3
33 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
34 #error "O_NONBLOCK does not work on this platform"
37 int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
39 dnl the O_NONBLOCK test was fine
41 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
43 dnl the code was bad, try a different program now, test 2
46 /* headers for FIONBIO test */
50 /* FIONBIO source test (old-style unix) */
52 int flags = ioctl(socket, FIONBIO, &flags);
54 dnl FIONBIO test was good
56 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
58 dnl FIONBIO test was also bad
59 dnl the code was bad, try a different program now, test 3
62 /* headers for ioctlsocket test (cygwin?) */
65 /* ioctlsocket source code */
67 int flags = ioctlsocket(socket, FIONBIO, &flags);
69 dnl ioctlsocket test was good
70 nonblock="ioctlsocket"
71 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
73 dnl ioctlsocket didnt compile!, go to test 4
76 /* headers for IoctlSocket test (Amiga?) */
77 #include <sys/ioctl.h>
79 /* IoctlSocket source code */
81 int flags = IoctlSocket(socket, FIONBIO, (long)1);
83 dnl ioctlsocket test was good
84 nonblock="IoctlSocket"
85 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
87 dnl Ioctlsocket didnt compile, do test 5!
89 /* headers for SO_NONBLOCK test (BeOS) */
90 #include <sys/types.h>
94 /* SO_NONBLOCK source code */
97 int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
99 dnl the SO_NONBLOCK test was good
100 nonblock="SO_NONBLOCK"
101 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
103 dnl test 5 didnt compile!
105 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
107 dnl end of fifth test
110 dnl end of forth test
113 dnl end of third test
116 dnl end of second test
119 dnl end of non-blocking try-compile test
120 AC_MSG_RESULT($nonblock)
122 if test "$nonblock" = "nada"; then
123 AC_MSG_WARN([non-block sockets disabled])
127 dnl Check for socklen_t: historically on BSD it is an int, and in
128 dnl POSIX 1g it is a type of its own, but some platforms use different
129 dnl types for the argument to getsockopt, getpeername, etc. So we
130 dnl have to test to find something that will work.
131 AC_DEFUN([TYPE_SOCKLEN_T],
133 AC_CHECK_TYPE([socklen_t], ,[
134 AC_MSG_CHECKING([for socklen_t equivalent])
135 AC_CACHE_VAL([curl_cv_socklen_t_equiv],
137 # Systems have either "struct sockaddr *" or
138 # "void *" as the second argument to getpeername
139 curl_cv_socklen_t_equiv=
140 for arg2 in "struct sockaddr" void; do
141 for t in int size_t unsigned long "unsigned long"; do
143 #ifdef HAVE_SYS_TYPES_H
144 #include <sys/types.h>
146 #ifdef HAVE_SYS_SOCKET_H
147 #include <sys/socket.h>
150 int getpeername (int, $arg2 *, $t *);
153 getpeername(0,0,&len);
155 curl_cv_socklen_t_equiv="$t"
161 if test "x$curl_cv_socklen_t_equiv" = x; then
162 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
165 AC_MSG_RESULT($curl_cv_socklen_t_equiv)
166 AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
167 [type to use in place of socklen_t if not defined])],
168 [#include <sys/types.h>
169 #include <sys/socket.h>])
172 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
173 dnl and a few other things. If not found, we set it to unsigned int, as even
174 dnl 64-bit implementations use to set it to a 32-bit type.
175 AC_DEFUN([TYPE_IN_ADDR_T],
177 AC_CHECK_TYPE([in_addr_t], ,[
178 AC_MSG_CHECKING([for in_addr_t equivalent])
179 AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
181 curl_cv_in_addr_t_equiv=
182 for t in "unsigned long" int size_t unsigned long; do
184 #ifdef HAVE_SYS_TYPES_H
185 #include <sys/types.h>
187 #ifdef HAVE_SYS_SOCKET_H
188 #include <sys/socket.h>
190 #ifdef HAVE_ARPA_INET_H
191 #include <arpa/inet.h>
194 $t data = inet_addr ("1.2.3.4");
196 curl_cv_in_addr_t_equiv="$t"
201 if test "x$curl_cv_in_addr_t_equiv" = x; then
202 AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
205 AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
206 AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
207 [type to use in place of in_addr_t if not defined])],
208 [#include <sys/types.h>
209 #include <sys/socket.h>
210 #include <arpa/inet.h>])
213 dnl ************************************************************
214 dnl check for "localhost", if it doesn't exist, we can't do the
215 dnl gethostbyname_r tests!
218 AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
219 AC_MSG_CHECKING([if "localhost" resolves])
222 #include <sys/types.h>
228 h = gethostbyname("localhost");
229 exit (h == NULL ? 1 : 0); }],[
230 AC_MSG_RESULT(yes)],[
232 AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
238 dnl ************************************************************
239 dnl check for working getaddrinfo()
241 AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
242 AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
245 #include <sys/types.h>
246 #include <sys/socket.h>
249 struct addrinfo hints, *ai;
252 memset(&hints, 0, sizeof(hints));
253 hints.ai_family = AF_UNSPEC;
254 hints.ai_socktype = SOCK_STREAM;
255 error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
264 ac_cv_working_getaddrinfo="yes"
266 ac_cv_working_getaddrinfo="no"
268 ac_cv_working_getaddrinfo="yes"
270 if test "$ac_cv_working_getaddrinfo" = "yes"; then
271 AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
272 AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
275 AC_SUBST(IPV6_ENABLED)
280 AC_DEFUN([CURL_CHECK_LOCALTIME_R],
282 dnl check for a few thread-safe functions
283 AC_CHECK_FUNCS(localtime_r,[
284 AC_MSG_CHECKING(whether localtime_r is declared)
285 AC_EGREP_CPP(localtime_r,[
287 AC_MSG_RESULT(yes)],[
289 AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
290 AC_EGREP_CPP(localtime_r,[
293 AC_DEFINE(NEED_REENTRANT)
295 AC_MSG_RESULT(no))])])
298 AC_DEFUN([CURL_CHECK_INET_NTOA_R],
300 dnl determine if function definition for inet_ntoa_r exists.
301 AC_CHECK_FUNCS(inet_ntoa_r,[
302 AC_MSG_CHECKING(whether inet_ntoa_r is declared)
303 AC_EGREP_CPP(inet_ntoa_r,[
304 #include <arpa/inet.h>],[
305 AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
306 AC_MSG_RESULT(yes)],[
308 AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
309 AC_EGREP_CPP(inet_ntoa_r,[
311 #include <arpa/inet.h>],[
312 AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
313 AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
315 AC_MSG_RESULT(no))])])
318 AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R],
320 dnl check for number of arguments to gethostbyaddr_r. it might take
321 dnl either 5, 7, or 8 arguments.
322 AC_CHECK_FUNCS(gethostbyaddr_r,[
323 AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
325 #include <sys/types.h>
326 #include <netdb.h>],[
331 struct hostent_data hdata;
333 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
335 AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
336 ac_cv_gethostbyaddr_args=5],[
338 AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
341 #include <sys/types.h>
342 #include <netdb.h>],[
347 struct hostent_data hdata;
349 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
351 AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
352 AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
353 ac_cv_gethostbyaddr_args=5],[
355 AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
357 #include <sys/types.h>
358 #include <netdb.h>],[
367 hp = gethostbyaddr_r(address, length, type, &h,
368 buffer, 8192, &h_errnop);],[
370 AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args] )
371 ac_cv_gethostbyaddr_args=7],[
373 AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
375 #include <sys/types.h>
376 #include <netdb.h>],[
386 rc = gethostbyaddr_r(address, length, type, &h,
387 buffer, 8192, &hp, &h_errnop);],[
389 AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
390 ac_cv_gethostbyaddr_args=8],[
392 have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
395 AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R],
397 dnl check for number of arguments to gethostbyname_r. it might take
398 dnl either 3, 5, or 6 arguments.
399 AC_CHECK_FUNCS(gethostbyname_r,[
400 AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
403 #include <sys/types.h>
406 #define NULL (void *)0
409 gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
410 struct hostent_data data;
411 gethostbyname_r(NULL, NULL, NULL);],[
413 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
414 ac_cv_gethostbyname_args=3],[
416 AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
421 #include <sys/types.h>
424 #define NULL (void *)0
427 gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
428 struct hostent_data data;
429 gethostbyname_r(NULL, NULL, NULL);],[
431 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
432 AC_DEFINE(NEED_REENTRANT, 1, [needs REENTRANT])
433 ac_cv_gethostbyname_args=3],[
435 AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
437 #include <sys/types.h>
440 #define NULL (void *)0
443 gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
444 gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
446 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
447 ac_cv_gethostbyname_args=5],[
449 AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
451 #include <sys/types.h>
454 #define NULL (void *)0
457 gethostbyname_r(const char *, struct hostent *, char *, size_t,
458 struct hostent **, int *);],[
459 gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
461 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
462 ac_cv_gethostbyname_args=6],[
464 have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
465 [ac_cv_gethostbyname_args=0])],
466 [ac_cv_gethostbyname_args=0])],
467 [ac_cv_gethostbyname_args=0])],
468 [ac_cv_gethostbyname_args=0])])
470 if test "$ac_cv_func_gethostbyname_r" = "yes"; then
471 if test "$ac_cv_gethostbyname_args" = "0"; then
472 dnl there's a gethostbyname_r() function, but we don't know how
473 dnl many arguments it wants!
474 AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
479 dnl We create a function for detecting which compiler we use and then set as
480 dnl pendantic compiler options as possible for that particular compiler. The
481 dnl options are only used for debug-builds.
483 AC_DEFUN([CURL_CC_DEBUG_OPTS],
485 if test "$GCC" = "yes"; then
487 dnl figure out gcc version!
488 AC_MSG_CHECKING([gcc version])
489 gccver=`$CC -dumpversion`
490 num1=`echo $gccver | cut -d . -f1`
491 num2=`echo $gccver | cut -d . -f2`
492 gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
493 AC_MSG_RESULT($gccver)
495 AC_MSG_CHECKING([if this is icc in disguise])
496 AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
497 dnl action if the text is found, this it has not been replaced by the
501 dnl the text was not found, it was replaced by the cpp
506 if test "$ICC" = "yes"; then
507 dnl this is icc, not gcc.
509 dnl ICC warnings we ignore:
510 dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
511 dnl "invalid format string conversion"
512 dnl * 279 warns on static conditions in while expressions
513 dnl * 981 warns on "operands are evaluated in unspecified order"
514 dnl * 1419 warns on "external declaration in primary source file"
515 dnl which we know and do on purpose.
517 WARN="-wd279,269,1419,981"
519 if test "$gccnum" -gt "600"; then
520 dnl icc 6.0 and older doesn't have the -Wall flag
524 dnl this is a set of options we believe *ALL* gcc versions support:
525 WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
527 dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
529 if test "$gccnum" -gt "295"; then
530 dnl only if the compiler is newer than 2.95 since we got lots of
531 dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
532 dnl gcc 2.95.4 on FreeBSD 4.9!
536 if test "$gccnum" -ge "296"; then
537 dnl gcc 2.96 or later
538 WARN="$WARN -Wfloat-equal"
541 if test "$gccnum" -gt "296"; then
542 dnl this option does not exist in 2.96
543 WARN="$WARN -Wno-format-nonliteral"
546 dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
547 dnl on i686-Linux as it gives us heaps with false positives
548 if test "$gccnum" -ge "303"; then
549 dnl gcc 3.3 and later
550 WARN="$WARN -Wendif-labels -Wstrict-prototypes"
553 for flag in $CPPFLAGS; do
556 dnl Include path, provide a -isystem option for the same dir
557 dnl to prevent warnings in those dirs. The -isystem was not very
558 dnl reliable on earlier gcc versions.
559 add=`echo $flag | sed 's/^-I/-isystem /g'`
567 CFLAGS="$CFLAGS $WARN"
569 AC_MSG_NOTICE([Added this set of compiler options: $WARN])
573 AC_MSG_NOTICE([Added no extra compiler options])
577 dnl strip off optimizer flags
579 for flag in $CFLAGS; do
582 dnl echo "cut off $flag"
585 NEWFLAGS="$NEWFLAGS $flag"
591 ]) dnl end of AC_DEFUN()