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