Blame SOURCES/libsodium-1.0.18/configure.ac

ca16be
AC_PREREQ([2.65])
ca16be
AC_INIT([libsodium],[1.0.18],
ca16be
  [https://github.com/jedisct1/libsodium/issues],
ca16be
  [libsodium],
ca16be
  [https://github.com/jedisct1/libsodium])
ca16be
AC_CONFIG_AUX_DIR([build-aux])
ca16be
AC_CONFIG_MACRO_DIR([m4])
ca16be
AC_CONFIG_SRCDIR([src/libsodium/sodium/version.c])
ca16be
AC_CANONICAL_HOST
ca16be
AM_INIT_AUTOMAKE([1.11 dist-bzip2 tar-ustar foreign subdir-objects])
ca16be
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
ca16be
AM_MAINTAINER_MODE
ca16be
AM_DEP_TRACK
ca16be
ca16be
AC_SUBST(VERSION)
ca16be
ca16be
SODIUM_LIBRARY_VERSION_MAJOR=10
ca16be
SODIUM_LIBRARY_VERSION_MINOR=3
ca16be
DLL_VERSION=24
ca16be
SODIUM_LIBRARY_VERSION=26:0:3
ca16be
#                       | | |
ca16be
#                +------+ | +---+
ca16be
#                |        |     |
ca16be
#             current:revision:age
ca16be
#                |        |     |
ca16be
#                |        |     +- increment if interfaces have been added
ca16be
#                |        |        set to zero if interfaces have been removed
ca16be
#                |        |        or changed
ca16be
#                |        +- increment if source code has changed
ca16be
#                |           set to zero if current is incremented
ca16be
#                +- increment if interfaces have been added, removed or changed
ca16be
AC_SUBST(SODIUM_LIBRARY_VERSION_MAJOR)
ca16be
AC_SUBST(SODIUM_LIBRARY_VERSION_MINOR)
ca16be
AC_SUBST(SODIUM_LIBRARY_VERSION)
ca16be
AC_SUBST(DLL_VERSION)
ca16be
ca16be
AC_LANG_ASSERT(C)
ca16be
LX_CFLAGS=${CFLAGS-NONE}
ca16be
PKGCONFIG_LIBS_PRIVATE=""
ca16be
ca16be
dnl Path check
ca16be
ca16be
AS_IF([pwd | fgrep ' ' > /dev/null 2>&1],
ca16be
  [AC_MSG_ERROR([The build directory contains whitespaces - This can cause tests/installation to fail due to limitations of some libtool versions])]
ca16be
)
ca16be
ca16be
dnl Switches
ca16be
ca16be
AC_ARG_ENABLE(ssp,
ca16be
[AS_HELP_STRING(--disable-ssp,Do not compile with -fstack-protector)],
ca16be
[
ca16be
  AS_IF([test "x$enableval" = "xno"], [
ca16be
    enable_ssp="no"
ca16be
  ], [
ca16be
    enable_ssp="yes"
ca16be
  ])
ca16be
],
ca16be
[
ca16be
  enable_ssp="yes"
ca16be
])
ca16be
ca16be
AC_ARG_ENABLE(asm,
ca16be
[AS_HELP_STRING(--disable-asm,[Do not compile assembly code -- As a side effect, this disables CPU-specific implementations on non-Windows platforms. Only for use with targets such as WebAssembly.])],
ca16be
[
ca16be
  AS_IF([test "x$enableval" = "xno"], [
ca16be
    enable_asm="no"
ca16be
  ], [
ca16be
    enable_asm="yes"
ca16be
  ])
ca16be
],
ca16be
[
ca16be
  enable_asm="yes"
ca16be
])
ca16be
ca16be
AS_IF([test "x$EMSCRIPTEN" != "x"], [
ca16be
  AX_CHECK_COMPILE_FLAG([-s ASSERTIONS=0], [
ca16be
    enable_asm="no"
ca16be
    AC_MSG_WARN([compiling to JavaScript - asm implementations disabled])
ca16be
  ], [
ca16be
    AC_MSG_WARN([EMSCRIPTEN environment variable defined, but emcc doesn't appear to be used - Assuming compilation to native code])
ca16be
    CFLAGS="$CFLAGS -U__EMSCRIPTEN__"
ca16be
    unset EMSCRIPTEN
ca16be
  ])
ca16be
])
ca16be
ca16be
AC_ARG_ENABLE(pie,
ca16be
[AS_HELP_STRING(--disable-pie,Do not produce position independent executables)],
ca16be
 enable_pie=$enableval, enable_pie="maybe")
ca16be
ca16be
AS_CASE([$host_os], [mingw*|cygwin*|msys], [enable_pie="no"])
ca16be
ca16be
AC_ARG_ENABLE(blocking-random,
ca16be
[AS_HELP_STRING(--enable-blocking-random,Enable this switch only if /dev/urandom is totally broken on the target platform)],
ca16be
[
ca16be
  AS_IF([test "x$enableval" = "xyes"], [
ca16be
    AC_DEFINE([USE_BLOCKING_RANDOM], [1], [/dev/urandom is insecure on the target platform])
ca16be
  ])
ca16be
])
ca16be
ca16be
AC_ARG_ENABLE(minimal,
ca16be
[AS_HELP_STRING(--enable-minimal,
ca16be
  [Only compile the minimum set of functions required for the high-level API])],
ca16be
[
ca16be
  AS_IF([test "x$enableval" = "xyes"], [
ca16be
    enable_minimal="yes"
ca16be
    SODIUM_LIBRARY_MINIMAL_DEF="#define SODIUM_LIBRARY_MINIMAL 1"
ca16be
    AC_DEFINE([MINIMAL], [1], [Define for a minimal build, without deprecated functions and functions that high-level APIs depend on])
ca16be
  ], [
ca16be
    enable_minimal="no"
ca16be
  ])
ca16be
],
ca16be
[
ca16be
  enable_minimal="no"
ca16be
])
ca16be
AM_CONDITIONAL([MINIMAL], [test x$enable_minimal = xyes])
ca16be
AC_SUBST(SODIUM_LIBRARY_MINIMAL_DEF)
ca16be
ca16be
AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads],
ca16be
 [use pthreads library, or --without-pthreads to disable threading support.]),
ca16be
 [ ], [withval="yes"])
ca16be
ca16be
AS_IF([test "x$withval" = "xyes"], [
ca16be
  AX_PTHREAD([
ca16be
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
ca16be
        #include <pthread.h>
ca16be
      ]], [[
ca16be
        pthread_mutex_t mutex;
ca16be
ca16be
        pthread_mutex_lock(&mutex);
ca16be
        pthread_mutex_unlock(&mutex)
ca16be
      ]]
ca16be
    )], [
ca16be
        AC_DEFINE([HAVE_PTHREAD], [1], [Define if you have POSIX threads libraries and header files])
ca16be
        with_threads="yes"
ca16be
        LIBS="$PTHREAD_LIBS $LIBS"
ca16be
        PKGCONFIG_LIBS_PRIVATE="$PTHREAD_LIBS $PTHREAD_CFLAGS $PKGCONFIG_LIBS_PRIVATE"
ca16be
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
ca16be
        CC="$PTHREAD_CC"
ca16be
      ])
ca16be
    ],
