quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

configure.ac (32647B)


      1 AC_PREREQ([2.69])
      2 AC_INIT([libsodium],[1.0.20],[https://github.com/jedisct1/libsodium/issues],[libsodium],[https://libsodium.org])
      3 AC_CONFIG_AUX_DIR([build-aux])
      4 AC_CONFIG_MACRO_DIR([m4])
      5 AC_CONFIG_SRCDIR([src/libsodium/sodium/version.c])
      6 AC_CANONICAL_HOST
      7 AC_CANONICAL_TARGET
      8 AM_INIT_AUTOMAKE([1.11 dist-bzip2 tar-ustar foreign subdir-objects])
      9 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
     10 AM_MAINTAINER_MODE
     11 AM_DEP_TRACK
     12 
     13 AC_SUBST(VERSION)
     14 
     15 SODIUM_LIBRARY_VERSION_MAJOR=26
     16 SODIUM_LIBRARY_VERSION_MINOR=2
     17 DLL_VERSION=26
     18 SODIUM_LIBRARY_VERSION=28:0:2
     19 #                       | | |
     20 #                +------+ | +---+
     21 #                |        |     |
     22 #             current:revision:age
     23 #                |        |     |
     24 #                |        |     +- increment if interfaces have been added
     25 #                |        |        set to zero if interfaces have been removed
     26 #                |        |        or changed
     27 #                |        +- increment if source code has changed
     28 #                |           set to zero if current is incremented
     29 #                +- increment if interfaces have been added, removed or changed
     30 AC_SUBST(SODIUM_LIBRARY_VERSION_MAJOR)
     31 AC_SUBST(SODIUM_LIBRARY_VERSION_MINOR)
     32 AC_SUBST(SODIUM_LIBRARY_VERSION)
     33 AC_SUBST(DLL_VERSION)
     34 
     35 AC_LANG_ASSERT(C)
     36 LX_CFLAGS=${CFLAGS-NONE}
     37 PKGCONFIG_LIBS_PRIVATE=""
     38 
     39 dnl Path check
     40 
     41 AS_IF([pwd | fgrep ' ' > /dev/null 2>&1],
     42   [AC_MSG_ERROR([The build directory contains whitespaces - This can cause tests/installation to fail due to limitations of some libtool versions])]
     43 )
     44 
     45 sodium_CFLAGS=${CFLAGS+set}
     46 : ${CFLAGS=""}
     47 
     48 AC_PROG_CC
     49 AM_PROG_AS
     50 AC_USE_SYSTEM_EXTENSIONS
     51 
     52 dnl Default optimization flags
     53 
     54 if test "$sodium_CFLAGS" != "set" ; then
     55   AX_CHECK_COMPILE_FLAG([-O3], [CFLAGS="$CFLAGS -O3"],
     56     [AX_CHECK_COMPILE_FLAG([-O2], [CFLAGS="$CFLAGS -O2"],
     57       [AX_CHECK_COMPILE_FLAG([-O1], [CFLAGS="$CFLAGS -O1"],
     58         [AX_CHECK_COMPILE_FLAG([-O], [CFLAGS="$CFLAGS -O"])])])])
     59 fi
     60 
     61 dnl Switches
     62 
     63 AC_ARG_ENABLE(ssp,
     64 [AS_HELP_STRING(--disable-ssp,Do not compile with -fstack-protector)],
     65 [
     66   AS_IF([test "x$enableval" = "xno"], [
     67     enable_ssp="no"
     68   ], [
     69     enable_ssp="yes"
     70   ])
     71 ],
     72 [
     73   enable_ssp="yes"
     74 ])
     75 
     76 AC_ARG_ENABLE(asm,
     77 [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.])],
     78 [
     79   AS_IF([test "x$enableval" = "xno"], [
     80     enable_asm="no"
     81   ], [
     82     enable_asm="yes"
     83   ])
     84 ],
     85 [
     86   enable_asm="yes"
     87 ])
     88 
     89 AS_IF([test "x$EMSCRIPTEN" != "x"], [
     90   AX_CHECK_COMPILE_FLAG([-s ASSERTIONS=0], [
     91     enable_asm="no"
     92     AC_MSG_WARN([compiling to JavaScript - asm implementations disabled])
     93   ], [
     94     AC_MSG_WARN([EMSCRIPTEN environment variable defined, but emcc doesn\'t appear to be used - Assuming compilation to native code])
     95     CFLAGS="$CFLAGS -U__EMSCRIPTEN__"
     96     unset EMSCRIPTEN
     97   ])
     98 ])
     99 
    100 AC_ARG_ENABLE(pie,
    101 [AS_HELP_STRING(--disable-pie,Do not produce position independent executables)],
    102  enable_pie=$enableval, enable_pie="maybe")
    103 
    104 AS_CASE([$host_os], [mingw*|cygwin*|msys|eabi*], [enable_pie="no"])
    105 
    106 AC_ARG_ENABLE(blocking-random,
    107 [AS_HELP_STRING(--enable-blocking-random,Enable this switch only if /dev/urandom is totally broken on the target platform)],
    108 [
    109   AS_IF([test "x$enableval" = "xyes"], [
    110     AC_DEFINE([USE_BLOCKING_RANDOM], [1], [/dev/urandom is insecure on the target platform])
    111   ])
    112 ])
    113 
    114 AC_ARG_ENABLE(minimal,
    115 [AS_HELP_STRING(--enable-minimal,
    116   [Only compile the minimum set of functions required for the high-level API])],
    117 [
    118   AS_IF([test "x$enableval" = "xyes"], [
    119     enable_minimal="yes"
    120     SODIUM_LIBRARY_MINIMAL_DEF="#define SODIUM_LIBRARY_MINIMAL 1"
    121     AC_DEFINE([MINIMAL], [1], [Define for a minimal build, without deprecated functions and functions that high-level APIs depend on])
    122   ], [
    123     enable_minimal="no"
    124   ])
    125 ],
    126 [
    127   enable_minimal="no"
    128 ])
    129 AM_CONDITIONAL([MINIMAL], [test x$enable_minimal = xyes])
    130 AC_SUBST(SODIUM_LIBRARY_MINIMAL_DEF)
    131 
    132 AC_ARG_WITH(pthreads, AS_HELP_STRING([--with-pthreads],
    133  [use pthreads library, or --without-pthreads to disable threading support]),
    134  [ ], [withval="yes"])
    135 
    136 AS_IF([test "x$withval" = "xyes"], [
    137   AX_PTHREAD([
    138     AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    139         #include <pthread.h>
    140       ]], [[
    141         pthread_mutex_t mutex;
    142 
    143         pthread_mutex_lock(&mutex);
    144         pthread_mutex_unlock(&mutex)
    145       ]]
    146     )], [
    147         AC_DEFINE([HAVE_PTHREAD], [1], [Define if you have POSIX threads libraries and header files])
    148         with_threads="yes"
    149         LIBS="$PTHREAD_LIBS $LIBS"
    150         PKGCONFIG_LIBS_PRIVATE="$PTHREAD_LIBS $PTHREAD_CFLAGS $PKGCONFIG_LIBS_PRIVATE"
    151         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
    152         CC="$PTHREAD_CC"
    153       ])
    154     ],
    155     [ AC_MSG_NOTICE(pthread mutexes are not available) ]
    156   )
    157 ], [with_threads="no"])
    158 
    159 AC_ARG_WITH(safecode,
    160 [AS_HELP_STRING(--with-safecode,For maintainers only - please do not use)],
    161 [AS_IF([test "x$withval" = "xyes"], [
    162     AC_ARG_VAR([SAFECODE_HOME], [set to the safecode base directory])
    163     : ${SAFECODE_HOME:=/opt/safecode}
    164     LDFLAGS="$LDFLAGS -L${SAFECODE_HOME}/lib"
    165     LIBS="$LIBS -lsc_dbg_rt -lpoolalloc_bitmap -lstdc++"
    166     CFLAGS="$CFLAGS -fmemsafety"
    167   ])
    168 ])
    169 
    170 AC_ARG_WITH(ctgrind,
    171 [AS_HELP_STRING(--with-ctgrind,For maintainers only - please do not use)],
    172 [AS_IF([test "x$withval" = "xyes"], [
    173     AC_CHECK_LIB(ctgrind, ct_poison)
    174   ])
    175 ])
    176 
    177 AC_ARG_ENABLE(retpoline,
    178 [AS_HELP_STRING(--enable-retpoline,Use return trampolines for indirect calls)],
    179 [AS_IF([test "x$enableval" = "xyes"], [
    180   AX_CHECK_COMPILE_FLAG([-mindirect-branch=thunk-inline],
    181     [CFLAGS="$CFLAGS -mindirect-branch=thunk-inline"],
    182     [AX_CHECK_COMPILE_FLAG([-mretpoline], [CFLAGS="$CFLAGS -mretpoline"])]
    183   )
    184   AX_CHECK_COMPILE_FLAG([-mindirect-branch-register])
    185   ])
    186 ])
    187 
    188 ENABLE_CWFLAGS=no
    189 AC_ARG_ENABLE(debug,
    190 [AS_HELP_STRING(--enable-debug,For maintainers only - please do not use)],
    191 [
    192   AS_IF([test "x$enableval" = "xyes"], [
    193     AS_IF([test "x$LX_CFLAGS" = "xNONE"], [
    194       nxflags=""
    195       for flag in `echo $CFLAGS`; do
    196         AS_CASE([$flag],
    197           [-O*], [ ],
    198           [-g*], [ ],
    199           [*], [AS_VAR_APPEND([nxflags], [" $flag"])])
    200       done
    201       CFLAGS="$nxflags -O -g3"
    202     ])
    203     ENABLE_CWFLAGS=yes
    204     CPPFLAGS="$CPPFLAGS -DDEBUG=1 -U_FORTIFY_SOURCE"
    205   ])
    206 ])
    207 
    208 AC_ARG_ENABLE(opt,
    209 [AS_HELP_STRING(--enable-opt,Optimize for the native CPU - The resulting library will be faster but not portable)],
    210 [
    211   AS_IF([test "x$enableval" = "xyes"], [
    212     AX_CHECK_COMPILE_FLAG([-ftree-vectorize], [CFLAGS="$CFLAGS -ftree-vectorize"])
    213     AX_CHECK_COMPILE_FLAG([-ftree-slp-vectorize], [CFLAGS="$CFLAGS -ftree-slp-vectorize"])
    214     AX_CHECK_COMPILE_FLAG([-fomit-frame-pointer], [CFLAGS="$CFLAGS -fomit-frame-pointer"])
    215     AX_CHECK_COMPILE_FLAG([-march=native], [CFLAGS="$CFLAGS -march=native"])
    216     AX_CHECK_COMPILE_FLAG([-mtune=native], [CFLAGS="$CFLAGS -mtune=native"])
    217   ])
    218 ])
    219 
    220 AC_SUBST(MAINT)
    221 AC_SUBST(PKGCONFIG_LIBS_PRIVATE)
    222 
    223 AX_VALGRIND_CHECK
    224 
    225 dnl Checks
    226 
    227 AC_C_VARARRAYS
    228 
    229 AC_CHECK_DEFINE([__wasi__], [WASI="yes"], [])
    230 
    231 AS_CASE([$host_os], [linux-gnu], [AX_ADD_FORTIFY_SOURCE], [ ])
    232 
    233 AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
    234   [CFLAGS="$CFLAGS -fvisibility=hidden"])
    235 
    236 AS_CASE([$host_os], [cygwin*|mingw*|msys|pw32*|cegcc*|eabi*], [ ], [
    237   AX_CHECK_COMPILE_FLAG([-fPIC], [CFLAGS="$CFLAGS -fPIC"])
    238 ])
    239 
    240 AS_IF([test "$enable_pie" != "no"],[
    241   AX_CHECK_COMPILE_FLAG([-fPIE], [
    242     AX_CHECK_LINK_FLAG([-pie], [
    243       [CFLAGS="$CFLAGS -fPIE"
    244        LDFLAGS="$LDFLAGS -pie"]
    245     ])
    246   ])
    247 ])
    248 
    249 AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
    250 AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CFLAGS="$CFLAGS -fno-strict-overflow"], [
    251   AX_CHECK_COMPILE_FLAG([-fwrapv], [CFLAGS="$CFLAGS -fwrapv"])
    252 ])
    253 
    254 AS_IF([test "$GCC" = "yes" ], [
    255   AS_CASE([$host_cpu],
    256     [i?86|amd64|x86_64], [
    257       AC_COMPILE_IFELSE(
    258         [AC_LANG_SOURCE([
    259 #if !defined(__clang__) && defined(__GNUC__) && ((__GNUC__ << 8) | __GNUC_MINOR__) < 0x403
    260 # error old gcc
    261 #endif
    262 int main(void) { return 0; }
    263          ])],,[
    264           AX_CHECK_COMPILE_FLAG([-flax-vector-conversions], [CFLAGS="$CFLAGS -flax-vector-conversions"])
    265         ])
    266       ]
    267     )
    268   ])
    269 
    270 LIBTOOL_OLD_FLAGS="$LIBTOOL_EXTRA_FLAGS"
    271 LIBTOOL_EXTRA_FLAGS="$LIBTOOL_EXTRA_FLAGS -version-info $SODIUM_LIBRARY_VERSION"
    272 AC_ARG_ENABLE(soname-versions,
    273   [AS_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for Android) (default: enabled)])],
    274     [
    275         AS_IF([test "x$enableval" = "xno"], [
    276           LIBTOOL_EXTRA_FLAGS="$LIBTOOL_OLD_FLAGS -avoid-version"
    277         ])
    278     ]
    279 )
    280 
    281 AS_CASE([$host_os],
    282   [cygwin*|mingw*|msys|pw32*|cegcc*], [
    283     AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
    284     AX_CHECK_LINK_FLAG([-Wl,--high-entropy-va], [LDFLAGS="$LDFLAGS -Wl,--high-entropy-va"])
    285     AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
    286   ])
    287 
    288 AS_CASE([$host_os],
    289   [cygwin*|mingw*|msys|pw32*|cegcc*|eabi*], [
    290     AX_CHECK_COMPILE_FLAG([-fno-asynchronous-unwind-tables], [
    291       [CFLAGS="$CFLAGS -fno-asynchronous-unwind-tables"]
    292     ])
    293 ])
    294 
    295 AS_IF([test "x$enable_ssp" != "xno"],[
    296 
    297 AS_CASE([$host_os],
    298   [solaris*|cygwin*|mingw*|msys|pw32*|cegcc*|haiku|none|eabi*], [ ],
    299   [*], [
    300     AX_CHECK_COMPILE_FLAG([-fstack-protector], [
    301       AX_CHECK_LINK_FLAG([-fstack-protector],
    302         [CFLAGS="$CFLAGS -fstack-protector"]
    303       )
    304     ])
    305   ])
    306 ])
    307 
    308 AX_CHECK_COMPILE_FLAG([$CFLAGS -Wall], [CWFLAGS="$CFLAGS -Wall"])
    309 AX_CHECK_COMPILE_FLAG([$CFLAGS -Wno-deprecated-declarations], [CFLAGS="$CFLAGS -Wno-deprecated-declarations"])
    310 AX_CHECK_COMPILE_FLAG([$CFLAGS -Wno-unknown-pragmas], [CFLAGS="$CFLAGS -Wno-unknown-pragmas"])
    311 
    312 AC_ARG_VAR([CWFLAGS], [compilation flags for generating extra warnings])
    313 
    314 AC_MSG_CHECKING(for clang)
    315 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
    316 #ifndef __clang__
    317 #error Not clang nor zig cc
    318 #endif
    319 ]])],
    320   [AC_MSG_RESULT(yes)
    321    AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-warning-option],
    322      [CWFLAGS="$CWFLAGS -Wno-unknown-warning-option"])
    323   ],
    324   [AC_MSG_RESULT(no)
    325 ])
    326 
    327 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wextra], [CWFLAGS="$WCFLAGS -Wextra"])
    328 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Warray-bounds], [CWFLAGS="$CWFLAGS -Warray-bounds"])
    329 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wbad-function-cast], [CWFLAGS="$CWFLAGS -Wbad-function-cast"])
    330 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-qual], [CWFLAGS="$CWFLAGS -Wcast-qual"])
    331 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wdiv-by-zero], [CWFLAGS="$CWFLAGS -Wdiv-by-zero"])
    332 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wduplicated-branches], [CWFLAGS="$CWFLAGS -Wduplicated-branches"])
    333 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wduplicated-cond], [CWFLAGS="$CWFLAGS -Wduplicated-cond"])
    334 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wfloat-equal], [CWFLAGS="$CWFLAGS -Wfloat-equal"])
    335 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wformat=2], [CWFLAGS="$CWFLAGS -Wformat=2"])
    336 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wlogical-op], [CWFLAGS="$CWFLAGS -Wlogical-op"])
    337 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmaybe-uninitialized], [CWFLAGS="$CWFLAGS -Wmaybe-uninitialized"])
    338 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmisleading-indentation], [CWFLAGS="$CWFLAGS -Wmisleading-indentation"])
    339 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-declarations], [CWFLAGS="$CWFLAGS -Wmissing-declarations"])
    340 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-prototypes], [CWFLAGS="$CWFLAGS -Wmissing-prototypes"])
    341 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnested-externs], [CWFLAGS="$CWFLAGS -Wnested-externs"])
    342 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-type-limits], [CWFLAGS="$CWFLAGS -Wno-type-limits"])
    343 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-pragmas], [CWFLAGS="$CWFLAGS -Wno-unknown-pragmas"])
    344 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnormalized=id], [CWFLAGS="$CWFLAGS -Wnormalized=id"])
    345 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnull-dereference], [CWFLAGS="$CWFLAGS -Wnull-dereference"])
    346 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wold-style-declaration], [CWFLAGS="$CWFLAGS -Wold-style-declaration"])
    347 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wpointer-arith], [CWFLAGS="$CWFLAGS -Wpointer-arith"])
    348 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wredundant-decls], [CWFLAGS="$CWFLAGS -Wredundant-decls"])
    349 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wrestrict], [CWFLAGS="$CWFLAGS -Wrestrict"])
    350 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wshorten-64-to-32], [CWFLAGS="$CWFLAGS -Wshorten-64-to-32"])
    351 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wsometimes-uninitialized], [CWFLAGS="$CWFLAGS -Wsometimes-uninitialized"])
    352 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wstrict-prototypes], [CWFLAGS="$CWFLAGS -Wstrict-prototypes"])
    353 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum"])
    354 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])
    355 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wwrite-strings], [CWFLAGS="$CWFLAGS -Wwrite-strings"])
    356 
    357 AS_IF([test "x$EMSCRIPTEN" = "x"], [
    358   AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
    359   AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
    360   AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
    361 ])
    362 
    363 AX_CHECK_CATCHABLE_SEGV
    364 AX_CHECK_CATCHABLE_ABRT
    365 
    366 AS_IF([test "x$with_threads" = "xyes"], [
    367   AX_TLS([AC_MSG_RESULT(thread local storage is supported)
    368           AX_CHECK_COMPILE_FLAG([-ftls-model=local-dynamic],
    369             [CFLAGS="$CFLAGS -ftls-model=local-dynamic"])],
    370          [AC_MSG_RESULT(thread local storage is not supported)]) ])
    371 
    372 LT_INIT
    373 AC_SUBST(LIBTOOL_DEPS)
    374 
    375 AC_ARG_VAR([AR], [path to the ar utility])
    376 AC_CHECK_TOOL([AR], [ar], [ar])
    377 
    378 dnl Checks for headers and codegen feature flags
    379 
    380 target_cpu_aarch64=no
    381 AC_MSG_CHECKING(for ARM64 target)
    382 AC_LINK_IFELSE(
    383   [AC_LANG_PROGRAM([
    384 #ifndef __aarch64__
    385 #error Not aarch64
    386 #endif
    387 #include <arm_neon.h>
    388    ], [(void) 0])],
    389    [AC_MSG_RESULT(yes)
    390     target_cpu_aarch64=yes],
    391    [AC_MSG_RESULT(no)
    392     target_cpu_aarch64=no])
    393 
    394 AS_IF([test "x$EMSCRIPTEN" = "x"], [
    395 
    396   AS_IF([test "x$target_cpu_aarch64" = "xyes"], [
    397     have_armcrypto=no
    398     AC_MSG_CHECKING(for ARM crypto instructions set)
    399     AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    400       #ifndef __ARM_FEATURE_CRYPTO
    401       #  define __ARM_FEATURE_CRYPTO 1
    402       #endif
    403       #ifndef __ARM_FEATURE_AES
    404       #  define __ARM_FEATURE_AES 1
    405       #endif
    406 
    407       #include <arm_neon.h>
    408 
    409       #ifdef __clang__
    410       #  pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
    411       #elif defined(__GNUC__)
    412       #  pragma GCC target("+simd+crypto")
    413       #endif
    414     ]], [[
    415       int64x2_t x = { 0, 0 };
    416       vaeseq_u8(vmovq_n_u8(0), vmovq_n_u8(0));
    417       vmull_high_p64(vreinterpretq_p64_s64(x), vreinterpretq_p64_s64(x));
    418 
    419       #ifdef __clang__
    420       #  pragma clang attribute pop
    421       #endif
    422       (void) 0
    423       ]])],
    424       [
    425         AC_MSG_RESULT(yes)
    426         have_armcrypto=yes
    427       ],
    428       [
    429         AC_MSG_RESULT(no)
    430         oldcflags="$CFLAGS"
    431         AX_CHECK_COMPILE_FLAG([-march=armv8-a+crypto+aes], [
    432           CFLAGS="$CFLAGS -march=armv8-a+crypto+aes"
    433           AC_MSG_CHECKING(for ARM crypto instructions set with -march=armv8-a+crypto+aes)
    434           AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    435             #ifdef __clang__
    436             #  pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
    437             #elif defined(__GNUC__)
    438             #  pragma GCC target("+simd+crypto")
    439             #endif
    440             #ifndef __ARM_FEATURE_CRYPTO
    441             #  define __ARM_FEATURE_CRYPTO 1
    442             #endif
    443             #ifndef __ARM_FEATURE_AES
    444             #  define __ARM_FEATURE_AES 1
    445             #endif
    446 
    447             #include <arm_neon.h>
    448           ]], [[
    449             int64x2_t x = { 0, 0 };
    450             vaeseq_u8(vmovq_n_u8(0), vmovq_n_u8(0));
    451             vmull_high_p64(vreinterpretq_p64_s64(x), vreinterpretq_p64_s64(x));
    452 
    453             #ifdef __clang__
    454             #  pragma clang attribute pop
    455             #endif
    456             (void) 0
    457           ]])],
    458             [
    459               AC_MSG_RESULT(yes - with addition of -march=armv8-a+crypto+aes)
    460               have_armcrypto=yes
    461               CFLAGS_ARMCRYPTO="-march=armv8-a+crypto+aes"
    462             ],
    463             [AC_MSG_RESULT(no)])
    464           CFLAGS="$oldcflags"
    465         ])
    466       ])
    467       AS_IF([test "$have_armcrypto" = "yes"],[AC_DEFINE([HAVE_ARMCRYPTO], [1], [ARM crypto extensions are available])])
    468   ])
    469 
    470   oldcflags="$CFLAGS"
    471   AX_CHECK_COMPILE_FLAG([-mmmx], [CFLAGS="$CFLAGS -mmmx"])
    472   AC_MSG_CHECKING(for MMX instructions set)
    473   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    474 #pragma GCC target("mmx")
    475 #include <mmintrin.h>
    476 ]], [[ __m64 x = _mm_setzero_si64(); ]])],
    477     [AC_MSG_RESULT(yes)
    478      AC_DEFINE([HAVE_MMINTRIN_H], [1], [mmx is available])
    479      AX_CHECK_COMPILE_FLAG([-mmmx], [CFLAGS_MMX="-mmmx"])],
    480     [AC_MSG_RESULT(no)])
    481   CFLAGS="$oldcflags"
    482 
    483   oldcflags="$CFLAGS"
    484   AX_CHECK_COMPILE_FLAG([-msse2], [CFLAGS="$CFLAGS -msse2"])
    485   AC_MSG_CHECKING(for SSE2 instructions set)
    486   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    487 #pragma GCC target("sse2")
    488 #ifndef __SSE2__
    489 # define __SSE2__
    490 #endif
    491 #include <emmintrin.h>
    492 ]], [[ __m128d x = _mm_setzero_pd();
    493        __m128i z = _mm_srli_epi64(_mm_setzero_si128(), 26); ]])],
    494     [AC_MSG_RESULT(yes)
    495      AC_DEFINE([HAVE_EMMINTRIN_H], [1], [sse2 is available])
    496      AX_CHECK_COMPILE_FLAG([-msse2], [CFLAGS_SSE2="-msse2"])],
    497     [AC_MSG_RESULT(no)])
    498   CFLAGS="$oldcflags"
    499 
    500   oldcflags="$CFLAGS"
    501   AX_CHECK_COMPILE_FLAG([-msse3], [CFLAGS="$CFLAGS -msse3"])
    502   AC_MSG_CHECKING(for SSE3 instructions set)
    503   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    504 #pragma GCC target("sse3")
    505 #include <pmmintrin.h>
    506 ]], [[ __m128 x = _mm_addsub_ps(_mm_cvtpd_ps(_mm_setzero_pd()),
    507                                 _mm_cvtpd_ps(_mm_setzero_pd())); ]])],
    508     [AC_MSG_RESULT(yes)
    509      AC_DEFINE([HAVE_PMMINTRIN_H], [1], [sse3 is available])
    510      AX_CHECK_COMPILE_FLAG([-msse3], [CFLAGS_SSE3="-msse3"])],
    511     [AC_MSG_RESULT(no)])
    512   CFLAGS="$oldcflags"
    513 
    514   oldcflags="$CFLAGS"
    515   AX_CHECK_COMPILE_FLAG([-mssse3], [CFLAGS="$CFLAGS -mssse3"])
    516   AC_MSG_CHECKING(for SSSE3 instructions set)
    517   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    518 #pragma GCC target("ssse3")
    519 #include <tmmintrin.h>
    520 ]], [[ __m64 x = _mm_abs_pi32(_m_from_int(0)); ]])],
    521     [AC_MSG_RESULT(yes)
    522      AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])
    523      AX_CHECK_COMPILE_FLAG([-mssse3], [CFLAGS_SSSE3="-mssse3"])],
    524     [AC_MSG_RESULT(no)])
    525   CFLAGS="$oldcflags"
    526 
    527   oldcflags="$CFLAGS"
    528   AX_CHECK_COMPILE_FLAG([-msse4.1], [CFLAGS="$CFLAGS -msse4.1"])
    529   AC_MSG_CHECKING(for SSE4.1 instructions set)
    530   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    531 #pragma GCC target("sse4.1")
    532 #include <smmintrin.h>
    533 ]], [[ __m128i x = _mm_minpos_epu16(_mm_setzero_si128()); ]])],
    534     [AC_MSG_RESULT(yes)
    535      AC_DEFINE([HAVE_SMMINTRIN_H], [1], [sse4.1 is available])
    536      AX_CHECK_COMPILE_FLAG([-msse4.1], [CFLAGS_SSE41="-msse4.1"])],
    537     [AC_MSG_RESULT(no)])
    538   CFLAGS="$oldcflags"
    539 
    540   oldcflags="$CFLAGS"
    541   AX_CHECK_COMPILE_FLAG([-mavx], [CFLAGS="$CFLAGS -mavx"])
    542   AC_MSG_CHECKING(for AVX instructions set)
    543   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    544 #pragma GCC target("avx")
    545 #include <immintrin.h>
    546 ]], [[ _mm256_zeroall(); ]])],
    547     [AC_MSG_RESULT(yes)
    548      AC_DEFINE([HAVE_AVXINTRIN_H], [1], [AVX is available])
    549      AX_CHECK_COMPILE_FLAG([-mavx], [CFLAGS_AVX="-mavx"])],
    550     [AC_MSG_RESULT(no)])
    551   CFLAGS="$oldcflags"
    552 
    553   oldcflags="$CFLAGS"
    554   AX_CHECK_COMPILE_FLAG([-mavx2], [CFLAGS="$CFLAGS -mavx2"])
    555   AC_MSG_CHECKING(for AVX2 instructions set)
    556   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    557 #pragma GCC target("avx2")
    558 #include <immintrin.h>
    559 ]], [[
    560 __m256 x = _mm256_set1_ps(3.14);
    561 __m256 y = _mm256_permutevar8x32_ps(x, _mm256_set1_epi32(42));
    562 return _mm256_movemask_ps(_mm256_cmp_ps(x, y, _CMP_NEQ_OQ));
    563 ]])],
    564     [AC_MSG_RESULT(yes)
    565      AC_DEFINE([HAVE_AVX2INTRIN_H], [1], [AVX2 is available])
    566      AX_CHECK_COMPILE_FLAG([-mavx2], [CFLAGS_AVX2="-mavx2"])
    567      AC_MSG_CHECKING(if _mm256_broadcastsi128_si256 is correctly defined)
    568      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    569 #pragma GCC target("avx2")
    570 #include <immintrin.h>
    571      ]], [[ __m256i y = _mm256_broadcastsi128_si256(_mm_setzero_si128()); ]])],
    572        [AC_MSG_RESULT(yes)],
    573        [AC_MSG_RESULT(no)
    574         AC_DEFINE([_mm256_broadcastsi128_si256], [_mm_broadcastsi128_si256],
    575                   [Define to the local name of _mm256_broadcastsi128_si256])])
    576      ],
    577     [AC_MSG_RESULT(no)])
    578   CFLAGS="$oldcflags"
    579 
    580   oldcflags="$CFLAGS"
    581   AX_CHECK_COMPILE_FLAG([-mavx512f], [CFLAGS="$CFLAGS -mavx512f"])
    582   AC_MSG_CHECKING(for AVX512F instructions set)
    583   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    584 #pragma GCC target("avx512f")
    585 #include <immintrin.h>
    586 ]], [[
    587 
    588 #ifndef __AVX512F__
    589 # error No AVX512 support
    590 #elif defined(__clang__)
    591 # if __clang_major__ < 4
    592 #  error Compiler AVX512 support may be broken
    593 # endif
    594 #elif defined(__GNUC__)
    595 # if __GNUC__ < 6
    596 #  error Compiler AVX512 support may be broken
    597 # endif
    598 #endif
    599 
    600 __m512i x = _mm512_setzero_epi32();
    601 __m512i y = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), x);
    602 ]])],
    603     [AC_MSG_RESULT(yes)
    604      AC_DEFINE([HAVE_AVX512FINTRIN_H], [1], [AVX512F is available])
    605      AX_CHECK_COMPILE_FLAG([-mavx512f], [CFLAGS_AVX512F="-mavx512f"])],
    606     [AC_MSG_RESULT(no)
    607      AX_CHECK_COMPILE_FLAG([$CFLAGS -mno-avx512f],
    608        [CFLAGS="$CFLAGS -mno-avx512f"])
    609     ])
    610   CFLAGS="$oldcflags"
    611 
    612   oldcflags="$CFLAGS"
    613   AX_CHECK_COMPILE_FLAG([-maes], [CFLAGS="$CFLAGS -maes"])
    614   AX_CHECK_COMPILE_FLAG([-mpclmul], [CFLAGS="$CFLAGS -mpclmul"])
    615   AC_MSG_CHECKING(for AESNI instructions set and PCLMULQDQ)
    616   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    617 #pragma GCC target("aes")
    618 #pragma GCC target("pclmul")
    619 #include <wmmintrin.h>
    620 ]], [[ __m128i x = _mm_aesimc_si128(_mm_setzero_si128());
    621        __m128i y = _mm_clmulepi64_si128(_mm_setzero_si128(), _mm_setzero_si128(), 0);]])],
    622     [AC_MSG_RESULT(yes)
    623      AC_DEFINE([HAVE_WMMINTRIN_H], [1], [aesni is available])
    624      AX_CHECK_COMPILE_FLAG([-maes], [CFLAGS_AESNI="-maes"])
    625      AX_CHECK_COMPILE_FLAG([-mpclmul], [CFLAGS_PCLMUL="-mpclmul"])
    626      ],
    627     [AC_MSG_RESULT(no)])
    628   CFLAGS="$oldcflags"
    629 
    630   oldcflags="$CFLAGS"
    631   AX_CHECK_COMPILE_FLAG([-mrdrnd], [CFLAGS="$CFLAGS -mrdrnd"])
    632   AC_MSG_CHECKING(for RDRAND)
    633   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    634 #pragma GCC target("rdrnd")
    635 #include <immintrin.h>
    636 ]], [[ unsigned long long x; _rdrand64_step(&x); ]])],
    637     [AC_MSG_RESULT(yes)
    638      AC_DEFINE([HAVE_RDRAND], [1], [rdrand is available])
    639      AX_CHECK_COMPILE_FLAG([-mrdrnd], [CFLAGS_RDRAND="-mrdrnd"])
    640      ],
    641     [AC_MSG_RESULT(no)])
    642   CFLAGS="$oldcflags"
    643 
    644 ])
    645 
    646 AC_SUBST(CFLAGS_ARMCRYPTO)
    647 AC_SUBST(CFLAGS_MMX)
    648 AC_SUBST(CFLAGS_SSE2)
    649 AC_SUBST(CFLAGS_SSE3)
    650 AC_SUBST(CFLAGS_SSSE3)
    651 AC_SUBST(CFLAGS_SSE41)
    652 AC_SUBST(CFLAGS_AVX)
    653 AC_SUBST(CFLAGS_AVX2)
    654 AC_SUBST(CFLAGS_AVX512F)
    655 AC_SUBST(CFLAGS_AESNI)
    656 AC_SUBST(CFLAGS_PCLMUL)
    657 AC_SUBST(CFLAGS_RDRAND)
    658 
    659 AC_CHECK_HEADERS([sys/mman.h sys/param.h sys/random.h intrin.h sys/auxv.h])
    660 AC_CHECK_HEADERS([CommonCrypto/CommonRandom.h])
    661 AC_CHECK_HEADERS([cet.h threads.h])
    662 
    663 AC_MSG_CHECKING([if _xgetbv() is available])
    664 AC_LINK_IFELSE(
    665   [AC_LANG_PROGRAM([[ #include <intrin.h> ]], [[ (void) _xgetbv(0) ]])],
    666   [AC_MSG_RESULT(yes)
    667    AC_DEFINE([HAVE__XGETBV], [1], [_xgetbv() is available])],
    668   [AC_MSG_RESULT(no)])
    669 
    670 dnl Checks for typedefs, structures, and compiler characteristics.
    671 
    672 AC_C_INLINE
    673 AS_CASE([$host_cpu],
    674   [i?86|amd64|x86_64],
    675     [ac_cv_c_bigendian=no]
    676 )
    677 AC_C_BIGENDIAN(
    678   AC_DEFINE(NATIVE_BIG_ENDIAN, 1, [machine is bigendian]),
    679   AC_DEFINE(NATIVE_LITTLE_ENDIAN, 1, [machine is littleendian]),
    680   AC_MSG_ERROR([unknown endianness]),
    681   AC_MSG_ERROR([universal endianness is not supported - compile separately and use lipo(1)])
    682 )
    683 
    684 AC_MSG_CHECKING(whether __STDC_LIMIT_MACROS is required)
    685 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    686 #include <limits.h>
    687 #include <stdint.h>
    688 ]], [[
    689 (void) SIZE_MAX;
    690 (void) UINT64_MAX;
    691 ]])],
    692   [AC_MSG_RESULT(no)],
    693   [AC_MSG_RESULT(yes)
    694    CPPFLAGS="$CPPFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
    695 ])
    696 
    697 AC_MSG_CHECKING(whether we can use inline asm code)
    698 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    699 ]], [[
    700 int a = 42;
    701 int *pnt = &a;
    702 __asm__ __volatile__ ("" : : "r"(pnt) : "memory");
    703 ]])],
    704   [AC_MSG_RESULT(yes)
    705    AC_DEFINE([HAVE_INLINE_ASM], [1], [inline asm code can be used])]
    706   [AC_MSG_RESULT(no)]
    707 )
    708 
    709 HAVE_AMD64_ASM_V=0
    710 AS_IF([test "$enable_asm" != "no"],[
    711   AC_MSG_CHECKING(whether we can use x86_64 asm code)
    712   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    713   ]], [[
    714 #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
    715 # if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
    716 #  error Windows x86_64 calling conventions are not supported yet
    717 # endif
    718 /* neat */
    719 #else
    720 # error !x86_64
    721 #endif
    722 unsigned char i = 0, o = 0, t;
    723 __asm__ __volatile__ ("pxor %%xmm12, %%xmm6 \n"
    724                       "movb (%[i]), %[t] \n"
    725                       "addb %[t], (%[o]) \n"
    726                       : [t] "=&r"(t)
    727                       : [o] "D"(&o), [i] "S"(&i)
    728                       : "memory", "flags", "cc");
    729 ]])],
    730   [AC_MSG_RESULT(yes)
    731    AC_DEFINE([HAVE_AMD64_ASM], [1], [x86_64 asm code can be used])
    732    HAVE_AMD64_ASM_V=1],
    733   [AC_MSG_RESULT(no)])
    734 ])
    735 AM_CONDITIONAL([HAVE_AMD64_ASM], [test $HAVE_AMD64_ASM_V = 1])
    736 AC_SUBST(HAVE_AMD64_ASM_V)
    737 
    738 HAVE_AVX_ASM_V=0
    739 AS_IF([test "$enable_asm" != "no"],[
    740   AC_MSG_CHECKING(whether we can assemble AVX opcodes)
    741   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    742   ]], [[
    743 #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
    744 # if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
    745 #  error Windows x86_64 calling conventions are not supported yet
    746 # endif
    747 /* neat */
    748 #else
    749 # error !x86_64
    750 #endif
    751 __asm__ __volatile__ ("vpunpcklqdq %xmm0,%xmm13,%xmm0");
    752 ]])],
    753   [AC_MSG_RESULT(yes)
    754    AC_DEFINE([HAVE_AVX_ASM], [1], [AVX opcodes are supported])
    755    HAVE_AVX_ASM_V=1],
    756   [AC_MSG_RESULT(no)])
    757 ])
    758 AM_CONDITIONAL([HAVE_AVX_ASM], [test $HAVE_AVX_ASM_V = 1])
    759 AC_SUBST(HAVE_AVX_ASM_V)
    760 
    761 AC_MSG_CHECKING(for 128-bit arithmetic)
    762 HAVE_TI_MODE_V=0
    763 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    764 #if !defined(__clang__) && !defined(__GNUC__) && !defined(__SIZEOF_INT128__)
    765 # error mode(TI) is a gcc extension, and __int128 is not available
    766 #endif
    767 #if defined(__clang__) && !defined(__x86_64__) && !defined(__aarch64__)
    768 # error clang does not properly handle the 128-bit type on 32-bit systems
    769 #endif
    770 #ifndef NATIVE_LITTLE_ENDIAN
    771 # error libsodium currently expects a little endian CPU for the 128-bit type
    772 #endif
    773 #ifdef __EMSCRIPTEN__
    774 # error emscripten currently doesn't support some operations on integers larger than 64 bits
    775 #endif
    776 #include <stddef.h>
    777 #include <stdint.h>
    778 #if defined(__SIZEOF_INT128__)
    779 typedef unsigned __int128 uint128_t;
    780 #else
    781 typedef unsigned uint128_t __attribute__((mode(TI)));
    782 #endif
    783 void fcontract(uint128_t *t) {
    784   *t += 0x8000000000000 - 1;
    785   *t *= *t;
    786   *t >>= 84;
    787 }
    788 ]], [[
    789 (void) fcontract;
    790 ]])],
    791 [AC_MSG_RESULT(yes)
    792  AC_DEFINE([HAVE_TI_MODE], [1], [gcc TI mode is available])
    793  HAVE_TI_MODE_V=1],
    794 [AC_MSG_RESULT(no)])
    795 AM_CONDITIONAL([HAVE_TI_MODE], [test $HAVE_TI_MODE_V = 1])
    796 AC_SUBST(HAVE_TI_MODE_V)
    797 
    798 HAVE_CPUID_V=0
    799 AS_IF([test "$enable_asm" != "no"],[
    800   AC_MSG_CHECKING(for cpuid instruction)
    801   AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
    802 unsigned int cpu_info[4];
    803 __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" :
    804                       "=a" (cpu_info[0]), "=&r" (cpu_info[1]),
    805                       "=c" (cpu_info[2]), "=d" (cpu_info[3]) :
    806                       "0" (0U), "2" (0U));
    807   ]])],
    808   [AC_MSG_RESULT(yes)
    809    AC_DEFINE([HAVE_CPUID], [1], [cpuid instruction is available])
    810    HAVE_CPUID_V=1],
    811   [AC_MSG_RESULT(no)])
    812   ])
    813 AC_SUBST(HAVE_CPUID_V)
    814 
    815 asm_hide_symbol="unsupported"
    816 AS_IF([test "$enable_asm" != "no"],[
    817   AC_MSG_CHECKING(if the .private_extern asm directive is supported)
    818   AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
    819 __asm__ __volatile__ (".private_extern dummy_symbol \n"
    820                       ".private_extern _dummy_symbol \n"
    821                       ".globl dummy_symbol \n"
    822                       ".globl _dummy_symbol \n"
    823                       "dummy_symbol: \n"
    824                       "_dummy_symbol: \n"
    825                       "    nop \n"
    826 );
    827   ]])],
    828   [AC_MSG_RESULT(yes)
    829    asm_hide_symbol=".private_extern"],
    830   [AC_MSG_RESULT(no)])
    831 
    832   AC_MSG_CHECKING(if the .hidden asm directive is supported)
    833   AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
    834 __asm__ __volatile__ (".hidden dummy_symbol \n"
    835                       ".hidden _dummy_symbol \n"
    836                       ".globl dummy_symbol \n"
    837                       ".globl _dummy_symbol \n"
    838                       "dummy_symbol: \n"
    839                       "_dummy_symbol: \n"
    840                       "    nop \n"
    841 );
    842   ]])],
    843   [AC_MSG_RESULT(yes)
    844    AS_IF([test "$asm_hide_symbol" = "unsupported"],
    845           [asm_hide_symbol=".hidden"],
    846           [AC_MSG_NOTICE([unable to reliably tag symbols as private])
    847            asm_hide_symbol="unsupported"])
    848   ],
    849   [AC_MSG_RESULT(no)])
    850 
    851   AS_IF([test "$asm_hide_symbol" != "unsupported"],[
    852     AC_DEFINE_UNQUOTED([ASM_HIDE_SYMBOL], [$asm_hide_symbol], [directive to hide symbols])
    853   ])
    854 ])
    855 
    856 AC_MSG_CHECKING(if weak symbols are supported)
    857 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    858 #if !defined(__ELF__) && !defined(__APPLE_CC__)
    859 # error Support for weak symbols may not be available
    860 #endif
    861 __attribute__((weak)) void __dummy(void *x) { }
    862 void f(void *x) { __dummy(x); }
    863 ]], [[ ]]
    864 )],
    865 [AC_MSG_RESULT(yes)
    866  AC_DEFINE([HAVE_WEAK_SYMBOLS], [1], [weak symbols are supported])],
    867 [AC_MSG_RESULT(no)])
    868 
    869 AC_MSG_CHECKING(if atomic operations are supported)
    870 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
    871 static volatile int _sodium_lock;
    872 __sync_lock_test_and_set(&_sodium_lock, 1);
    873 __sync_lock_release(&_sodium_lock);
    874 ]]
    875 )],
    876 [AC_MSG_RESULT(yes)
    877  AC_DEFINE([HAVE_ATOMIC_OPS], [1], [atomic operations are supported])],
    878 [AC_MSG_RESULT(no)])
    879 
    880 AC_MSG_CHECKING(if C11 memory fences are supported)
    881 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    882 #include <stdatomic.h>
    883  ]], [[
    884 atomic_thread_fence(memory_order_acquire);
    885 ]]
    886 )],
    887 [AC_MSG_RESULT(yes)
    888  AC_DEFINE([HAVE_C11_MEMORY_FENCES], [1], [C11 memory fences are supported])],
    889 [AC_MSG_RESULT(no)])
    890 
    891 AC_MSG_CHECKING(if gcc memory fences are supported)
    892 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
    893 __atomic_thread_fence(__ATOMIC_ACQUIRE);
    894 ]]
    895 )],
    896 [AC_MSG_RESULT(yes)
    897  AC_DEFINE([HAVE_GCC_MEMORY_FENCES], [1], [GCC memory fences are supported])],
    898 [AC_MSG_RESULT(no)])
    899 
    900 dnl Checks for functions and headers
    901 
    902 AC_FUNC_ALLOCA
    903 AS_IF([test "x$EMSCRIPTEN" = "x"],[
    904   AC_CHECK_FUNCS([arc4random arc4random_buf])
    905   AS_IF([test "x$WASI" = "x"],[
    906     AC_CHECK_FUNCS([mmap mlock madvise mprotect])
    907     AC_CHECK_FUNCS([raise])
    908     AC_CHECK_FUNCS([sysconf])
    909   ])
    910   AC_MSG_CHECKING(for getrandom with a standard API)
    911   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    912 #include <stdlib.h>
    913 #ifdef HAVE_UNISTD_H
    914 # include <unistd.h>
    915 #endif
    916 #ifdef HAVE_SYS_RANDOM_H
    917 # include <sys/random.h>
    918 #endif
    919 ]], [[
    920 unsigned char buf;
    921 if (&getrandom != NULL) {
    922   (void) getrandom((void *) &buf, 1U, 0U);
    923 }
    924   ]])],
    925   [AC_MSG_RESULT(yes)
    926    AC_CHECK_FUNCS([getrandom])],
    927   [AC_MSG_RESULT(no)
    928   ])
    929 
    930   AC_MSG_CHECKING(for getentropy with a standard API)
    931   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    932 #include <stdlib.h>
    933 #ifdef HAVE_UNISTD_H
    934 # include <unistd.h>
    935 #endif
    936 #ifdef HAVE_SYS_RANDOM_H
    937 # include <sys/random.h>
    938 #endif
    939 ]], [[
    940 unsigned char buf;
    941 if (&getentropy != NULL) {
    942   (void) getentropy((void *) &buf, 1U);
    943 }
    944   ]])],
    945   [AC_MSG_RESULT(yes)
    946    AC_CHECK_FUNCS([getentropy])],
    947   [AC_MSG_RESULT(no)
    948   ])
    949 ])
    950 
    951 AS_IF([test "x$WASI" = "x"],[
    952   AC_CHECK_FUNCS([getpid])
    953   AC_CHECK_FUNCS([getauxval elf_aux_info])
    954 ])
    955 
    956 AC_CHECK_FUNCS([posix_memalign nanosleep clock_gettime])
    957 
    958 AS_IF([test "x$WASI" = "x"],[
    959   AC_CHECK_FUNCS([memset_s explicit_bzero memset_explicit explicit_memset])
    960 ])
    961 
    962 AC_SUBST([LIBTOOL_EXTRA_FLAGS])
    963 
    964 TEST_LDFLAGS=''
    965 AS_IF([test "x$EMSCRIPTEN" != "x"],[
    966   EXEEXT=.js
    967   TEST_LDFLAGS='--pre-js pre.js.inc -s RESERVED_FUNCTION_POINTERS=8'
    968 ])
    969 AC_SUBST(TEST_LDFLAGS)
    970 AM_CONDITIONAL([EMSCRIPTEN], [test "x$EMSCRIPTEN" != "x"])
    971 AM_CONDITIONAL([WASI], [test "x$WASI" != "x"])
    972 
    973 AC_DEFINE([CONFIGURED], [1], [the build system was properly configured])
    974 
    975 dnl Libtool.
    976 
    977 LT_INIT([dlopen win32-dll])
    978 gl_LD_OUTPUT_DEF
    979 
    980 dnl Output.
    981 
    982 AH_VERBATIM([NDEBUG], [/* Always evaluate assert() calls */
    983 #ifdef NDEBUG
    984 #/**/undef/**/ NDEBUG
    985 #endif])
    986 
    987 AS_IF([test "x$ENABLE_CWFLAGS" = "xyes"], [
    988   CFLAGS="$CFLAGS $CWFLAGS"
    989 ])
    990 
    991 AC_CONFIG_FILES([Makefile
    992                  builds/Makefile
    993                  contrib/Makefile
    994                  dist-build/Makefile
    995                  libsodium.pc
    996                  libsodium-uninstalled.pc
    997                  src/Makefile
    998                  src/libsodium/Makefile
    999                  src/libsodium/include/Makefile
   1000                  src/libsodium/include/sodium/version.h
   1001                  test/default/Makefile
   1002                  test/Makefile
   1003                  ])
   1004 AC_OUTPUT