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