Merge "Force to use getifaddrs() to get interface addresses" into tizen_base
[platform/upstream/curl.git] / acinclude.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2018, 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 https://curl.haxx.se/docs/copyright.html.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 #***************************************************************************
22
23 dnl CURL_CHECK_DEF (SYMBOL, [INCLUDES], [SILENT])
24 dnl -------------------------------------------------
25 dnl Use the C preprocessor to find out if the given object-style symbol
26 dnl is defined and get its expansion. This macro will not use default
27 dnl includes even if no INCLUDES argument is given. This macro will run
28 dnl silently when invoked with three arguments. If the expansion would
29 dnl result in a set of double-quoted strings the returned expansion will
30 dnl actually be a single double-quoted string concatenating all them.
31
32 AC_DEFUN([CURL_CHECK_DEF], [
33   AC_REQUIRE([CURL_CPP_P])dnl
34   OLDCPPFLAGS=$CPPFLAGS
35   # CPPPFLAG comes from CURL_CPP_P
36   CPPFLAGS="$CPPFLAGS $CPPPFLAG"
37   AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
38   AS_VAR_PUSHDEF([ac_Def], [curl_cv_def_$1])dnl
39   if test -z "$SED"; then
40     AC_MSG_ERROR([SED not set. Cannot continue without SED being set.])
41   fi
42   if test -z "$GREP"; then
43     AC_MSG_ERROR([GREP not set. Cannot continue without GREP being set.])
44   fi
45   ifelse($3,,[AC_MSG_CHECKING([for preprocessor definition of $1])])
46   tmp_exp=""
47   AC_PREPROC_IFELSE([
48     AC_LANG_SOURCE(
49 ifelse($2,,,[$2])[[
50 #ifdef $1
51 CURL_DEF_TOKEN $1
52 #endif
53     ]])
54   ],[
55     tmp_exp=`eval "$ac_cpp conftest.$ac_ext" 2>/dev/null | \
56       "$GREP" CURL_DEF_TOKEN 2>/dev/null | \
57       "$SED" 's/.*CURL_DEF_TOKEN[[ ]][[ ]]*//' 2>/dev/null | \
58       "$SED" 's/[["]][[ ]]*[["]]//g' 2>/dev/null`
59     if test -z "$tmp_exp" || test "$tmp_exp" = "$1"; then
60       tmp_exp=""
61     fi
62   ])
63   if test -z "$tmp_exp"; then
64     AS_VAR_SET(ac_HaveDef, no)
65     ifelse($3,,[AC_MSG_RESULT([no])])
66   else
67     AS_VAR_SET(ac_HaveDef, yes)
68     AS_VAR_SET(ac_Def, $tmp_exp)
69     ifelse($3,,[AC_MSG_RESULT([$tmp_exp])])
70   fi
71   AS_VAR_POPDEF([ac_Def])dnl
72   AS_VAR_POPDEF([ac_HaveDef])dnl
73   CPPFLAGS=$OLDCPPFLAGS
74 ])
75
76
77 dnl CURL_CHECK_DEF_CC (SYMBOL, [INCLUDES], [SILENT])
78 dnl -------------------------------------------------
79 dnl Use the C compiler to find out only if the given symbol is defined
80 dnl or not, this can not find out its expansion. This macro will not use
81 dnl default includes even if no INCLUDES argument is given. This macro
82 dnl will run silently when invoked with three arguments.
83
84 AC_DEFUN([CURL_CHECK_DEF_CC], [
85   AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
86   ifelse($3,,[AC_MSG_CHECKING([for compiler definition of $1])])
87   AC_COMPILE_IFELSE([
88     AC_LANG_SOURCE(
89 ifelse($2,,,[$2])[[
90 int main (void)
91 {
92 #ifdef $1
93   return 0;
94 #else
95   force compilation error
96 #endif
97 }
98     ]])
99   ],[
100     tst_symbol_defined="yes"
101   ],[
102     tst_symbol_defined="no"
103   ])
104   if test "$tst_symbol_defined" = "yes"; then
105     AS_VAR_SET(ac_HaveDef, yes)
106     ifelse($3,,[AC_MSG_RESULT([yes])])
107   else
108     AS_VAR_SET(ac_HaveDef, no)
109     ifelse($3,,[AC_MSG_RESULT([no])])
110   fi
111   AS_VAR_POPDEF([ac_HaveDef])dnl
112 ])
113
114
115 dnl CURL_CHECK_LIB_XNET
116 dnl -------------------------------------------------
117 dnl Verify if X/Open network library is required.
118
119 AC_DEFUN([CURL_CHECK_LIB_XNET], [
120   AC_MSG_CHECKING([if X/Open network library is required])
121   tst_lib_xnet_required="no"
122   AC_COMPILE_IFELSE([
123     AC_LANG_SOURCE([[
124 int main (void)
125 {
126 #if defined(__hpux) && defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600)
127   return 0;
128 #elif defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)
129   return 0;
130 #else
131   force compilation error
132 #endif
133 }
134     ]])
135   ],[
136     tst_lib_xnet_required="yes"
137     LIBS="-lxnet $LIBS"
138   ])
139   AC_MSG_RESULT([$tst_lib_xnet_required])
140 ])
141
142
143 dnl CURL_CHECK_AIX_ALL_SOURCE
144 dnl -------------------------------------------------
145 dnl Provides a replacement of traditional AC_AIX with
146 dnl an uniform behaviour across all autoconf versions,
147 dnl and with our own placement rules.
148
149 AC_DEFUN([CURL_CHECK_AIX_ALL_SOURCE], [
150   AH_VERBATIM([_ALL_SOURCE],
151     [/* Define to 1 if OS is AIX. */
152 #ifndef _ALL_SOURCE
153 #  undef _ALL_SOURCE
154 #endif])
155   AC_BEFORE([$0], [AC_SYS_LARGEFILE])dnl
156   AC_BEFORE([$0], [CURL_CONFIGURE_REENTRANT])dnl
157   AC_BEFORE([$0], [CURL_CONFIGURE_PULL_SYS_POLL])dnl
158   AC_MSG_CHECKING([if OS is AIX (to define _ALL_SOURCE)])
159   AC_EGREP_CPP([yes_this_is_aix],[
160 #ifdef _AIX
161    yes_this_is_aix
162 #endif
163   ],[
164     AC_MSG_RESULT([yes])
165     AC_DEFINE(_ALL_SOURCE)
166   ],[
167     AC_MSG_RESULT([no])
168   ])
169 ])
170
171
172 dnl CURL_CHECK_HEADER_WINDOWS
173 dnl -------------------------------------------------
174 dnl Check for compilable and valid windows.h header
175
176 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
177   AC_CACHE_CHECK([for windows.h], [curl_cv_header_windows_h], [
178     AC_COMPILE_IFELSE([
179       AC_LANG_PROGRAM([[
180 #undef inline
181 #ifndef WIN32_LEAN_AND_MEAN
182 #define WIN32_LEAN_AND_MEAN
183 #endif
184 #include <windows.h>
185       ]],[[
186 #if defined(__CYGWIN__) || defined(__CEGCC__)
187         HAVE_WINDOWS_H shall not be defined.
188 #else
189         int dummy=2*WINVER;
190 #endif
191       ]])
192     ],[
193       curl_cv_header_windows_h="yes"
194     ],[
195       curl_cv_header_windows_h="no"
196     ])
197   ])
198   case "$curl_cv_header_windows_h" in
199     yes)
200       AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
201         [Define to 1 if you have the windows.h header file.])
202       ;;
203   esac
204 ])
205
206
207 dnl CURL_CHECK_NATIVE_WINDOWS
208 dnl -------------------------------------------------
209 dnl Check if building a native Windows target
210
211 AC_DEFUN([CURL_CHECK_NATIVE_WINDOWS], [
212   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
213   AC_CACHE_CHECK([whether build target is a native Windows one], [curl_cv_native_windows], [
214     if test "$curl_cv_header_windows_h" = "no"; then
215       curl_cv_native_windows="no"
216     else
217       AC_COMPILE_IFELSE([
218         AC_LANG_PROGRAM([[
219         ]],[[
220 #if defined(__MINGW32__) || defined(__MINGW32CE__) || \
221    (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)))
222           int dummy=1;
223 #else
224           Not a native Windows build target.
225 #endif
226         ]])
227       ],[
228         curl_cv_native_windows="yes"
229       ],[
230         curl_cv_native_windows="no"
231       ])
232     fi
233   ])
234   AM_CONDITIONAL(DOING_NATIVE_WINDOWS, test "x$curl_cv_native_windows" = xyes)
235 ])
236
237
238 dnl CURL_CHECK_HEADER_WINSOCK
239 dnl -------------------------------------------------
240 dnl Check for compilable and valid winsock.h header
241
242 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
243   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
244   AC_CACHE_CHECK([for winsock.h], [curl_cv_header_winsock_h], [
245     AC_COMPILE_IFELSE([
246       AC_LANG_PROGRAM([[
247 #undef inline
248 #ifndef WIN32_LEAN_AND_MEAN
249 #define WIN32_LEAN_AND_MEAN
250 #endif
251 #include <windows.h>
252 #include <winsock.h>
253       ]],[[
254 #if defined(__CYGWIN__) || defined(__CEGCC__)
255         HAVE_WINSOCK_H shall not be defined.
256 #else
257         int dummy=WSACleanup();
258 #endif
259       ]])
260     ],[
261       curl_cv_header_winsock_h="yes"
262     ],[
263       curl_cv_header_winsock_h="no"
264     ])
265   ])
266   case "$curl_cv_header_winsock_h" in
267     yes)
268       AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
269         [Define to 1 if you have the winsock.h header file.])
270       ;;
271   esac
272 ])
273
274
275 dnl CURL_CHECK_HEADER_WINSOCK2
276 dnl -------------------------------------------------
277 dnl Check for compilable and valid winsock2.h header
278
279 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
280   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
281   AC_CACHE_CHECK([for winsock2.h], [curl_cv_header_winsock2_h], [
282     AC_COMPILE_IFELSE([
283       AC_LANG_PROGRAM([[
284 #undef inline
285 #ifndef WIN32_LEAN_AND_MEAN
286 #define WIN32_LEAN_AND_MEAN
287 #endif
288 #include <windows.h>
289 #include <winsock2.h>
290       ]],[[
291 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
292         HAVE_WINSOCK2_H shall not be defined.
293 #else
294         int dummy=2*IPPROTO_ESP;
295 #endif
296       ]])
297     ],[
298       curl_cv_header_winsock2_h="yes"
299     ],[
300       curl_cv_header_winsock2_h="no"
301     ])
302   ])
303   case "$curl_cv_header_winsock2_h" in
304     yes)
305       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
306         [Define to 1 if you have the winsock2.h header file.])
307       ;;
308   esac
309 ])
310
311
312 dnl CURL_CHECK_HEADER_WS2TCPIP
313 dnl -------------------------------------------------
314 dnl Check for compilable and valid ws2tcpip.h header
315
316 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
317   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
318   AC_CACHE_CHECK([for ws2tcpip.h], [curl_cv_header_ws2tcpip_h], [
319     AC_COMPILE_IFELSE([
320       AC_LANG_PROGRAM([[
321 #undef inline
322 #ifndef WIN32_LEAN_AND_MEAN
323 #define WIN32_LEAN_AND_MEAN
324 #endif
325 #include <windows.h>
326 #include <winsock2.h>
327 #include <ws2tcpip.h>
328       ]],[[
329 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
330         HAVE_WS2TCPIP_H shall not be defined.
331 #else
332         int dummy=2*IP_PKTINFO;
333 #endif
334       ]])
335     ],[
336       curl_cv_header_ws2tcpip_h="yes"
337     ],[
338       curl_cv_header_ws2tcpip_h="no"
339     ])
340   ])
341   case "$curl_cv_header_ws2tcpip_h" in
342     yes)
343       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
344         [Define to 1 if you have the ws2tcpip.h header file.])
345       ;;
346   esac
347 ])
348
349
350 dnl CURL_CHECK_HEADER_WINLDAP
351 dnl -------------------------------------------------
352 dnl Check for compilable and valid winldap.h header
353
354 AC_DEFUN([CURL_CHECK_HEADER_WINLDAP], [
355   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
356   AC_CACHE_CHECK([for winldap.h], [curl_cv_header_winldap_h], [
357     AC_COMPILE_IFELSE([
358       AC_LANG_PROGRAM([[
359 #undef inline
360 #ifdef HAVE_WINDOWS_H
361 #ifndef WIN32_LEAN_AND_MEAN
362 #define WIN32_LEAN_AND_MEAN
363 #endif
364 #include <windows.h>
365 #endif
366 #include <winldap.h>
367       ]],[[
368 #if defined(__CYGWIN__) || defined(__CEGCC__)
369         HAVE_WINLDAP_H shall not be defined.
370 #else
371         LDAP *ldp = ldap_init("dummy", LDAP_PORT);
372         ULONG res = ldap_unbind(ldp);
373 #endif
374       ]])
375     ],[
376       curl_cv_header_winldap_h="yes"
377     ],[
378       curl_cv_header_winldap_h="no"
379     ])
380   ])
381   case "$curl_cv_header_winldap_h" in
382     yes)
383       AC_DEFINE_UNQUOTED(HAVE_WINLDAP_H, 1,
384         [Define to 1 if you have the winldap.h header file.])
385       ;;
386   esac
387 ])
388
389
390 dnl CURL_CHECK_HEADER_WINBER
391 dnl -------------------------------------------------
392 dnl Check for compilable and valid winber.h header
393
394 AC_DEFUN([CURL_CHECK_HEADER_WINBER], [
395   AC_REQUIRE([CURL_CHECK_HEADER_WINLDAP])dnl
396   AC_CACHE_CHECK([for winber.h], [curl_cv_header_winber_h], [
397     AC_COMPILE_IFELSE([
398       AC_LANG_PROGRAM([[
399 #undef inline
400 #ifdef HAVE_WINDOWS_H
401 #ifndef WIN32_LEAN_AND_MEAN
402 #define WIN32_LEAN_AND_MEAN
403 #endif
404 #include <windows.h>
405 #endif
406 #include <winldap.h>
407 #include <winber.h>
408       ]],[[
409 #if defined(__CYGWIN__) || defined(__CEGCC__)
410         HAVE_WINBER_H shall not be defined.
411 #else
412         BERVAL *bvp = NULL;
413         BerElement *bep = ber_init(bvp);
414         ber_free(bep, 1);
415 #endif
416       ]])
417     ],[
418       curl_cv_header_winber_h="yes"
419     ],[
420       curl_cv_header_winber_h="no"
421     ])
422   ])
423   case "$curl_cv_header_winber_h" in
424     yes)
425       AC_DEFINE_UNQUOTED(HAVE_WINBER_H, 1,
426         [Define to 1 if you have the winber.h header file.])
427       ;;
428   esac
429 ])
430
431
432 dnl CURL_CHECK_HEADER_LBER
433 dnl -------------------------------------------------
434 dnl Check for compilable and valid lber.h header,
435 dnl and check if it is needed even with ldap.h
436
437 AC_DEFUN([CURL_CHECK_HEADER_LBER], [
438   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
439   AC_CACHE_CHECK([for lber.h], [curl_cv_header_lber_h], [
440     AC_COMPILE_IFELSE([
441       AC_LANG_PROGRAM([[
442 #undef inline
443 #ifdef HAVE_WINDOWS_H
444 #ifndef WIN32_LEAN_AND_MEAN
445 #define WIN32_LEAN_AND_MEAN
446 #endif
447 #include <windows.h>
448 #else
449 #ifdef HAVE_SYS_TYPES_H
450 #include <sys/types.h>
451 #endif
452 #endif
453 #ifndef NULL
454 #define NULL (void *)0
455 #endif
456 #include <lber.h>
457       ]],[[
458         BerValue *bvp = NULL;
459         BerElement *bep = ber_init(bvp);
460         ber_free(bep, 1);
461       ]])
462     ],[
463       curl_cv_header_lber_h="yes"
464     ],[
465       curl_cv_header_lber_h="no"
466     ])
467   ])
468   if test "$curl_cv_header_lber_h" = "yes"; then
469     AC_DEFINE_UNQUOTED(HAVE_LBER_H, 1,
470       [Define to 1 if you have the lber.h header file.])
471     #
472     AC_COMPILE_IFELSE([
473       AC_LANG_PROGRAM([[
474 #undef inline
475 #ifdef HAVE_WINDOWS_H
476 #ifndef WIN32_LEAN_AND_MEAN
477 #define WIN32_LEAN_AND_MEAN
478 #endif
479 #include <windows.h>
480 #else
481 #ifdef HAVE_SYS_TYPES_H
482 #include <sys/types.h>
483 #endif
484 #endif
485 #ifndef NULL
486 #define NULL (void *)0
487 #endif
488 #ifndef LDAP_DEPRECATED
489 #define LDAP_DEPRECATED 1
490 #endif
491 #include <ldap.h>
492       ]],[[
493         BerValue *bvp = NULL;
494         BerElement *bep = ber_init(bvp);
495         ber_free(bep, 1);
496       ]])
497     ],[
498       curl_cv_need_header_lber_h="no"
499     ],[
500       curl_cv_need_header_lber_h="yes"
501     ])
502     #
503     case "$curl_cv_need_header_lber_h" in
504       yes)
505         AC_DEFINE_UNQUOTED(NEED_LBER_H, 1,
506           [Define to 1 if you need the lber.h header file even with ldap.h])
507         ;;
508     esac
509   fi
510 ])
511
512
513 dnl CURL_CHECK_HEADER_LDAP
514 dnl -------------------------------------------------
515 dnl Check for compilable and valid ldap.h header
516
517 AC_DEFUN([CURL_CHECK_HEADER_LDAP], [
518   AC_REQUIRE([CURL_CHECK_HEADER_LBER])dnl
519   AC_CACHE_CHECK([for ldap.h], [curl_cv_header_ldap_h], [
520     AC_COMPILE_IFELSE([
521       AC_LANG_PROGRAM([[
522 #undef inline
523 #ifdef HAVE_WINDOWS_H
524 #ifndef WIN32_LEAN_AND_MEAN
525 #define WIN32_LEAN_AND_MEAN
526 #endif
527 #include <windows.h>
528 #else
529 #ifdef HAVE_SYS_TYPES_H
530 #include <sys/types.h>
531 #endif
532 #endif
533 #ifndef LDAP_DEPRECATED
534 #define LDAP_DEPRECATED 1
535 #endif
536 #ifdef NEED_LBER_H
537 #include <lber.h>
538 #endif
539 #include <ldap.h>
540       ]],[[
541         LDAP *ldp = ldap_init("dummy", LDAP_PORT);
542         int res = ldap_unbind(ldp);
543       ]])
544     ],[
545       curl_cv_header_ldap_h="yes"
546     ],[
547       curl_cv_header_ldap_h="no"
548     ])
549   ])
550   case "$curl_cv_header_ldap_h" in
551     yes)
552       AC_DEFINE_UNQUOTED(HAVE_LDAP_H, 1,
553         [Define to 1 if you have the ldap.h header file.])
554       ;;
555   esac
556 ])
557
558
559 dnl CURL_CHECK_HEADER_LDAP_SSL
560 dnl -------------------------------------------------
561 dnl Check for compilable and valid ldap_ssl.h header
562
563 AC_DEFUN([CURL_CHECK_HEADER_LDAP_SSL], [
564   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
565   AC_CACHE_CHECK([for ldap_ssl.h], [curl_cv_header_ldap_ssl_h], [
566     AC_COMPILE_IFELSE([
567       AC_LANG_PROGRAM([[
568 #undef inline
569 #ifdef HAVE_WINDOWS_H
570 #ifndef WIN32_LEAN_AND_MEAN
571 #define WIN32_LEAN_AND_MEAN
572 #endif
573 #include <windows.h>
574 #else
575 #ifdef HAVE_SYS_TYPES_H
576 #include <sys/types.h>
577 #endif
578 #endif
579 #ifndef LDAP_DEPRECATED
580 #define LDAP_DEPRECATED 1
581 #endif
582 #ifdef NEED_LBER_H
583 #include <lber.h>
584 #endif
585 #ifdef HAVE_LDAP_H
586 #include <ldap.h>
587 #endif
588 #include <ldap_ssl.h>
589       ]],[[
590         LDAP *ldp = ldapssl_init("dummy", LDAPS_PORT, 1);
591       ]])
592     ],[
593       curl_cv_header_ldap_ssl_h="yes"
594     ],[
595       curl_cv_header_ldap_ssl_h="no"
596     ])
597   ])
598   case "$curl_cv_header_ldap_ssl_h" in
599     yes)
600       AC_DEFINE_UNQUOTED(HAVE_LDAP_SSL_H, 1,
601         [Define to 1 if you have the ldap_ssl.h header file.])
602       ;;
603   esac
604 ])
605
606
607 dnl CURL_CHECK_HEADER_LDAPSSL
608 dnl -------------------------------------------------
609 dnl Check for compilable and valid ldapssl.h header
610
611 AC_DEFUN([CURL_CHECK_HEADER_LDAPSSL], [
612   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
613   AC_CACHE_CHECK([for ldapssl.h], [curl_cv_header_ldapssl_h], [
614     AC_COMPILE_IFELSE([
615       AC_LANG_PROGRAM([[
616 #undef inline
617 #ifdef HAVE_WINDOWS_H
618 #ifndef WIN32_LEAN_AND_MEAN
619 #define WIN32_LEAN_AND_MEAN
620 #endif
621 #include <windows.h>
622 #else
623 #ifdef HAVE_SYS_TYPES_H
624 #include <sys/types.h>
625 #endif
626 #endif
627 #ifndef NULL
628 #define NULL (void *)0
629 #endif
630 #ifndef LDAP_DEPRECATED
631 #define LDAP_DEPRECATED 1
632 #endif
633 #ifdef NEED_LBER_H
634 #include <lber.h>
635 #endif
636 #ifdef HAVE_LDAP_H
637 #include <ldap.h>
638 #endif
639 #include <ldapssl.h>
640       ]],[[
641         char *cert_label = NULL;
642         LDAP *ldp = ldap_ssl_init("dummy", LDAPS_PORT, cert_label);
643       ]])
644     ],[
645       curl_cv_header_ldapssl_h="yes"
646     ],[
647       curl_cv_header_ldapssl_h="no"
648     ])
649   ])
650   case "$curl_cv_header_ldapssl_h" in
651     yes)
652       AC_DEFINE_UNQUOTED(HAVE_LDAPSSL_H, 1,
653         [Define to 1 if you have the ldapssl.h header file.])
654       ;;
655   esac
656 ])
657
658
659 dnl CURL_CHECK_LIBS_WINLDAP
660 dnl -------------------------------------------------
661 dnl Check for libraries needed for WINLDAP support,
662 dnl and prepended to LIBS any needed libraries.
663 dnl This macro can take an optional parameter with a
664 dnl white space separated list of libraries to check
665 dnl before the WINLDAP default ones.
666
667 AC_DEFUN([CURL_CHECK_LIBS_WINLDAP], [
668   AC_REQUIRE([CURL_CHECK_HEADER_WINBER])dnl
669   #
670   AC_MSG_CHECKING([for WINLDAP libraries])
671   #
672   u_libs=""
673   #
674   ifelse($1,,,[
675     for x_lib in $1; do
676       case "$x_lib" in
677         -l*)
678           l_lib="$x_lib"
679           ;;
680         *)
681           l_lib="-l$x_lib"
682           ;;
683       esac
684       if test -z "$u_libs"; then
685         u_libs="$l_lib"
686       else
687         u_libs="$u_libs $l_lib"
688       fi
689     done
690   ])
691   #
692   curl_cv_save_LIBS="$LIBS"
693   curl_cv_ldap_LIBS="unknown"
694   #
695   for x_nlibs in '' "$u_libs" \
696     '-lwldap32' ; do
697     if test "$curl_cv_ldap_LIBS" = "unknown"; then
698       if test -z "$x_nlibs"; then
699         LIBS="$curl_cv_save_LIBS"
700       else
701         LIBS="$x_nlibs $curl_cv_save_LIBS"
702       fi
703       AC_LINK_IFELSE([
704         AC_LANG_PROGRAM([[
705 #undef inline
706 #ifdef HAVE_WINDOWS_H
707 #ifndef WIN32_LEAN_AND_MEAN
708 #define WIN32_LEAN_AND_MEAN
709 #endif
710 #include <windows.h>
711 #ifdef HAVE_WINLDAP_H
712 #include <winldap.h>
713 #endif
714 #ifdef HAVE_WINBER_H
715 #include <winber.h>
716 #endif
717 #endif
718         ]],[[
719           BERVAL *bvp = NULL;
720           BerElement *bep = ber_init(bvp);
721           LDAP *ldp = ldap_init("dummy", LDAP_PORT);
722           ULONG res = ldap_unbind(ldp);
723           ber_free(bep, 1);
724         ]])
725       ],[
726         curl_cv_ldap_LIBS="$x_nlibs"
727       ])
728     fi
729   done
730   #
731   LIBS="$curl_cv_save_LIBS"
732   #
733   case X-"$curl_cv_ldap_LIBS" in
734     X-unknown)
735       AC_MSG_RESULT([cannot find WINLDAP libraries])
736       ;;
737     X-)
738       AC_MSG_RESULT([no additional lib required])
739       ;;
740     *)
741       if test -z "$curl_cv_save_LIBS"; then
742         LIBS="$curl_cv_ldap_LIBS"
743       else
744         LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
745       fi
746       AC_MSG_RESULT([$curl_cv_ldap_LIBS])
747       ;;
748   esac
749   #
750 ])
751
752
753 dnl CURL_CHECK_LIBS_LDAP
754 dnl -------------------------------------------------
755 dnl Check for libraries needed for LDAP support,
756 dnl and prepended to LIBS any needed libraries.
757 dnl This macro can take an optional parameter with a
758 dnl white space separated list of libraries to check
759 dnl before the default ones.
760
761 AC_DEFUN([CURL_CHECK_LIBS_LDAP], [
762   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
763   #
764   AC_MSG_CHECKING([for LDAP libraries])
765   #
766   u_libs=""
767   #
768   ifelse($1,,,[
769     for x_lib in $1; do
770       case "$x_lib" in
771         -l*)
772           l_lib="$x_lib"
773           ;;
774         *)
775           l_lib="-l$x_lib"
776           ;;
777       esac
778       if test -z "$u_libs"; then
779         u_libs="$l_lib"
780       else
781         u_libs="$u_libs $l_lib"
782       fi
783     done
784   ])
785   #
786   curl_cv_save_LIBS="$LIBS"
787   curl_cv_ldap_LIBS="unknown"
788   #
789   for x_nlibs in '' "$u_libs" \
790     '-lldap' \
791     '-lldap -llber' \
792     '-llber -lldap' \
793     '-lldapssl -lldapx -lldapsdk' \
794     '-lldapsdk -lldapx -lldapssl' ; do
795     if test "$curl_cv_ldap_LIBS" = "unknown"; then
796       if test -z "$x_nlibs"; then
797         LIBS="$curl_cv_save_LIBS"
798       else
799         LIBS="$x_nlibs $curl_cv_save_LIBS"
800       fi
801       AC_LINK_IFELSE([
802         AC_LANG_PROGRAM([[
803 #undef inline
804 #ifdef HAVE_WINDOWS_H
805 #ifndef WIN32_LEAN_AND_MEAN
806 #define WIN32_LEAN_AND_MEAN
807 #endif
808 #include <windows.h>
809 #else
810 #ifdef HAVE_SYS_TYPES_H
811 #include <sys/types.h>
812 #endif
813 #endif
814 #ifndef NULL
815 #define NULL (void *)0
816 #endif
817 #ifndef LDAP_DEPRECATED
818 #define LDAP_DEPRECATED 1
819 #endif
820 #ifdef NEED_LBER_H
821 #include <lber.h>
822 #endif
823 #ifdef HAVE_LDAP_H
824 #include <ldap.h>
825 #endif
826         ]],[[
827           BerValue *bvp = NULL;
828           BerElement *bep = ber_init(bvp);
829           LDAP *ldp = ldap_init("dummy", LDAP_PORT);
830           int res = ldap_unbind(ldp);
831           ber_free(bep, 1);
832         ]])
833       ],[
834         curl_cv_ldap_LIBS="$x_nlibs"
835       ])
836     fi
837   done
838   #
839   LIBS="$curl_cv_save_LIBS"
840   #
841   case X-"$curl_cv_ldap_LIBS" in
842     X-unknown)
843       AC_MSG_RESULT([cannot find LDAP libraries])
844       ;;
845     X-)
846       AC_MSG_RESULT([no additional lib required])
847       ;;
848     *)
849       if test -z "$curl_cv_save_LIBS"; then
850         LIBS="$curl_cv_ldap_LIBS"
851       else
852         LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
853       fi
854       AC_MSG_RESULT([$curl_cv_ldap_LIBS])
855       ;;
856   esac
857   #
858 ])
859
860
861 dnl CURL_CHECK_HEADER_MALLOC
862 dnl -------------------------------------------------
863 dnl Check for compilable and valid malloc.h header,
864 dnl and check if it is needed even with stdlib.h
865
866 AC_DEFUN([CURL_CHECK_HEADER_MALLOC], [
867   AC_CACHE_CHECK([for malloc.h], [curl_cv_header_malloc_h], [
868     AC_COMPILE_IFELSE([
869       AC_LANG_PROGRAM([[
870 #include <malloc.h>
871       ]],[[
872         void *p = malloc(10);
873         void *q = calloc(10,10);
874         free(p);
875         free(q);
876       ]])
877     ],[
878       curl_cv_header_malloc_h="yes"
879     ],[
880       curl_cv_header_malloc_h="no"
881     ])
882   ])
883   if test "$curl_cv_header_malloc_h" = "yes"; then
884     AC_DEFINE_UNQUOTED(HAVE_MALLOC_H, 1,
885       [Define to 1 if you have the malloc.h header file.])
886     #
887     AC_COMPILE_IFELSE([
888       AC_LANG_PROGRAM([[
889 #include <stdlib.h>
890       ]],[[
891         void *p = malloc(10);
892         void *q = calloc(10,10);
893         free(p);
894         free(q);
895       ]])
896     ],[
897       curl_cv_need_header_malloc_h="no"
898     ],[
899       curl_cv_need_header_malloc_h="yes"
900     ])
901     #
902     case "$curl_cv_need_header_malloc_h" in
903       yes)
904         AC_DEFINE_UNQUOTED(NEED_MALLOC_H, 1,
905           [Define to 1 if you need the malloc.h header file even with stdlib.h])
906         ;;
907     esac
908   fi
909 ])
910
911
912 dnl CURL_CHECK_HEADER_MEMORY
913 dnl -------------------------------------------------
914 dnl Check for compilable and valid memory.h header,
915 dnl and check if it is needed even with stdlib.h for
916 dnl memory related functions.
917
918 AC_DEFUN([CURL_CHECK_HEADER_MEMORY], [
919   AC_CACHE_CHECK([for memory.h], [curl_cv_header_memory_h], [
920     AC_COMPILE_IFELSE([
921       AC_LANG_PROGRAM([[
922 #include <memory.h>
923       ]],[[
924         void *p = malloc(10);
925         void *q = calloc(10,10);
926         free(p);
927         free(q);
928       ]])
929     ],[
930       curl_cv_header_memory_h="yes"
931     ],[
932       curl_cv_header_memory_h="no"
933     ])
934   ])
935   if test "$curl_cv_header_memory_h" = "yes"; then
936     AC_DEFINE_UNQUOTED(HAVE_MEMORY_H, 1,
937       [Define to 1 if you have the memory.h header file.])
938     #
939     AC_COMPILE_IFELSE([
940       AC_LANG_PROGRAM([[
941 #include <stdlib.h>
942       ]],[[
943         void *p = malloc(10);
944         void *q = calloc(10,10);
945         free(p);
946         free(q);
947       ]])
948     ],[
949       curl_cv_need_header_memory_h="no"
950     ],[
951       curl_cv_need_header_memory_h="yes"
952     ])
953     #
954     case "$curl_cv_need_header_memory_h" in
955       yes)
956         AC_DEFINE_UNQUOTED(NEED_MEMORY_H, 1,
957           [Define to 1 if you need the memory.h header file even with stdlib.h])
958         ;;
959     esac
960   fi
961 ])
962
963 dnl TYPE_SOCKADDR_STORAGE
964 dnl -------------------------------------------------
965 dnl Check for struct sockaddr_storage. Most IPv6-enabled
966 dnl hosts have it, but AIX 4.3 is one known exception.
967
968 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
969 [
970    AC_CHECK_TYPE([struct sockaddr_storage],
971         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
972                   [if struct sockaddr_storage is defined]), ,
973    [
974 #undef inline
975 #ifdef HAVE_WINDOWS_H
976 #ifndef WIN32_LEAN_AND_MEAN
977 #define WIN32_LEAN_AND_MEAN
978 #endif
979 #include <windows.h>
980 #ifdef HAVE_WINSOCK2_H
981 #include <winsock2.h>
982 #endif
983 #else
984 #ifdef HAVE_SYS_TYPES_H
985 #include <sys/types.h>
986 #endif
987 #ifdef HAVE_SYS_SOCKET_H
988 #include <sys/socket.h>
989 #endif
990 #ifdef HAVE_NETINET_IN_H
991 #include <netinet/in.h>
992 #endif
993 #ifdef HAVE_ARPA_INET_H
994 #include <arpa/inet.h>
995 #endif
996 #endif
997    ])
998 ])
999
1000 dnl CURL_CHECK_FUNC_RECV
1001 dnl -------------------------------------------------
1002 dnl Test if the socket recv() function is available,
1003 dnl and check its return type and the types of its
1004 dnl arguments. If the function succeeds HAVE_RECV
1005 dnl will be defined, defining the types of the arguments
1006 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3
1007 dnl and RECV_TYPE_ARG4, defining the type of the function
1008 dnl return value in RECV_TYPE_RETV.
1009
1010 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
1011   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1012   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1013   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1014   #
1015   AC_MSG_CHECKING([for recv])
1016   AC_LINK_IFELSE([
1017     AC_LANG_PROGRAM([[
1018 #undef inline
1019 #ifdef HAVE_WINDOWS_H
1020 #ifndef WIN32_LEAN_AND_MEAN
1021 #define WIN32_LEAN_AND_MEAN
1022 #endif
1023 #include <windows.h>
1024 #ifdef HAVE_WINSOCK2_H
1025 #include <winsock2.h>
1026 #else
1027 #ifdef HAVE_WINSOCK_H
1028 #include <winsock.h>
1029 #endif
1030 #endif
1031 #else
1032 #ifdef HAVE_SYS_TYPES_H
1033 #include <sys/types.h>
1034 #endif
1035 #ifdef HAVE_SYS_SOCKET_H
1036 #include <sys/socket.h>
1037 #endif
1038 #endif
1039     ]],[[
1040       recv(0, 0, 0, 0);
1041     ]])
1042   ],[
1043     AC_MSG_RESULT([yes])
1044     curl_cv_recv="yes"
1045   ],[
1046     AC_MSG_RESULT([no])
1047     curl_cv_recv="no"
1048   ])
1049   #
1050   if test "$curl_cv_recv" = "yes"; then
1051     AC_CACHE_CHECK([types of args and return type for recv],
1052       [curl_cv_func_recv_args], [
1053       curl_cv_func_recv_args="unknown"
1054       for recv_retv in 'int' 'ssize_t'; do
1055         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1056           for recv_arg2 in 'char *' 'void *'; do
1057             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1058               for recv_arg4 in 'int' 'unsigned int'; do
1059                 if test "$curl_cv_func_recv_args" = "unknown"; then
1060                   AC_COMPILE_IFELSE([
1061                     AC_LANG_PROGRAM([[
1062 #undef inline
1063 #ifdef HAVE_WINDOWS_H
1064 #ifndef WIN32_LEAN_AND_MEAN
1065 #define WIN32_LEAN_AND_MEAN
1066 #endif
1067 #include <windows.h>
1068 #ifdef HAVE_WINSOCK2_H
1069 #include <winsock2.h>
1070 #else
1071 #ifdef HAVE_WINSOCK_H
1072 #include <winsock.h>
1073 #endif
1074 #endif
1075 #define RECVCALLCONV PASCAL
1076 #else
1077 #ifdef HAVE_SYS_TYPES_H
1078 #include <sys/types.h>
1079 #endif
1080 #ifdef HAVE_SYS_SOCKET_H
1081 #include <sys/socket.h>
1082 #endif
1083 #define RECVCALLCONV
1084 #endif
1085                       extern $recv_retv RECVCALLCONV
1086 #ifdef __ANDROID__
1087 __attribute__((overloadable))
1088 #endif
1089                       recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
1090                     ]],[[
1091                       $recv_arg1 s=0;
1092                       $recv_arg2 buf=0;
1093                       $recv_arg3 len=0;
1094                       $recv_arg4 flags=0;
1095                       $recv_retv res = recv(s, buf, len, flags);
1096                     ]])
1097                   ],[
1098                     curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
1099                   ])
1100                 fi
1101               done
1102             done
1103           done
1104         done
1105       done
1106     ]) # AC-CACHE-CHECK
1107     if test "$curl_cv_func_recv_args" = "unknown"; then
1108       AC_MSG_ERROR([Cannot find proper types to use for recv args])
1109     else
1110       recv_prev_IFS=$IFS; IFS=','
1111       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
1112       IFS=$recv_prev_IFS
1113       shift
1114       #
1115       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
1116         [Define to the type of arg 1 for recv.])
1117       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
1118         [Define to the type of arg 2 for recv.])
1119       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
1120         [Define to the type of arg 3 for recv.])
1121       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
1122         [Define to the type of arg 4 for recv.])
1123       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
1124         [Define to the function return type for recv.])
1125       #
1126       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
1127         [Define to 1 if you have the recv function.])
1128       curl_cv_func_recv="yes"
1129     fi
1130   else
1131     AC_MSG_ERROR([Unable to link function recv])
1132   fi
1133 ])
1134
1135
1136 dnl CURL_CHECK_FUNC_SEND
1137 dnl -------------------------------------------------
1138 dnl Test if the socket send() function is available,
1139 dnl and check its return type and the types of its
1140 dnl arguments. If the function succeeds HAVE_SEND
1141 dnl will be defined, defining the types of the arguments
1142 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3
1143 dnl and SEND_TYPE_ARG4, defining the type of the function
1144 dnl return value in SEND_TYPE_RETV, and also defining the
1145 dnl type qualifier of second argument in SEND_QUAL_ARG2.
1146
1147 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
1148   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1149   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1150   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1151   #
1152   AC_MSG_CHECKING([for send])
1153   AC_LINK_IFELSE([
1154     AC_LANG_PROGRAM([[
1155 #undef inline
1156 #ifdef HAVE_WINDOWS_H
1157 #ifndef WIN32_LEAN_AND_MEAN
1158 #define WIN32_LEAN_AND_MEAN
1159 #endif
1160 #include <windows.h>
1161 #ifdef HAVE_WINSOCK2_H
1162 #include <winsock2.h>
1163 #else
1164 #ifdef HAVE_WINSOCK_H
1165 #include <winsock.h>
1166 #endif
1167 #endif
1168 #else
1169 #ifdef HAVE_SYS_TYPES_H
1170 #include <sys/types.h>
1171 #endif
1172 #ifdef HAVE_SYS_SOCKET_H
1173 #include <sys/socket.h>
1174 #endif
1175 #endif
1176     ]],[[
1177       send(0, 0, 0, 0);
1178     ]])
1179   ],[
1180     AC_MSG_RESULT([yes])
1181     curl_cv_send="yes"
1182   ],[
1183     AC_MSG_RESULT([no])
1184     curl_cv_send="no"
1185   ])
1186   #
1187   if test "$curl_cv_send" = "yes"; then
1188     AC_CACHE_CHECK([types of args and return type for send],
1189       [curl_cv_func_send_args], [
1190       curl_cv_func_send_args="unknown"
1191       for send_retv in 'int' 'ssize_t'; do
1192         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1193           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
1194             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1195               for send_arg4 in 'int' 'unsigned int'; do
1196                 if test "$curl_cv_func_send_args" = "unknown"; then
1197                   AC_COMPILE_IFELSE([
1198                     AC_LANG_PROGRAM([[
1199 #undef inline
1200 #ifdef HAVE_WINDOWS_H
1201 #ifndef WIN32_LEAN_AND_MEAN
1202 #define WIN32_LEAN_AND_MEAN
1203 #endif
1204 #include <windows.h>
1205 #ifdef HAVE_WINSOCK2_H
1206 #include <winsock2.h>
1207 #else
1208 #ifdef HAVE_WINSOCK_H
1209 #include <winsock.h>
1210 #endif
1211 #endif
1212 #define SENDCALLCONV PASCAL
1213 #else
1214 #ifdef HAVE_SYS_TYPES_H
1215 #include <sys/types.h>
1216 #endif
1217 #ifdef HAVE_SYS_SOCKET_H
1218 #include <sys/socket.h>
1219 #endif
1220 #define SENDCALLCONV
1221 #endif
1222                       extern $send_retv SENDCALLCONV
1223 #ifdef __ANDROID__
1224 __attribute__((overloadable))
1225 #endif
1226                       send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
1227                     ]],[[
1228                       $send_arg1 s=0;
1229                       $send_arg3 len=0;
1230                       $send_arg4 flags=0;
1231                       $send_retv res = send(s, 0, len, flags);
1232                     ]])
1233                   ],[
1234                     curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
1235                   ])
1236                 fi
1237               done
1238             done
1239           done
1240         done
1241       done
1242     ]) # AC-CACHE-CHECK
1243     if test "$curl_cv_func_send_args" = "unknown"; then
1244       AC_MSG_ERROR([Cannot find proper types to use for send args])
1245     else
1246       send_prev_IFS=$IFS; IFS=','
1247       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
1248       IFS=$send_prev_IFS
1249       shift
1250       #
1251       send_qual_type_arg2=$[2]
1252       #
1253       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
1254         [Define to the type of arg 1 for send.])
1255       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
1256         [Define to the type of arg 3 for send.])
1257       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
1258         [Define to the type of arg 4 for send.])
1259       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
1260         [Define to the function return type for send.])
1261       #
1262       prev_sh_opts=$-
1263       #
1264       case $prev_sh_opts in
1265         *f*)
1266           ;;
1267         *)
1268           set -f
1269           ;;
1270       esac
1271       #
1272       case "$send_qual_type_arg2" in
1273         const*)
1274           send_qual_arg2=const
1275           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
1276         ;;
1277         *)
1278           send_qual_arg2=
1279           send_type_arg2=$send_qual_type_arg2
1280         ;;
1281       esac
1282       #
1283       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
1284         [Define to the type qualifier of arg 2 for send.])
1285       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
1286         [Define to the type of arg 2 for send.])
1287       #
1288       case $prev_sh_opts in
1289         *f*)
1290           ;;
1291         *)
1292           set +f
1293           ;;
1294       esac
1295       #
1296       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
1297         [Define to 1 if you have the send function.])
1298       curl_cv_func_send="yes"
1299     fi
1300   else
1301     AC_MSG_ERROR([Unable to link function send])
1302   fi
1303 ])
1304
1305 dnl CURL_CHECK_MSG_NOSIGNAL
1306 dnl -------------------------------------------------
1307 dnl Check for MSG_NOSIGNAL
1308
1309 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
1310   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1311   AC_CACHE_CHECK([for MSG_NOSIGNAL], [curl_cv_msg_nosignal], [
1312     AC_COMPILE_IFELSE([
1313       AC_LANG_PROGRAM([[
1314 #undef inline
1315 #ifdef HAVE_WINDOWS_H
1316 #ifndef WIN32_LEAN_AND_MEAN
1317 #define WIN32_LEAN_AND_MEAN
1318 #endif
1319 #include <windows.h>
1320 #ifdef HAVE_WINSOCK2_H
1321 #include <winsock2.h>
1322 #else
1323 #ifdef HAVE_WINSOCK_H
1324 #include <winsock.h>
1325 #endif
1326 #endif
1327 #else
1328 #ifdef HAVE_SYS_TYPES_H
1329 #include <sys/types.h>
1330 #endif
1331 #ifdef HAVE_SYS_SOCKET_H
1332 #include <sys/socket.h>
1333 #endif
1334 #endif
1335       ]],[[
1336         int flag=MSG_NOSIGNAL;
1337       ]])
1338     ],[
1339       curl_cv_msg_nosignal="yes"
1340     ],[
1341       curl_cv_msg_nosignal="no"
1342     ])
1343   ])
1344   case "$curl_cv_msg_nosignal" in
1345     yes)
1346       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
1347         [Define to 1 if you have the MSG_NOSIGNAL flag.])
1348       ;;
1349   esac
1350 ])
1351
1352
1353 dnl CURL_CHECK_STRUCT_TIMEVAL
1354 dnl -------------------------------------------------
1355 dnl Check for timeval struct
1356
1357 AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
1358   AC_REQUIRE([AC_HEADER_TIME])dnl
1359   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1360   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1361   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h sys/socket.h)
1362   AC_CACHE_CHECK([for struct timeval], [curl_cv_struct_timeval], [
1363     AC_COMPILE_IFELSE([
1364       AC_LANG_PROGRAM([[
1365 #undef inline
1366 #ifdef HAVE_WINDOWS_H
1367 #ifndef WIN32_LEAN_AND_MEAN
1368 #define WIN32_LEAN_AND_MEAN
1369 #endif
1370 #include <windows.h>
1371 #ifdef HAVE_WINSOCK2_H
1372 #include <winsock2.h>
1373 #else
1374 #ifdef HAVE_WINSOCK_H
1375 #include <winsock.h>
1376 #endif
1377 #endif
1378 #endif
1379 #ifdef HAVE_SYS_TYPES_H
1380 #include <sys/types.h>
1381 #endif
1382 #ifdef HAVE_SYS_TIME_H
1383 #include <sys/time.h>
1384 #ifdef TIME_WITH_SYS_TIME
1385 #include <time.h>
1386 #endif
1387 #else
1388 #ifdef HAVE_TIME_H
1389 #include <time.h>
1390 #endif
1391 #endif
1392 #ifdef HAVE_SYS_SOCKET_H
1393 #include <sys/socket.h>
1394 #endif
1395       ]],[[
1396         struct timeval ts;
1397         ts.tv_sec  = 0;
1398         ts.tv_usec = 0;
1399       ]])
1400     ],[
1401       curl_cv_struct_timeval="yes"
1402     ],[
1403       curl_cv_struct_timeval="no"
1404     ])
1405   ])
1406   case "$curl_cv_struct_timeval" in
1407     yes)
1408       AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMEVAL, 1,
1409         [Define to 1 if you have the timeval struct.])
1410       ;;
1411   esac
1412 ])
1413
1414
1415 dnl TYPE_SIG_ATOMIC_T
1416 dnl -------------------------------------------------
1417 dnl Check if the sig_atomic_t type is available, and
1418 dnl verify if it is already defined as volatile.
1419
1420 AC_DEFUN([TYPE_SIG_ATOMIC_T], [
1421   AC_CHECK_HEADERS(signal.h)
1422   AC_CHECK_TYPE([sig_atomic_t],[
1423     AC_DEFINE(HAVE_SIG_ATOMIC_T, 1,
1424       [Define to 1 if sig_atomic_t is an available typedef.])
1425   ], ,[
1426 #ifdef HAVE_SIGNAL_H
1427 #include <signal.h>
1428 #endif
1429   ])
1430   case "$ac_cv_type_sig_atomic_t" in
1431     yes)
1432       #
1433       AC_MSG_CHECKING([if sig_atomic_t is already defined as volatile])
1434       AC_LINK_IFELSE([
1435         AC_LANG_PROGRAM([[
1436 #ifdef HAVE_SIGNAL_H
1437 #include <signal.h>
1438 #endif
1439         ]],[[
1440           static volatile sig_atomic_t dummy = 0;
1441         ]])
1442       ],[
1443         AC_MSG_RESULT([no])
1444         curl_cv_sig_atomic_t_volatile="no"
1445       ],[
1446         AC_MSG_RESULT([yes])
1447         curl_cv_sig_atomic_t_volatile="yes"
1448       ])
1449       #
1450       if test "$curl_cv_sig_atomic_t_volatile" = "yes"; then
1451         AC_DEFINE(HAVE_SIG_ATOMIC_T_VOLATILE, 1,
1452           [Define to 1 if sig_atomic_t is already defined as volatile.])
1453       fi
1454       ;;
1455   esac
1456 ])
1457
1458
1459 dnl TYPE_IN_ADDR_T
1460 dnl -------------------------------------------------
1461 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
1462 dnl and a few other things.
1463
1464 AC_DEFUN([TYPE_IN_ADDR_T], [
1465   AC_CHECK_TYPE([in_addr_t], ,[
1466     dnl in_addr_t not available
1467     AC_CACHE_CHECK([for in_addr_t equivalent],
1468       [curl_cv_in_addr_t_equiv], [
1469       curl_cv_in_addr_t_equiv="unknown"
1470       for t in "unsigned long" int size_t unsigned long; do
1471         if test "$curl_cv_in_addr_t_equiv" = "unknown"; then
1472           AC_LINK_IFELSE([
1473             AC_LANG_PROGRAM([[
1474 #undef inline
1475 #ifdef HAVE_WINDOWS_H
1476 #ifndef WIN32_LEAN_AND_MEAN
1477 #define WIN32_LEAN_AND_MEAN
1478 #endif
1479 #include <windows.h>
1480 #ifdef HAVE_WINSOCK2_H
1481 #include <winsock2.h>
1482 #else
1483 #ifdef HAVE_WINSOCK_H
1484 #include <winsock.h>
1485 #endif
1486 #endif
1487 #else
1488 #ifdef HAVE_SYS_TYPES_H
1489 #include <sys/types.h>
1490 #endif
1491 #ifdef HAVE_SYS_SOCKET_H
1492 #include <sys/socket.h>
1493 #endif
1494 #ifdef HAVE_NETINET_IN_H
1495 #include <netinet/in.h>
1496 #endif
1497 #ifdef HAVE_ARPA_INET_H
1498 #include <arpa/inet.h>
1499 #endif
1500 #endif
1501             ]],[[
1502               $t data = inet_addr ("1.2.3.4");
1503             ]])
1504           ],[
1505             curl_cv_in_addr_t_equiv="$t"
1506           ])
1507         fi
1508       done
1509     ])
1510     case "$curl_cv_in_addr_t_equiv" in
1511       unknown)
1512         AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
1513         ;;
1514       *)
1515         AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
1516           [Type to use in place of in_addr_t when system does not provide it.])
1517         ;;
1518     esac
1519   ],[
1520 #undef inline
1521 #ifdef HAVE_WINDOWS_H
1522 #ifndef WIN32_LEAN_AND_MEAN
1523 #define WIN32_LEAN_AND_MEAN
1524 #endif
1525 #include <windows.h>
1526 #ifdef HAVE_WINSOCK2_H
1527 #include <winsock2.h>
1528 #else
1529 #ifdef HAVE_WINSOCK_H
1530 #include <winsock.h>
1531 #endif
1532 #endif
1533 #else
1534 #ifdef HAVE_SYS_TYPES_H
1535 #include <sys/types.h>
1536 #endif
1537 #ifdef HAVE_SYS_SOCKET_H
1538 #include <sys/socket.h>
1539 #endif
1540 #ifdef HAVE_NETINET_IN_H
1541 #include <netinet/in.h>
1542 #endif
1543 #ifdef HAVE_ARPA_INET_H
1544 #include <arpa/inet.h>
1545 #endif
1546 #endif
1547   ])
1548 ])
1549
1550
1551 dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
1552 dnl -------------------------------------------------
1553 dnl Check if monotonic clock_gettime is available.
1554
1555 AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
1556   AC_REQUIRE([AC_HEADER_TIME])dnl
1557   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1558   AC_MSG_CHECKING([for monotonic clock_gettime])
1559   #
1560   if test "x$dontwant_rt" = "xno" ; then
1561     AC_COMPILE_IFELSE([
1562       AC_LANG_PROGRAM([[
1563 #ifdef HAVE_SYS_TYPES_H
1564 #include <sys/types.h>
1565 #endif
1566 #ifdef HAVE_SYS_TIME_H
1567 #include <sys/time.h>
1568 #ifdef TIME_WITH_SYS_TIME
1569 #include <time.h>
1570 #endif
1571 #else
1572 #ifdef HAVE_TIME_H
1573 #include <time.h>
1574 #endif
1575 #endif
1576       ]],[[
1577         struct timespec ts;
1578         (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1579       ]])
1580     ],[
1581       AC_MSG_RESULT([yes])
1582       curl_func_clock_gettime="yes"
1583     ],[
1584       AC_MSG_RESULT([no])
1585       curl_func_clock_gettime="no"
1586     ])
1587   fi
1588   dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally postponed
1589   dnl until library linking and run-time checks for clock_gettime succeed.
1590 ])
1591
1592
1593 dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
1594 dnl -------------------------------------------------
1595 dnl If monotonic clock_gettime is available then,
1596 dnl check and prepended to LIBS any needed libraries.
1597
1598 AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
1599   AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
1600   #
1601   if test "$curl_func_clock_gettime" = "yes"; then
1602     #
1603     AC_MSG_CHECKING([for clock_gettime in libraries])
1604     #
1605     curl_cv_save_LIBS="$LIBS"
1606     curl_cv_gclk_LIBS="unknown"
1607     #
1608     for x_xlibs in '' '-lrt' '-lposix4' ; do
1609       if test "$curl_cv_gclk_LIBS" = "unknown"; then
1610         if test -z "$x_xlibs"; then
1611           LIBS="$curl_cv_save_LIBS"
1612         else
1613           LIBS="$x_xlibs $curl_cv_save_LIBS"
1614         fi
1615         AC_LINK_IFELSE([
1616           AC_LANG_PROGRAM([[
1617 #ifdef HAVE_SYS_TYPES_H
1618 #include <sys/types.h>
1619 #endif
1620 #ifdef HAVE_SYS_TIME_H
1621 #include <sys/time.h>
1622 #ifdef TIME_WITH_SYS_TIME
1623 #include <time.h>
1624 #endif
1625 #else
1626 #ifdef HAVE_TIME_H
1627 #include <time.h>
1628 #endif
1629 #endif
1630           ]],[[
1631             struct timespec ts;
1632             (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1633           ]])
1634         ],[
1635           curl_cv_gclk_LIBS="$x_xlibs"
1636         ])
1637       fi
1638     done
1639     #
1640     LIBS="$curl_cv_save_LIBS"
1641     #
1642     case X-"$curl_cv_gclk_LIBS" in
1643       X-unknown)
1644         AC_MSG_RESULT([cannot find clock_gettime])
1645         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1646         curl_func_clock_gettime="no"
1647         ;;
1648       X-)
1649         AC_MSG_RESULT([no additional lib required])
1650         curl_func_clock_gettime="yes"
1651         ;;
1652       *)
1653         if test -z "$curl_cv_save_LIBS"; then
1654           LIBS="$curl_cv_gclk_LIBS"
1655         else
1656           LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
1657         fi
1658         AC_MSG_RESULT([$curl_cv_gclk_LIBS])
1659         curl_func_clock_gettime="yes"
1660         ;;
1661     esac
1662     #
1663     dnl only do runtime verification when not cross-compiling
1664     if test "x$cross_compiling" != "xyes" &&
1665       test "$curl_func_clock_gettime" = "yes"; then
1666       AC_MSG_CHECKING([if monotonic clock_gettime works])
1667       CURL_RUN_IFELSE([
1668         AC_LANG_PROGRAM([[
1669 #ifdef HAVE_STDLIB_H
1670 #include <stdlib.h>
1671 #endif
1672 #ifdef HAVE_SYS_TYPES_H
1673 #include <sys/types.h>
1674 #endif
1675 #ifdef HAVE_SYS_TIME_H
1676 #include <sys/time.h>
1677 #ifdef TIME_WITH_SYS_TIME
1678 #include <time.h>
1679 #endif
1680 #else
1681 #ifdef HAVE_TIME_H
1682 #include <time.h>
1683 #endif
1684 #endif
1685         ]],[[
1686           struct timespec ts;
1687           if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
1688             exit(0);
1689           else
1690             exit(1);
1691         ]])
1692       ],[
1693         AC_MSG_RESULT([yes])
1694       ],[
1695         AC_MSG_RESULT([no])
1696         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1697         curl_func_clock_gettime="no"
1698         LIBS="$curl_cv_save_LIBS"
1699       ])
1700     fi
1701     #
1702     case "$curl_func_clock_gettime" in
1703       yes)
1704         AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
1705           [Define to 1 if you have the clock_gettime function and monotonic timer.])
1706         ;;
1707     esac
1708     #
1709   fi
1710   #
1711 ])
1712
1713
1714 dnl CURL_CHECK_LIBS_CONNECT
1715 dnl -------------------------------------------------
1716 dnl Verify if network connect function is already available
1717 dnl using current libraries or if another one is required.
1718
1719 AC_DEFUN([CURL_CHECK_LIBS_CONNECT], [
1720   AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
1721   AC_MSG_CHECKING([for connect in libraries])
1722   tst_connect_save_LIBS="$LIBS"
1723   tst_connect_need_LIBS="unknown"
1724   for tst_lib in '' '-lsocket' ; do
1725     if test "$tst_connect_need_LIBS" = "unknown"; then
1726       LIBS="$tst_lib $tst_connect_save_LIBS"
1727       AC_LINK_IFELSE([
1728         AC_LANG_PROGRAM([[
1729           $curl_includes_winsock2
1730           #ifndef HAVE_WINDOWS_H
1731             int connect(int, void*, int);
1732           #endif
1733         ]],[[
1734           if(0 != connect(0, 0, 0))
1735             return 1;
1736         ]])
1737       ],[
1738         tst_connect_need_LIBS="$tst_lib"
1739       ])
1740     fi
1741   done
1742   LIBS="$tst_connect_save_LIBS"
1743   #
1744   case X-"$tst_connect_need_LIBS" in
1745     X-unknown)
1746       AC_MSG_RESULT([cannot find connect])
1747       AC_MSG_ERROR([cannot find connect function in libraries.])
1748       ;;
1749     X-)
1750       AC_MSG_RESULT([yes])
1751       ;;
1752     *)
1753       AC_MSG_RESULT([$tst_connect_need_LIBS])
1754       LIBS="$tst_connect_need_LIBS $tst_connect_save_LIBS"
1755       ;;
1756   esac
1757 ])
1758
1759
1760 dnl CURL_DEFINE_UNQUOTED (VARIABLE, [VALUE])
1761 dnl -------------------------------------------------
1762 dnl Like AC_DEFINE_UNQUOTED this macro will define a C preprocessor
1763 dnl symbol that can be further used in custom template configuration
1764 dnl files. This macro, unlike AC_DEFINE_UNQUOTED, does not use a third
1765 dnl argument for the description. Symbol definitions done with this
1766 dnl macro are intended to be exclusively used in handcrafted *.h.in
1767 dnl template files. Contrary to what AC_DEFINE_UNQUOTED does, this one
1768 dnl prevents autoheader generation and insertion of symbol template
1769 dnl stub and definition into the first configuration header file. Do
1770 dnl not use this macro as a replacement for AC_DEFINE_UNQUOTED, each
1771 dnl one serves different functional needs.
1772
1773 AC_DEFUN([CURL_DEFINE_UNQUOTED], [
1774 cat >>confdefs.h <<_EOF
1775 [@%:@define] $1 ifelse($#, 2, [$2], 1)
1776 _EOF
1777 ])
1778
1779 dnl CURL_CONFIGURE_PULL_SYS_POLL
1780 dnl -------------------------------------------------
1781 dnl The need for the sys/poll.h inclusion arises mainly to properly
1782 dnl interface AIX systems which define macros 'events' and 'revents'.
1783
1784 AC_DEFUN([CURL_CONFIGURE_PULL_SYS_POLL], [
1785   AC_REQUIRE([CURL_INCLUDES_POLL])dnl
1786   #
1787   tst_poll_events_macro_defined="unknown"
1788   #
1789   AC_COMPILE_IFELSE([
1790     AC_LANG_PROGRAM([[
1791       $curl_includes_poll
1792     ]],[[
1793 #if defined(events) || defined(revents)
1794       return 0;
1795 #else
1796       force compilation error
1797 #endif
1798     ]])
1799   ],[
1800     tst_poll_events_macro_defined="yes"
1801   ],[
1802     tst_poll_events_macro_defined="no"
1803   ])
1804   #
1805   if test "$tst_poll_events_macro_defined" = "yes"; then
1806     if test "x$ac_cv_header_sys_poll_h" = "xyes"; then
1807       CURL_DEFINE_UNQUOTED([CURL_PULL_SYS_POLL_H])
1808     fi
1809   fi
1810   #
1811 ])
1812
1813
1814 dnl CURL_CHECK_FUNC_SELECT
1815 dnl -------------------------------------------------
1816 dnl Test if the socket select() function is available,
1817 dnl and check its return type and the types of its
1818 dnl arguments. If the function succeeds HAVE_SELECT
1819 dnl will be defined, defining the types of the
1820 dnl arguments in SELECT_TYPE_ARG1, SELECT_TYPE_ARG234
1821 dnl and SELECT_TYPE_ARG5, defining the type of the
1822 dnl function return value in SELECT_TYPE_RETV, and
1823 dnl also defining the type qualifier of fifth argument
1824 dnl in SELECT_QUAL_ARG5.
1825
1826 AC_DEFUN([CURL_CHECK_FUNC_SELECT], [
1827   AC_REQUIRE([CURL_CHECK_STRUCT_TIMEVAL])dnl
1828   AC_CHECK_HEADERS(sys/select.h sys/socket.h)
1829   #
1830   AC_MSG_CHECKING([for select])
1831   AC_LINK_IFELSE([
1832     AC_LANG_PROGRAM([[
1833 #undef inline
1834 #ifdef HAVE_WINDOWS_H
1835 #ifndef WIN32_LEAN_AND_MEAN
1836 #define WIN32_LEAN_AND_MEAN
1837 #endif
1838 #include <windows.h>
1839 #ifdef HAVE_WINSOCK2_H
1840 #include <winsock2.h>
1841 #else
1842 #ifdef HAVE_WINSOCK_H
1843 #include <winsock.h>
1844 #endif
1845 #endif
1846 #endif
1847 #ifdef HAVE_SYS_TYPES_H
1848 #include <sys/types.h>
1849 #endif
1850 #ifdef HAVE_SYS_TIME_H
1851 #include <sys/time.h>
1852 #ifdef TIME_WITH_SYS_TIME
1853 #include <time.h>
1854 #endif
1855 #else
1856 #ifdef HAVE_TIME_H
1857 #include <time.h>
1858 #endif
1859 #endif
1860 #ifndef HAVE_WINDOWS_H
1861 #ifdef HAVE_SYS_SELECT_H
1862 #include <sys/select.h>
1863 #endif
1864 #ifdef HAVE_SYS_SOCKET_H
1865 #include <sys/socket.h>
1866 #endif
1867 #endif
1868     ]],[[
1869       select(0, 0, 0, 0, 0);
1870     ]])
1871   ],[
1872     AC_MSG_RESULT([yes])
1873     curl_cv_select="yes"
1874   ],[
1875     AC_MSG_RESULT([no])
1876     curl_cv_select="no"
1877   ])
1878   #
1879   if test "$curl_cv_select" = "yes"; then
1880     AC_CACHE_CHECK([types of args and return type for select],
1881       [curl_cv_func_select_args], [
1882       curl_cv_func_select_args="unknown"
1883       for sel_retv in 'int' 'ssize_t'; do
1884         for sel_arg1 in 'int' 'ssize_t' 'size_t' 'unsigned long int' 'unsigned int'; do
1885           for sel_arg234 in 'fd_set *' 'int *' 'void *'; do
1886             for sel_arg5 in 'struct timeval *' 'const struct timeval *'; do
1887               if test "$curl_cv_func_select_args" = "unknown"; then
1888                 AC_COMPILE_IFELSE([
1889                   AC_LANG_PROGRAM([[
1890 #undef inline
1891 #ifdef HAVE_WINDOWS_H
1892 #ifndef WIN32_LEAN_AND_MEAN
1893 #define WIN32_LEAN_AND_MEAN
1894 #endif
1895 #include <windows.h>
1896 #ifdef HAVE_WINSOCK2_H
1897 #include <winsock2.h>
1898 #else
1899 #ifdef HAVE_WINSOCK_H
1900 #include <winsock.h>
1901 #endif
1902 #endif
1903 #define SELECTCALLCONV PASCAL
1904 #endif
1905 #ifdef HAVE_SYS_TYPES_H
1906 #include <sys/types.h>
1907 #endif
1908 #ifdef HAVE_SYS_TIME_H
1909 #include <sys/time.h>
1910 #ifdef TIME_WITH_SYS_TIME
1911 #include <time.h>
1912 #endif
1913 #else
1914 #ifdef HAVE_TIME_H
1915 #include <time.h>
1916 #endif
1917 #endif
1918 #ifndef HAVE_WINDOWS_H
1919 #ifdef HAVE_SYS_SELECT_H
1920 #include <sys/select.h>
1921 #endif
1922 #ifdef HAVE_SYS_SOCKET_H
1923 #include <sys/socket.h>
1924 #endif
1925 #define SELECTCALLCONV
1926 #endif
1927 #ifndef HAVE_STRUCT_TIMEVAL
1928                     struct timeval {
1929                       long tv_sec;
1930                       long tv_usec;
1931                     };
1932 #endif
1933                     extern $sel_retv SELECTCALLCONV
1934 #ifdef __ANDROID__
1935 __attribute__((overloadable))
1936 #endif
1937                         select($sel_arg1,
1938                                         $sel_arg234,
1939                                         $sel_arg234,
1940                                         $sel_arg234,
1941                                         $sel_arg5);
1942                   ]],[[
1943                     $sel_arg1   nfds=0;
1944                     $sel_arg234 rfds=0;
1945                     $sel_arg234 wfds=0;
1946                     $sel_arg234 efds=0;
1947                     $sel_retv res = select(nfds, rfds, wfds, efds, 0);
1948                   ]])
1949                 ],[
1950                   curl_cv_func_select_args="$sel_arg1,$sel_arg234,$sel_arg5,$sel_retv"
1951                 ])
1952               fi
1953             done
1954           done
1955         done
1956       done
1957     ]) # AC-CACHE-CHECK
1958     if test "$curl_cv_func_select_args" = "unknown"; then
1959       AC_MSG_WARN([Cannot find proper types to use for select args])
1960       AC_MSG_WARN([HAVE_SELECT will not be defined])
1961     else
1962       select_prev_IFS=$IFS; IFS=','
1963       set dummy `echo "$curl_cv_func_select_args" | sed 's/\*/\*/g'`
1964       IFS=$select_prev_IFS
1965       shift
1966       #
1967       sel_qual_type_arg5=$[3]
1968       #
1969       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG1, $[1],
1970         [Define to the type of arg 1 for select.])
1971       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG234, $[2],
1972         [Define to the type of args 2, 3 and 4 for select.])
1973       AC_DEFINE_UNQUOTED(SELECT_TYPE_RETV, $[4],
1974         [Define to the function return type for select.])
1975       #
1976       prev_sh_opts=$-
1977       #
1978       case $prev_sh_opts in
1979         *f*)
1980           ;;
1981         *)
1982           set -f
1983           ;;
1984       esac
1985       #
1986       case "$sel_qual_type_arg5" in
1987         const*)
1988           sel_qual_arg5=const
1989           sel_type_arg5=`echo $sel_qual_type_arg5 | sed 's/^const //'`
1990         ;;
1991         *)
1992           sel_qual_arg5=
1993           sel_type_arg5=$sel_qual_type_arg5
1994         ;;
1995       esac
1996       #
1997       AC_DEFINE_UNQUOTED(SELECT_QUAL_ARG5, $sel_qual_arg5,
1998         [Define to the type qualifier of arg 5 for select.])
1999       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG5, $sel_type_arg5,
2000         [Define to the type of arg 5 for select.])
2001       #
2002       case $prev_sh_opts in
2003         *f*)
2004           ;;
2005         *)
2006           set +f
2007           ;;
2008       esac
2009       #
2010       AC_DEFINE_UNQUOTED(HAVE_SELECT, 1,
2011         [Define to 1 if you have the select function.])
2012       curl_cv_func_select="yes"
2013     fi
2014   fi
2015 ])
2016
2017
2018 dnl CURL_VERIFY_RUNTIMELIBS
2019 dnl -------------------------------------------------
2020 dnl Verify that the shared libs found so far can be used when running
2021 dnl programs, since otherwise the situation will create odd configure errors
2022 dnl that are misleading people.
2023 dnl
2024 dnl Make sure this test is run BEFORE the first test in the script that
2025 dnl runs anything, which at the time of this writing is the AC_CHECK_SIZEOF
2026 dnl macro. It must also run AFTER all lib-checking macros are complete.
2027
2028 AC_DEFUN([CURL_VERIFY_RUNTIMELIBS], [
2029
2030   dnl this test is of course not sensible if we are cross-compiling!
2031   if test "x$cross_compiling" != xyes; then
2032
2033     dnl just run a program to verify that the libs checked for previous to this
2034     dnl point also is available run-time!
2035     AC_MSG_CHECKING([run-time libs availability])
2036     CURL_RUN_IFELSE([
2037 int main()
2038 {
2039   return 0;
2040 }
2041 ],
2042     AC_MSG_RESULT([fine]),
2043     AC_MSG_RESULT([failed])
2044     AC_MSG_ERROR([one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS])
2045     )
2046
2047     dnl if this test fails, configure has already stopped
2048   fi
2049 ])
2050
2051
2052 dnl CURL_CHECK_VARIADIC_MACROS
2053 dnl -------------------------------------------------
2054 dnl Check compiler support of variadic macros
2055
2056 AC_DEFUN([CURL_CHECK_VARIADIC_MACROS], [
2057   AC_CACHE_CHECK([for compiler support of C99 variadic macro style],
2058     [curl_cv_variadic_macros_c99], [
2059     AC_COMPILE_IFELSE([
2060       AC_LANG_PROGRAM([[
2061 #define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
2062 #define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
2063         int fun3(int arg1, int arg2, int arg3);
2064         int fun2(int arg1, int arg2);
2065         int fun3(int arg1, int arg2, int arg3)
2066         { return arg1 + arg2 + arg3; }
2067         int fun2(int arg1, int arg2)
2068         { return arg1 + arg2; }
2069       ]],[[
2070         int res3 = c99_vmacro3(1, 2, 3);
2071         int res2 = c99_vmacro2(1, 2);
2072       ]])
2073     ],[
2074       curl_cv_variadic_macros_c99="yes"
2075     ],[
2076       curl_cv_variadic_macros_c99="no"
2077     ])
2078   ])
2079   case "$curl_cv_variadic_macros_c99" in
2080     yes)
2081       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_C99, 1,
2082         [Define to 1 if compiler supports C99 variadic macro style.])
2083       ;;
2084   esac
2085   AC_CACHE_CHECK([for compiler support of old gcc variadic macro style],
2086     [curl_cv_variadic_macros_gcc], [
2087     AC_COMPILE_IFELSE([
2088       AC_LANG_PROGRAM([[
2089 #define gcc_vmacro3(first, args...) fun3(first, args)
2090 #define gcc_vmacro2(first, args...) fun2(first, args)
2091         int fun3(int arg1, int arg2, int arg3);
2092         int fun2(int arg1, int arg2);
2093         int fun3(int arg1, int arg2, int arg3)
2094         { return arg1 + arg2 + arg3; }
2095         int fun2(int arg1, int arg2)
2096         { return arg1 + arg2; }
2097       ]],[[
2098         int res3 = gcc_vmacro3(1, 2, 3);
2099         int res2 = gcc_vmacro2(1, 2);
2100       ]])
2101     ],[
2102       curl_cv_variadic_macros_gcc="yes"
2103     ],[
2104       curl_cv_variadic_macros_gcc="no"
2105     ])
2106   ])
2107   case "$curl_cv_variadic_macros_gcc" in
2108     yes)
2109       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_GCC, 1,
2110         [Define to 1 if compiler supports old gcc variadic macro style.])
2111       ;;
2112   esac
2113 ])
2114
2115
2116 dnl CURL_CHECK_CA_BUNDLE
2117 dnl -------------------------------------------------
2118 dnl Check if a default ca-bundle should be used
2119 dnl
2120 dnl regarding the paths this will scan:
2121 dnl /etc/ssl/certs/ca-certificates.crt Debian systems
2122 dnl /etc/pki/tls/certs/ca-bundle.crt Redhat and Mandriva
2123 dnl /usr/share/ssl/certs/ca-bundle.crt old(er) Redhat
2124 dnl /usr/local/share/certs/ca-root-nss.crt FreeBSD
2125 dnl /etc/ssl/cert.pem OpenBSD, FreeBSD (symlink)
2126 dnl /etc/ssl/certs/ (ca path) SUSE
2127
2128 AC_DEFUN([CURL_CHECK_CA_BUNDLE], [
2129
2130   AC_MSG_CHECKING([default CA cert bundle/path])
2131
2132   AC_ARG_WITH(ca-bundle,
2133 AC_HELP_STRING([--with-ca-bundle=FILE],
2134 [Path to a file containing CA certificates (example: /etc/ca-bundle.crt)])
2135 AC_HELP_STRING([--without-ca-bundle], [Don't use a default CA bundle]),
2136   [
2137     want_ca="$withval"
2138     if test "x$want_ca" = "xyes"; then
2139       AC_MSG_ERROR([--with-ca-bundle=FILE requires a path to the CA bundle])
2140     fi
2141   ],
2142   [ want_ca="unset" ])
2143   AC_ARG_WITH(ca-path,
2144 AC_HELP_STRING([--with-ca-path=DIRECTORY],
2145 [Path to a directory containing CA certificates stored individually, with \
2146 their filenames in a hash format. This option can be used with OpenSSL, \
2147 GnuTLS and PolarSSL backends. Refer to OpenSSL c_rehash for details. \
2148 (example: /etc/certificates)])
2149 AC_HELP_STRING([--without-ca-path], [Don't use a default CA path]),
2150   [
2151     want_capath="$withval"
2152     if test "x$want_capath" = "xyes"; then
2153       AC_MSG_ERROR([--with-ca-path=DIRECTORY requires a path to the CA path directory])
2154     fi
2155   ],
2156   [ want_capath="unset"])
2157
2158   ca_warning="   (warning: certs not found)"
2159   capath_warning="   (warning: certs not found)"
2160   check_capath=""
2161
2162   if test "x$want_ca" != "xno" -a "x$want_ca" != "xunset" -a \
2163           "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
2164     dnl both given
2165     ca="$want_ca"
2166     capath="$want_capath"
2167   elif test "x$want_ca" != "xno" -a "x$want_ca" != "xunset"; then
2168     dnl --with-ca-bundle given
2169     ca="$want_ca"
2170     capath="no"
2171   elif test "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
2172     dnl --with-ca-path given
2173     if test "x$OPENSSL_ENABLED" != "x1" -a "x$GNUTLS_ENABLED" != "x1" -a "x$POLARSSL_ENABLED" != "x1"; then
2174       AC_MSG_ERROR([--with-ca-path only works with OpenSSL, GnuTLS or PolarSSL])
2175     fi
2176     capath="$want_capath"
2177     ca="no"
2178   else
2179     dnl first try autodetecting a CA bundle , then a CA path
2180     dnl both autodetections can be skipped by --without-ca-*
2181     ca="no"
2182     capath="no"
2183     if test "x$cross_compiling" != "xyes"; then
2184       dnl NOT cross-compiling and...
2185       dnl neither of the --with-ca-* options are provided
2186       if test "x$want_ca" = "xunset"; then
2187         dnl the path we previously would have installed the curl ca bundle
2188         dnl to, and thus we now check for an already existing cert in that
2189         dnl place in case we find no other
2190         if test "x$prefix" != xNONE; then
2191           cac="${prefix}/share/curl/curl-ca-bundle.crt"
2192         else
2193           cac="$ac_default_prefix/share/curl/curl-ca-bundle.crt"
2194         fi
2195
2196         for a in /etc/ssl/certs/ca-certificates.crt \
2197                  /etc/pki/tls/certs/ca-bundle.crt \
2198                  /usr/share/ssl/certs/ca-bundle.crt \
2199                  /usr/local/share/certs/ca-root-nss.crt \
2200                  /etc/ssl/cert.pem \
2201                  "$cac"; do
2202           if test -f "$a"; then
2203             ca="$a"
2204             break
2205           fi
2206         done
2207       fi
2208       if test "x$want_capath" = "xunset" -a "x$ca" = "xno" -a \
2209               "x$OPENSSL_ENABLED" = "x1"; then
2210         check_capath="/etc/ssl/certs/"
2211       fi
2212     else
2213       dnl no option given and cross-compiling
2214       AC_MSG_WARN([skipped the ca-cert path detection when cross-compiling])
2215     fi
2216   fi
2217
2218   if test "x$ca" = "xno" || test -f "$ca"; then
2219     ca_warning=""
2220   fi
2221
2222   if test "x$capath" != "xno"; then
2223     check_capath="$capath"
2224   fi
2225
2226   if test ! -z "$check_capath"; then
2227     for a in "$check_capath"; do
2228       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
2229         if test "x$capath" = "xno"; then
2230           capath="$a"
2231         fi
2232         capath_warning=""
2233         break
2234       fi
2235     done
2236   fi
2237
2238   if test "x$capath" = "xno"; then
2239     capath_warning=""
2240   fi
2241
2242   if test "x$ca" != "xno"; then
2243     CURL_CA_BUNDLE='"'$ca'"'
2244     AC_DEFINE_UNQUOTED(CURL_CA_BUNDLE, "$ca", [Location of default ca bundle])
2245     AC_SUBST(CURL_CA_BUNDLE)
2246     AC_MSG_RESULT([$ca])
2247   fi
2248   if test "x$capath" != "xno"; then
2249     CURL_CA_PATH="\"$capath\""
2250     AC_DEFINE_UNQUOTED(CURL_CA_PATH, "$capath", [Location of default ca path])
2251     AC_MSG_RESULT([$capath (capath)])
2252   fi
2253   if test "x$ca" = "xno" && test "x$capath" = "xno"; then
2254     AC_MSG_RESULT([no])
2255   fi
2256
2257   AC_MSG_CHECKING([whether to use builtin CA store of SSL library])
2258   AC_ARG_WITH(ca-fallback,
2259 AC_HELP_STRING([--with-ca-fallback], [Use the built in CA store of the SSL library])
2260 AC_HELP_STRING([--without-ca-fallback], [Don't use the built in CA store of the SSL library]),
2261   [
2262     if test "x$with_ca_fallback" != "xyes" -a "x$with_ca_fallback" != "xno"; then
2263       AC_MSG_ERROR([--with-ca-fallback only allows yes or no as parameter])
2264     fi
2265   ],
2266   [ with_ca_fallback="no"])
2267   AC_MSG_RESULT([$with_ca_fallback])
2268   if test "x$with_ca_fallback" = "xyes"; then
2269     if test "x$OPENSSL_ENABLED" != "x1" -a "x$GNUTLS_ENABLED" != "x1"; then
2270       AC_MSG_ERROR([--with-ca-fallback only works with OpenSSL or GnuTLS])
2271     fi
2272     AC_DEFINE_UNQUOTED(CURL_CA_FALLBACK, 1, [define "1" to use built in CA store of SSL library ])
2273   fi
2274 ])
2275
2276 dnl CURL_CHECK_WIN32_LARGEFILE
2277 dnl -------------------------------------------------
2278 dnl Check if curl's WIN32 large file will be used
2279
2280 AC_DEFUN([CURL_CHECK_WIN32_LARGEFILE], [
2281   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
2282   AC_MSG_CHECKING([whether build target supports WIN32 file API])
2283   curl_win32_file_api="no"
2284   if test "$curl_cv_header_windows_h" = "yes"; then
2285     if test x"$enable_largefile" != "xno"; then
2286       AC_COMPILE_IFELSE([
2287         AC_LANG_PROGRAM([[
2288         ]],[[
2289 #if !defined(_WIN32_WCE) && \
2290     (defined(__MINGW32__) || \
2291     (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64))))
2292           int dummy=1;
2293 #else
2294           WIN32 large file API not supported.
2295 #endif
2296         ]])
2297       ],[
2298         curl_win32_file_api="win32_large_files"
2299       ])
2300     fi
2301     if test "$curl_win32_file_api" = "no"; then
2302       AC_COMPILE_IFELSE([
2303         AC_LANG_PROGRAM([[
2304         ]],[[
2305 #if defined(_WIN32_WCE) || defined(__MINGW32__) || defined(_MSC_VER)
2306           int dummy=1;
2307 #else
2308           WIN32 small file API not supported.
2309 #endif
2310         ]])
2311       ],[
2312         curl_win32_file_api="win32_small_files"
2313       ])
2314     fi
2315   fi
2316   case "$curl_win32_file_api" in
2317     win32_large_files)
2318       AC_MSG_RESULT([yes (large file enabled)])
2319       AC_DEFINE_UNQUOTED(USE_WIN32_LARGE_FILES, 1,
2320         [Define to 1 if you are building a Windows target with large file support.])
2321       ;;
2322     win32_small_files)
2323       AC_MSG_RESULT([yes (large file disabled)])
2324       AC_DEFINE_UNQUOTED(USE_WIN32_SMALL_FILES, 1,
2325         [Define to 1 if you are building a Windows target without large file support.])
2326       ;;
2327     *)
2328       AC_MSG_RESULT([no])
2329       ;;
2330   esac
2331 ])
2332
2333 dnl CURL_EXPORT_PCDIR ($pcdir)
2334 dnl ------------------------
2335 dnl if $pcdir is not empty, set PKG_CONFIG_LIBDIR to $pcdir and export
2336 dnl
2337 dnl we need this macro since pkg-config distinguishes among empty and unset
2338 dnl variable while checking PKG_CONFIG_LIBDIR
2339 dnl
2340
2341 AC_DEFUN([CURL_EXPORT_PCDIR], [
2342     if test -n "$1"; then
2343       PKG_CONFIG_LIBDIR="$1"
2344       export PKG_CONFIG_LIBDIR
2345     fi
2346 ])
2347
2348 dnl CURL_CHECK_PKGCONFIG ($module, [$pcdir])
2349 dnl ------------------------
2350 dnl search for the pkg-config tool. Set the PKGCONFIG variable to hold the
2351 dnl path to it, or 'no' if not found/present.
2352 dnl
2353 dnl If pkg-config is present, check that it has info about the $module or
2354 dnl return "no" anyway!
2355 dnl
2356 dnl Optionally PKG_CONFIG_LIBDIR may be given as $pcdir.
2357 dnl
2358
2359 AC_DEFUN([CURL_CHECK_PKGCONFIG], [
2360     if test -n "$PKG_CONFIG"; then
2361       PKGCONFIG="$PKG_CONFIG"
2362     else
2363       AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no],
2364         [$PATH:/usr/bin:/usr/local/bin])
2365     fi
2366
2367     if test "x$PKGCONFIG" != "xno"; then
2368       AC_MSG_CHECKING([for $1 options with pkg-config])
2369       dnl ask pkg-config about $1
2370       itexists=`CURL_EXPORT_PCDIR([$2]) dnl
2371         $PKGCONFIG --exists $1 >/dev/null 2>&1 && echo 1`
2372
2373       if test -z "$itexists"; then
2374         dnl pkg-config does not have info about the given module! set the
2375         dnl variable to 'no'
2376         PKGCONFIG="no"
2377         AC_MSG_RESULT([no])
2378       else
2379         AC_MSG_RESULT([found])
2380       fi
2381     fi
2382 ])
2383
2384
2385 dnl CURL_GENERATE_CONFIGUREHELP_PM
2386 dnl -------------------------------------------------
2387 dnl Generate test harness configurehelp.pm module, defining and
2388 dnl initializing some perl variables with values which are known
2389 dnl when the configure script runs. For portability reasons, test
2390 dnl harness needs information on how to run the C preprocessor.
2391
2392 AC_DEFUN([CURL_GENERATE_CONFIGUREHELP_PM], [
2393   AC_REQUIRE([AC_PROG_CPP])dnl
2394   tmp_cpp=`eval echo "$ac_cpp" 2>/dev/null`
2395   if test -z "$tmp_cpp"; then
2396     tmp_cpp='cpp'
2397   fi
2398   cat >./tests/configurehelp.pm <<_EOF
2399 [@%:@] This is a generated file.  Do not edit.
2400
2401 package configurehelp;
2402
2403 use strict;
2404 use warnings;
2405 use Exporter;
2406
2407 use vars qw(
2408     @ISA
2409     @EXPORT_OK
2410     \$Cpreprocessor
2411     );
2412
2413 @ISA = qw(Exporter);
2414
2415 @EXPORT_OK = qw(
2416     \$Cpreprocessor
2417     );
2418
2419 \$Cpreprocessor = '$tmp_cpp';
2420
2421 1;
2422 _EOF
2423 ])
2424
2425 dnl CURL_CPP_P
2426 dnl
2427 dnl Check if $cpp -P should be used for extract define values due to gcc 5
2428 dnl splitting up strings and defines between line outputs. gcc by default
2429 dnl (without -P) will show TEST EINVAL TEST as
2430 dnl
2431 dnl # 13 "conftest.c"
2432 dnl TEST
2433 dnl # 13 "conftest.c" 3 4
2434 dnl     22
2435 dnl # 13 "conftest.c"
2436 dnl            TEST
2437
2438 AC_DEFUN([CURL_CPP_P], [
2439   AC_MSG_CHECKING([if cpp -P is needed])
2440   AC_EGREP_CPP([TEST.*TEST], [
2441  #include <errno.h>
2442 TEST EINVAL TEST
2443   ], [cpp=no], [cpp=yes])
2444   AC_MSG_RESULT([$cpp])
2445
2446   dnl we need cpp -P so check if it works then
2447   if test "x$cpp" = "xyes"; then
2448     AC_MSG_CHECKING([if cpp -P works])
2449     OLDCPPFLAGS=$CPPFLAGS
2450     CPPFLAGS="$CPPFLAGS -P"
2451     AC_EGREP_CPP([TEST.*TEST], [
2452  #include <errno.h>
2453 TEST EINVAL TEST
2454     ], [cpp_p=yes], [cpp_p=no])
2455     AC_MSG_RESULT([$cpp_p])
2456
2457     if test "x$cpp_p" = "xno"; then
2458       AC_MSG_WARN([failed to figure out cpp -P alternative])
2459       # without -P
2460       CPPPFLAG=""
2461     else
2462       # with -P
2463       CPPPFLAG="-P"
2464     fi
2465     dnl restore CPPFLAGS
2466     CPPFLAGS=$OLDCPPFLAGS
2467   else
2468     # without -P
2469     CPPPFLAG=""
2470   fi
2471 ])
2472
2473
2474 dnl CURL_MAC_CFLAGS
2475 dnl
2476 dnl Check if -mmacosx-version-min, -miphoneos-version-min or any
2477 dnl similar are set manually, otherwise do. And set
2478 dnl -Werror=partial-availability.
2479 dnl
2480
2481 AC_DEFUN([CURL_MAC_CFLAGS], [
2482
2483   tst_cflags="no"
2484   case $host_os in
2485     darwin*)
2486       tst_cflags="yes"
2487       ;;
2488   esac
2489
2490   AC_MSG_CHECKING([for good-to-use Mac CFLAGS])
2491   AC_MSG_RESULT([$tst_cflags]);
2492
2493   if test "$tst_cflags" = "yes"; then
2494     AC_MSG_CHECKING([for *version-min in CFLAGS])
2495     min=""
2496     if test -z "$(echo $CFLAGS | grep m.*os.*-version-min)"; then
2497       min="-mmacosx-version-min=10.8"
2498       CFLAGS="$CFLAGS $min"
2499     fi
2500     if test -z "$min"; then
2501       AC_MSG_RESULT([set by user])
2502     else
2503       AC_MSG_RESULT([$min set])
2504     fi
2505
2506     old_CFLAGS=$CFLAGS
2507     CFLAGS="$CFLAGS -Werror=partial-availability"
2508     AC_MSG_CHECKING([whether $CC accepts -Werror=partial-availability])
2509     AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
2510       [AC_MSG_RESULT([yes])],
2511       [AC_MSG_RESULT([no])
2512       CFLAGS=$old_CFLAGS])
2513   fi
2514
2515 ])
2516
2517
2518 dnl CURL_SUPPORTS_BUILTIN_AVAILABLE
2519 dnl
2520 dnl Check to see if the compiler supports __builtin_available. This built-in
2521 dnl compiler function first appeared in Apple LLVM 9.0.0. It's so new that, at
2522 dnl the time this macro was written, the function was not yet documented. Its
2523 dnl purpose is to return true if the code is running under a certain OS version
2524 dnl or later.
2525
2526 AC_DEFUN([CURL_SUPPORTS_BUILTIN_AVAILABLE], [
2527   AC_MSG_CHECKING([to see if the compiler supports __builtin_available()])
2528   AC_COMPILE_IFELSE([
2529     AC_LANG_PROGRAM([[
2530 #include <stdlib.h>
2531     ]],[[
2532       if (__builtin_available(macOS 10.8, iOS 5.0, *)) {}
2533     ]])
2534   ],[
2535     AC_MSG_RESULT([yes])
2536     AC_DEFINE_UNQUOTED(HAVE_BUILTIN_AVAILABLE, 1,
2537         [Define to 1 if you have the __builtin_available function.])
2538   ],[
2539     AC_MSG_RESULT([no])
2540   ])
2541 ])