update several macros using AC_TRY_LINK with AC_LINK_IFELSE
[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 #if defined(__CYGWIN__) || defined(__CEGCC__)
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_NATIVE_WINDOWS
41 dnl -------------------------------------------------
42 dnl Check if building a native Windows target
43
44 AC_DEFUN([CURL_CHECK_NATIVE_WINDOWS], [
45   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
46   AC_CACHE_CHECK([whether build target is a native Windows one], [ac_cv_native_windows], [
47     if test "$ac_cv_header_windows_h" = "no"; then
48       ac_cv_native_windows="no"
49     else
50       AC_COMPILE_IFELSE([
51         AC_LANG_PROGRAM([[
52         ]],[[
53 #if defined(__MINGW32__) || defined(__MINGW32CE__)
54           int dummy=1;
55 #else
56           Not a native Windows build target.
57 #endif
58         ]])
59       ],[
60         ac_cv_native_windows="yes"
61       ],[
62         ac_cv_native_windows="no"
63       ])
64     fi
65   ])
66   case "$ac_cv_native_windows" in
67     yes)
68       AC_DEFINE_UNQUOTED(NATIVE_WINDOWS, 1,
69         [Define to 1 if you are building a native Windows target.])
70       ;;
71   esac
72 ])
73
74
75 dnl CURL_CHECK_HEADER_WINSOCK
76 dnl -------------------------------------------------
77 dnl Check for compilable and valid winsock.h header 
78
79 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
80   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
81   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
82     AC_COMPILE_IFELSE([
83       AC_LANG_PROGRAM([[
84 #undef inline
85 #ifndef WIN32_LEAN_AND_MEAN
86 #define WIN32_LEAN_AND_MEAN
87 #endif
88 #include <windows.h>
89 #include <winsock.h>
90       ]],[[
91 #if defined(__CYGWIN__) || defined(__CEGCC__)
92         HAVE_WINSOCK_H shall not be defined.
93 #else
94         int dummy=WSACleanup();
95 #endif
96       ]])
97     ],[
98       ac_cv_header_winsock_h="yes"
99     ],[
100       ac_cv_header_winsock_h="no"
101     ])
102   ])
103   case "$ac_cv_header_winsock_h" in
104     yes)
105       AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
106         [Define to 1 if you have the winsock.h header file.])
107       ;;
108   esac
109 ])
110
111
112 dnl CURL_CHECK_HEADER_WINSOCK2
113 dnl -------------------------------------------------
114 dnl Check for compilable and valid winsock2.h header 
115
116 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
117   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
118   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
119     AC_COMPILE_IFELSE([
120       AC_LANG_PROGRAM([[
121 #undef inline
122 #ifndef WIN32_LEAN_AND_MEAN
123 #define WIN32_LEAN_AND_MEAN
124 #endif
125 #include <windows.h>
126 #include <winsock2.h>
127       ]],[[
128 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
129         HAVE_WINSOCK2_H shall not be defined.
130 #else
131         int dummy=2*IPPROTO_ESP;
132 #endif
133       ]])
134     ],[
135       ac_cv_header_winsock2_h="yes"
136     ],[
137       ac_cv_header_winsock2_h="no"
138     ])
139   ])
140   case "$ac_cv_header_winsock2_h" in
141     yes)
142       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
143         [Define to 1 if you have the winsock2.h header file.])
144       ;;
145   esac
146 ])
147
148
149 dnl CURL_CHECK_HEADER_WS2TCPIP
150 dnl -------------------------------------------------
151 dnl Check for compilable and valid ws2tcpip.h header
152
153 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
154   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
155   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
156     AC_COMPILE_IFELSE([
157       AC_LANG_PROGRAM([[
158 #undef inline
159 #ifndef WIN32_LEAN_AND_MEAN
160 #define WIN32_LEAN_AND_MEAN
161 #endif
162 #include <windows.h>
163 #include <winsock2.h>
164 #include <ws2tcpip.h>
165       ]],[[
166 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
167         HAVE_WS2TCPIP_H shall not be defined.
168 #else
169         int dummy=2*IP_PKTINFO;
170 #endif
171       ]])
172     ],[
173       ac_cv_header_ws2tcpip_h="yes"
174     ],[
175       ac_cv_header_ws2tcpip_h="no"
176     ])
177   ])
178   case "$ac_cv_header_ws2tcpip_h" in
179     yes)
180       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
181         [Define to 1 if you have the ws2tcpip.h header file.])
182       ;;
183   esac
184 ])
185
186
187 dnl CURL_CHECK_HEADER_MALLOC
188 dnl -------------------------------------------------
189 dnl Check for compilable and valid malloc.h header,
190 dnl and check if it is needed even with stdlib.h
191
192 AC_DEFUN([CURL_CHECK_HEADER_MALLOC], [
193   AC_CACHE_CHECK([for malloc.h], [ac_cv_header_malloc_h], [
194     AC_COMPILE_IFELSE([
195       AC_LANG_PROGRAM([[
196 #include <malloc.h>
197       ]],[[
198         void *p = malloc(10);
199         void *q = calloc(10,10);
200         free(p);
201         free(q);
202       ]])
203     ],[
204       ac_cv_header_malloc_h="yes"
205     ],[
206       ac_cv_header_malloc_h="no"
207     ])
208   ])
209   if test "$ac_cv_header_malloc_h" = "yes"; then
210     AC_DEFINE_UNQUOTED(HAVE_MALLOC_H, 1,
211       [Define to 1 if you have the malloc.h header file.])
212     #
213     AC_COMPILE_IFELSE([
214       AC_LANG_PROGRAM([[
215 #include <stdlib.h>
216       ]],[[
217         void *p = malloc(10);
218         void *q = calloc(10,10);
219         free(p);
220         free(q);
221       ]])
222     ],[
223       curl_cv_need_header_malloc_h="no"
224     ],[
225       curl_cv_need_header_malloc_h="yes"
226     ])
227     #
228     case "$curl_cv_need_header_malloc_h" in
229       yes)
230         AC_DEFINE_UNQUOTED(NEED_MALLOC_H, 1,
231           [Define to 1 if you need the malloc.h header file even with stdlib.h])
232         ;;
233     esac
234   fi
235 ])
236
237
238 dnl CURL_CHECK_TYPE_SOCKLEN_T
239 dnl -------------------------------------------------
240 dnl Check for existing socklen_t type, and provide
241 dnl an equivalent type if socklen_t not available
242
243 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
244   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
245   AC_CHECK_TYPE([socklen_t], [
246     dnl socklen_t is available
247     AC_DEFINE_UNQUOTED(HAVE_SOCKLEN_T, 1,
248       [Define to 1 if socklen_t is available or a equivalent is defined.])
249   ],[
250     dnl socklen_t not available
251     AC_CACHE_CHECK([for socklen_t equivalent],
252       [curl_cv_socklen_t_equiv], [
253       curl_cv_socklen_t_equiv="unknown"
254       for arg1 in 'int' 'SOCKET'; do
255         for arg2 in "struct sockaddr" void; do
256           for t in int size_t unsigned long "unsigned long"; do
257             AC_COMPILE_IFELSE([
258               AC_LANG_PROGRAM([[
259 #undef inline
260 #ifdef HAVE_WINDOWS_H
261 #ifndef WIN32_LEAN_AND_MEAN
262 #define WIN32_LEAN_AND_MEAN
263 #endif
264 #include <windows.h>
265 #ifdef HAVE_WINSOCK2_H
266 #include <winsock2.h>
267 #else
268 #ifdef HAVE_WINSOCK_H
269 #include <winsock.h>
270 #endif
271 #endif
272 #define GETPEERNCALLCONV PASCAL
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 #define GETPEERNCALLCONV
281 #endif
282                 extern int GETPEERNCALLCONV getpeername ($arg1, $arg2 *, $t *);
283               ]],[[
284                 $t len=0;
285                 getpeername(0,0,&len);
286               ]])
287             ],[
288                curl_cv_socklen_t_equiv="$t"
289                break 3
290             ])
291           done
292         done
293       done
294     ])
295     case "$curl_cv_socklen_t_equiv" in
296       unknown)
297         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
298         ;;
299       *)
300         AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
301           [type to use in place of socklen_t if not defined])
302         AC_DEFINE_UNQUOTED(HAVE_SOCKLEN_T, 1,
303           [Define to 1 if socklen_t is available or a equivalent is defined.])
304         ;;
305     esac
306   ],[
307 #undef inline
308 #ifdef HAVE_WINDOWS_H
309 #ifndef WIN32_LEAN_AND_MEAN
310 #define WIN32_LEAN_AND_MEAN
311 #endif
312 #include <windows.h>
313 #ifdef HAVE_WINSOCK2_H
314 #include <winsock2.h>
315 #ifdef HAVE_WS2TCPIP_H
316 #include <ws2tcpip.h>
317 #endif
318 #endif
319 #else
320 #ifdef HAVE_SYS_TYPES_H
321 #include <sys/types.h>
322 #endif
323 #ifdef HAVE_SYS_SOCKET_H
324 #include <sys/socket.h>
325 #endif
326 #endif
327   ])
328 ])
329
330
331 dnl CURL_CHECK_FUNC_GETNAMEINFO
332 dnl -------------------------------------------------
333 dnl Test if the getnameinfo function is available, 
334 dnl and check the types of five of its arguments.
335 dnl If the function succeeds HAVE_GETNAMEINFO will be
336 dnl defined, defining the types of the arguments in
337 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
338 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
339 dnl and also defining the type qualifier of first 
340 dnl argument in GETNAMEINFO_QUAL_ARG1.
341
342 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
343   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
344   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
345   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
346   #
347   AC_MSG_CHECKING([for getnameinfo])
348   AC_LINK_IFELSE([
349     AC_LANG_FUNC_LINK_TRY([getnameinfo])
350   ],[
351     AC_MSG_RESULT([yes])
352     curl_cv_getnameinfo="yes"
353   ],[
354     AC_MSG_RESULT([no])
355     curl_cv_getnameinfo="no"
356   ])
357   #
358   if test "$curl_cv_getnameinfo" != "yes"; then
359     AC_MSG_CHECKING([deeper for getnameinfo])
360     AC_LINK_IFELSE([
361       AC_LANG_PROGRAM([[
362       ]],[[
363         getnameinfo();
364       ]])
365     ],[
366       AC_MSG_RESULT([yes])
367       curl_cv_getnameinfo="yes"
368     ],[
369       AC_MSG_RESULT([but still no])
370       curl_cv_getnameinfo="no"
371     ])
372   fi
373   #
374   if test "$curl_cv_getnameinfo" != "yes"; then
375     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
376     AC_LINK_IFELSE([
377       AC_LANG_PROGRAM([[
378 #undef inline
379 #ifdef HAVE_WINDOWS_H
380 #ifndef WIN32_LEAN_AND_MEAN
381 #define WIN32_LEAN_AND_MEAN
382 #endif
383 #include <windows.h>
384 #ifdef HAVE_WINSOCK2_H
385 #include <winsock2.h>
386 #ifdef HAVE_WS2TCPIP_H
387 #include <ws2tcpip.h>
388 #endif
389 #endif
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 #endif
401       ]],[[
402         getnameinfo(0, 0, 0, 0, 0, 0, 0);
403       ]])
404     ],[
405       AC_MSG_RESULT([yes])
406       curl_cv_getnameinfo="yes"
407     ],[
408       AC_MSG_RESULT([but still no])
409       curl_cv_getnameinfo="no"
410     ])
411   fi
412   #
413   if test "$curl_cv_getnameinfo" = "yes"; then
414     AC_CACHE_CHECK([types of arguments for getnameinfo],
415       [curl_cv_func_getnameinfo_args], [
416       curl_cv_func_getnameinfo_args="unknown"
417       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
418         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
419           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
420             for gni_arg7 in 'int' 'unsigned int'; do
421               AC_COMPILE_IFELSE([
422                 AC_LANG_PROGRAM([[
423 #undef inline 
424 #ifdef HAVE_WINDOWS_H
425 #ifndef WIN32_LEAN_AND_MEAN
426 #define WIN32_LEAN_AND_MEAN
427 #endif
428 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
429 #undef _WIN32_WINNT
430 #define _WIN32_WINNT 0x0501
431 #endif
432 #include <windows.h>
433 #ifdef HAVE_WINSOCK2_H
434 #include <winsock2.h> 
435 #ifdef HAVE_WS2TCPIP_H
436 #include <ws2tcpip.h>
437 #endif
438 #endif
439 #define GNICALLCONV WSAAPI
440 #else
441 #ifdef HAVE_SYS_TYPES_H
442 #include <sys/types.h>
443 #endif
444 #ifdef HAVE_SYS_SOCKET_H
445 #include <sys/socket.h>
446 #endif
447 #ifdef HAVE_NETDB_H
448 #include <netdb.h>
449 #endif
450 #define GNICALLCONV
451 #endif
452                   extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
453                                          char *, $gni_arg46,
454                                          char *, $gni_arg46,
455                                          $gni_arg7);
456                 ]],[[
457                   $gni_arg2 salen=0;
458                   $gni_arg46 hostlen=0;
459                   $gni_arg46 servlen=0;
460                   $gni_arg7 flags=0;
461                   int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
462                 ]])
463               ],[
464                  curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
465                  break 4
466               ])
467             done
468           done
469         done
470       done
471     ]) # AC_CACHE_CHECK
472     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
473       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
474       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
475     else
476       gni_prev_IFS=$IFS; IFS=','
477       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
478       IFS=$gni_prev_IFS
479       shift
480       #
481       gni_qual_type_arg1=$[1]
482       #
483       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
484         [Define to the type of arg 2 for getnameinfo.])
485       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
486         [Define to the type of args 4 and 6 for getnameinfo.])
487       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
488         [Define to the type of arg 7 for getnameinfo.])
489       #
490       prev_sh_opts=$-
491       #
492       case $prev_sh_opts in
493         *f*)
494           ;;
495         *)
496           set -f
497           ;;
498       esac
499       #
500       case "$gni_qual_type_arg1" in
501         const*)
502           gni_qual_arg1=const
503           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
504         ;;
505         *)
506           gni_qual_arg1=
507           gni_type_arg1=$gni_qual_type_arg1
508         ;;
509       esac
510       #
511       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
512         [Define to the type qualifier of arg 1 for getnameinfo.])
513       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
514         [Define to the type of arg 1 for getnameinfo.])
515       #
516       case $prev_sh_opts in
517         *f*)
518           ;;
519         *)
520           set +f
521           ;;
522       esac
523       #
524       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
525         [Define to 1 if you have the getnameinfo function.])
526       ac_cv_func_getnameinfo="yes"
527     fi
528   fi
529 ]) # AC_DEFUN
530
531
532 dnl TYPE_SOCKADDR_STORAGE
533 dnl -------------------------------------------------
534 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
535 dnl hosts have it, but AIX 4.3 is one known exception.
536
537 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
538 [
539    AC_CHECK_TYPE([struct sockaddr_storage],
540         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
541                   [if struct sockaddr_storage is defined]), ,
542    [
543 #undef inline
544 #ifdef HAVE_WINDOWS_H
545 #ifndef WIN32_LEAN_AND_MEAN
546 #define WIN32_LEAN_AND_MEAN
547 #endif
548 #include <windows.h>
549 #ifdef HAVE_WINSOCK2_H
550 #include <winsock2.h>
551 #endif
552 #else
553 #ifdef HAVE_SYS_TYPES_H
554 #include <sys/types.h>
555 #endif
556 #ifdef HAVE_SYS_SOCKET_H
557 #include <sys/socket.h>
558 #endif
559 #ifdef HAVE_NETINET_IN_H
560 #include <netinet/in.h>
561 #endif
562 #ifdef HAVE_ARPA_INET_H
563 #include <arpa/inet.h>
564 #endif
565 #endif
566    ])
567 ])
568
569
570 dnl CURL_CHECK_NI_WITHSCOPEID
571 dnl -------------------------------------------------
572 dnl Check for working NI_WITHSCOPEID in getnameinfo()
573
574 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
575   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
576   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
577   AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
578                    netdb.h netinet/in.h arpa/inet.h)
579   #
580   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
581     [ac_cv_working_ni_withscopeid], [
582     AC_RUN_IFELSE([
583       AC_LANG_PROGRAM([[
584 #ifdef HAVE_STDIO_H
585 #include <stdio.h>
586 #endif
587 #ifdef HAVE_SYS_TYPES_H
588 #include <sys/types.h>
589 #endif
590 #ifdef HAVE_SYS_SOCKET_H
591 #include <sys/socket.h>
592 #endif
593 #ifdef HAVE_NETDB_H
594 #include <netdb.h>
595 #endif
596 #ifdef HAVE_NETINET_IN_H
597 #include <netinet/in.h>
598 #endif
599 #ifdef HAVE_ARPA_INET_H
600 #include <arpa/inet.h>
601 #endif
602       ]],[[
603 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
604 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
605         struct sockaddr_storage sa;
606 #else
607         unsigned char sa[256];
608 #endif
609         char hostbuf[NI_MAXHOST];
610         int rc;
611         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
612         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
613         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
614         int fd = socket(AF_INET6, SOCK_STREAM, 0);
615         if(fd < 0) {
616           perror("socket()");
617           return 1; /* Error creating socket */
618         }
619         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
620         if(rc) {
621           perror("getsockname()");
622           return 2; /* Error retrieving socket name */
623         }
624         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
625         if(rc) {
626           printf("rc = %s\n", gai_strerror(rc));
627           return 3; /* Error translating socket address */
628         }
629         return 0; /* Ok, NI_WITHSCOPEID works */
630 #else
631         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
632 #endif
633       ]]) # AC_LANG_PROGRAM
634     ],[
635       # Exit code == 0. Program worked.
636       ac_cv_working_ni_withscopeid="yes"
637     ],[
638       # Exit code != 0. Program failed.
639       ac_cv_working_ni_withscopeid="no"
640     ],[
641       # Program is not run when cross-compiling. So we assume
642       # NI_WITHSCOPEID will work if we are able to compile it.
643       AC_COMPILE_IFELSE([
644         AC_LANG_PROGRAM([[
645 #include <sys/types.h>
646 #include <sys/socket.h>
647 #include <netdb.h>
648         ]],[[
649           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
650         ]])
651       ],[
652         ac_cv_working_ni_withscopeid="yes"
653       ],[
654         ac_cv_working_ni_withscopeid="no"
655       ]) # AC_COMPILE_IFELSE
656     ]) # AC_RUN_IFELSE
657   ]) # AC_CACHE_CHECK
658   case "$ac_cv_working_ni_withscopeid" in
659     yes)
660       AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
661         [Define to 1 if NI_WITHSCOPEID exists and works.])
662       ;;
663   esac
664 ]) # AC_DEFUN
665
666
667 dnl CURL_CHECK_FUNC_RECV
668 dnl -------------------------------------------------
669 dnl Test if the socket recv() function is available, 
670 dnl and check its return type and the types of its 
671 dnl arguments. If the function succeeds HAVE_RECV 
672 dnl will be defined, defining the types of the arguments 
673 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
674 dnl and RECV_TYPE_ARG4, defining the type of the function
675 dnl return value in RECV_TYPE_RETV.
676
677 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
678   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
679   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
680   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
681   #
682   AC_MSG_CHECKING([for recv])
683   AC_LINK_IFELSE([
684     AC_LANG_PROGRAM([[
685 #undef inline 
686 #ifdef HAVE_WINDOWS_H
687 #ifndef WIN32_LEAN_AND_MEAN
688 #define WIN32_LEAN_AND_MEAN
689 #endif
690 #include <windows.h>
691 #ifdef HAVE_WINSOCK2_H
692 #include <winsock2.h>
693 #else
694 #ifdef HAVE_WINSOCK_H
695 #include <winsock.h>
696 #endif
697 #endif
698 #else
699 #ifdef HAVE_SYS_TYPES_H
700 #include <sys/types.h>
701 #endif
702 #ifdef HAVE_SYS_SOCKET_H
703 #include <sys/socket.h>
704 #endif
705 #endif
706     ]],[[
707       recv(0, 0, 0, 0);
708     ]])
709   ],[
710     AC_MSG_RESULT([yes])
711     curl_cv_recv="yes"
712   ],[
713     AC_MSG_RESULT([no])
714     curl_cv_recv="no"
715   ])
716   #
717   if test "$curl_cv_recv" = "yes"; then
718     AC_CACHE_CHECK([types of args and return type for recv],
719       [curl_cv_func_recv_args], [
720       curl_cv_func_recv_args="unknown"
721       for recv_retv in 'int' 'ssize_t'; do
722         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
723           for recv_arg2 in 'char *' 'void *'; do
724             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
725               for recv_arg4 in 'int' 'unsigned int'; do
726                 AC_COMPILE_IFELSE([
727                   AC_LANG_PROGRAM([[
728 #undef inline 
729 #ifdef HAVE_WINDOWS_H
730 #ifndef WIN32_LEAN_AND_MEAN
731 #define WIN32_LEAN_AND_MEAN
732 #endif
733 #include <windows.h>
734 #ifdef HAVE_WINSOCK2_H
735 #include <winsock2.h>
736 #else
737 #ifdef HAVE_WINSOCK_H
738 #include <winsock.h>
739 #endif
740 #endif
741 #define RECVCALLCONV PASCAL
742 #else
743 #ifdef HAVE_SYS_TYPES_H
744 #include <sys/types.h>
745 #endif
746 #ifdef HAVE_SYS_SOCKET_H
747 #include <sys/socket.h>
748 #endif
749 #define RECVCALLCONV
750 #endif
751                     extern $recv_retv RECVCALLCONV recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
752                   ]],[[
753                     $recv_arg1 s=0;
754                     $recv_arg2 buf=0;
755                     $recv_arg3 len=0;
756                     $recv_arg4 flags=0;
757                     $recv_retv res = recv(s, buf, len, flags);
758                   ]])
759                 ],[
760                    curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
761                    break 5
762                 ])
763               done
764             done
765           done
766         done
767       done
768     ]) # AC_CACHE_CHECK
769     if test "$curl_cv_func_recv_args" = "unknown"; then
770       AC_MSG_ERROR([Cannot find proper types to use for recv args])
771     else
772       recv_prev_IFS=$IFS; IFS=','
773       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
774       IFS=$recv_prev_IFS
775       shift
776       #
777       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
778         [Define to the type of arg 1 for recv.])
779       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
780         [Define to the type of arg 2 for recv.])
781       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
782         [Define to the type of arg 3 for recv.])
783       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
784         [Define to the type of arg 4 for recv.])
785       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
786         [Define to the function return type for recv.])
787       #
788       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
789         [Define to 1 if you have the recv function.])
790       ac_cv_func_recv="yes"
791     fi
792   else
793     AC_MSG_ERROR([Unable to link function recv])
794   fi
795 ]) # AC_DEFUN
796
797
798 dnl CURL_CHECK_FUNC_SEND
799 dnl -------------------------------------------------
800 dnl Test if the socket send() function is available, 
801 dnl and check its return type and the types of its 
802 dnl arguments. If the function succeeds HAVE_SEND 
803 dnl will be defined, defining the types of the arguments 
804 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
805 dnl and SEND_TYPE_ARG4, defining the type of the function
806 dnl return value in SEND_TYPE_RETV, and also defining the 
807 dnl type qualifier of second argument in SEND_QUAL_ARG2.
808
809 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
810   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
811   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
812   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
813   #
814   AC_MSG_CHECKING([for send])
815   AC_LINK_IFELSE([
816     AC_LANG_PROGRAM([[
817 #undef inline 
818 #ifdef HAVE_WINDOWS_H
819 #ifndef WIN32_LEAN_AND_MEAN
820 #define WIN32_LEAN_AND_MEAN
821 #endif
822 #include <windows.h>
823 #ifdef HAVE_WINSOCK2_H
824 #include <winsock2.h>
825 #else
826 #ifdef HAVE_WINSOCK_H
827 #include <winsock.h>
828 #endif
829 #endif
830 #else
831 #ifdef HAVE_SYS_TYPES_H
832 #include <sys/types.h>
833 #endif
834 #ifdef HAVE_SYS_SOCKET_H
835 #include <sys/socket.h>
836 #endif
837 #endif
838     ]],[[
839       send(0, 0, 0, 0);
840     ]])
841   ],[
842     AC_MSG_RESULT([yes])
843     curl_cv_send="yes"
844   ],[
845     AC_MSG_RESULT([no])
846     curl_cv_send="no"
847   ])
848   #
849   if test "$curl_cv_send" = "yes"; then
850     AC_CACHE_CHECK([types of args and return type for send],
851       [curl_cv_func_send_args], [
852       curl_cv_func_send_args="unknown"
853       for send_retv in 'int' 'ssize_t'; do
854         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
855           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
856             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
857               for send_arg4 in 'int' 'unsigned int'; do
858                 AC_COMPILE_IFELSE([
859                   AC_LANG_PROGRAM([[
860 #undef inline 
861 #ifdef HAVE_WINDOWS_H
862 #ifndef WIN32_LEAN_AND_MEAN
863 #define WIN32_LEAN_AND_MEAN
864 #endif
865 #include <windows.h>
866 #ifdef HAVE_WINSOCK2_H
867 #include <winsock2.h>
868 #else
869 #ifdef HAVE_WINSOCK_H
870 #include <winsock.h>
871 #endif
872 #endif
873 #define SENDCALLCONV PASCAL
874 #else
875 #ifdef HAVE_SYS_TYPES_H
876 #include <sys/types.h>
877 #endif
878 #ifdef HAVE_SYS_SOCKET_H
879 #include <sys/socket.h>
880 #endif
881 #define SENDCALLCONV
882 #endif
883                     extern $send_retv SENDCALLCONV send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
884                   ]],[[
885                     $send_arg1 s=0;
886                     $send_arg3 len=0;
887                     $send_arg4 flags=0;
888                     $send_retv res = send(s, 0, len, flags);
889                   ]])
890                 ],[
891                    curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
892                    break 5
893                 ])
894               done
895             done
896           done
897         done
898       done
899     ]) # AC_CACHE_CHECK
900     if test "$curl_cv_func_send_args" = "unknown"; then
901       AC_MSG_ERROR([Cannot find proper types to use for send args])
902     else
903       send_prev_IFS=$IFS; IFS=','
904       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
905       IFS=$send_prev_IFS
906       shift
907       #
908       send_qual_type_arg2=$[2]
909       #
910       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
911         [Define to the type of arg 1 for send.])
912       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
913         [Define to the type of arg 3 for send.])
914       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
915         [Define to the type of arg 4 for send.])
916       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
917         [Define to the function return type for send.])
918       #
919       prev_sh_opts=$-
920       #
921       case $prev_sh_opts in
922         *f*)
923           ;;
924         *)
925           set -f
926           ;;
927       esac
928       #
929       case "$send_qual_type_arg2" in
930         const*)
931           send_qual_arg2=const
932           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
933         ;;
934         *)
935           send_qual_arg2=
936           send_type_arg2=$send_qual_type_arg2
937         ;;
938       esac
939       #
940       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
941         [Define to the type qualifier of arg 2 for send.])
942       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
943         [Define to the type of arg 2 for send.])
944       #
945       case $prev_sh_opts in
946         *f*)
947           ;;
948         *)
949           set +f
950           ;;
951       esac
952       #
953       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
954         [Define to 1 if you have the send function.])
955       ac_cv_func_send="yes"
956     fi
957   else
958     AC_MSG_ERROR([Unable to link function send])
959   fi
960 ]) # AC_DEFUN
961
962
963 dnl CURL_CHECK_MSG_NOSIGNAL
964 dnl -------------------------------------------------
965 dnl Check for MSG_NOSIGNAL
966
967 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
968   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
969   AC_CACHE_CHECK([for MSG_NOSIGNAL], [ac_cv_msg_nosignal], [
970     AC_COMPILE_IFELSE([
971       AC_LANG_PROGRAM([[
972 #undef inline 
973 #ifdef HAVE_WINDOWS_H
974 #ifndef WIN32_LEAN_AND_MEAN
975 #define WIN32_LEAN_AND_MEAN
976 #endif
977 #include <windows.h>
978 #ifdef HAVE_WINSOCK2_H
979 #include <winsock2.h>
980 #else
981 #ifdef HAVE_WINSOCK_H
982 #include <winsock.h>
983 #endif
984 #endif
985 #else
986 #ifdef HAVE_SYS_TYPES_H
987 #include <sys/types.h>
988 #endif
989 #ifdef HAVE_SYS_SOCKET_H
990 #include <sys/socket.h>
991 #endif
992 #endif
993       ]],[[
994         int flag=MSG_NOSIGNAL;
995       ]])
996     ],[
997       ac_cv_msg_nosignal="yes"
998     ],[
999       ac_cv_msg_nosignal="no"
1000     ])
1001   ])
1002   case "$ac_cv_msg_nosignal" in
1003     yes)
1004       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
1005         [Define to 1 if you have the MSG_NOSIGNAL flag.])
1006       ;;
1007   esac
1008 ]) # AC_DEFUN
1009
1010
1011 dnl CURL_CHECK_STRUCT_TIMEVAL
1012 dnl -------------------------------------------------
1013 dnl Check for timeval struct
1014
1015 AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
1016   AC_REQUIRE([AC_HEADER_TIME])dnl
1017   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1018   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1019   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1020   AC_CACHE_CHECK([for struct timeval], [ac_cv_struct_timeval], [
1021     AC_COMPILE_IFELSE([
1022       AC_LANG_PROGRAM([[
1023 #undef inline 
1024 #ifdef HAVE_WINDOWS_H
1025 #ifndef WIN32_LEAN_AND_MEAN
1026 #define WIN32_LEAN_AND_MEAN
1027 #endif
1028 #include <windows.h>
1029 #ifdef HAVE_WINSOCK2_H
1030 #include <winsock2.h>
1031 #else
1032 #ifdef HAVE_WINSOCK_H
1033 #include <winsock.h>
1034 #endif
1035 #endif
1036 #endif
1037 #ifdef HAVE_SYS_TYPES_H
1038 #include <sys/types.h>
1039 #endif
1040 #ifdef HAVE_SYS_TIME_H
1041 #include <sys/time.h>
1042 #ifdef TIME_WITH_SYS_TIME
1043 #include <time.h>
1044 #endif
1045 #else
1046 #ifdef HAVE_TIME_H
1047 #include <time.h>
1048 #endif
1049 #endif
1050       ]],[[
1051         struct timeval ts;
1052         ts.tv_sec  = 0;
1053         ts.tv_usec = 0;
1054       ]])
1055     ],[
1056       ac_cv_struct_timeval="yes"
1057     ],[
1058       ac_cv_struct_timeval="no"
1059     ])
1060   ])
1061   case "$ac_cv_struct_timeval" in
1062     yes)
1063       AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMEVAL, 1,
1064         [Define to 1 if you have the timeval struct.])
1065       ;;
1066   esac
1067 ]) # AC_DEFUN
1068
1069
1070 dnl TYPE_SIG_ATOMIC_T
1071 dnl -------------------------------------------------
1072 dnl Check if the sig_atomic_t type is available, and
1073 dnl verify if it is already defined as volatile.
1074
1075 AC_DEFUN([TYPE_SIG_ATOMIC_T], [
1076   AC_CHECK_HEADERS(signal.h)
1077   AC_CHECK_TYPE([sig_atomic_t],[
1078     AC_DEFINE(HAVE_SIG_ATOMIC_T, 1,
1079       [Define to 1 if sig_atomic_t is an available typedef.])
1080   ], ,[
1081 #ifdef HAVE_SIGNAL_H
1082 #include <signal.h>
1083 #endif
1084   ])
1085   case "$ac_cv_type_sig_atomic_t" in
1086     yes)
1087       #
1088       AC_MSG_CHECKING([if sig_atomic_t is already defined as volatile])
1089       AC_LINK_IFELSE([
1090         AC_LANG_PROGRAM([[
1091 #ifdef HAVE_SIGNAL_H
1092 #include <signal.h>
1093 #endif
1094         ]],[[
1095           static volatile sig_atomic_t dummy = 0;
1096         ]])
1097       ],[
1098         AC_MSG_RESULT([no])
1099         ac_cv_sig_atomic_t_volatile="no"
1100       ],[
1101         AC_MSG_RESULT([yes])
1102         ac_cv_sig_atomic_t_volatile="yes"
1103       ])
1104       #
1105       if test "$ac_cv_sig_atomic_t_volatile" = "yes"; then
1106         AC_DEFINE(HAVE_SIG_ATOMIC_T_VOLATILE, 1,
1107           [Define to 1 if sig_atomic_t is already defined as volatile.])
1108       fi
1109       ;;
1110   esac
1111 ]) # AC_DEFUN
1112
1113
1114 dnl CURL_CHECK_NONBLOCKING_SOCKET
1115 dnl -------------------------------------------------
1116 dnl Check for how to set a socket to non-blocking state. There seems to exist
1117 dnl four known different ways, with the one used almost everywhere being POSIX
1118 dnl and XPG3, while the other different ways for different systems (old BSD,
1119 dnl Windows and Amiga).
1120 dnl
1121 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
1122 dnl O_NONBLOCK define is found but does not work. This condition is attempted
1123 dnl to get caught in this script by using an excessive number of #ifdefs...
1124
1125 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET], [
1126   AC_MSG_CHECKING([non-blocking sockets style])
1127   nonblock="unknown"
1128   #
1129   AC_COMPILE_IFELSE([
1130     AC_LANG_PROGRAM([[
1131 /* headers for O_NONBLOCK test */
1132 #include <sys/types.h>
1133 #include <unistd.h>
1134 #include <fcntl.h>
1135 /* */
1136 #if defined(sun) || defined(__sun__) || \
1137     defined(__SUNPRO_C) || defined(__SUNPRO_CC)
1138 # if defined(__SVR4) || defined(__srv4__)
1139 #  define PLATFORM_SOLARIS
1140 # else
1141 #  define PLATFORM_SUNOS4
1142 # endif
1143 #endif
1144 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
1145 # define PLATFORM_AIX_V3
1146 #endif
1147 /* */
1148 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
1149 #error "O_NONBLOCK does not work on this platform"
1150 #endif
1151     ]],[[
1152       /* O_NONBLOCK source test */
1153       int socket;
1154       int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
1155     ]])
1156   ],[
1157     dnl the O_NONBLOCK test was fine
1158     nonblock="O_NONBLOCK"
1159     AC_DEFINE(HAVE_O_NONBLOCK, 1,
1160       [use O_NONBLOCK for non-blocking sockets])
1161   ])
1162   #
1163   if test "$nonblock" = "unknown"; then
1164     AC_COMPILE_IFELSE([
1165       AC_LANG_PROGRAM([[
1166 /* headers for FIONBIO test */
1167 #include <unistd.h>
1168 #include <stropts.h>
1169       ]],[[
1170         /* FIONBIO source test (old-style unix) */
1171         int socket;
1172         int flags = ioctl(socket, FIONBIO, &flags);
1173       ]])
1174     ],[
1175       dnl FIONBIO test was good
1176       nonblock="FIONBIO"
1177       AC_DEFINE(HAVE_FIONBIO, 1,
1178         [use FIONBIO for non-blocking sockets])
1179     ])
1180   fi
1181   #
1182   if test "$nonblock" = "unknown"; then
1183     AC_COMPILE_IFELSE([
1184       AC_LANG_PROGRAM([[
1185 /* headers for ioctlsocket test (Windows) */
1186 #undef inline
1187 #ifdef HAVE_WINDOWS_H
1188 #ifndef WIN32_LEAN_AND_MEAN
1189 #define WIN32_LEAN_AND_MEAN
1190 #endif
1191 #include <windows.h>
1192 #ifdef HAVE_WINSOCK2_H
1193 #include <winsock2.h>
1194 #else
1195 #ifdef HAVE_WINSOCK_H
1196 #include <winsock.h>
1197 #endif
1198 #endif
1199 #endif
1200       ]],[[
1201         /* ioctlsocket source code (Windows) */
1202         SOCKET sd;
1203         unsigned long flags = 0;
1204         sd = socket(0, 0, 0);
1205         ioctlsocket(sd, FIONBIO, &flags);
1206       ]])
1207     ],[
1208       dnl ioctlsocket test was good
1209       nonblock="ioctlsocket"
1210       AC_DEFINE(HAVE_IOCTLSOCKET, 1,
1211         [use ioctlsocket() for non-blocking sockets])
1212     ])
1213   fi
1214   #
1215   if test "$nonblock" = "unknown"; then
1216     AC_LINK_IFELSE([
1217       AC_LANG_PROGRAM([[
1218 /* headers for IoctlSocket test (Amiga?) */
1219 #include <sys/ioctl.h>
1220       ]],[[
1221         /* IoctlSocket source code (Amiga?) */
1222         int socket;
1223         int flags = IoctlSocket(socket, FIONBIO, (long)1);
1224       ]])
1225     ],[
1226       dnl Ioctlsocket test was good
1227       nonblock="IoctlSocket"
1228       AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1,
1229         [use Ioctlsocket() for non-blocking sockets])
1230     ])
1231   fi
1232   #
1233   if test "$nonblock" = "unknown"; then
1234     AC_COMPILE_IFELSE([
1235       AC_LANG_PROGRAM([[
1236 /* headers for SO_NONBLOCK test (BeOS) */
1237 #include <socket.h>
1238       ]],[[
1239         /* SO_NONBLOCK source code (BeOS) */
1240         long b = 1;
1241         int socket;
1242         int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
1243       ]])
1244     ],[
1245       dnl the SO_NONBLOCK test was good
1246       nonblock="SO_NONBLOCK"
1247       AC_DEFINE(HAVE_SO_NONBLOCK, 1,
1248         [use SO_NONBLOCK for non-blocking sockets])
1249     ])
1250   fi
1251   #
1252   AC_MSG_RESULT($nonblock)
1253   #
1254   if test "$nonblock" = "unknown"; then
1255     AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1,
1256       [disabled non-blocking sockets])
1257     AC_MSG_WARN([non-block sockets disabled])
1258   fi
1259 ])
1260
1261
1262 dnl TYPE_IN_ADDR_T
1263 dnl -------------------------------------------------
1264 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
1265 dnl and a few other things.
1266 AC_DEFUN([TYPE_IN_ADDR_T],
1267 [
1268    AC_CHECK_TYPE([in_addr_t], ,[
1269       AC_MSG_CHECKING([for in_addr_t equivalent])
1270       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
1271       [
1272          curl_cv_in_addr_t_equiv=
1273          for t in "unsigned long" int size_t unsigned long; do
1274             AC_LINK_IFELSE([
1275               AC_LANG_PROGRAM([[
1276 #undef inline
1277 #ifdef HAVE_WINDOWS_H
1278 #ifndef WIN32_LEAN_AND_MEAN
1279 #define WIN32_LEAN_AND_MEAN
1280 #endif
1281 #include <windows.h>
1282 #ifdef HAVE_WINSOCK2_H
1283 #include <winsock2.h>
1284 #else
1285 #ifdef HAVE_WINSOCK_H
1286 #include <winsock.h>
1287 #endif
1288 #endif
1289 #else
1290 #ifdef HAVE_SYS_TYPES_H
1291 #include <sys/types.h>
1292 #endif
1293 #ifdef HAVE_SYS_SOCKET_H
1294 #include <sys/socket.h>
1295 #endif
1296 #ifdef HAVE_NETINET_IN_H
1297 #include <netinet/in.h>
1298 #endif
1299 #ifdef HAVE_ARPA_INET_H
1300 #include <arpa/inet.h>
1301 #endif
1302 #endif
1303               ]],[[
1304                 $t data = inet_addr ("1.2.3.4");
1305               ]])
1306             ],[
1307               curl_cv_in_addr_t_equiv="$t"
1308               break
1309             ])
1310          done
1311
1312          if test "x$curl_cv_in_addr_t_equiv" = x; then
1313             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
1314          fi
1315       ])
1316       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
1317       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
1318                         [type to use in place of in_addr_t if not defined])],
1319       [
1320 #undef inline
1321 #ifdef HAVE_WINDOWS_H
1322 #ifndef WIN32_LEAN_AND_MEAN
1323 #define WIN32_LEAN_AND_MEAN
1324 #endif
1325 #include <windows.h>
1326 #ifdef HAVE_WINSOCK2_H
1327 #include <winsock2.h>
1328 #else
1329 #ifdef HAVE_WINSOCK_H
1330 #include <winsock.h>
1331 #endif
1332 #endif
1333 #else
1334 #ifdef HAVE_SYS_TYPES_H
1335 #include <sys/types.h>
1336 #endif
1337 #ifdef HAVE_SYS_SOCKET_H
1338 #include <sys/socket.h>
1339 #endif
1340 #ifdef HAVE_NETINET_IN_H
1341 #include <netinet/in.h>
1342 #endif
1343 #ifdef HAVE_ARPA_INET_H
1344 #include <arpa/inet.h>
1345 #endif
1346 #endif
1347   ]) dnl AC_CHECK_TYPE
1348 ]) dnl AC_DEFUN
1349
1350 dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
1351 dnl -------------------------------------------------
1352 dnl Check if monotonic clock_gettime is available.
1353
1354 AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
1355   AC_REQUIRE([AC_HEADER_TIME])dnl
1356   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1357   AC_MSG_CHECKING([for monotonic clock_gettime])
1358   AC_COMPILE_IFELSE([
1359     AC_LANG_PROGRAM([[
1360 #ifdef HAVE_SYS_TYPES_H
1361 #include <sys/types.h>
1362 #endif
1363 #ifdef HAVE_SYS_TIME_H
1364 #include <sys/time.h>
1365 #ifdef TIME_WITH_SYS_TIME
1366 #include <time.h>
1367 #endif
1368 #else
1369 #ifdef HAVE_TIME_H
1370 #include <time.h>
1371 #endif
1372 #endif
1373     ]],[[
1374       struct timespec ts;
1375       (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1376     ]])
1377   ],[
1378     AC_MSG_RESULT([yes])
1379     ac_cv_func_clock_gettime="yes"
1380   ],[
1381     AC_MSG_RESULT([no])
1382     ac_cv_func_clock_gettime="no"
1383   ])
1384   dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally
1385   dnl postponed until library linking checks for clock_gettime pass.
1386 ]) dnl AC_DEFUN
1387
1388 dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
1389 dnl -------------------------------------------------
1390 dnl If monotonic clock_gettime is available then,
1391 dnl check and prepended to LIBS any needed libraries.
1392
1393 AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
1394   AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
1395   #
1396   if test "$ac_cv_func_clock_gettime" = "yes"; then
1397     #
1398     AC_MSG_CHECKING([for clock_gettime in libraries])
1399     #
1400     curl_cv_save_LIBS="$LIBS"
1401     curl_cv_gclk_LIBS="unknown"
1402     #
1403     for x_xlibs in '' '-lrt' '-lposix4' ; do
1404       if test -z "$x_xlibs"; then
1405         LIBS="$curl_cv_save_LIBS"
1406       else
1407         LIBS="$x_xlibs $curl_cv_save_LIBS"
1408       fi
1409       AC_LINK_IFELSE([
1410         AC_LANG_PROGRAM([[
1411 #ifdef HAVE_SYS_TYPES_H
1412 #include <sys/types.h>
1413 #endif
1414 #ifdef HAVE_SYS_TIME_H
1415 #include <sys/time.h>
1416 #ifdef TIME_WITH_SYS_TIME
1417 #include <time.h>
1418 #endif
1419 #else
1420 #ifdef HAVE_TIME_H
1421 #include <time.h>
1422 #endif
1423 #endif
1424         ]],[[
1425           struct timespec ts;
1426           (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1427         ]])
1428       ],[
1429         curl_cv_gclk_LIBS="$x_xlibs"
1430         break
1431       ])
1432     done
1433     #
1434     LIBS="$curl_cv_save_LIBS"
1435     #
1436     case X-"$curl_cv_gclk_LIBS" in
1437       X-unknown)
1438         AC_MSG_RESULT([cannot find clock_gettime])
1439         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1440         ac_cv_func_clock_gettime="no"
1441         ;;
1442       X-)
1443         AC_MSG_RESULT([no additional lib required])
1444         ac_cv_func_clock_gettime="yes"
1445         ;;
1446       *)
1447         if test -z "$curl_cv_save_LIBS"; then
1448           LIBS="$curl_cv_gclk_LIBS"
1449         else
1450           LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
1451         fi
1452         AC_MSG_RESULT([$curl_cv_gclk_LIBS])
1453         ac_cv_func_clock_gettime="yes"
1454         ;;
1455     esac
1456     #
1457     case "$ac_cv_func_clock_gettime" in
1458       yes)
1459         AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
1460           [Define to 1 if you have the clock_gettime function and monotonic timer.])
1461         ;;
1462     esac
1463     #
1464   fi
1465   #
1466 ]) dnl AC_DEFUN
1467
1468 dnl **********************************************************************
1469 dnl CURL_DETECT_ICC ([ACTION-IF-YES])
1470 dnl
1471 dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
1472 dnl sets the $ICC variable to "yes" or "no"
1473 dnl **********************************************************************
1474 AC_DEFUN([CURL_DETECT_ICC],
1475 [
1476     ICC="no"
1477     AC_MSG_CHECKING([for icc in use])
1478     if test "$GCC" = "yes"; then
1479        dnl check if this is icc acting as gcc in disguise
1480        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
1481          dnl action if the text is found, this it has not been replaced by the
1482          dnl cpp
1483          ICC="no",
1484          dnl the text was not found, it was replaced by the cpp
1485          ICC="yes"
1486          AC_MSG_RESULT([yes])
1487          [$1]
1488        )
1489     fi
1490     if test "$ICC" = "no"; then
1491         # this is not ICC
1492         AC_MSG_RESULT([no])
1493     fi
1494 ])
1495
1496 dnl We create a function for detecting which compiler we use and then set as
1497 dnl pendantic compiler options as possible for that particular compiler. The
1498 dnl options are only used for debug-builds.
1499
1500 dnl This is a copy of the original found in curl's configure script. Don't
1501 dnl modify this one, edit the one in curl and copy it back here when that one
1502 dnl is changed.
1503
1504 AC_DEFUN([CURL_CC_DEBUG_OPTS],
1505 [
1506     if test "z$ICC" = "z"; then
1507       CURL_DETECT_ICC
1508     fi
1509
1510     if test "$GCC" = "yes"; then
1511
1512        dnl figure out gcc version!
1513        AC_MSG_CHECKING([gcc version])
1514        gccver=`$CC -dumpversion`
1515        num1=`echo $gccver | cut -d . -f1`
1516        num2=`echo $gccver | cut -d . -f2`
1517        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
1518        AC_MSG_RESULT($gccver)
1519
1520        if test "$ICC" = "yes"; then
1521          dnl this is icc, not gcc.
1522
1523          dnl ICC warnings we ignore:
1524          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
1525          dnl   "invalid format string conversion"
1526          dnl * 279 warns on static conditions in while expressions
1527          dnl * 981 warns on "operands are evaluated in unspecified order"
1528          dnl * 1418 "external definition with no prior declaration"
1529          dnl * 1419 warns on "external declaration in primary source file"
1530          dnl   which we know and do on purpose.
1531
1532          WARN="-wd279,269,981,1418,1419"
1533
1534          if test "$gccnum" -gt "600"; then
1535             dnl icc 6.0 and older doesn't have the -Wall flag
1536             WARN="-Wall $WARN"
1537          fi
1538        else dnl $ICC = yes
1539          dnl this is a set of options we believe *ALL* gcc versions support:
1540          WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
1541
1542          dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
1543
1544          if test "$gccnum" -ge "207"; then
1545            dnl gcc 2.7 or later
1546            WARN="$WARN -Wmissing-declarations"
1547          fi
1548
1549          if test "$gccnum" -gt "295"; then
1550            dnl only if the compiler is newer than 2.95 since we got lots of
1551            dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
1552            dnl gcc 2.95.4 on FreeBSD 4.9!
1553            WARN="$WARN -Wundef -Wno-long-long -Wsign-compare -Wshadow -Wno-multichar"
1554          fi
1555
1556          if test "$gccnum" -ge "296"; then
1557            dnl gcc 2.96 or later
1558            WARN="$WARN -Wfloat-equal"
1559          fi
1560
1561          if test "$gccnum" -gt "296"; then
1562            dnl this option does not exist in 2.96
1563            WARN="$WARN -Wno-format-nonliteral"
1564          fi
1565
1566          dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
1567          dnl on i686-Linux as it gives us heaps with false positives.
1568          dnl Also, on gcc 4.0.X it is totally unbearable and complains all
1569          dnl over making it unusable for generic purposes. Let's not use it.
1570
1571          if test "$gccnum" -ge "303"; then
1572            dnl gcc 3.3 and later
1573            WARN="$WARN -Wendif-labels -Wstrict-prototypes"
1574          fi
1575
1576          if test "$gccnum" -ge "304"; then
1577            # try these on gcc 3.4
1578            WARN="$WARN -Wdeclaration-after-statement"
1579          fi
1580
1581          for flag in $CPPFLAGS; do
1582            case "$flag" in
1583             -I*)
1584               dnl Include path, provide a -isystem option for the same dir
1585               dnl to prevent warnings in those dirs. The -isystem was not very
1586               dnl reliable on earlier gcc versions.
1587               add=`echo $flag | sed 's/^-I/-isystem /g'`
1588               WARN="$WARN $add"
1589               ;;
1590            esac
1591          done
1592
1593        fi dnl $ICC = no
1594
1595        CFLAGS="$CFLAGS $WARN"
1596
1597       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
1598
1599     else dnl $GCC = yes
1600
1601       AC_MSG_NOTICE([Added no extra compiler options])
1602
1603     fi dnl $GCC = yes
1604
1605     dnl strip off optimizer flags
1606     NEWFLAGS=""
1607     for flag in $CFLAGS; do
1608       case "$flag" in
1609       -O*)
1610         dnl echo "cut off $flag"
1611         ;;
1612       *)
1613         NEWFLAGS="$NEWFLAGS $flag"
1614         ;;
1615       esac
1616     done
1617     CFLAGS=$NEWFLAGS
1618
1619 ]) dnl end of AC_DEFUN()
1620
1621
1622 dnl This macro determines if the specified struct exists in the specified file
1623 dnl Syntax:
1624 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
1625
1626 AC_DEFUN([CARES_CHECK_STRUCT], [
1627   AC_MSG_CHECKING([for struct $2])
1628   AC_TRY_COMPILE([$1], 
1629     [
1630       struct $2 struct_instance;
1631     ], ac_struct="yes", ac_found="no")
1632   if test "$ac_struct" = "yes" ; then
1633     AC_MSG_RESULT(yes)
1634     $3
1635   else
1636     AC_MSG_RESULT(no)
1637     $4
1638   fi
1639 ])
1640
1641 dnl This macro determines if the specified constant exists in the specified file
1642 dnl Syntax:
1643 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
1644
1645 AC_DEFUN([CARES_CHECK_CONSTANT], [
1646   AC_MSG_CHECKING([for $2])
1647   AC_EGREP_CPP(VARIABLEWASDEFINED,
1648    [
1649       $1
1650
1651       #ifdef $2
1652         VARIABLEWASDEFINED
1653       #else
1654         NJET
1655       #endif
1656     ], ac_constant="yes", ac_constant="no"
1657   )
1658   if test "$ac_constant" = "yes" ; then
1659     AC_MSG_RESULT(yes)
1660     $3
1661   else
1662     AC_MSG_RESULT(no)
1663     $4
1664   fi
1665 ])
1666
1667
1668 dnl CARES_CHECK_GETSERVBYPORT_R
1669 dnl -------------------------------------------------
1670 dnl Test if the getservbyport_r function is available,
1671 dnl and find out how many parameters it takes.
1672
1673 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
1674   AC_MSG_CHECKING([how many arguments getservbyport_r takes])
1675   ac_func_getservbyport_r="unknown"
1676
1677   AC_LINK_IFELSE([
1678     AC_LANG_PROGRAM([[
1679 #include <netdb.h>
1680     ]],[[
1681       int p1, p5;
1682       char *p2, p4[4096];
1683       struct servent *p3, *p6;
1684       getservbyport_r(p1, p2, p3, p4, p5, &p6);
1685     ]])
1686   ],[
1687     ac_func_getservbyport_r="6"
1688   ])
1689
1690   if test "$ac_func_getservbyport_r" = "unknown"; then
1691     AC_LINK_IFELSE([
1692       AC_LANG_PROGRAM([[
1693 #include <netdb.h>
1694       ]],[[
1695         int p1, p5;
1696         char *p2, p4[4096];
1697         struct servent *p3;
1698         getservbyport_r(p1, p2, p3, p4, p5);
1699       ]])
1700     ],[
1701       ac_func_getservbyport_r="5"
1702     ])
1703   fi
1704
1705   if test "$ac_func_getservbyport_r" = "unknown"; then
1706     AC_LINK_IFELSE([
1707       AC_LANG_PROGRAM([[
1708 #include <netdb.h>
1709       ]],[[
1710         int p1;
1711         char *p2;
1712         struct servent *p3;
1713         struct servent_data p4;
1714         getservbyport_r(p1, p2, p3, &p4);
1715       ]])
1716     ],[
1717       ac_func_getservbyport_r="4"
1718     ])
1719   fi
1720
1721   if test "$ac_func_getservbyport_r" = "unknown"; then
1722     AC_MSG_RESULT([not found])
1723   else
1724     AC_MSG_RESULT($ac_func_getservbyport_r)
1725     AC_DEFINE(HAVE_GETSERVBYPORT_R, 1,
1726       [Specifies whether getservbyport_r is present])
1727     AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r,
1728       [Specifies the number of arguments to getservbyport_r])
1729     if test "$ac_func_getservbyport_r" = "4" ; then
1730       AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data),
1731         [Specifies the size of the buffer to pass to getservbyport_r])
1732     else
1733       AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096,
1734         [Specifies the size of the buffer to pass to getservbyport_r])
1735     fi
1736   fi
1737 ])
1738