ca16be
    [ AC_MSG_NOTICE(pthread mutexes are not available) ]
ca16be
  )
ca16be
], [with_threads="no"])
ca16be
ca16be
AC_ARG_WITH(safecode,
ca16be
[AS_HELP_STRING(--with-safecode,For maintainers only - please do not use)],
ca16be
[AS_IF([test "x$withval" = "xyes"], [
ca16be
    AC_ARG_VAR([SAFECODE_HOME], [set to the safecode base directory])
ca16be
    : ${SAFECODE_HOME:=/opt/safecode}
ca16be
    LDFLAGS="$LDFLAGS -L${SAFECODE_HOME}/lib"
ca16be
    LIBS="$LIBS -lsc_dbg_rt -lpoolalloc_bitmap -lstdc++"
ca16be
    CFLAGS="$CFLAGS -fmemsafety"
ca16be
  ])
ca16be
])
ca16be
ca16be
AC_ARG_WITH(ctgrind,
ca16be
[AS_HELP_STRING(--with-ctgrind,For maintainers only - please do not use)],
ca16be
[AS_IF([test "x$withval" = "xyes"], [
ca16be
    AC_CHECK_LIB(ctgrind, ct_poison)
ca16be
  ])
ca16be
])
ca16be
ca16be
AC_ARG_ENABLE(retpoline,
ca16be
[AS_HELP_STRING(--enable-retpoline,Use return trampolines for indirect calls)],
ca16be
[AS_IF([test "x$enableval" = "xyes"], [
ca16be
  AX_CHECK_COMPILE_FLAG([-mindirect-branch=thunk-inline],
ca16be
    [CFLAGS="$CFLAGS -mindirect-branch=thunk-inline"],
ca16be
    [AX_CHECK_COMPILE_FLAG([-mretpoline], [CFLAGS="$CFLAGS -mretpoline"])]
ca16be
  )
ca16be
  AX_CHECK_COMPILE_FLAG([-mindirect-branch-register])
ca16be
  ])
ca16be
])
ca16be
ca16be
ENABLE_CWFLAGS=no
ca16be
AC_ARG_ENABLE(debug,
ca16be
[AS_HELP_STRING(--enable-debug,For maintainers only - please do not use)],
ca16be
[
ca16be
  AS_IF([test "x$enableval" = "xyes"], [
ca16be
    AS_IF([test "x$LX_CFLAGS" = "xNONE"], [
ca16be
      nxflags=""
ca16be
      for flag in `echo $CFLAGS`; do
ca16be
        AS_CASE([$flag],
ca16be
          [-O*], [ ],
ca16be
          [-g*], [ ],
ca16be
          [*], [AS_VAR_APPEND([nxflags], [" $flag"])])
ca16be
      done
ca16be
      CFLAGS="$nxflags -O -g3"
ca16be
    ])
ca16be
    ENABLE_CWFLAGS=yes
ca16be
    CPPFLAGS="$CPPFLAGS -DDEBUG=1 -U_FORTIFY_SOURCE"
ca16be
  ])
ca16be
])
ca16be
ca16be
AC_ARG_ENABLE(opt,
ca16be
[AS_HELP_STRING(--enable-opt,Optimize for the native CPU - The resulting library will be faster but not portable)],
ca16be
[
ca16be
  AS_IF([test "x$enableval" = "xyes"], [
ca16be
    AX_CHECK_COMPILE_FLAG([-Ofast], [CFLAGS="$CFLAGS -Ofast"])
ca16be
    AX_CHECK_COMPILE_FLAG([-ftree-vectorize], [CFLAGS="$CFLAGS -ftree-vectorize"])
ca16be
    AX_CHECK_COMPILE_FLAG([-ftree-slp-vectorize], [CFLAGS="$CFLAGS -ftree-slp-vectorize"])
ca16be
    AX_CHECK_COMPILE_FLAG([-fomit-frame-pointer], [CFLAGS="$CFLAGS -fomit-frame-pointer"])
ca16be
    AX_CHECK_COMPILE_FLAG([-march=native], [CFLAGS="$CFLAGS -march=native"])
ca16be
  ])
ca16be
])
ca16be
ca16be
AC_SUBST(MAINT)
ca16be
AC_SUBST(PKGCONFIG_LIBS_PRIVATE)
ca16be
ca16be
AX_VALGRIND_CHECK
ca16be
ca16be
dnl Checks
ca16be
ca16be
AC_PROG_CC_C99
ca16be
AM_PROG_AS
ca16be
AC_USE_SYSTEM_EXTENSIONS
ca16be
AC_C_VARARRAYS
ca16be
ca16be
AC_CHECK_DEFINE([__wasi__], [WASI="yes"], [])
ca16be
ca16be
AC_CHECK_DEFINE([_FORTIFY_SOURCE], [], [
ca16be
  AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=2],
ca16be
    [CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"])
ca16be
])
ca16be
ca16be
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
ca16be
  [CFLAGS="$CFLAGS -fvisibility=hidden"])
