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