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