configure.ac 38.3 KB
Newer Older
1 2 3 4
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
#
AC_PREREQ([2.67])
5
AC_INIT([aria2],[1.29.0],[https://github.com/aria2/aria2/issues],[aria2],[https://aria2.github.io/])
6 7 8 9 10 11 12

AC_CANONICAL_HOST
AC_CANONICAL_TARGET

AM_INIT_AUTOMAKE([subdir-objects])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

13
AC_USE_SYSTEM_EXTENSIONS
14 15

LT_PREREQ([2.2.6])
16 17 18 19 20 21 22
LT_INIT([disable-static])
dnl See versioning rule:
dnl  http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
AC_SUBST(LT_CURRENT, 0)
AC_SUBST(LT_REVISION, 0)
AC_SUBST(LT_AGE, 0)

23
AC_CONFIG_MACRO_DIR([m4])
24
m4_ifdef([AM_PATH_CPPUNIT], [AM_PATH_CPPUNIT(1.10.2)])
25 26 27
AC_CONFIG_SRCDIR([src/a2io.h])
AC_CONFIG_HEADERS([config.h])

28 29 30 31 32 33 34
# extra flags
EXTRACFLAGS=
EXTRACXXFLAGS=
EXTRACPPFLAGS=
EXTRALDFLAGS=
EXTRALIBS=

35
case "$host" in
36
  *mingw*)
37
    win_build=yes
38 39 40 41 42
    EXTRALIBS="-lws2_32 -lwsock32 -lgdi32 -lwinmm -liphlpapi -lpsapi $EXTRALIBS"
    # Define _POSIX_C_SOURCE to 1. This makes {asc,local}time_r
    # available from <time.h> even without (un)helpful interference
    # from <pthread.h>, and also defines __USE_MINGW_ANSI_STDIO.
    EXTRACPPFLAGS="$EXTRACPPFLAGS -D_POSIX_C_SOURCE=1"
43
    # Build with ASLR (dynamicbase) and NX compatiblity (nxcompat)
44 45 46
    # Enable pie once upstream/binutils gets fixed to produce correct
    # binaries with it.
    EXTRALDFLAGS="$EXTRALDFLAGS -Wl,--dynamicbase -Wl,--nxcompat"
47 48 49
    ;;
esac

50 51
AC_DEFINE_UNQUOTED([BUILD], ["$build"], [Define build-type])
AC_DEFINE_UNQUOTED([HOST], ["$host"], [Define build-type])
52 53 54
AC_DEFINE_UNQUOTED([TARGET], ["$target"], [Define target-type])

# Checks for arguments.
55
ARIA2_ARG_WITH([libuv])
56
ARIA2_ARG_WITHOUT([appletls])
57
ARIA2_ARG_WITHOUT([wintls])
58 59 60 61 62 63 64 65 66 67 68 69
ARIA2_ARG_WITHOUT([gnutls])
ARIA2_ARG_WITHOUT([libnettle])
ARIA2_ARG_WITHOUT([libgmp])
ARIA2_ARG_WITHOUT([libgcrypt])
ARIA2_ARG_WITHOUT([openssl])
ARIA2_ARG_WITHOUT([sqlite3])
ARIA2_ARG_WITHOUT([libxml2])
ARIA2_ARG_WITHOUT([libexpat])
ARIA2_ARG_WITHOUT([libcares])
ARIA2_ARG_WITHOUT([libz])
ARIA2_ARG_WITH([tcmalloc])
ARIA2_ARG_WITH([jemalloc])
70
ARIA2_ARG_WITHOUT([libssh2])
71

72
ARIA2_ARG_DISABLE([ssl])
73 74
ARIA2_ARG_DISABLE([bittorrent])
ARIA2_ARG_DISABLE([metalink])
75
ARIA2_ARG_DISABLE([websocket])
76 77
ARIA2_ARG_DISABLE([epoll])
ARIA2_ARG_ENABLE([libaria2])
78
ARIA2_ARG_ENABLE([werror])
79 80 81

AC_ARG_WITH([ca-bundle],
  AS_HELP_STRING([--with-ca-bundle=FILE],[Use FILE as default CA bundle.]),
82 83 84 85 86 87 88 89
  [AC_DEFINE_UNQUOTED([CA_BUNDLE], ["$withval"], [Define to choose default CA bundle.])
   ca_bundle=$withval
  ], [])

AC_ARG_WITH([disk-cache],
  AS_HELP_STRING([--with-disk-cache=SIZE],[Use SIZE as the default disk-cache size.]),
  [AC_DEFINE_UNQUOTED([DEFAULT_DISK_CACHE], ["$withval"], [Define to choose default disk-cache size])],
  [])
90

91 92 93 94 95
AC_ARG_WITH([bashcompletiondir],
  AS_HELP_STRING([--with-bashcompletiondir=DIR],
                 [Directory to install bash_completion file]),
  [bashcompletiondir=$withval], [bashcompletiondir=$docdir/bash_completion])

96
AC_ARG_VAR([ARIA2_STATIC], [Set 'yes' to build a statically linked aria2])
97

98 99 100 101 102 103 104
AC_ARG_ENABLE([gnutls-system-crypto-policy],
    AS_HELP_STRING([--enable-gnutls-system-crypto-policy], [Enable gnutls system wide crypto policy]))

AS_IF([test "x$enable_gnutls_system_crypto_policy" = "xyes"], [
  AC_DEFINE([USE_GNUTLS_SYSTEM_CRYPTO_POLICY], [1], [Define to 1 if using gnutls system wide crypto policy .])
])

105 106 107 108 109 110
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MKDIR_P
AC_PROG_YACC
111
AM_PROG_AS
112

113 114
# Speed GCC compilation up.
if test "$GCC" = yes; then
115
  EXTRACFLAGS="$EXTRACFLAGS -pipe"
116 117
fi
if test "$GXX" = yes; then
118
  EXTRACXXFLAGS="$EXTRACXXFLAGS -pipe"
119 120
fi

121 122 123 124 125 126
AC_CHECK_TOOL([AR], [ar], [:])
if test "x$AR" = "x:"; then
  AC_MSG_FAILURE([ar is not found in the system.])
fi
AC_SUBST([AR])

127 128 129 130
AC_PATH_PROGS([SPHINXBUILD], [sphinx-build])
AC_SUBST([SPHINXBUILD])
AM_CONDITIONAL([HAVE_SPHINXBUILD], [ test "x$SPHINXBUILD" != "x" ])

131 132 133 134
AC_PATH_PROGS([RST2HTML], [rst2html.py rst2html])
AC_SUBST([RST2HTML])
AM_CONDITIONAL([HAVE_RST2HTML], [ test "x$RST2HTML" != "x" ])

135 136 137 138 139 140
# Setting language choice
AC_LANG([C++])

# Check pkg-config is available
PKG_PROG_PKG_CONFIG([0.20])

141
# Check C++ compiler supports C++0x/C++11 feature
142 143 144
save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS=

145 146
AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
CXX1XCXXFLAGS="$CXXFLAGS"
CXXFLAGS="$save_CXXFLAGS"
AC_SUBST([CXX1XCXXFLAGS])

# Check C++ compiler actually supports nullptr
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXX1XCXXFLAGS"

AC_MSG_CHECKING([whether the c++ compiler supports nullptr])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]],
[[
int *a = nullptr;
]])],
[],
[AC_MSG_FAILURE([C++ compiler does not understand nullptr, perhaps C++ compiler is too old.  Try again with new one (gcc >= 4.8.3 or clang >= 3.4)])])

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
# i686-w64-mingw32-g++ 4.6 does not support override keyword. For
# those compilers, define CXX11_OVERRIDE to empty string. Otherwise
# define it as override. Use CXX11_OVERRIDE instead of override.
AC_MSG_CHECKING([whether the C++ compiler supports `override` keyword])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
struct Base {
virtual void f() = 0;
};
struct Derived : Base {
virtual void f() override {}
};
]],
[[
Derived x;
]])],
    [cxx11_override=override
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])
AC_DEFINE_UNQUOTED([CXX11_OVERRIDE], [$cxx11_override],
                   [Define `override` keyword if the compiler supports it])

