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