Tests done using 'aclocal -I m4' in buildconf and 'ACLOCAL_AMFLAGS = -I m4
[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 ]) # AC_DEFUN
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 ]) # AC_DEFUN
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 ]) # AC_DEFUN
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 ]) # AC_DEFUN
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 ]) # AC_DEFUN
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 ]) # AC_DEFUN
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 ]) # AC_DEFUN
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 ]) # AC_DEFUN
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   ]) dnl AC_CHECK_TYPE
2167 ]) dnl AC_DEFUN
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 ]) dnl AC_DEFUN
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 ]) dnl AC_DEFUN
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 ]) # AC_DEFUN
2525
2526
2527 dnl ************************************************************
2528 dnl check for "localhost", if it doesn't exist, we can't do the
2529 dnl gethostbyname_r tests!
2530 dnl 
2531
2532 AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
2533 AC_MSG_CHECKING([if "localhost" resolves])
2534 AC_TRY_RUN([
2535 #include <string.h>
2536 #include <sys/types.h>
2537 #include <netdb.h>
2538 #ifndef NULL
2539 #define NULL (void *)0
2540 #endif
2541
2542 int
2543 main () {
2544 struct hostent *h;
2545 h = gethostbyname("localhost");
2546 exit (h == NULL ? 1 : 0); }],[
2547       AC_MSG_RESULT(yes)],[
2548       AC_MSG_RESULT(no)
2549       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
2550
2551       ]
2552 )
2553 ])
2554
2555 dnl ************************************************************
2556 dnl check for working getaddrinfo() that works with AI_NUMERICHOST
2557 dnl
2558 AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
2559   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
2560   AC_TRY_RUN( [
2561 #include <netdb.h>
2562 #include <sys/types.h>
2563 #include <sys/socket.h>
2564
2565 int main(void)
2566 {
2567     struct addrinfo hints, *ai;
2568     int error;
2569
2570     memset(&hints, 0, sizeof(hints));
2571     hints.ai_flags = AI_NUMERICHOST;
2572     hints.ai_family = AF_UNSPEC;
2573     hints.ai_socktype = SOCK_STREAM;
2574     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
2575     if (error) {
2576         return 1;
2577     }
2578     return 0;
2579 }
2580 ],[
2581   ac_cv_working_getaddrinfo="yes"
2582 ],[
2583   ac_cv_working_getaddrinfo="no"
2584 ],[
2585   ac_cv_working_getaddrinfo="yes"
2586 ])])
2587 if test "$ac_cv_working_getaddrinfo" = "yes"; then
2588   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
2589   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
2590
2591   IPV6_ENABLED=1
2592   AC_SUBST(IPV6_ENABLED)
2593 fi
2594 ])
2595
2596
2597 AC_DEFUN([CURL_CHECK_LOCALTIME_R],
2598 [
2599   dnl check for localtime_r
2600   AC_CHECK_FUNCS(localtime_r,[
2601     AC_MSG_CHECKING(whether localtime_r is declared)
2602     AC_EGREP_CPP(localtime_r,[
2603 #undef _REENTRANT
2604 #include <time.h>],[
2605       AC_MSG_RESULT(yes)],[
2606       AC_MSG_RESULT(no)
2607       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
2608       AC_EGREP_CPP(localtime_r,[
2609 #undef _REENTRANT
2610 #define _REENTRANT
2611 #include <time.h>],[
2612         AC_MSG_RESULT(yes)],
2613         AC_MSG_RESULT(no))])])
2614 ])
2615
2616 dnl
2617 dnl This function checks for strerror_r(). If it isn't found at first, it
2618 dnl retries with _THREAD_SAFE defined, as that is what AIX seems to require
2619 dnl in order to find this function.
2620 dnl
2621 dnl If the function is found, it will then proceed to check how the function
2622 dnl actually works: glibc-style or POSIX-style.
2623 dnl
2624 dnl glibc:
2625 dnl      char *strerror_r(int errnum, char *buf, size_t n);
2626 dnl  
2627 dnl  What this one does is to return the error string (no surprises there),
2628 dnl  but it doesn't usually copy anything into buf!  The 'buf' and 'n'
2629 dnl  parameters are only meant as an optional working area, in case strerror_r
2630 dnl  needs it.  A quick test on a few systems shows that it's generally not
2631 dnl  touched at all.
2632 dnl
2633 dnl POSIX:
2634 dnl      int strerror_r(int errnum, char *buf, size_t n);
2635 dnl
2636 AC_DEFUN([CURL_CHECK_STRERROR_R],
2637 [
2638   AC_CHECK_FUNCS(strerror_r)
2639
2640   if test "x$ac_cv_func_strerror_r" = "xyes"; then
2641
2642     AC_MSG_CHECKING(whether strerror_r is declared)
2643     AC_EGREP_CPP(strerror_r,[
2644 #undef _REENTRANT
2645 #include <string.h>],[
2646       AC_MSG_RESULT(yes)],[
2647       AC_MSG_RESULT(no)
2648       AC_MSG_CHECKING(whether strerror_r with -D_REENTRANT is declared)
2649       AC_EGREP_CPP(strerror_r,[
2650 #undef _REENTRANT
2651 #define _REENTRANT
2652 #include <string.h>],[
2653         AC_MSG_RESULT(yes)],
2654         AC_MSG_RESULT(no)
2655         AC_DEFINE(HAVE_NO_STRERROR_R_DECL, 1, [we have no strerror_r() proto])
2656        ) dnl with _THREAD_SAFE
2657     ]) dnl plain cpp for it
2658
2659     dnl determine if this strerror_r() is glibc or POSIX
2660     AC_MSG_CHECKING([for a glibc strerror_r API])
2661     AC_TRY_RUN([
2662 #include <string.h>
2663 #include <errno.h>
2664 int
2665 main () {
2666   char buffer[1024]; /* big enough to play with */
2667   char *string =
2668     strerror_r(EACCES, buffer, sizeof(buffer));
2669     /* this should've returned a string */
2670     if(!string || !string[0])
2671       return 99;
2672     return 0;
2673 }
2674 ],
2675     GLIBC_STRERROR_R="1"
2676     AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
2677     AC_MSG_RESULT([yes]),
2678     AC_MSG_RESULT([no]),
2679
2680     dnl Use an inferior method of strerror_r detection while cross-compiling
2681     AC_EGREP_CPP(yes, [
2682 #include <features.h>
2683 #ifdef __GLIBC__
2684 yes
2685 #endif
2686 ], 
2687       dnl looks like glibc, so assume a glibc-style strerror_r()
2688       GLIBC_STRERROR_R="1"
2689       AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
2690       AC_MSG_RESULT([yes]),
2691       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
2692     ) dnl while cross-compiling
2693     )
2694
2695     if test -z "$GLIBC_STRERROR_R"; then
2696
2697       AC_MSG_CHECKING([for a POSIX strerror_r API])
2698       AC_TRY_RUN([
2699 #include <string.h>
2700 #include <errno.h>
2701 int
2702 main () {
2703   char buffer[1024]; /* big enough to play with */
2704   int error =
2705     strerror_r(EACCES, buffer, sizeof(buffer));
2706     /* This should've returned zero, and written an error string in the
2707        buffer.*/
2708     if(!buffer[0] || error)
2709       return 99;
2710     return 0;
2711 }
2712 ],
2713       AC_DEFINE(HAVE_POSIX_STRERROR_R, 1, [we have a POSIX-style strerror_r()])
2714       AC_MSG_RESULT([yes]),
2715       AC_MSG_RESULT([no]) ,
2716       dnl cross-compiling!
2717       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
2718     )
2719
2720     fi dnl if not using glibc API
2721
2722   fi dnl we have a strerror_r
2723
2724 ])
2725
2726 AC_DEFUN([CURL_CHECK_INET_NTOA_R],
2727 [
2728   dnl determine if function definition for inet_ntoa_r exists.
2729   AC_CHECK_FUNCS(inet_ntoa_r,[
2730     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
2731     AC_EGREP_CPP(inet_ntoa_r,[
2732 #undef _REENTRANT
2733 #include <arpa/inet.h>],[
2734       AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
2735       AC_MSG_RESULT(yes)],[
2736       AC_MSG_RESULT(no)
2737       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
2738       AC_EGREP_CPP(inet_ntoa_r,[
2739 #undef _REENTRANT
2740 #define _REENTRANT
2741 #include <arpa/inet.h>],[
2742         AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
2743         AC_MSG_RESULT(yes)],
2744         AC_MSG_RESULT(no))])])
2745 ])
2746
2747
2748 dnl CURL_CHECK_GETHOSTBYADDR_R
2749 dnl -------------------------------------------------
2750 dnl check number of arguments for gethostbyaddr_r, it
2751 dnl might take either 5, 7, or 8 arguments.
2752
2753 AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R], [
2754   #
2755   AC_MSG_CHECKING([for gethostbyaddr_r])
2756   AC_LINK_IFELSE([
2757     AC_LANG_FUNC_LINK_TRY([gethostbyaddr_r])
2758   ],[
2759     AC_MSG_RESULT([yes])
2760     tmp_cv_gethostbyaddr_r="yes"
2761   ],[
2762     AC_MSG_RESULT([no])
2763     tmp_cv_gethostbyaddr_r="no"
2764   ])
2765   #
2766   if test "$tmp_cv_gethostbyaddr_r" != "yes"; then
2767     AC_MSG_CHECKING([deeper for gethostbyaddr_r])
2768     AC_LINK_IFELSE([
2769       AC_LANG_PROGRAM([[
2770       ]],[[
2771         gethostbyaddr_r();
2772       ]])
2773     ],[
2774       AC_MSG_RESULT([yes])
2775       tmp_cv_gethostbyaddr_r="yes"
2776     ],[
2777       AC_MSG_RESULT([but still no])
2778       tmp_cv_gethostbyaddr_r="no"
2779     ])
2780   fi
2781   #
2782   if test "$tmp_cv_gethostbyaddr_r" = "yes"; then
2783
2784     ac_cv_gethostbyaddr_r_args="unknown"
2785
2786     AC_MSG_CHECKING([if gethostbyaddr_r takes 5 arguments])
2787     AC_COMPILE_IFELSE([
2788       AC_LANG_PROGRAM([[
2789 #undef _REENTRANT
2790 #include <sys/types.h>
2791 #include <netdb.h>
2792       ]],[[
2793         char * address;
2794         int length;
2795         int type;
2796         struct hostent h;
2797         struct hostent_data hdata;
2798         int rc;
2799         rc = gethostbyaddr_r(address, length, type, &h, &hdata);
2800       ]])
2801     ],[
2802       AC_MSG_RESULT([yes])
2803       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
2804       ac_cv_gethostbyaddr_r_args="5"
2805     ],[
2806       AC_MSG_RESULT([no])
2807     ])
2808
2809     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2810       AC_MSG_CHECKING([if gethostbyaddr_r with -D_REENTRANT takes 5 arguments])
2811       AC_COMPILE_IFELSE([
2812         AC_LANG_PROGRAM([[
2813 #undef _REENTRANT
2814 #define _REENTRANT
2815 #include <sys/types.h>
2816 #include <netdb.h>
2817         ]],[[
2818           char * address;
2819           int length;
2820           int type;
2821           struct hostent h;
2822           struct hostent_data hdata;
2823           int rc;
2824           rc = gethostbyaddr_r(address, length, type, &h, &hdata);
2825         ]])
2826       ],[
2827         AC_MSG_RESULT([yes])
2828         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
2829         ac_cv_gethostbyaddr_r_args="5"
2830       ],[
2831         AC_MSG_RESULT([no])
2832       ])
2833     fi
2834
2835     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2836       AC_MSG_CHECKING([if gethostbyaddr_r takes 7 arguments])
2837       AC_COMPILE_IFELSE([
2838         AC_LANG_PROGRAM([[
2839 #undef _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 with -D_REENTRANT takes 7 arguments])
2864       AC_COMPILE_IFELSE([
2865         AC_LANG_PROGRAM([[
2866 #undef _REENTRANT
2867 #define _REENTRANT
2868 #include <sys/types.h>
2869 #include <netdb.h>
2870         ]],[[
2871           char * address;
2872           int length;
2873           int type;
2874           struct hostent h;
2875           char buffer[8192];
2876           int h_errnop;
2877           struct hostent * hp;
2878           hp = gethostbyaddr_r(address, length, type, &h,
2879                                buffer, 8192, &h_errnop);
2880         ]])
2881       ],[
2882         AC_MSG_RESULT([yes])
2883         AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args])
2884         ac_cv_gethostbyaddr_r_args="7"
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 takes 8 arguments])
2892       AC_COMPILE_IFELSE([
2893         AC_LANG_PROGRAM([[
2894 #undef _REENTRANT
2895 #include <sys/types.h>
2896 #include <netdb.h>
2897         ]],[[
2898           char * address;
2899           int length;
2900           int type;
2901           struct hostent h;
2902           char buffer[8192];
2903           int h_errnop;
2904           struct hostent * hp;
2905           int rc;
2906           rc = gethostbyaddr_r(address, length, type, &h,
2907                                buffer, 8192, &hp, &h_errnop);
2908         ]])
2909       ],[
2910         AC_MSG_RESULT([yes])
2911         AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
2912         ac_cv_gethostbyaddr_r_args="8"
2913       ],[
2914         AC_MSG_RESULT([no])
2915       ])
2916     fi
2917
2918     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2919       AC_MSG_CHECKING([if gethostbyaddr_r with -D_REENTRANT takes 8 arguments])
2920       AC_COMPILE_IFELSE([
2921         AC_LANG_PROGRAM([[
2922 #undef _REENTRANT
2923 #define _REENTRANT
2924 #include <sys/types.h>
2925 #include <netdb.h>
2926         ]],[[
2927           char * address;
2928           int length;
2929           int type;
2930           struct hostent h;
2931           char buffer[8192];
2932           int h_errnop;
2933           struct hostent * hp;
2934           int rc;
2935           rc = gethostbyaddr_r(address, length, type, &h,
2936                                buffer, 8192, &hp, &h_errnop);
2937         ]])
2938       ],[
2939         AC_MSG_RESULT([yes])
2940         AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
2941         ac_cv_gethostbyaddr_r_args="8"
2942       ],[
2943         AC_MSG_RESULT([no])
2944       ])
2945     fi
2946
2947     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2948       AC_MSG_WARN([Cannot find out how to use gethostbyaddr_r])
2949       AC_MSG_WARN([HAVE_GETHOSTBYADDR_R will not be defined])
2950       ac_cv_func_gethostbyaddr_r="no"
2951     else
2952       AC_DEFINE_UNQUOTED(HAVE_GETHOSTBYADDR_R, 1,
2953         [Define to 1 if you have the gethostbyaddr_r function.])
2954       ac_cv_func_gethostbyaddr_r="yes"
2955     fi
2956
2957   else
2958     ac_cv_func_gethostbyaddr_r="no"
2959   fi
2960 ])
2961
2962
2963 dnl CURL_CHECK_GETHOSTBYNAME_R
2964 dnl -------------------------------------------------
2965 dnl check number of arguments for gethostbyname_r, it
2966 dnl might take either 3, 5, or 6 arguments.
2967
2968 AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R], [
2969   #
2970   AC_MSG_CHECKING([for gethostbyname_r])
2971   AC_LINK_IFELSE([
2972     AC_LANG_FUNC_LINK_TRY([gethostbyname_r])
2973   ],[
2974     AC_MSG_RESULT([yes])
2975     tmp_cv_gethostbyname_r="yes"
2976   ],[
2977     AC_MSG_RESULT([no])
2978     tmp_cv_gethostbyname_r="no"
2979   ])
2980   #
2981   if test "$tmp_cv_gethostbyname_r" != "yes"; then
2982     AC_MSG_CHECKING([deeper for gethostbyname_r])
2983     AC_LINK_IFELSE([
2984       AC_LANG_PROGRAM([[
2985       ]],[[
2986         gethostbyname_r();
2987       ]])
2988     ],[
2989       AC_MSG_RESULT([yes])
2990       tmp_cv_gethostbyname_r="yes"
2991     ],[
2992       AC_MSG_RESULT([but still no])
2993       tmp_cv_gethostbyname_r="no"
2994     ])
2995   fi
2996   #
2997   if test "$tmp_cv_gethostbyname_r" = "yes"; then
2998
2999     ac_cv_gethostbyname_r_args="unknown"
3000
3001     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
3002     AC_COMPILE_IFELSE([
3003       AC_LANG_PROGRAM([[
3004 #undef _REENTRANT
3005 #include <string.h>
3006 #include <sys/types.h>
3007 #include <netdb.h>
3008 #undef NULL
3009 #define NULL (void *)0
3010         int
3011         gethostbyname_r(const char *, struct hostent *,
3012                         struct hostent_data *);
3013       ]],[[
3014         struct hostent_data data;
3015         gethostbyname_r(NULL, NULL, NULL);
3016       ]])
3017     ],[
3018       AC_MSG_RESULT([yes])
3019       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
3020       ac_cv_gethostbyname_r_args="3"
3021     ],[
3022       AC_MSG_RESULT([no])
3023     ])
3024
3025     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3026       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
3027       AC_COMPILE_IFELSE([
3028         AC_LANG_PROGRAM([[
3029 #undef _REENTRANT
3030 #define _REENTRANT
3031 #include <string.h>
3032 #include <sys/types.h>
3033 #include <netdb.h>
3034 #undef NULL
3035 #define NULL (void *)0
3036           int
3037           gethostbyname_r(const char *, struct hostent *,
3038                           struct hostent_data *);
3039         ]],[[
3040           struct hostent_data data;
3041           gethostbyname_r(NULL, NULL, NULL);
3042         ]])
3043       ],[
3044         AC_MSG_RESULT([yes])
3045         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
3046         ac_cv_gethostbyname_r_args="3"
3047       ],[
3048         AC_MSG_RESULT([no])
3049       ])
3050     fi
3051
3052     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3053       AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
3054       AC_COMPILE_IFELSE([
3055         AC_LANG_PROGRAM([[
3056 #undef _REENTRANT
3057 #include <sys/types.h>
3058 #include <netdb.h>
3059 #undef NULL
3060 #define NULL (void *)0
3061           struct hostent *
3062           gethostbyname_r(const char *, struct hostent *,
3063                           char *, int, int *);
3064         ]],[[
3065           gethostbyname_r(NULL, NULL, NULL, 0, NULL);
3066         ]])
3067       ],[
3068         AC_MSG_RESULT([yes])
3069         AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
3070         ac_cv_gethostbyname_r_args="5"
3071       ],[
3072         AC_MSG_RESULT([no])
3073       ])
3074     fi
3075
3076     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3077       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 5 arguments])
3078       AC_COMPILE_IFELSE([
3079         AC_LANG_PROGRAM([[
3080 #undef _REENTRANT
3081 #define _REENTRANT
3082 #include <sys/types.h>
3083 #include <netdb.h>
3084 #undef NULL
3085 #define NULL (void *)0
3086           struct hostent *
3087           gethostbyname_r(const char *, struct hostent *,
3088                           char *, int, int *);
3089         ]],[[
3090           gethostbyname_r(NULL, NULL, NULL, 0, NULL);
3091         ]])
3092       ],[
3093         AC_MSG_RESULT([yes])
3094         AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
3095         ac_cv_gethostbyname_r_args="5"
3096       ],[
3097         AC_MSG_RESULT([no])
3098       ])
3099     fi
3100
3101     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3102       AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
3103       AC_COMPILE_IFELSE([
3104         AC_LANG_PROGRAM([[
3105 #undef _REENTRANT
3106 #include <sys/types.h>
3107 #include <netdb.h>
3108 #undef NULL
3109 #define NULL (void *)0
3110           int
3111           gethostbyname_r(const char *, struct hostent *,
3112                           char *, size_t, struct hostent **, int *);
3113         ]],[[
3114           gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
3115         ]])
3116       ],[
3117         AC_MSG_RESULT([yes])
3118         AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
3119         ac_cv_gethostbyname_r_args="6"
3120       ],[
3121         AC_MSG_RESULT([no])
3122       ])
3123     fi
3124
3125     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3126       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 6 arguments])
3127       AC_COMPILE_IFELSE([
3128         AC_LANG_PROGRAM([[
3129 #undef _REENTRANT
3130 #define _REENTRANT
3131 #include <sys/types.h>
3132 #include <netdb.h>
3133 #undef NULL
3134 #define NULL (void *)0
3135           int
3136           gethostbyname_r(const char *, struct hostent *,
3137                           char *, size_t, struct hostent **, int *);
3138         ]],[[
3139           gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
3140         ]])
3141       ],[
3142         AC_MSG_RESULT([yes])
3143         AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
3144         ac_cv_gethostbyname_r_args="6"
3145       ],[
3146         AC_MSG_RESULT([no])
3147       ])
3148     fi
3149
3150     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3151       AC_MSG_WARN([Cannot find out how to use gethostbyname_r])
3152       AC_MSG_WARN([HAVE_GETHOSTBYNAME_R will not be defined])
3153       ac_cv_func_gethostbyname_r="no"
3154     else
3155       AC_DEFINE_UNQUOTED(HAVE_GETHOSTBYNAME_R, 1,
3156         [Define to 1 if you have the gethostbyname_r function.])
3157       ac_cv_func_gethostbyname_r="yes"
3158     fi
3159
3160   else
3161     ac_cv_func_gethostbyname_r="no"
3162   fi
3163 ])
3164
3165
3166 dnl **********************************************************************
3167 dnl CURL_DETECT_ICC ([ACTION-IF-YES])
3168 dnl
3169 dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
3170 dnl sets the $ICC variable to "yes" or "no"
3171 dnl **********************************************************************
3172 AC_DEFUN([CURL_DETECT_ICC],
3173 [
3174     ICC="no"
3175     AC_MSG_CHECKING([for icc in use])
3176     if test "$GCC" = "yes"; then
3177        dnl check if this is icc acting as gcc in disguise
3178        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
3179          dnl action if the text is found, this it has not been replaced by the
3180          dnl cpp
3181          ICC="no",
3182          dnl the text was not found, it was replaced by the cpp
3183          ICC="yes"
3184          AC_MSG_RESULT([yes])
3185          [$1]
3186        )
3187     fi
3188     if test "$ICC" = "no"; then
3189         # this is not ICC
3190         AC_MSG_RESULT([no])
3191     fi
3192 ])
3193
3194 dnl We create a function for detecting which compiler we use and then set as
3195 dnl pendantic compiler options as possible for that particular compiler. The
3196 dnl options are only used for debug-builds.
3197
3198 AC_DEFUN([CURL_CC_DEBUG_OPTS],
3199 [
3200     if test "z$ICC" = "z"; then
3201       CURL_DETECT_ICC
3202     fi
3203
3204     if test "$GCC" = "yes"; then
3205
3206        dnl figure out gcc version!
3207        AC_MSG_CHECKING([gcc version])
3208        gccver=`$CC -dumpversion`
3209        num1=`echo $gccver | cut -d . -f1`
3210        num2=`echo $gccver | cut -d . -f2`
3211        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
3212        AC_MSG_RESULT($gccver)
3213
3214        if test "$ICC" = "yes"; then
3215          dnl this is icc, not gcc.
3216
3217          dnl ICC warnings we ignore:
3218          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
3219          dnl   "invalid format string conversion"
3220          dnl * 279 warns on static conditions in while expressions
3221          dnl * 981 warns on "operands are evaluated in unspecified order"
3222          dnl * 1418 "external definition with no prior declaration"
3223          dnl * 1419 warns on "external declaration in primary source file"
3224          dnl   which we know and do on purpose.
3225
3226          WARN="-wd279,269,981,1418,1419"
3227
3228          if test "$gccnum" -gt "600"; then
3229             dnl icc 6.0 and older doesn't have the -Wall flag
3230             WARN="-Wall $WARN"
3231          fi
3232        else dnl $ICC = yes
3233          dnl this is a set of options we believe *ALL* gcc versions support:
3234          WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
3235
3236          dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
3237
3238          if test "$gccnum" -ge "207"; then
3239            dnl gcc 2.7 or later
3240            WARN="$WARN -Wmissing-declarations"
3241          fi
3242
3243          if test "$gccnum" -gt "295"; then
3244            dnl only if the compiler is newer than 2.95 since we got lots of
3245            dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
3246            dnl gcc 2.95.4 on FreeBSD 4.9!
3247            WARN="$WARN -Wundef -Wno-long-long -Wsign-compare -Wshadow -Wno-multichar"
3248          fi
3249
3250          if test "$gccnum" -ge "296"; then
3251            dnl gcc 2.96 or later
3252            WARN="$WARN -Wfloat-equal"
3253          fi
3254
3255          if test "$gccnum" -gt "296"; then
3256            dnl this option does not exist in 2.96
3257            WARN="$WARN -Wno-format-nonliteral"
3258          fi
3259
3260          dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
3261          dnl on i686-Linux as it gives us heaps with false positives.
3262          dnl Also, on gcc 4.0.X it is totally unbearable and complains all
3263          dnl over making it unusable for generic purposes. Let's not use it.
3264
3265          if test "$gccnum" -ge "303"; then
3266            dnl gcc 3.3 and later
3267            WARN="$WARN -Wendif-labels -Wstrict-prototypes"
3268          fi
3269
3270          if test "$gccnum" -ge "304"; then
3271            # try these on gcc 3.4
3272            WARN="$WARN -Wdeclaration-after-statement"
3273          fi
3274
3275          for flag in $CPPFLAGS; do
3276            case "$flag" in
3277             -I*)
3278               dnl Include path, provide a -isystem option for the same dir
3279               dnl to prevent warnings in those dirs. The -isystem was not very
3280               dnl reliable on earlier gcc versions.
3281               add=`echo $flag | sed 's/^-I/-isystem /g'`
3282               WARN="$WARN $add"
3283               ;;
3284            esac
3285          done
3286
3287        fi dnl $ICC = no
3288
3289        CFLAGS="$CFLAGS $WARN"
3290
3291       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
3292
3293     else dnl $GCC = yes
3294
3295       AC_MSG_NOTICE([Added no extra compiler options])
3296
3297     fi dnl $GCC = yes
3298
3299     dnl strip off optimizer flags
3300     NEWFLAGS=""
3301     for flag in $CFLAGS; do
3302       case "$flag" in
3303       -O*)
3304         dnl echo "cut off $flag"
3305         ;;
3306       *)
3307         NEWFLAGS="$NEWFLAGS $flag"
3308         ;;
3309       esac
3310     done
3311     CFLAGS=$NEWFLAGS
3312
3313 ]) dnl end of AC_DEFUN()
3314
3315 # This is only a temporary fix. This macro is here to replace the broken one
3316 # delivered by the automake project (including the 1.9.6 release). As soon as
3317 # they ship a working version we SHOULD remove this work-around.
3318
3319 AC_DEFUN([AM_MISSING_HAS_RUN],
3320 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
3321 test x"${MISSING+set}" = xset || MISSING="\${SHELL} \"$am_aux_dir/missing\""
3322 # Use eval to expand $SHELL
3323 if eval "$MISSING --run true"; then
3324   am_missing_run="$MISSING --run "
3325 else
3326   am_missing_run=
3327   AC_MSG_WARN([`missing' script is too old or missing])
3328 fi
3329 ])
3330
3331
3332 dnl CURL_VERIFY_RUNTIMELIBS
3333 dnl -------------------------------------------------
3334 dnl Verify that the shared libs found so far can be used when running
3335 dnl programs, since otherwise the situation will create odd configure errors
3336 dnl that are misleading people.
3337 dnl
3338 dnl Make sure this test is run BEFORE the first test in the script that
3339 dnl runs anything, which at the time of this writing is the AC_CHECK_SIZEOF
3340 dnl macro. It must also run AFTER all lib-checking macros are complete.
3341
3342 AC_DEFUN([CURL_VERIFY_RUNTIMELIBS], [
3343
3344   dnl this test is of course not sensible if we are cross-compiling!
3345   if test "x$cross_compiling" != xyes; then
3346
3347     dnl just run a program to verify that the libs checked for previous to this
3348     dnl point also is available run-time!
3349     AC_MSG_CHECKING([run-time libs availability])
3350     AC_TRY_RUN([
3351 main()
3352 {
3353   return 0;
3354 }
3355 ],
3356     AC_MSG_RESULT([fine]),
3357     AC_MSG_RESULT([failed])
3358     AC_MSG_ERROR([one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS])
3359     )
3360
3361     dnl if this test fails, configure has already stopped
3362   fi
3363 ])
3364
3365
3366 dnl CURL_CHECK_VARIADIC_MACROS
3367 dnl -------------------------------------------------
3368 dnl Check compiler support of variadic macros
3369
3370 AC_DEFUN([CURL_CHECK_VARIADIC_MACROS], [
3371   AC_CACHE_CHECK([for compiler support of C99 variadic macro style],
3372     [curl_cv_variadic_macros_c99], [
3373     AC_COMPILE_IFELSE([
3374       AC_LANG_PROGRAM([[
3375 #define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
3376 #define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
3377         int fun3(int arg1, int arg2, int arg3);
3378         int fun2(int arg1, int arg2);
3379         int fun3(int arg1, int arg2, int arg3)
3380         { return arg1 + arg2 + arg3; }
3381         int fun2(int arg1, int arg2)
3382         { return arg1 + arg2; }
3383       ]],[[
3384         int res3 = c99_vmacro3(1, 2, 3);
3385         int res2 = c99_vmacro2(1, 2);
3386       ]])
3387     ],[
3388       curl_cv_variadic_macros_c99="yes"
3389     ],[
3390       curl_cv_variadic_macros_c99="no"
3391     ])
3392   ])
3393   case "$curl_cv_variadic_macros_c99" in
3394     yes)
3395       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_C99, 1,
3396         [Define to 1 if compiler supports C99 variadic macro style.])
3397       ;;
3398   esac
3399   AC_CACHE_CHECK([for compiler support of old gcc variadic macro style],
3400     [curl_cv_variadic_macros_gcc], [
3401     AC_COMPILE_IFELSE([
3402       AC_LANG_PROGRAM([[
3403 #define gcc_vmacro3(first, args...) fun3(first, args)
3404 #define gcc_vmacro2(first, args...) fun2(first, args)
3405         int fun3(int arg1, int arg2, int arg3);
3406         int fun2(int arg1, int arg2);
3407         int fun3(int arg1, int arg2, int arg3)
3408         { return arg1 + arg2 + arg3; }
3409         int fun2(int arg1, int arg2)
3410         { return arg1 + arg2; }
3411       ]],[[
3412         int res3 = gcc_vmacro3(1, 2, 3);
3413         int res2 = gcc_vmacro2(1, 2);
3414       ]])
3415     ],[
3416       curl_cv_variadic_macros_gcc="yes"
3417     ],[
3418       curl_cv_variadic_macros_gcc="no"
3419     ])
3420   ])
3421   case "$curl_cv_variadic_macros_gcc" in
3422     yes)
3423       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_GCC, 1,
3424         [Define to 1 if compiler supports old gcc variadic macro style.])
3425       ;;
3426   esac
3427 ])
3428
3429
3430 dnl CURL_CHECK_CA_BUNDLE
3431 dnl -------------------------------------------------
3432 dnl Check if a default ca-bundle should be used
3433 dnl
3434 dnl regarding the paths this will scan:
3435 dnl /etc/ssl/certs/ca-certificates.crt Debian systems
3436 dnl /etc/pki/tls/certs/ca-bundle.crt Redhat and Mandriva
3437 dnl /usr/share/ssl/certs/ca-bundle.crt old(er) Redhat
3438 dnl /etc/ssl/certs/ (ca path) SUSE
3439
3440 AC_DEFUN([CURL_CHECK_CA_BUNDLE], [
3441
3442   AC_MSG_CHECKING([default CA cert bundle/path])
3443
3444   AC_ARG_WITH(ca-bundle,
3445 AC_HELP_STRING([--with-ca-bundle=FILE], [File name to use as CA bundle])
3446 AC_HELP_STRING([--without-ca-bundle], [Don't use a default CA bundle]),
3447   [
3448     want_ca="$withval"
3449     if test "x$want_ca" = "xyes"; then
3450       AC_MSG_ERROR([--with-ca-bundle=FILE requires a path to the CA bundle])
3451     fi
3452   ],
3453   [ want_ca="unset" ])
3454   AC_ARG_WITH(ca-path,
3455 AC_HELP_STRING([--with-ca-path=DIRECTORY], [Directory to use as CA path])
3456 AC_HELP_STRING([--without-ca-path], [Don't use a default CA path]),
3457   [
3458     want_capath="$withval"
3459     if test "x$want_capath" = "xyes"; then
3460       AC_MSG_ERROR([--with-ca-path=DIRECTORY requires a path to the CA path directory])
3461     fi
3462   ],
3463   [ want_capath="unset"])
3464
3465   if test "x$want_ca" != "xno" -a "x$want_ca" != "xunset" -a \
3466           "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
3467     dnl both given
3468     AC_MSG_ERROR([Can't specify both --with-ca-bundle and --with-ca-path.])
3469   elif test "x$want_ca" != "xno" -a "x$want_ca" != "xunset"; then
3470     dnl --with-ca-bundle given
3471     ca="$want_ca"
3472     capath="no"
3473   elif test "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
3474     dnl --with-ca-path given
3475     if test "x$OPENSSL_ENABLED" != "x1"; then
3476       AC_MSG_ERROR([--with-ca-path only works with openSSL])
3477     fi
3478     capath="$want_capath"
3479     ca="no"
3480   else
3481     dnl neither of --with-ca-* given
3482     dnl first try autodetecting a CA bundle , then a CA path
3483     dnl both autodetections can be skipped by --without-ca-*
3484     ca="no"
3485     capath="no"
3486     if test "x$want_ca" = "xunset"; then
3487       dnl the path we previously would have installed the curl ca bundle
3488       dnl to, and thus we now check for an already existing cert in that place
3489       dnl in case we find no other
3490       if test "x$prefix" != xNONE; then
3491         cac="${prefix}/share/curl/curl-ca-bundle.crt"
3492       else
3493         cac="$ac_default_prefix/share/curl/curl-ca-bundle.crt"
3494       fi
3495
3496       for a in /etc/ssl/certs/ca-certificates.crt \
3497                /etc/pki/tls/certs/ca-bundle.crt \
3498                /usr/share/ssl/certs/ca-bundle.crt \
3499                "$cac"; do
3500         if test -f "$a"; then
3501           ca="$a"
3502           break
3503         fi
3504       done
3505     fi
3506     if test "x$want_capath" = "xunset" -a "x$ca" = "xno" -a \
3507             "x$OPENSSL_ENABLED" = "x1"; then
3508       for a in /etc/ssl/certs/; do
3509         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
3510           capath="$a"
3511           break
3512         fi
3513       done
3514     fi
3515   fi
3516         
3517     
3518
3519   if test "x$ca" != "xno"; then
3520     CURL_CA_BUNDLE='"'$ca'"'
3521     AC_DEFINE_UNQUOTED(CURL_CA_BUNDLE, "$ca", [Location of default ca bundle])
3522     AC_SUBST(CURL_CA_BUNDLE)
3523     AC_MSG_RESULT([$ca])
3524   elif test "x$capath" != "xno"; then
3525     CURL_CA_PATH="\"$capath\""
3526     AC_DEFINE_UNQUOTED(CURL_CA_PATH, "$capath", [Location of default ca path])
3527     AC_MSG_RESULT([$capath (capath)])
3528   else
3529     AC_MSG_RESULT([no])
3530   fi
3531 ])
3532
3533
3534 dnl Tests done using 'aclocal -I m4' in buildconf and 'ACLOCAL_AMFLAGS = -I m4'
3535 dnl in top Makefile.am triggered a problem that prevented aclocal from running
3536 dnl successfully on SunOS 5.10 with GNU m4 1.4.5 and GNU Autoconf 2.61
3537 dnl We actually don't need all the bells and whistles that the above mechanism
3538 dnl provides. We only need to include our m4/reentrant.m4 file here.
3539
3540 m4_include([m4/reentrant.m4])
3541