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