ca16be
ca16be
AS_CASE([$host_os], [cygwin*|mingw*|msys|pw32*|cegcc*], [ ], [
ca16be
  AX_CHECK_COMPILE_FLAG([-fPIC], [CFLAGS="$CFLAGS -fPIC"])
ca16be
])
ca16be
ca16be
AS_IF([test "$enable_pie" != "no"],[
ca16be
  AX_CHECK_COMPILE_FLAG([-fPIE], [
ca16be
    AX_CHECK_LINK_FLAG([-pie], [
ca16be
      [CFLAGS="$CFLAGS -fPIE"
ca16be
       LDFLAGS="$LDFLAGS -pie"]
ca16be
    ])
ca16be
  ])
ca16be
])
ca16be
ca16be
AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
ca16be
AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CFLAGS="$CFLAGS -fno-strict-overflow"], [
ca16be
  AX_CHECK_COMPILE_FLAG([-fwrapv], [CFLAGS="$CFLAGS -fwrapv"])
ca16be
])
ca16be
ca16be
AS_IF([test "$GCC" = "yes" ], [
ca16be
  AS_CASE([$host_cpu],
ca16be
    [i?86|amd64|x86_64], [
ca16be
      AC_COMPILE_IFELSE(
ca16be
        [AC_LANG_SOURCE([
ca16be
#if !defined(__clang__) && defined(__GNUC__) && ((__GNUC__ << 8) | __GNUC_MINOR__) < 0x403
ca16be
# error old gcc
ca16be
#endif
ca16be
int main(void) { return 0; }
ca16be
         ])],,[
ca16be
          AX_CHECK_COMPILE_FLAG([-flax-vector-conversions], [CFLAGS="$CFLAGS -flax-vector-conversions"])
ca16be
        ])
ca16be
      ]
ca16be
    )
ca16be
  ])
ca16be
ca16be
LIBTOOL_OLD_FLAGS="$LIBTOOL_EXTRA_FLAGS"
ca16be
LIBTOOL_EXTRA_FLAGS="$LIBTOOL_EXTRA_FLAGS -version-info $SODIUM_LIBRARY_VERSION"
ca16be
AC_ARG_ENABLE(soname-versions,
ca16be
  [AC_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for Android) (default: enabled)])],
ca16be
    [
ca16be
        AS_IF([test "x$enableval" = "xno"], [
ca16be
          LIBTOOL_EXTRA_FLAGS="$LIBTOOL_OLD_FLAGS -avoid-version"
ca16be
        ])
ca16be
    ]
ca16be
)
ca16be
ca16be
AS_CASE([$host_os],
ca16be
  [cygwin*|mingw*|msys|pw32*|cegcc*], [
ca16be
    AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
ca16be
    AX_CHECK_LINK_FLAG([-Wl,--high-entropy-va], [LDFLAGS="$LDFLAGS -Wl,--high-entropy-va"])
ca16be
    AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
ca16be
  ])
ca16be
ca16be
AS_CASE([$host_os],
ca16be
  [cygwin*|mingw*|msys|pw32*|cegcc*], [
ca16be
    AX_CHECK_COMPILE_FLAG([-fno-asynchronous-unwind-tables], [
ca16be
      [CFLAGS="$CFLAGS -fno-asynchronous-unwind-tables"]
ca16be
    ])
ca16be
])
ca16be
ca16be
AS_IF([test "x$enable_ssp" != "xno"],[
ca16be
ca16be
AS_CASE([$host_os],
ca16be
  [cygwin*|mingw*|msys|pw32*|cegcc*|haiku|none], [ ],
ca16be
  [*], [
ca16be
    AX_CHECK_COMPILE_FLAG([-fstack-protector], [
ca16be
      AX_CHECK_LINK_FLAG([-fstack-protector],
ca16be
        [CFLAGS="$CFLAGS -fstack-protector"]
ca16be
      )
ca16be
    ])
ca16be
  ])
ca16be
])
ca16be
ca16be
AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
ca16be
ca16be
AX_CHECK_COMPILE_FLAG([$CFLAGS -Wall], [CWFLAGS="$CFLAGS -Wall"])
ca16be
AX_CHECK_COMPILE_FLAG([$CFLAGS -Wextra], [CWFLAGS="$CFLAGS -Wextra"])
ca16be
ca16be
AC_MSG_CHECKING(for clang)
ca16be
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
ca16be
#ifndef __clang__
ca16be
#error Not clang
ca16be
#endif
ca16be
]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-warning-option],
ca16be
     [CWFLAGS="$CWFLAGS -Wno-unknown-warning-option"])
