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 #define WIN32_LEAN_AND_MEAN
18 ac_cv_header_windows_h="yes"
20 ac_cv_header_windows_h="no"
23 if test "x$ac_cv_header_windows_h" = "xyes"; then
24 AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
25 [Define to 1 if you have the windows.h header file.])
26 AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
27 [Define to avoid automatic inclusion of winsock.h])
32 dnl CURL_CHECK_HEADER_WINSOCK
33 dnl -------------------------------------------------
34 dnl Check for compilable and valid winsock.h header
36 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
37 AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
38 AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
42 #define WIN32_LEAN_AND_MEAN
46 int dummy=WSACleanup();
49 ac_cv_header_winsock_h="yes"
51 ac_cv_header_winsock_h="no"
54 if test "x$ac_cv_header_winsock_h" = "xyes"; then
55 AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
56 [Define to 1 if you have the winsock.h header file.])
61 dnl CURL_CHECK_HEADER_WINSOCK2
62 dnl -------------------------------------------------
63 dnl Check for compilable and valid winsock2.h header
65 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
66 AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
67 AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
71 #define WIN32_LEAN_AND_MEAN
75 int dummy=2*IPPROTO_ESP;
78 ac_cv_header_winsock2_h="yes"
80 ac_cv_header_winsock2_h="no"
83 if test "x$ac_cv_header_winsock2_h" = "xyes"; then
84 AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
85 [Define to 1 if you have the winsock2.h header file.])
90 dnl CURL_CHECK_HEADER_WS2TCPIP
91 dnl -------------------------------------------------
92 dnl Check for compilable and valid ws2tcpip.h header
94 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
95 AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
96 AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
100 #define WIN32_LEAN_AND_MEAN
102 #include <winsock2.h>
103 #include <ws2tcpip.h>
105 int dummy=2*IP_PKTINFO;
108 ac_cv_header_ws2tcpip_h="yes"
110 ac_cv_header_ws2tcpip_h="no"
113 if test "x$ac_cv_header_ws2tcpip_h" = "xyes"; then
114 AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
115 [Define to 1 if you have the ws2tcpip.h header file.])
120 dnl CURL_CHECK_TYPE_SOCKLEN_T
121 dnl -------------------------------------------------
122 dnl Check for existing socklen_t type, and provide
123 dnl an equivalent type if socklen_t not available
125 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
126 AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
127 AC_CHECK_TYPE([socklen_t], ,[
128 AC_CACHE_CHECK([for socklen_t equivalent],
129 [curl_cv_socklen_t_equiv], [
130 curl_cv_socklen_t_equiv="unknown"
131 for arg2 in "struct sockaddr" void; do
132 for t in int size_t unsigned long "unsigned long"; do
136 #ifdef HAVE_WINDOWS_H
137 #define WIN32_LEAN_AND_MEAN
139 #ifdef HAVE_WINSOCK2_H
140 #include <winsock2.h>
142 #ifdef HAVE_WINSOCK_H
147 #ifdef HAVE_SYS_TYPES_H
148 #include <sys/types.h>
150 #ifdef HAVE_SYS_SOCKET_H
151 #include <sys/socket.h>
154 int getpeername (int, $arg2 *, $t *);
157 getpeername(0,0,&len);
160 curl_cv_socklen_t_equiv="$t"
166 if test "$curl_cv_socklen_t_equiv" = "unknown"; then
167 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
169 AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
170 [type to use in place of socklen_t if not defined])
173 #ifdef HAVE_WINDOWS_H
174 #ifdef HAVE_WS2TCPIP_H
175 #include <ws2tcpip.h>
178 #ifdef HAVE_SYS_TYPES_H
179 #include <sys/types.h>
181 #ifdef HAVE_SYS_SOCKET_H
182 #include <sys/socket.h>
189 dnl CURL_FUNC_GETNAMEINFO_ARGTYPES
190 dnl -------------------------------------------------
191 dnl Check the type to be passed to five of the arguments
192 dnl of getnameinfo function, and define those types in
193 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
194 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7.
195 dnl This function is experimental and its results shall
196 dnl not be trusted while this notice is in place ------
198 AC_DEFUN([CURL_FUNC_GETNAMEINFO_ARGTYPES], [
199 AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
200 AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
201 AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
202 AC_CACHE_CHECK([types of arguments for getnameinfo],
203 [curl_cv_func_getnameinfo_args], [
204 curl_cv_func_getnameinfo_args="unknown"
205 for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
206 for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
207 for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
208 for gni_arg7 in 'int' 'unsigned int'; do
212 #ifdef HAVE_WINDOWS_H
213 #define WIN32_LEAN_AND_MEAN
214 #if defined(__MINGW32__) && ( (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501) )
216 #define _WIN32_WINNT 0x0501
219 #ifdef HAVE_WINSOCK2_H
220 #include <winsock2.h>
222 #ifdef HAVE_WS2TCPIP_H
223 #include <ws2tcpip.h>
226 #ifdef HAVE_SYS_TYPES_H
227 #include <sys/types.h>
229 #ifdef HAVE_SYS_SOCKET_H
230 #include <sys/socket.h>
236 extern int getnameinfo($gni_arg1, $gni_arg2,
242 $gni_arg46 hostlen=0;
243 $gni_arg46 servlen=0;
245 int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
248 curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
256 if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
257 AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
259 gni_prev_IFS=$IFS; IFS=','
260 set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
263 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1],
264 [Define to the type of arg 1 for `getnameinfo'.])
265 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
266 [Define to the type of arg 2 for `getnameinfo'.])
267 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
268 [Define to the type of args 4 and 6 for `getnameinfo'.])
269 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
270 [Define to the type of arg 7 for `getnameinfo'.])
275 dnl Check for how to set a socket to non-blocking state. There seems to exist
276 dnl four known different ways, with the one used almost everywhere being POSIX
277 dnl and XPG3, while the other different ways for different systems (old BSD,
278 dnl Windows and Amiga).
280 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
281 dnl O_NONBLOCK define is found but does not work. This condition is attempted
282 dnl to get caught in this script by using an excessive number of #ifdefs...
284 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
286 AC_MSG_CHECKING([non-blocking sockets style])
289 /* headers for O_NONBLOCK test */
290 #include <sys/types.h>
294 /* try to compile O_NONBLOCK */
296 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
297 # if defined(__SVR4) || defined(__srv4__)
298 # define PLATFORM_SOLARIS
300 # define PLATFORM_SUNOS4
303 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
304 # define PLATFORM_AIX_V3
307 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
308 #error "O_NONBLOCK does not work on this platform"
311 int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
313 dnl the O_NONBLOCK test was fine
314 nonblock="O_NONBLOCK"
315 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
317 dnl the code was bad, try a different program now, test 2
320 /* headers for FIONBIO test */
324 /* FIONBIO source test (old-style unix) */
326 int flags = ioctl(socket, FIONBIO, &flags);
328 dnl FIONBIO test was good
330 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
332 dnl FIONBIO test was also bad
333 dnl the code was bad, try a different program now, test 3
336 /* headers for ioctlsocket test (cygwin?) */
339 /* ioctlsocket source code */
341 unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
343 dnl ioctlsocket test was good
344 nonblock="ioctlsocket"
345 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
347 dnl ioctlsocket didnt compile!, go to test 4
350 /* headers for IoctlSocket test (Amiga?) */
351 #include <sys/ioctl.h>
353 /* IoctlSocket source code */
355 int flags = IoctlSocket(socket, FIONBIO, (long)1);
357 dnl ioctlsocket test was good
358 nonblock="IoctlSocket"
359 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
361 dnl Ioctlsocket didnt compile, do test 5!
363 /* headers for SO_NONBLOCK test (BeOS) */
366 /* SO_NONBLOCK source code */
369 int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
371 dnl the SO_NONBLOCK test was good
372 nonblock="SO_NONBLOCK"
373 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
375 dnl test 5 didnt compile!
377 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
379 dnl end of fifth test
382 dnl end of forth test
385 dnl end of third test
388 dnl end of second test
391 dnl end of non-blocking try-compile test
392 AC_MSG_RESULT($nonblock)
394 if test "$nonblock" = "nada"; then
395 AC_MSG_WARN([non-block sockets disabled])
399 dnl We create a function for detecting which compiler we use and then set as
400 dnl pendantic compiler options as possible for that particular compiler. The
401 dnl options are only used for debug-builds.
403 dnl This is a copy of the original found in curl's configure script. Don't
404 dnl modify this one, edit the one in curl and copy it back here when that one
407 AC_DEFUN([CURL_CC_DEBUG_OPTS],
409 if test "$GCC" = "yes"; then
411 dnl figure out gcc version!
412 AC_MSG_CHECKING([gcc version])
413 gccver=`$CC -dumpversion`
414 num1=`echo $gccver | cut -d . -f1`
415 num2=`echo $gccver | cut -d . -f2`
416 gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
417 AC_MSG_RESULT($gccver)
419 AC_MSG_CHECKING([if this is icc in disguise])
420 AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
421 dnl action if the text is found, this it has not been replaced by the
425 dnl the text was not found, it was replaced by the cpp
430 if test "$ICC" = "yes"; then
431 dnl this is icc, not gcc.
433 dnl ICC warnings we ignore:
434 dnl * 279 warns on static conditions in while expressions
435 dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
436 dnl "invalid format string conversion"
440 if test "$gccnum" -gt "600"; then
441 dnl icc 6.0 and older doesn't have the -Wall flag
446 WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
448 dnl -Wcast-align is a bit too annoying ;-)
450 if test "$gccnum" -ge "296"; then
451 dnl gcc 2.96 or later
452 WARN="$WARN -Wfloat-equal"
454 if test "$gccnum" -gt "296"; then
455 dnl this option does not exist in 2.96
456 WARN="$WARN -Wno-format-nonliteral"
459 dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
460 dnl on i686-Linux as it gives us heaps with false positives
461 if test "$gccnum" -ge "303"; then
462 dnl gcc 3.3 and later
463 WARN="$WARN -Wendif-labels -Wstrict-prototypes"
467 for flag in $CPPFLAGS; do
471 add=`echo $flag | sed 's/^-I/-isystem /g'`
479 CFLAGS="$CFLAGS $WARN"
483 dnl strip off optimizer flags
485 for flag in $CFLAGS; do
488 dnl echo "cut off $flag"
491 NEWFLAGS="$NEWFLAGS $flag"
497 ]) dnl end of AC_DEFUN()
500 dnl This macro determines if the specified struct exists in the specified file
502 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
504 AC_DEFUN([CARES_CHECK_STRUCT], [
505 AC_MSG_CHECKING([for struct $2])
508 struct $2 struct_instance;
509 ], ac_struct="yes", ac_found="no")
510 if test "$ac_struct" = "yes" ; then
519 dnl This macro determines if the specified constant exists in the specified file
521 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
523 AC_DEFUN([CARES_CHECK_CONSTANT], [
524 AC_MSG_CHECKING([for $2])
525 AC_EGREP_CPP(VARIABLEWASDEFINED,
534 ], ac_constant="yes", ac_constant="no"
536 if test "$ac_constant" = "yes" ; then
546 dnl This macro determines how many parameters getservbyport_r takes
547 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
548 AC_MSG_CHECKING([how many arguments getservbyport_r takes])
550 [#include <netdb.h>],
554 struct servent *p3, *p6;
555 getservbyport_r(p1, p2, p3, p4, p5, &p6);
556 ], ac_func_getservbyport_r=6,
558 [#include <netdb.h>],
563 getservbyport_r(p1, p2, p3, p4, p5);
564 ], ac_func_getservbyport_r=5,
566 [#include <netdb.h>],
571 struct servent_data p4;
572 getservbyport_r(p1, p2, p3, &p4);
573 ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
577 if test $ac_func_getservbyport_r != "0" ; then
578 AC_MSG_RESULT($ac_func_getservbyport_r)
579 AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
580 AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to
582 if test $ac_func_getservbyport_r = "4" ; then
583 AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to
586 AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
589 AC_MSG_RESULT([not found])