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