1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at http://curl.haxx.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21#***************************************************************************
22
23# File version for 'aclocal' use. Keep it a single number.
24# serial 14
25
26dnl CURL_CHECK_OPTION_THREADED_RESOLVER
27dnl -------------------------------------------------
28dnl Verify if configure has been invoked with option
29dnl --enable-threaded-resolver or --disable-threaded-resolver, and
30dnl set shell variable want_thres as appropriate.
31
32AC_DEFUN([CURL_CHECK_OPTION_THREADED_RESOLVER], [
33  AC_MSG_CHECKING([whether to enable the threaded resolver])
34  OPT_THRES="default"
35  AC_ARG_ENABLE(threaded_resolver,
36AC_HELP_STRING([--enable-threaded-resolver],[Enable threaded resolver])
37AC_HELP_STRING([--disable-threaded-resolver],[Disable threaded resolver]),
38  OPT_THRES=$enableval)
39  case "$OPT_THRES" in
40    yes)
41      dnl --enable-threaded-resolver option used
42      want_thres="yes"
43      ;;
44    *)
45      dnl configure option not specified
46      want_thres="no"
47      ;;
48  esac
49  AC_MSG_RESULT([$want_thres])
50])
51
52dnl CURL_CHECK_OPTION_ARES
53dnl -------------------------------------------------
54dnl Verify if configure has been invoked with option
55dnl --enable-ares or --disable-ares, and
56dnl set shell variable want_ares as appropriate.
57
58AC_DEFUN([CURL_CHECK_OPTION_ARES], [
59dnl   AC_BEFORE([$0],[CURL_CHECK_OPTION_THREADS])dnl
60  AC_BEFORE([$0],[CURL_CHECK_LIB_ARES])dnl
61  AC_MSG_CHECKING([whether to enable c-ares for DNS lookups])
62  OPT_ARES="default"
63  AC_ARG_ENABLE(ares,
64AC_HELP_STRING([--enable-ares@<:@=PATH@:>@],[Enable c-ares for DNS lookups])
65AC_HELP_STRING([--disable-ares],[Disable c-ares for DNS lookups]),
66  OPT_ARES=$enableval)
67  case "$OPT_ARES" in
68    no)
69      dnl --disable-ares option used
70      want_ares="no"
71      ;;
72    default)
73      dnl configure option not specified
74      want_ares="no"
75      ;;
76    *)
77      dnl --enable-ares option used
78      want_ares="yes"
79      if test -n "$enableval" && test "$enableval" != "yes"; then
80        want_ares_path="$enableval"
81      fi
82      ;;
83  esac
84  AC_MSG_RESULT([$want_ares])
85])
86
87
88dnl CURL_CHECK_OPTION_CURLDEBUG
89dnl -------------------------------------------------
90dnl Verify if configure has been invoked with option
91dnl --enable-curldebug or --disable-curldebug, and set
92dnl shell variable want_curldebug value as appropriate.
93
94AC_DEFUN([CURL_CHECK_OPTION_CURLDEBUG], [
95  AC_BEFORE([$0],[CURL_CHECK_CURLDEBUG])dnl
96  AC_MSG_CHECKING([whether to enable curl debug memory tracking])
97  OPT_CURLDEBUG_BUILD="default"
98  AC_ARG_ENABLE(curldebug,
99AC_HELP_STRING([--enable-curldebug],[Enable curl debug memory tracking])
100AC_HELP_STRING([--disable-curldebug],[Disable curl debug memory tracking]),
101  OPT_CURLDEBUG_BUILD=$enableval)
102  case "$OPT_CURLDEBUG_BUILD" in
103    no)
104      dnl --disable-curldebug option used
105      want_curldebug="no"
106      AC_MSG_RESULT([no])
107      ;;
108    default)
109      dnl configure's curldebug option not specified. Initially we will
110      dnl handle this as a a request to use the same setting as option
111      dnl --enable-debug. IOW, initially, for debug-enabled builds
112      dnl this will be handled as a request to enable curldebug if
113      dnl possible, and for debug-disabled builds this will be handled
114      dnl as a request to disable curldebug.
115      if test "$want_debug" = "yes"; then
116        AC_MSG_RESULT([(assumed) yes])
117      else
118        AC_MSG_RESULT([no])
119      fi
120      want_curldebug_assumed="yes"
121      want_curldebug="$want_debug"
122      ;;
123    *)
124      dnl --enable-curldebug option used.
125      dnl The use of this option value is a request to enable curl's
126      dnl debug memory tracking for the libcurl library. This can only
127      dnl be done when some requisites are simultaneously satisfied.
128      dnl Later on, these requisites are verified and if they are not
129      dnl fully satisfied the option will be ignored and act as if
130      dnl --disable-curldebug had been given setting shell variable
131      dnl want_curldebug to 'no'.
132      want_curldebug="yes"
133      AC_MSG_RESULT([yes])
134      ;;
135  esac
136])
137
138
139dnl CURL_CHECK_OPTION_DEBUG
140dnl -------------------------------------------------
141dnl Verify if configure has been invoked with option
142dnl --enable-debug or --disable-debug, and set shell
143dnl variable want_debug value as appropriate.
144
145AC_DEFUN([CURL_CHECK_OPTION_DEBUG], [
146  AC_BEFORE([$0],[CURL_CHECK_OPTION_WARNINGS])dnl
147  AC_BEFORE([$0],[CURL_CHECK_OPTION_CURLDEBUG])dnl
148  AC_BEFORE([$0],[CURL_CHECK_PROG_CC])dnl
149  AC_MSG_CHECKING([whether to enable debug build options])
150  OPT_DEBUG_BUILD="default"
151  AC_ARG_ENABLE(debug,
152AC_HELP_STRING([--enable-debug],[Enable debug build options])
153AC_HELP_STRING([--disable-debug],[Disable debug build options]),
154  OPT_DEBUG_BUILD=$enableval)
155  case "$OPT_DEBUG_BUILD" in
156    no)
157      dnl --disable-debug option used
158      want_debug="no"
159      ;;
160    default)
161      dnl configure option not specified
162      want_debug="no"
163      ;;
164    *)
165      dnl --enable-debug option used
166      want_debug="yes"
167      ;;
168  esac
169  AC_MSG_RESULT([$want_debug])
170])
171
172
173dnl CURL_CHECK_OPTION_NONBLOCKING
174dnl -------------------------------------------------
175dnl Verify if configure has been invoked with option
176dnl --enable-nonblocking or --disable-nonblocking, and
177dnl set shell variable want_nonblocking as appropriate.
178
179AC_DEFUN([CURL_CHECK_OPTION_NONBLOCKING], [
180  AC_BEFORE([$0],[CURL_CHECK_NONBLOCKING_SOCKET])dnl
181  AC_MSG_CHECKING([whether to enable non-blocking communications])
182  OPT_NONBLOCKING="default"
183  AC_ARG_ENABLE(nonblocking,
184AC_HELP_STRING([--enable-nonblocking],[Enable non-blocking communications])
185AC_HELP_STRING([--disable-nonblocking],[Disable non-blocking communications]),
186  OPT_NONBLOCKING=$enableval)
187  case "$OPT_NONBLOCKING" in
188    no)
189      dnl --disable-nonblocking option used
190      want_nonblocking="no"
191      ;;
192    default)
193      dnl configure option not specified
194      want_nonblocking="yes"
195      ;;
196    *)
197      dnl --enable-nonblocking option used
198      want_nonblocking="yes"
199      ;;
200  esac
201  AC_MSG_RESULT([$want_nonblocking])
202])
203
204
205dnl CURL_CHECK_OPTION_OPTIMIZE
206dnl -------------------------------------------------
207dnl Verify if configure has been invoked with option
208dnl --enable-optimize or --disable-optimize, and set
209dnl shell variable want_optimize value as appropriate.
210
211AC_DEFUN([CURL_CHECK_OPTION_OPTIMIZE], [
212  AC_REQUIRE([CURL_CHECK_OPTION_DEBUG])dnl
213  AC_BEFORE([$0],[CURL_CHECK_PROG_CC])dnl
214  AC_MSG_CHECKING([whether to enable compiler optimizer])
215  OPT_COMPILER_OPTIMIZE="default"
216  AC_ARG_ENABLE(optimize,
217AC_HELP_STRING([--enable-optimize],[Enable compiler optimizations])
218AC_HELP_STRING([--disable-optimize],[Disable compiler optimizations]),
219  OPT_COMPILER_OPTIMIZE=$enableval)
220  case "$OPT_COMPILER_OPTIMIZE" in
221    no)
222      dnl --disable-optimize option used. We will handle this as
223      dnl a request to disable compiler optimizations if possible.
224      dnl If the compiler is known CFLAGS and CPPFLAGS will be
225      dnl overridden, otherwise this can not be honored.
226      want_optimize="no"
227      AC_MSG_RESULT([no])
228      ;;
229    default)
230      dnl configure's optimize option not specified. Initially we will
231      dnl handle this as a a request contrary to configure's setting
232      dnl for --enable-debug. IOW, initially, for debug-enabled builds
233      dnl this will be handled as a request to disable optimizations if
234      dnl possible, and for debug-disabled builds this will be handled
235      dnl initially as a request to enable optimizations if possible.
236      dnl Finally, if the compiler is known and CFLAGS and CPPFLAGS do
237      dnl not have any optimizer flag the request will be honored, in
238      dnl any other case the request can not be honored.
239      dnl IOW, existing optimizer flags defined in CFLAGS or CPPFLAGS
240      dnl will always take precedence over any initial assumption.
241      if test "$want_debug" = "yes"; then
242        want_optimize="assume_no"
243        AC_MSG_RESULT([(assumed) no])
244      else
245        want_optimize="assume_yes"
246        AC_MSG_RESULT([(assumed) yes])
247      fi
248      ;;
249    *)
250      dnl --enable-optimize option used. We will handle this as
251      dnl a request to enable compiler optimizations if possible.
252      dnl If the compiler is known CFLAGS and CPPFLAGS will be
253      dnl overridden, otherwise this can not be honored.
254      want_optimize="yes"
255      AC_MSG_RESULT([yes])
256      ;;
257  esac
258])
259
260
261dnl CURL_CHECK_OPTION_THREADS
262dnl -------------------------------------------------
263dnl Verify if configure has been invoked with option
264dnl --enable-threads or --disable-threads, and
265dnl set shell variable want_threads as appropriate.
266
267dnl AC_DEFUN([CURL_CHECK_OPTION_THREADS], [
268dnl   AC_BEFORE([$0],[CURL_CHECK_LIB_THREADS])dnl
269dnl   AC_MSG_CHECKING([whether to enable threads for DNS lookups])
270dnl   OPT_THREADS="default"
271dnl   AC_ARG_ENABLE(threads,
272dnl AC_HELP_STRING([--enable-threads@<:@=PATH@:>@],[Enable threads for DNS lookups])
273dnl AC_HELP_STRING([--disable-threads],[Disable threads for DNS lookups]),
274dnl   OPT_THREADS=$enableval)
275dnl   case "$OPT_THREADS" in
276dnl     no)
277dnl       dnl --disable-threads option used
278dnl       want_threads="no"
279dnl       AC_MSG_RESULT([no])
280dnl       ;;
281dnl     default)
282dnl       dnl configure option not specified
283dnl       want_threads="no"
284dnl       AC_MSG_RESULT([(assumed) no])
285dnl       ;;
286dnl     *)
287dnl       dnl --enable-threads option used
288dnl       want_threads="yes"
289dnl       want_threads_path="$enableval"
290dnl       AC_MSG_RESULT([yes])
291dnl       ;;
292dnl   esac
293dnl   #
294dnl   if test "$want_ares" = "assume_yes"; then
295dnl     if test "$want_threads" = "yes"; then
296dnl       AC_MSG_CHECKING([whether to ignore c-ares enabling assumed setting])
297dnl       AC_MSG_RESULT([yes])
298dnl       want_ares="no"
299dnl     else
300dnl       want_ares="yes"
301dnl     fi
302dnl   fi
303dnl   if test "$want_threads" = "yes" && test "$want_ares" = "yes"; then
304dnl     AC_MSG_ERROR([options --enable-ares and --enable-threads are mutually exclusive, at most one may be enabled.])
305dnl   fi
306dnl ])
307
308
309dnl CURL_CHECK_OPTION_WARNINGS
310dnl -------------------------------------------------
311dnl Verify if configure has been invoked with option
312dnl --enable-warnings or --disable-warnings, and set
313dnl shell variable want_warnings as appropriate.
314
315AC_DEFUN([CURL_CHECK_OPTION_WARNINGS], [
316  AC_REQUIRE([CURL_CHECK_OPTION_DEBUG])dnl
317  AC_BEFORE([$0],[CURL_CHECK_OPTION_WERROR])dnl
318  AC_BEFORE([$0],[CURL_CHECK_PROG_CC])dnl
319  AC_MSG_CHECKING([whether to enable strict compiler warnings])
320  OPT_COMPILER_WARNINGS="default"
321  AC_ARG_ENABLE(warnings,
322AC_HELP_STRING([--enable-warnings],[Enable strict compiler warnings])
323AC_HELP_STRING([--disable-warnings],[Disable strict compiler warnings]),
324  OPT_COMPILER_WARNINGS=$enableval)
325  case "$OPT_COMPILER_WARNINGS" in
326    no)
327      dnl --disable-warnings option used
328      want_warnings="no"
329      ;;
330    default)
331      dnl configure option not specified, so
332      dnl use same setting as --enable-debug
333      want_warnings="$want_debug"
334      ;;
335    *)
336      dnl --enable-warnings option used
337      want_warnings="yes"
338      ;;
339  esac
340  AC_MSG_RESULT([$want_warnings])
341])
342
343dnl CURL_CHECK_OPTION_WERROR
344dnl -------------------------------------------------
345dnl Verify if configure has been invoked with option
346dnl --enable-werror or --disable-werror, and set
347dnl shell variable want_werror as appropriate.
348
349AC_DEFUN([CURL_CHECK_OPTION_WERROR], [
350  AC_BEFORE([$0],[CURL_CHECK_COMPILER])dnl
351  AC_MSG_CHECKING([whether to enable compiler warnings as errors])
352  OPT_COMPILER_WERROR="default"
353  AC_ARG_ENABLE(werror,
354AC_HELP_STRING([--enable-werror],[Enable compiler warnings as errors])
355AC_HELP_STRING([--disable-werror],[Disable compiler warnings as errors]),
356  OPT_COMPILER_WERROR=$enableval)
357  case "$OPT_COMPILER_WERROR" in
358    no)
359      dnl --disable-werror option used
360      want_werror="no"
361      ;;
362    default)
363      dnl configure option not specified
364      want_werror="no"
365      ;;
366    *)
367      dnl --enable-werror option used
368      want_werror="yes"
369      ;;
370  esac
371  AC_MSG_RESULT([$want_werror])
372])
373
374
375dnl CURL_CHECK_NONBLOCKING_SOCKET
376dnl -------------------------------------------------
377dnl Check for how to set a socket into non-blocking state.
378
379AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET], [
380  AC_REQUIRE([CURL_CHECK_OPTION_NONBLOCKING])dnl
381  AC_REQUIRE([CURL_CHECK_FUNC_FCNTL])dnl
382  AC_REQUIRE([CURL_CHECK_FUNC_IOCTL])dnl
383  AC_REQUIRE([CURL_CHECK_FUNC_IOCTLSOCKET])dnl
384  AC_REQUIRE([CURL_CHECK_FUNC_IOCTLSOCKET_CAMEL])dnl
385  AC_REQUIRE([CURL_CHECK_FUNC_SETSOCKOPT])dnl
386  #
387  tst_method="unknown"
388  if test "$want_nonblocking" = "yes"; then
389    AC_MSG_CHECKING([how to set a socket into non-blocking mode])
390    if test "x$ac_cv_func_fcntl_o_nonblock" = "xyes"; then
391      tst_method="fcntl O_NONBLOCK"
392    elif test "x$ac_cv_func_ioctl_fionbio" = "xyes"; then
393      tst_method="ioctl FIONBIO"
394    elif test "x$ac_cv_func_ioctlsocket_fionbio" = "xyes"; then
395      tst_method="ioctlsocket FIONBIO"
396    elif test "x$ac_cv_func_ioctlsocket_camel_fionbio" = "xyes"; then
397      tst_method="IoctlSocket FIONBIO"
398    elif test "x$ac_cv_func_setsockopt_so_nonblock" = "xyes"; then
399      tst_method="setsockopt SO_NONBLOCK"
400    fi
401    AC_MSG_RESULT([$tst_method])
402    if test "$tst_method" = "unknown"; then
403      AC_MSG_WARN([cannot determine non-blocking socket method.])
404    fi
405  fi
406  if test "$tst_method" = "unknown"; then
407    AC_DEFINE_UNQUOTED(USE_BLOCKING_SOCKETS, 1,
408      [Define to disable non-blocking sockets.])
409    AC_MSG_WARN([non-blocking sockets disabled.])
410  fi
411])
412
413
414dnl CURL_CHECK_LIB_ARES
415dnl -------------------------------------------------
416dnl When c-ares library support has been requested,
417dnl performs necessary checks and adjustsments needed
418dnl to enable support of this library.
419
420AC_DEFUN([CURL_CHECK_LIB_ARES], [
421  #
422  if test "$want_ares" = "yes"; then
423    dnl c-ares library support has been requested
424    clean_CPPFLAGS="$CPPFLAGS"
425    clean_LDFLAGS="$LDFLAGS"
426    clean_LIBS="$LIBS"
427    embedded_ares="unknown"
428    configure_runpath=`pwd`
429    embedded_ares_builddir="$configure_runpath/ares"
430    if test -n "$want_ares_path"; then
431      dnl c-ares library path has been specified
432      ares_CPPFLAGS="-I$want_ares_path/include"
433      ares_LDFLAGS="-L$want_ares_path/lib"
434      ares_LIBS="-lcares"
435    else
436      dnl c-ares library path has not been given
437      if test -d "$srcdir/ares"; then
438        dnl c-ares sources embedded in curl tree
439        embedded_ares="yes"
440        AC_CONFIG_SUBDIRS(ares)
441        dnl c-ares has installable configured header files, path
442        dnl inclusion fully done in makefiles for in-tree builds.
443        ares_CPPFLAGS=""
444        ares_LDFLAGS="-L$embedded_ares_builddir"
445        ares_LIBS="-lcares"
446      else
447        dnl c-ares path not specified, use defaults
448        ares_CPPFLAGS=""
449        ares_LDFLAGS=""
450        ares_LIBS="-lcares"
451      fi
452    fi
453    #
454    CPPFLAGS="$ares_CPPFLAGS $clean_CPPFLAGS"
455    LDFLAGS="$ares_LDFLAGS $clean_LDFLAGS"
456    LIBS="$ares_LIBS $clean_LIBS"
457    #
458    if test "$embedded_ares" != "yes"; then
459      dnl check if c-ares new enough when not using an embedded
460      dnl source tree one which normally has not been built yet.
461      AC_MSG_CHECKING([that c-ares is good and recent enough])
462      AC_LINK_IFELSE([
463        AC_LANG_PROGRAM([[
464#include <ares.h>
465          /* set of dummy functions in case c-ares was built with debug */
466          void curl_dofree() { }
467          void curl_sclose() { }
468          void curl_domalloc() { }
469          void curl_docalloc() { }
470          void curl_socket() { }
471        ]],[[
472          ares_channel channel;
473          ares_cancel(channel); /* added in 1.2.0 */
474          ares_process_fd(channel, 0, 0); /* added in 1.4.0 */
475          ares_dup(&channel, channel); /* added in 1.6.0 */
476        ]])
477      ],[
478        AC_MSG_RESULT([yes])
479      ],[
480        AC_MSG_RESULT([no])
481        AC_MSG_ERROR([c-ares library defective or too old])
482        dnl restore initial settings
483        CPPFLAGS="$clean_CPPFLAGS"
484        LDFLAGS="$clean_LDFLAGS"
485        LIBS="$clean_LIBS"
486        # prevent usage
487        want_ares="no"
488      ])
489    fi
490    if test "$want_ares" = "yes"; then
491      dnl finally c-ares will be used
492      AC_DEFINE(USE_ARES, 1, [Define to enable c-ares support])
493      AC_SUBST([USE_ARES], [1])
494      curl_res_msg="c-ares"
495    fi
496  fi
497])
498
499