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_CHECK_FUNC_GETNAMEINFO
208 dnl -------------------------------------------------
209 dnl Test if the getnameinfo function is available,
210 dnl and check the types of five of its arguments.
211 dnl If the function succeeds HAVE_GETNAMEINFO will be
212 dnl defined, defining the types of the arguments in
213 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
214 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7.
215 dnl This function is experimental and its results shall
216 dnl not be trusted while this notice is in place ------
218 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
219 AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
220 AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
221 AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
223 AC_MSG_CHECKING([for getnameinfo])
225 AC_LANG_FUNC_LINK_TRY([getnameinfo])
228 curl_cv_getnameinfo="yes"
231 curl_cv_getnameinfo="no"
234 if test "$curl_cv_getnameinfo" != "yes"; then
235 AC_MSG_CHECKING([deeper for getnameinfo])
241 curl_cv_getnameinfo="yes"
243 AC_MSG_RESULT([but still no])
244 curl_cv_getnameinfo="no"
248 if test "$curl_cv_getnameinfo" != "yes"; then
249 AC_MSG_CHECKING([deeper and deeper for getnameinfo])
252 #ifdef HAVE_WINDOWS_H
253 #ifndef WIN32_LEAN_AND_MEAN
254 #define WIN32_LEAN_AND_MEAN
257 #ifdef HAVE_WINSOCK2_H
258 #include <winsock2.h>
259 #ifdef HAVE_WS2TCPIP_H
260 #include <ws2tcpip.h>
264 #ifdef HAVE_SYS_TYPES_H
265 #include <sys/types.h>
267 #ifdef HAVE_SYS_SOCKET_H
268 #include <sys/socket.h>
275 getnameinfo(0, 0, 0, 0, 0, 0, 0);
278 curl_cv_getnameinfo="yes"
280 AC_MSG_RESULT([but still no])
281 curl_cv_getnameinfo="no"
285 if test "$curl_cv_getnameinfo" = "yes"; then
286 AC_CACHE_CHECK([types of arguments for getnameinfo],
287 [curl_cv_func_getnameinfo_args], [
288 curl_cv_func_getnameinfo_args="unknown"
289 for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
290 for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
291 for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
292 for gni_arg7 in 'int' 'unsigned int'; do
296 #ifdef HAVE_WINDOWS_H
297 #ifndef WIN32_LEAN_AND_MEAN
298 #define WIN32_LEAN_AND_MEAN
300 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
302 #define _WIN32_WINNT 0x0501
305 #ifdef HAVE_WINSOCK2_H
306 #include <winsock2.h>
307 #ifdef HAVE_WS2TCPIP_H
308 #include <ws2tcpip.h>
311 #define GNICALLCONV WSAAPI
313 #ifdef HAVE_SYS_TYPES_H
314 #include <sys/types.h>
316 #ifdef HAVE_SYS_SOCKET_H
317 #include <sys/socket.h>
324 extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
330 $gni_arg46 hostlen=0;
331 $gni_arg46 servlen=0;
333 int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
336 curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
344 if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
345 AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
346 AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
348 gni_prev_IFS=$IFS; IFS=','
349 set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
352 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1],
353 [Define to the type of arg 1 for getnameinfo.])
354 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
355 [Define to the type of arg 2 for getnameinfo.])
356 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
357 [Define to the type of args 4 and 6 for getnameinfo.])
358 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
359 [Define to the type of arg 7 for getnameinfo.])
360 AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
361 [Define to 1 if you have the getnameinfo function.])
362 ac_cv_func_getnameinfo="yes"
368 dnl CURL_CHECK_NONBLOCKING_SOCKET
369 dnl -------------------------------------------------
370 dnl Check for how to set a socket to non-blocking state. There seems to exist
371 dnl four known different ways, with the one used almost everywhere being POSIX
372 dnl and XPG3, while the other different ways for different systems (old BSD,
373 dnl Windows and Amiga).
375 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
376 dnl O_NONBLOCK define is found but does not work. This condition is attempted
377 dnl to get caught in this script by using an excessive number of #ifdefs...
379 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
381 AC_MSG_CHECKING([non-blocking sockets style])
384 /* headers for O_NONBLOCK test */
385 #include <sys/types.h>
389 /* try to compile O_NONBLOCK */
391 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
392 # if defined(__SVR4) || defined(__srv4__)
393 # define PLATFORM_SOLARIS
395 # define PLATFORM_SUNOS4
398 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
399 # define PLATFORM_AIX_V3
402 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
403 #error "O_NONBLOCK does not work on this platform"
406 int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
408 dnl the O_NONBLOCK test was fine
409 nonblock="O_NONBLOCK"
410 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
412 dnl the code was bad, try a different program now, test 2
415 /* headers for FIONBIO test */
419 /* FIONBIO source test (old-style unix) */
421 int flags = ioctl(socket, FIONBIO, &flags);
423 dnl FIONBIO test was good
425 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
427 dnl FIONBIO test was also bad
428 dnl the code was bad, try a different program now, test 3
431 /* headers for ioctlsocket test (Windows) */
433 #ifdef HAVE_WINDOWS_H
434 #ifndef WIN32_LEAN_AND_MEAN
435 #define WIN32_LEAN_AND_MEAN
438 #ifdef HAVE_WINSOCK2_H
439 #include <winsock2.h>
441 #ifdef HAVE_WINSOCK_H
447 /* ioctlsocket source code */
449 unsigned long flags = 0;
450 sd = socket(0, 0, 0);
451 ioctlsocket(sd, FIONBIO, &flags);
453 dnl ioctlsocket test was good
454 nonblock="ioctlsocket"
455 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
457 dnl ioctlsocket didnt compile!, go to test 4
460 /* headers for IoctlSocket test (Amiga?) */
461 #include <sys/ioctl.h>
463 /* IoctlSocket source code */
465 int flags = IoctlSocket(socket, FIONBIO, (long)1);
467 dnl ioctlsocket test was good
468 nonblock="IoctlSocket"
469 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
471 dnl Ioctlsocket didnt compile, do test 5!
473 /* headers for SO_NONBLOCK test (BeOS) */
476 /* SO_NONBLOCK source code */
479 int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
481 dnl the SO_NONBLOCK test was good
482 nonblock="SO_NONBLOCK"
483 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
485 dnl test 5 didnt compile!
487 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
489 dnl end of fifth test
492 dnl end of forth test
495 dnl end of third test
498 dnl end of second test
501 dnl end of non-blocking try-compile test
502 AC_MSG_RESULT($nonblock)
504 if test "$nonblock" = "nada"; then
505 AC_MSG_WARN([non-block sockets disabled])
510 dnl TYPE_SOCKADDR_STORAGE
511 dnl -------------------------------------------------
512 dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
513 dnl AIX 4.3 is one known exception.
514 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
516 AC_CHECK_TYPE([struct sockaddr_storage],
517 AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
518 [if struct sockaddr_storage is defined]), ,
521 #ifdef HAVE_WINDOWS_H
522 #ifndef WIN32_LEAN_AND_MEAN
523 #define WIN32_LEAN_AND_MEAN
526 #ifdef HAVE_WINSOCK2_H
527 #include <winsock2.h>
530 #ifdef HAVE_SYS_TYPES_H
531 #include <sys/types.h>
533 #ifdef HAVE_SYS_SOCKET_H
534 #include <sys/socket.h>
536 #ifdef HAVE_NETINET_IN_H
537 #include <netinet/in.h>
539 #ifdef HAVE_ARPA_INET_H
540 #include <arpa/inet.h>
548 dnl -------------------------------------------------
549 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
550 dnl and a few other things.
551 AC_DEFUN([TYPE_IN_ADDR_T],
553 AC_CHECK_TYPE([in_addr_t], ,[
554 AC_MSG_CHECKING([for in_addr_t equivalent])
555 AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
557 curl_cv_in_addr_t_equiv=
558 for t in "unsigned long" int size_t unsigned long; do
561 #ifdef HAVE_WINDOWS_H
562 #ifndef WIN32_LEAN_AND_MEAN
563 #define WIN32_LEAN_AND_MEAN
566 #ifdef HAVE_WINSOCK2_H
567 #include <winsock2.h>
569 #ifdef HAVE_WINSOCK_H
574 #ifdef HAVE_SYS_TYPES_H
575 #include <sys/types.h>
577 #ifdef HAVE_SYS_SOCKET_H
578 #include <sys/socket.h>
580 #ifdef HAVE_NETINET_IN_H
581 #include <netinet/in.h>
583 #ifdef HAVE_ARPA_INET_H
584 #include <arpa/inet.h>
588 $t data = inet_addr ("1.2.3.4");
590 curl_cv_in_addr_t_equiv="$t"
595 if test "x$curl_cv_in_addr_t_equiv" = x; then
596 AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
599 AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
600 AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
601 [type to use in place of in_addr_t if not defined])],
604 #ifdef HAVE_WINDOWS_H
605 #ifndef WIN32_LEAN_AND_MEAN
606 #define WIN32_LEAN_AND_MEAN
609 #ifdef HAVE_WINSOCK2_H
610 #include <winsock2.h>
612 #ifdef HAVE_WINSOCK_H
617 #ifdef HAVE_SYS_TYPES_H
618 #include <sys/types.h>
620 #ifdef HAVE_SYS_SOCKET_H
621 #include <sys/socket.h>
623 #ifdef HAVE_NETINET_IN_H
624 #include <netinet/in.h>
626 #ifdef HAVE_ARPA_INET_H
627 #include <arpa/inet.h>
635 dnl We create a function for detecting which compiler we use and then set as
636 dnl pendantic compiler options as possible for that particular compiler. The
637 dnl options are only used for debug-builds.
639 dnl This is a copy of the original found in curl's configure script. Don't
640 dnl modify this one, edit the one in curl and copy it back here when that one
643 AC_DEFUN([CURL_CC_DEBUG_OPTS],
645 if test "$GCC" = "yes"; then
647 dnl figure out gcc version!
648 AC_MSG_CHECKING([gcc version])
649 gccver=`$CC -dumpversion`
650 num1=`echo $gccver | cut -d . -f1`
651 num2=`echo $gccver | cut -d . -f2`
652 gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
653 AC_MSG_RESULT($gccver)
655 AC_MSG_CHECKING([if this is icc in disguise])
656 AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
657 dnl action if the text is found, this it has not been replaced by the
661 dnl the text was not found, it was replaced by the cpp
666 if test "$ICC" = "yes"; then
667 dnl this is icc, not gcc.
669 dnl ICC warnings we ignore:
670 dnl * 279 warns on static conditions in while expressions
671 dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
672 dnl "invalid format string conversion"
676 if test "$gccnum" -gt "600"; then
677 dnl icc 6.0 and older doesn't have the -Wall flag
682 WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
684 dnl -Wcast-align is a bit too annoying ;-)
686 if test "$gccnum" -ge "296"; then
687 dnl gcc 2.96 or later
688 WARN="$WARN -Wfloat-equal"
690 if test "$gccnum" -gt "296"; then
691 dnl this option does not exist in 2.96
692 WARN="$WARN -Wno-format-nonliteral"
695 dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
696 dnl on i686-Linux as it gives us heaps with false positives
697 if test "$gccnum" -ge "303"; then
698 dnl gcc 3.3 and later
699 WARN="$WARN -Wendif-labels -Wstrict-prototypes"
703 for flag in $CPPFLAGS; do
707 add=`echo $flag | sed 's/^-I/-isystem /g'`
715 CFLAGS="$CFLAGS $WARN"
719 dnl strip off optimizer flags
721 for flag in $CFLAGS; do
724 dnl echo "cut off $flag"
727 NEWFLAGS="$NEWFLAGS $flag"
733 ]) dnl end of AC_DEFUN()
736 dnl This macro determines if the specified struct exists in the specified file
738 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
740 AC_DEFUN([CARES_CHECK_STRUCT], [
741 AC_MSG_CHECKING([for struct $2])
744 struct $2 struct_instance;
745 ], ac_struct="yes", ac_found="no")
746 if test "$ac_struct" = "yes" ; then
755 dnl This macro determines if the specified constant exists in the specified file
757 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
759 AC_DEFUN([CARES_CHECK_CONSTANT], [
760 AC_MSG_CHECKING([for $2])
761 AC_EGREP_CPP(VARIABLEWASDEFINED,
770 ], ac_constant="yes", ac_constant="no"
772 if test "$ac_constant" = "yes" ; then
782 dnl This macro determines how many parameters getservbyport_r takes
783 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
784 AC_MSG_CHECKING([how many arguments getservbyport_r takes])
786 [#include <netdb.h>],
790 struct servent *p3, *p6;
791 getservbyport_r(p1, p2, p3, p4, p5, &p6);
792 ], ac_func_getservbyport_r=6,
794 [#include <netdb.h>],
799 getservbyport_r(p1, p2, p3, p4, p5);
800 ], ac_func_getservbyport_r=5,
802 [#include <netdb.h>],
807 struct servent_data p4;
808 getservbyport_r(p1, p2, p3, &p4);
809 ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
813 if test $ac_func_getservbyport_r != "0" ; then
814 AC_MSG_RESULT($ac_func_getservbyport_r)
815 AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
816 AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to
818 if test $ac_func_getservbyport_r = "4" ; then
819 AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to
822 AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
825 AC_MSG_RESULT([not found])