ca16be
  ],
ca16be
  [AC_MSG_RESULT(no)
ca16be
])
ca16be
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wbad-function-cast], [CWFLAGS="$CWFLAGS -Wbad-function-cast"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-qual], [CWFLAGS="$CWFLAGS -Wcast-qual"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wdiv-by-zero], [CWFLAGS="$CWFLAGS -Wdiv-by-zero"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wduplicated-branches], [CWFLAGS="$CWFLAGS -Wduplicated-branches"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wduplicated-cond], [CWFLAGS="$CWFLAGS -Wduplicated-cond"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wfloat-equal], [CWFLAGS="$CWFLAGS -Wfloat-equal"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wformat=2], [CWFLAGS="$CWFLAGS -Wformat=2"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wlogical-op], [CWFLAGS="$CWFLAGS -Wlogical-op"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmaybe-uninitialized], [CWFLAGS="$CWFLAGS -Wmaybe-uninitialized"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmisleading-indentation], [CWFLAGS="$CWFLAGS -Wmisleading-indentation"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-declarations], [CWFLAGS="$CWFLAGS -Wmissing-declarations"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-prototypes], [CWFLAGS="$CWFLAGS -Wmissing-prototypes"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnested-externs], [CWFLAGS="$CWFLAGS -Wnested-externs"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-type-limits], [CWFLAGS="$CWFLAGS -Wno-type-limits"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-pragmas], [CWFLAGS="$CWFLAGS -Wno-unknown-pragmas"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnormalized=id], [CWFLAGS="$CWFLAGS -Wnormalized=id"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnull-dereference], [CWFLAGS="$CWFLAGS -Wnull-dereference"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wold-style-declaration], [CWFLAGS="$CWFLAGS -Wold-style-declaration"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wpointer-arith], [CWFLAGS="$CWFLAGS -Wpointer-arith"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wredundant-decls], [CWFLAGS="$CWFLAGS -Wredundant-decls"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wrestrict], [CWFLAGS="$CWFLAGS -Wrestrict"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wshorten-64-to-32], [CWFLAGS="$CWFLAGS -Wshorten-64-to-32"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wsometimes-uninitialized], [CWFLAGS="$CWFLAGS -Wsometimes-uninitialized"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wstrict-prototypes], [CWFLAGS="$CWFLAGS -Wstrict-prototypes"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])
ca16be
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wwrite-strings], [CWFLAGS="$CWFLAGS -Wwrite-strings"])
ca16be
ca16be
AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
ca16be
AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
ca16be
AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
ca16be
ca16be
AX_CHECK_CATCHABLE_SEGV
ca16be
AX_CHECK_CATCHABLE_ABRT
ca16be
ca16be
AS_IF([test "x$with_threads" = "xyes"], [
ca16be
  AX_TLS([AC_MSG_RESULT(thread local storage is supported)
ca16be
          AX_CHECK_COMPILE_FLAG([-ftls-model=local-dynamic],
ca16be
            [CFLAGS="$CFLAGS -ftls-model=local-dynamic"])],
ca16be
         [AC_MSG_RESULT(thread local storage is not supported)]) ])
ca16be
ca16be
LT_INIT
ca16be
AC_SUBST(LIBTOOL_DEPS)
ca16be
ca16be
AC_ARG_VAR([AR], [path to the ar utility])
ca16be
AC_CHECK_TOOL([AR], [ar], [ar])
ca16be
ca16be
dnl Checks for headers
ca16be
ca16be
AS_IF([test "x$EMSCRIPTEN" = "x"], [
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-mmmx], [CFLAGS="$CFLAGS -mmmx"])
ca16be
  AC_MSG_CHECKING(for MMX instructions set)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("mmx")
ca16be
#include <mmintrin.h>
ca16be
]], [[ __m64 x = _mm_setzero_si64(); ]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_MMINTRIN_H], [1], [mmx is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-mmmx], [CFLAGS_MMX="-mmmx"])],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-msse2], [CFLAGS="$CFLAGS -msse2"])
ca16be
  AC_MSG_CHECKING(for SSE2 instructions set)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("sse2")
ca16be
#ifndef __SSE2__
ca16be
# define __SSE2__
ca16be
#endif
ca16be
#include <emmintrin.h>
ca16be
]], [[ __m128d x = _mm_setzero_pd();
ca16be
       __m128i z = _mm_srli_epi64(_mm_setzero_si128(), 26); ]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_EMMINTRIN_H], [1], [sse2 is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-msse2], [CFLAGS_SSE2="-msse2"])],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-msse3], [CFLAGS="$CFLAGS -msse3"])
ca16be
  AC_MSG_CHECKING(for SSE3 instructions set)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("sse3")
ca16be
#include <pmmintrin.h>
ca16be
]], [[ __m128 x = _mm_addsub_ps(_mm_cvtpd_ps(_mm_setzero_pd()),
ca16be
                                _mm_cvtpd_ps(_mm_setzero_pd())); ]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_PMMINTRIN_H], [1], [sse3 is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-msse3], [CFLAGS_SSE3="-msse3"])],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-mssse3], [CFLAGS="$CFLAGS -mssse3"])
ca16be
  AC_MSG_CHECKING(for SSSE3 instructions set)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("ssse3")
