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