185 186
CXXFLAGS=$save_CXXFLAGS

187 188 189 190 191 192
# Check static build is requested
if test "x$ARIA2_STATIC" = "xyes"; then
  case "$host" in
    i686*mingw*)
      dnl Define _USE_32BIT_TIME_T because 32bit library of MinGW-w64
      dnl does not implement many 64bit version functions.
193
      EXTRACPPFLAGS="$EXTRACPPFLAGS -D_USE_32BIT_TIME_T"
194 195
    ;;
  esac
196 197
  # Make pkg-config produce static linking variables
  PKG_CONFIG="$PKG_CONFIG --static"
198 199
else
  dnl Make variable empty to avoid confusion
200
  ARIA2_STATIC=no
201 202
fi

203
# Checks for libraries.
204 205 206 207

# Check availability of libz
if test "x$with_libz" = "xyes"; then
  PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.3], [have_zlib=yes], [have_zlib=no])
208
  if test "x$have_zlib" != "xyes"; then
209
    AC_MSG_WARN([$ZLIB_PKG_ERRORS])
210
    AC_CHECK_LIB([z], [zlibVersion], [have_zlib=yes], [have_zlib=no])
211

212
    if test "x$have_zlib" = "xyes"; then
213 214 215 216
      ZLIB_CFLAGS=
      ZLIB_LIBS="-lz"
      AC_SUBST([ZLIB_CFLAGS])
      AC_SUBST([ZLIB_LIBS])
217
    elif test "x$with_libz_requested" = "xyes"; then
218 219 220
      ARIA2_DEP_NOT_MET([libz])
    fi
  fi
221 222 223 224
  if test "x$have_zlib" = "xyes"; then
    AC_DEFINE([HAVE_ZLIB], [1], [Define to 1 if you have zlib.])
    # Android NDK arch-mips contains gzbuffer symbol but it is missing
    # in zlib.h
225 226 227 228
    save_CFLAGS=$CFLAGS
    save_LIBS=$LIBS
    CFLAGS="$CFLAGS $ZLIB_CFLAGS"
    LIBS="$ZLIB_LIBS $LIBS"
229 230 231 232 233 234
    AC_CHECK_DECL([gzbuffer], [have_decl_gzbuffer=yes], [],
                  [[#include <zlib.h>]])
    if test "x$have_decl_gzbuffer" = "xyes"; then
      AC_CHECK_FUNC([gzbuffer])
    fi
    AC_CHECK_FUNCS([gzsetparams])
235 236
    CFLAGS=$save_CFLAGS
    LIBS=$save_LIBS
237
  fi
238 239
fi

240
have_libuv=no
241 242 243
if test "x$with_libuv" = "xyes"; then
  case "$host" in
    *mingw*|*msvc*)
244 245 246 247
      libuv_cflags="-D_WIN32_WINNT=0x0600"
      save_CPPFLAGS=$CPPFLAGS
      save_LIBS=$LIBS
      CPPFLAGS="$CPPFLAGS $libuv_cflags"
248 249 250
      AC_SEARCH_LIBS([uv_poll_init_socket], [uv], [
                      AC_CHECK_HEADER([uv.h], [have_libuv=yes], [have_libuv=no])
                      ], [have_libuv=no])
251 252 253 254 255
      if test "x$have_libuv" = "xyes"; then
        LIBUV_CFLAGS=$libuv_cflags
        LIBUV_LIBS=-luv
        AC_SUBST([LIBUV_CFLAGS])
        AC_SUBST([LIBUV_LIBS])
256
      fi
257 258
      CPPFLAGS=$save_CPPFLAGS
      CPPLIBS=$save_LIBS
259 260 261
    ;;

    *darwin*)
262 263 264 265
      libuv_ldflags="-framework Foundation -framework CoreServices -framework ApplicationServices"
      save_LDFLAGS=$LDFLAGS
      save_LIBS=$LIBS
      LDFLAGS="$LDFLAGS $libuv_ldflags"
266 267
      AC_SEARCH_LIBS([uv_poll_init_socket], [uv], [
                      AC_CHECK_HEADER([uv.h], [have_libuv=yes], [have_libuv=no])
268 269 270 271 272 273
                      ], [have_libuv=no], [-lm])
      if test "x$have_libuv" = "xyes"; then
        LIBUV_CFLAGS=
        LIBUV_LIBS="$libuv_ldflags -luv -lm"
        AC_SUBST([LIBUV_CFLAGS])
        AC_SUBST([LIBUV_LIBS])
274
      fi
275 276
      LDFLAGS=$save_LDFLAGS
      LIBS=$save_LIBS
277 278 279 280 281
      ;;

    *)
      dnl Yeah, sucks that luv does not bring a pkg-config or config-tool
      AC_MSG_CHECKING([for libuv])
282
      save_LIBS=$LIBS
283
      for combo in "" "-lrt" "-ldl -lrt" "-ldl -lrt -lpthread" "-lkvm"; do
284
        LIBS="-luv $combo $save_LIBS -lm"
285 286 287 288 289 290 291 292
        AC_LINK_IFELSE([AC_LANG_SOURCE([
extern "C" int uv_poll_init_socket(void);
int main() { return uv_poll_init_socket(); }
                       ])], [
                        AC_MSG_RESULT(-luv $combo -lm)
                        AC_CHECK_HEADER([uv.h], [have_libuv=yes], [have_libuv=no])
                        ], [have_libuv=no])
        if test "x$have_libuv" = "xyes"; then
293 294 295 296
          LIBUV_CFLAGS=
          LIBUV_LIBS="-luv $combo -lm"
          AC_SUBST([LIBUV_CFLAGS])
          AC_SUBST([LIBUV_LIBS])
297 298 299
          break;
        fi
      done
300
      LIBS=$save_LIBS
301 302 303 304 305 306 307 308
      if test "x$have_libuv" != "xyes"; then
        AC_MSG_RESULT("no")
      fi
    ;;
  esac

  if test "x$have_libuv" = "xyes"; then
    AC_DEFINE([HAVE_LIBUV], [1], [Define to 1 if you have libuv.])
