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