3 dnl CURL_CHECK_HEADER_WINDOWS
4 dnl -------------------------------------------------
5 dnl Check for compilable and valid windows.h header
7 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
8 AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
12 #ifndef WIN32_LEAN_AND_MEAN
13 #define WIN32_LEAN_AND_MEAN
20 ac_cv_header_windows_h="yes"
22 ac_cv_header_windows_h="no"
25 if test "x$ac_cv_header_windows_h" = "xyes"; then
26 AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
27 [Define to 1 if you have the windows.h header file.])
28 AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
29 [Define to avoid automatic inclusion of winsock.h])
34 dnl CURL_CHECK_HEADER_WINSOCK
35 dnl -------------------------------------------------
36 dnl Check for compilable and valid winsock.h header
38 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
39 AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
40 AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
44 #ifndef WIN32_LEAN_AND_MEAN
45 #define WIN32_LEAN_AND_MEAN
50 int dummy=WSACleanup();
53 ac_cv_header_winsock_h="yes"
55 ac_cv_header_winsock_h="no"
58 if test "x$ac_cv_header_winsock_h" = "xyes"; then
59 AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
60 [Define to 1 if you have the winsock.h header file.])
65 dnl CURL_CHECK_HEADER_WINSOCK2
66 dnl -------------------------------------------------
67 dnl Check for compilable and valid winsock2.h header
69 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
70 AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
71 AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
75 #ifndef WIN32_LEAN_AND_MEAN
76 #define WIN32_LEAN_AND_MEAN
81 int dummy=2*IPPROTO_ESP;
84 ac_cv_header_winsock2_h="yes"
86 ac_cv_header_winsock2_h="no"
89 if test "x$ac_cv_header_winsock2_h" = "xyes"; then
90 AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
91 [Define to 1 if you have the winsock2.h header file.])
96 dnl CURL_CHECK_HEADER_WS2TCPIP
97 dnl -------------------------------------------------
98 dnl Check for compilable and valid ws2tcpip.h header
100 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
101 AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
102 AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
106 #ifndef WIN32_LEAN_AND_MEAN
107 #define WIN32_LEAN_AND_MEAN
110 #include <winsock2.h>
111 #include <ws2tcpip.h>
113 int dummy=2*IP_PKTINFO;
116 ac_cv_header_ws2tcpip_h="yes"
118 ac_cv_header_ws2tcpip_h="no"
121 if test "x$ac_cv_header_ws2tcpip_h" = "xyes"; then
122 AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
123 [Define to 1 if you have the ws2tcpip.h header file.])
128 dnl CURL_CHECK_TYPE_SOCKLEN_T
129 dnl -------------------------------------------------
130 dnl Check for existing socklen_t type, and provide
131 dnl an equivalent type if socklen_t not available
133 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
134 AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
135 AC_CHECK_TYPE([socklen_t], ,[
136 AC_CACHE_CHECK([for socklen_t equivalent],
137 [curl_cv_socklen_t_equiv], [
138 curl_cv_socklen_t_equiv="unknown"
139 for arg2 in "struct sockaddr" void; do
140 for t in int size_t unsigned long "unsigned long"; do
144 #ifdef HAVE_WINDOWS_H
145 #ifndef WIN32_LEAN_AND_MEAN
146 #define WIN32_LEAN_AND_MEAN
149 #ifdef HAVE_WINSOCK2_H
150 #include <winsock2.h>
152 #ifdef HAVE_WINSOCK_H
157 #ifdef HAVE_SYS_TYPES_H
158 #include <sys/types.h>
160 #ifdef HAVE_SYS_SOCKET_H
161 #include <sys/socket.h>
164 int getpeername (int, $arg2 *, $t *);
167 getpeername(0,0,&len);
170 curl_cv_socklen_t_equiv="$t"
176 if test "$curl_cv_socklen_t_equiv" = "unknown"; then
177 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
179 AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
180 [type to use in place of socklen_t if not defined])
184 #ifdef HAVE_WINDOWS_H
185 #ifndef WIN32_LEAN_AND_MEAN
186 #define WIN32_LEAN_AND_MEAN
189 #ifdef HAVE_WINSOCK2_H
190 #include <winsock2.h>
191 #ifdef HAVE_WS2TCPIP_H
192 #include <ws2tcpip.h>
196 #ifdef HAVE_SYS_TYPES_H
197 #include <sys/types.h>
199 #ifdef HAVE_SYS_SOCKET_H
200 #include <sys/socket.h>
207 dnl CURL_FUNC_GETNAMEINFO_ARGTYPES
208 dnl -------------------------------------------------
209 dnl Check the type to be passed to five of the arguments
210 dnl of getnameinfo function, and define those types in
211 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
212 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7.
213 dnl This function is experimental and its results shall
214 dnl not be trusted while this notice is in place ------
216 AC_DEFUN([CURL_FUNC_GETNAMEINFO_ARGTYPES], [
217 AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
218 AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
219 AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
220 AC_CACHE_CHECK([types of arguments for getnameinfo],
221 [curl_cv_func_getnameinfo_args], [
222 curl_cv_func_getnameinfo_args="unknown"
223 for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
224 for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
225 for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
226 for gni_arg7 in 'int' 'unsigned int'; do
230 #ifdef HAVE_WINDOWS_H
231 #ifndef WIN32_LEAN_AND_MEAN
232 #define WIN32_LEAN_AND_MEAN
234 #if defined(__MINGW32__) && ( (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501) )
236 #define _WIN32_WINNT 0x0501
239 #ifdef HAVE_WINSOCK2_H
240 #include <winsock2.h>
241 #ifdef HAVE_WS2TCPIP_H
242 #include <ws2tcpip.h>
246 #ifdef HAVE_SYS_TYPES_H
247 #include <sys/types.h>
249 #ifdef HAVE_SYS_SOCKET_H
250 #include <sys/socket.h>
256 extern int getnameinfo($gni_arg1, $gni_arg2,
262 $gni_arg46 hostlen=0;
263 $gni_arg46 servlen=0;
265 int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
268 curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
276 if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
277 AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
279 gni_prev_IFS=$IFS; IFS=','
280 set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
283 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1],
284 [Define to the type of arg 1 for getnameinfo.])
285 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
286 [Define to the type of arg 2 for getnameinfo.])
287 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
288 [Define to the type of args 4 and 6 for getnameinfo.])
289 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
290 [Define to the type of arg 7 for getnameinfo.])
295 dnl CURL_CHECK_NONBLOCKING_SOCKET
296 dnl -------------------------------------------------
297 dnl Check for how to set a socket to non-blocking state. There seems to exist
298 dnl four known different ways, with the one used almost everywhere being POSIX
299 dnl and XPG3, while the other different ways for different systems (old BSD,
300 dnl Windows and Amiga).
302 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
303 dnl O_NONBLOCK define is found but does not work. This condition is attempted
304 dnl to get caught in this script by using an excessive number of #ifdefs...
306 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
308 AC_MSG_CHECKING([non-blocking sockets style])
311 /* headers for O_NONBLOCK test */
312 #include <sys/types.h>
316 /* try to compile O_NONBLOCK */
318 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
319 # if defined(__SVR4) || defined(__srv4__)
320 # define PLATFORM_SOLARIS
322 # define PLATFORM_SUNOS4
325 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
326 # define PLATFORM_AIX_V3
329 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
330 #error "O_NONBLOCK does not work on this platform"
333 int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
335 dnl the O_NONBLOCK test was fine
336 nonblock="O_NONBLOCK"
337 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
339 dnl the code was bad, try a different program now, test 2
342 /* headers for FIONBIO test */
346 /* FIONBIO source test (old-style unix) */
348 int flags = ioctl(socket, FIONBIO, &flags);
350 dnl FIONBIO test was good
352 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
354 dnl FIONBIO test was also bad
355 dnl the code was bad, try a different program now, test 3
358 /* headers for ioctlsocket test (Windows) */
360 #ifdef HAVE_WINDOWS_H
361 #ifndef WIN32_LEAN_AND_MEAN
362 #define WIN32_LEAN_AND_MEAN
365 #ifdef HAVE_WINSOCK2_H
366 #include <winsock2.h>
368 #ifdef HAVE_WINSOCK_H
374 /* ioctlsocket source code */
376 unsigned long flags = 0;
377 sd = socket(0, 0, 0);
378 ioctlsocket(sd, FIONBIO, &flags);
380 dnl ioctlsocket test was good
381 nonblock="ioctlsocket"
382 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
384 dnl ioctlsocket didnt compile!, go to test 4
387 /* headers for IoctlSocket test (Amiga?) */
388 #include <sys/ioctl.h>
390 /* IoctlSocket source code */
392 int flags = IoctlSocket(socket, FIONBIO, (long)1);
394 dnl ioctlsocket test was good
395 nonblock="IoctlSocket"
396 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
398 dnl Ioctlsocket didnt compile, do test 5!
400 /* headers for SO_NONBLOCK test (BeOS) */
403 /* SO_NONBLOCK source code */
406 int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
408 dnl the SO_NONBLOCK test was good
409 nonblock="SO_NONBLOCK"
410 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
412 dnl test 5 didnt compile!
414 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
416 dnl end of fifth test
419 dnl end of forth test
422 dnl end of third test
425 dnl end of second test
428 dnl end of non-blocking try-compile test
429 AC_MSG_RESULT($nonblock)
431 if test "$nonblock" = "nada"; then
432 AC_MSG_WARN([non-block sockets disabled])
437 dnl TYPE_SOCKADDR_STORAGE
438 dnl -------------------------------------------------
439 dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
440 dnl AIX 4.3 is one known exception.
441 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
443 AC_CHECK_TYPE([struct sockaddr_storage],
444 AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
445 [if struct sockaddr_storage is defined]), ,
448 #ifdef HAVE_WINDOWS_H
449 #ifndef WIN32_LEAN_AND_MEAN
450 #define WIN32_LEAN_AND_MEAN
453 #ifdef HAVE_WINSOCK2_H
454 #include <winsock2.h>
457 #ifdef HAVE_SYS_TYPES_H
458 #include <sys/types.h>
460 #ifdef HAVE_SYS_SOCKET_H
461 #include <sys/socket.h>
463 #ifdef HAVE_NETINET_IN_H
464 #include <netinet/in.h>
466 #ifdef HAVE_ARPA_INET_H
467 #include <arpa/inet.h>
475 dnl -------------------------------------------------
476 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
477 dnl and a few other things.
478 AC_DEFUN([TYPE_IN_ADDR_T],
480 AC_CHECK_TYPE([in_addr_t], ,[
481 AC_MSG_CHECKING([for in_addr_t equivalent])
482 AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
484 curl_cv_in_addr_t_equiv=
485 for t in "unsigned long" int size_t unsigned long; do
488 #ifdef HAVE_WINDOWS_H
489 #ifndef WIN32_LEAN_AND_MEAN
490 #define WIN32_LEAN_AND_MEAN
493 #ifdef HAVE_WINSOCK2_H
494 #include <winsock2.h>
496 #ifdef HAVE_WINSOCK_H
501 #ifdef HAVE_SYS_TYPES_H
502 #include <sys/types.h>
504 #ifdef HAVE_SYS_SOCKET_H
505 #include <sys/socket.h>
507 #ifdef HAVE_NETINET_IN_H
508 #include <netinet/in.h>
510 #ifdef HAVE_ARPA_INET_H
511 #include <arpa/inet.h>
515 $t data = inet_addr ("1.2.3.4");
517 curl_cv_in_addr_t_equiv="$t"
522 if test "x$curl_cv_in_addr_t_equiv" = x; then
523 AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
526 AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
527 AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
528 [type to use in place of in_addr_t if not defined])],
531 #ifdef HAVE_WINDOWS_H
532 #ifndef WIN32_LEAN_AND_MEAN
533 #define WIN32_LEAN_AND_MEAN
536 #ifdef HAVE_WINSOCK2_H
537 #include <winsock2.h>
539 #ifdef HAVE_WINSOCK_H
544 #ifdef HAVE_SYS_TYPES_H
545 #include <sys/types.h>
547 #ifdef HAVE_SYS_SOCKET_H
548 #include <sys/socket.h>
550 #ifdef HAVE_NETINET_IN_H
551 #include <netinet/in.h>
553 #ifdef HAVE_ARPA_INET_H
554 #include <arpa/inet.h>
562 dnl We create a function for detecting which compiler we use and then set as
563 dnl pendantic compiler options as possible for that particular compiler. The
564 dnl options are only used for debug-builds.
566 dnl This is a copy of the original found in curl's configure script. Don't
567 dnl modify this one, edit the one in curl and copy it back here when that one
570 AC_DEFUN([CURL_CC_DEBUG_OPTS],
572 if test "$GCC" = "yes"; then
574 dnl figure out gcc version!
575 AC_MSG_CHECKING([gcc version])
576 gccver=`$CC -dumpversion`
577 num1=`echo $gccver | cut -d . -f1`
578 num2=`echo $gccver | cut -d . -f2`
579 gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
580 AC_MSG_RESULT($gccver)
582 AC_MSG_CHECKING([if this is icc in disguise])
583 AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
584 dnl action if the text is found, this it has not been replaced by the
588 dnl the text was not found, it was replaced by the cpp
593 if test "$ICC" = "yes"; then
594 dnl this is icc, not gcc.
596 dnl ICC warnings we ignore:
597 dnl * 279 warns on static conditions in while expressions
598 dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
599 dnl "invalid format string conversion"
603 if test "$gccnum" -gt "600"; then
604 dnl icc 6.0 and older doesn't have the -Wall flag
609 WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
611 dnl -Wcast-align is a bit too annoying ;-)
613 if test "$gccnum" -ge "296"; then
614 dnl gcc 2.96 or later
615 WARN="$WARN -Wfloat-equal"
617 if test "$gccnum" -gt "296"; then
618 dnl this option does not exist in 2.96
619 WARN="$WARN -Wno-format-nonliteral"
622 dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
623 dnl on i686-Linux as it gives us heaps with false positives
624 if test "$gccnum" -ge "303"; then
625 dnl gcc 3.3 and later
626 WARN="$WARN -Wendif-labels -Wstrict-prototypes"
630 for flag in $CPPFLAGS; do
634 add=`echo $flag | sed 's/^-I/-isystem /g'`
642 CFLAGS="$CFLAGS $WARN"
646 dnl strip off optimizer flags
648 for flag in $CFLAGS; do
651 dnl echo "cut off $flag"
654 NEWFLAGS="$NEWFLAGS $flag"
660 ]) dnl end of AC_DEFUN()
663 dnl This macro determines if the specified struct exists in the specified file
665 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
667 AC_DEFUN([CARES_CHECK_STRUCT], [
668 AC_MSG_CHECKING([for struct $2])
671 struct $2 struct_instance;
672 ], ac_struct="yes", ac_found="no")
673 if test "$ac_struct" = "yes" ; then
682 dnl This macro determines if the specified constant exists in the specified file
684 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
686 AC_DEFUN([CARES_CHECK_CONSTANT], [
687 AC_MSG_CHECKING([for $2])
688 AC_EGREP_CPP(VARIABLEWASDEFINED,
697 ], ac_constant="yes", ac_constant="no"
699 if test "$ac_constant" = "yes" ; then
709 dnl This macro determines how many parameters getservbyport_r takes
710 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
711 AC_MSG_CHECKING([how many arguments getservbyport_r takes])
713 [#include <netdb.h>],
717 struct servent *p3, *p6;
718 getservbyport_r(p1, p2, p3, p4, p5, &p6);
719 ], ac_func_getservbyport_r=6,
721 [#include <netdb.h>],
726 getservbyport_r(p1, p2, p3, p4, p5);
727 ], ac_func_getservbyport_r=5,
729 [#include <netdb.h>],
734 struct servent_data p4;
735 getservbyport_r(p1, p2, p3, &p4);
736 ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
740 if test $ac_func_getservbyport_r != "0" ; then
741 AC_MSG_RESULT($ac_func_getservbyport_r)
742 AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
743 AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to
745 if test $ac_func_getservbyport_r = "4" ; then
746 AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to
749 AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
752 AC_MSG_RESULT([not found])