309 310
    save_LIBS=$LIBS
    LIBS="$LIBUV_LIBS $LIBS"
311
    AC_CHECK_FUNCS([uv_last_error])
312
    LIBS=$save_LIBS
313 314 315 316 317 318
  elif test "x$with_libuv_requested" = "xyes"; then
    ARIA2_DEP_NOT_MET([libuv])
  fi
fi
AM_CONDITIONAL([HAVE_LIBUV], [test "x$have_libuv" = "xyes"])

319
have_libxml2=no
320
if test "x$with_libxml2" = "xyes"; then
321 322 323 324 325 326 327
  m4_ifdef([AM_PATH_XML2], [AM_PATH_XML2([2.6.24], [have_libxml2=yes])], [
    AC_MSG_WARN([configure was generated without libxml2 detection.  libxml2 detection is disabled])
    XML_CPPFLAGS=
    XML_LIBS=
    AC_SUBST([XML_CPPFLAGS])
    AC_SUBST([XML_LIBS])
  ])
328 329 330 331 332 333 334
  if test "x$have_libxml2" = "xyes"; then
    AC_DEFINE([HAVE_LIBXML2], [1], [Define to 1 if you have libxml2.])
  elif test "x$with_libxml2_requested" = "xyes"; then
    ARIA2_DEP_NOT_MET([libxml2])
  fi
fi

335
have_libexpat=no
336
if test "x$with_libexpat" = "xyes" && test "x$have_libxml2" != "xyes"; then
337 338 339 340 341 342 343 344 345
  m4_ifdef([AM_PATH_LIBEXPAT], [AM_PATH_LIBEXPAT], [
    AC_MSG_WARN([configure was generated without libexpat detection.  libexpat detection is disabled])
    EXPAT_CFLAGS=
    EXPAT_LIBS=
    AC_SUBST([EXPAT_CFLAGS])
    AC_SUBST([EXPAT_LIBS])
  ])
  if test "x$have_libexpat" != "xyes" &&
     test "x$with_libexpat_requested" = "xyes"; then
346 347 348 349
    ARIA2_DEP_NOT_MET([libexpat])
  fi
fi

350
have_sqlite3=no
351
if test "x$with_sqlite3" = "xyes"; then
352
  PKG_CHECK_MODULES([SQLITE3],[sqlite3],[have_sqlite3=yes],[have_sqlite3=no])
353
  if test "x$have_sqlite3" = "xyes"; then
354
    AC_DEFINE([HAVE_SQLITE3], [1], [Define to 1 if you have sqlite3.])
355
    save_LIBS=$LIBS
356
    LIBS="$SQLITE3_LIBS $LIBS"
357
    AC_CHECK_FUNCS([sqlite3_open_v2])
358
    LIBS=$save_LIBS
359 360 361 362 363
  else
    AC_MSG_WARN([$SQLITE3_PKG_ERRORS])
    if test "x$with_sqlite3_requested" = "xyes"; then
      ARIA2_DEP_NOT_MET([sqlite3])
    fi
364 365 366
  fi
fi

367 368 369 370
case "$host" in
  *darwin*)
    have_osx="yes"
  ;;
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
  *mingw*)
    AC_CHECK_HEADERS([windows.h \
                      winsock2.h \
                      ws2tcpip.h \
                      mmsystem.h \
                      io.h \
                      iphlpapi.h\
                      winioctl.h \
                      share.h], [], [],
                      [[
#ifdef HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
#endif
#ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
                      ]])
  ;;
392 393
esac

394 395 396 397 398 399 400 401 402 403

if test "x$enable_ssl" != "xyes"; then
  with_appletls=no
  with_wintls=no
  with_libnettle=no
  with_libgcrypt=no
  with_gnutls=no
  with_openssl=no
fi

404
have_appletls=no
405 406 407 408
if test "x$with_appletls" = "xyes"; then
  AC_MSG_CHECKING([whether to enable Mac OS X native SSL/TLS])
  if test "x$have_osx" = "xyes"; then
    AC_DEFINE([HAVE_APPLETLS], [1], [Define to 1 if you have Apple TLS])
409 410
    APPLETLS_LDFLAGS="-framework CoreFoundation -framework Security"
    AC_SUBST([APPLETLS_LDFLAGS])
411
    have_appletls="yes"
412 413
    have_ssl=yes
    have_nativetls=yes
414 415 416 417 418 419 420 421 422
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
    if test "x$with_appletls_requested" = "xyes"; then
      ARIA2_DEP_NOT_MET([appletls])
    fi
  fi
fi

423
have_wintls=no
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
if test "x$with_wintls" = "xyes"; then
  AC_HAVE_LIBRARY([crypt32],[have_wintls_libs=yes],[have_wintls_libs=no])
  AC_HAVE_LIBRARY([secur32],[have_wintls_libs=$have_wintls_libs],[have_wintls_libs=no])
  AC_HAVE_LIBRARY([advapi32],[have_wintls_libs=$have_wintls_libs],[have_wintls_libs=no])
  AC_CHECK_HEADER([wincrypt.h], [have_wintls_headers=yes], [have_wintls_headers=no], [[
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
  ]])
  AC_CHECK_HEADER([security.h], [have_wintls_headers=$have_wintls_headers], [have_wintls_headers=no], [[
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#ifndef SECURITY_WIN32
#define SECURITY_WIN32 1
#endif
  ]])

  if test "x$have_wintls_libs" = "xyes" &&
     test "x$have_wintls_headers" = "xyes"; then
    AC_DEFINE([SECURITY_WIN32], [1], [Use security.h in WIN32 mode])
445 446
    WINTLS_LIBS="-lcrypt32 -lsecur32 -ladvapi32"
    AC_SUBST([WINTLS_LIBS])
447
    have_wintls=yes
448 449
    have_ssl=yes
    have_nativetls=yes
450 451 452 453 454 455 456 457 458 459
  else
    have_wintls=no
  fi
  if test "x$have_wintls" != "xyes"; then
    if test "x$with_wintls_requested" = "xyes"; then
      ARIA2_DEP_NOT_MET([wintls])
    fi
  fi
fi

460
have_libgnutls=no
461
if test "x$with_gnutls" = "xyes" && test "x$have_ssl" != "xyes"; then
462 463 464 465 466
  # gnutls >= 2.8 doesn't have libgnutls-config anymore. We require
  # 2.2.0 because we use gnutls_priority_set_direct()
  PKG_CHECK_MODULES([LIBGNUTLS], [gnutls >= 2.2.0],
                    [have_libgnutls=yes], [have_libgnutls=no])
  if test "x$have_libgnutls" = "xyes"; then
467
    have_ssl=yes
468
    AC_DEFINE([HAVE_LIBGNUTLS], [1], [Define to 1 if you have libgnutls.])
469
    save_LIBS=$LIBS
470
    LIBS="$LIBGNUTLS_LIBS $LIBS"
471
    AC_CHECK_FUNCS([gnutls_certificate_set_x509_system_trust])
472
    LIBS=$save_LIBS
473 474 475 476 477
  else
    AC_MSG_WARN([$LIBGNUTLS_PKG_ERRORS])
    if test "x$with_gnutls_requested" = "xyes"; then
      ARIA2_DEP_NOT_MET([gnutls])
    fi
