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