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