478 479 480
  fi
fi

481
have_openssl=no
482
if test "x$with_openssl" = "xyes" && test "x$have_ssl" != "xyes"; then
483 484
  PKG_CHECK_MODULES([OPENSSL], [openssl >= 0.9.8],
                    [have_openssl=yes], [have_openssl=no])
485
  if test "x$have_openssl" = "xyes"; then
486
    have_ssl=yes
487 488
    AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if you have openssl.])

489 490
    save_LIBS=$LIBS
    LIBS="$OPENSSL_LIBS $LIBS"
491 492 493 494 495 496 497 498
    AC_CHECK_FUNCS([EVP_DigestInit_ex], [have_digestinit_ex=yes])
    if test "x$have_digestinit_ex" = "x"; then
      AC_DEFINE([HAVE_OLD_OPENSSL], [1], [Define to 1 if you have old openssl.])
    fi
    AC_CHECK_FUNCS([EVP_sha224])
    AC_CHECK_FUNCS([EVP_sha256])
    AC_CHECK_FUNCS([EVP_sha384])
    AC_CHECK_FUNCS([EVP_sha512])
499
    LIBS=$save_LIBS
500 501 502 503 504
  else
    AC_MSG_WARN([$OPENSSL_PKG_ERRORS])
    if test "x$with_openssl_requested" = "xyes"; then
      ARIA2_DEP_NOT_MET([openssl])
    fi
505 506 507
  fi
fi

508 509 510
have_libnettle=no
have_libgmp=no
have_libgcrypt=no
511
if test "x$have_openssl" != "xyes"; then
512 513
  if test "x$with_libnettle" = "xyes" &&
     test "x$have_nativetls" != "xyes"; then
514 515
    AC_CHECK_LIB([nettle], [nettle_sha1_init],
                 [have_libnettle=yes], [have_libnettle=no])
516
    if test "x$have_libnettle" = "xyes"; then
517 518 519 520
      LIBNETTLE_CFLAGS=
      LIBNETTLE_LIBS="-lnettle"
      AC_SUBST([LIBNETTLE_CFLAGS])
      AC_SUBST([LIBNETTLE_LIBS])
521 522 523 524
      AC_DEFINE([HAVE_LIBNETTLE], [1], [Define to 1 if you have libnettle.])
    fi
  fi
  if test "x$with_libgmp" = "xyes" &&
525
     (test "x$have_libnettle" = "xyes" ||
526
      test "x$have_nativetls" = "xyes") &&
527
     test "x$enable_bittorrent" = "xyes"; then
528
    AC_CHECK_LIB([gmp], [__gmpz_init], [have_libgmp=yes], [have_libgmp=no])
529
    if test "x$have_libgmp" = "xyes"; then
530 531 532 533
      LIBGMP_CFLAGS=
      LIBGMP_LIBS=-lgmp
      AC_SUBST([LIBGMP_CFLAGS])
      AC_SUBST([LIBGMP_LIBS])
534
      AC_DEFINE([HAVE_LIBGMP], [1], [Define to 1 if you have libgmp.])
535 536
      save_LIBS=$LIBS
      LIBS="$LIBGMP_LIBS $LIBS"
537
      AC_CHECK_FUNCS([__gmpz_powm_sec], [have_mpz_powm_sec=yes])
538
      LIBS=$save_LIBS
539 540 541 542 543 544 545 546
      if test "x$have_mpz_powm_sec" = "xyes"; then
        AC_DEFINE([HAVE_GMP_SEC], [1], [Define to 1 if you have a GMP with sec functions.])
      fi
    else
      AC_MSG_WARN([libgmp not found])
      if test "x$with_libgmp_requested" = "xyes"; then
        ARIA2_DEP_NOT_MET([libgmp])
      fi
547 548 549
    fi
  fi
  if test "x$with_libgcrypt" = "xyes" &&
550
     test "x$have_nativetls" != "xyes" &&
551
     test "x$have_libnettle" != "xyes"; then
552 553 554 555 556 557 558
    m4_ifdef([AM_PATH_LIBGCRYPT], [AM_PATH_LIBGCRYPT([1.2.4], [have_libgcrypt=yes])], [
    AC_MSG_WARN([configure was generated without libgcrypt detection.  libgcrypt detection is disabled])
      LIBGCRYPT_CFLAGS=
      LIBGCRYPT_LIBS=
      AC_SUBST([LIBGCRYPT_CFLAGS])
      AC_SUBST([LIBGCRYPT_LIBS])
    ])
559 560 561 562 563 564
    if test "x$have_libgcrypt" = "xyes"; then
      AC_DEFINE([HAVE_LIBGCRYPT], [1], [Define to 1 if you have libgcrypt.])
    fi
  fi
fi

565 566 567 568 569 570 571 572 573 574 575 576 577 578
have_libssh2=no
if test "x$with_libssh2" = "xyes"; then
  PKG_CHECK_MODULES([LIBSSH2], [libssh2], [have_libssh2=yes], [have_libssh2=no])
  if test "x$have_libssh2" = "xyes"; then
    AC_DEFINE([HAVE_LIBSSH2], [1], [Define to 1 if you have libssh2.])
  else
    AC_MSG_WARN([$LIBSSH2_PKG_ERRORS])
    if test "x$with_libssh2_requested" = "xyes"; then
      ARIA2_DEP_NOT_MET([libssh2])
    fi
  fi
fi

have_libcares=no
579
if test "x$with_libcares" = "xyes"; then
580 581
  PKG_CHECK_MODULES([LIBCARES], [libcares >= 1.7.0], [have_libcares=yes],
                    [have_libcares=no])
582
  if test "x$have_libcares" = "xyes"; then
583
    AC_DEFINE([HAVE_LIBCARES], [1], [Define to 1 if you have libcares.])
584 585
    save_LIBS=$LIBS
    save_CPPFLAGS=$CPPFLAGS
586 587
    LIBS="$LIBCARES_LIBS $LIBS"
    CPPFLAGS="$LIBCARES_CFLAGS $CPPFLAGS"
