Simplify check for NEED_MALLOC_H, and make more explicit that NEED_MALLOC_H shall...
[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 #ifdef __CYGWIN__
18         HAVE_WINDOWS_H shall not be defined.
19 #else
20         int dummy=2*WINVER;
21 #endif
22       ])
23     ],[
24       ac_cv_header_windows_h="yes"
25     ],[
26       ac_cv_header_windows_h="no"
27     ])
28   ])
29   case "$ac_cv_header_windows_h" in
30     yes)
31       AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
32         [Define to 1 if you have the windows.h header file.])
33       AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
34         [Define to avoid automatic inclusion of winsock.h])
35       ;;
36   esac
37 ])
38
39
40 dnl CURL_CHECK_HEADER_WINSOCK
41 dnl -------------------------------------------------
42 dnl Check for compilable and valid winsock.h header 
43
44 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
45   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
46   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
47     AC_COMPILE_IFELSE([
48       AC_LANG_PROGRAM([
49 #undef inline
50 #ifndef WIN32_LEAN_AND_MEAN
51 #define WIN32_LEAN_AND_MEAN
52 #endif
53 #include <windows.h>
54 #include <winsock.h>
55       ],[
56 #ifdef __CYGWIN__
57         HAVE_WINSOCK_H shall not be defined.
58 #else
59         int dummy=WSACleanup();
60 #endif
61       ])
62     ],[
63       ac_cv_header_winsock_h="yes"
64     ],[
65       ac_cv_header_winsock_h="no"
66     ])
67   ])
68   case "$ac_cv_header_winsock_h" in
69     yes)
70       AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
71         [Define to 1 if you have the winsock.h header file.])
72       ;;
73   esac
74 ])
75
76
77 dnl CURL_CHECK_HEADER_WINSOCK2
78 dnl -------------------------------------------------
79 dnl Check for compilable and valid winsock2.h header 
80
81 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
82   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
83   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
84     AC_COMPILE_IFELSE([
85       AC_LANG_PROGRAM([
86 #undef inline
87 #ifndef WIN32_LEAN_AND_MEAN
88 #define WIN32_LEAN_AND_MEAN
89 #endif
90 #include <windows.h>
91 #include <winsock2.h>
92       ],[
93 #ifdef __CYGWIN__
94         HAVE_WINSOCK2_H shall not be defined.
95 #else
96         int dummy=2*IPPROTO_ESP;
97 #endif
98       ])
99     ],[
100       ac_cv_header_winsock2_h="yes"
101     ],[
102       ac_cv_header_winsock2_h="no"
103     ])
104   ])
105   case "$ac_cv_header_winsock2_h" in
106     yes)
107       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
108         [Define to 1 if you have the winsock2.h header file.])
109       ;;
110   esac
111 ])
112
113
114 dnl CURL_CHECK_HEADER_WS2TCPIP
115 dnl -------------------------------------------------
116 dnl Check for compilable and valid ws2tcpip.h header
117
118 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
119   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
120   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
121     AC_COMPILE_IFELSE([
122       AC_LANG_PROGRAM([
123 #undef inline
124 #ifndef WIN32_LEAN_AND_MEAN
125 #define WIN32_LEAN_AND_MEAN
126 #endif
127 #include <windows.h>
128 #include <winsock2.h>
129 #include <ws2tcpip.h>
130       ],[
131 #ifdef __CYGWIN__
132         HAVE_WS2TCPIP_H shall not be defined.
133 #else
134         int dummy=2*IP_PKTINFO;
135 #endif
136       ])
137     ],[
138       ac_cv_header_ws2tcpip_h="yes"
139     ],[
140       ac_cv_header_ws2tcpip_h="no"
141     ])
142   ])
143   case "$ac_cv_header_ws2tcpip_h" in
144     yes)
145       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
146         [Define to 1 if you have the ws2tcpip.h header file.])
147       ;;
148   esac
149 ])
150
151
152 dnl CURL_CHECK_HEADER_MALLOC
153 dnl -------------------------------------------------
154 dnl Check for compilable and valid malloc.h header,
155 dnl and check if it is needed even with stdlib.h
156
157 AC_DEFUN([CURL_CHECK_HEADER_MALLOC], [
158   AC_CACHE_CHECK([for malloc.h], [ac_cv_header_malloc_h], [
159     AC_COMPILE_IFELSE([
160       AC_LANG_PROGRAM([
161 #include <malloc.h>
162       ],[
163         void *p = malloc(10);
164         void *q = calloc(10,10);
165         free(p);
166         free(q);
167       ])
168     ],[
169       ac_cv_header_malloc_h="yes"
170     ],[
171       ac_cv_header_malloc_h="no"
172     ])
173   ])
174   if test "$ac_cv_header_malloc_h" = "yes"; then
175     AC_DEFINE_UNQUOTED(HAVE_MALLOC_H, 1,
176       [Define to 1 if you have the malloc.h header file.])
177     #
178     AC_COMPILE_IFELSE([
179       AC_LANG_PROGRAM([
180 #include <stdlib.h>
181       ],[
182         void *p = malloc(10);
183         void *q = calloc(10,10);
184         free(p);
185         free(q);
186       ])
187     ],[
188       curl_cv_need_header_malloc_h="no"
189     ],[
190       curl_cv_need_header_malloc_h="yes"
191     ])
192     #
193     case "$curl_cv_need_header_malloc_h" in
194       yes)
195         AC_DEFINE_UNQUOTED(NEED_MALLOC_H, 1,
196           [Define to 1 if you need the malloc.h header file even with stdlib.h])
197         ;;
198     esac
199   fi
200 ])
201
202
203 dnl CURL_CHECK_TYPE_SOCKLEN_T
204 dnl -------------------------------------------------
205 dnl Check for existing socklen_t type, and provide
206 dnl an equivalent type if socklen_t not available
207
208 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
209   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
210   AC_CHECK_TYPE([socklen_t], ,[
211     AC_CACHE_CHECK([for socklen_t equivalent], 
212       [curl_cv_socklen_t_equiv], [
213       curl_cv_socklen_t_equiv="unknown"
214       for arg2 in "struct sockaddr" void; do
215         for t in int size_t unsigned long "unsigned long"; do
216           AC_COMPILE_IFELSE([
217             AC_LANG_PROGRAM([
218 #undef inline
219 #ifdef HAVE_WINDOWS_H
220 #ifndef WIN32_LEAN_AND_MEAN
221 #define WIN32_LEAN_AND_MEAN
222 #endif
223 #include <windows.h>
224 #ifdef HAVE_WINSOCK2_H
225 #include <winsock2.h>
226 #else
227 #ifdef HAVE_WINSOCK_H
228 #include <winsock.h>
229 #endif
230 #endif
231 #else
232 #ifdef HAVE_SYS_TYPES_H
233 #include <sys/types.h>
234 #endif
235 #ifdef HAVE_SYS_SOCKET_H
236 #include <sys/socket.h>
237 #endif
238 #endif
239               int getpeername (int, $arg2 *, $t *);
240             ],[
241               $t len=0;
242               getpeername(0,0,&len);
243             ])
244           ],[
245              curl_cv_socklen_t_equiv="$t"
246              break 2
247           ])
248         done
249       done
250     ])
251     case "$curl_cv_socklen_t_equiv" in
252       unknown)
253         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
254         ;;
255       *)
256         AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
257           [type to use in place of socklen_t if not defined])
258         ;;
259     esac
260   ],[
261 #undef inline
262 #ifdef HAVE_WINDOWS_H
263 #ifndef WIN32_LEAN_AND_MEAN
264 #define WIN32_LEAN_AND_MEAN
265 #endif
266 #include <windows.h>
267 #ifdef HAVE_WINSOCK2_H
268 #include <winsock2.h>
269 #ifdef HAVE_WS2TCPIP_H
270 #include <ws2tcpip.h>
271 #endif
272 #endif
273 #else
274 #ifdef HAVE_SYS_TYPES_H
275 #include <sys/types.h>
276 #endif
277 #ifdef HAVE_SYS_SOCKET_H
278 #include <sys/socket.h>
279 #endif
280 #endif
281   ])
282 ])
283
284
285 dnl CURL_CHECK_FUNC_GETNAMEINFO
286 dnl -------------------------------------------------
287 dnl Test if the getnameinfo function is available, 
288 dnl and check the types of five of its arguments.
289 dnl If the function succeeds HAVE_GETNAMEINFO will be
290 dnl defined, defining the types of the arguments in
291 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
292 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
293 dnl and also defining the type qualifier of first 
294 dnl argument in GETNAMEINFO_QUAL_ARG1.
295
296 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
297   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
298   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
299   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
300   #
301   AC_MSG_CHECKING([for getnameinfo])
302   AC_LINK_IFELSE([
303       AC_LANG_FUNC_LINK_TRY([getnameinfo])
304     ],[
305       AC_MSG_RESULT([yes])
306       curl_cv_getnameinfo="yes"
307     ],[
308       AC_MSG_RESULT([no])
309       curl_cv_getnameinfo="no"
310   ])
311   #
312   if test "$curl_cv_getnameinfo" != "yes"; then
313     AC_MSG_CHECKING([deeper for getnameinfo])
314     AC_TRY_LINK([
315       ],[
316         getnameinfo();
317       ],[
318         AC_MSG_RESULT([yes])
319         curl_cv_getnameinfo="yes"
320       ],[
321         AC_MSG_RESULT([but still no])
322         curl_cv_getnameinfo="no"
323     ])
324   fi
325   #
326   if test "$curl_cv_getnameinfo" != "yes"; then
327     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
328     AC_TRY_LINK([
329 #undef inline
330 #ifdef HAVE_WINDOWS_H
331 #ifndef WIN32_LEAN_AND_MEAN
332 #define WIN32_LEAN_AND_MEAN
333 #endif
334 #include <windows.h>
335 #ifdef HAVE_WINSOCK2_H
336 #include <winsock2.h>
337 #ifdef HAVE_WS2TCPIP_H
338 #include <ws2tcpip.h>
339 #endif
340 #endif
341 #else
342 #ifdef HAVE_SYS_TYPES_H
343 #include <sys/types.h>
344 #endif
345 #ifdef HAVE_SYS_SOCKET_H
346 #include <sys/socket.h>
347 #endif
348 #ifdef HAVE_NETDB_H
349 #include <netdb.h>
350 #endif
351 #endif
352       ],[
353         getnameinfo(0, 0, 0, 0, 0, 0, 0);
354       ],[ 
355         AC_MSG_RESULT([yes])
356         curl_cv_getnameinfo="yes"
357       ],[
358         AC_MSG_RESULT([but still no])
359         curl_cv_getnameinfo="no"
360     ])
361   fi
362   #
363   if test "$curl_cv_getnameinfo" = "yes"; then
364     AC_CACHE_CHECK([types of arguments for getnameinfo],
365       [curl_cv_func_getnameinfo_args], [
366       curl_cv_func_getnameinfo_args="unknown"
367       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
368         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
369           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
370             for gni_arg7 in 'int' 'unsigned int'; do
371               AC_COMPILE_IFELSE([
372                 AC_LANG_PROGRAM([
373 #undef inline 
374 #ifdef HAVE_WINDOWS_H
375 #ifndef WIN32_LEAN_AND_MEAN
376 #define WIN32_LEAN_AND_MEAN
377 #endif
378 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
379 #undef _WIN32_WINNT
380 #define _WIN32_WINNT 0x0501
381 #endif
382 #include <windows.h>
383 #ifdef HAVE_WINSOCK2_H
384 #include <winsock2.h> 
385 #ifdef HAVE_WS2TCPIP_H
386 #include <ws2tcpip.h>
387 #endif
388 #endif
389 #define GNICALLCONV WSAAPI
390 #else
391 #ifdef HAVE_SYS_TYPES_H
392 #include <sys/types.h>
393 #endif
394 #ifdef HAVE_SYS_SOCKET_H
395 #include <sys/socket.h>
396 #endif
397 #ifdef HAVE_NETDB_H
398 #include <netdb.h>
399 #endif
400 #define GNICALLCONV
401 #endif
402                   extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
403                                          char *, $gni_arg46,
404                                          char *, $gni_arg46,
405                                          $gni_arg7);
406                 ],[
407                   $gni_arg2 salen=0;
408                   $gni_arg46 hostlen=0;
409                   $gni_arg46 servlen=0;
410                   $gni_arg7 flags=0;
411                   int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
412                 ])
413               ],[
414                  curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
415                  break 4
416               ])
417             done
418           done
419         done
420       done
421     ]) # AC_CACHE_CHECK
422     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
423       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
424       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
425     else
426       gni_prev_IFS=$IFS; IFS=','
427       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
428       IFS=$gni_prev_IFS
429       shift
430       #
431       gni_qual_type_arg1=$[1]
432       #
433       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
434         [Define to the type of arg 2 for getnameinfo.])
435       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
436         [Define to the type of args 4 and 6 for getnameinfo.])
437       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
438         [Define to the type of arg 7 for getnameinfo.])
439       #
440       prev_sh_opts=$-
441       #
442       case $prev_sh_opts in
443         *f*)
444           ;;
445         *)
446           set -f
447           ;;
448       esac
449       #
450       case "$gni_qual_type_arg1" in
451         const*)
452           gni_qual_arg1=const
453           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
454         ;;
455         *)
456           gni_qual_arg1=
457           gni_type_arg1=$gni_qual_type_arg1
458         ;;
459       esac
460       #
461       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
462         [Define to the type qualifier of arg 1 for getnameinfo.])
463       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
464         [Define to the type of arg 1 for getnameinfo.])
465       #
466       case $prev_sh_opts in
467         *f*)
468           ;;
469         *)
470           set +f
471           ;;
472       esac
473       #
474       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
475         [Define to 1 if you have the getnameinfo function.])
476       ac_cv_func_getnameinfo="yes"
477     fi
478   fi
479 ]) # AC_DEFUN
480
481
482 dnl TYPE_SOCKADDR_STORAGE
483 dnl -------------------------------------------------
484 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
485 dnl hosts have it, but AIX 4.3 is one known exception.
486
487 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
488 [
489    AC_CHECK_TYPE([struct sockaddr_storage],
490         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
491                   [if struct sockaddr_storage is defined]), ,
492    [
493 #undef inline
494 #ifdef HAVE_WINDOWS_H
495 #ifndef WIN32_LEAN_AND_MEAN
496 #define WIN32_LEAN_AND_MEAN
497 #endif
498 #include <windows.h>
499 #ifdef HAVE_WINSOCK2_H
500 #include <winsock2.h>
501 #endif
502 #else
503 #ifdef HAVE_SYS_TYPES_H
504 #include <sys/types.h>
505 #endif
506 #ifdef HAVE_SYS_SOCKET_H
507 #include <sys/socket.h>
508 #endif
509 #ifdef HAVE_NETINET_IN_H
510 #include <netinet/in.h>
511 #endif
512 #ifdef HAVE_ARPA_INET_H
513 #include <arpa/inet.h>
514 #endif
515 #endif
516    ])
517 ])
518
519
520 dnl CURL_CHECK_NI_WITHSCOPEID
521 dnl -------------------------------------------------
522 dnl Check for working NI_WITHSCOPEID in getnameinfo()
523
524 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
525   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
526   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
527   AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
528                    netdb.h netinet/in.h arpa/inet.h)
529   #
530   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
531     [ac_cv_working_ni_withscopeid], [
532     AC_RUN_IFELSE([
533       AC_LANG_PROGRAM([
534 #ifdef HAVE_STDIO_H
535 #include <stdio.h>
536 #endif
537 #ifdef HAVE_SYS_TYPES_H
538 #include <sys/types.h>
539 #endif
540 #ifdef HAVE_SYS_SOCKET_H
541 #include <sys/socket.h>
542 #endif
543 #ifdef HAVE_NETDB_H
544 #include <netdb.h>
545 #endif
546 #ifdef HAVE_NETINET_IN_H
547 #include <netinet/in.h>
548 #endif
549 #ifdef HAVE_ARPA_INET_H
550 #include <arpa/inet.h>
551 #endif
552       ],[
553 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
554 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
555         struct sockaddr_storage sa;
556 #else
557         unsigned char sa[256];
558 #endif
559         char hostbuf[NI_MAXHOST];
560         int rc;
561         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
562         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
563         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
564         int fd = socket(AF_INET6, SOCK_STREAM, 0);
565         if(fd < 0) {
566           perror("socket()");
567           return 1; /* Error creating socket */
568         }
569         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
570         if(rc) {
571           perror("getsockname()");
572           return 2; /* Error retrieving socket name */
573         }
574         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
575         if(rc) {
576           printf("rc = %s\n", gai_strerror(rc));
577           return 3; /* Error translating socket address */
578         }
579         return 0; /* Ok, NI_WITHSCOPEID works */
580 #else
581         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
582 #endif
583       ]) # AC_LANG_PROGRAM
584     ],[
585       # Exit code == 0. Program worked.
586       ac_cv_working_ni_withscopeid="yes"
587     ],[
588       # Exit code != 0. Program failed.
589       ac_cv_working_ni_withscopeid="no"
590     ],[
591       # Program is not run when cross-compiling. So we assume
592       # NI_WITHSCOPEID will work if we are able to compile it.
593       AC_COMPILE_IFELSE([
594         AC_LANG_PROGRAM([
595 #include <sys/types.h>
596 #include <sys/socket.h>
597 #include <netdb.h>
598         ],[
599           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
600         ])
601       ],[
602         ac_cv_working_ni_withscopeid="yes"
603       ],[
604         ac_cv_working_ni_withscopeid="no"
605       ]) # AC_COMPILE_IFELSE
606     ]) # AC_RUN_IFELSE
607   ]) # AC_CACHE_CHECK
608   case "$ac_cv_working_ni_withscopeid" in
609     yes)
610       AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
611         [Define to 1 if NI_WITHSCOPEID exists and works.])
612       ;;
613   esac
614 ]) # AC_DEFUN
615
616
617 dnl CURL_CHECK_FUNC_RECV
618 dnl -------------------------------------------------
619 dnl Test if the socket recv() function is available, 
620 dnl and check its return type and the types of its 
621 dnl arguments. If the function succeeds HAVE_RECV 
622 dnl will be defined, defining the types of the arguments 
623 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
624 dnl and RECV_TYPE_ARG4, defining the type of the function
625 dnl return value in RECV_TYPE_RETV.
626
627 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
628   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
629   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
630   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
631   #
632   AC_MSG_CHECKING([for recv])
633   AC_TRY_LINK([
634 #undef inline 
635 #ifdef HAVE_WINDOWS_H
636 #ifndef WIN32_LEAN_AND_MEAN
637 #define WIN32_LEAN_AND_MEAN
638 #endif
639 #include <windows.h>
640 #ifdef HAVE_WINSOCK2_H
641 #include <winsock2.h>
642 #else
643 #ifdef HAVE_WINSOCK_H
644 #include <winsock.h>
645 #endif
646 #endif
647 #else
648 #ifdef HAVE_SYS_TYPES_H
649 #include <sys/types.h>
650 #endif
651 #ifdef HAVE_SYS_SOCKET_H
652 #include <sys/socket.h>
653 #endif
654 #endif
655     ],[
656       recv(0, 0, 0, 0);
657     ],[ 
658       AC_MSG_RESULT([yes])
659       curl_cv_recv="yes"
660     ],[
661       AC_MSG_RESULT([no])
662       curl_cv_recv="no"
663   ])
664   #
665   if test "$curl_cv_recv" = "yes"; then
666     AC_CACHE_CHECK([types of arguments and return type for recv],
667       [curl_cv_func_recv_args], [
668       curl_cv_func_recv_args="unknown"
669       for recv_retv in 'int' 'ssize_t'; do
670         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
671           for recv_arg2 in 'char *' 'void *'; do
672             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
673               for recv_arg4 in 'int' 'unsigned int'; do
674                 AC_COMPILE_IFELSE([
675                   AC_LANG_PROGRAM([
676 #undef inline 
677 #ifdef HAVE_WINDOWS_H
678 #ifndef WIN32_LEAN_AND_MEAN
679 #define WIN32_LEAN_AND_MEAN
680 #endif
681 #include <windows.h>
682 #ifdef HAVE_WINSOCK2_H
683 #include <winsock2.h>
684 #else
685 #ifdef HAVE_WINSOCK_H
686 #include <winsock.h>
687 #endif
688 #endif
689 #define RECVCALLCONV PASCAL
690 #else
691 #ifdef HAVE_SYS_TYPES_H
692 #include <sys/types.h>
693 #endif
694 #ifdef HAVE_SYS_SOCKET_H
695 #include <sys/socket.h>
696 #endif
697 #define RECVCALLCONV
698 #endif
699                     extern $recv_retv RECVCALLCONV recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
700                   ],[
701                     $recv_arg1 s=0;
702                     $recv_arg2 buf=0;
703                     $recv_arg3 len=0;
704                     $recv_arg4 flags=0;
705                     $recv_retv res = recv(s, buf, len, flags);
706                   ])
707                 ],[
708                    curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
709                    break 5
710                 ])
711               done
712             done
713           done
714         done
715       done
716     ]) # AC_CACHE_CHECK
717     if test "$curl_cv_func_recv_args" = "unknown"; then
718       AC_MSG_WARN([Cannot find proper types to use for recv args])
719       AC_MSG_WARN([HAVE_RECV will not be defined])
720     else
721       recv_prev_IFS=$IFS; IFS=','
722       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
723       IFS=$recv_prev_IFS
724       shift
725       #
726       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
727         [Define to the type of arg 1 for recv.])
728       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
729         [Define to the type of arg 2 for recv.])
730       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
731         [Define to the type of arg 3 for recv.])
732       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
733         [Define to the type of arg 4 for recv.])
734       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
735         [Define to the function return type for recv.])
736       #
737       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
738         [Define to 1 if you have the recv function.])
739       ac_cv_func_recv="yes"
740     fi
741   fi
742 ]) # AC_DEFUN
743
744
745 dnl CURL_CHECK_FUNC_SEND
746 dnl -------------------------------------------------
747 dnl Test if the socket send() function is available, 
748 dnl and check its return type and the types of its 
749 dnl arguments. If the function succeeds HAVE_SEND 
750 dnl will be defined, defining the types of the arguments 
751 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
752 dnl and SEND_TYPE_ARG4, defining the type of the function
753 dnl return value in SEND_TYPE_RETV, and also defining the 
754 dnl type qualifier of second argument in SEND_QUAL_ARG2.
755
756 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
757   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
758   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
759   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
760   #
761   AC_MSG_CHECKING([for send])
762   AC_TRY_LINK([
763 #undef inline 
764 #ifdef HAVE_WINDOWS_H
765 #ifndef WIN32_LEAN_AND_MEAN
766 #define WIN32_LEAN_AND_MEAN
767 #endif
768 #include <windows.h>
769 #ifdef HAVE_WINSOCK2_H
770 #include <winsock2.h>
771 #else
772 #ifdef HAVE_WINSOCK_H
773 #include <winsock.h>
774 #endif
775 #endif
776 #else
777 #ifdef HAVE_SYS_TYPES_H
778 #include <sys/types.h>
779 #endif
780 #ifdef HAVE_SYS_SOCKET_H
781 #include <sys/socket.h>
782 #endif
783 #endif
784     ],[
785       send(0, 0, 0, 0);
786     ],[ 
787       AC_MSG_RESULT([yes])
788       curl_cv_send="yes"
789     ],[
790       AC_MSG_RESULT([no])
791       curl_cv_send="no"
792   ])
793   #
794   if test "$curl_cv_send" = "yes"; then
795     AC_CACHE_CHECK([types of arguments and return type for send],
796       [curl_cv_func_send_args], [
797       curl_cv_func_send_args="unknown"
798       for send_retv in 'int' 'ssize_t'; do
799         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
800           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
801             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
802               for send_arg4 in 'int' 'unsigned int'; do
803                 AC_COMPILE_IFELSE([
804                   AC_LANG_PROGRAM([
805 #undef inline 
806 #ifdef HAVE_WINDOWS_H
807 #ifndef WIN32_LEAN_AND_MEAN
808 #define WIN32_LEAN_AND_MEAN
809 #endif
810 #include <windows.h>
811 #ifdef HAVE_WINSOCK2_H
812 #include <winsock2.h>
813 #else
814 #ifdef HAVE_WINSOCK_H
815 #include <winsock.h>
816 #endif
817 #endif
818 #define SENDCALLCONV PASCAL
819 #else
820 #ifdef HAVE_SYS_TYPES_H
821 #include <sys/types.h>
822 #endif
823 #ifdef HAVE_SYS_SOCKET_H
824 #include <sys/socket.h>
825 #endif
826 #define SENDCALLCONV
827 #endif
828                     extern $send_retv SENDCALLCONV send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
829                   ],[
830                     $send_arg1 s=0;
831                     $send_arg3 len=0;
832                     $send_arg4 flags=0;
833                     $send_retv res = send(s, 0, len, flags);
834                   ])
835                 ],[
836                    curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
837                    break 5
838                 ])
839               done
840             done
841           done
842         done
843       done
844     ]) # AC_CACHE_CHECK
845     if test "$curl_cv_func_send_args" = "unknown"; then
846       AC_MSG_WARN([Cannot find proper types to use for send args])
847       AC_MSG_WARN([HAVE_SEND will not be defined])
848     else
849       send_prev_IFS=$IFS; IFS=','
850       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
851       IFS=$send_prev_IFS
852       shift
853       #
854       send_qual_type_arg2=$[2]
855       #
856       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
857         [Define to the type of arg 1 for send.])
858       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
859         [Define to the type of arg 3 for send.])
860       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
861         [Define to the type of arg 4 for send.])
862       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
863         [Define to the function return type for send.])
864       #
865       prev_sh_opts=$-
866       #
867       case $prev_sh_opts in
868         *f*)
869           ;;
870         *)
871           set -f
872           ;;
873       esac
874       #
875       case "$send_qual_type_arg2" in
876         const*)
877           send_qual_arg2=const
878           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
879         ;;
880         *)
881           send_qual_arg2=
882           send_type_arg2=$send_qual_type_arg2
883         ;;
884       esac
885       #
886       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
887         [Define to the type qualifier of arg 2 for send.])
888       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
889         [Define to the type of arg 2 for send.])
890       #
891       case $prev_sh_opts in
892         *f*)
893           ;;
894         *)
895           set +f
896           ;;
897       esac
898       #
899       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
900         [Define to 1 if you have the send function.])
901       ac_cv_func_send="yes"
902     fi
903   fi
904 ]) # AC_DEFUN
905
906
907 dnl CURL_CHECK_NONBLOCKING_SOCKET
908 dnl -------------------------------------------------
909 dnl Check for how to set a socket to non-blocking state. There seems to exist
910 dnl four known different ways, with the one used almost everywhere being POSIX
911 dnl and XPG3, while the other different ways for different systems (old BSD,
912 dnl Windows and Amiga).
913 dnl
914 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
915 dnl O_NONBLOCK define is found but does not work. This condition is attempted
916 dnl to get caught in this script by using an excessive number of #ifdefs...
917 dnl
918 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
919 [
920   AC_MSG_CHECKING([non-blocking sockets style])
921
922   AC_TRY_COMPILE([
923 /* headers for O_NONBLOCK test */
924 #include <sys/types.h>
925 #include <unistd.h>
926 #include <fcntl.h>
927 ],[
928 /* try to compile O_NONBLOCK */
929
930 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
931 # if defined(__SVR4) || defined(__srv4__)
932 #  define PLATFORM_SOLARIS
933 # else
934 #  define PLATFORM_SUNOS4
935 # endif
936 #endif
937 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
938 # define PLATFORM_AIX_V3
939 #endif
940
941 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
942 #error "O_NONBLOCK does not work on this platform"
943 #endif
944   int socket;
945   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
946 ],[
947 dnl the O_NONBLOCK test was fine
948 nonblock="O_NONBLOCK"
949 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
950 ],[
951 dnl the code was bad, try a different program now, test 2
952
953   AC_TRY_COMPILE([
954 /* headers for FIONBIO test */
955 #include <unistd.h>
956 #include <stropts.h>
957 ],[
958 /* FIONBIO source test (old-style unix) */
959  int socket;
960  int flags = ioctl(socket, FIONBIO, &flags);
961 ],[
962 dnl FIONBIO test was good
963 nonblock="FIONBIO"
964 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
965 ],[
966 dnl FIONBIO test was also bad
967 dnl the code was bad, try a different program now, test 3
968
969   AC_TRY_COMPILE([
970 /* headers for ioctlsocket test (Windows) */
971 #undef inline
972 #ifdef HAVE_WINDOWS_H
973 #ifndef WIN32_LEAN_AND_MEAN
974 #define WIN32_LEAN_AND_MEAN
975 #endif
976 #include <windows.h>
977 #ifdef HAVE_WINSOCK2_H
978 #include <winsock2.h>
979 #else
980 #ifdef HAVE_WINSOCK_H
981 #include <winsock.h>
982 #endif
983 #endif
984 #endif
985 ],[
986 /* ioctlsocket source code */
987  SOCKET sd;
988  unsigned long flags = 0;
989  sd = socket(0, 0, 0);
990  ioctlsocket(sd, FIONBIO, &flags);
991 ],[
992 dnl ioctlsocket test was good
993 nonblock="ioctlsocket"
994 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
995 ],[
996 dnl ioctlsocket didnt compile!, go to test 4
997
998   AC_TRY_LINK([
999 /* headers for IoctlSocket test (Amiga?) */
1000 #include <sys/ioctl.h>
1001 ],[
1002 /* IoctlSocket source code */
1003  int socket;
1004  int flags = IoctlSocket(socket, FIONBIO, (long)1);
1005 ],[
1006 dnl ioctlsocket test was good
1007 nonblock="IoctlSocket"
1008 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
1009 ],[
1010 dnl Ioctlsocket didnt compile, do test 5!
1011   AC_TRY_COMPILE([
1012 /* headers for SO_NONBLOCK test (BeOS) */
1013 #include <socket.h>
1014 ],[
1015 /* SO_NONBLOCK source code */
1016  long b = 1;
1017  int socket;
1018  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
1019 ],[
1020 dnl the SO_NONBLOCK test was good
1021 nonblock="SO_NONBLOCK"
1022 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
1023 ],[
1024 dnl test 5 didnt compile!
1025 nonblock="nada"
1026 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
1027 ])
1028 dnl end of fifth test
1029
1030 ])
1031 dnl end of forth test
1032
1033 ])
1034 dnl end of third test
1035
1036 ])
1037 dnl end of second test
1038
1039 ])
1040 dnl end of non-blocking try-compile test
1041   AC_MSG_RESULT($nonblock)
1042
1043   if test "$nonblock" = "nada"; then
1044     AC_MSG_WARN([non-block sockets disabled])
1045   fi
1046 ])
1047
1048
1049 dnl TYPE_SOCKADDR_STORAGE
1050 dnl -------------------------------------------------
1051 dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
1052 dnl AIX 4.3 is one known exception.
1053 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
1054 [
1055    AC_CHECK_TYPE([struct sockaddr_storage],
1056         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
1057                   [if struct sockaddr_storage is defined]), ,
1058    [
1059 #undef inline
1060 #ifdef HAVE_WINDOWS_H
1061 #ifndef WIN32_LEAN_AND_MEAN
1062 #define WIN32_LEAN_AND_MEAN
1063 #endif
1064 #include <windows.h>
1065 #ifdef HAVE_WINSOCK2_H
1066 #include <winsock2.h>
1067 #endif
1068 #else
1069 #ifdef HAVE_SYS_TYPES_H
1070 #include <sys/types.h>
1071 #endif
1072 #ifdef HAVE_SYS_SOCKET_H
1073 #include <sys/socket.h>
1074 #endif
1075 #ifdef HAVE_NETINET_IN_H
1076 #include <netinet/in.h>
1077 #endif
1078 #ifdef HAVE_ARPA_INET_H
1079 #include <arpa/inet.h>
1080 #endif
1081 #endif
1082    ])
1083 ])
1084
1085
1086 dnl TYPE_IN_ADDR_T
1087 dnl -------------------------------------------------
1088 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
1089 dnl and a few other things.
1090 AC_DEFUN([TYPE_IN_ADDR_T],
1091 [
1092    AC_CHECK_TYPE([in_addr_t], ,[
1093       AC_MSG_CHECKING([for in_addr_t equivalent])
1094       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
1095       [
1096          curl_cv_in_addr_t_equiv=
1097          for t in "unsigned long" int size_t unsigned long; do
1098             AC_TRY_COMPILE([
1099 #undef inline
1100 #ifdef HAVE_WINDOWS_H
1101 #ifndef WIN32_LEAN_AND_MEAN
1102 #define WIN32_LEAN_AND_MEAN
1103 #endif
1104 #include <windows.h>
1105 #ifdef HAVE_WINSOCK2_H
1106 #include <winsock2.h>
1107 #else
1108 #ifdef HAVE_WINSOCK_H
1109 #include <winsock.h>
1110 #endif
1111 #endif
1112 #else
1113 #ifdef HAVE_SYS_TYPES_H
1114 #include <sys/types.h>
1115 #endif
1116 #ifdef HAVE_SYS_SOCKET_H
1117 #include <sys/socket.h>
1118 #endif
1119 #ifdef HAVE_NETINET_IN_H
1120 #include <netinet/in.h>
1121 #endif
1122 #ifdef HAVE_ARPA_INET_H
1123 #include <arpa/inet.h>
1124 #endif
1125 #endif
1126             ],[
1127                $t data = inet_addr ("1.2.3.4");
1128             ],[
1129                curl_cv_in_addr_t_equiv="$t"
1130                break
1131             ])
1132          done
1133
1134          if test "x$curl_cv_in_addr_t_equiv" = x; then
1135             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
1136          fi
1137       ])
1138       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
1139       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
1140                         [type to use in place of in_addr_t if not defined])],
1141       [
1142 #undef inline
1143 #ifdef HAVE_WINDOWS_H
1144 #ifndef WIN32_LEAN_AND_MEAN
1145 #define WIN32_LEAN_AND_MEAN
1146 #endif
1147 #include <windows.h>
1148 #ifdef HAVE_WINSOCK2_H
1149 #include <winsock2.h>
1150 #else
1151 #ifdef HAVE_WINSOCK_H
1152 #include <winsock.h>
1153 #endif
1154 #endif
1155 #else
1156 #ifdef HAVE_SYS_TYPES_H
1157 #include <sys/types.h>
1158 #endif
1159 #ifdef HAVE_SYS_SOCKET_H
1160 #include <sys/socket.h>
1161 #endif
1162 #ifdef HAVE_NETINET_IN_H
1163 #include <netinet/in.h>
1164 #endif
1165 #ifdef HAVE_ARPA_INET_H
1166 #include <arpa/inet.h>
1167 #endif
1168
1169 #endif
1170   ]) dnl AC_CHECK_TYPE
1171 ]) dnl AC_DEFUN
1172
1173
1174 dnl We create a function for detecting which compiler we use and then set as
1175 dnl pendantic compiler options as possible for that particular compiler. The
1176 dnl options are only used for debug-builds.
1177
1178 dnl This is a copy of the original found in curl's configure script. Don't
1179 dnl modify this one, edit the one in curl and copy it back here when that one
1180 dnl is changed.
1181
1182 AC_DEFUN([CURL_CC_DEBUG_OPTS],
1183 [
1184     if test "$GCC" = "yes"; then
1185
1186        dnl figure out gcc version!
1187        AC_MSG_CHECKING([gcc version])
1188        gccver=`$CC -dumpversion`
1189        num1=`echo $gccver | cut -d . -f1`
1190        num2=`echo $gccver | cut -d . -f2`
1191        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
1192        AC_MSG_RESULT($gccver)
1193
1194        AC_MSG_CHECKING([if this is icc in disguise])
1195        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
1196          dnl action if the text is found, this it has not been replaced by the
1197          dnl cpp
1198          ICC="no"
1199          AC_MSG_RESULT([no]),
1200          dnl the text was not found, it was replaced by the cpp
1201          ICC="yes"
1202          AC_MSG_RESULT([yes])
1203        )
1204
1205        if test "$ICC" = "yes"; then
1206          dnl this is icc, not gcc.
1207
1208          dnl ICC warnings we ignore:
1209          dnl * 279 warns on static conditions in while expressions
1210          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
1211          dnl   "invalid format string conversion"
1212
1213          WARN="-wd279,269"
1214
1215          if test "$gccnum" -gt "600"; then
1216             dnl icc 6.0 and older doesn't have the -Wall flag
1217             WARN="-Wall $WARN"
1218          fi
1219        else dnl $ICC = yes
1220          dnl 
1221          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
1222
1223          dnl -Wcast-align is a bit too annoying ;-)
1224
1225          if test "$gccnum" -ge "296"; then
1226            dnl gcc 2.96 or later
1227            WARN="$WARN -Wfloat-equal"
1228
1229            if test "$gccnum" -gt "296"; then
1230              dnl this option does not exist in 2.96
1231              WARN="$WARN -Wno-format-nonliteral"
1232            fi
1233
1234            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
1235            dnl on i686-Linux as it gives us heaps with false positives
1236            if test "$gccnum" -ge "303"; then
1237              dnl gcc 3.3 and later
1238              WARN="$WARN -Wendif-labels -Wstrict-prototypes"
1239            fi
1240          fi
1241
1242          for flag in $CPPFLAGS; do
1243            case "$flag" in
1244             -I*)
1245               dnl include path
1246               add=`echo $flag | sed 's/^-I/-isystem /g'`
1247               WARN="$WARN $add"
1248               ;;
1249            esac
1250          done
1251
1252        fi dnl $ICC = no
1253
1254        CFLAGS="$CFLAGS $WARN"
1255
1256     fi dnl $GCC = yes
1257
1258     dnl strip off optimizer flags
1259     NEWFLAGS=""
1260     for flag in $CFLAGS; do
1261       case "$flag" in
1262       -O*)
1263         dnl echo "cut off $flag"
1264         ;;
1265       *)
1266         NEWFLAGS="$NEWFLAGS $flag"
1267         ;;
1268       esac
1269     done
1270     CFLAGS=$NEWFLAGS
1271
1272 ]) dnl end of AC_DEFUN()
1273
1274
1275 dnl This macro determines if the specified struct exists in the specified file
1276 dnl Syntax:
1277 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
1278
1279 AC_DEFUN([CARES_CHECK_STRUCT], [
1280   AC_MSG_CHECKING([for struct $2])
1281   AC_TRY_COMPILE([$1], 
1282     [
1283       struct $2 struct_instance;
1284     ], ac_struct="yes", ac_found="no")
1285   if test "$ac_struct" = "yes" ; then
1286     AC_MSG_RESULT(yes)
1287     $3
1288   else
1289     AC_MSG_RESULT(no)
1290     $4
1291   fi
1292 ])
1293
1294 dnl This macro determines if the specified constant exists in the specified file
1295 dnl Syntax:
1296 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
1297
1298 AC_DEFUN([CARES_CHECK_CONSTANT], [
1299   AC_MSG_CHECKING([for $2])
1300   AC_EGREP_CPP(VARIABLEWASDEFINED,
1301    [
1302       $1
1303
1304       #ifdef $2
1305         VARIABLEWASDEFINED
1306       #else
1307         NJET
1308       #endif
1309     ], ac_constant="yes", ac_constant="no"
1310   )
1311   if test "$ac_constant" = "yes" ; then
1312     AC_MSG_RESULT(yes)
1313     $3
1314   else
1315     AC_MSG_RESULT(no)
1316     $4
1317   fi
1318 ])
1319
1320
1321 dnl This macro determines how many parameters getservbyport_r takes
1322 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
1323   AC_MSG_CHECKING([how many arguments getservbyport_r takes])
1324   AC_TRY_LINK(
1325     [#include <netdb.h>],
1326     [
1327       int p1, p5;
1328       char *p2, p4[4096];
1329       struct servent *p3, *p6;
1330       getservbyport_r(p1, p2, p3, p4, p5, &p6);
1331     ], ac_func_getservbyport_r=6,
1332     [AC_TRY_LINK(
1333       [#include <netdb.h>],
1334       [
1335         int p1, p5;
1336         char *p2, p4[4096];
1337         struct servent *p3;
1338         getservbyport_r(p1, p2, p3, p4, p5);
1339       ], ac_func_getservbyport_r=5,
1340       [AC_TRY_LINK(
1341         [#include <netdb.h>],
1342         [
1343           int p1;
1344           char *p2;
1345           struct servent *p3;
1346           struct servent_data p4;
1347           getservbyport_r(p1, p2, p3, &p4);
1348         ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
1349       )]
1350     )]
1351   )
1352 if test $ac_func_getservbyport_r != "0" ; then
1353   AC_MSG_RESULT($ac_func_getservbyport_r)
1354   AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
1355   AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to 
1356 getservbyport_r])
1357   if test $ac_func_getservbyport_r = "4" ; then
1358    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to 
1359 getservbyport_r])
1360   else
1361    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
1362   fi
1363 else
1364   AC_MSG_RESULT([not found])
1365 fi
1366 ])
1367
1368 # Prevent libtool for checking how to run C++ compiler and check for other
1369 # tools we don't want to use. We do this by m4-defining the _LT_AC_TAGCONFIG
1370 # variable to the code to run, as by default it uses a much more complicated
1371 # approach. The code below that is actually added seems to be used for cases
1372 # where configure has trouble figuring out what C compiler to use but where
1373 # the installed libtool has an idea.
1374 #
1375 # This function is a re-implemented version of the Paolo Bonzini fix posted to
1376 # the c-ares mailing list by Bram Matthys on May 6 2006. My version removes
1377 # redundant code but also adds the LTCFLAGS check that wasn't in that patch.
1378 #
1379 # Some code in this function was extracted from the generated configure script.
1380 #
1381 # CARES_CLEAR_LIBTOOL_TAGS
1382 AC_DEFUN([CARES_CLEAR_LIBTOOL_TAGS],
1383   [m4_define([_LT_AC_TAGCONFIG], [
1384   if test -f "$ltmain"; then
1385     if test ! -f "${ofile}"; then
1386       AC_MSG_WARN([output file `$ofile' does not exist])
1387     fi
1388
1389     if test -z "$LTCC"; then
1390       eval "`$SHELL ${ofile} --config | grep '^LTCC='`"
1391       if test -z "$LTCC"; then
1392         AC_MSG_WARN([output file `$ofile' does not look like a libtool
1393 script])
1394       else
1395         AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile'])
1396       fi
1397     fi
1398     if test -z "$LTCFLAGS"; then
1399       eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`"
1400     fi
1401   fi
1402   ])]
1403 )