cleanup duplicate line
[platform/upstream/curl.git] / acinclude.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
9 #
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 # $Id$
22 ###########################################################################
23
24
25 dnl CURL_CHECK_COMPILER_HALT_ON_ERROR
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 compiles with errors.
30
31 AC_DEFUN([CURL_CHECK_COMPILER_HALT_ON_ERROR], [
32   AC_MSG_CHECKING([if compiler halts on compilation errors])
33   AC_COMPILE_IFELSE([
34     AC_LANG_PROGRAM([[
35     ]],[[
36       force compilation error
37     ]])
38   ],[
39     AC_MSG_RESULT([no])
40     AC_MSG_ERROR([compiler does not halt on compilation errors.])
41   ],[
42     AC_MSG_RESULT([yes])
43   ])
44 ])
45
46
47 dnl CURL_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE
48 dnl -------------------------------------------------
49 dnl Verifies if the compiler actually halts after the
50 dnl compilation phase without generating any object
51 dnl code file, when the source code tries to define a
52 dnl type for a constant array with negative dimension.
53
54 AC_DEFUN([CURL_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE], [
55   AC_REQUIRE([CURL_CHECK_COMPILER_HALT_ON_ERROR])dnl
56   AC_MSG_CHECKING([if compiler halts on negative sized arrays])
57   AC_COMPILE_IFELSE([
58     AC_LANG_PROGRAM([[
59       typedef char bad_t[sizeof(char) == sizeof(int) ? -1 : -1 ];
60     ]],[[
61       bad_t dummy;
62     ]])
63   ],[
64     AC_MSG_RESULT([no])
65     AC_MSG_ERROR([compiler does not halt on negative sized arrays.])
66   ],[
67     AC_MSG_RESULT([yes])
68   ])
69 ])
70
71
72 dnl CURL_CHECK_DEF(SYMBOL, [INCLUDES], [SILENT])
73 dnl -------------------------------------------------
74 dnl Use the C preprocessor to find out if the given object-style symbol
75 dnl is defined and get its expansion. This macro will not use default
76 dnl includes even if no INCLUDES argument is given. This macro will run
77 dnl silently when invoked with three arguments.
78
79 AC_DEFUN([CURL_CHECK_DEF], [
80   AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
81   AS_VAR_PUSHDEF([ac_Def], [curl_cv_def_$1])dnl
82   ifelse($3,,[AC_MSG_CHECKING([for preprocessor definition of $1])])
83   tmp_exp=""
84   AC_PREPROC_IFELSE([
85     AC_LANG_SOURCE(
86 ifelse($2,,,[$2])[[
87 #ifdef $1
88 CURL_DEF_TOKEN $1
89 #endif
90     ]])
91   ],[
92     tmp_exp=`eval "$ac_cpp conftest.$ac_ext" 2>/dev/null | \
93       "$GREP" CURL_DEF_TOKEN 2>/dev/null | \
94       "$SED" 's/.*CURL_DEF_TOKEN[[ ]]//' 2>/dev/null | \
95       "$SED" 'q' 2>/dev/null`
96     if test "$tmp_exp" = "$1"; then
97       tmp_exp=""
98     fi
99   ])
100   if test -z "$tmp_exp"; then
101     AS_VAR_SET([ac_HaveDef], [no])
102     ifelse($3,,[AC_MSG_RESULT([no])])
103   else
104     AS_VAR_SET([ac_HaveDef], [yes])
105     AS_VAR_SET([ac_Def], [$tmp_exp])
106     ifelse($3,,[AC_MSG_RESULT([$tmp_exp])])
107   fi
108   AS_VAR_POPDEF([ac_Def])dnl
109   AS_VAR_POPDEF([ac_HaveDef])dnl
110 ])
111
112
113 dnl CONFIGURE_WITH_REENTRANT
114 dnl -------------------------------------------------
115 dnl This macro ensures that configuration tests done
116 dnl after this will execute with preprocessor symbol
117 dnl _REENTRANT defined. This macro also ensures that
118 dnl the generated config file will equally define it.
119
120 AC_DEFUN([CONFIGURE_WITH_REENTRANT], [
121 AC_BEFORE([$0], [AC_PREPROC_IFELSE])dnl
122 AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
123 AC_BEFORE([$0], [AC_LINK_IFELSE])dnl
124 AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
125 AH_VERBATIM([_REENTRANT],
126 [/* Define _REENTRANT if not already defined */
127 @%:@ifndef _REENTRANT
128 @%:@ define _REENTRANT
129 @%:@endif])
130 cat >>confdefs.h <<_ACEOF
131 [@%:@ifndef _REENTRANT
132 @%:@ define _REENTRANT
133 @%:@endif]
134 _ACEOF
135 ])
136
137
138 dnl CURL_CHECK_HEADER_WINDOWS
139 dnl -------------------------------------------------
140 dnl Check for compilable and valid windows.h header 
141
142 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
143   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
144     AC_COMPILE_IFELSE([
145       AC_LANG_PROGRAM([[
146 #undef inline
147 #ifndef WIN32_LEAN_AND_MEAN
148 #define WIN32_LEAN_AND_MEAN
149 #endif
150 #include <windows.h>
151       ]],[[
152 #if defined(__CYGWIN__) || defined(__CEGCC__)
153         HAVE_WINDOWS_H shall not be defined.
154 #else
155         int dummy=2*WINVER;
156 #endif
157       ]])
158     ],[
159       ac_cv_header_windows_h="yes"
160     ],[
161       ac_cv_header_windows_h="no"
162     ])
163   ])
164   case "$ac_cv_header_windows_h" in
165     yes)
166       AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
167         [Define to 1 if you have the windows.h header file.])
168       AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
169         [Define to avoid automatic inclusion of winsock.h])
170       ;;
171   esac
172 ])
173
174
175 dnl CURL_CHECK_NATIVE_WINDOWS
176 dnl -------------------------------------------------
177 dnl Check if building a native Windows target
178
179 AC_DEFUN([CURL_CHECK_NATIVE_WINDOWS], [
180   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
181   AC_CACHE_CHECK([whether build target is a native Windows one], [ac_cv_native_windows], [
182     if test "$ac_cv_header_windows_h" = "no"; then
183       ac_cv_native_windows="no"
184     else
185       AC_COMPILE_IFELSE([
186         AC_LANG_PROGRAM([[
187         ]],[[
188 #if defined(__MINGW32__) || defined(__MINGW32CE__) || \
189    (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)))
190           int dummy=1;
191 #else
192           Not a native Windows build target.
193 #endif
194         ]])
195       ],[
196         ac_cv_native_windows="yes"
197       ],[
198         ac_cv_native_windows="no"
199       ])
200     fi
201   ])
202   case "$ac_cv_native_windows" in
203     yes)
204       AC_DEFINE_UNQUOTED(NATIVE_WINDOWS, 1,
205         [Define to 1 if you are building a native Windows target.])
206       ;;
207   esac
208 ])
209
210
211 dnl CURL_CHECK_HEADER_WINSOCK
212 dnl -------------------------------------------------
213 dnl Check for compilable and valid winsock.h header 
214
215 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
216   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
217   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
218     AC_COMPILE_IFELSE([
219       AC_LANG_PROGRAM([[
220 #undef inline
221 #ifndef WIN32_LEAN_AND_MEAN
222 #define WIN32_LEAN_AND_MEAN
223 #endif
224 #include <windows.h>
225 #include <winsock.h>
226       ]],[[
227 #if defined(__CYGWIN__) || defined(__CEGCC__)
228         HAVE_WINSOCK_H shall not be defined.
229 #else
230         int dummy=WSACleanup();
231 #endif
232       ]])
233     ],[
234       ac_cv_header_winsock_h="yes"
235     ],[
236       ac_cv_header_winsock_h="no"
237     ])
238   ])
239   case "$ac_cv_header_winsock_h" in
240     yes)
241       AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
242         [Define to 1 if you have the winsock.h header file.])
243       ;;
244   esac
245 ])
246
247
248 dnl CURL_CHECK_HEADER_WINSOCK2
249 dnl -------------------------------------------------
250 dnl Check for compilable and valid winsock2.h header 
251
252 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
253   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
254   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
255     AC_COMPILE_IFELSE([
256       AC_LANG_PROGRAM([[
257 #undef inline
258 #ifndef WIN32_LEAN_AND_MEAN
259 #define WIN32_LEAN_AND_MEAN
260 #endif
261 #include <windows.h>
262 #include <winsock2.h>
263       ]],[[
264 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
265         HAVE_WINSOCK2_H shall not be defined.
266 #else
267         int dummy=2*IPPROTO_ESP;
268 #endif
269       ]])
270     ],[
271       ac_cv_header_winsock2_h="yes"
272     ],[
273       ac_cv_header_winsock2_h="no"
274     ])
275   ])
276   case "$ac_cv_header_winsock2_h" in
277     yes)
278       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
279         [Define to 1 if you have the winsock2.h header file.])
280       ;;
281   esac
282 ])
283
284
285 dnl CURL_CHECK_HEADER_WS2TCPIP
286 dnl -------------------------------------------------
287 dnl Check for compilable and valid ws2tcpip.h header
288
289 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
290   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
291   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
292     AC_COMPILE_IFELSE([
293       AC_LANG_PROGRAM([[
294 #undef inline
295 #ifndef WIN32_LEAN_AND_MEAN
296 #define WIN32_LEAN_AND_MEAN
297 #endif
298 #include <windows.h>
299 #include <winsock2.h>
300 #include <ws2tcpip.h>
301       ]],[[
302 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
303         HAVE_WS2TCPIP_H shall not be defined.
304 #else
305         int dummy=2*IP_PKTINFO;
306 #endif
307       ]])
308     ],[
309       ac_cv_header_ws2tcpip_h="yes"
310     ],[
311       ac_cv_header_ws2tcpip_h="no"
312     ])
313   ])
314   case "$ac_cv_header_ws2tcpip_h" in
315     yes)
316       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
317         [Define to 1 if you have the ws2tcpip.h header file.])
318       ;;
319   esac
320 ])
321
322
323 dnl CURL_CHECK_HEADER_WINLDAP
324 dnl -------------------------------------------------
325 dnl Check for compilable and valid winldap.h header
326
327 AC_DEFUN([CURL_CHECK_HEADER_WINLDAP], [
328   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
329   AC_CACHE_CHECK([for winldap.h], [ac_cv_header_winldap_h], [
330     AC_COMPILE_IFELSE([
331       AC_LANG_PROGRAM([[
332 #undef inline
333 #ifdef HAVE_WINDOWS_H
334 #ifndef WIN32_LEAN_AND_MEAN
335 #define WIN32_LEAN_AND_MEAN
336 #endif
337 #include <windows.h>
338 #endif
339 #include <winldap.h>
340       ]],[[
341 #if defined(__CYGWIN__) || defined(__CEGCC__)
342         HAVE_WINLDAP_H shall not be defined.
343 #else
344         LDAP *ldp = ldap_init("dummy", LDAP_PORT);
345         ULONG res = ldap_unbind(ldp);
346 #endif
347       ]])
348     ],[
349       ac_cv_header_winldap_h="yes"
350     ],[
351       ac_cv_header_winldap_h="no"
352     ])
353   ])
354   case "$ac_cv_header_winldap_h" in
355     yes)
356       AC_DEFINE_UNQUOTED(HAVE_WINLDAP_H, 1,
357         [Define to 1 if you have the winldap.h header file.])
358       ;;
359   esac
360 ])
361
362
363 dnl CURL_CHECK_HEADER_WINBER
364 dnl -------------------------------------------------
365 dnl Check for compilable and valid winber.h header
366
367 AC_DEFUN([CURL_CHECK_HEADER_WINBER], [
368   AC_REQUIRE([CURL_CHECK_HEADER_WINLDAP])dnl
369   AC_CACHE_CHECK([for winber.h], [ac_cv_header_winber_h], [
370     AC_COMPILE_IFELSE([
371       AC_LANG_PROGRAM([[
372 #undef inline
373 #ifdef HAVE_WINDOWS_H
374 #ifndef WIN32_LEAN_AND_MEAN
375 #define WIN32_LEAN_AND_MEAN
376 #endif
377 #include <windows.h>
378 #endif
379 #include <winldap.h>
380 #include <winber.h>
381       ]],[[
382 #if defined(__CYGWIN__) || defined(__CEGCC__)
383         HAVE_WINBER_H shall not be defined.
384 #else
385         BERVAL *bvp = NULL;
386         BerElement *bep = ber_init(bvp);
387         ber_free(bep, 1);
388 #endif
389       ]])
390     ],[
391       ac_cv_header_winber_h="yes"
392     ],[
393       ac_cv_header_winber_h="no"
394     ])
395   ])
396   case "$ac_cv_header_winber_h" in
397     yes)
398       AC_DEFINE_UNQUOTED(HAVE_WINBER_H, 1,
399         [Define to 1 if you have the winber.h header file.])
400       ;;
401   esac
402 ])
403
404
405 dnl CURL_CHECK_HEADER_LBER
406 dnl -------------------------------------------------
407 dnl Check for compilable and valid lber.h header,
408 dnl and check if it is needed even with ldap.h
409
410 AC_DEFUN([CURL_CHECK_HEADER_LBER], [
411   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
412   AC_CACHE_CHECK([for lber.h], [ac_cv_header_lber_h], [
413     AC_COMPILE_IFELSE([
414       AC_LANG_PROGRAM([[
415 #undef inline
416 #ifdef HAVE_WINDOWS_H
417 #ifndef WIN32_LEAN_AND_MEAN
418 #define WIN32_LEAN_AND_MEAN
419 #endif
420 #include <windows.h>
421 #else
422 #ifdef HAVE_SYS_TYPES_H
423 #include <sys/types.h>
424 #endif
425 #endif
426 #ifndef NULL
427 #define NULL (void *)0
428 #endif
429 #include <lber.h>
430       ]],[[
431         BerValue *bvp = NULL;
432         BerElement *bep = ber_init(bvp);
433         ber_free(bep, 1);
434       ]])
435     ],[
436       ac_cv_header_lber_h="yes"
437     ],[
438       ac_cv_header_lber_h="no"
439     ])
440   ])
441   if test "$ac_cv_header_lber_h" = "yes"; then
442     AC_DEFINE_UNQUOTED(HAVE_LBER_H, 1,
443       [Define to 1 if you have the lber.h header file.])
444     #
445     AC_COMPILE_IFELSE([
446       AC_LANG_PROGRAM([[
447 #undef inline
448 #ifdef HAVE_WINDOWS_H
449 #ifndef WIN32_LEAN_AND_MEAN
450 #define WIN32_LEAN_AND_MEAN
451 #endif
452 #include <windows.h>
453 #else
454 #ifdef HAVE_SYS_TYPES_H
455 #include <sys/types.h>
456 #endif
457 #endif
458 #ifndef NULL
459 #define NULL (void *)0
460 #endif
461 #ifndef LDAP_DEPRECATED
462 #define LDAP_DEPRECATED 1
463 #endif
464 #include <ldap.h>
465       ]],[[
466         BerValue *bvp = NULL;
467         BerElement *bep = ber_init(bvp);
468         ber_free(bep, 1);
469       ]])
470     ],[
471       curl_cv_need_header_lber_h="no"
472     ],[
473       curl_cv_need_header_lber_h="yes"
474     ])
475     #
476     case "$curl_cv_need_header_lber_h" in
477       yes)
478         AC_DEFINE_UNQUOTED(NEED_LBER_H, 1,
479           [Define to 1 if you need the lber.h header file even with ldap.h])
480         ;;
481     esac
482   fi
483 ])
484
485
486 dnl CURL_CHECK_HEADER_LDAP
487 dnl -------------------------------------------------
488 dnl Check for compilable and valid ldap.h header
489
490 AC_DEFUN([CURL_CHECK_HEADER_LDAP], [
491   AC_REQUIRE([CURL_CHECK_HEADER_LBER])dnl
492   AC_CACHE_CHECK([for ldap.h], [ac_cv_header_ldap_h], [
493     AC_COMPILE_IFELSE([
494       AC_LANG_PROGRAM([[
495 #undef inline
496 #ifdef HAVE_WINDOWS_H
497 #ifndef WIN32_LEAN_AND_MEAN
498 #define WIN32_LEAN_AND_MEAN
499 #endif
500 #include <windows.h>
501 #else
502 #ifdef HAVE_SYS_TYPES_H
503 #include <sys/types.h>
504 #endif
505 #endif
506 #ifndef LDAP_DEPRECATED
507 #define LDAP_DEPRECATED 1
508 #endif
509 #ifdef NEED_LBER_H
510 #include <lber.h>
511 #endif
512 #include <ldap.h>
513       ]],[[
514         LDAP *ldp = ldap_init("dummy", LDAP_PORT);
515         int res = ldap_unbind(ldp);
516       ]])
517     ],[
518       ac_cv_header_ldap_h="yes"
519     ],[
520       ac_cv_header_ldap_h="no"
521     ])
522   ])
523   case "$ac_cv_header_ldap_h" in
524     yes)
525       AC_DEFINE_UNQUOTED(HAVE_LDAP_H, 1,
526         [Define to 1 if you have the ldap.h header file.])
527       ;;
528   esac
529 ])
530
531
532 dnl CURL_CHECK_HEADER_LDAP_SSL
533 dnl -------------------------------------------------
534 dnl Check for compilable and valid ldap_ssl.h header
535
536 AC_DEFUN([CURL_CHECK_HEADER_LDAP_SSL], [
537   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
538   AC_CACHE_CHECK([for ldap_ssl.h], [ac_cv_header_ldap_ssl_h], [
539     AC_COMPILE_IFELSE([
540       AC_LANG_PROGRAM([[
541 #undef inline
542 #ifdef HAVE_WINDOWS_H
543 #ifndef WIN32_LEAN_AND_MEAN
544 #define WIN32_LEAN_AND_MEAN
545 #endif
546 #include <windows.h>
547 #else
548 #ifdef HAVE_SYS_TYPES_H
549 #include <sys/types.h>
550 #endif
551 #endif
552 #ifndef LDAP_DEPRECATED
553 #define LDAP_DEPRECATED 1
554 #endif
555 #ifdef NEED_LBER_H
556 #include <lber.h>
557 #endif
558 #ifdef HAVE_LDAP_H
559 #include <ldap.h>
560 #endif
561 #include <ldap_ssl.h>
562       ]],[[
563         LDAP *ldp = ldapssl_init("dummy", LDAPS_PORT, 1);
564       ]])
565     ],[
566       ac_cv_header_ldap_ssl_h="yes"
567     ],[
568       ac_cv_header_ldap_ssl_h="no"
569     ])
570   ])
571   case "$ac_cv_header_ldap_ssl_h" in
572     yes)
573       AC_DEFINE_UNQUOTED(HAVE_LDAP_SSL_H, 1,
574         [Define to 1 if you have the ldap_ssl.h header file.])
575       ;;
576   esac
577 ])
578
579
580 dnl CURL_CHECK_HEADER_LDAPSSL
581 dnl -------------------------------------------------
582 dnl Check for compilable and valid ldapssl.h header
583
584 AC_DEFUN([CURL_CHECK_HEADER_LDAPSSL], [
585   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
586   AC_CACHE_CHECK([for ldapssl.h], [ac_cv_header_ldapssl_h], [
587     AC_COMPILE_IFELSE([
588       AC_LANG_PROGRAM([[
589 #undef inline
590 #ifdef HAVE_WINDOWS_H
591 #ifndef WIN32_LEAN_AND_MEAN
592 #define WIN32_LEAN_AND_MEAN
593 #endif
594 #include <windows.h>
595 #else
596 #ifdef HAVE_SYS_TYPES_H
597 #include <sys/types.h>
598 #endif
599 #endif
600 #ifndef NULL
601 #define NULL (void *)0
602 #endif
603 #ifndef LDAP_DEPRECATED
604 #define LDAP_DEPRECATED 1
605 #endif
606 #ifdef NEED_LBER_H
607 #include <lber.h>
608 #endif
609 #ifdef HAVE_LDAP_H
610 #include <ldap.h>
611 #endif
612 #include <ldapssl.h>
613       ]],[[
614         char *cert_label = NULL;
615         LDAP *ldp = ldap_ssl_init("dummy", LDAPS_PORT, cert_label);
616       ]])
617     ],[
618       ac_cv_header_ldapssl_h="yes"
619     ],[
620       ac_cv_header_ldapssl_h="no"
621     ])
622   ])
623   case "$ac_cv_header_ldapssl_h" in
624     yes)
625       AC_DEFINE_UNQUOTED(HAVE_LDAPSSL_H, 1,
626         [Define to 1 if you have the ldapssl.h header file.])
627       ;;
628   esac
629 ])
630
631
632 dnl CURL_CHECK_LIBS_WINLDAP
633 dnl -------------------------------------------------
634 dnl Check for libraries needed for WINLDAP support,
635 dnl and prepended to LIBS any needed libraries.
636 dnl This macro can take an optional parameter with a
637 dnl white space separated list of libraries to check
638 dnl before the WINLDAP default ones.
639
640 AC_DEFUN([CURL_CHECK_LIBS_WINLDAP], [
641   AC_REQUIRE([CURL_CHECK_HEADER_WINBER])dnl
642   #
643   AC_MSG_CHECKING([for WINLDAP libraries])
644   #
645   u_libs=""
646   #
647   ifelse($1,,,[
648     for x_lib in $1; do
649       case "$x_lib" in
650         -l*)
651           l_lib="$x_lib"
652           ;;
653         *)
654           l_lib="-l$x_lib"
655           ;;
656       esac
657       if test -z "$u_libs"; then
658         u_libs="$l_lib"
659       else
660         u_libs="$u_libs $l_lib"
661       fi
662     done
663   ])
664   #
665   curl_cv_save_LIBS="$LIBS"
666   curl_cv_ldap_LIBS="unknown"
667   #
668   for x_nlibs in '' "$u_libs" \
669     '-lwldap32' ; do
670     if test "$curl_cv_ldap_LIBS" = "unknown"; then
671       if test -z "$x_nlibs"; then
672         LIBS="$curl_cv_save_LIBS"
673       else
674         LIBS="$x_nlibs $curl_cv_save_LIBS"
675       fi
676       AC_LINK_IFELSE([
677         AC_LANG_PROGRAM([[
678 #undef inline
679 #ifdef HAVE_WINDOWS_H
680 #ifndef WIN32_LEAN_AND_MEAN
681 #define WIN32_LEAN_AND_MEAN
682 #endif
683 #include <windows.h>
684 #ifdef HAVE_WINLDAP_H
685 #include <winldap.h>
686 #endif
687 #ifdef HAVE_WINBER_H
688 #include <winber.h>
689 #endif
690 #endif
691         ]],[[
692           BERVAL *bvp = NULL;
693           BerElement *bep = ber_init(bvp);
694           LDAP *ldp = ldap_init("dummy", LDAP_PORT);
695           ULONG res = ldap_unbind(ldp);
696           ber_free(bep, 1);
697         ]])
698       ],[
699         curl_cv_ldap_LIBS="$x_nlibs"
700       ])
701     fi
702   done
703   #
704   LIBS="$curl_cv_save_LIBS"
705   #
706   case X-"$curl_cv_ldap_LIBS" in
707     X-unknown)
708       AC_MSG_RESULT([cannot find WINLDAP libraries])
709       ;;
710     X-)
711       AC_MSG_RESULT([no additional lib required])
712       ;;
713     *)
714       if test -z "$curl_cv_save_LIBS"; then
715         LIBS="$curl_cv_ldap_LIBS"
716       else
717         LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
718       fi
719       AC_MSG_RESULT([$curl_cv_ldap_LIBS])
720       ;;
721   esac
722   #
723 ])
724
725
726 dnl CURL_CHECK_LIBS_LDAP
727 dnl -------------------------------------------------
728 dnl Check for libraries needed for LDAP support,
729 dnl and prepended to LIBS any needed libraries.
730 dnl This macro can take an optional parameter with a
731 dnl white space separated list of libraries to check
732 dnl before the default ones.
733
734 AC_DEFUN([CURL_CHECK_LIBS_LDAP], [
735   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
736   #
737   AC_MSG_CHECKING([for LDAP libraries])
738   #
739   u_libs=""
740   #
741   ifelse($1,,,[
742     for x_lib in $1; do
743       case "$x_lib" in
744         -l*)
745           l_lib="$x_lib"
746           ;;
747         *)
748           l_lib="-l$x_lib"
749           ;;
750       esac
751       if test -z "$u_libs"; then
752         u_libs="$l_lib"
753       else
754         u_libs="$u_libs $l_lib"
755       fi
756     done
757   ])
758   #
759   curl_cv_save_LIBS="$LIBS"
760   curl_cv_ldap_LIBS="unknown"
761   #
762   for x_nlibs in '' "$u_libs" \
763     '-lldap' \
764     '-llber -lldap' \
765     '-lldap -llber' \
766     '-lldapssl -lldapx -lldapsdk' \
767     '-lldapsdk -lldapx -lldapssl' ; do
768     if test "$curl_cv_ldap_LIBS" = "unknown"; then
769       if test -z "$x_nlibs"; then
770         LIBS="$curl_cv_save_LIBS"
771       else
772         LIBS="$x_nlibs $curl_cv_save_LIBS"
773       fi
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 #else
783 #ifdef HAVE_SYS_TYPES_H
784 #include <sys/types.h>
785 #endif
786 #endif
787 #ifndef NULL
788 #define NULL (void *)0
789 #endif
790 #ifndef LDAP_DEPRECATED
791 #define LDAP_DEPRECATED 1
792 #endif
793 #ifdef NEED_LBER_H
794 #include <lber.h>
795 #endif
796 #ifdef HAVE_LDAP_H
797 #include <ldap.h>
798 #endif
799         ]],[[
800           BerValue *bvp = NULL;
801           BerElement *bep = ber_init(bvp);
802           LDAP *ldp = ldap_init("dummy", LDAP_PORT);
803           int res = ldap_unbind(ldp);
804           ber_free(bep, 1);
805         ]])
806       ],[
807         curl_cv_ldap_LIBS="$x_nlibs"
808       ])
809     fi
810   done
811   #
812   LIBS="$curl_cv_save_LIBS"
813   #
814   case X-"$curl_cv_ldap_LIBS" in
815     X-unknown)
816       AC_MSG_RESULT([cannot find LDAP libraries])
817       ;;
818     X-)
819       AC_MSG_RESULT([no additional lib required])
820       ;;
821     *)
822       if test -z "$curl_cv_save_LIBS"; then
823         LIBS="$curl_cv_ldap_LIBS"
824       else
825         LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
826       fi
827       AC_MSG_RESULT([$curl_cv_ldap_LIBS])
828       ;;
829   esac
830   #
831 ])
832
833
834 dnl CURL_CHECK_HEADER_MALLOC
835 dnl -------------------------------------------------
836 dnl Check for compilable and valid malloc.h header,
837 dnl and check if it is needed even with stdlib.h
838
839 AC_DEFUN([CURL_CHECK_HEADER_MALLOC], [
840   AC_CACHE_CHECK([for malloc.h], [ac_cv_header_malloc_h], [
841     AC_COMPILE_IFELSE([
842       AC_LANG_PROGRAM([[
843 #include <malloc.h>
844       ]],[[
845         void *p = malloc(10);
846         void *q = calloc(10,10);
847         free(p);
848         free(q);
849       ]])
850     ],[
851       ac_cv_header_malloc_h="yes"
852     ],[
853       ac_cv_header_malloc_h="no"
854     ])
855   ])
856   if test "$ac_cv_header_malloc_h" = "yes"; then
857     AC_DEFINE_UNQUOTED(HAVE_MALLOC_H, 1,
858       [Define to 1 if you have the malloc.h header file.])
859     #
860     AC_COMPILE_IFELSE([
861       AC_LANG_PROGRAM([[
862 #include <stdlib.h>
863       ]],[[
864         void *p = malloc(10);
865         void *q = calloc(10,10);
866         free(p);
867         free(q);
868       ]])
869     ],[
870       curl_cv_need_header_malloc_h="no"
871     ],[
872       curl_cv_need_header_malloc_h="yes"
873     ])
874     #
875     case "$curl_cv_need_header_malloc_h" in
876       yes)
877         AC_DEFINE_UNQUOTED(NEED_MALLOC_H, 1,
878           [Define to 1 if you need the malloc.h header file even with stdlib.h])
879         ;;
880     esac
881   fi
882 ])
883
884
885 dnl CURL_CHECK_TYPE_SOCKLEN_T
886 dnl -------------------------------------------------
887 dnl Check for existing socklen_t type, and provide
888 dnl an equivalent type if socklen_t not available
889
890 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
891   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
892   AC_CHECK_TYPE([socklen_t], ,[
893     dnl socklen_t not available
894     AC_CACHE_CHECK([for socklen_t equivalent],
895       [curl_cv_socklen_t_equiv], [
896       curl_cv_socklen_t_equiv="unknown"
897       for arg1 in 'int' 'SOCKET'; do
898         for arg2 in "struct sockaddr" void; do
899           for t in int size_t unsigned long "unsigned long"; do
900             if test "$curl_cv_socklen_t_equiv" = "unknown"; then
901               AC_COMPILE_IFELSE([
902                 AC_LANG_PROGRAM([[
903 #undef inline
904 #ifdef HAVE_WINDOWS_H
905 #ifndef WIN32_LEAN_AND_MEAN
906 #define WIN32_LEAN_AND_MEAN
907 #endif
908 #include <windows.h>
909 #ifdef HAVE_WINSOCK2_H
910 #include <winsock2.h>
911 #else
912 #ifdef HAVE_WINSOCK_H
913 #include <winsock.h>
914 #endif
915 #endif
916 #define GETPEERNCALLCONV PASCAL
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 #define GETPEERNCALLCONV
925 #endif
926                   extern int GETPEERNCALLCONV getpeername($arg1, $arg2 *, $t *);
927                 ]],[[
928                   $t len=0;
929                   getpeername(0,0,&len);
930                 ]])
931               ],[
932                 curl_cv_socklen_t_equiv="$t"
933               ])
934             fi
935           done
936         done
937       done
938     ])
939     case "$curl_cv_socklen_t_equiv" in
940       unknown)
941         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
942         ;;
943       *)
944         AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
945           [Type to use in place of socklen_t when system does not provide it.])
946         ;;
947     esac
948   ],[
949 #undef inline
950 #ifdef HAVE_WINDOWS_H
951 #ifndef WIN32_LEAN_AND_MEAN
952 #define WIN32_LEAN_AND_MEAN
953 #endif
954 #include <windows.h>
955 #ifdef HAVE_WINSOCK2_H
956 #include <winsock2.h>
957 #ifdef HAVE_WS2TCPIP_H
958 #include <ws2tcpip.h>
959 #endif
960 #endif
961 #else
962 #ifdef HAVE_SYS_TYPES_H
963 #include <sys/types.h>
964 #endif
965 #ifdef HAVE_SYS_SOCKET_H
966 #include <sys/socket.h>
967 #endif
968 #endif
969   ])
970 ])
971
972
973 dnl CURL_CHECK_FUNC_GETNAMEINFO
974 dnl -------------------------------------------------
975 dnl Test if the getnameinfo function is available, 
976 dnl and check the types of five of its arguments.
977 dnl If the function succeeds HAVE_GETNAMEINFO will be
978 dnl defined, defining the types of the arguments in
979 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
980 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
981 dnl and also defining the type qualifier of first 
982 dnl argument in GETNAMEINFO_QUAL_ARG1.
983
984 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
985   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
986   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
987   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
988   #
989   AC_MSG_CHECKING([for getnameinfo])
990   AC_LINK_IFELSE([
991     AC_LANG_FUNC_LINK_TRY([getnameinfo])
992   ],[
993     AC_MSG_RESULT([yes])
994     curl_cv_getnameinfo="yes"
995   ],[
996     AC_MSG_RESULT([no])
997     curl_cv_getnameinfo="no"
998   ])
999   #
1000   if test "$curl_cv_getnameinfo" != "yes"; then
1001     AC_MSG_CHECKING([deeper for getnameinfo])
1002     AC_LINK_IFELSE([
1003       AC_LANG_PROGRAM([[
1004       ]],[[
1005         getnameinfo();
1006       ]])
1007     ],[
1008       AC_MSG_RESULT([yes])
1009       curl_cv_getnameinfo="yes"
1010     ],[
1011       AC_MSG_RESULT([but still no])
1012       curl_cv_getnameinfo="no"
1013     ])
1014   fi
1015   #
1016   if test "$curl_cv_getnameinfo" != "yes"; then
1017     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
1018     AC_LINK_IFELSE([
1019       AC_LANG_PROGRAM([[
1020 #undef inline
1021 #ifdef HAVE_WINDOWS_H
1022 #ifndef WIN32_LEAN_AND_MEAN
1023 #define WIN32_LEAN_AND_MEAN
1024 #endif
1025 #include <windows.h>
1026 #ifdef HAVE_WINSOCK2_H
1027 #include <winsock2.h>
1028 #ifdef HAVE_WS2TCPIP_H
1029 #include <ws2tcpip.h>
1030 #endif
1031 #endif
1032 #else
1033 #ifdef HAVE_SYS_TYPES_H
1034 #include <sys/types.h>
1035 #endif
1036 #ifdef HAVE_SYS_SOCKET_H
1037 #include <sys/socket.h>
1038 #endif
1039 #ifdef HAVE_NETDB_H
1040 #include <netdb.h>
1041 #endif
1042 #endif
1043       ]],[[
1044         getnameinfo(0, 0, 0, 0, 0, 0, 0);
1045       ]])
1046     ],[
1047       AC_MSG_RESULT([yes])
1048       curl_cv_getnameinfo="yes"
1049     ],[
1050       AC_MSG_RESULT([but still no])
1051       curl_cv_getnameinfo="no"
1052     ])
1053   fi
1054   #
1055   if test "$curl_cv_getnameinfo" = "yes"; then
1056     AC_CACHE_CHECK([types of arguments for getnameinfo],
1057       [curl_cv_func_getnameinfo_args], [
1058       curl_cv_func_getnameinfo_args="unknown"
1059       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
1060         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
1061           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
1062             for gni_arg7 in 'int' 'unsigned int'; do
1063               if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
1064                 AC_COMPILE_IFELSE([
1065                   AC_LANG_PROGRAM([[
1066 #undef inline 
1067 #ifdef HAVE_WINDOWS_H
1068 #ifndef WIN32_LEAN_AND_MEAN
1069 #define WIN32_LEAN_AND_MEAN
1070 #endif
1071 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
1072 #undef _WIN32_WINNT
1073 #define _WIN32_WINNT 0x0501
1074 #endif
1075 #include <windows.h>
1076 #ifdef HAVE_WINSOCK2_H
1077 #include <winsock2.h> 
1078 #ifdef HAVE_WS2TCPIP_H
1079 #include <ws2tcpip.h>
1080 #endif
1081 #endif
1082 #define GNICALLCONV WSAAPI
1083 #else
1084 #ifdef HAVE_SYS_TYPES_H
1085 #include <sys/types.h>
1086 #endif
1087 #ifdef HAVE_SYS_SOCKET_H
1088 #include <sys/socket.h>
1089 #endif
1090 #ifdef HAVE_NETDB_H
1091 #include <netdb.h>
1092 #endif
1093 #define GNICALLCONV
1094 #endif
1095                     extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
1096                                            char *, $gni_arg46,
1097                                            char *, $gni_arg46,
1098                                            $gni_arg7);
1099                   ]],[[
1100                     $gni_arg2 salen=0;
1101                     $gni_arg46 hostlen=0;
1102                     $gni_arg46 servlen=0;
1103                     $gni_arg7 flags=0;
1104                     int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
1105                   ]])
1106                 ],[
1107                   curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
1108                 ])
1109               fi
1110             done
1111           done
1112         done
1113       done
1114     ]) # AC_CACHE_CHECK
1115     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
1116       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
1117       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
1118     else
1119       gni_prev_IFS=$IFS; IFS=','
1120       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
1121       IFS=$gni_prev_IFS
1122       shift
1123       #
1124       gni_qual_type_arg1=$[1]
1125       #
1126       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
1127         [Define to the type of arg 2 for getnameinfo.])
1128       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
1129         [Define to the type of args 4 and 6 for getnameinfo.])
1130       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
1131         [Define to the type of arg 7 for getnameinfo.])
1132       #
1133       prev_sh_opts=$-
1134       #
1135       case $prev_sh_opts in
1136         *f*)
1137           ;;
1138         *)
1139           set -f
1140           ;;
1141       esac
1142       #
1143       case "$gni_qual_type_arg1" in
1144         const*)
1145           gni_qual_arg1=const
1146           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
1147         ;;
1148         *)
1149           gni_qual_arg1=
1150           gni_type_arg1=$gni_qual_type_arg1
1151         ;;
1152       esac
1153       #
1154       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
1155         [Define to the type qualifier of arg 1 for getnameinfo.])
1156       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
1157         [Define to the type of arg 1 for getnameinfo.])
1158       #
1159       case $prev_sh_opts in
1160         *f*)
1161           ;;
1162         *)
1163           set +f
1164           ;;
1165       esac
1166       #
1167       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
1168         [Define to 1 if you have the getnameinfo function.])
1169       ac_cv_func_getnameinfo="yes"
1170     fi
1171   fi
1172 ]) # AC_DEFUN
1173
1174
1175 dnl TYPE_SOCKADDR_STORAGE
1176 dnl -------------------------------------------------
1177 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
1178 dnl hosts have it, but AIX 4.3 is one known exception.
1179
1180 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
1181 [
1182    AC_CHECK_TYPE([struct sockaddr_storage],
1183         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
1184                   [if struct sockaddr_storage is defined]), ,
1185    [
1186 #undef inline
1187 #ifdef HAVE_WINDOWS_H
1188 #ifndef WIN32_LEAN_AND_MEAN
1189 #define WIN32_LEAN_AND_MEAN
1190 #endif
1191 #include <windows.h>
1192 #ifdef HAVE_WINSOCK2_H
1193 #include <winsock2.h>
1194 #endif
1195 #else
1196 #ifdef HAVE_SYS_TYPES_H
1197 #include <sys/types.h>
1198 #endif
1199 #ifdef HAVE_SYS_SOCKET_H
1200 #include <sys/socket.h>
1201 #endif
1202 #ifdef HAVE_NETINET_IN_H
1203 #include <netinet/in.h>
1204 #endif
1205 #ifdef HAVE_ARPA_INET_H
1206 #include <arpa/inet.h>
1207 #endif
1208 #endif
1209    ])
1210 ])
1211
1212
1213 dnl CURL_CHECK_NI_WITHSCOPEID
1214 dnl -------------------------------------------------
1215 dnl Check for working NI_WITHSCOPEID in getnameinfo()
1216
1217 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
1218   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
1219   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
1220   AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
1221                    netdb.h netinet/in.h arpa/inet.h)
1222   #
1223   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
1224     [ac_cv_working_ni_withscopeid], [
1225     AC_RUN_IFELSE([
1226       AC_LANG_PROGRAM([[
1227 #ifdef HAVE_STDIO_H
1228 #include <stdio.h>
1229 #endif
1230 #ifdef HAVE_SYS_TYPES_H
1231 #include <sys/types.h>
1232 #endif
1233 #ifdef HAVE_SYS_SOCKET_H
1234 #include <sys/socket.h>
1235 #endif
1236 #ifdef HAVE_NETDB_H
1237 #include <netdb.h>
1238 #endif
1239 #ifdef HAVE_NETINET_IN_H
1240 #include <netinet/in.h>
1241 #endif
1242 #ifdef HAVE_ARPA_INET_H
1243 #include <arpa/inet.h>
1244 #endif
1245       ]],[[
1246 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
1247 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
1248         struct sockaddr_storage sa;
1249 #else
1250         unsigned char sa[256];
1251 #endif
1252         char hostbuf[NI_MAXHOST];
1253         int rc;
1254         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
1255         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
1256         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
1257         int fd = socket(AF_INET6, SOCK_STREAM, 0);
1258         if(fd < 0) {
1259           perror("socket()");
1260           return 1; /* Error creating socket */
1261         }
1262         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
1263         if(rc) {
1264           perror("getsockname()");
1265           return 2; /* Error retrieving socket name */
1266         }
1267         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
1268         if(rc) {
1269           printf("rc = %s\n", gai_strerror(rc));
1270           return 3; /* Error translating socket address */
1271         }
1272         return 0; /* Ok, NI_WITHSCOPEID works */
1273 #else
1274         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
1275 #endif
1276       ]]) # AC_LANG_PROGRAM
1277     ],[
1278       # Exit code == 0. Program worked.
1279       ac_cv_working_ni_withscopeid="yes"
1280     ],[
1281       # Exit code != 0. Program failed.
1282       ac_cv_working_ni_withscopeid="no"
1283     ],[
1284       # Program is not run when cross-compiling. So we assume
1285       # NI_WITHSCOPEID will work if we are able to compile it.
1286       AC_COMPILE_IFELSE([
1287         AC_LANG_PROGRAM([[
1288 #include <sys/types.h>
1289 #include <sys/socket.h>
1290 #include <netdb.h>
1291         ]],[[
1292           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
1293         ]])
1294       ],[
1295         ac_cv_working_ni_withscopeid="yes"
1296       ],[
1297         ac_cv_working_ni_withscopeid="no"
1298       ]) # AC_COMPILE_IFELSE
1299     ]) # AC_RUN_IFELSE
1300   ]) # AC_CACHE_CHECK
1301   case "$ac_cv_working_ni_withscopeid" in
1302     yes)
1303       AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
1304         [Define to 1 if NI_WITHSCOPEID exists and works.])
1305       ;;
1306   esac
1307 ]) # AC_DEFUN
1308
1309
1310 dnl CURL_CHECK_FUNC_RECV
1311 dnl -------------------------------------------------
1312 dnl Test if the socket recv() function is available, 
1313 dnl and check its return type and the types of its 
1314 dnl arguments. If the function succeeds HAVE_RECV 
1315 dnl will be defined, defining the types of the arguments 
1316 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
1317 dnl and RECV_TYPE_ARG4, defining the type of the function
1318 dnl return value in RECV_TYPE_RETV.
1319
1320 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
1321   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1322   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1323   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1324   #
1325   AC_MSG_CHECKING([for recv])
1326   AC_LINK_IFELSE([
1327     AC_LANG_PROGRAM([[
1328 #undef inline 
1329 #ifdef HAVE_WINDOWS_H
1330 #ifndef WIN32_LEAN_AND_MEAN
1331 #define WIN32_LEAN_AND_MEAN
1332 #endif
1333 #include <windows.h>
1334 #ifdef HAVE_WINSOCK2_H
1335 #include <winsock2.h>
1336 #else
1337 #ifdef HAVE_WINSOCK_H
1338 #include <winsock.h>
1339 #endif
1340 #endif
1341 #else
1342 #ifdef HAVE_SYS_TYPES_H
1343 #include <sys/types.h>
1344 #endif
1345 #ifdef HAVE_SYS_SOCKET_H
1346 #include <sys/socket.h>
1347 #endif
1348 #endif
1349     ]],[[
1350       recv(0, 0, 0, 0);
1351     ]])
1352   ],[
1353     AC_MSG_RESULT([yes])
1354     curl_cv_recv="yes"
1355   ],[
1356     AC_MSG_RESULT([no])
1357     curl_cv_recv="no"
1358   ])
1359   #
1360   if test "$curl_cv_recv" = "yes"; then
1361     AC_CACHE_CHECK([types of args and return type for recv],
1362       [curl_cv_func_recv_args], [
1363       curl_cv_func_recv_args="unknown"
1364       for recv_retv in 'int' 'ssize_t'; do
1365         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1366           for recv_arg2 in 'char *' 'void *'; do
1367             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1368               for recv_arg4 in 'int' 'unsigned int'; do
1369                 if test "$curl_cv_func_recv_args" = "unknown"; then
1370                   AC_COMPILE_IFELSE([
1371                     AC_LANG_PROGRAM([[
1372 #undef inline 
1373 #ifdef HAVE_WINDOWS_H
1374 #ifndef WIN32_LEAN_AND_MEAN
1375 #define WIN32_LEAN_AND_MEAN
1376 #endif
1377 #include <windows.h>
1378 #ifdef HAVE_WINSOCK2_H
1379 #include <winsock2.h>
1380 #else
1381 #ifdef HAVE_WINSOCK_H
1382 #include <winsock.h>
1383 #endif
1384 #endif
1385 #define RECVCALLCONV PASCAL
1386 #else
1387 #ifdef HAVE_SYS_TYPES_H
1388 #include <sys/types.h>
1389 #endif
1390 #ifdef HAVE_SYS_SOCKET_H
1391 #include <sys/socket.h>
1392 #endif
1393 #define RECVCALLCONV
1394 #endif
1395                       extern $recv_retv RECVCALLCONV
1396                       recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
1397                     ]],[[
1398                       $recv_arg1 s=0;
1399                       $recv_arg2 buf=0;
1400                       $recv_arg3 len=0;
1401                       $recv_arg4 flags=0;
1402                       $recv_retv res = recv(s, buf, len, flags);
1403                     ]])
1404                   ],[
1405                     curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
1406                   ])
1407                 fi
1408               done
1409             done
1410           done
1411         done
1412       done
1413     ]) # AC_CACHE_CHECK
1414     if test "$curl_cv_func_recv_args" = "unknown"; then
1415       AC_MSG_ERROR([Cannot find proper types to use for recv args])
1416     else
1417       recv_prev_IFS=$IFS; IFS=','
1418       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
1419       IFS=$recv_prev_IFS
1420       shift
1421       #
1422       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
1423         [Define to the type of arg 1 for recv.])
1424       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
1425         [Define to the type of arg 2 for recv.])
1426       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
1427         [Define to the type of arg 3 for recv.])
1428       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
1429         [Define to the type of arg 4 for recv.])
1430       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
1431         [Define to the function return type for recv.])
1432       #
1433       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
1434         [Define to 1 if you have the recv function.])
1435       ac_cv_func_recv="yes"
1436     fi
1437   else
1438     AC_MSG_ERROR([Unable to link function recv])
1439   fi
1440 ]) # AC_DEFUN
1441
1442
1443 dnl CURL_CHECK_FUNC_SEND
1444 dnl -------------------------------------------------
1445 dnl Test if the socket send() function is available, 
1446 dnl and check its return type and the types of its 
1447 dnl arguments. If the function succeeds HAVE_SEND 
1448 dnl will be defined, defining the types of the arguments 
1449 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
1450 dnl and SEND_TYPE_ARG4, defining the type of the function
1451 dnl return value in SEND_TYPE_RETV, and also defining the 
1452 dnl type qualifier of second argument in SEND_QUAL_ARG2.
1453
1454 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
1455   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1456   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1457   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1458   #
1459   AC_MSG_CHECKING([for send])
1460   AC_LINK_IFELSE([
1461     AC_LANG_PROGRAM([[
1462 #undef inline 
1463 #ifdef HAVE_WINDOWS_H
1464 #ifndef WIN32_LEAN_AND_MEAN
1465 #define WIN32_LEAN_AND_MEAN
1466 #endif
1467 #include <windows.h>
1468 #ifdef HAVE_WINSOCK2_H
1469 #include <winsock2.h>
1470 #else
1471 #ifdef HAVE_WINSOCK_H
1472 #include <winsock.h>
1473 #endif
1474 #endif
1475 #else
1476 #ifdef HAVE_SYS_TYPES_H
1477 #include <sys/types.h>
1478 #endif
1479 #ifdef HAVE_SYS_SOCKET_H
1480 #include <sys/socket.h>
1481 #endif
1482 #endif
1483     ]],[[
1484       send(0, 0, 0, 0);
1485     ]])
1486   ],[
1487     AC_MSG_RESULT([yes])
1488     curl_cv_send="yes"
1489   ],[
1490     AC_MSG_RESULT([no])
1491     curl_cv_send="no"
1492   ])
1493   #
1494   if test "$curl_cv_send" = "yes"; then
1495     AC_CACHE_CHECK([types of args and return type for send],
1496       [curl_cv_func_send_args], [
1497       curl_cv_func_send_args="unknown"
1498       for send_retv in 'int' 'ssize_t'; do
1499         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1500           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
1501             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1502               for send_arg4 in 'int' 'unsigned int'; do
1503                 if test "$curl_cv_func_send_args" = "unknown"; then
1504                   AC_COMPILE_IFELSE([
1505                     AC_LANG_PROGRAM([[
1506 #undef inline 
1507 #ifdef HAVE_WINDOWS_H
1508 #ifndef WIN32_LEAN_AND_MEAN
1509 #define WIN32_LEAN_AND_MEAN
1510 #endif
1511 #include <windows.h>
1512 #ifdef HAVE_WINSOCK2_H
1513 #include <winsock2.h>
1514 #else
1515 #ifdef HAVE_WINSOCK_H
1516 #include <winsock.h>
1517 #endif
1518 #endif
1519 #define SENDCALLCONV PASCAL
1520 #else
1521 #ifdef HAVE_SYS_TYPES_H
1522 #include <sys/types.h>
1523 #endif
1524 #ifdef HAVE_SYS_SOCKET_H
1525 #include <sys/socket.h>
1526 #endif
1527 #define SENDCALLCONV
1528 #endif
1529                       extern $send_retv SENDCALLCONV
1530                       send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
1531                     ]],[[
1532                       $send_arg1 s=0;
1533                       $send_arg3 len=0;
1534                       $send_arg4 flags=0;
1535                       $send_retv res = send(s, 0, len, flags);
1536                     ]])
1537                   ],[
1538                     curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
1539                   ])
1540                 fi
1541               done
1542             done
1543           done
1544         done
1545       done
1546     ]) # AC_CACHE_CHECK
1547     if test "$curl_cv_func_send_args" = "unknown"; then
1548       AC_MSG_ERROR([Cannot find proper types to use for send args])
1549     else
1550       send_prev_IFS=$IFS; IFS=','
1551       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
1552       IFS=$send_prev_IFS
1553       shift
1554       #
1555       send_qual_type_arg2=$[2]
1556       #
1557       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
1558         [Define to the type of arg 1 for send.])
1559       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
1560         [Define to the type of arg 3 for send.])
1561       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
1562         [Define to the type of arg 4 for send.])
1563       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
1564         [Define to the function return type for send.])
1565       #
1566       prev_sh_opts=$-
1567       #
1568       case $prev_sh_opts in
1569         *f*)
1570           ;;
1571         *)
1572           set -f
1573           ;;
1574       esac
1575       #
1576       case "$send_qual_type_arg2" in
1577         const*)
1578           send_qual_arg2=const
1579           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
1580         ;;
1581         *)
1582           send_qual_arg2=
1583           send_type_arg2=$send_qual_type_arg2
1584         ;;
1585       esac
1586       #
1587       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
1588         [Define to the type qualifier of arg 2 for send.])
1589       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
1590         [Define to the type of arg 2 for send.])
1591       #
1592       case $prev_sh_opts in
1593         *f*)
1594           ;;
1595         *)
1596           set +f
1597           ;;
1598       esac
1599       #
1600       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
1601         [Define to 1 if you have the send function.])
1602       ac_cv_func_send="yes"
1603     fi
1604   else
1605     AC_MSG_ERROR([Unable to link function send])
1606   fi
1607 ]) # AC_DEFUN
1608
1609
1610 dnl CURL_CHECK_FUNC_RECVFROM
1611 dnl -------------------------------------------------
1612 dnl Test if the socket recvfrom() function is available,
1613 dnl and check its return type and the types of its
1614 dnl arguments. If the function succeeds HAVE_RECVFROM
1615 dnl will be defined, defining the types of the arguments
1616 dnl in RECVFROM_TYPE_ARG1, RECVFROM_TYPE_ARG2, and so on
1617 dnl to RECVFROM_TYPE_ARG6, defining also the type of the
1618 dnl function return value in RECVFROM_TYPE_RETV.
1619 dnl Notice that the types returned for pointer arguments
1620 dnl will actually be the type pointed by the pointer.
1621
1622 AC_DEFUN([CURL_CHECK_FUNC_RECVFROM], [
1623   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1624   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1625   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1626   #
1627   AC_MSG_CHECKING([for recvfrom])
1628   AC_LINK_IFELSE([
1629     AC_LANG_PROGRAM([[
1630 #undef inline 
1631 #ifdef HAVE_WINDOWS_H
1632 #ifndef WIN32_LEAN_AND_MEAN
1633 #define WIN32_LEAN_AND_MEAN
1634 #endif
1635 #include <windows.h>
1636 #ifdef HAVE_WINSOCK2_H
1637 #include <winsock2.h>
1638 #else
1639 #ifdef HAVE_WINSOCK_H
1640 #include <winsock.h>
1641 #endif
1642 #endif
1643 #else
1644 #ifdef HAVE_SYS_TYPES_H
1645 #include <sys/types.h>
1646 #endif
1647 #ifdef HAVE_SYS_SOCKET_H
1648 #include <sys/socket.h>
1649 #endif
1650 #endif
1651     ]],[[
1652       recvfrom(0, 0, 0, 0, 0, 0);
1653     ]])
1654   ],[
1655     AC_MSG_RESULT([yes])
1656     curl_cv_recvfrom="yes"
1657   ],[
1658     AC_MSG_RESULT([no])
1659     curl_cv_recvfrom="no"
1660   ])
1661   #
1662   if test "$curl_cv_recvfrom" = "yes"; then
1663     AC_CACHE_CHECK([types of args and return type for recvfrom],
1664       [curl_cv_func_recvfrom_args], [
1665       curl_cv_func_recvfrom_args="unknown"
1666       for recvfrom_retv in 'int' 'ssize_t'; do
1667         for recvfrom_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1668           for recvfrom_arg2 in 'char *' 'void *'; do
1669             for recvfrom_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1670               for recvfrom_arg4 in 'int' 'unsigned int'; do
1671                 for recvfrom_arg5 in 'struct sockaddr *' 'void *'; do
1672                   for recvfrom_arg6 in 'socklen_t *' 'int *' 'unsigned int *' 'size_t *' 'void *'; do
1673                     if test "$curl_cv_func_recvfrom_args" = "unknown"; then
1674                       AC_COMPILE_IFELSE([
1675                         AC_LANG_PROGRAM([[
1676 #undef inline 
1677 #ifdef HAVE_WINDOWS_H
1678 #ifndef WIN32_LEAN_AND_MEAN
1679 #define WIN32_LEAN_AND_MEAN
1680 #endif
1681 #include <windows.h>
1682 #ifdef HAVE_WINSOCK2_H
1683 #include <winsock2.h>
1684 #else
1685 #ifdef HAVE_WINSOCK_H
1686 #include <winsock.h>
1687 #endif
1688 #endif
1689 #define RECVFROMCALLCONV PASCAL
1690 #else
1691 #ifdef HAVE_SYS_TYPES_H
1692 #include <sys/types.h>
1693 #endif
1694 #ifdef HAVE_SYS_SOCKET_H
1695 #include <sys/socket.h>
1696 #endif
1697 #define RECVFROMCALLCONV
1698 #endif
1699                           extern $recvfrom_retv RECVFROMCALLCONV
1700                           recvfrom($recvfrom_arg1, $recvfrom_arg2,
1701                                    $recvfrom_arg3, $recvfrom_arg4,
1702                                    $recvfrom_arg5, $recvfrom_arg6);
1703                         ]],[[
1704                           $recvfrom_arg1 s=0;
1705                           $recvfrom_arg2 buf=0;
1706                           $recvfrom_arg3 len=0;
1707                           $recvfrom_arg4 flags=0;
1708                           $recvfrom_arg5 addr=0;
1709                           $recvfrom_arg6 addrlen=0;
1710                           $recvfrom_retv res=0;
1711                           res = recvfrom(s, buf, len, flags, addr, addrlen);
1712                         ]])
1713                       ],[
1714                         curl_cv_func_recvfrom_args="$recvfrom_arg1,$recvfrom_arg2,$recvfrom_arg3,$recvfrom_arg4,$recvfrom_arg5,$recvfrom_arg6,$recvfrom_retv"
1715                       ])
1716                     fi
1717                   done
1718                 done
1719               done
1720             done
1721           done
1722         done
1723       done
1724     ]) # AC_CACHE_CHECK
1725     if test "$curl_cv_func_recvfrom_args" = "unknown"; then
1726       AC_MSG_ERROR([Cannot find proper types to use for recvfrom args])
1727     else
1728       recvfrom_prev_IFS=$IFS; IFS=','
1729       set dummy `echo "$curl_cv_func_recvfrom_args" | sed 's/\*/\*/g'`
1730       IFS=$recvfrom_prev_IFS
1731       shift
1732       #
1733       recvfrom_ptrt_arg2=$[2]
1734       recvfrom_ptrt_arg5=$[5]
1735       recvfrom_ptrt_arg6=$[6]
1736       #
1737       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG1, $[1],
1738         [Define to the type of arg 1 for recvfrom.])
1739       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG3, $[3],
1740         [Define to the type of arg 3 for recvfrom.])
1741       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG4, $[4],
1742         [Define to the type of arg 4 for recvfrom.])
1743       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_RETV, $[7],
1744         [Define to the function return type for recvfrom.])
1745       #
1746       prev_sh_opts=$-
1747       #
1748       case $prev_sh_opts in
1749         *f*)
1750           ;;
1751         *)
1752           set -f
1753           ;;
1754       esac
1755       #
1756       recvfrom_type_arg2=`echo $recvfrom_ptrt_arg2 | sed 's/ \*//'`
1757       recvfrom_type_arg5=`echo $recvfrom_ptrt_arg5 | sed 's/ \*//'`
1758       recvfrom_type_arg6=`echo $recvfrom_ptrt_arg6 | sed 's/ \*//'`
1759       #
1760       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG2, $recvfrom_type_arg2,
1761         [Define to the type pointed by arg 2 for recvfrom.])
1762       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG5, $recvfrom_type_arg5,
1763         [Define to the type pointed by arg 5 for recvfrom.])
1764       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG6, $recvfrom_type_arg6,
1765         [Define to the type pointed by arg 6 for recvfrom.])
1766       #
1767       if test "$recvfrom_type_arg2" = "void"; then
1768         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG2_IS_VOID, 1,
1769           [Define to 1 if the type pointed by arg 2 for recvfrom is void.])
1770       fi
1771       if test "$recvfrom_type_arg5" = "void"; then
1772         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG5_IS_VOID, 1,
1773           [Define to 1 if the type pointed by arg 5 for recvfrom is void.])
1774       fi
1775       if test "$recvfrom_type_arg6" = "void"; then
1776         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG6_IS_VOID, 1,
1777           [Define to 1 if the type pointed by arg 6 for recvfrom is void.])
1778       fi
1779       #
1780       case $prev_sh_opts in
1781         *f*)
1782           ;;
1783         *)
1784           set +f
1785           ;;
1786       esac
1787       #
1788       AC_DEFINE_UNQUOTED(HAVE_RECVFROM, 1,
1789         [Define to 1 if you have the recvfrom function.])
1790       ac_cv_func_recvfrom="yes"
1791     fi
1792   else
1793     AC_MSG_ERROR([Unable to link function recvfrom])
1794   fi
1795 ]) # AC_DEFUN
1796
1797
1798 dnl CURL_CHECK_MSG_NOSIGNAL
1799 dnl -------------------------------------------------
1800 dnl Check for MSG_NOSIGNAL
1801
1802 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
1803   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1804   AC_CACHE_CHECK([for MSG_NOSIGNAL], [ac_cv_msg_nosignal], [
1805     AC_COMPILE_IFELSE([
1806       AC_LANG_PROGRAM([[
1807 #undef inline 
1808 #ifdef HAVE_WINDOWS_H
1809 #ifndef WIN32_LEAN_AND_MEAN
1810 #define WIN32_LEAN_AND_MEAN
1811 #endif
1812 #include <windows.h>
1813 #ifdef HAVE_WINSOCK2_H
1814 #include <winsock2.h>
1815 #else
1816 #ifdef HAVE_WINSOCK_H
1817 #include <winsock.h>
1818 #endif
1819 #endif
1820 #else
1821 #ifdef HAVE_SYS_TYPES_H
1822 #include <sys/types.h>
1823 #endif
1824 #ifdef HAVE_SYS_SOCKET_H
1825 #include <sys/socket.h>
1826 #endif
1827 #endif
1828       ]],[[
1829         int flag=MSG_NOSIGNAL;
1830       ]])
1831     ],[
1832       ac_cv_msg_nosignal="yes"
1833     ],[
1834       ac_cv_msg_nosignal="no"
1835     ])
1836   ])
1837   case "$ac_cv_msg_nosignal" in
1838     yes)
1839       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
1840         [Define to 1 if you have the MSG_NOSIGNAL flag.])
1841       ;;
1842   esac
1843 ]) # AC_DEFUN
1844
1845
1846 dnl CURL_CHECK_STRUCT_TIMEVAL
1847 dnl -------------------------------------------------
1848 dnl Check for timeval struct
1849
1850 AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
1851   AC_REQUIRE([AC_HEADER_TIME])dnl
1852   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1853   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1854   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1855   AC_CACHE_CHECK([for struct timeval], [ac_cv_struct_timeval], [
1856     AC_COMPILE_IFELSE([
1857       AC_LANG_PROGRAM([[
1858 #undef inline 
1859 #ifdef HAVE_WINDOWS_H
1860 #ifndef WIN32_LEAN_AND_MEAN
1861 #define WIN32_LEAN_AND_MEAN
1862 #endif
1863 #include <windows.h>
1864 #ifdef HAVE_WINSOCK2_H
1865 #include <winsock2.h>
1866 #else
1867 #ifdef HAVE_WINSOCK_H
1868 #include <winsock.h>
1869 #endif
1870 #endif
1871 #endif
1872 #ifdef HAVE_SYS_TYPES_H
1873 #include <sys/types.h>
1874 #endif
1875 #ifdef HAVE_SYS_TIME_H
1876 #include <sys/time.h>
1877 #ifdef TIME_WITH_SYS_TIME
1878 #include <time.h>
1879 #endif
1880 #else
1881 #ifdef HAVE_TIME_H
1882 #include <time.h>
1883 #endif
1884 #endif
1885       ]],[[
1886         struct timeval ts;
1887         ts.tv_sec  = 0;
1888         ts.tv_usec = 0;
1889       ]])
1890     ],[
1891       ac_cv_struct_timeval="yes"
1892     ],[
1893       ac_cv_struct_timeval="no"
1894     ])
1895   ])
1896   case "$ac_cv_struct_timeval" in
1897     yes)
1898       AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMEVAL, 1,
1899         [Define to 1 if you have the timeval struct.])
1900       ;;
1901   esac
1902 ]) # AC_DEFUN
1903
1904
1905 dnl TYPE_SIG_ATOMIC_T
1906 dnl -------------------------------------------------
1907 dnl Check if the sig_atomic_t type is available, and
1908 dnl verify if it is already defined as volatile.
1909
1910 AC_DEFUN([TYPE_SIG_ATOMIC_T], [
1911   AC_CHECK_HEADERS(signal.h)
1912   AC_CHECK_TYPE([sig_atomic_t],[
1913     AC_DEFINE(HAVE_SIG_ATOMIC_T, 1,
1914       [Define to 1 if sig_atomic_t is an available typedef.])
1915   ], ,[
1916 #ifdef HAVE_SIGNAL_H
1917 #include <signal.h>
1918 #endif
1919   ])
1920   case "$ac_cv_type_sig_atomic_t" in
1921     yes)
1922       #
1923       AC_MSG_CHECKING([if sig_atomic_t is already defined as volatile])
1924       AC_LINK_IFELSE([
1925         AC_LANG_PROGRAM([[
1926 #ifdef HAVE_SIGNAL_H
1927 #include <signal.h>
1928 #endif
1929         ]],[[
1930           static volatile sig_atomic_t dummy = 0;
1931         ]])
1932       ],[
1933         AC_MSG_RESULT([no])
1934         ac_cv_sig_atomic_t_volatile="no"
1935       ],[
1936         AC_MSG_RESULT([yes])
1937         ac_cv_sig_atomic_t_volatile="yes"
1938       ])
1939       #
1940       if test "$ac_cv_sig_atomic_t_volatile" = "yes"; then
1941         AC_DEFINE(HAVE_SIG_ATOMIC_T_VOLATILE, 1,
1942           [Define to 1 if sig_atomic_t is already defined as volatile.])
1943       fi
1944       ;;
1945   esac
1946 ]) # AC_DEFUN
1947
1948
1949 dnl CURL_CHECK_NONBLOCKING_SOCKET
1950 dnl -------------------------------------------------
1951 dnl Check for how to set a socket to non-blocking state. There seems to exist
1952 dnl four known different ways, with the one used almost everywhere being POSIX
1953 dnl and XPG3, while the other different ways for different systems (old BSD,
1954 dnl Windows and Amiga).
1955 dnl
1956 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
1957 dnl O_NONBLOCK define is found but does not work. This condition is attempted
1958 dnl to get caught in this script by using an excessive number of #ifdefs...
1959
1960 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET], [
1961   AC_MSG_CHECKING([non-blocking sockets style])
1962   nonblock="unknown"
1963   #
1964   AC_COMPILE_IFELSE([
1965     AC_LANG_PROGRAM([[
1966 /* headers for O_NONBLOCK test */
1967 #include <sys/types.h>
1968 #include <unistd.h>
1969 #include <fcntl.h>
1970 /* */
1971 #if defined(sun) || defined(__sun__) || \
1972     defined(__SUNPRO_C) || defined(__SUNPRO_CC)
1973 # if defined(__SVR4) || defined(__srv4__)
1974 #  define PLATFORM_SOLARIS
1975 # else
1976 #  define PLATFORM_SUNOS4
1977 # endif
1978 #endif
1979 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
1980 # define PLATFORM_AIX_V3
1981 #endif
1982 /* */
1983 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
1984 #error "O_NONBLOCK does not work on this platform"
1985 #endif
1986     ]],[[
1987       /* O_NONBLOCK source test */
1988       int socket;
1989       int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
1990     ]])
1991   ],[
1992     dnl the O_NONBLOCK test was fine
1993     nonblock="O_NONBLOCK"
1994     AC_DEFINE(HAVE_O_NONBLOCK, 1,
1995       [use O_NONBLOCK for non-blocking sockets])
1996   ])
1997   #
1998   if test "$nonblock" = "unknown"; then
1999     AC_COMPILE_IFELSE([
2000       AC_LANG_PROGRAM([[
2001 /* headers for FIONBIO test */
2002 #include <unistd.h>
2003 #include <stropts.h>
2004       ]],[[
2005         /* FIONBIO source test (old-style unix) */
2006         int socket;
2007         int flags = ioctl(socket, FIONBIO, &flags);
2008       ]])
2009     ],[
2010       dnl FIONBIO test was good
2011       nonblock="FIONBIO"
2012       AC_DEFINE(HAVE_FIONBIO, 1,
2013         [use FIONBIO for non-blocking sockets])
2014     ])
2015   fi
2016   #
2017   if test "$nonblock" = "unknown"; then
2018     AC_COMPILE_IFELSE([
2019       AC_LANG_PROGRAM([[
2020 /* headers for ioctlsocket test (Windows) */
2021 #undef inline
2022 #ifdef HAVE_WINDOWS_H
2023 #ifndef WIN32_LEAN_AND_MEAN
2024 #define WIN32_LEAN_AND_MEAN
2025 #endif
2026 #include <windows.h>
2027 #ifdef HAVE_WINSOCK2_H
2028 #include <winsock2.h>
2029 #else
2030 #ifdef HAVE_WINSOCK_H
2031 #include <winsock.h>
2032 #endif
2033 #endif
2034 #endif
2035       ]],[[
2036         /* ioctlsocket source code (Windows) */
2037         SOCKET sd;
2038         unsigned long flags = 0;
2039         sd = socket(0, 0, 0);
2040         ioctlsocket(sd, FIONBIO, &flags);
2041       ]])
2042     ],[
2043       dnl ioctlsocket test was good
2044       nonblock="ioctlsocket"
2045       AC_DEFINE(HAVE_IOCTLSOCKET, 1,
2046         [use ioctlsocket() for non-blocking sockets])
2047     ])
2048   fi
2049   #
2050   if test "$nonblock" = "unknown"; then
2051     AC_LINK_IFELSE([
2052       AC_LANG_PROGRAM([[
2053 /* headers for IoctlSocket test (Amiga?) */
2054 #include <sys/ioctl.h>
2055       ]],[[
2056         /* IoctlSocket source code (Amiga?) */
2057         int socket;
2058         int flags = IoctlSocket(socket, FIONBIO, (long)1);
2059       ]])
2060     ],[
2061       dnl Ioctlsocket test was good
2062       nonblock="IoctlSocket"
2063       AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1,
2064         [use Ioctlsocket() for non-blocking sockets])
2065     ])
2066   fi
2067   #
2068   if test "$nonblock" = "unknown"; then
2069     AC_COMPILE_IFELSE([
2070       AC_LANG_PROGRAM([[
2071 /* headers for SO_NONBLOCK test (BeOS) */
2072 #include <socket.h>
2073       ]],[[
2074         /* SO_NONBLOCK source code (BeOS) */
2075         long b = 1;
2076         int socket;
2077         int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
2078       ]])
2079     ],[
2080       dnl the SO_NONBLOCK test was good
2081       nonblock="SO_NONBLOCK"
2082       AC_DEFINE(HAVE_SO_NONBLOCK, 1,
2083         [use SO_NONBLOCK for non-blocking sockets])
2084     ])
2085   fi
2086   #
2087   AC_MSG_RESULT($nonblock)
2088   #
2089   if test "$nonblock" = "unknown"; then
2090     AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1,
2091       [disabled non-blocking sockets])
2092     AC_MSG_WARN([non-block sockets disabled])
2093   fi
2094 ])
2095
2096
2097 dnl TYPE_IN_ADDR_T
2098 dnl -------------------------------------------------
2099 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
2100 dnl and a few other things.
2101
2102 AC_DEFUN([TYPE_IN_ADDR_T], [
2103   AC_CHECK_TYPE([in_addr_t], ,[
2104     dnl in_addr_t not available
2105     AC_CACHE_CHECK([for in_addr_t equivalent],
2106       [curl_cv_in_addr_t_equiv], [
2107       curl_cv_in_addr_t_equiv="unknown"
2108       for t in "unsigned long" int size_t unsigned long; do
2109         if test "$curl_cv_in_addr_t_equiv" = "unknown"; then
2110           AC_LINK_IFELSE([
2111             AC_LANG_PROGRAM([[
2112 #undef inline
2113 #ifdef HAVE_WINDOWS_H
2114 #ifndef WIN32_LEAN_AND_MEAN
2115 #define WIN32_LEAN_AND_MEAN
2116 #endif
2117 #include <windows.h>
2118 #ifdef HAVE_WINSOCK2_H
2119 #include <winsock2.h>
2120 #else
2121 #ifdef HAVE_WINSOCK_H
2122 #include <winsock.h>
2123 #endif
2124 #endif
2125 #else
2126 #ifdef HAVE_SYS_TYPES_H
2127 #include <sys/types.h>
2128 #endif
2129 #ifdef HAVE_SYS_SOCKET_H
2130 #include <sys/socket.h>
2131 #endif
2132 #ifdef HAVE_NETINET_IN_H
2133 #include <netinet/in.h>
2134 #endif
2135 #ifdef HAVE_ARPA_INET_H
2136 #include <arpa/inet.h>
2137 #endif
2138 #endif
2139             ]],[[
2140               $t data = inet_addr ("1.2.3.4");
2141             ]])
2142           ],[
2143             curl_cv_in_addr_t_equiv="$t"
2144           ])
2145         fi
2146       done
2147     ])
2148     case "$curl_cv_in_addr_t_equiv" in
2149       unknown)
2150         AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
2151         ;;
2152       *)
2153         AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
2154           [Type to use in place of in_addr_t when system does not provide it.])
2155         ;;
2156     esac
2157   ],[
2158 #undef inline
2159 #ifdef HAVE_WINDOWS_H
2160 #ifndef WIN32_LEAN_AND_MEAN
2161 #define WIN32_LEAN_AND_MEAN
2162 #endif
2163 #include <windows.h>
2164 #ifdef HAVE_WINSOCK2_H
2165 #include <winsock2.h>
2166 #else
2167 #ifdef HAVE_WINSOCK_H
2168 #include <winsock.h>
2169 #endif
2170 #endif
2171 #else
2172 #ifdef HAVE_SYS_TYPES_H
2173 #include <sys/types.h>
2174 #endif
2175 #ifdef HAVE_SYS_SOCKET_H
2176 #include <sys/socket.h>
2177 #endif
2178 #ifdef HAVE_NETINET_IN_H
2179 #include <netinet/in.h>
2180 #endif
2181 #ifdef HAVE_ARPA_INET_H
2182 #include <arpa/inet.h>
2183 #endif
2184 #endif
2185   ]) dnl AC_CHECK_TYPE
2186 ]) dnl AC_DEFUN
2187
2188
2189 dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
2190 dnl -------------------------------------------------
2191 dnl Check if monotonic clock_gettime is available.
2192
2193 AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
2194   AC_REQUIRE([AC_HEADER_TIME])dnl
2195   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
2196   AC_MSG_CHECKING([for monotonic clock_gettime])
2197   AC_COMPILE_IFELSE([
2198     AC_LANG_PROGRAM([[
2199 #ifdef HAVE_SYS_TYPES_H
2200 #include <sys/types.h>
2201 #endif
2202 #ifdef HAVE_SYS_TIME_H
2203 #include <sys/time.h>
2204 #ifdef TIME_WITH_SYS_TIME
2205 #include <time.h>
2206 #endif
2207 #else
2208 #ifdef HAVE_TIME_H
2209 #include <time.h>
2210 #endif
2211 #endif
2212     ]],[[
2213       struct timespec ts;
2214       (void)clock_gettime(CLOCK_MONOTONIC, &ts);
2215     ]])
2216   ],[
2217     AC_MSG_RESULT([yes])
2218     ac_cv_func_clock_gettime="yes"
2219   ],[
2220     AC_MSG_RESULT([no])
2221     ac_cv_func_clock_gettime="no"
2222   ])
2223   dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally postponed
2224   dnl until library linking and run-time checks for clock_gettime succeed.
2225 ]) dnl AC_DEFUN
2226
2227
2228 dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
2229 dnl -------------------------------------------------
2230 dnl If monotonic clock_gettime is available then,
2231 dnl check and prepended to LIBS any needed libraries.
2232
2233 AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
2234   AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
2235   #
2236   if test "$ac_cv_func_clock_gettime" = "yes"; then
2237     #
2238     AC_MSG_CHECKING([for clock_gettime in libraries])
2239     #
2240     curl_cv_save_LIBS="$LIBS"
2241     curl_cv_gclk_LIBS="unknown"
2242     #
2243     for x_xlibs in '' '-lrt' '-lposix4' ; do
2244       if test "$curl_cv_gclk_LIBS" = "unknown"; then
2245         if test -z "$x_xlibs"; then
2246           LIBS="$curl_cv_save_LIBS"
2247         else
2248           LIBS="$x_xlibs $curl_cv_save_LIBS"
2249         fi
2250         AC_LINK_IFELSE([
2251           AC_LANG_PROGRAM([[
2252 #ifdef HAVE_SYS_TYPES_H
2253 #include <sys/types.h>
2254 #endif
2255 #ifdef HAVE_SYS_TIME_H
2256 #include <sys/time.h>
2257 #ifdef TIME_WITH_SYS_TIME
2258 #include <time.h>
2259 #endif
2260 #else
2261 #ifdef HAVE_TIME_H
2262 #include <time.h>
2263 #endif
2264 #endif
2265           ]],[[
2266             struct timespec ts;
2267             (void)clock_gettime(CLOCK_MONOTONIC, &ts);
2268           ]])
2269         ],[
2270           curl_cv_gclk_LIBS="$x_xlibs"
2271         ])
2272       fi
2273     done
2274     #
2275     LIBS="$curl_cv_save_LIBS"
2276     #
2277     case X-"$curl_cv_gclk_LIBS" in
2278       X-unknown)
2279         AC_MSG_RESULT([cannot find clock_gettime])
2280         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
2281         ac_cv_func_clock_gettime="no"
2282         ;;
2283       X-)
2284         AC_MSG_RESULT([no additional lib required])
2285         ac_cv_func_clock_gettime="yes"
2286         ;;
2287       *)
2288         if test -z "$curl_cv_save_LIBS"; then
2289           LIBS="$curl_cv_gclk_LIBS"
2290         else
2291           LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
2292         fi
2293         AC_MSG_RESULT([$curl_cv_gclk_LIBS])
2294         ac_cv_func_clock_gettime="yes"
2295         ;;
2296     esac
2297     #
2298     dnl only do runtime verification when not cross-compiling
2299     if test "x$cross_compiling" != "xyes" &&
2300       test "$ac_cv_func_clock_gettime" = "yes"; then
2301       AC_MSG_CHECKING([if monotonic clock_gettime works])
2302       AC_RUN_IFELSE([
2303         AC_LANG_PROGRAM([[
2304 #ifdef HAVE_SYS_TYPES_H
2305 #include <sys/types.h>
2306 #endif
2307 #ifdef HAVE_SYS_TIME_H
2308 #include <sys/time.h>
2309 #ifdef TIME_WITH_SYS_TIME
2310 #include <time.h>
2311 #endif
2312 #else
2313 #ifdef HAVE_TIME_H
2314 #include <time.h>
2315 #endif
2316 #endif
2317         ]],[[
2318           struct timespec ts;
2319           if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
2320             exit(0);
2321           else
2322             exit(1);
2323         ]])
2324       ],[
2325         AC_MSG_RESULT([yes])
2326       ],[
2327         AC_MSG_RESULT([no])
2328         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
2329         ac_cv_func_clock_gettime="no"
2330         LIBS="$curl_cv_save_LIBS"
2331       ])
2332     fi
2333     #
2334     case "$ac_cv_func_clock_gettime" in
2335       yes)
2336         AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
2337           [Define to 1 if you have the clock_gettime function and monotonic timer.])
2338         ;;
2339     esac
2340     #
2341   fi
2342   #
2343 ]) dnl AC_DEFUN
2344
2345
2346 dnl CURL_CHECK_FUNC_SELECT
2347 dnl -------------------------------------------------
2348 dnl Test if the socket select() function is available,
2349 dnl and check its return type and the types of its
2350 dnl arguments. If the function succeeds HAVE_SELECT
2351 dnl will be defined, defining the types of the
2352 dnl arguments in SELECT_TYPE_ARG1, SELECT_TYPE_ARG234
2353 dnl and SELECT_TYPE_ARG5, defining the type of the
2354 dnl function return value in SELECT_TYPE_RETV, and
2355 dnl also defining the type qualifier of fifth argument
2356 dnl in SELECT_QUAL_ARG5.
2357
2358 AC_DEFUN([CURL_CHECK_FUNC_SELECT], [
2359   AC_REQUIRE([CURL_CHECK_STRUCT_TIMEVAL])dnl
2360   AC_CHECK_HEADERS(sys/select.h sys/socket.h)
2361   #
2362   AC_MSG_CHECKING([for select])
2363   AC_LINK_IFELSE([
2364     AC_LANG_PROGRAM([[
2365 #undef inline
2366 #ifdef HAVE_WINDOWS_H
2367 #ifndef WIN32_LEAN_AND_MEAN
2368 #define WIN32_LEAN_AND_MEAN
2369 #endif
2370 #include <windows.h>
2371 #ifdef HAVE_WINSOCK2_H
2372 #include <winsock2.h>
2373 #else
2374 #ifdef HAVE_WINSOCK_H
2375 #include <winsock.h>
2376 #endif
2377 #endif
2378 #endif
2379 #ifdef HAVE_SYS_TYPES_H
2380 #include <sys/types.h>
2381 #endif
2382 #ifdef HAVE_SYS_TIME_H
2383 #include <sys/time.h>
2384 #ifdef TIME_WITH_SYS_TIME
2385 #include <time.h>
2386 #endif
2387 #else
2388 #ifdef HAVE_TIME_H
2389 #include <time.h>
2390 #endif
2391 #endif
2392 #ifndef HAVE_WINDOWS_H
2393 #ifdef HAVE_SYS_SELECT_H
2394 #include <sys/select.h>
2395 #endif
2396 #ifdef HAVE_SYS_SOCKET_H
2397 #include <sys/socket.h>
2398 #endif
2399 #endif
2400     ]],[[
2401       select(0, 0, 0, 0, 0);
2402     ]])
2403   ],[
2404     AC_MSG_RESULT([yes])
2405     curl_cv_select="yes"
2406   ],[
2407     AC_MSG_RESULT([no])
2408     curl_cv_select="no"
2409   ])
2410   #
2411   if test "$curl_cv_select" = "yes"; then
2412     AC_CACHE_CHECK([types of args and return type for select],
2413       [curl_cv_func_select_args], [
2414       curl_cv_func_select_args="unknown"
2415       for sel_retv in 'int' 'ssize_t'; do
2416         for sel_arg1 in 'int' 'ssize_t' 'size_t' 'unsigned long int' 'unsigned int'; do
2417           for sel_arg234 in 'fd_set *' 'int *' 'void *'; do
2418             for sel_arg5 in 'struct timeval *' 'const struct timeval *'; do
2419               if test "$curl_cv_func_select_args" = "unknown"; then
2420                 AC_COMPILE_IFELSE([
2421                   AC_LANG_PROGRAM([[
2422 #undef inline
2423 #ifdef HAVE_WINDOWS_H
2424 #ifndef WIN32_LEAN_AND_MEAN
2425 #define WIN32_LEAN_AND_MEAN
2426 #endif
2427 #include <windows.h>
2428 #ifdef HAVE_WINSOCK2_H
2429 #include <winsock2.h>
2430 #else
2431 #ifdef HAVE_WINSOCK_H
2432 #include <winsock.h>
2433 #endif
2434 #endif
2435 #define SELECTCALLCONV PASCAL
2436 #endif
2437 #ifdef HAVE_SYS_TYPES_H
2438 #include <sys/types.h>
2439 #endif
2440 #ifdef HAVE_SYS_TIME_H
2441 #include <sys/time.h>
2442 #ifdef TIME_WITH_SYS_TIME
2443 #include <time.h>
2444 #endif
2445 #else
2446 #ifdef HAVE_TIME_H
2447 #include <time.h>
2448 #endif
2449 #endif
2450 #ifndef HAVE_WINDOWS_H
2451 #ifdef HAVE_SYS_SELECT_H
2452 #include <sys/select.h>
2453 #endif
2454 #ifdef HAVE_SYS_SOCKET_H
2455 #include <sys/socket.h>
2456 #endif
2457 #define SELECTCALLCONV
2458 #endif
2459 #ifndef HAVE_STRUCT_TIMEVAL
2460                     struct timeval {
2461                       long tv_sec;
2462                       long tv_usec;
2463                     };
2464 #endif
2465                     extern $sel_retv SELECTCALLCONV select($sel_arg1,
2466                                                            $sel_arg234,
2467                                                            $sel_arg234,
2468                                                            $sel_arg234,
2469                                                            $sel_arg5);
2470                   ]],[[
2471                     $sel_arg1   nfds=0;
2472                     $sel_arg234 rfds=0;
2473                     $sel_arg234 wfds=0;
2474                     $sel_arg234 efds=0;
2475                     $sel_retv res = select(nfds, rfds, wfds, efds, 0);
2476                   ]])
2477                 ],[
2478                   curl_cv_func_select_args="$sel_arg1,$sel_arg234,$sel_arg5,$sel_retv"
2479                 ])
2480               fi
2481             done
2482           done
2483         done
2484       done
2485     ]) # AC_CACHE_CHECK
2486     if test "$curl_cv_func_select_args" = "unknown"; then
2487       AC_MSG_WARN([Cannot find proper types to use for select args])
2488       AC_MSG_WARN([HAVE_SELECT will not be defined])
2489     else
2490       select_prev_IFS=$IFS; IFS=','
2491       set dummy `echo "$curl_cv_func_select_args" | sed 's/\*/\*/g'`
2492       IFS=$select_prev_IFS
2493       shift
2494       #
2495       sel_qual_type_arg5=$[3]
2496       #
2497       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG1, $[1],
2498         [Define to the type of arg 1 for select.])
2499       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG234, $[2],
2500         [Define to the type of args 2, 3 and 4 for select.])
2501       AC_DEFINE_UNQUOTED(SELECT_TYPE_RETV, $[4],
2502         [Define to the function return type for select.])
2503       #
2504       prev_sh_opts=$-
2505       #
2506       case $prev_sh_opts in
2507         *f*)
2508           ;;
2509         *)
2510           set -f
2511           ;;
2512       esac
2513       #
2514       case "$sel_qual_type_arg5" in
2515         const*)
2516           sel_qual_arg5=const
2517           sel_type_arg5=`echo $sel_qual_type_arg5 | sed 's/^const //'`
2518         ;;
2519         *)
2520           sel_qual_arg5=
2521           sel_type_arg5=$sel_qual_type_arg5
2522         ;;
2523       esac
2524       #
2525       AC_DEFINE_UNQUOTED(SELECT_QUAL_ARG5, $sel_qual_arg5,
2526         [Define to the type qualifier of arg 5 for select.])
2527       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG5, $sel_type_arg5,
2528         [Define to the type of arg 5 for select.])
2529       #
2530       case $prev_sh_opts in
2531         *f*)
2532           ;;
2533         *)
2534           set +f
2535           ;;
2536       esac
2537       #
2538       AC_DEFINE_UNQUOTED(HAVE_SELECT, 1,
2539         [Define to 1 if you have the select function.])
2540       ac_cv_func_select="yes"
2541     fi
2542   fi
2543 ]) # AC_DEFUN
2544
2545
2546 dnl ************************************************************
2547 dnl check for "localhost", if it doesn't exist, we can't do the
2548 dnl gethostbyname_r tests!
2549 dnl 
2550
2551 AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
2552 AC_MSG_CHECKING([if "localhost" resolves])
2553 AC_TRY_RUN([
2554 #include <string.h>
2555 #include <sys/types.h>
2556 #include <netdb.h>
2557 #ifndef NULL
2558 #define NULL (void *)0
2559 #endif
2560
2561 int
2562 main () {
2563 struct hostent *h;
2564 h = gethostbyname("localhost");
2565 exit (h == NULL ? 1 : 0); }],[
2566       AC_MSG_RESULT(yes)],[
2567       AC_MSG_RESULT(no)
2568       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
2569
2570       ]
2571 )
2572 ])
2573
2574 dnl ************************************************************
2575 dnl check for working getaddrinfo() that works with AI_NUMERICHOST
2576 dnl
2577 AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
2578   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
2579   AC_TRY_RUN( [
2580 #include <netdb.h>
2581 #include <sys/types.h>
2582 #include <sys/socket.h>
2583
2584 int main(void)
2585 {
2586     struct addrinfo hints, *ai;
2587     int error;
2588
2589     memset(&hints, 0, sizeof(hints));
2590     hints.ai_flags = AI_NUMERICHOST;
2591     hints.ai_family = AF_UNSPEC;
2592     hints.ai_socktype = SOCK_STREAM;
2593     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
2594     if (error) {
2595         return 1;
2596     }
2597     return 0;
2598 }
2599 ],[
2600   ac_cv_working_getaddrinfo="yes"
2601 ],[
2602   ac_cv_working_getaddrinfo="no"
2603 ],[
2604   ac_cv_working_getaddrinfo="yes"
2605 ])])
2606 if test "$ac_cv_working_getaddrinfo" = "yes"; then
2607   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
2608   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
2609
2610   IPV6_ENABLED=1
2611   AC_SUBST(IPV6_ENABLED)
2612 fi
2613 ])
2614
2615
2616 AC_DEFUN([CURL_CHECK_LOCALTIME_R],
2617 [
2618   dnl check for localtime_r
2619   AC_CHECK_FUNCS(localtime_r,[
2620     AC_MSG_CHECKING(whether localtime_r is declared)
2621     AC_EGREP_CPP(localtime_r,[
2622 #undef _REENTRANT
2623 #include <time.h>],[
2624       AC_MSG_RESULT(yes)],[
2625       AC_MSG_RESULT(no)
2626       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
2627       AC_EGREP_CPP(localtime_r,[
2628 #undef _REENTRANT
2629 #define _REENTRANT
2630 #include <time.h>],[
2631         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
2632         AC_MSG_RESULT(yes)],
2633         AC_MSG_RESULT(no))])])
2634 ])
2635
2636 dnl
2637 dnl This function checks for strerror_r(). If it isn't found at first, it
2638 dnl retries with _THREAD_SAFE defined, as that is what AIX seems to require
2639 dnl in order to find this function.
2640 dnl
2641 dnl If the function is found, it will then proceed to check how the function
2642 dnl actually works: glibc-style or POSIX-style.
2643 dnl
2644 dnl glibc:
2645 dnl      char *strerror_r(int errnum, char *buf, size_t n);
2646 dnl  
2647 dnl  What this one does is to return the error string (no surprises there),
2648 dnl  but it doesn't usually copy anything into buf!  The 'buf' and 'n'
2649 dnl  parameters are only meant as an optional working area, in case strerror_r
2650 dnl  needs it.  A quick test on a few systems shows that it's generally not
2651 dnl  touched at all.
2652 dnl
2653 dnl POSIX:
2654 dnl      int strerror_r(int errnum, char *buf, size_t n);
2655 dnl
2656 AC_DEFUN([CURL_CHECK_STRERROR_R],
2657 [
2658   AC_CHECK_FUNCS(strerror_r)
2659
2660   if test "x$ac_cv_func_strerror_r" = "xyes"; then
2661
2662     AC_MSG_CHECKING(whether strerror_r is declared)
2663     AC_EGREP_CPP(strerror_r,[
2664 #undef _REENTRANT
2665 #include <string.h>],[
2666       AC_MSG_RESULT(yes)],[
2667       AC_MSG_RESULT(no)
2668       AC_MSG_CHECKING(whether strerror_r with -D_REENTRANT is declared)
2669       AC_EGREP_CPP(strerror_r,[
2670 #undef _REENTRANT
2671 #define _REENTRANT
2672 #include <string.h>],[
2673         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
2674         AC_MSG_RESULT(yes)],
2675         AC_MSG_RESULT(no)
2676         AC_DEFINE(HAVE_NO_STRERROR_R_DECL, 1, [we have no strerror_r() proto])
2677        ) dnl with _THREAD_SAFE
2678     ]) dnl plain cpp for it
2679
2680     dnl determine if this strerror_r() is glibc or POSIX
2681     AC_MSG_CHECKING([for a glibc strerror_r API])
2682     AC_TRY_RUN([
2683 #include <string.h>
2684 #include <errno.h>
2685 int
2686 main () {
2687   char buffer[1024]; /* big enough to play with */
2688   char *string =
2689     strerror_r(EACCES, buffer, sizeof(buffer));
2690     /* this should've returned a string */
2691     if(!string || !string[0])
2692       return 99;
2693     return 0;
2694 }
2695 ],
2696     GLIBC_STRERROR_R="1"
2697     AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
2698     AC_MSG_RESULT([yes]),
2699     AC_MSG_RESULT([no]),
2700
2701     dnl Use an inferior method of strerror_r detection while cross-compiling
2702     AC_EGREP_CPP(yes, [
2703 #include <features.h>
2704 #ifdef __GLIBC__
2705 yes
2706 #endif
2707 ], 
2708       dnl looks like glibc, so assume a glibc-style strerror_r()
2709       GLIBC_STRERROR_R="1"
2710       AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
2711       AC_MSG_RESULT([yes]),
2712       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
2713     ) dnl while cross-compiling
2714     )
2715
2716     if test -z "$GLIBC_STRERROR_R"; then
2717
2718       AC_MSG_CHECKING([for a POSIX strerror_r API])
2719       AC_TRY_RUN([
2720 #include <string.h>
2721 #include <errno.h>
2722 int
2723 main () {
2724   char buffer[1024]; /* big enough to play with */
2725   int error =
2726     strerror_r(EACCES, buffer, sizeof(buffer));
2727     /* This should've returned zero, and written an error string in the
2728        buffer.*/
2729     if(!buffer[0] || error)
2730       return 99;
2731     return 0;
2732 }
2733 ],
2734       AC_DEFINE(HAVE_POSIX_STRERROR_R, 1, [we have a POSIX-style strerror_r()])
2735       AC_MSG_RESULT([yes]),
2736       AC_MSG_RESULT([no]) ,
2737       dnl cross-compiling!
2738       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
2739     )
2740
2741     fi dnl if not using glibc API
2742
2743   fi dnl we have a strerror_r
2744
2745 ])
2746
2747 AC_DEFUN([CURL_CHECK_INET_NTOA_R],
2748 [
2749   dnl determine if function definition for inet_ntoa_r exists.
2750   AC_CHECK_FUNCS(inet_ntoa_r,[
2751     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
2752     AC_EGREP_CPP(inet_ntoa_r,[
2753 #undef _REENTRANT
2754 #include <arpa/inet.h>],[
2755       AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
2756       AC_MSG_RESULT(yes)],[
2757       AC_MSG_RESULT(no)
2758       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
2759       AC_EGREP_CPP(inet_ntoa_r,[
2760 #undef _REENTRANT
2761 #define _REENTRANT
2762 #include <arpa/inet.h>],[
2763         AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
2764         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
2765         AC_MSG_RESULT(yes)],
2766         AC_MSG_RESULT(no))])])
2767 ])
2768
2769
2770 dnl CURL_CHECK_GETHOSTBYADDR_R
2771 dnl -------------------------------------------------
2772 dnl check number of arguments for gethostbyaddr_r, it
2773 dnl might take either 5, 7, or 8 arguments.
2774
2775 AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R], [
2776   #
2777   AC_MSG_CHECKING([for gethostbyaddr_r])
2778   AC_LINK_IFELSE([
2779     AC_LANG_FUNC_LINK_TRY([gethostbyaddr_r])
2780   ],[
2781     AC_MSG_RESULT([yes])
2782     tmp_cv_gethostbyaddr_r="yes"
2783   ],[
2784     AC_MSG_RESULT([no])
2785     tmp_cv_gethostbyaddr_r="no"
2786   ])
2787   #
2788   if test "$tmp_cv_gethostbyaddr_r" != "yes"; then
2789     AC_MSG_CHECKING([deeper for gethostbyaddr_r])
2790     AC_LINK_IFELSE([
2791       AC_LANG_PROGRAM([[
2792       ]],[[
2793         gethostbyaddr_r();
2794       ]])
2795     ],[
2796       AC_MSG_RESULT([yes])
2797       tmp_cv_gethostbyaddr_r="yes"
2798     ],[
2799       AC_MSG_RESULT([but still no])
2800       tmp_cv_gethostbyaddr_r="no"
2801     ])
2802   fi
2803   #
2804   if test "$tmp_cv_gethostbyaddr_r" = "yes"; then
2805
2806     ac_cv_gethostbyaddr_r_args="unknown"
2807
2808     AC_MSG_CHECKING([if gethostbyaddr_r takes 5 arguments])
2809     AC_COMPILE_IFELSE([
2810       AC_LANG_PROGRAM([[
2811 #undef _REENTRANT
2812 #include <sys/types.h>
2813 #include <netdb.h>
2814       ]],[[
2815         char * address;
2816         int length;
2817         int type;
2818         struct hostent h;
2819         struct hostent_data hdata;
2820         int rc;
2821         rc = gethostbyaddr_r(address, length, type, &h, &hdata);
2822       ]])
2823     ],[
2824       AC_MSG_RESULT([yes])
2825       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
2826       ac_cv_gethostbyaddr_r_args="5"
2827     ],[
2828       AC_MSG_RESULT([no])
2829     ])
2830
2831     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2832       AC_MSG_CHECKING([if gethostbyaddr_r with -D_REENTRANT takes 5 arguments])
2833       AC_COMPILE_IFELSE([
2834         AC_LANG_PROGRAM([[
2835 #undef _REENTRANT
2836 #define _REENTRANT
2837 #include <sys/types.h>
2838 #include <netdb.h>
2839         ]],[[
2840           char * address;
2841           int length;
2842           int type;
2843           struct hostent h;
2844           struct hostent_data hdata;
2845           int rc;
2846           rc = gethostbyaddr_r(address, length, type, &h, &hdata);
2847         ]])
2848       ],[
2849         AC_MSG_RESULT([yes])
2850         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
2851         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
2852         ac_cv_gethostbyaddr_r_args="5"
2853       ],[
2854         AC_MSG_RESULT([no])
2855       ])
2856     fi
2857
2858     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2859       AC_MSG_CHECKING([if gethostbyaddr_r takes 7 arguments])
2860       AC_COMPILE_IFELSE([
2861         AC_LANG_PROGRAM([[
2862 #undef _REENTRANT
2863 #include <sys/types.h>
2864 #include <netdb.h>
2865         ]],[[
2866           char * address;
2867           int length;
2868           int type;
2869           struct hostent h;
2870           char buffer[8192];
2871           int h_errnop;
2872           struct hostent * hp;
2873           hp = gethostbyaddr_r(address, length, type, &h,
2874                                buffer, 8192, &h_errnop);
2875         ]])
2876       ],[
2877         AC_MSG_RESULT([yes])
2878         AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args])
2879         ac_cv_gethostbyaddr_r_args="7"
2880       ],[
2881         AC_MSG_RESULT([no])
2882       ])
2883     fi
2884
2885     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2886       AC_MSG_CHECKING([if gethostbyaddr_r with -D_REENTRANT takes 7 arguments])
2887       AC_COMPILE_IFELSE([
2888         AC_LANG_PROGRAM([[
2889 #undef _REENTRANT
2890 #define _REENTRANT
2891 #include <sys/types.h>
2892 #include <netdb.h>
2893         ]],[[
2894           char * address;
2895           int length;
2896           int type;
2897           struct hostent h;
2898           char buffer[8192];
2899           int h_errnop;
2900           struct hostent * hp;
2901           hp = gethostbyaddr_r(address, length, type, &h,
2902                                buffer, 8192, &h_errnop);
2903         ]])
2904       ],[
2905         AC_MSG_RESULT([yes])
2906         AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args])
2907         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
2908         ac_cv_gethostbyaddr_r_args="7"
2909       ],[
2910         AC_MSG_RESULT([no])
2911       ])
2912     fi
2913
2914     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2915       AC_MSG_CHECKING([if gethostbyaddr_r takes 8 arguments])
2916       AC_COMPILE_IFELSE([
2917         AC_LANG_PROGRAM([[
2918 #undef _REENTRANT
2919 #include <sys/types.h>
2920 #include <netdb.h>
2921         ]],[[
2922           char * address;
2923           int length;
2924           int type;
2925           struct hostent h;
2926           char buffer[8192];
2927           int h_errnop;
2928           struct hostent * hp;
2929           int rc;
2930           rc = gethostbyaddr_r(address, length, type, &h,
2931                                buffer, 8192, &hp, &h_errnop);
2932         ]])
2933       ],[
2934         AC_MSG_RESULT([yes])
2935         AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
2936         ac_cv_gethostbyaddr_r_args="8"
2937       ],[
2938         AC_MSG_RESULT([no])
2939       ])
2940     fi
2941
2942     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2943       AC_MSG_CHECKING([if gethostbyaddr_r with -D_REENTRANT takes 8 arguments])
2944       AC_COMPILE_IFELSE([
2945         AC_LANG_PROGRAM([[
2946 #undef _REENTRANT
2947 #define _REENTRANT
2948 #include <sys/types.h>
2949 #include <netdb.h>
2950         ]],[[
2951           char * address;
2952           int length;
2953           int type;
2954           struct hostent h;
2955           char buffer[8192];
2956           int h_errnop;
2957           struct hostent * hp;
2958           int rc;
2959           rc = gethostbyaddr_r(address, length, type, &h,
2960                                buffer, 8192, &hp, &h_errnop);
2961         ]])
2962       ],[
2963         AC_MSG_RESULT([yes])
2964         AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
2965         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
2966         ac_cv_gethostbyaddr_r_args="8"
2967       ],[
2968         AC_MSG_RESULT([no])
2969       ])
2970     fi
2971
2972     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2973       AC_MSG_WARN([Cannot find out how to use gethostbyaddr_r])
2974       AC_MSG_WARN([HAVE_GETHOSTBYADDR_R will not be defined])
2975       ac_cv_func_gethostbyaddr_r="no"
2976     else
2977       AC_DEFINE_UNQUOTED(HAVE_GETHOSTBYADDR_R, 1,
2978         [Define to 1 if you have the gethostbyaddr_r function.])
2979       ac_cv_func_gethostbyaddr_r="yes"
2980     fi
2981
2982   else
2983     ac_cv_func_gethostbyaddr_r="no"
2984   fi
2985 ])
2986
2987
2988 dnl CURL_CHECK_GETHOSTBYNAME_R
2989 dnl -------------------------------------------------
2990 dnl check number of arguments for gethostbyname_r, it
2991 dnl might take either 3, 5, or 6 arguments.
2992
2993 AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R], [
2994   #
2995   AC_MSG_CHECKING([for gethostbyname_r])
2996   AC_LINK_IFELSE([
2997     AC_LANG_FUNC_LINK_TRY([gethostbyname_r])
2998   ],[
2999     AC_MSG_RESULT([yes])
3000     tmp_cv_gethostbyname_r="yes"
3001   ],[
3002     AC_MSG_RESULT([no])
3003     tmp_cv_gethostbyname_r="no"
3004   ])
3005   #
3006   if test "$tmp_cv_gethostbyname_r" != "yes"; then
3007     AC_MSG_CHECKING([deeper for gethostbyname_r])
3008     AC_LINK_IFELSE([
3009       AC_LANG_PROGRAM([[
3010       ]],[[
3011         gethostbyname_r();
3012       ]])
3013     ],[
3014       AC_MSG_RESULT([yes])
3015       tmp_cv_gethostbyname_r="yes"
3016     ],[
3017       AC_MSG_RESULT([but still no])
3018       tmp_cv_gethostbyname_r="no"
3019     ])
3020   fi
3021   #
3022   if test "$tmp_cv_gethostbyname_r" = "yes"; then
3023
3024     ac_cv_gethostbyname_r_args="unknown"
3025
3026     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
3027     AC_COMPILE_IFELSE([
3028       AC_LANG_PROGRAM([[
3029 #undef _REENTRANT
3030 #include <string.h>
3031 #include <sys/types.h>
3032 #include <netdb.h>
3033 #undef NULL
3034 #define NULL (void *)0
3035         int
3036         gethostbyname_r(const char *, struct hostent *,
3037                         struct hostent_data *);
3038       ]],[[
3039         struct hostent_data data;
3040         gethostbyname_r(NULL, NULL, NULL);
3041       ]])
3042     ],[
3043       AC_MSG_RESULT([yes])
3044       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
3045       ac_cv_gethostbyname_r_args="3"
3046     ],[
3047       AC_MSG_RESULT([no])
3048     ])
3049
3050     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3051       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
3052       AC_COMPILE_IFELSE([
3053         AC_LANG_PROGRAM([[
3054 #undef _REENTRANT
3055 #define _REENTRANT
3056 #include <string.h>
3057 #include <sys/types.h>
3058 #include <netdb.h>
3059 #undef NULL
3060 #define NULL (void *)0
3061           int
3062           gethostbyname_r(const char *, struct hostent *,
3063                           struct hostent_data *);
3064         ]],[[
3065           struct hostent_data data;
3066           gethostbyname_r(NULL, NULL, NULL);
3067         ]])
3068       ],[
3069         AC_MSG_RESULT([yes])
3070         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
3071         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
3072         ac_cv_gethostbyname_r_args="3"
3073       ],[
3074         AC_MSG_RESULT([no])
3075       ])
3076     fi
3077
3078     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3079       AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
3080       AC_COMPILE_IFELSE([
3081         AC_LANG_PROGRAM([[
3082 #undef _REENTRANT
3083 #include <sys/types.h>
3084 #include <netdb.h>
3085 #undef NULL
3086 #define NULL (void *)0
3087           struct hostent *
3088           gethostbyname_r(const char *, struct hostent *,
3089                           char *, int, int *);
3090         ]],[[
3091           gethostbyname_r(NULL, NULL, NULL, 0, NULL);
3092         ]])
3093       ],[
3094         AC_MSG_RESULT([yes])
3095         AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
3096         ac_cv_gethostbyname_r_args="5"
3097       ],[
3098         AC_MSG_RESULT([no])
3099       ])
3100     fi
3101
3102     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3103       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 5 arguments])
3104       AC_COMPILE_IFELSE([
3105         AC_LANG_PROGRAM([[
3106 #undef _REENTRANT
3107 #define _REENTRANT
3108 #include <sys/types.h>
3109 #include <netdb.h>
3110 #undef NULL
3111 #define NULL (void *)0
3112           struct hostent *
3113           gethostbyname_r(const char *, struct hostent *,
3114                           char *, int, int *);
3115         ]],[[
3116           gethostbyname_r(NULL, NULL, NULL, 0, NULL);
3117         ]])
3118       ],[
3119         AC_MSG_RESULT([yes])
3120         AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
3121         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
3122         ac_cv_gethostbyname_r_args="5"
3123       ],[
3124         AC_MSG_RESULT([no])
3125       ])
3126     fi
3127
3128     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3129       AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
3130       AC_COMPILE_IFELSE([
3131         AC_LANG_PROGRAM([[
3132 #undef _REENTRANT
3133 #include <sys/types.h>
3134 #include <netdb.h>
3135 #undef NULL
3136 #define NULL (void *)0
3137           int
3138           gethostbyname_r(const char *, struct hostent *,
3139                           char *, size_t, struct hostent **, int *);
3140         ]],[[
3141           gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
3142         ]])
3143       ],[
3144         AC_MSG_RESULT([yes])
3145         AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
3146         ac_cv_gethostbyname_r_args="6"
3147       ],[
3148         AC_MSG_RESULT([no])
3149       ])
3150     fi
3151
3152     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3153       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 6 arguments])
3154       AC_COMPILE_IFELSE([
3155         AC_LANG_PROGRAM([[
3156 #undef _REENTRANT
3157 #define _REENTRANT
3158 #include <sys/types.h>
3159 #include <netdb.h>
3160 #undef NULL
3161 #define NULL (void *)0
3162           int
3163           gethostbyname_r(const char *, struct hostent *,
3164                           char *, size_t, struct hostent **, int *);
3165         ]],[[
3166           gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
3167         ]])
3168       ],[
3169         AC_MSG_RESULT([yes])
3170         AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
3171         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
3172         ac_cv_gethostbyname_r_args="6"
3173       ],[
3174         AC_MSG_RESULT([no])
3175       ])
3176     fi
3177
3178     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3179       AC_MSG_WARN([Cannot find out how to use gethostbyname_r])
3180       AC_MSG_WARN([HAVE_GETHOSTBYNAME_R will not be defined])
3181       ac_cv_func_gethostbyname_r="no"
3182     else
3183       AC_DEFINE_UNQUOTED(HAVE_GETHOSTBYNAME_R, 1,
3184         [Define to 1 if you have the gethostbyname_r function.])
3185       ac_cv_func_gethostbyname_r="yes"
3186     fi
3187
3188   else
3189     ac_cv_func_gethostbyname_r="no"
3190   fi
3191 ])
3192
3193
3194 dnl **********************************************************************
3195 dnl CURL_DETECT_ICC ([ACTION-IF-YES])
3196 dnl
3197 dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
3198 dnl sets the $ICC variable to "yes" or "no"
3199 dnl **********************************************************************
3200 AC_DEFUN([CURL_DETECT_ICC],
3201 [
3202     ICC="no"
3203     AC_MSG_CHECKING([for icc in use])
3204     if test "$GCC" = "yes"; then
3205        dnl check if this is icc acting as gcc in disguise
3206        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
3207          dnl action if the text is found, this it has not been replaced by the
3208          dnl cpp
3209          ICC="no",
3210          dnl the text was not found, it was replaced by the cpp
3211          ICC="yes"
3212          AC_MSG_RESULT([yes])
3213          [$1]
3214        )
3215     fi
3216     if test "$ICC" = "no"; then
3217         # this is not ICC
3218         AC_MSG_RESULT([no])
3219     fi
3220 ])
3221
3222 dnl We create a function for detecting which compiler we use and then set as
3223 dnl pendantic compiler options as possible for that particular compiler. The
3224 dnl options are only used for debug-builds.
3225
3226 AC_DEFUN([CURL_CC_DEBUG_OPTS],
3227 [
3228     if test "z$ICC" = "z"; then
3229       CURL_DETECT_ICC
3230     fi
3231
3232     if test "$GCC" = "yes"; then
3233
3234        dnl figure out gcc version!
3235        AC_MSG_CHECKING([gcc version])
3236        gccver=`$CC -dumpversion`
3237        num1=`echo $gccver | cut -d . -f1`
3238        num2=`echo $gccver | cut -d . -f2`
3239        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
3240        AC_MSG_RESULT($gccver)
3241
3242        if test "$ICC" = "yes"; then
3243          dnl this is icc, not gcc.
3244
3245          dnl ICC warnings we ignore:
3246          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
3247          dnl   "invalid format string conversion"
3248          dnl * 279 warns on static conditions in while expressions
3249          dnl * 981 warns on "operands are evaluated in unspecified order"
3250          dnl * 1418 "external definition with no prior declaration"
3251          dnl * 1419 warns on "external declaration in primary source file"
3252          dnl   which we know and do on purpose.
3253
3254          WARN="-wd279,269,981,1418,1419"
3255
3256          if test "$gccnum" -gt "600"; then
3257             dnl icc 6.0 and older doesn't have the -Wall flag
3258             WARN="-Wall $WARN"
3259          fi
3260        else dnl $ICC = yes
3261          dnl this is a set of options we believe *ALL* gcc versions support:
3262          WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
3263
3264          dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
3265
3266          if test "$gccnum" -ge "207"; then
3267            dnl gcc 2.7 or later
3268            WARN="$WARN -Wmissing-declarations"
3269          fi
3270
3271          if test "$gccnum" -gt "295"; then
3272            dnl only if the compiler is newer than 2.95 since we got lots of
3273            dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
3274            dnl gcc 2.95.4 on FreeBSD 4.9!
3275            WARN="$WARN -Wundef -Wno-long-long -Wsign-compare -Wshadow -Wno-multichar"
3276          fi
3277
3278          if test "$gccnum" -ge "296"; then
3279            dnl gcc 2.96 or later
3280            WARN="$WARN -Wfloat-equal"
3281          fi
3282
3283          if test "$gccnum" -gt "296"; then
3284            dnl this option does not exist in 2.96
3285            WARN="$WARN -Wno-format-nonliteral"
3286          fi
3287
3288          dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
3289          dnl on i686-Linux as it gives us heaps with false positives.
3290          dnl Also, on gcc 4.0.X it is totally unbearable and complains all
3291          dnl over making it unusable for generic purposes. Let's not use it.
3292
3293          if test "$gccnum" -ge "303"; then
3294            dnl gcc 3.3 and later
3295            WARN="$WARN -Wendif-labels -Wstrict-prototypes"
3296          fi
3297
3298          if test "$gccnum" -ge "304"; then
3299            # try these on gcc 3.4
3300            WARN="$WARN -Wdeclaration-after-statement"
3301          fi
3302
3303          for flag in $CPPFLAGS; do
3304            case "$flag" in
3305             -I*)
3306               dnl Include path, provide a -isystem option for the same dir
3307               dnl to prevent warnings in those dirs. The -isystem was not very
3308               dnl reliable on earlier gcc versions.
3309               add=`echo $flag | sed 's/^-I/-isystem /g'`
3310               WARN="$WARN $add"
3311               ;;
3312            esac
3313          done
3314
3315        fi dnl $ICC = no
3316
3317        CFLAGS="$CFLAGS $WARN"
3318
3319       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
3320
3321     else dnl $GCC = yes
3322
3323       AC_MSG_NOTICE([Added no extra compiler options])
3324
3325     fi dnl $GCC = yes
3326
3327     dnl strip off optimizer flags
3328     NEWFLAGS=""
3329     for flag in $CFLAGS; do
3330       case "$flag" in
3331       -O*)
3332         dnl echo "cut off $flag"
3333         ;;
3334       *)
3335         NEWFLAGS="$NEWFLAGS $flag"
3336         ;;
3337       esac
3338     done
3339     CFLAGS=$NEWFLAGS
3340
3341 ]) dnl end of AC_DEFUN()
3342
3343 # This is only a temporary fix. This macro is here to replace the broken one
3344 # delivered by the automake project (including the 1.9.6 release). As soon as
3345 # they ship a working version we SHOULD remove this work-around.
3346
3347 AC_DEFUN([AM_MISSING_HAS_RUN],
3348 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
3349 test x"${MISSING+set}" = xset || MISSING="\${SHELL} \"$am_aux_dir/missing\""
3350 # Use eval to expand $SHELL
3351 if eval "$MISSING --run true"; then
3352   am_missing_run="$MISSING --run "
3353 else
3354   am_missing_run=
3355   AC_MSG_WARN([`missing' script is too old or missing])
3356 fi
3357 ])
3358
3359
3360 dnl CURL_VERIFY_RUNTIMELIBS
3361 dnl -------------------------------------------------
3362 dnl Verify that the shared libs found so far can be used when running
3363 dnl programs, since otherwise the situation will create odd configure errors
3364 dnl that are misleading people.
3365 dnl
3366 dnl Make sure this test is run BEFORE the first test in the script that
3367 dnl runs anything, which at the time of this writing is the AC_CHECK_SIZEOF
3368 dnl macro. It must also run AFTER all lib-checking macros are complete.
3369
3370 AC_DEFUN([CURL_VERIFY_RUNTIMELIBS], [
3371
3372   dnl this test is of course not sensible if we are cross-compiling!
3373   if test "x$cross_compiling" != xyes; then
3374
3375     dnl just run a program to verify that the libs checked for previous to this
3376     dnl point also is available run-time!
3377     AC_MSG_CHECKING([run-time libs availability])
3378     AC_TRY_RUN([
3379 main()
3380 {
3381   return 0;
3382 }
3383 ],
3384     AC_MSG_RESULT([fine]),
3385     AC_MSG_RESULT([failed])
3386     AC_MSG_ERROR([one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS])
3387     )
3388
3389     dnl if this test fails, configure has already stopped
3390   fi
3391 ])
3392
3393
3394 dnl CURL_CHECK_VARIADIC_MACROS
3395 dnl -------------------------------------------------
3396 dnl Check compiler support of variadic macros
3397
3398 AC_DEFUN([CURL_CHECK_VARIADIC_MACROS], [
3399   AC_CACHE_CHECK([for compiler support of C99 variadic macro style],
3400     [curl_cv_variadic_macros_c99], [
3401     AC_COMPILE_IFELSE([
3402       AC_LANG_PROGRAM([[
3403 #define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
3404 #define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
3405         int fun3(int arg1, int arg2, int arg3);
3406         int fun2(int arg1, int arg2);
3407         int fun3(int arg1, int arg2, int arg3)
3408         { return arg1 + arg2 + arg3; }
3409         int fun2(int arg1, int arg2)
3410         { return arg1 + arg2; }
3411       ]],[[
3412         int res3 = c99_vmacro3(1, 2, 3);
3413         int res2 = c99_vmacro2(1, 2);
3414       ]])
3415     ],[
3416       curl_cv_variadic_macros_c99="yes"
3417     ],[
3418       curl_cv_variadic_macros_c99="no"
3419     ])
3420   ])
3421   case "$curl_cv_variadic_macros_c99" in
3422     yes)
3423       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_C99, 1,
3424         [Define to 1 if compiler supports C99 variadic macro style.])
3425       ;;
3426   esac
3427   AC_CACHE_CHECK([for compiler support of old gcc variadic macro style],
3428     [curl_cv_variadic_macros_gcc], [
3429     AC_COMPILE_IFELSE([
3430       AC_LANG_PROGRAM([[
3431 #define gcc_vmacro3(first, args...) fun3(first, args)
3432 #define gcc_vmacro2(first, args...) fun2(first, args)
3433         int fun3(int arg1, int arg2, int arg3);
3434         int fun2(int arg1, int arg2);
3435         int fun3(int arg1, int arg2, int arg3)
3436         { return arg1 + arg2 + arg3; }
3437         int fun2(int arg1, int arg2)
3438         { return arg1 + arg2; }
3439       ]],[[
3440         int res3 = gcc_vmacro3(1, 2, 3);
3441         int res2 = gcc_vmacro2(1, 2);
3442       ]])
3443     ],[
3444       curl_cv_variadic_macros_gcc="yes"
3445     ],[
3446       curl_cv_variadic_macros_gcc="no"
3447     ])
3448   ])
3449   case "$curl_cv_variadic_macros_gcc" in
3450     yes)
3451       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_GCC, 1,
3452         [Define to 1 if compiler supports old gcc variadic macro style.])
3453       ;;
3454   esac
3455 ])
3456
3457
3458 dnl CURL_CHECK_CA_BUNDLE
3459 dnl -------------------------------------------------
3460 dnl Check if a default ca-bundle should be used
3461 dnl
3462 dnl regarding the paths this will scan:
3463 dnl /etc/ssl/certs/ca-certificates.crt Debian systems
3464 dnl /etc/pki/tls/certs/ca-bundle.crt Redhat and Mandriva
3465 dnl /usr/share/ssl/certs/ca-bundle.crt old(er) Redhat
3466 dnl /etc/ssl/certs/ (ca path) SUSE
3467
3468 AC_DEFUN([CURL_CHECK_CA_BUNDLE], [
3469
3470   AC_MSG_CHECKING([default CA cert bundle/path])
3471
3472   AC_ARG_WITH(ca-bundle,
3473 AC_HELP_STRING([--with-ca-bundle=FILE], [File name to use as CA bundle])
3474 AC_HELP_STRING([--without-ca-bundle], [Don't use a default CA bundle]),
3475   [
3476     want_ca="$withval"
3477     if test "x$want_ca" = "xyes"; then
3478       AC_MSG_ERROR([--with-ca-bundle=FILE requires a path to the CA bundle])
3479     fi
3480   ],
3481   [ want_ca="unset" ])
3482   AC_ARG_WITH(ca-path,
3483 AC_HELP_STRING([--with-ca-path=DIRECTORY], [Directory to use as CA path])
3484 AC_HELP_STRING([--without-ca-path], [Don't use a default CA path]),
3485   [
3486     want_capath="$withval"
3487     if test "x$want_capath" = "xyes"; then
3488       AC_MSG_ERROR([--with-ca-path=DIRECTORY requires a path to the CA path directory])
3489     fi
3490   ],
3491   [ want_capath="unset"])
3492
3493   if test "x$want_ca" != "xno" -a "x$want_ca" != "xunset" -a \
3494           "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
3495     dnl both given
3496     AC_MSG_ERROR([Can't specify both --with-ca-bundle and --with-ca-path.])
3497   elif test "x$want_ca" != "xno" -a "x$want_ca" != "xunset"; then
3498     dnl --with-ca-bundle given
3499     ca="$want_ca"
3500     capath="no"
3501   elif test "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
3502     dnl --with-ca-path given
3503     if test "x$OPENSSL_ENABLED" != "x1"; then
3504       AC_MSG_ERROR([--with-ca-path only works with openSSL])
3505     fi
3506     capath="$want_capath"
3507     ca="no"
3508   else
3509     dnl neither of --with-ca-* given
3510     dnl first try autodetecting a CA bundle , then a CA path
3511     dnl both autodetections can be skipped by --without-ca-*
3512     ca="no"
3513     capath="no"
3514     if test "x$want_ca" = "xunset"; then
3515       dnl the path we previously would have installed the curl ca bundle
3516       dnl to, and thus we now check for an already existing cert in that place
3517       dnl in case we find no other
3518       if test "x$prefix" != xNONE; then
3519         cac="${prefix}/share/curl/curl-ca-bundle.crt"
3520       else
3521         cac="$ac_default_prefix/share/curl/curl-ca-bundle.crt"
3522       fi
3523
3524       for a in /etc/ssl/certs/ca-certificates.crt \
3525                /etc/pki/tls/certs/ca-bundle.crt \
3526                /usr/share/ssl/certs/ca-bundle.crt \
3527                "$cac"; do
3528         if test -f "$a"; then
3529           ca="$a"
3530           break
3531         fi
3532       done
3533     fi
3534     if test "x$want_capath" = "xunset" -a "x$ca" = "xno" -a \
3535             "x$OPENSSL_ENABLED" = "x1"; then
3536       for a in /etc/ssl/certs/; do
3537         if test -d "$a" && ls "$a"/[[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]].0 >/dev/null 2>/dev/null; then
3538           capath="$a"
3539           break
3540         fi
3541       done
3542     fi
3543   fi
3544         
3545     
3546
3547   if test "x$ca" != "xno"; then
3548     CURL_CA_BUNDLE='"'$ca'"'
3549     AC_DEFINE_UNQUOTED(CURL_CA_BUNDLE, "$ca", [Location of default ca bundle])
3550     AC_SUBST(CURL_CA_BUNDLE)
3551     AC_MSG_RESULT([$ca])
3552   elif test "x$capath" != "xno"; then
3553     CURL_CA_PATH="\"$capath\""
3554     AC_DEFINE_UNQUOTED(CURL_CA_PATH, "$capath", [Location of default ca path])
3555     AC_MSG_RESULT([$capath (capath)])
3556   else
3557     AC_MSG_RESULT([no])
3558   fi
3559 ])
3560