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