ca16be
#include <tmmintrin.h>
ca16be
]], [[ __m64 x = _mm_abs_pi32(_m_from_int(0)); ]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-mssse3], [CFLAGS_SSSE3="-mssse3"])],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-msse4.1], [CFLAGS="$CFLAGS -msse4.1"])
ca16be
  AC_MSG_CHECKING(for SSE4.1 instructions set)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("sse4.1")
ca16be
#include <smmintrin.h>
ca16be
]], [[ __m128i x = _mm_minpos_epu16(_mm_setzero_si128()); ]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_SMMINTRIN_H], [1], [sse4.1 is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-msse4.1], [CFLAGS_SSE41="-msse4.1"])],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-mavx], [CFLAGS="$CFLAGS -mavx"])
ca16be
  AC_MSG_CHECKING(for AVX instructions set)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("avx")
ca16be
#include <immintrin.h>
ca16be
]], [[ _mm256_zeroall(); ]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_AVXINTRIN_H], [1], [AVX is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-mavx], [CFLAGS_AVX="-mavx"])],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-mavx2], [CFLAGS="$CFLAGS -mavx2"])
ca16be
  AC_MSG_CHECKING(for AVX2 instructions set)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("avx2")
ca16be
#include <immintrin.h>
ca16be
]], [[
ca16be
__m256 x = _mm256_set1_ps(3.14);
ca16be
__m256 y = _mm256_permutevar8x32_ps(x, _mm256_set1_epi32(42));
ca16be
return _mm256_movemask_ps(_mm256_cmp_ps(x, y, _CMP_NEQ_OQ));
ca16be
]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_AVX2INTRIN_H], [1], [AVX2 is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-mavx2], [CFLAGS_AVX2="-mavx2"])
ca16be
     AC_MSG_CHECKING(if _mm256_broadcastsi128_si256 is correctly defined)
ca16be
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("avx2")
ca16be
#include <immintrin.h>
ca16be
     ]], [[ __m256i y = _mm256_broadcastsi128_si256(_mm_setzero_si128()); ]])],
ca16be
       [AC_MSG_RESULT(yes)],
ca16be
       [AC_MSG_RESULT(no)
ca16be
        AC_DEFINE([_mm256_broadcastsi128_si256], [_mm_broadcastsi128_si256],
ca16be
                  [Define to the local name of _mm256_broadcastsi128_si256])])
ca16be
     ],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-mavx512f], [CFLAGS="$CFLAGS -mavx512f"])
ca16be
  AC_MSG_CHECKING(for AVX512F instructions set)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("avx512f")
ca16be
#include <immintrin.h>
ca16be
]], [[
ca16be
ca16be
#ifndef __AVX512F__
ca16be
# error No AVX512 support
ca16be
#elif defined(__clang__)
ca16be
# if __clang_major__ < 4
ca16be
#  error Compiler AVX512 support may be broken
ca16be
# endif
ca16be
#elif defined(__GNUC__)
ca16be
# if __GNUC__ < 6
ca16be
#  error Compiler AVX512 support may be broken
ca16be
# endif
ca16be
#endif
ca16be
ca16be
__m512i x = _mm512_setzero_epi32();
ca16be
__m512i y = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), x);
ca16be
]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_AVX512FINTRIN_H], [1], [AVX512F is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-mavx512f], [CFLAGS_AVX512F="-mavx512f"])],
ca16be
    [AC_MSG_RESULT(no)
ca16be
     AX_CHECK_COMPILE_FLAG([$CFLAGS -mno-avx512f],
ca16be
       [CFLAGS="$CFLAGS -mno-avx512f"])
ca16be
    ])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-maes], [CFLAGS="$CFLAGS -maes"])
ca16be
  AX_CHECK_COMPILE_FLAG([-mpclmul], [CFLAGS="$CFLAGS -mpclmul"])
ca16be
  AC_MSG_CHECKING(for AESNI instructions set and PCLMULQDQ)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("aes")
ca16be
#pragma GCC target("pclmul")
ca16be
#include <wmmintrin.h>
ca16be
]], [[ __m128i x = _mm_aesimc_si128(_mm_setzero_si128());
ca16be
       __m128i y = _mm_clmulepi64_si128(_mm_setzero_si128(), _mm_setzero_si128(), 0);]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_WMMINTRIN_H], [1], [aesni is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-maes], [CFLAGS_AESNI="-maes"])
ca16be
     AX_CHECK_COMPILE_FLAG([-mpclmul], [CFLAGS_PCLMUL="-mpclmul"])
ca16be
     ],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
  oldcflags="$CFLAGS"
ca16be
  AX_CHECK_COMPILE_FLAG([-mrdrnd], [CFLAGS="$CFLAGS -mrdrnd"])
ca16be
  AC_MSG_CHECKING(for RDRAND)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#pragma GCC target("rdrnd")
ca16be
#include <immintrin.h>
ca16be
]], [[ unsigned long long x; _rdrand64_step(&x); ]])],
ca16be
    [AC_MSG_RESULT(yes)
ca16be
     AC_DEFINE([HAVE_RDRAND], [1], [rdrand is available])
ca16be
     AX_CHECK_COMPILE_FLAG([-mrdrnd], [CFLAGS_RDRAND="-mrdrnd"])
ca16be
     ],
ca16be
    [AC_MSG_RESULT(no)])
ca16be
  CFLAGS="$oldcflags"
