Imported Upstream version 8.5.0
[platform/upstream/curl.git] / acinclude.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 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.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 # SPDX-License-Identifier: curl
22 #
23 #***************************************************************************
24
25 dnl CURL_CHECK_DEF (SYMBOL, [INCLUDES], [SILENT])
26 dnl -------------------------------------------------
27 dnl Use the C preprocessor to find out if the given object-style symbol
28 dnl is defined and get its expansion. This macro will not use default
29 dnl includes even if no INCLUDES argument is given. This macro will run
30 dnl silently when invoked with three arguments. If the expansion would
31 dnl result in a set of double-quoted strings the returned expansion will
32 dnl actually be a single double-quoted string concatenating all them.
33
34 AC_DEFUN([CURL_CHECK_DEF], [
35   AC_REQUIRE([CURL_CPP_P])dnl
36   OLDCPPFLAGS=$CPPFLAGS
37   # CPPPFLAG comes from CURL_CPP_P
38   CPPFLAGS="$CPPFLAGS $CPPPFLAG"
39   AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
40   AS_VAR_PUSHDEF([ac_Def], [curl_cv_def_$1])dnl
41   if test -z "$SED"; then
42     AC_MSG_ERROR([SED not set. Cannot continue without SED being set.])
43   fi
44   if test -z "$GREP"; then
45     AC_MSG_ERROR([GREP not set. Cannot continue without GREP being set.])
46   fi
47   ifelse($3,,[AC_MSG_CHECKING([for preprocessor definition of $1])])
48   tmp_exp=""
49   AC_PREPROC_IFELSE([
50     AC_LANG_SOURCE(
51 ifelse($2,,,[$2])[[
52 #ifdef $1
53 CURL_DEF_TOKEN $1
54 #endif
55     ]])
56   ],[
57     tmp_exp=`eval "$ac_cpp conftest.$ac_ext" 2>/dev/null | \
58       "$GREP" CURL_DEF_TOKEN 2>/dev/null | \
59       "$SED" 's/.*CURL_DEF_TOKEN[[ ]][[ ]]*//' 2>/dev/null | \
60       "$SED" 's/[["]][[ ]]*[["]]//g' 2>/dev/null`
61     if test -z "$tmp_exp" || test "$tmp_exp" = "$1"; then
62       tmp_exp=""
63     fi
64   ])
65   if test -z "$tmp_exp"; then
66     AS_VAR_SET(ac_HaveDef, no)
67     ifelse($3,,[AC_MSG_RESULT([no])])
68   else
69     AS_VAR_SET(ac_HaveDef, yes)
70     AS_VAR_SET(ac_Def, $tmp_exp)
71     ifelse($3,,[AC_MSG_RESULT([$tmp_exp])])
72   fi
73   AS_VAR_POPDEF([ac_Def])dnl
74   AS_VAR_POPDEF([ac_HaveDef])dnl
75   CPPFLAGS=$OLDCPPFLAGS
76 ])
77
78
79 dnl CURL_CHECK_DEF_CC (SYMBOL, [INCLUDES], [SILENT])
80 dnl -------------------------------------------------
81 dnl Use the C compiler to find out only if the given symbol is defined
82 dnl or not, this can not find out its expansion. This macro will not use
83 dnl default includes even if no INCLUDES argument is given. This macro
84 dnl will run silently when invoked with three arguments.
85
86 AC_DEFUN([CURL_CHECK_DEF_CC], [
87   AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
88   ifelse($3,,[AC_MSG_CHECKING([for compiler definition of $1])])
89   AC_COMPILE_IFELSE([
90     AC_LANG_SOURCE(
91 ifelse($2,,,[$2])[[
92 int main (void)
93 {
94 #ifdef $1
95   return 0;
96 #else
97   force compilation error
98 #endif
99 }
100     ]])
101   ],[
102     tst_symbol_defined="yes"
103   ],[
104     tst_symbol_defined="no"
105   ])
106   if test "$tst_symbol_defined" = "yes"; then
107     AS_VAR_SET(ac_HaveDef, yes)
108     ifelse($3,,[AC_MSG_RESULT([yes])])
109   else
110     AS_VAR_SET(ac_HaveDef, no)
111     ifelse($3,,[AC_MSG_RESULT([no])])
112   fi
113   AS_VAR_POPDEF([ac_HaveDef])dnl
114 ])
115
116
117 dnl CURL_CHECK_LIB_XNET
118 dnl -------------------------------------------------
119 dnl Verify if X/Open network library is required.
120
121 AC_DEFUN([CURL_CHECK_LIB_XNET], [
122   AC_MSG_CHECKING([if X/Open network library is required])
123   tst_lib_xnet_required="no"
124   AC_COMPILE_IFELSE([
125     AC_LANG_SOURCE([[
126 int main (void)
127 {
128 #if defined(__hpux) && defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600)
129   return 0;
130 #elif defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)
131   return 0;
132 #else
133   force compilation error
134 #endif
135 }
136     ]])
137   ],[
138     tst_lib_xnet_required="yes"
139     LIBS="-lxnet $LIBS"
140   ])
141   AC_MSG_RESULT([$tst_lib_xnet_required])
142 ])
143
144
145 dnl CURL_CHECK_AIX_ALL_SOURCE
146 dnl -------------------------------------------------
147 dnl Provides a replacement of traditional AC_AIX with
148 dnl an uniform behavior across all autoconf versions,
149 dnl and with our own placement rules.
150
151 AC_DEFUN([CURL_CHECK_AIX_ALL_SOURCE], [
152   AH_VERBATIM([_ALL_SOURCE],
153     [/* Define to 1 if OS is AIX. */
154 #ifndef _ALL_SOURCE
155 #  undef _ALL_SOURCE
156 #endif])
157   AC_BEFORE([$0], [AC_SYS_LARGEFILE])dnl
158   AC_BEFORE([$0], [CURL_CONFIGURE_REENTRANT])dnl
159   AC_BEFORE([$0], [CURL_CONFIGURE_PULL_SYS_POLL])dnl
160   AC_MSG_CHECKING([if OS is AIX (to define _ALL_SOURCE)])
161   AC_EGREP_CPP([yes_this_is_aix],[
162 #ifdef _AIX
163    yes_this_is_aix
164 #endif
165   ],[
166     AC_MSG_RESULT([yes])
167     AC_DEFINE(_ALL_SOURCE)
168   ],[
169     AC_MSG_RESULT([no])
170   ])
171 ])
172
173
174 dnl CURL_CHECK_HEADER_WINDOWS
175 dnl -------------------------------------------------
176 dnl Check for compilable and valid windows.h header
177
178 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
179   AC_CACHE_CHECK([for windows.h], [curl_cv_header_windows_h], [
180     AC_COMPILE_IFELSE([
181       AC_LANG_PROGRAM([[
182 #undef inline
183 #ifndef WIN32_LEAN_AND_MEAN
184 #define WIN32_LEAN_AND_MEAN
185 #endif
186 #include <windows.h>
187       ]],[[
188 #if defined(__CYGWIN__) || defined(__CEGCC__)
189         HAVE_WINDOWS_H shall not be defined.
190 #else
191         int dummy=2*WINVER;
192 #endif
193       ]])
194     ],[
195       curl_cv_header_windows_h="yes"
196     ],[
197       curl_cv_header_windows_h="no"
198     ])
199   ])
200   case "$curl_cv_header_windows_h" in
201     yes)
202       AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
203         [Define to 1 if you have the windows.h header file.])
204       ;;
205   esac
206 ])
207
208
209 dnl CURL_CHECK_NATIVE_WINDOWS
210 dnl -------------------------------------------------
211 dnl Check if building a native Windows target
212
213 AC_DEFUN([CURL_CHECK_NATIVE_WINDOWS], [
214   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
215   AC_CACHE_CHECK([whether build target is a native Windows one], [curl_cv_native_windows], [
216     if test "$curl_cv_header_windows_h" = "no"; then
217       curl_cv_native_windows="no"
218     else
219       AC_COMPILE_IFELSE([
220         AC_LANG_PROGRAM([[
221         ]],[[
222 #if defined(__MINGW32__) || defined(__MINGW32CE__) || \
223    (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)))
224           int dummy=1;
225 #else
226           Not a native Windows build target.
227 #endif
228         ]])
229       ],[
230         curl_cv_native_windows="yes"
231       ],[
232         curl_cv_native_windows="no"
233       ])
234     fi
235   ])
236   AM_CONDITIONAL(DOING_NATIVE_WINDOWS, test "x$curl_cv_native_windows" = xyes)
237 ])
238
239
240 dnl CURL_CHECK_HEADER_WINSOCK2
241 dnl -------------------------------------------------
242 dnl Check for compilable and valid winsock2.h header
243
244 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
245   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
246   AC_CACHE_CHECK([for winsock2.h], [curl_cv_header_winsock2_h], [
247     AC_COMPILE_IFELSE([
248       AC_LANG_PROGRAM([[
249 #undef inline
250 #ifndef WIN32_LEAN_AND_MEAN
251 #define WIN32_LEAN_AND_MEAN
252 #endif
253 #include <windows.h>
254 #include <winsock2.h>
255       ]],[[
256 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
257         HAVE_WINSOCK2_H shall not be defined.
258 #else
259         int dummy=2*IPPROTO_ESP;
260 #endif
261       ]])
262     ],[
263       curl_cv_header_winsock2_h="yes"
264     ],[
265       curl_cv_header_winsock2_h="no"
266     ])
267   ])
268   case "$curl_cv_header_winsock2_h" in
269     yes)
270       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
271         [Define to 1 if you have the winsock2.h header file.])
272       ;;
273   esac
274 ])
275
276
277 dnl CURL_CHECK_HEADER_WS2TCPIP
278 dnl -------------------------------------------------
279 dnl Check for compilable and valid ws2tcpip.h header
280
281 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
282   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
283   AC_CACHE_CHECK([for ws2tcpip.h], [curl_cv_header_ws2tcpip_h], [
284     AC_COMPILE_IFELSE([
285       AC_LANG_PROGRAM([[
286 #undef inline
287 #ifndef WIN32_LEAN_AND_MEAN
288 #define WIN32_LEAN_AND_MEAN
289 #endif
290 #include <windows.h>
291 #include <winsock2.h>
292 #include <ws2tcpip.h>
293       ]],[[
294 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
295         HAVE_WS2TCPIP_H shall not be defined.
296 #else
297         int dummy=2*IP_PKTINFO;
298 #endif
299       ]])
300     ],[
301       curl_cv_header_ws2tcpip_h="yes"
302     ],[
303       curl_cv_header_ws2tcpip_h="no"
304     ])
305   ])
306   case "$curl_cv_header_ws2tcpip_h" in
307     yes)
308       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
309         [Define to 1 if you have the ws2tcpip.h header file.])
310       ;;
311   esac
312 ])
313
314
315 dnl CURL_CHECK_HEADER_LBER
316 dnl -------------------------------------------------
317 dnl Check for compilable and valid lber.h header,
318 dnl and check if it is needed even with ldap.h
319
320 AC_DEFUN([CURL_CHECK_HEADER_LBER], [
321   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
322   AC_CACHE_CHECK([for lber.h], [curl_cv_header_lber_h], [
323     AC_COMPILE_IFELSE([
324       AC_LANG_PROGRAM([[
325 #undef inline
326 #ifdef HAVE_WINDOWS_H
327 #ifndef WIN32_LEAN_AND_MEAN
328 #define WIN32_LEAN_AND_MEAN
329 #endif
330 #include <windows.h>
331 #else
332 #ifdef HAVE_SYS_TYPES_H
333 #include <sys/types.h>
334 #endif
335 #endif
336 #ifndef NULL
337 #define NULL (void *)0
338 #endif
339 #include <lber.h>
340       ]],[[
341         BerValue *bvp = NULL;
342         BerElement *bep = ber_init(bvp);
343         ber_free(bep, 1);
344       ]])
345     ],[
346       curl_cv_header_lber_h="yes"
347     ],[
348       curl_cv_header_lber_h="no"
349     ])
350   ])
351   if test "$curl_cv_header_lber_h" = "yes"; then
352     AC_DEFINE_UNQUOTED(HAVE_LBER_H, 1,
353       [Define to 1 if you have the lber.h header file.])
354     #
355     AC_COMPILE_IFELSE([
356       AC_LANG_PROGRAM([[
357 #undef inline
358 #ifdef HAVE_WINDOWS_H
359 #ifndef WIN32_LEAN_AND_MEAN
360 #define WIN32_LEAN_AND_MEAN
361 #endif
362 #include <windows.h>
363 #else
364 #ifdef HAVE_SYS_TYPES_H
365 #include <sys/types.h>
366 #endif
367 #endif
368 #ifndef NULL
369 #define NULL (void *)0
370 #endif
371 #ifndef LDAP_DEPRECATED
372 #define LDAP_DEPRECATED 1
373 #endif
374 #include <ldap.h>
375       ]],[[
376         BerValue *bvp = NULL;
377         BerElement *bep = ber_init(bvp);
378         ber_free(bep, 1);
379       ]])
380     ],[
381       curl_cv_need_header_lber_h="no"
382     ],[
383       curl_cv_need_header_lber_h="yes"
384     ])
385     #
386     case "$curl_cv_need_header_lber_h" in
387       yes)
388         AC_DEFINE_UNQUOTED(NEED_LBER_H, 1,
389           [Define to 1 if you need the lber.h header file even with ldap.h])
390         ;;
391     esac
392   fi
393 ])
394
395
396 dnl CURL_CHECK_HEADER_LDAP
397 dnl -------------------------------------------------
398 dnl Check for compilable and valid ldap.h header
399
400 AC_DEFUN([CURL_CHECK_HEADER_LDAP], [
401   AC_REQUIRE([CURL_CHECK_HEADER_LBER])dnl
402   AC_CACHE_CHECK([for ldap.h], [curl_cv_header_ldap_h], [
403     AC_COMPILE_IFELSE([
404       AC_LANG_PROGRAM([[
405 #undef inline
406 #ifdef HAVE_WINDOWS_H
407 #ifndef WIN32_LEAN_AND_MEAN
408 #define WIN32_LEAN_AND_MEAN
409 #endif
410 #include <windows.h>
411 #else
412 #ifdef HAVE_SYS_TYPES_H
413 #include <sys/types.h>
414 #endif
415 #endif
416 #ifndef LDAP_DEPRECATED
417 #define LDAP_DEPRECATED 1
418 #endif
419 #ifdef NEED_LBER_H
420 #include <lber.h>
421 #endif
422 #include <ldap.h>
423       ]],[[
424         LDAP *ldp = ldap_init("0.0.0.0", LDAP_PORT);
425         int res = ldap_unbind(ldp);
426       ]])
427     ],[
428       curl_cv_header_ldap_h="yes"
429     ],[
430       curl_cv_header_ldap_h="no"
431     ])
432   ])
433   case "$curl_cv_header_ldap_h" in
434     yes)
435       AC_DEFINE_UNQUOTED(HAVE_LDAP_H, 1,
436         [Define to 1 if you have the ldap.h header file.])
437       ;;
438   esac
439 ])
440
441
442 dnl CURL_CHECK_HEADER_LDAP_SSL
443 dnl -------------------------------------------------
444 dnl Check for compilable and valid ldap_ssl.h header
445
446 AC_DEFUN([CURL_CHECK_HEADER_LDAP_SSL], [
447   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
448   AC_CACHE_CHECK([for ldap_ssl.h], [curl_cv_header_ldap_ssl_h], [
449     AC_COMPILE_IFELSE([
450       AC_LANG_PROGRAM([[
451 #undef inline
452 #ifdef HAVE_WINDOWS_H
453 #ifndef WIN32_LEAN_AND_MEAN
454 #define WIN32_LEAN_AND_MEAN
455 #endif
456 #include <windows.h>
457 #else
458 #ifdef HAVE_SYS_TYPES_H
459 #include <sys/types.h>
460 #endif
461 #endif
462 #ifndef LDAP_DEPRECATED
463 #define LDAP_DEPRECATED 1
464 #endif
465 #ifdef NEED_LBER_H
466 #include <lber.h>
467 #endif
468 #ifdef HAVE_LDAP_H
469 #include <ldap.h>
470 #endif
471 #include <ldap_ssl.h>
472       ]],[[
473         LDAP *ldp = ldapssl_init("0.0.0.0", LDAPS_PORT, 1);
474       ]])
475     ],[
476       curl_cv_header_ldap_ssl_h="yes"
477     ],[
478       curl_cv_header_ldap_ssl_h="no"
479     ])
480   ])
481   case "$curl_cv_header_ldap_ssl_h" in
482     yes)
483       AC_DEFINE_UNQUOTED(HAVE_LDAP_SSL_H, 1,
484         [Define to 1 if you have the ldap_ssl.h header file.])
485       ;;
486   esac
487 ])
488
489
490 dnl CURL_CHECK_LIBS_WINLDAP
491 dnl -------------------------------------------------
492 dnl Check for libraries needed for WINLDAP support,
493 dnl and prepended to LIBS any needed libraries.
494 dnl This macro can take an optional parameter with a
495 dnl whitespace separated list of libraries to check
496 dnl before the WINLDAP default ones.
497
498 AC_DEFUN([CURL_CHECK_LIBS_WINLDAP], [
499   AC_REQUIRE([CURL_CHECK_HEADER_WINBER])dnl
500   #
501   AC_MSG_CHECKING([for WINLDAP libraries])
502   #
503   u_libs=""
504   #
505   ifelse($1,,,[
506     for x_lib in $1; do
507       case "$x_lib" in
508         -l*)
509           l_lib="$x_lib"
510           ;;
511         *)
512           l_lib="-l$x_lib"
513           ;;
514       esac
515       if test -z "$u_libs"; then
516         u_libs="$l_lib"
517       else
518         u_libs="$u_libs $l_lib"
519       fi
520     done
521   ])
522   #
523   curl_cv_save_LIBS="$LIBS"
524   curl_cv_ldap_LIBS="unknown"
525   #
526   for x_nlibs in '' "$u_libs" \
527     '-lwldap32' ; do
528     if test "$curl_cv_ldap_LIBS" = "unknown"; then
529       if test -z "$x_nlibs"; then
530         LIBS="$curl_cv_save_LIBS"
531       else
532         LIBS="$x_nlibs $curl_cv_save_LIBS"
533       fi
534       AC_LINK_IFELSE([
535         AC_LANG_PROGRAM([[
536 #undef inline
537 #ifdef HAVE_WINDOWS_H
538 #ifndef WIN32_LEAN_AND_MEAN
539 #define WIN32_LEAN_AND_MEAN
540 #endif
541 #include <windows.h>
542 #include <winldap.h>
543 #ifdef HAVE_WINBER_H
544 #include <winber.h>
545 #endif
546 #endif
547         ]],[[
548           BERVAL *bvp = NULL;
549           BerElement *bep = ber_init(bvp);
550           LDAP *ldp = ldap_init("0.0.0.0", LDAP_PORT);
551           ULONG res = ldap_unbind(ldp);
552           ber_free(bep, 1);
553         ]])
554       ],[
555         curl_cv_ldap_LIBS="$x_nlibs"
556       ])
557     fi
558   done
559   #
560   LIBS="$curl_cv_save_LIBS"
561   #
562   case X-"$curl_cv_ldap_LIBS" in
563     X-unknown)
564       AC_MSG_RESULT([cannot find WINLDAP libraries])
565       ;;
566     X-)
567       AC_MSG_RESULT([no additional lib required])
568       ;;
569     *)
570       if test -z "$curl_cv_save_LIBS"; then
571         LIBS="$curl_cv_ldap_LIBS"
572       else
573         LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
574       fi
575       AC_MSG_RESULT([$curl_cv_ldap_LIBS])
576       ;;
577   esac
578   #
579 ])
580
581
582 dnl CURL_CHECK_LIBS_LDAP
583 dnl -------------------------------------------------
584 dnl Check for libraries needed for LDAP support,
585 dnl and prepended to LIBS any needed libraries.
586 dnl This macro can take an optional parameter with a
587 dnl whitespace separated list of libraries to check
588 dnl before the default ones.
589
590 AC_DEFUN([CURL_CHECK_LIBS_LDAP], [
591   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
592   #
593   AC_MSG_CHECKING([for LDAP libraries])
594   #
595   u_libs=""
596   #
597   ifelse($1,,,[
598     for x_lib in $1; do
599       case "$x_lib" in
600         -l*)
601           l_lib="$x_lib"
602           ;;
603         *)
604           l_lib="-l$x_lib"
605           ;;
606       esac
607       if test -z "$u_libs"; then
608         u_libs="$l_lib"
609       else
610         u_libs="$u_libs $l_lib"
611       fi
612     done
613   ])
614   #
615   curl_cv_save_LIBS="$LIBS"
616   curl_cv_ldap_LIBS="unknown"
617   #
618   for x_nlibs in '' "$u_libs" \
619     '-lldap' \
620     '-lldap -llber' \
621     '-llber -lldap' \
622     '-lldapssl -lldapx -lldapsdk' \
623     '-lldapsdk -lldapx -lldapssl' \
624     '-lldap -llber -lssl -lcrypto' ; do
625
626     if test "$curl_cv_ldap_LIBS" = "unknown"; then
627       if test -z "$x_nlibs"; then
628         LIBS="$curl_cv_save_LIBS"
629       else
630         LIBS="$x_nlibs $curl_cv_save_LIBS"
631       fi
632       AC_LINK_IFELSE([
633         AC_LANG_PROGRAM([[
634 #undef inline
635 #ifdef HAVE_WINDOWS_H
636 #ifndef WIN32_LEAN_AND_MEAN
637 #define WIN32_LEAN_AND_MEAN
638 #endif
639 #include <windows.h>
640 #else
641 #ifdef HAVE_SYS_TYPES_H
642 #include <sys/types.h>
643 #endif
644 #endif
645 #ifndef NULL
646 #define NULL (void *)0
647 #endif
648 #ifndef LDAP_DEPRECATED
649 #define LDAP_DEPRECATED 1
650 #endif
651 #ifdef NEED_LBER_H
652 #include <lber.h>
653 #endif
654 #ifdef HAVE_LDAP_H
655 #include <ldap.h>
656 #endif
657         ]],[[
658           BerValue *bvp = NULL;
659           BerElement *bep = ber_init(bvp);
660           LDAP *ldp = ldap_init("0.0.0.0", LDAP_PORT);
661           int res = ldap_unbind(ldp);
662           ber_free(bep, 1);
663         ]])
664       ],[
665         curl_cv_ldap_LIBS="$x_nlibs"
666       ])
667     fi
668   done
669   #
670   LIBS="$curl_cv_save_LIBS"
671   #
672   case X-"$curl_cv_ldap_LIBS" in
673     X-unknown)
674       AC_MSG_RESULT([cannot find LDAP libraries])
675       ;;
676     X-)
677       AC_MSG_RESULT([no additional lib required])
678       ;;
679     *)
680       if test -z "$curl_cv_save_LIBS"; then
681         LIBS="$curl_cv_ldap_LIBS"
682       else
683         LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
684       fi
685       AC_MSG_RESULT([$curl_cv_ldap_LIBS])
686       ;;
687   esac
688   #
689 ])
690
691
692 dnl TYPE_SOCKADDR_STORAGE
693 dnl -------------------------------------------------
694 dnl Check for struct sockaddr_storage. Most IPv6-enabled
695 dnl hosts have it, but AIX 4.3 is one known exception.
696
697 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
698 [
699    AC_CHECK_TYPE([struct sockaddr_storage],
700         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
701                   [if struct sockaddr_storage is defined]), ,
702    [
703 #undef inline
704 #ifdef HAVE_WINDOWS_H
705 #ifndef WIN32_LEAN_AND_MEAN
706 #define WIN32_LEAN_AND_MEAN
707 #endif
708 #ifdef HAVE_WINSOCK2_H
709 #include <winsock2.h>
710 #endif
711 #include <windows.h>
712 #else
713 #ifdef HAVE_SYS_TYPES_H
714 #include <sys/types.h>
715 #endif
716 #ifdef HAVE_SYS_SOCKET_H
717 #include <sys/socket.h>
718 #endif
719 #ifdef HAVE_NETINET_IN_H
720 #include <netinet/in.h>
721 #endif
722 #ifdef HAVE_ARPA_INET_H
723 #include <arpa/inet.h>
724 #endif
725 #endif
726    ])
727 ])
728
729 dnl CURL_CHECK_FUNC_RECV
730 dnl -------------------------------------------------
731 dnl Test if the socket recv() function is available,
732
733 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
734   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
735   AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
736   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
737   #
738   AC_MSG_CHECKING([for recv])
739   AC_LINK_IFELSE([
740     AC_LANG_PROGRAM([[
741 #undef inline
742 #ifdef HAVE_WINDOWS_H
743 #ifndef WIN32_LEAN_AND_MEAN
744 #define WIN32_LEAN_AND_MEAN
745 #endif
746 #ifdef HAVE_WINSOCK2_H
747 #include <winsock2.h>
748 #endif
749 #include <windows.h>
750 #else
751 $curl_includes_bsdsocket
752 #ifdef HAVE_SYS_TYPES_H
753 #include <sys/types.h>
754 #endif
755 #ifdef HAVE_SYS_SOCKET_H
756 #include <sys/socket.h>
757 #endif
758 #endif
759     ]],[[
760       recv(0, 0, 0, 0);
761     ]])
762   ],[
763     AC_MSG_RESULT([yes])
764     curl_cv_recv="yes"
765   ],[
766     AC_MSG_RESULT([no])
767     curl_cv_recv="no"
768   ])
769   #
770   if test "$curl_cv_recv" = "yes"; then
771       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
772         [Define to 1 if you have the recv function.])
773       curl_cv_func_recv="yes"
774   else
775     AC_MSG_ERROR([Unable to link function recv])
776   fi
777 ])
778
779
780 dnl CURL_CHECK_FUNC_SEND
781 dnl -------------------------------------------------
782 dnl Test if the socket send() function is available,
783
784 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
785   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
786   AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
787   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
788   #
789   AC_MSG_CHECKING([for send])
790   AC_LINK_IFELSE([
791     AC_LANG_PROGRAM([[
792 #undef inline
793 #ifdef HAVE_WINDOWS_H
794 #ifndef WIN32_LEAN_AND_MEAN
795 #define WIN32_LEAN_AND_MEAN
796 #endif
797 #ifdef HAVE_WINSOCK2_H
798 #include <winsock2.h>
799 #endif
800 #include <windows.h>
801 #else
802 $curl_includes_bsdsocket
803 #ifdef HAVE_SYS_TYPES_H
804 #include <sys/types.h>
805 #endif
806 #ifdef HAVE_SYS_SOCKET_H
807 #include <sys/socket.h>
808 #endif
809 #endif
810     ]],[[
811       send(0, 0, 0, 0);
812     ]])
813   ],[
814     AC_MSG_RESULT([yes])
815     curl_cv_send="yes"
816   ],[
817     AC_MSG_RESULT([no])
818     curl_cv_send="no"
819   ])
820   #
821   if test "$curl_cv_send" = "yes"; then
822     AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
823       [Define to 1 if you have the send function.])
824     curl_cv_func_send="yes"
825   else
826     AC_MSG_ERROR([Unable to link function send])
827   fi
828 ])
829
830 dnl CURL_CHECK_MSG_NOSIGNAL
831 dnl -------------------------------------------------
832 dnl Check for MSG_NOSIGNAL
833
834 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
835   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
836   AC_CACHE_CHECK([for MSG_NOSIGNAL], [curl_cv_msg_nosignal], [
837     AC_COMPILE_IFELSE([
838       AC_LANG_PROGRAM([[
839 #undef inline
840 #ifdef HAVE_WINDOWS_H
841 #ifndef WIN32_LEAN_AND_MEAN
842 #define WIN32_LEAN_AND_MEAN
843 #endif
844 #ifdef HAVE_WINSOCK2_H
845 #include <winsock2.h>
846 #endif
847 #include <windows.h>
848 #else
849 #ifdef HAVE_SYS_TYPES_H
850 #include <sys/types.h>
851 #endif
852 #ifdef HAVE_SYS_SOCKET_H
853 #include <sys/socket.h>
854 #endif
855 #endif
856       ]],[[
857         int flag=MSG_NOSIGNAL;
858       ]])
859     ],[
860       curl_cv_msg_nosignal="yes"
861     ],[
862       curl_cv_msg_nosignal="no"
863     ])
864   ])
865   case "$curl_cv_msg_nosignal" in
866     yes)
867       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
868         [Define to 1 if you have the MSG_NOSIGNAL flag.])
869       ;;
870   esac
871 ])
872
873
874 dnl CURL_CHECK_STRUCT_TIMEVAL
875 dnl -------------------------------------------------
876 dnl Check for timeval struct
877
878 AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
879   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
880   AC_CHECK_HEADERS(sys/types.h sys/time.h sys/socket.h)
881   AC_CACHE_CHECK([for struct timeval], [curl_cv_struct_timeval], [
882     AC_COMPILE_IFELSE([
883       AC_LANG_PROGRAM([[
884 #undef inline
885 #ifdef HAVE_WINDOWS_H
886 #ifndef WIN32_LEAN_AND_MEAN
887 #define WIN32_LEAN_AND_MEAN
888 #endif
889 #ifdef HAVE_WINSOCK2_H
890 #include <winsock2.h>
891 #endif
892 #include <windows.h>
893 #endif
894 #ifdef HAVE_SYS_TYPES_H
895 #include <sys/types.h>
896 #endif
897 #ifdef HAVE_SYS_TIME_H
898 #include <sys/time.h>
899 #endif
900 #include <time.h>
901 #ifdef HAVE_SYS_SOCKET_H
902 #include <sys/socket.h>
903 #endif
904       ]],[[
905         struct timeval ts;
906         ts.tv_sec  = 0;
907         ts.tv_usec = 0;
908       ]])
909     ],[
910       curl_cv_struct_timeval="yes"
911     ],[
912       curl_cv_struct_timeval="no"
913     ])
914   ])
915   case "$curl_cv_struct_timeval" in
916     yes)
917       AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMEVAL, 1,
918         [Define to 1 if you have the timeval struct.])
919       ;;
920   esac
921 ])
922
923
924 dnl TYPE_IN_ADDR_T
925 dnl -------------------------------------------------
926 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
927 dnl and a few other things.
928
929 AC_DEFUN([TYPE_IN_ADDR_T], [
930   AC_CHECK_TYPE([in_addr_t], ,[
931     dnl in_addr_t not available
932     AC_CACHE_CHECK([for in_addr_t equivalent],
933       [curl_cv_in_addr_t_equiv], [
934       curl_cv_in_addr_t_equiv="unknown"
935       for t in "unsigned long" int size_t unsigned long; do
936         if test "$curl_cv_in_addr_t_equiv" = "unknown"; then
937           AC_LINK_IFELSE([
938             AC_LANG_PROGRAM([[
939 #undef inline
940 #ifdef HAVE_WINDOWS_H
941 #ifndef WIN32_LEAN_AND_MEAN
942 #define WIN32_LEAN_AND_MEAN
943 #endif
944 #ifdef HAVE_WINSOCK2_H
945 #include <winsock2.h>
946 #endif
947 #include <windows.h>
948 #else
949 #ifdef HAVE_SYS_TYPES_H
950 #include <sys/types.h>
951 #endif
952 #ifdef HAVE_SYS_SOCKET_H
953 #include <sys/socket.h>
954 #endif
955 #ifdef HAVE_NETINET_IN_H
956 #include <netinet/in.h>
957 #endif
958 #ifdef HAVE_ARPA_INET_H
959 #include <arpa/inet.h>
960 #endif
961 #endif
962             ]],[[
963               $t data = inet_addr ("1.2.3.4");
964             ]])
965           ],[
966             curl_cv_in_addr_t_equiv="$t"
967           ])
968         fi
969       done
970     ])
971     case "$curl_cv_in_addr_t_equiv" in
972       unknown)
973         AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
974         ;;
975       *)
976         AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
977           [Type to use in place of in_addr_t when system does not provide it.])
978         ;;
979     esac
980   ],[
981 #undef inline
982 #ifdef HAVE_WINDOWS_H
983 #ifndef WIN32_LEAN_AND_MEAN
984 #define WIN32_LEAN_AND_MEAN
985 #endif
986 #ifdef HAVE_WINSOCK2_H
987 #include <winsock2.h>
988 #endif
989 #include <windows.h>
990 #else
991 #ifdef HAVE_SYS_TYPES_H
992 #include <sys/types.h>
993 #endif
994 #ifdef HAVE_SYS_SOCKET_H
995 #include <sys/socket.h>
996 #endif
997 #ifdef HAVE_NETINET_IN_H
998 #include <netinet/in.h>
999 #endif
1000 #ifdef HAVE_ARPA_INET_H
1001 #include <arpa/inet.h>
1002 #endif
1003 #endif
1004   ])
1005 ])
1006
1007
1008 dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
1009 dnl -------------------------------------------------
1010 dnl Check if monotonic clock_gettime is available.
1011
1012 AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
1013   AC_CHECK_HEADERS(sys/types.h sys/time.h)
1014   AC_MSG_CHECKING([for monotonic clock_gettime])
1015   #
1016   if test "x$dontwant_rt" = "xno" ; then
1017     AC_COMPILE_IFELSE([
1018       AC_LANG_PROGRAM([[
1019 #ifdef HAVE_SYS_TYPES_H
1020 #include <sys/types.h>
1021 #endif
1022 #ifdef HAVE_SYS_TIME_H
1023 #include <sys/time.h>
1024 #endif
1025 #include <time.h>
1026       ]],[[
1027         struct timespec ts;
1028         (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1029       ]])
1030     ],[
1031       AC_MSG_RESULT([yes])
1032       curl_func_clock_gettime="yes"
1033     ],[
1034       AC_MSG_RESULT([no])
1035       curl_func_clock_gettime="no"
1036     ])
1037   fi
1038   dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally postponed
1039   dnl until library linking and run-time checks for clock_gettime succeed.
1040 ])
1041
1042 dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC_RAW
1043 dnl -------------------------------------------------
1044 dnl Check if monotonic clock_gettime is available.
1045
1046 AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC_RAW], [
1047   AC_CHECK_HEADERS(sys/types.h sys/time.h)
1048   AC_MSG_CHECKING([for raw monotonic clock_gettime])
1049   #
1050   if test "x$dontwant_rt" = "xno" ; then
1051     AC_COMPILE_IFELSE([
1052       AC_LANG_PROGRAM([[
1053 #ifdef HAVE_SYS_TYPES_H
1054 #include <sys/types.h>
1055 #endif
1056 #ifdef HAVE_SYS_TIME_H
1057 #include <sys/time.h>
1058 #endif
1059 #include <time.h>
1060       ]],[[
1061         struct timespec ts;
1062         (void)clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
1063       ]])
1064     ],[
1065       AC_MSG_RESULT([yes])
1066       AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC_RAW, 1,
1067         [Define to 1 if you have the clock_gettime function and raw monotonic timer.])
1068     ],[
1069       AC_MSG_RESULT([no])
1070     ])
1071   fi
1072 ])
1073
1074
1075 dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
1076 dnl -------------------------------------------------
1077 dnl If monotonic clock_gettime is available then,
1078 dnl check and prepended to LIBS any needed libraries.
1079
1080 AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
1081   AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
1082   #
1083   if test "$curl_func_clock_gettime" = "yes"; then
1084     #
1085     AC_MSG_CHECKING([for clock_gettime in libraries])
1086     #
1087     curl_cv_save_LIBS="$LIBS"
1088     curl_cv_gclk_LIBS="unknown"
1089     #
1090     for x_xlibs in '' '-lrt' '-lposix4' ; do
1091       if test "$curl_cv_gclk_LIBS" = "unknown"; then
1092         if test -z "$x_xlibs"; then
1093           LIBS="$curl_cv_save_LIBS"
1094         else
1095           LIBS="$x_xlibs $curl_cv_save_LIBS"
1096         fi
1097         AC_LINK_IFELSE([
1098           AC_LANG_PROGRAM([[
1099 #ifdef HAVE_SYS_TYPES_H
1100 #include <sys/types.h>
1101 #endif
1102 #ifdef HAVE_SYS_TIME_H
1103 #include <sys/time.h>
1104 #endif
1105 #include <time.h>
1106           ]],[[
1107             struct timespec ts;
1108             (void)clock_gettime(CLOCK_MONOTONIC, &ts);
1109           ]])
1110         ],[
1111           curl_cv_gclk_LIBS="$x_xlibs"
1112         ])
1113       fi
1114     done
1115     #
1116     LIBS="$curl_cv_save_LIBS"
1117     #
1118     case X-"$curl_cv_gclk_LIBS" in
1119       X-unknown)
1120         AC_MSG_RESULT([cannot find clock_gettime])
1121         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1122         curl_func_clock_gettime="no"
1123         ;;
1124       X-)
1125         AC_MSG_RESULT([no additional lib required])
1126         curl_func_clock_gettime="yes"
1127         ;;
1128       *)
1129         if test -z "$curl_cv_save_LIBS"; then
1130           LIBS="$curl_cv_gclk_LIBS"
1131         else
1132           LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
1133         fi
1134         AC_MSG_RESULT([$curl_cv_gclk_LIBS])
1135         curl_func_clock_gettime="yes"
1136         ;;
1137     esac
1138     #
1139     dnl only do runtime verification when not cross-compiling
1140     if test "x$cross_compiling" != "xyes" &&
1141       test "$curl_func_clock_gettime" = "yes"; then
1142       AC_MSG_CHECKING([if monotonic clock_gettime works])
1143       CURL_RUN_IFELSE([
1144         AC_LANG_PROGRAM([[
1145 #include <stdlib.h>
1146 #ifdef HAVE_SYS_TYPES_H
1147 #include <sys/types.h>
1148 #endif
1149 #ifdef HAVE_SYS_TIME_H
1150 #include <sys/time.h>
1151 #endif
1152 #include <time.h>
1153         ]],[[
1154           struct timespec ts;
1155           if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
1156             exit(0);
1157           else
1158             exit(1);
1159         ]])
1160       ],[
1161         AC_MSG_RESULT([yes])
1162       ],[
1163         AC_MSG_RESULT([no])
1164         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
1165         curl_func_clock_gettime="no"
1166         LIBS="$curl_cv_save_LIBS"
1167       ])
1168     fi
1169     #
1170     case "$curl_func_clock_gettime" in
1171       yes)
1172         AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
1173           [Define to 1 if you have the clock_gettime function and monotonic timer.])
1174         ;;
1175     esac
1176     #
1177   fi
1178   #
1179 ])
1180
1181
1182 dnl CURL_CHECK_LIBS_CONNECT
1183 dnl -------------------------------------------------
1184 dnl Verify if network connect function is already available
1185 dnl using current libraries or if another one is required.
1186
1187 AC_DEFUN([CURL_CHECK_LIBS_CONNECT], [
1188   AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
1189   AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
1190   AC_MSG_CHECKING([for connect in libraries])
1191   tst_connect_save_LIBS="$LIBS"
1192   tst_connect_need_LIBS="unknown"
1193   for tst_lib in '' '-lsocket' ; do
1194     if test "$tst_connect_need_LIBS" = "unknown"; then
1195       LIBS="$tst_lib $tst_connect_save_LIBS"
1196       AC_LINK_IFELSE([
1197         AC_LANG_PROGRAM([[
1198           $curl_includes_winsock2
1199           $curl_includes_bsdsocket
1200           #if !defined(HAVE_WINDOWS_H) && !defined(HAVE_PROTO_BSDSOCKET_H)
1201             int connect(int, void*, int);
1202           #endif
1203         ]],[[
1204           if(0 != connect(0, 0, 0))
1205             return 1;
1206         ]])
1207       ],[
1208         tst_connect_need_LIBS="$tst_lib"
1209       ])
1210     fi
1211   done
1212   LIBS="$tst_connect_save_LIBS"
1213   #
1214   case X-"$tst_connect_need_LIBS" in
1215     X-unknown)
1216       AC_MSG_RESULT([cannot find connect])
1217       AC_MSG_ERROR([cannot find connect function in libraries.])
1218       ;;
1219     X-)
1220       AC_MSG_RESULT([yes])
1221       ;;
1222     *)
1223       AC_MSG_RESULT([$tst_connect_need_LIBS])
1224       LIBS="$tst_connect_need_LIBS $tst_connect_save_LIBS"
1225       ;;
1226   esac
1227 ])
1228
1229
1230 dnl CURL_DEFINE_UNQUOTED (VARIABLE, [VALUE])
1231 dnl -------------------------------------------------
1232 dnl Like AC_DEFINE_UNQUOTED this macro will define a C preprocessor
1233 dnl symbol that can be further used in custom template configuration
1234 dnl files. This macro, unlike AC_DEFINE_UNQUOTED, does not use a third
1235 dnl argument for the description. Symbol definitions done with this
1236 dnl macro are intended to be exclusively used in handcrafted *.h.in
1237 dnl template files. Contrary to what AC_DEFINE_UNQUOTED does, this one
1238 dnl prevents autoheader generation and insertion of symbol template
1239 dnl stub and definition into the first configuration header file. Do
1240 dnl not use this macro as a replacement for AC_DEFINE_UNQUOTED, each
1241 dnl one serves different functional needs.
1242
1243 AC_DEFUN([CURL_DEFINE_UNQUOTED], [
1244 cat >>confdefs.h <<_EOF
1245 [@%:@define] $1 ifelse($#, 2, [$2], 1)
1246 _EOF
1247 ])
1248
1249 dnl CURL_CONFIGURE_PULL_SYS_POLL
1250 dnl -------------------------------------------------
1251 dnl The need for the sys/poll.h inclusion arises mainly to properly
1252 dnl interface AIX systems which define macros 'events' and 'revents'.
1253
1254 AC_DEFUN([CURL_CONFIGURE_PULL_SYS_POLL], [
1255   AC_REQUIRE([CURL_INCLUDES_POLL])dnl
1256   #
1257   tst_poll_events_macro_defined="unknown"
1258   #
1259   AC_COMPILE_IFELSE([
1260     AC_LANG_PROGRAM([[
1261       $curl_includes_poll
1262     ]],[[
1263 #if defined(events) || defined(revents)
1264       return 0;
1265 #else
1266       force compilation error
1267 #endif
1268     ]])
1269   ],[
1270     tst_poll_events_macro_defined="yes"
1271   ],[
1272     tst_poll_events_macro_defined="no"
1273   ])
1274   #
1275   if test "$tst_poll_events_macro_defined" = "yes"; then
1276     if test "x$ac_cv_header_sys_poll_h" = "xyes"; then
1277       CURL_DEFINE_UNQUOTED([CURL_PULL_SYS_POLL_H])
1278     fi
1279   fi
1280   #
1281 ])
1282
1283
1284 dnl CURL_CHECK_FUNC_SELECT
1285 dnl -------------------------------------------------
1286 dnl Test if the socket select() function is available.
1287
1288 AC_DEFUN([CURL_CHECK_FUNC_SELECT], [
1289   AC_REQUIRE([CURL_CHECK_STRUCT_TIMEVAL])dnl
1290   AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
1291   AC_CHECK_HEADERS(sys/select.h sys/socket.h)
1292   #
1293   AC_MSG_CHECKING([for select])
1294   AC_LINK_IFELSE([
1295     AC_LANG_PROGRAM([[
1296 #undef inline
1297 #ifdef HAVE_WINDOWS_H
1298 #ifndef WIN32_LEAN_AND_MEAN
1299 #define WIN32_LEAN_AND_MEAN
1300 #endif
1301 #ifdef HAVE_WINSOCK2_H
1302 #include <winsock2.h>
1303 #endif
1304 #include <windows.h>
1305 #endif
1306 #ifdef HAVE_SYS_TYPES_H
1307 #include <sys/types.h>
1308 #endif
1309 #ifdef HAVE_SYS_TIME_H
1310 #include <sys/time.h>
1311 #endif
1312 #include <time.h>
1313 #ifndef HAVE_WINDOWS_H
1314 #ifdef HAVE_SYS_SELECT_H
1315 #include <sys/select.h>
1316 #elif defined(HAVE_UNISTD_H)
1317 #include <unistd.h>
1318 #endif
1319 #ifdef HAVE_SYS_SOCKET_H
1320 #include <sys/socket.h>
1321 #endif
1322 $curl_includes_bsdsocket
1323 #endif
1324     ]],[[
1325       select(0, 0, 0, 0, 0);
1326     ]])
1327   ],[
1328     AC_MSG_RESULT([yes])
1329     curl_cv_select="yes"
1330   ],[
1331     AC_MSG_RESULT([no])
1332     curl_cv_select="no"
1333   ])
1334   #
1335   if test "$curl_cv_select" = "yes"; then
1336     AC_DEFINE_UNQUOTED(HAVE_SELECT, 1,
1337       [Define to 1 if you have the select function.])
1338     curl_cv_func_select="yes"
1339   fi
1340 ])
1341
1342
1343 dnl CURL_VERIFY_RUNTIMELIBS
1344 dnl -------------------------------------------------
1345 dnl Verify that the shared libs found so far can be used when running
1346 dnl programs, since otherwise the situation will create odd configure errors
1347 dnl that are misleading people.
1348 dnl
1349 dnl Make sure this test is run BEFORE the first test in the script that
1350 dnl runs anything, which at the time of this writing is the AC_CHECK_SIZEOF
1351 dnl macro. It must also run AFTER all lib-checking macros are complete.
1352
1353 AC_DEFUN([CURL_VERIFY_RUNTIMELIBS], [
1354
1355   dnl this test is of course not sensible if we are cross-compiling!
1356   if test "x$cross_compiling" != xyes; then
1357
1358     dnl just run a program to verify that the libs checked for previous to this
1359     dnl point also is available run-time!
1360     AC_MSG_CHECKING([run-time libs availability])
1361     CURL_RUN_IFELSE([
1362 int main()
1363 {
1364   return 0;
1365 }
1366 ],
1367     AC_MSG_RESULT([fine]),
1368     AC_MSG_RESULT([failed])
1369     AC_MSG_ERROR([one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS])
1370     )
1371
1372     dnl if this test fails, configure has already stopped
1373   fi
1374 ])
1375
1376
1377 dnl CURL_CHECK_CA_BUNDLE
1378 dnl -------------------------------------------------
1379 dnl Check if a default ca-bundle should be used
1380 dnl
1381 dnl regarding the paths this will scan:
1382 dnl /etc/ssl/certs/ca-certificates.crt Debian systems
1383 dnl /etc/pki/tls/certs/ca-bundle.crt Redhat and Mandriva
1384 dnl /usr/share/ssl/certs/ca-bundle.crt old(er) Redhat
1385 dnl /usr/local/share/certs/ca-root-nss.crt MidnightBSD
1386 dnl /etc/ssl/cert.pem OpenBSD, MidnightBSD (symlink)
1387 dnl /etc/ssl/certs (CA path) SUSE, FreeBSD
1388
1389 AC_DEFUN([CURL_CHECK_CA_BUNDLE], [
1390
1391   AC_MSG_CHECKING([default CA cert bundle/path])
1392
1393   AC_ARG_WITH(ca-bundle,
1394 AS_HELP_STRING([--with-ca-bundle=FILE],
1395 [Path to a file containing CA certificates (example: /etc/ca-bundle.crt)])
1396 AS_HELP_STRING([--without-ca-bundle], [Don't use a default CA bundle]),
1397   [
1398     want_ca="$withval"
1399     if test "x$want_ca" = "xyes"; then
1400       AC_MSG_ERROR([--with-ca-bundle=FILE requires a path to the CA bundle])
1401     fi
1402   ],
1403   [ want_ca="unset" ])
1404   AC_ARG_WITH(ca-path,
1405 AS_HELP_STRING([--with-ca-path=DIRECTORY],
1406 [Path to a directory containing CA certificates stored individually, with \
1407 their filenames in a hash format. This option can be used with the OpenSSL, \
1408 GnuTLS, mbedTLS and wolfSSL backends. Refer to OpenSSL c_rehash for details. \
1409 (example: /etc/certificates)])
1410 AS_HELP_STRING([--without-ca-path], [Don't use a default CA path]),
1411   [
1412     want_capath="$withval"
1413     if test "x$want_capath" = "xyes"; then
1414       AC_MSG_ERROR([--with-ca-path=DIRECTORY requires a path to the CA path directory])
1415     fi
1416   ],
1417   [ want_capath="unset"])
1418
1419   ca_warning="   (warning: certs not found)"
1420   capath_warning="   (warning: certs not found)"
1421   check_capath=""
1422
1423   if test "x$want_ca" != "xno" -a "x$want_ca" != "xunset" -a \
1424           "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
1425     dnl both given
1426     ca="$want_ca"
1427     capath="$want_capath"
1428   elif test "x$want_ca" != "xno" -a "x$want_ca" != "xunset"; then
1429     dnl --with-ca-bundle given
1430     ca="$want_ca"
1431     capath="no"
1432   elif test "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
1433     dnl --with-ca-path given
1434     if test "x$OPENSSL_ENABLED" != "x1" -a \
1435             "x$GNUTLS_ENABLED" != "x1" -a \
1436             "x$MBEDTLS_ENABLED" != "x1" -a \
1437             "x$WOLFSSL_ENABLED" != "x1"; then
1438       AC_MSG_ERROR([--with-ca-path only works with OpenSSL, GnuTLS, mbedTLS or wolfSSL])
1439     fi
1440     capath="$want_capath"
1441     ca="no"
1442   else
1443     dnl first try autodetecting a CA bundle , then a CA path
1444     dnl both autodetections can be skipped by --without-ca-*
1445     ca="no"
1446     capath="no"
1447     if test "x$cross_compiling" != "xyes"; then
1448       dnl NOT cross-compiling and...
1449       dnl neither of the --with-ca-* options are provided
1450       if test "x$want_ca" = "xunset"; then
1451         dnl the path we previously would have installed the curl ca bundle
1452         dnl to, and thus we now check for an already existing cert in that
1453         dnl place in case we find no other
1454         if test "x$prefix" != xNONE; then
1455           cac="${prefix}/share/curl/curl-ca-bundle.crt"
1456         else
1457           cac="$ac_default_prefix/share/curl/curl-ca-bundle.crt"
1458         fi
1459
1460         for a in /etc/ssl/certs/ca-certificates.crt \
1461                  /etc/pki/tls/certs/ca-bundle.crt \
1462                  /usr/share/ssl/certs/ca-bundle.crt \
1463                  /usr/local/share/certs/ca-root-nss.crt \
1464                  /etc/ssl/cert.pem \
1465                  "$cac"; do
1466           if test -f "$a"; then
1467             ca="$a"
1468             break
1469           fi
1470         done
1471       fi
1472       AC_MSG_NOTICE([want $want_capath ca $ca])
1473       if test "x$want_capath" = "xunset"; then
1474         if test "x$OPENSSL_ENABLED" = "x1" -o \
1475                 "x$GNUTLS_ENABLED" = "x1" -o \
1476                 "x$MBEDTLS_ENABLED" = "x1" -o \
1477                 "x$WOLFSSL_ENABLED" = "x1"; then
1478           check_capath="/etc/ssl/certs"
1479         fi
1480       fi
1481     else
1482       dnl no option given and cross-compiling
1483       AC_MSG_WARN([skipped the ca-cert path detection when cross-compiling])
1484     fi
1485   fi
1486
1487   if test "x$ca" = "xno" || test -f "$ca"; then
1488     ca_warning=""
1489   fi
1490
1491   if test "x$capath" != "xno"; then
1492     check_capath="$capath"
1493   fi
1494
1495   if test ! -z "$check_capath"; then
1496     for a in "$check_capath"; do
1497       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
1498         if test "x$capath" = "xno"; then
1499           capath="$a"
1500         fi
1501         capath_warning=""
1502         break
1503       fi
1504     done
1505   fi
1506
1507   if test "x$capath" = "xno"; then
1508     capath_warning=""
1509   fi
1510
1511   if test "x$ca" != "xno"; then
1512     CURL_CA_BUNDLE='"'$ca'"'
1513     AC_DEFINE_UNQUOTED(CURL_CA_BUNDLE, "$ca", [Location of default ca bundle])
1514     AC_SUBST(CURL_CA_BUNDLE)
1515     AC_MSG_RESULT([$ca])
1516   fi
1517   if test "x$capath" != "xno"; then
1518     CURL_CA_PATH="\"$capath\""
1519     AC_DEFINE_UNQUOTED(CURL_CA_PATH, "$capath", [Location of default ca path])
1520     AC_MSG_RESULT([$capath (capath)])
1521   fi
1522   if test "x$ca" = "xno" && test "x$capath" = "xno"; then
1523     AC_MSG_RESULT([no])
1524   fi
1525
1526   AC_MSG_CHECKING([whether to use builtin CA store of SSL library])
1527   AC_ARG_WITH(ca-fallback,
1528 AS_HELP_STRING([--with-ca-fallback], [Use the built in CA store of the SSL library])
1529 AS_HELP_STRING([--without-ca-fallback], [Don't use the built in CA store of the SSL library]),
1530   [
1531     if test "x$with_ca_fallback" != "xyes" -a "x$with_ca_fallback" != "xno"; then
1532       AC_MSG_ERROR([--with-ca-fallback only allows yes or no as parameter])
1533     fi
1534   ],
1535   [ with_ca_fallback="no"])
1536   AC_MSG_RESULT([$with_ca_fallback])
1537   if test "x$with_ca_fallback" = "xyes"; then
1538     if test "x$OPENSSL_ENABLED" != "x1" -a "x$GNUTLS_ENABLED" != "x1"; then
1539       AC_MSG_ERROR([--with-ca-fallback only works with OpenSSL or GnuTLS])
1540     fi
1541     AC_DEFINE_UNQUOTED(CURL_CA_FALLBACK, 1, [define "1" to use built in CA store of SSL library ])
1542   fi
1543 ])
1544
1545 dnl CURL_CHECK_WIN32_LARGEFILE
1546 dnl -------------------------------------------------
1547 dnl Check if curl's WIN32 large file will be used
1548
1549 AC_DEFUN([CURL_CHECK_WIN32_LARGEFILE], [
1550   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
1551   AC_MSG_CHECKING([whether build target supports WIN32 file API])
1552   curl_win32_file_api="no"
1553   if test "$curl_cv_header_windows_h" = "yes"; then
1554     if test x"$enable_largefile" != "xno"; then
1555       AC_COMPILE_IFELSE([
1556         AC_LANG_PROGRAM([[
1557         ]],[[
1558 #if !defined(_WIN32_WCE) && \
1559     (defined(__MINGW32__) || \
1560     (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64))))
1561           int dummy=1;
1562 #else
1563           WIN32 large file API not supported.
1564 #endif
1565         ]])
1566       ],[
1567         curl_win32_file_api="win32_large_files"
1568       ])
1569     fi
1570     if test "$curl_win32_file_api" = "no"; then
1571       AC_COMPILE_IFELSE([
1572         AC_LANG_PROGRAM([[
1573         ]],[[
1574 #if defined(_WIN32_WCE) || defined(__MINGW32__) || defined(_MSC_VER)
1575           int dummy=1;
1576 #else
1577           WIN32 small file API not supported.
1578 #endif
1579         ]])
1580       ],[
1581         curl_win32_file_api="win32_small_files"
1582       ])
1583     fi
1584   fi
1585   case "$curl_win32_file_api" in
1586     win32_large_files)
1587       AC_MSG_RESULT([yes (large file enabled)])
1588       AC_DEFINE_UNQUOTED(USE_WIN32_LARGE_FILES, 1,
1589         [Define to 1 if you are building a Windows target with large file support.])
1590       AC_SUBST(USE_WIN32_LARGE_FILES, [1])
1591       ;;
1592     win32_small_files)
1593       AC_MSG_RESULT([yes (large file disabled)])
1594       AC_DEFINE_UNQUOTED(USE_WIN32_SMALL_FILES, 1,
1595         [Define to 1 if you are building a Windows target without large file support.])
1596       AC_SUBST(USE_WIN32_SMALL_FILES, [1])
1597       ;;
1598     *)
1599       AC_MSG_RESULT([no])
1600       ;;
1601   esac
1602 ])
1603
1604 dnl CURL_CHECK_WIN32_CRYPTO
1605 dnl -------------------------------------------------
1606 dnl Check if curl's WIN32 crypto lib can be used
1607
1608 AC_DEFUN([CURL_CHECK_WIN32_CRYPTO], [
1609   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
1610   AC_MSG_CHECKING([whether build target supports WIN32 crypto API])
1611   curl_win32_crypto_api="no"
1612   if test "$curl_cv_header_windows_h" = "yes"; then
1613     AC_COMPILE_IFELSE([
1614       AC_LANG_PROGRAM([[
1615 #undef inline
1616 #ifndef WIN32_LEAN_AND_MEAN
1617 #define WIN32_LEAN_AND_MEAN
1618 #endif
1619 #include <windows.h>
1620 #include <wincrypt.h>
1621       ]],[[
1622         HCRYPTPROV hCryptProv;
1623         if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
1624                                CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
1625           CryptReleaseContext(hCryptProv, 0);
1626         }
1627       ]])
1628     ],[
1629       curl_win32_crypto_api="yes"
1630     ])
1631   fi
1632   case "$curl_win32_crypto_api" in
1633     yes)
1634       AC_MSG_RESULT([yes])
1635       AC_DEFINE_UNQUOTED(USE_WIN32_CRYPTO, 1,
1636         [Define to 1 if you are building a Windows target with crypto API support.])
1637       AC_SUBST(USE_WIN32_CRYPTO, [1])
1638       ;;
1639     *)
1640       AC_MSG_RESULT([no])
1641       ;;
1642   esac
1643 ])
1644
1645 dnl CURL_EXPORT_PCDIR ($pcdir)
1646 dnl ------------------------
1647 dnl if $pcdir is not empty, set PKG_CONFIG_LIBDIR to $pcdir and export
1648 dnl
1649 dnl we need this macro since pkg-config distinguishes among empty and unset
1650 dnl variable while checking PKG_CONFIG_LIBDIR
1651 dnl
1652
1653 AC_DEFUN([CURL_EXPORT_PCDIR], [
1654     if test -n "$1"; then
1655       PKG_CONFIG_LIBDIR="$1"
1656       export PKG_CONFIG_LIBDIR
1657     fi
1658 ])
1659
1660 dnl CURL_CHECK_PKGCONFIG ($module, [$pcdir])
1661 dnl ------------------------
1662 dnl search for the pkg-config tool. Set the PKGCONFIG variable to hold the
1663 dnl path to it, or 'no' if not found/present.
1664 dnl
1665 dnl If pkg-config is present, check that it has info about the $module or
1666 dnl return "no" anyway!
1667 dnl
1668 dnl Optionally PKG_CONFIG_LIBDIR may be given as $pcdir.
1669 dnl
1670
1671 AC_DEFUN([CURL_CHECK_PKGCONFIG], [
1672     if test -n "$PKG_CONFIG"; then
1673       PKGCONFIG="$PKG_CONFIG"
1674     else
1675       AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no],
1676         [$PATH:/usr/bin:/usr/local/bin])
1677     fi
1678
1679     if test "x$PKGCONFIG" != "xno"; then
1680       AC_MSG_CHECKING([for $1 options with pkg-config])
1681       dnl ask pkg-config about $1
1682       itexists=`CURL_EXPORT_PCDIR([$2]) dnl
1683         $PKGCONFIG --exists $1 >/dev/null 2>&1 && echo 1`
1684
1685       if test -z "$itexists"; then
1686         dnl pkg-config does not have info about the given module! set the
1687         dnl variable to 'no'
1688         PKGCONFIG="no"
1689         AC_MSG_RESULT([no])
1690       else
1691         AC_MSG_RESULT([found])
1692       fi
1693     fi
1694 ])
1695
1696
1697 dnl CURL_GENERATE_CONFIGUREHELP_PM
1698 dnl -------------------------------------------------
1699 dnl Generate test harness configurehelp.pm module, defining and
1700 dnl initializing some perl variables with values which are known
1701 dnl when the configure script runs. For portability reasons, test
1702 dnl harness needs information on how to run the C preprocessor.
1703
1704 AC_DEFUN([CURL_GENERATE_CONFIGUREHELP_PM], [
1705   AC_REQUIRE([AC_PROG_CPP])dnl
1706   tmp_cpp=`eval echo "$ac_cpp" 2>/dev/null`
1707   if test -z "$tmp_cpp"; then
1708     tmp_cpp='cpp'
1709   fi
1710   cat >./tests/configurehelp.pm <<_EOF
1711 [@%:@] This is a generated file.  Do not edit.
1712
1713 package configurehelp;
1714
1715 use strict;
1716 use warnings;
1717 use Exporter;
1718
1719 use vars qw(
1720     @ISA
1721     @EXPORT_OK
1722     \$Cpreprocessor
1723     );
1724
1725 @ISA = qw(Exporter);
1726
1727 @EXPORT_OK = qw(
1728     \$Cpreprocessor
1729     );
1730
1731 \$Cpreprocessor = '$tmp_cpp';
1732
1733 1;
1734 _EOF
1735 ])
1736
1737 dnl CURL_CPP_P
1738 dnl
1739 dnl Check if $cpp -P should be used for extract define values due to gcc 5
1740 dnl splitting up strings and defines between line outputs. gcc by default
1741 dnl (without -P) will show TEST EINVAL TEST as
1742 dnl
1743 dnl # 13 "conftest.c"
1744 dnl TEST
1745 dnl # 13 "conftest.c" 3 4
1746 dnl     22
1747 dnl # 13 "conftest.c"
1748 dnl            TEST
1749
1750 AC_DEFUN([CURL_CPP_P], [
1751   AC_MSG_CHECKING([if cpp -P is needed])
1752   AC_EGREP_CPP([TEST.*TEST], [
1753  #include <errno.h>
1754 TEST EINVAL TEST
1755   ], [cpp=no], [cpp=yes])
1756   AC_MSG_RESULT([$cpp])
1757
1758   dnl we need cpp -P so check if it works then
1759   if test "x$cpp" = "xyes"; then
1760     AC_MSG_CHECKING([if cpp -P works])
1761     OLDCPPFLAGS=$CPPFLAGS
1762     CPPFLAGS="$CPPFLAGS -P"
1763     AC_EGREP_CPP([TEST.*TEST], [
1764  #include <errno.h>
1765 TEST EINVAL TEST
1766     ], [cpp_p=yes], [cpp_p=no])
1767     AC_MSG_RESULT([$cpp_p])
1768
1769     if test "x$cpp_p" = "xno"; then
1770       AC_MSG_WARN([failed to figure out cpp -P alternative])
1771       # without -P
1772       CPPPFLAG=""
1773     else
1774       # with -P
1775       CPPPFLAG="-P"
1776     fi
1777     dnl restore CPPFLAGS
1778     CPPFLAGS=$OLDCPPFLAGS
1779   else
1780     # without -P
1781     CPPPFLAG=""
1782   fi
1783 ])
1784
1785
1786 dnl CURL_DARWIN_CFLAGS
1787 dnl
1788 dnl Set -Werror=partial-availability to detect possible breaking code
1789 dnl with very low deployment targets.
1790 dnl
1791
1792 AC_DEFUN([CURL_DARWIN_CFLAGS], [
1793
1794   tst_cflags="no"
1795   case $host_os in
1796     darwin*)
1797       tst_cflags="yes"
1798       ;;
1799   esac
1800
1801   AC_MSG_CHECKING([for good-to-use Darwin CFLAGS])
1802   AC_MSG_RESULT([$tst_cflags]);
1803
1804   if test "$tst_cflags" = "yes"; then
1805     old_CFLAGS=$CFLAGS
1806     CFLAGS="$CFLAGS -Werror=partial-availability"
1807     AC_MSG_CHECKING([whether $CC accepts -Werror=partial-availability])
1808     AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1809       [AC_MSG_RESULT([yes])],
1810       [AC_MSG_RESULT([no])
1811       CFLAGS=$old_CFLAGS])
1812   fi
1813
1814 ])
1815
1816
1817 dnl CURL_SUPPORTS_BUILTIN_AVAILABLE
1818 dnl
1819 dnl Check to see if the compiler supports __builtin_available. This built-in
1820 dnl compiler function first appeared in Apple LLVM 9.0.0. It's so new that, at
1821 dnl the time this macro was written, the function was not yet documented. Its
1822 dnl purpose is to return true if the code is running under a certain OS version
1823 dnl or later.
1824
1825 AC_DEFUN([CURL_SUPPORTS_BUILTIN_AVAILABLE], [
1826   AC_MSG_CHECKING([to see if the compiler supports __builtin_available()])
1827   AC_COMPILE_IFELSE([
1828     AC_LANG_PROGRAM([[
1829 #include <stdlib.h>
1830     ]],[[
1831       if (__builtin_available(macOS 10.8, iOS 5.0, *)) {}
1832     ]])
1833   ],[
1834     AC_MSG_RESULT([yes])
1835     AC_DEFINE_UNQUOTED(HAVE_BUILTIN_AVAILABLE, 1,
1836         [Define to 1 if you have the __builtin_available function.])
1837   ],[
1838     AC_MSG_RESULT([no])
1839   ])
1840 ])