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