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