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