ca16be
ca16be
])
ca16be
ca16be
AC_SUBST(CFLAGS_MMX)
ca16be
AC_SUBST(CFLAGS_SSE2)
ca16be
AC_SUBST(CFLAGS_SSE3)
ca16be
AC_SUBST(CFLAGS_SSSE3)
ca16be
AC_SUBST(CFLAGS_SSE41)
ca16be
AC_SUBST(CFLAGS_AVX)
ca16be
AC_SUBST(CFLAGS_AVX2)
ca16be
AC_SUBST(CFLAGS_AVX512F)
ca16be
AC_SUBST(CFLAGS_AESNI)
ca16be
AC_SUBST(CFLAGS_PCLMUL)
ca16be
AC_SUBST(CFLAGS_RDRAND)
ca16be
ca16be
AC_CHECK_HEADERS([sys/mman.h sys/random.h intrin.h])
ca16be
ca16be
AC_MSG_CHECKING([if _xgetbv() is available])
ca16be
AC_LINK_IFELSE(
ca16be
  [AC_LANG_PROGRAM([[ #include <intrin.h> ]], [[ (void) _xgetbv(0) ]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AC_DEFINE([HAVE__XGETBV], [1], [_xgetbv() is available])],
ca16be
  [AC_MSG_RESULT(no)])
ca16be
ca16be
dnl Checks for typedefs, structures, and compiler characteristics.
ca16be
ca16be
AC_C_INLINE
ca16be
AS_CASE([$host_cpu],
ca16be
  [i?86|amd64|x86_64],
ca16be
    [ac_cv_c_bigendian=no]
ca16be
)
ca16be
AC_C_BIGENDIAN(
ca16be
  AC_DEFINE(NATIVE_BIG_ENDIAN, 1, [machine is bigendian]),
ca16be
  AC_DEFINE(NATIVE_LITTLE_ENDIAN, 1, [machine is littleendian]),
ca16be
  AC_MSG_ERROR([unknown endianness]),
ca16be
  AC_MSG_ERROR([universal endianness is not supported - compile separately and use lipo(1)])
ca16be
)
ca16be
ca16be
AC_MSG_CHECKING(whether __STDC_LIMIT_MACROS is required)
ca16be
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#include <limits.h>
ca16be
#include <stdint.h>
ca16be
]], [[
ca16be
(void) SIZE_MAX;
ca16be
(void) UINT64_MAX;
ca16be
]])],
ca16be
  [AC_MSG_RESULT(no)],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   CPPFLAGS="$CPPFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
ca16be
])
ca16be
ca16be
AC_MSG_CHECKING(whether we can use inline asm code)
ca16be
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
ca16be
]], [[
ca16be
int a = 42;
ca16be
int *pnt = &a;
ca16be
__asm__ __volatile__ ("" : : "r"(pnt) : "memory");
ca16be
]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AC_DEFINE([HAVE_INLINE_ASM], [1], [inline asm code can be used])]
ca16be
  [AC_MSG_RESULT(no)]
ca16be
)
ca16be
ca16be
HAVE_AMD64_ASM_V=0
ca16be
AS_IF([test "$enable_asm" != "no"],[
ca16be
  AC_MSG_CHECKING(whether we can use x86_64 asm code)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
  ]], [[
ca16be
#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
ca16be
# if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
ca16be
#  error Windows x86_64 calling conventions are not supported yet
ca16be
# endif
ca16be
/* neat */
ca16be
#else
ca16be
# error !x86_64
ca16be
#endif
ca16be
unsigned char i = 0, o = 0, t;
ca16be
__asm__ __volatile__ ("pxor %%xmm12, %%xmm6 \n"
ca16be
                      "movb (%[i]), %[t] \n"
ca16be
                      "addb %[t], (%[o]) \n"
ca16be
                      : [t] "=&r"(t)
ca16be
                      : [o] "D"(&o), [i] "S"(&i)
ca16be
                      : "memory", "flags", "cc");
ca16be
]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AC_DEFINE([HAVE_AMD64_ASM], [1], [x86_64 asm code can be used])
ca16be
   HAVE_AMD64_ASM_V=1],
ca16be
  [AC_MSG_RESULT(no)])
ca16be
])
ca16be
AM_CONDITIONAL([HAVE_AMD64_ASM], [test $HAVE_AMD64_ASM_V = 1])
ca16be
AC_SUBST(HAVE_AMD64_ASM_V)
ca16be
ca16be
HAVE_AVX_ASM_V=0
ca16be
AS_IF([test "$enable_asm" != "no"],[
ca16be
  AC_MSG_CHECKING(whether we can assemble AVX opcodes)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
  ]], [[
ca16be
#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
ca16be
# if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
ca16be
#  error Windows x86_64 calling conventions are not supported yet
ca16be
# endif
ca16be
/* neat */
ca16be
#else
ca16be
# error !x86_64
ca16be
#endif
ca16be
__asm__ __volatile__ ("vpunpcklqdq %xmm0,%xmm13,%xmm0");
ca16be
]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AC_DEFINE([HAVE_AVX_ASM], [1], [AVX opcodes are supported])
ca16be
   HAVE_AVX_ASM_V=1],
ca16be
  [AC_MSG_RESULT(no)])
