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