Fix shell globbing in CURL_CHECK_FUNC_GETNAMEINFO
[platform/upstream/c-ares.git] / acinclude.m4
1
2
3 dnl CURL_CHECK_HEADER_WINDOWS
4 dnl -------------------------------------------------
5 dnl Check for compilable and valid windows.h header 
6
7 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
8   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
9     AC_COMPILE_IFELSE([
10       AC_LANG_PROGRAM([
11 #undef inline
12 #ifndef WIN32_LEAN_AND_MEAN
13 #define WIN32_LEAN_AND_MEAN
14 #endif
15 #include <windows.h>
16       ],[
17         int dummy=2*WINVER;
18       ])
19     ],[
20       ac_cv_header_windows_h="yes"
21     ],[
22       ac_cv_header_windows_h="no"
23     ])
24   ])
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])
30   fi
31 ])
32
33
34 dnl CURL_CHECK_HEADER_WINSOCK
35 dnl -------------------------------------------------
36 dnl Check for compilable and valid winsock.h header 
37
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], [
41     AC_COMPILE_IFELSE([
42       AC_LANG_PROGRAM([
43 #undef inline
44 #ifndef WIN32_LEAN_AND_MEAN
45 #define WIN32_LEAN_AND_MEAN
46 #endif
47 #include <windows.h>
48 #include <winsock.h>
49       ],[
50         int dummy=WSACleanup();
51       ])
52     ],[
53       ac_cv_header_winsock_h="yes"
54     ],[
55       ac_cv_header_winsock_h="no"
56     ])
57   ])
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.])
61   fi
62 ])
63
64
65 dnl CURL_CHECK_HEADER_WINSOCK2
66 dnl -------------------------------------------------
67 dnl Check for compilable and valid winsock2.h header 
68
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], [
72     AC_COMPILE_IFELSE([
73       AC_LANG_PROGRAM([
74 #undef inline
75 #ifndef WIN32_LEAN_AND_MEAN
76 #define WIN32_LEAN_AND_MEAN
77 #endif
78 #include <windows.h>
79 #include <winsock2.h>
80       ],[
81         int dummy=2*IPPROTO_ESP;
82       ])
83     ],[
84       ac_cv_header_winsock2_h="yes"
85     ],[
86       ac_cv_header_winsock2_h="no"
87     ])
88   ])
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.])
92   fi
93 ])
94
95
96 dnl CURL_CHECK_HEADER_WS2TCPIP
97 dnl -------------------------------------------------
98 dnl Check for compilable and valid ws2tcpip.h header
99
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], [
103     AC_COMPILE_IFELSE([
104       AC_LANG_PROGRAM([
105 #undef inline
106 #ifndef WIN32_LEAN_AND_MEAN
107 #define WIN32_LEAN_AND_MEAN
108 #endif
109 #include <windows.h>
110 #include <winsock2.h>
111 #include <ws2tcpip.h>
112       ],[
113         int dummy=2*IP_PKTINFO;
114       ])
115     ],[
116       ac_cv_header_ws2tcpip_h="yes"
117     ],[
118       ac_cv_header_ws2tcpip_h="no"
119     ])
120   ])
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.])
124   fi
125 ])
126
127
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
132
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
141           AC_COMPILE_IFELSE([
142             AC_LANG_PROGRAM([
143 #undef inline
144 #ifdef HAVE_WINDOWS_H
145 #ifndef WIN32_LEAN_AND_MEAN
146 #define WIN32_LEAN_AND_MEAN
147 #endif
148 #include <windows.h>
149 #ifdef HAVE_WINSOCK2_H
150 #include <winsock2.h>
151 #else
152 #ifdef HAVE_WINSOCK_H
153 #include <winsock.h>
154 #endif
155 #endif
156 #else
157 #ifdef HAVE_SYS_TYPES_H
158 #include <sys/types.h>
159 #endif
160 #ifdef HAVE_SYS_SOCKET_H
161 #include <sys/socket.h>
162 #endif
163 #endif
164               int getpeername (int, $arg2 *, $t *);
165             ],[
166               $t len=0;
167               getpeername(0,0,&len);
168             ])
169           ],[
170              curl_cv_socklen_t_equiv="$t"
171              break 2
172           ])
173         done
174       done
175     ])
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])
178     else
179       AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
180         [type to use in place of socklen_t if not defined])
181     fi
182   ],[
183 #undef inline
184 #ifdef HAVE_WINDOWS_H
185 #ifndef WIN32_LEAN_AND_MEAN
186 #define WIN32_LEAN_AND_MEAN
187 #endif
188 #include <windows.h>
189 #ifdef HAVE_WINSOCK2_H
190 #include <winsock2.h>
191 #ifdef HAVE_WS2TCPIP_H
192 #include <ws2tcpip.h>
193 #endif
194 #endif
195 #else
196 #ifdef HAVE_SYS_TYPES_H
197 #include <sys/types.h>
198 #endif
199 #ifdef HAVE_SYS_SOCKET_H
200 #include <sys/socket.h>
201 #endif
202 #endif
203   ])
204 ])
205
206
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 and also defining the type qualifier of first 
216 dnl argument in GETNAMEINFO_QUAL_ARG1.
217
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)
222   #
223   AC_MSG_CHECKING([for getnameinfo])
224   AC_LINK_IFELSE([
225       AC_LANG_FUNC_LINK_TRY([getnameinfo])
226     ],[
227       AC_MSG_RESULT([yes])
228       curl_cv_getnameinfo="yes"
229     ],[
230       AC_MSG_RESULT([no])
231       curl_cv_getnameinfo="no"
232   ])
233   #
234   if test "$curl_cv_getnameinfo" != "yes"; then
235     AC_MSG_CHECKING([deeper for getnameinfo])
236     AC_TRY_LINK([
237       ],[
238         getnameinfo();
239       ],[
240         AC_MSG_RESULT([yes])
241         curl_cv_getnameinfo="yes"
242       ],[
243         AC_MSG_RESULT([but still no])
244         curl_cv_getnameinfo="no"
245     ])
246   fi
247   #
248   if test "$curl_cv_getnameinfo" != "yes"; then
249     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
250     AC_TRY_LINK([
251 #undef inline
252 #ifdef HAVE_WINDOWS_H
253 #ifndef WIN32_LEAN_AND_MEAN
254 #define WIN32_LEAN_AND_MEAN
255 #endif
256 #include <windows.h>
257 #ifdef HAVE_WINSOCK2_H
258 #include <winsock2.h>
259 #ifdef HAVE_WS2TCPIP_H
260 #include <ws2tcpip.h>
261 #endif
262 #endif
263 #else
264 #ifdef HAVE_SYS_TYPES_H
265 #include <sys/types.h>
266 #endif
267 #ifdef HAVE_SYS_SOCKET_H
268 #include <sys/socket.h>
269 #endif
270 #ifdef HAVE_NETDB_H
271 #include <netdb.h>
272 #endif
273 #endif
274       ],[
275         getnameinfo(0, 0, 0, 0, 0, 0, 0);
276       ],[ 
277         AC_MSG_RESULT([yes])
278         curl_cv_getnameinfo="yes"
279       ],[
280         AC_MSG_RESULT([but still no])
281         curl_cv_getnameinfo="no"
282     ])
283   fi
284   #
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
293               AC_COMPILE_IFELSE([
294                 AC_LANG_PROGRAM([
295 #undef inline 
296 #ifdef HAVE_WINDOWS_H
297 #ifndef WIN32_LEAN_AND_MEAN
298 #define WIN32_LEAN_AND_MEAN
299 #endif
300 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
301 #undef _WIN32_WINNT
302 #define _WIN32_WINNT 0x0501
303 #endif
304 #include <windows.h>
305 #ifdef HAVE_WINSOCK2_H
306 #include <winsock2.h> 
307 #ifdef HAVE_WS2TCPIP_H
308 #include <ws2tcpip.h>
309 #endif
310 #endif
311 #define GNICALLCONV WSAAPI
312 #else
313 #ifdef HAVE_SYS_TYPES_H
314 #include <sys/types.h>
315 #endif
316 #ifdef HAVE_SYS_SOCKET_H
317 #include <sys/socket.h>
318 #endif
319 #ifdef HAVE_NETDB_H
320 #include <netdb.h>
321 #endif
322 #define GNICALLCONV
323 #endif
324                   extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
325                                          char *, $gni_arg46,
326                                          char *, $gni_arg46,
327                                          $gni_arg7);
328                 ],[
329                   $gni_arg2 salen=0;
330                   $gni_arg46 hostlen=0;
331                   $gni_arg46 servlen=0;
332                   $gni_arg7 flags=0;
333                   int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
334                 ])
335               ],[
336                  curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
337                  break 4
338               ])
339             done
340           done
341         done
342       done
343     ]) # AC_CACHE_CHECK
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])
347     else
348       gni_prev_IFS=$IFS; IFS=','
349       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
350       IFS=$gni_prev_IFS
351       shift
352       #
353       gni_qual_type_arg1=$[1]
354       #
355       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
356         [Define to the type of arg 2 for getnameinfo.])
357       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
358         [Define to the type of args 4 and 6 for getnameinfo.])
359       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
360         [Define to the type of arg 7 for getnameinfo.])
361       #
362       gni_opts=$-
363       #
364       case $gni_opts in
365       esac
366         *f*)
367           ;;
368         *)
369           set -f
370           ;;
371       esac
372       #
373       case "$gni_qual_type_arg1" in
374         const*)
375           gni_qual_arg1=const
376           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
377         ;;
378         *)
379           gni_qual_arg1=
380           gni_type_arg1=$gni_qual_type_arg1
381         ;;
382       esac
383       #
384       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
385         [Define to the type qualifier of arg 1 for getnameinfo.])
386       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
387         [Define to the type of arg 1 for getnameinfo.])
388       #
389       case $gni_opts in
390       esac
391         *f*)
392           ;;
393         *)
394           set +f
395           ;;
396       esac
397       #
398       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
399         [Define to 1 if you have the getnameinfo function.])
400       ac_cv_func_getnameinfo="yes"
401     fi
402   fi
403 ]) # AC_DEFUN
404
405
406 dnl CURL_CHECK_NONBLOCKING_SOCKET
407 dnl -------------------------------------------------
408 dnl Check for how to set a socket to non-blocking state. There seems to exist
409 dnl four known different ways, with the one used almost everywhere being POSIX
410 dnl and XPG3, while the other different ways for different systems (old BSD,
411 dnl Windows and Amiga).
412 dnl
413 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
414 dnl O_NONBLOCK define is found but does not work. This condition is attempted
415 dnl to get caught in this script by using an excessive number of #ifdefs...
416 dnl
417 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
418 [
419   AC_MSG_CHECKING([non-blocking sockets style])
420
421   AC_TRY_COMPILE([
422 /* headers for O_NONBLOCK test */
423 #include <sys/types.h>
424 #include <unistd.h>
425 #include <fcntl.h>
426 ],[
427 /* try to compile O_NONBLOCK */
428
429 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
430 # if defined(__SVR4) || defined(__srv4__)
431 #  define PLATFORM_SOLARIS
432 # else
433 #  define PLATFORM_SUNOS4
434 # endif
435 #endif
436 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
437 # define PLATFORM_AIX_V3
438 #endif
439
440 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
441 #error "O_NONBLOCK does not work on this platform"
442 #endif
443   int socket;
444   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
445 ],[
446 dnl the O_NONBLOCK test was fine
447 nonblock="O_NONBLOCK"
448 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
449 ],[
450 dnl the code was bad, try a different program now, test 2
451
452   AC_TRY_COMPILE([
453 /* headers for FIONBIO test */
454 #include <unistd.h>
455 #include <stropts.h>
456 ],[
457 /* FIONBIO source test (old-style unix) */
458  int socket;
459  int flags = ioctl(socket, FIONBIO, &flags);
460 ],[
461 dnl FIONBIO test was good
462 nonblock="FIONBIO"
463 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
464 ],[
465 dnl FIONBIO test was also bad
466 dnl the code was bad, try a different program now, test 3
467
468   AC_TRY_COMPILE([
469 /* headers for ioctlsocket test (Windows) */
470 #undef inline
471 #ifdef HAVE_WINDOWS_H
472 #ifndef WIN32_LEAN_AND_MEAN
473 #define WIN32_LEAN_AND_MEAN
474 #endif
475 #include <windows.h>
476 #ifdef HAVE_WINSOCK2_H
477 #include <winsock2.h>
478 #else
479 #ifdef HAVE_WINSOCK_H
480 #include <winsock.h>
481 #endif
482 #endif
483 #endif
484 ],[
485 /* ioctlsocket source code */
486  SOCKET sd;
487  unsigned long flags = 0;
488  sd = socket(0, 0, 0);
489  ioctlsocket(sd, FIONBIO, &flags);
490 ],[
491 dnl ioctlsocket test was good
492 nonblock="ioctlsocket"
493 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
494 ],[
495 dnl ioctlsocket didnt compile!, go to test 4
496
497   AC_TRY_LINK([
498 /* headers for IoctlSocket test (Amiga?) */
499 #include <sys/ioctl.h>
500 ],[
501 /* IoctlSocket source code */
502  int socket;
503  int flags = IoctlSocket(socket, FIONBIO, (long)1);
504 ],[
505 dnl ioctlsocket test was good
506 nonblock="IoctlSocket"
507 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
508 ],[
509 dnl Ioctlsocket didnt compile, do test 5!
510   AC_TRY_COMPILE([
511 /* headers for SO_NONBLOCK test (BeOS) */
512 #include <socket.h>
513 ],[
514 /* SO_NONBLOCK source code */
515  long b = 1;
516  int socket;
517  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
518 ],[
519 dnl the SO_NONBLOCK test was good
520 nonblock="SO_NONBLOCK"
521 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
522 ],[
523 dnl test 5 didnt compile!
524 nonblock="nada"
525 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
526 ])
527 dnl end of fifth test
528
529 ])
530 dnl end of forth test
531
532 ])
533 dnl end of third test
534
535 ])
536 dnl end of second test
537
538 ])
539 dnl end of non-blocking try-compile test
540   AC_MSG_RESULT($nonblock)
541
542   if test "$nonblock" = "nada"; then
543     AC_MSG_WARN([non-block sockets disabled])
544   fi
545 ])
546
547
548 dnl TYPE_SOCKADDR_STORAGE
549 dnl -------------------------------------------------
550 dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
551 dnl AIX 4.3 is one known exception.
552 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
553 [
554    AC_CHECK_TYPE([struct sockaddr_storage],
555         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
556                   [if struct sockaddr_storage is defined]), ,
557    [
558 #undef inline
559 #ifdef HAVE_WINDOWS_H
560 #ifndef WIN32_LEAN_AND_MEAN
561 #define WIN32_LEAN_AND_MEAN
562 #endif
563 #include <windows.h>
564 #ifdef HAVE_WINSOCK2_H
565 #include <winsock2.h>
566 #endif
567 #else
568 #ifdef HAVE_SYS_TYPES_H
569 #include <sys/types.h>
570 #endif
571 #ifdef HAVE_SYS_SOCKET_H
572 #include <sys/socket.h>
573 #endif
574 #ifdef HAVE_NETINET_IN_H
575 #include <netinet/in.h>
576 #endif
577 #ifdef HAVE_ARPA_INET_H
578 #include <arpa/inet.h>
579 #endif
580 #endif
581    ])
582 ])
583
584
585 dnl TYPE_IN_ADDR_T
586 dnl -------------------------------------------------
587 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
588 dnl and a few other things.
589 AC_DEFUN([TYPE_IN_ADDR_T],
590 [
591    AC_CHECK_TYPE([in_addr_t], ,[
592       AC_MSG_CHECKING([for in_addr_t equivalent])
593       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
594       [
595          curl_cv_in_addr_t_equiv=
596          for t in "unsigned long" int size_t unsigned long; do
597             AC_TRY_COMPILE([
598 #undef inline
599 #ifdef HAVE_WINDOWS_H
600 #ifndef WIN32_LEAN_AND_MEAN
601 #define WIN32_LEAN_AND_MEAN
602 #endif
603 #include <windows.h>
604 #ifdef HAVE_WINSOCK2_H
605 #include <winsock2.h>
606 #else
607 #ifdef HAVE_WINSOCK_H
608 #include <winsock.h>
609 #endif
610 #endif
611 #else
612 #ifdef HAVE_SYS_TYPES_H
613 #include <sys/types.h>
614 #endif
615 #ifdef HAVE_SYS_SOCKET_H
616 #include <sys/socket.h>
617 #endif
618 #ifdef HAVE_NETINET_IN_H
619 #include <netinet/in.h>
620 #endif
621 #ifdef HAVE_ARPA_INET_H
622 #include <arpa/inet.h>
623 #endif
624 #endif
625             ],[
626                $t data = inet_addr ("1.2.3.4");
627             ],[
628                curl_cv_in_addr_t_equiv="$t"
629                break
630             ])
631          done
632
633          if test "x$curl_cv_in_addr_t_equiv" = x; then
634             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
635          fi
636       ])
637       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
638       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
639                         [type to use in place of in_addr_t if not defined])],
640       [
641 #undef inline
642 #ifdef HAVE_WINDOWS_H
643 #ifndef WIN32_LEAN_AND_MEAN
644 #define WIN32_LEAN_AND_MEAN
645 #endif
646 #include <windows.h>
647 #ifdef HAVE_WINSOCK2_H
648 #include <winsock2.h>
649 #else
650 #ifdef HAVE_WINSOCK_H
651 #include <winsock.h>
652 #endif
653 #endif
654 #else
655 #ifdef HAVE_SYS_TYPES_H
656 #include <sys/types.h>
657 #endif
658 #ifdef HAVE_SYS_SOCKET_H
659 #include <sys/socket.h>
660 #endif
661 #ifdef HAVE_NETINET_IN_H
662 #include <netinet/in.h>
663 #endif
664 #ifdef HAVE_ARPA_INET_H
665 #include <arpa/inet.h>
666 #endif
667
668 #endif
669   ]) dnl AC_CHECK_TYPE
670 ]) dnl AC_DEFUN
671
672
673 dnl We create a function for detecting which compiler we use and then set as
674 dnl pendantic compiler options as possible for that particular compiler. The
675 dnl options are only used for debug-builds.
676
677 dnl This is a copy of the original found in curl's configure script. Don't
678 dnl modify this one, edit the one in curl and copy it back here when that one
679 dnl is changed.
680
681 AC_DEFUN([CURL_CC_DEBUG_OPTS],
682 [
683     if test "$GCC" = "yes"; then
684
685        dnl figure out gcc version!
686        AC_MSG_CHECKING([gcc version])
687        gccver=`$CC -dumpversion`
688        num1=`echo $gccver | cut -d . -f1`
689        num2=`echo $gccver | cut -d . -f2`
690        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
691        AC_MSG_RESULT($gccver)
692
693        AC_MSG_CHECKING([if this is icc in disguise])
694        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
695          dnl action if the text is found, this it has not been replaced by the
696          dnl cpp
697          ICC="no"
698          AC_MSG_RESULT([no]),
699          dnl the text was not found, it was replaced by the cpp
700          ICC="yes"
701          AC_MSG_RESULT([yes])
702        )
703
704        if test "$ICC" = "yes"; then
705          dnl this is icc, not gcc.
706
707          dnl ICC warnings we ignore:
708          dnl * 279 warns on static conditions in while expressions
709          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
710          dnl   "invalid format string conversion"
711
712          WARN="-wd279,269"
713
714          if test "$gccnum" -gt "600"; then
715             dnl icc 6.0 and older doesn't have the -Wall flag
716             WARN="-Wall $WARN"
717          fi
718        else dnl $ICC = yes
719          dnl 
720          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
721
722          dnl -Wcast-align is a bit too annoying ;-)
723
724          if test "$gccnum" -ge "296"; then
725            dnl gcc 2.96 or later
726            WARN="$WARN -Wfloat-equal"
727
728            if test "$gccnum" -gt "296"; then
729              dnl this option does not exist in 2.96
730              WARN="$WARN -Wno-format-nonliteral"
731            fi
732
733            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
734            dnl on i686-Linux as it gives us heaps with false positives
735            if test "$gccnum" -ge "303"; then
736              dnl gcc 3.3 and later
737              WARN="$WARN -Wendif-labels -Wstrict-prototypes"
738            fi
739          fi
740
741          for flag in $CPPFLAGS; do
742            case "$flag" in
743             -I*)
744               dnl include path
745               add=`echo $flag | sed 's/^-I/-isystem /g'`
746               WARN="$WARN $add"
747               ;;
748            esac
749          done
750
751        fi dnl $ICC = no
752
753        CFLAGS="$CFLAGS $WARN"
754
755     fi dnl $GCC = yes
756
757     dnl strip off optimizer flags
758     NEWFLAGS=""
759     for flag in $CFLAGS; do
760       case "$flag" in
761       -O*)
762         dnl echo "cut off $flag"
763         ;;
764       *)
765         NEWFLAGS="$NEWFLAGS $flag"
766         ;;
767       esac
768     done
769     CFLAGS=$NEWFLAGS
770
771 ]) dnl end of AC_DEFUN()
772
773
774 dnl This macro determines if the specified struct exists in the specified file
775 dnl Syntax:
776 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
777
778 AC_DEFUN([CARES_CHECK_STRUCT], [
779   AC_MSG_CHECKING([for struct $2])
780   AC_TRY_COMPILE([$1], 
781     [
782       struct $2 struct_instance;
783     ], ac_struct="yes", ac_found="no")
784   if test "$ac_struct" = "yes" ; then
785     AC_MSG_RESULT(yes)
786     $3
787   else
788     AC_MSG_RESULT(no)
789     $4
790   fi
791 ])
792
793 dnl This macro determines if the specified constant exists in the specified file
794 dnl Syntax:
795 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
796
797 AC_DEFUN([CARES_CHECK_CONSTANT], [
798   AC_MSG_CHECKING([for $2])
799   AC_EGREP_CPP(VARIABLEWASDEFINED,
800    [
801       $1
802
803       #ifdef $2
804         VARIABLEWASDEFINED
805       #else
806         NJET
807       #endif
808     ], ac_constant="yes", ac_constant="no"
809   )
810   if test "$ac_constant" = "yes" ; then
811     AC_MSG_RESULT(yes)
812     $3
813   else
814     AC_MSG_RESULT(no)
815     $4
816   fi
817 ])
818
819
820 dnl This macro determines how many parameters getservbyport_r takes
821 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
822   AC_MSG_CHECKING([how many arguments getservbyport_r takes])
823   AC_TRY_LINK(
824     [#include <netdb.h>],
825     [
826       int p1, p5;
827       char *p2, p4[4096];
828       struct servent *p3, *p6;
829       getservbyport_r(p1, p2, p3, p4, p5, &p6);
830     ], ac_func_getservbyport_r=6,
831     [AC_TRY_LINK(
832       [#include <netdb.h>],
833       [
834         int p1, p5;
835         char *p2, p4[4096];
836         struct servent *p3;
837         getservbyport_r(p1, p2, p3, p4, p5);
838       ], ac_func_getservbyport_r=5,
839       [AC_TRY_LINK(
840         [#include <netdb.h>],
841         [
842           int p1;
843           char *p2;
844           struct servent *p3;
845           struct servent_data p4;
846           getservbyport_r(p1, p2, p3, &p4);
847         ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
848       )]
849     )]
850   )
851 if test $ac_func_getservbyport_r != "0" ; then
852   AC_MSG_RESULT($ac_func_getservbyport_r)
853   AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
854   AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to 
855 getservbyport_r])
856   if test $ac_func_getservbyport_r = "4" ; then
857    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to 
858 getservbyport_r])
859   else
860    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
861   fi
862 else
863   AC_MSG_RESULT([not found])
864 fi
865 ])
866
867 # Prevent libtool for checking how to run C++ compiler and check for other
868 # tools we don't want to use. We do this by m4-defining the _LT_AC_TAGCONFIG
869 # variable to the code to run, as by default it uses a much more complicated
870 # approach. The code below that is actually added seems to be used for cases
871 # where configure has trouble figuring out what C compiler to use but where
872 # the installed libtool has an idea.
873 #
874 # This function is a re-implemented version of the Paolo Bonzini fix posted to
875 # the c-ares mailing list by Bram Matthys on May 6 2006. My version removes
876 # redundant code but also adds the LTCFLAGS check that wasn't in that patch.
877 #
878 # Some code in this function was extracted from the generated configure script.
879 #
880 # CARES_CLEAR_LIBTOOL_TAGS
881 AC_DEFUN([CARES_CLEAR_LIBTOOL_TAGS],
882   [m4_define([_LT_AC_TAGCONFIG], [
883   if test -f "$ltmain"; then
884     if test ! -f "${ofile}"; then
885       AC_MSG_WARN([output file `$ofile' does not exist])
886     fi
887
888     if test -z "$LTCC"; then
889       eval "`$SHELL ${ofile} --config | grep '^LTCC='`"
890       if test -z "$LTCC"; then
891         AC_MSG_WARN([output file `$ofile' does not look like a libtool
892 script])
893       else
894         AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile'])
895       fi
896     fi
897     if test -z "$LTCFLAGS"; then
898       eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`"
899     fi
900   fi
901   ])]
902 )