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