ca16be
])
ca16be
AM_CONDITIONAL([HAVE_AVX_ASM], [test $HAVE_AVX_ASM_V = 1])
ca16be
AC_SUBST(HAVE_AVX_ASM_V)
ca16be
ca16be
AC_MSG_CHECKING(for 128-bit arithmetic)
ca16be
HAVE_TI_MODE_V=0
ca16be
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#if !defined(__clang__) && !defined(__GNUC__) && !defined(__SIZEOF_INT128__)
ca16be
# error mode(TI) is a gcc extension, and __int128 is not available
ca16be
#endif
ca16be
#if defined(__clang__) && !defined(__x86_64__) && !defined(__aarch64__)
ca16be
# error clang does not properly handle the 128-bit type on 32-bit systems
ca16be
#endif
ca16be
#ifndef NATIVE_LITTLE_ENDIAN
ca16be
# error libsodium currently expects a little endian CPU for the 128-bit type
ca16be
#endif
ca16be
#ifdef __EMSCRIPTEN__
ca16be
# error emscripten currently doesn't support some operations on integers larger than 64 bits
ca16be
#endif
ca16be
#include <stddef.h>
ca16be
#include <stdint.h>
ca16be
#if defined(__SIZEOF_INT128__)
ca16be
typedef unsigned __int128 uint128_t;
ca16be
#else
ca16be
typedef unsigned uint128_t __attribute__((mode(TI)));
ca16be
#endif
ca16be
void fcontract(uint128_t *t) {
ca16be
  *t += 0x8000000000000 - 1;
ca16be
  *t *= *t;
ca16be
  *t >>= 84;
ca16be
}
ca16be
]], [[
ca16be
(void) fcontract;
ca16be
]])],
ca16be
[AC_MSG_RESULT(yes)
ca16be
 AC_DEFINE([HAVE_TI_MODE], [1], [gcc TI mode is available])
ca16be
 HAVE_TI_MODE_V=1],
ca16be
[AC_MSG_RESULT(no)])
ca16be
AM_CONDITIONAL([HAVE_TI_MODE], [test $HAVE_TI_MODE_V = 1])
ca16be
AC_SUBST(HAVE_TI_MODE_V)
ca16be
ca16be
HAVE_CPUID_V=0
ca16be
AS_IF([test "$enable_asm" != "no"],[
ca16be
  AC_MSG_CHECKING(for cpuid instruction)
ca16be
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
ca16be
unsigned int cpu_info[4];
ca16be
__asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" :
ca16be
                      "=a" (cpu_info[0]), "=&r" (cpu_info[1]),
ca16be
                      "=c" (cpu_info[2]), "=d" (cpu_info[3]) :
ca16be
                      "0" (0U), "2" (0U));
ca16be
  ]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AC_DEFINE([HAVE_CPUID], [1], [cpuid instruction is available])
ca16be
   HAVE_CPUID_V=1],
ca16be
  [AC_MSG_RESULT(no)])
ca16be
  ])
ca16be
AC_SUBST(HAVE_CPUID_V)
ca16be
ca16be
asm_hide_symbol="unsupported"
ca16be
AS_IF([test "$enable_asm" != "no"],[
ca16be
  AC_MSG_CHECKING(if the .private_extern asm directive is supported)
ca16be
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
ca16be
__asm__ __volatile__ (".private_extern dummy_symbol \n"
ca16be
                      ".private_extern _dummy_symbol \n"
ca16be
                      ".globl dummy_symbol \n"
ca16be
                      ".globl _dummy_symbol \n"
ca16be
                      "dummy_symbol: \n"
ca16be
                      "_dummy_symbol: \n"
ca16be
                      "    nop \n"
ca16be
);
ca16be
  ]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   asm_hide_symbol=".private_extern"],
ca16be
  [AC_MSG_RESULT(no)])
ca16be
ca16be
  AC_MSG_CHECKING(if the .hidden asm directive is supported)
ca16be
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
ca16be
__asm__ __volatile__ (".hidden dummy_symbol \n"
ca16be
                      ".hidden _dummy_symbol \n"
ca16be
                      ".globl dummy_symbol \n"
ca16be
                      ".globl _dummy_symbol \n"
ca16be
                      "dummy_symbol: \n"
ca16be
                      "_dummy_symbol: \n"
ca16be
                      "    nop \n"
ca16be
);
ca16be
  ]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AS_IF([test "$asm_hide_symbol" = "unsupported"],
ca16be
          [asm_hide_symbol=".hidden"],
ca16be
          [AC_MSG_NOTICE([unable to reliably tag symbols as private])
ca16be
           asm_hide_symbol="unsupported"])
ca16be
  ],
ca16be
  [AC_MSG_RESULT(no)])
ca16be
ca16be
  AS_IF([test "$asm_hide_symbol" != "unsupported"],[
ca16be
    AC_DEFINE_UNQUOTED([ASM_HIDE_SYMBOL], [$asm_hide_symbol], [directive to hide symbols])
ca16be
  ])
ca16be
])
ca16be
ca16be
AC_MSG_CHECKING(if weak symbols are supported)
ca16be
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
ca16be
#if !defined(__ELF__) && !defined(__APPLE_CC__)
ca16be
# error Support for weak symbols may not be available
ca16be
#endif
ca16be
__attribute__((weak)) void __dummy(void *x) { }
ca16be
void f(void *x) { __dummy(x); }
ca16be
]], [[ ]]
ca16be
)],
ca16be
[AC_MSG_RESULT(yes)
ca16be
 AC_DEFINE([HAVE_WEAK_SYMBOLS], [1], [weak symbols are supported])],
ca16be
[AC_MSG_RESULT(no)])
ca16be
ca16be
AC_MSG_CHECKING(if data alignment is required)
ca16be
aligned_access_required=yes
ca16be
AS_CASE([$host_cpu],
ca16be
  [i?86|amd64|x86_64|powerpc*|s390*],
ca16be
    [aligned_access_required=no],
ca16be
  [arm*],
ca16be
    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ca16be
#ifndef __ARM_FEATURE_UNALIGNED
ca16be
# error data alignment is required
ca16be
#endif
ca16be
      ]], [[]])], [aligned_access_required=no], [])]