588 589
    AC_CHECK_TYPES([ares_addr_node], [], [], [[#include <ares.h>]])
    AC_CHECK_FUNCS([ares_set_servers])
590 591
    LIBS=$save_LIBS
    CPPFLAGS=$save_CPPFLAGS
592

593
    # -DCARES_STATICLIB is appended by pkg-config file libcares.pc
594 595 596 597 598
  else
    AC_MSG_WARN([$LIBCARES_PKG_ERRORS])
    if test "x$with_libcares_requested" = "xyes"; then
      ARIA2_DEP_NOT_MET([libcares])
    fi
599 600 601
  fi
fi

602
use_md=""
603
if test "x$have_appletls" = "xyes"; then
604 605 606
  use_md="apple"
  AC_DEFINE([USE_APPLE_MD], [1], [What message digest implementation to use])
else
607 608 609
  if test "x$have_libnettle" = "xyes"; then
    AC_DEFINE([USE_LIBNETTLE_MD], [1], [What message digest implementation to use])
    use_md="libnettle"
610
  else
611 612 613
    if test "x$have_libgcrypt" = "xyes"; then
      AC_DEFINE([USE_LIBGCRYPT_MD], [1], [What message digest implementation to use])
      use_md="libgcrypt"
614
    else
615 616 617
      if test "x$have_openssl" = "xyes"; then
        AC_DEFINE([USE_OPENSSL_MD], [1], [What message digest implementation to use])
        use_md="openssl"
618
      else
619 620
        AC_DEFINE([USE_INTERNAL_MD], [1], [What message digest implementation to use])
        use_md="internal"
621 622 623 624 625
      fi
    fi
  fi
fi

626
# Define variables based on the result of the checks for libraries.
627
if test "x$have_ssl" = "xyes"; then
628 629 630
  AC_DEFINE([ENABLE_SSL], [1], [Define to 1 if ssl support is enabled.])
  AM_CONDITIONAL([ENABLE_SSL], true)
else
631
  have_ssl="no"
632 633 634
  AM_CONDITIONAL([ENABLE_SSL], false)
fi

635 636 637

AM_CONDITIONAL([HAVE_OSX], [ test "x$have_osx" = "xyes" ])
AM_CONDITIONAL([HAVE_APPLETLS], [ test "x$have_appletls" = "xyes" ])
638
AM_CONDITIONAL([HAVE_WINTLS], [ test "x$have_wintls" = "xyes" ])
639
AM_CONDITIONAL([USE_APPLE_MD], [ test "x$use_md" = "xapple" ])
640
AM_CONDITIONAL([USE_WINDOWS_MD], [ test "x$use_md" = "xwindows" ])
641 642
AM_CONDITIONAL([HAVE_LIBGNUTLS], [ test "x$have_libgnutls" = "xyes" ])
AM_CONDITIONAL([HAVE_LIBNETTLE], [ test "x$have_libnettle" = "xyes" ])
643
AM_CONDITIONAL([USE_LIBNETTLE_MD], [ test "x$use_md" = "xlibnettle"])
644 645
AM_CONDITIONAL([HAVE_LIBGMP], [ test "x$have_libgmp" = "xyes" ])
AM_CONDITIONAL([HAVE_LIBGCRYPT], [ test "x$have_libgcrypt" = "xyes" ])
646
AM_CONDITIONAL([USE_LIBGCRYPT_MD], [ test "x$use_md" = "xlibgcrypt"])
647
AM_CONDITIONAL([HAVE_OPENSSL], [ test "x$have_openssl" = "xyes" ])
648
AM_CONDITIONAL([USE_OPENSSL_MD], [ test "x$use_md" = "xopenssl"])
649
AM_CONDITIONAL([USE_INTERNAL_MD], [ test "x$use_md" = "xinternal"])
650

651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
if test "x$have_libgmp" = "xyes" ||
   test "x$have_libgcrypt" = "xyes" ||
   test "x$have_openssl" = "xyes"; then
  AM_CONDITIONAL([USE_INTERNAL_BIGNUM], false)
else
  AC_DEFINE([USE_INTERNAL_BIGNUM], [1], [Define to 1 if internal BIGNUM support is enabled.])
  AM_CONDITIONAL([USE_INTERNAL_BIGNUM], true)
fi

if test "x$have_libnettle" = "xyes" ||
   test "x$have_libgcrypt" = "xyes" ||
   test "x$have_openssl" = "xyes"; then
  AM_CONDITIONAL([USE_INTERNAL_ARC4], false)
else
  AC_DEFINE([USE_INTERNAL_ARC4], [1], [Define to 1 if internal ARC4 support is enabled.])
  AM_CONDITIONAL([USE_INTERNAL_ARC4], true)
667 668
fi

669
if test "x$enable_bittorrent" = "xyes"; then
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
  AC_DEFINE([ENABLE_BITTORRENT], [1],
            [Define to 1 if BitTorrent support is enabled.])
  AM_CONDITIONAL([ENABLE_BITTORRENT], true)
else
  if test "x$enable_bittorrent_requested" = "xyes"; then
    ARIA2_FET_NOT_SUPPORTED([bittorrent])
  fi
  enable_bittorrent=no
  AM_CONDITIONAL([ENABLE_BITTORRENT], false)
fi

if (test "x$have_libxml2" = "xyes" || test "x$have_libexpat" = "xyes") &&
   test "x$enable_metalink" = "xyes"; then
  AC_DEFINE([ENABLE_METALINK], [1],
            [Define to 1 if Metalink support is enabled.])
  AM_CONDITIONAL([ENABLE_METALINK], true)
else
  if test "x$enable_metalink_requested" = "xyes"; then
    ARIA2_FET_NOT_SUPPORTED([metalink])
  fi
  enable_metalink=no
  AM_CONDITIONAL([ENABLE_METALINK], false)
fi

AM_CONDITIONAL([HAVE_SOME_XMLLIB],
  [test "x$have_libxml2" = "xyes" || test "x$have_libexpat" = "xyes"])

if test "x$have_libxml2" = "xyes" || test "x$have_libexpat" = "xyes"; then
  enable_xml_rpc=yes
699 700
else
  enable_xml_rpc=no
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
fi

if test "x$enable_xml_rpc" = "xyes"; then
  AC_DEFINE([ENABLE_XML_RPC], [1],
            [Define to 1 if XML-RPC support is enabled.])
fi
AM_CONDITIONAL([ENABLE_XML_RPC], [test "x$enable_xml_rpc" = "xyes"])

AM_CONDITIONAL([HAVE_LIBXML2], [test "x$have_libxml2" = "xyes"])
AM_CONDITIONAL([HAVE_LIBEXPAT], [test "x$have_libexpat" = "xyes"])

if test "x$have_libcares" = "xyes"; then
  AC_DEFINE([ENABLE_ASYNC_DNS], [1],
            [Define to 1 if asynchronous DNS support is enabled.])
  AM_CONDITIONAL([ENABLE_ASYNC_DNS], true)
else
  AM_CONDITIONAL([ENABLE_ASYNC_DNS], false)
fi

# Set conditional for libz
AM_CONDITIONAL([HAVE_ZLIB], [test "x$have_zlib" = "xyes"])

# Set conditional for sqlite3
AM_CONDITIONAL([HAVE_SQLITE3], [test "x$have_sqlite3" = "xyes"])

726 727
# Set conditional for libssh2
AM_CONDITIONAL([HAVE_LIBSSH2], [test "x$have_libssh2" = "xyes"])
728

729
case "$host" in
730
  *solaris*)
731 732 733 734 735
    save_LIBS=$LIBS
    LIBS=
    AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [$save_LIBS])
    EXTRALIBS="$LIBS $EXTRALIBS"
    LIBS=$save_LIBS
736
    ;;
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
esac

# Checks for header files.
AC_FUNC_ALLOCA
AC_HEADER_STDC

AC_CHECK_HEADERS([argz.h \
                  arpa/inet.h \
                  fcntl.h \
                  float.h \
                  inttypes.h \
                  langinfo.h \
                  libintl.h \
                  limits.h \
                  locale.h \
                  malloc.h \
                  netdb.h \
                  netinet/in.h \
755
                  netinet/tcp.h \
756 757 758
                  poll.h \
                  port.h \
                  signal.h \
759 760 761 762 763 764 765 766
                  stddef.h \
                  stdint.h \
                  stdio_ext.h \
                  stdlib.h \
                  string.h \
                  strings.h \
                  sys/ioctl.h \
                  sys/param.h \
767
                  sys/resource.h \
768
                  sys/signal.h \
769 770
                  sys/socket.h \
                  sys/time.h \
771
                  sys/types.h \
772
                  sys/uio.h \
773
                  sys/utsname.h \
774 775
                  termios.h \
                  unistd.h \
776
                  utime.h \
777
                  wchar.h \
778 779
                  ifaddrs.h \
                  pwd.h])
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_INT8_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_TYPE_PID_T
AC_C_VOLATILE
801 802
AC_CHECK_TYPES([ptrdiff_t])
AC_CHECK_TYPE([struct timespec], [have_timespec=yes], [have_timespec=no])
803 804 805
AC_C_BIGENDIAN
AC_SYS_LARGEFILE

806 807 808 809 810
if test "x$have_timespec" = "xyes"; then
  AC_DEFINE([HAVE_A2_STRUCT_TIMESPEC], [1],
            [Define to 1 if the system has the type `struct timespec'.])
fi

811
# Checks for library functions.
812
AM_GNU_GETTEXT([external])
813 814 815 816 817 818 819 820 821 822 823 824
AM_GNU_GETTEXT_VERSION([0.18])
AC_FUNC_ERROR_AT_LINE
AC_PROG_GCC_TRADITIONAL

AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STAT
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_FUNC_FORK
AC_FUNC_STRTOD
825 826 827
# Don't use AC_FUNC_MMAP becaue it fails on some platforms (e.g.,
# OpenWRT) which have mmap and it works in the way we use in aria2.
# Instead use mmap in AC_CHECK_FUNCS list.
828 829 830 831 832 833 834 835
AC_CHECK_FUNCS([__argz_count \
                __argz_next \
                __argz_stringify \
                atexit \
                ftruncate \
                getcwd \
                gethostbyaddr \
                gethostbyname \
836
                getifaddrs \
837
                getpagesize \
838
                getrandom \
839 840 841 842 843
                memchr \
                memmove \
                mempcpy \
                memset \
                mkdir \
844
                mmap \
845 846
                munmap \
                nl_langinfo \
847
                posix_fadvise \
848
                posix_memalign \
849
                pow \
850 851 852 853
                putenv \
                rmdir \
                select \
                setlocale \
854
                sigaction \
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
                sleep \
                socket \
                stpcpy \
                strcasecmp \
                strchr \
                strcspn \
                strdup \
                strerror \
                strncasecmp \
                strstr \
                strtol \
                strtoul \
                strtoull \
                tzset \
                unsetenv \
                usleep \
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
                utime \
                utimes])

AC_MSG_CHECKING([for getrandom linux syscall interface])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
#include <linux/random.h>
]],
[[
int x = GRND_NONBLOCK;
int y = (int)SYS_getrandom;
]])],
  [have_getrandom_interface=yes
   AC_DEFINE([HAVE_GETRANDOM_INTERFACE], [1], [Define to 1 if getrandom linux syscall interface is available.])],
  [have_getrandom_interface=no])
AC_MSG_RESULT([$have_getrandom_interface])
AM_CONDITIONAL([HAVE_GETRANDOM_INTERFACE], [test "x$have_getrandom_interface" = "xyes"])
888

889 890 891 892 893 894 895 896 897
dnl Put tcmalloc/jemalloc checks after the posix_memalign check.
dnl These libraries may implement posix_memalign, while the usual CRT may not
dnl (e.g. mingw). Since we aren't including the corresponding library headers
dnl this will lead to undefined posix_memalign() errors when compiling
if test "x$with_tcmalloc_requested" = "xyes" &&
   test "x$with_jemalloc_requested" = "xyes"; then
  AC_MSG_FAILURE([Cannot use both, tcmalloc and jemalloc!])
fi

898
have_tcmalloc=no
899 900 901 902
if test "x$with_tcmalloc" = "xyes"; then
  dnl Important: put malloc libs at the very end.
  dnl Only newish versions have a .pc, thus try CHECK_LIB as well.
  PKG_CHECK_MODULES([TCMALLOC], [libtcmalloc_minimal], [have_tcmalloc=yes], [have_tcmalloc=no])
903
  if test "x$have_tcmalloc" != "xyes"; then
904 905
    AC_CHECK_LIB([tcmalloc_minimal], [malloc], [have_tcmalloc=yes], [have_tcmalloc=no])
    if test "x$have_tcmalloc" = "xyes"; then
906 907 908 909
      TCMALLOC_CFLAGS=
      TCMALLOC_LIBS="-ltcmalloc_minimal"
      AC_SUBST([TCMALLOC_CFLAGS])
      AC_SUBST([TCMALLOC_LIBS])
910 911 912 913 914 915 916 917
    else
      if test "x$with_tcmalloc_requested" = "xyes"; then
        ARIA2_DEP_NOT_MET([tcmalloc_minimal])
      fi
    fi
  fi
fi

918 919
have_jemalloc=no
if test "x$with_jemalloc" = "xyes"; then
920 921 922 923
  dnl Important: put malloc libs at the very end.
  dnl Usually jemalloc does not come with a .pc, as the official source does not
  dnl generate one.
  PKG_CHECK_MODULES([JEMALLOC], [jemalloc], [have_jemalloc=yes], [have_jemalloc=no])
924
  if test "x$have_jemalloc" != "xyes"; then
925 926
    AC_CHECK_LIB([jemalloc], [malloc], [have_jemalloc=yes], [have_jemalloc=no])
    if test "x$have_jemalloc" = "xyes"; then
927 928 929 930
      JEMALLOC_CFLAGS=
      JEMALLOC_LIBS="-ljemalloc"
      AC_SUBST([JEMALLOC_CFLAGS])
      AC_SUBST([JEMALLOC_LIBS])
931 932 933 934 935 936 937 938
    else
      if test "x$with_jemalloc_requested" = "xyes"; then
        ARIA2_DEP_NOT_MET([jemalloc (unprefixed)])
      fi
    fi
  fi
fi

939
have_epoll=no
940 941 942 943 944 945 946 947 948 949 950 951
if test "x$enable_epoll" = "xyes"; then
  AC_CHECK_FUNCS([epoll_create], [have_epoll=yes])
  if test "x$have_epoll" = "xyes"; then
    AC_DEFINE([HAVE_EPOLL], [1], [Define to 1 if epoll is available.])
  fi
fi
AM_CONDITIONAL([HAVE_EPOLL], [test "x$have_epoll" = "xyes"])

AC_CHECK_FUNCS([posix_fallocate],[have_posix_fallocate=yes])
ARIA2_CHECK_FALLOCATE
if test "x$have_posix_fallocate" = "xyes" ||
   test "x$have_fallocate" = "xyes" ||
952
   test "x$have_osx" = "xyes" ||
953 954 955 956 957 958
   test "x$win_build" = "xyes"; then
  AC_DEFINE([HAVE_SOME_FALLOCATE], [1],
            [Define to 1 if *_fallocate is available.])
fi
AM_CONDITIONAL([HAVE_SOME_FALLOCATE],
  [test "x$have_posix_fallocate" = "xyes" || test "x$have_fallocate" = "xyes" \
959
  || test "x$have_osx" = "xyes" || test "x$win_build" = "xyes"])
960

961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
# mingw needs this
save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $EXTRACPPFLAGS"
AC_MSG_CHECKING([for asctime_r])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    #include <time.h>
  ]], [[
    struct tm r; char *c;
    asctime_r(&r, c);
  ]])],
  [AM_CONDITIONAL([HAVE_ASCTIME_R], true)
   AC_MSG_RESULT([yes])
   AC_DEFINE([HAVE_ASCTIME_R], [1], [Define to 1 if you have the `asctime_r' function or macro.])],
  [AC_MSG_RESULT([no])
   AM_CONDITIONAL([HAVE_ASCTIME_R], false)])

AC_MSG_CHECKING([for localtime_r])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    #include <time.h>
  ]], [[
    time_t t; struct tm r;
    localtime_r(&t, &r);
  ]])],
  [AM_CONDITIONAL([HAVE_LOCALTIME_R], true)
   AC_MSG_RESULT([yes])
   AC_DEFINE([HAVE_LOCALTIME_R], [1], [Define to 1 if you have the `localtime_r' function or macro.])],
  [AC_MSG_RESULT([no])
   AM_CONDITIONAL([HAVE_LOCALTIME_R], false)])
CPPFLAGS=$save_CPPFLAGS
990 991

AC_CHECK_FUNCS([basename],
992 993
        [AM_CONDITIONAL([HAVE_BASENAME], true)],
        [AM_CONDITIONAL([HAVE_BASENAME], false)])
994
AC_CHECK_FUNCS([gai_strerror],
995 996
        [AM_CONDITIONAL([HAVE_GAI_STRERROR], true)],
        [AM_CONDITIONAL([HAVE_GAI_STRERROR], false)])
997
AC_CHECK_FUNCS([getaddrinfo],
998 999
        [AM_CONDITIONAL([HAVE_GETADDRINFO], true)],
        [AM_CONDITIONAL([HAVE_GETADDRINFO], false)])
1000
AC_CHECK_FUNCS([gettimeofday],
1001 1002
        [AM_CONDITIONAL([HAVE_GETTIMEOFDAY], true)],
        [AM_CONDITIONAL([HAVE_GETTIMEOFDAY], false)])
1003
AC_CHECK_FUNCS([strptime],
1004 1005
        [AM_CONDITIONAL([HAVE_STRPTIME], true)],
        [AM_CONDITIONAL([HAVE_STRPTIME], false)])
1006 1007 1008 1009 1010 1011
AC_CHECK_FUNCS([daemon], [have_daemon=yes])
AM_CONDITIONAL([HAVE_DAEMON], [test "x$have_daemon" = "xyes"])

AC_CHECK_FUNCS([poll], [have_poll=yes])
AM_CONDITIONAL([HAVE_POLL], [test "x$have_poll" = "xyes"])

1012
case "$host" in
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
  *mingw*)
    AM_CONDITIONAL([MINGW_BUILD], true)
    dnl defined in ws2tcpip.h, but only if _WIN32_WINNT >= 0x0501
    AM_CONDITIONAL([HAVE_GETADDRINFO], true)
    dnl defined in ws2tcpip.h, but missing in C:\mingw\lib\libws2_32.a
    AM_CONDITIONAL([HAVE_GAI_STRERROR], false)
    ;;
  *)
    AM_CONDITIONAL([MINGW_BUILD], false)
    ;;
esac

1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
case "$host" in
  *android*)
    # timegm is not declared with Android NDK r12b
    AM_CONDITIONAL([HAVE_TIMEGM], false)
    ;;
  *)
    AC_CHECK_FUNCS([timegm],
        [AM_CONDITIONAL([HAVE_TIMEGM], true)],
        [AM_CONDITIONAL([HAVE_TIMEGM], false)])
    ;;
esac

1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
AC_CHECK_FUNCS([port_associate], [have_port_associate=yes])
AM_CONDITIONAL([HAVE_PORT_ASSOCIATE], [test "x$have_port_associate" = "xyes"])

AC_CHECK_FUNCS([kqueue], [have_kqueue=yes])
AM_CONDITIONAL([HAVE_KQUEUE], [test "x$have_kqueue" = "xyes"])
if test "x$have_kqueue" = "xyes"; then
    AC_MSG_CHECKING([whether struct kevent.udata is intptr_t])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
]],
[[
struct kevent event;
event.udata = reinterpret_cast<intptr_t>(&event);
]])],
    [kevent_udata_intptr_t=yes], [kevent_udata_intptr_t=no])
    AC_MSG_RESULT([$kevent_udata_intptr_t])
    if test "x$kevent_udata_intptr_t" = "xyes"; then
       AC_DEFINE([KEVENT_UDATA_INTPTR_T], [1], [Define to 1 if struct kevent.udata is intptr_t])
    fi
fi

AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
                [AC_DEFINE([HAVE_SOCKADDR_IN_SIN_LEN],[1],
                  [Define to 1 if struct sockaddr_in has sin_len member.])],
                [],
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
                [[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
]])

AC_CHECK_MEMBER([struct sockaddr_in6.sin6_len],
                [AC_DEFINE([HAVE_SOCKADDR_IN6_SIN6_LEN],[1],
                  [Define to 1 if struct sockaddr_in6 has sin6_len member.])],
                [],
                [[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
]])
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098

# Check struct option.name is assignable from const char*.  struct
# option.name in opensolaris is of type char*. In Linux, it is const
# char*
AC_MSG_CHECKING([whether struct option.name is assignable from const char*])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <unistd.h>
#include <getopt.h>
]],
[[
const char* s = "const char";
option op;
op.name = s;
]])],
[have_option_const_name=yes], [have_option_const_name=no])
AC_MSG_RESULT([$have_option_const_name])
if test "x$have_option_const_name" = "xyes"; then
  AC_DEFINE([HAVE_OPTION_CONST_NAME], [1], [Define 1 if struct option.name is const char*])
fi

1099 1100
if test "x$enable_websocket" = "xyes"; then
  AC_CONFIG_SUBDIRS([deps/wslay])
1101 1102 1103
  enable_websocket=yes
  AC_DEFINE([ENABLE_WEBSOCKET], [1],
            [Define 1 if WebSocket support is enabled.])
1104 1105
  # $(top_srcdir) for `make distcheck`
  WSLAY_CFLAGS="-I\$(top_builddir)/deps/wslay/lib/includes -I\$(top_srcdir)/deps/wslay/lib/includes"
1106
  WSLAY_LIBS="\$(top_builddir)/deps/wslay/lib/libwslay.la"
1107
  AC_SUBST([WSLAY_CFLAGS])
1108
  AC_SUBST([WSLAY_LIBS])
1109 1110 1111
fi
AM_CONDITIONAL([ENABLE_WEBSOCKET], [test "x$enable_websocket" = "xyes"])

1112 1113
AM_CONDITIONAL([ENABLE_LIBARIA2], [test "x$enable_libaria2" = "xyes"])

1114 1115
AC_SUBST([bashcompletiondir])

1116 1117
case "$host" in
  *android*)
1118
    android=yes
1119
    LIBS="$LIBS -lstdc++ -lsupc++"
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
    case "$host" in
      arm-*)
        android_arm=yes
        ;;
      mipsel-*)
        android_mips=yes
        ;;
      i686-*)
        android_x86=yes
        ;;
    esac
1131 1132 1133 1134 1135
    ;;
  *)
    ;;
esac

1136
AM_CONDITIONAL([ANDROID], [test "x$android" = "xyes"])
1137 1138 1139 1140
AM_CONDITIONAL([ANDROID_ARM], [test "x$android_arm" = "xyes"])
AM_CONDITIONAL([ANDROID_MIPS], [test "x$android_mips" = "xyes"])
AM_CONDITIONAL([ANDROID_X86], [test "x$android_x86" = "xyes"])

1141
if test "x$ARIA2_STATIC" = "xyes"; then
1142 1143
  # -static-libgcc and -static-libstdc++ are linker flags and not for
  # libtool.
1144
  EXTRALDFLAGS="$EXTRALDFLAGS -all-static"
1145
  dnl For non-MinGW build, we need additional libs for static build.
1146 1147 1148 1149 1150
  case "$host" in
    *mingw*|*msvc*|*darwin*)
    ;;

    *)
1151
      EXTRALIBS="$EXTRALIBS -lpthread -ldl -lrt"
1152 1153 1154 1155 1156 1157
    ;;
  esac
fi

if test "x$win_build" = "xyes" && test "x$enable_libaria2" = "xyes"; then
  # Creating dll needs this
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
  EXTRALDFLAGS="$EXTRALDFLAGS -no-undefined"
fi

AC_SUBST([EXTRACFLAGS])
AC_SUBST([EXTRACXXFLAGS])
AC_SUBST([EXTRACPPFLAGS])
AC_SUBST([EXTRALDFLAGS])
AC_SUBST([EXTRALIBS])

save_CXXFLAGS=$CXXFLAGS
CXXFLAGS=

if test "x$enable_werror" = "xyes"; then
  AX_CHECK_COMPILE_FLAG([-Wall], [CXXFLAGS="$CXXFLAGS -Wall"])
  AX_CHECK_COMPILE_FLAG([-Werror], [CXXFLAGS="$CXXFLAGS -Werror"])
  AX_CHECK_COMPILE_FLAG([-Wformat-security], [CXXFLAGS="$CXXFLAGS -Wformat-security"])
1174 1175
fi

1176 1177 1178 1179 1180
WARNCXXFLAGS=$CXXFLAGS
CXXFLAGS=$save_CXXFLAGS

AC_SUBST([WARNCXXFLAGS])

1181
AC_CONFIG_FILES([Makefile
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
                src/Makefile
                src/libaria2.pc
                src/includes/Makefile
                test/Makefile
                po/Makefile.in
                lib/Makefile
                doc/Makefile
                doc/manual-src/Makefile
                doc/manual-src/en/Makefile
                doc/manual-src/en/conf.py
                doc/manual-src/ru/Makefile
                doc/manual-src/ru/conf.py
                doc/manual-src/pt/Makefile
                doc/manual-src/pt/conf.py
                deps/Makefile])
1197 1198
AC_OUTPUT

1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
AC_MSG_NOTICE([summary of build options:

Build:          $build
Host:           $host
Target:         $target
Install prefix: $prefix
CC:             $CC
CXX:            $CXX
CPP:            $CPP
CXXFLAGS:       $CXXFLAGS
CFLAGS:         $CFLAGS
CPPFLAGS:       $CPPFLAGS
LDFLAGS:        $LDFLAGS
LIBS:           $LIBS
DEFS:           $DEFS
CXX1XCXXFLAGS:  $CXX1XCXXFLAGS
EXTRACXXFLAGS:  $EXTRACXXFLAGS
EXTRACFLAGS:    $EXTRACFLAGS
EXTRACPPFLAGS:  $EXTRACPPFLAGS
EXTRALDFLAGS:   $EXTRALDFLAGS
EXTRALIBS:      $EXTRALIBS
WARNCXXFLAGS:   $WARNCXXFLAGS
LibUV:          $have_libuv (CFLAGS='$LIBUV_CFLAGS' LIBS='$LIBUV_LIBS')
SQLite3:        $have_sqlite3 (CFLAGS='$SQLITE3_CFLAGS' LIBS='$SQLITE3_LIBS')
SSL Support:    $have_ssl
AppleTLS:       $have_appletls (LDFLAGS='$APPLETLS_LDFLAGS')
WinTLS:         $have_wintls (LIBS='$WINTLS_LIBS')
GnuTLS:         $have_libgnutls (CFLAGS='$LIBGNUTLS_CFLAGS' LIBS='$LIBGNUTLS_LIBS')
OpenSSL:        $have_openssl (CFLAGS='$OPENSSL_CFLAGS' LIBS='$OPENSSL_LIBS')
CA Bundle:      $ca_bundle
LibNettle:      $have_libnettle (CFLAGS='$LIBNETTLE_CFLAGS' LIBS='$LIBNETTLE_LIBS')
LibGmp:         $have_libgmp (CFLAGS='$LIBGMP_CFLAGS' LIBS='$LIBGMP_LIBS')
LibGcrypt:      $have_libgcrypt (CFLAGS='$LIBGCRYPT_CFLAGS' LIBS='$LIBGCRYPT_LIBS')
LibXML2:        $have_libxml2 (CFLAGS='$XML_CPPFLAGS' LIBS='$XML_LIBS')
LibExpat:       $have_libexpat (CFLAGS='$EXPAT_CFLAGS' LIBS='$EXPAT_LIBS')
LibCares:       $have_libcares (CFLAGS='$LIBCARES_CFLAGS' LIBS='$LIBCARES_LIBS')
Zlib:           $have_zlib (CFLAGS='$ZLIB_CFLAGS' LIBS='$ZLIB_LIBS')
Libssh2:        $have_libssh2 (CFLAGS='$LIBSSH2_CFLAGS' LIBS='$LIBSSH2_LIBS')
Tcmalloc:       $have_tcmalloc (CFLAGS='$TCMALLOC_CFLAGS' LIBS='$TCMALLOC_LIBS')
Jemalloc:       $have_jemalloc (CFLAGS='$JEMALLOC_CFLAGS' LIBS='$JEMALLOC_LIBS')
Epoll:          $have_epoll
Bittorrent:     $enable_bittorrent
Metalink:       $enable_metalink
XML-RPC:        $enable_xml_rpc
Message Digest: $use_md
WebSocket:      $enable_websocket (CFLAGS='$WSLAY_CFLAGS' LIBS='$WSLAY_LIBS')
Libaria2:       $enable_libaria2 (shared=${enable_shared} static=${enable_static})
bash_completion dir: $bashcompletiondir
Static build:   $ARIA2_STATIC
])