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