ca16be
)
ca16be
AS_IF([test "x$aligned_access_required" = "xyes"],
ca16be
  [AC_MSG_RESULT(yes)],
ca16be
  [AC_MSG_RESULT(no)
ca16be
   AC_DEFINE([CPU_UNALIGNED_ACCESS], [1], [unaligned memory access is supported])])
ca16be
ca16be
AC_MSG_CHECKING(if atomic operations are supported)
ca16be
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
ca16be
static volatile int _sodium_lock;
ca16be
__sync_lock_test_and_set(&_sodium_lock, 1);
ca16be
__sync_lock_release(&_sodium_lock);
ca16be
]]
ca16be
)],
ca16be
[AC_MSG_RESULT(yes)
ca16be
 AC_DEFINE([HAVE_ATOMIC_OPS], [1], [atomic operations are supported])],
ca16be
[AC_MSG_RESULT(no)])
ca16be
ca16be
dnl Checks for functions and headers
ca16be
ca16be
AC_FUNC_ALLOCA
ca16be
AS_IF([test "x$EMSCRIPTEN" = "x"],[
ca16be
  AC_CHECK_FUNCS([arc4random arc4random_buf])
ca16be
  AC_CHECK_FUNCS([mmap mlock madvise mprotect])
ca16be
ca16be
  AC_MSG_CHECKING(for getrandom with a standard API)
ca16be
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
ca16be
#include <stdlib.h>
ca16be
#ifdef HAVE_UNISTD_H
ca16be
# include <unistd.h>
ca16be
#endif
ca16be
#ifdef HAVE_SYS_RANDOM_H
ca16be
# include <sys/random.h>
ca16be
#endif
ca16be
]], [[
ca16be
unsigned char buf;
ca16be
(void) getrandom((void *) &buf, 1U, 0U);
ca16be
  ]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AC_CHECK_FUNCS([getrandom])],
ca16be
  [AC_MSG_RESULT(no)
ca16be
  ])
ca16be
ca16be
  AC_MSG_CHECKING(for getentropy with a standard API)
ca16be
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
ca16be
#include <stdlib.h>
ca16be
#ifdef HAVE_UNISTD_H
ca16be
# include <unistd.h>
ca16be
#endif
ca16be
#ifdef HAVE_SYS_RANDOM_H
ca16be
# include <sys/random.h>
ca16be
#endif
ca16be
]], [[
ca16be
#ifdef __APPLE__
ca16be
# error getentropy() is currently disabled on Apple operating systems
ca16be
#endif
ca16be
ca16be
unsigned char buf;
ca16be
(void) getentropy((void *) &buf, 1U);
ca16be
  ]])],
ca16be
  [AC_MSG_RESULT(yes)
ca16be
   AC_CHECK_FUNCS([getentropy])],
ca16be
  [AC_MSG_RESULT(no)
ca16be
  ])
ca16be
])
ca16be
AC_CHECK_FUNCS([posix_memalign getpid nanosleep])
ca16be
AC_CHECK_FUNCS([memset_s explicit_bzero explicit_memset])
ca16be
ca16be
AC_SUBST([LIBTOOL_EXTRA_FLAGS])
ca16be
ca16be
TEST_LDFLAGS=''
ca16be
AS_IF([test "x$EMSCRIPTEN" != "x"],[
ca16be
  EXEEXT=.js
ca16be
  TEST_LDFLAGS='--memory-init-file 0 --pre-js pre.js.inc -s RESERVED_FUNCTION_POINTERS=8'
ca16be
])
ca16be
AC_SUBST(TEST_LDFLAGS)
ca16be
AM_CONDITIONAL([EMSCRIPTEN], [test "x$EMSCRIPTEN" != "x"])
ca16be
AM_CONDITIONAL([WASI], [test "x$WASI" != "x"])
ca16be
ca16be
AC_DEFINE([CONFIGURED], [1], [the build system was properly configured])
ca16be
ca16be
dnl Libtool.
ca16be
ca16be
LT_INIT([dlopen])
ca16be
AC_LIBTOOL_WIN32_DLL
ca16be
gl_LD_OUTPUT_DEF
ca16be
ca16be
dnl Output.
ca16be
ca16be
AH_VERBATIM([NDEBUG], [/* Always evaluate assert() calls */
ca16be
#ifdef NDEBUG
ca16be
#/**/undef/**/ NDEBUG
ca16be
#endif])
ca16be
ca16be
AS_IF([test "x$ENABLE_CWFLAGS" = "xyes"], [
ca16be
  CFLAGS="$CFLAGS $CWFLAGS"
ca16be
])
ca16be
ca16be
AC_CONFIG_FILES([Makefile
ca16be
                 builds/Makefile
ca16be
                 contrib/Makefile
ca16be
                 dist-build/Makefile
ca16be
                 libsodium.pc
ca16be
                 libsodium-uninstalled.pc
ca16be
                 msvc-scripts/Makefile
ca16be
                 src/Makefile
ca16be
                 src/libsodium/Makefile
ca16be
                 src/libsodium/include/Makefile
ca16be
                 src/libsodium/include/sodium/version.h
ca16be
                 test/default/Makefile
ca16be
                 test/Makefile
ca16be
                 ])
ca16be
AC_OUTPUT