2 AC_INIT([libsodium],[1.0.0],
3 [https://github.com/jedisct1/libsodium/issues],
5 [https://github.com/jedisct1/libsodium])
6 AC_CONFIG_MACRO_DIR([m4])
7 AC_CONFIG_SRCDIR([src/libsodium/sodium/version.c])
9 AM_INIT_AUTOMAKE([1.11 dist-bzip2 tar-ustar foreign subdir-objects])
10 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
15 ISODATE=`date +%Y-%m-%d`
18 SODIUM_LIBRARY_VERSION_MAJOR=7
19 SODIUM_LIBRARY_VERSION_MINOR=2
21 SODIUM_LIBRARY_VERSION=13:2:0
25 # current:revision:age
27 # | | +- increment if interfaces have been added
28 # | | set to zero if interfaces have been removed
30 # | +- increment if source code has changed
31 # | set to zero if current is incremented
32 # +- increment if interfaces have been added, removed or changed
33 AC_SUBST(SODIUM_LIBRARY_VERSION_MAJOR)
34 AC_SUBST(SODIUM_LIBRARY_VERSION_MINOR)
35 AC_SUBST(SODIUM_LIBRARY_VERSION)
38 LX_CFLAGS=${CFLAGS-NONE}
43 [AS_HELP_STRING(--disable-ssp,Do not compile with -fstack-protector)],
45 AS_IF([test "x$enableval" = "xno"], [
56 [AS_HELP_STRING(--disable-asm,Disable assembly implementations)],
58 AS_IF([test "x$enableval" = "xno"], [
68 AS_IF([test "x$EMSCRIPTEN" != "x"],[
70 AC_MSG_WARN([compiling to javascript - asm implementations disabled])
74 [AS_HELP_STRING(--disable-pie,Do not produce position independent executables)],
75 enable_pie=$enableval, enable_pie="maybe")
77 AS_CASE([$host_os], [mingw*|cygwin*|msys], [enable_pie="no"])
79 AC_ARG_ENABLE(blocking-random,
80 [AS_HELP_STRING(--enable-blocking-random,Use /dev/random instead of /dev/urandom)],
82 AS_IF([test "x$enableval" = "xyes"], [
83 AC_DEFINE([USE_BLOCKING_RANDOM], [1], [Use blocking random])
87 AC_ARG_ENABLE(minimal,
88 [AS_HELP_STRING(--enable-minimal,
89 [Only compile the minimum set of functions required for the high-level API])],
91 AS_IF([test "x$enableval" = "xyes"], [
100 AM_CONDITIONAL([MINIMAL], [test x$enable_minimal = xyes])
102 AC_ARG_WITH(safecode,
103 [AS_HELP_STRING(--with-safecode,For maintainers only - please do not use)],
104 [AS_IF([test "x$withval" = "xyes"], [
105 AC_ARG_VAR([SAFECODE_HOME], [set to the safecode base directory])
106 : ${SAFECODE_HOME:=/opt/safecode}
107 LDFLAGS="$LDFLAGS -L${SAFECODE_HOME}/lib"
108 LIBS="$LIBS -lsc_dbg_rt -lpoolalloc_bitmap -lstdc++"
109 CFLAGS="$CFLAGS -fmemsafety"
114 [AS_HELP_STRING(--enable-debug,For maintainers only - please do not use)],
116 AS_IF([test "x$enableval" = "xyes"], [
117 AS_IF([test "x$LX_CFLAGS" = "xNONE"], [
119 for flag in `echo $CFLAGS`; do
123 [*], [AS_VAR_APPEND([nxflags], [" $flag"])])
125 CFLAGS="$nxflags -O0 -g3"
127 CPPFLAGS="$CPPFLAGS -DDEBUG=1"
137 AC_USE_SYSTEM_EXTENSIONS
138 CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
140 AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
141 [CFLAGS="$CFLAGS -fvisibility=hidden"])
143 AS_CASE([$host_os], [cygwin*|mingw*|msys|pw32*|cegcc*], [ ], [
144 AX_CHECK_COMPILE_FLAG([-fPIC], [
145 AX_CHECK_LINK_FLAG([-fPIC],
146 [CFLAGS="$CFLAGS -fPIC"]
151 AS_IF([test "$enable_pie" != "no"],[
152 AX_CHECK_COMPILE_FLAG([-fPIE], [
153 AX_CHECK_LINK_FLAG([-fPIE],
154 [AX_CHECK_LINK_FLAG([-pie],
155 [CFLAGS="$CFLAGS -fPIE"
156 LDFLAGS="$LDFLAGS -pie"])
161 AX_CHECK_COMPILE_FLAG([-fwrapv], [CFLAGS="$CFLAGS -fwrapv"])
162 AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
163 AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CFLAGS="$CFLAGS -fno-strict-overflow"])
165 LIBTOOL_OLD_FLAGS="$LIBTOOL_EXTRA_FLAGS"
166 LIBTOOL_EXTRA_FLAGS="$LIBTOOL_EXTRA_FLAGS -version-info $SODIUM_LIBRARY_VERSION"
167 AC_ARG_ENABLE(soname-versions,
168 [AC_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for Android) (default: enabled)])],
170 AS_IF([test "x$enableval" = "xno"], [
171 LIBTOOL_EXTRA_FLAGS="$LIBTOOL_OLD_FLAGS -avoid-version"
177 [cygwin*|mingw*|msys|pw32*|cegcc*], [
178 AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
179 AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
182 AS_IF([test "x$enable_ssp" != "xno"],[
185 [cygwin*|mingw*|msys|pw32*|cegcc*], [ ],
187 AX_CHECK_COMPILE_FLAG([-fstack-protector], [
188 AX_CHECK_LINK_FLAG([-fstack-protector],
189 [CFLAGS="$CFLAGS -fstack-protector"]
195 AX_CHECK_COMPILE_FLAG([-Winit-self], [CFLAGS="$CFLAGS -Winit-self"])
196 AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"])
197 AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])
198 AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"])
200 AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
202 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wall], [CWFLAGS="$CWFLAGS -Wall"])
203 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wextra], [CWFLAGS="$CWFLAGS -Wextra"])
205 AC_MSG_CHECKING(for clang)
206 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
212 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-warning-option],
213 [CWFLAGS="$CWFLAGS -Wno-unknown-warning-option"])
218 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wbad-function-cast], [CWFLAGS="$CWFLAGS -Wbad-function-cast"])
219 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-align], [CWFLAGS="$CWFLAGS -Wcast-align"])
220 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-qual], [CWFLAGS="$CWFLAGS -Wcast-qual"])
221 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wchar-subscripts], [CWFLAGS="$CWFLAGS -Wchar-subscripts"])
222 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcomment], [CWFLAGS="$CWFLAGS -Wcomment"])
223 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wfloat-equal], [CWFLAGS="$CWFLAGS -Wfloat-equal"])
224 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wformat=2], [CWFLAGS="$CWFLAGS -Wformat=2"])
225 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wimplicit], [CWFLAGS="$CWFLAGS -Wimplicit"])
226 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-declarations], [CWFLAGS="$CWFLAGS -Wmissing-declarations"])
227 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-prototypes], [CWFLAGS="$CWFLAGS -Wmissing-prototypes"])
228 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnormalized=id], [CWFLAGS="$CWFLAGS -Wnormalized=id"])
229 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Woverride-init], [CWFLAGS="$CWFLAGS -Woverride-init"])
230 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wparentheses], [CWFLAGS="$CWFLAGS -Wparentheses"])
231 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wpointer-arith], [CWFLAGS="$CWFLAGS -Wpointer-arith"])
232 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wredundant-decls], [CWFLAGS="$CWFLAGS -Wredundant-decls"])
233 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wstrict-prototypes], [CWFLAGS="$CWFLAGS -Wstrict-prototypes"])
234 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum"])
235 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])
237 AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
238 AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
239 AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
242 AC_SUBST(LIBTOOL_DEPS)
244 AC_ARG_VAR([AR], [path to the ar utility])
245 AC_CHECK_TOOL([AR], [ar], [ar])
247 dnl Checks for headers
249 AS_IF([test "x$EMSCRIPTEN" = "x"],[
251 AC_MSG_CHECKING(for MMX instructions set)
252 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
253 #pragma GCC target("mmx")
254 #include <mmintrin.h>
255 ]], [[ __m64 x = _mm_setzero_si64(); ]])],
257 AC_DEFINE([HAVE_MMINTRIN_H], [1], [mmx is available])],
260 AC_MSG_CHECKING(for SSE2 instructions set)
261 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
262 #pragma GCC target("sse2")
263 #include <emmintrin.h>
264 ]], [[ __m128d x = _mm_setzero_pd(); ]])],
266 AC_DEFINE([HAVE_EMMINTRIN_H], [1], [sse2 is available])],
269 AC_MSG_CHECKING(for SSE3 instructions set)
270 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
271 #pragma GCC target("sse3")
272 #include <pmmintrin.h>
273 ]], [[ __m128 x = _mm_addsub_ps(_mm_cvtpd_ps(_mm_setzero_pd()),
274 _mm_cvtpd_ps(_mm_setzero_pd())); ]])],
276 AC_DEFINE([HAVE_PMMINTRIN_H], [1], [sse3 is available])],
279 AC_MSG_CHECKING(for SSSE3 instructions set)
280 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
281 #pragma GCC target("ssse3")
282 #include <tmmintrin.h>
283 ]], [[ __m64 x = _mm_abs_pi32(_m_from_int(0)); ]])],
285 AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])],
289 AC_CHECK_HEADERS([sys/mman.h])
291 dnl Checks for typedefs, structures, and compiler characteristics.
295 AC_DEFINE(NATIVE_BIG_ENDIAN, 1, [machine is bigendian]),
296 AC_DEFINE(NATIVE_LITTLE_ENDIAN, 1, [machine is littleendian]),
297 AC_MSG_ERROR([unknown endianess]),
298 AC_MSG_ERROR([universal endianess is not supported - compile separately and use lipo(1)])
301 AC_MSG_CHECKING(whether __STDC_LIMIT_MACROS is required)
302 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
311 CPPFLAGS="$CPPFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
315 AS_IF([test "$enable_asm" != "no"],[
316 AC_MSG_CHECKING(whether we should use x86_64 asm code)
317 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
319 #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
320 # if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
321 # error Windows x86_64 calling conventions are not supported yet
327 __asm__("pxor %xmm12,%xmm6");
330 AC_DEFINE([HAVE_AMD64_ASM], [1], [x86_64 asm code should be used])
334 AM_CONDITIONAL([HAVE_AMD64_ASM], [test $HAVE_AMD64_ASM_V = 1])
335 AC_SUBST(HAVE_AMD64_ASM_V)
337 AC_MSG_CHECKING(for 128-bit arithmetic)
339 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
341 # error mode(TI) is a gcc extension
343 #if defined(__clang__) && !defined(__x86_64__)
344 # error clang doesn't properly compile smult_curve25519_donna_c64.c
346 #ifndef NATIVE_LITTLE_ENDIAN
347 # error donna_c64 currently requires a little endian CPU
350 # error emscripten currently supports only shift operations on integers \
351 # larger than 64 bits
354 typedef unsigned uint128_t __attribute__((mode(TI)));
355 void fcontract(uint128_t *t) {
356 *t += 0x8000000000000 - 1;
362 AC_DEFINE([HAVE_TI_MODE], [1], [gcc TI mode is available])
365 AM_CONDITIONAL([HAVE_TI_MODE], [test $HAVE_TI_MODE_V = 1])
366 AC_SUBST(HAVE_TI_MODE_V)
369 AS_IF([test "$enable_asm" != "no"],[
370 AC_MSG_CHECKING(for cpuid instruction)
371 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
372 unsigned int cpu_info[4];
373 __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" :
374 "=a" (cpu_info[0]), "=&r" (cpu_info[1]),
375 "=c" (cpu_info[2]), "=d" (cpu_info[3]) :
379 AC_DEFINE([HAVE_CPUID], [1], [cpuid instruction is available])
383 AC_SUBST(HAVE_CPUID_V)
385 AC_MSG_CHECKING(if weak symbols are supported)
386 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
387 __attribute__((weak)) void __dummy(void *x) { }
388 void f(void *x) { __dummy(x); }
392 AC_DEFINE([HAVE_WEAK_SYMBOLS], [1], [weak symbols are supported])],
396 [i*86 | x86_64 | powerpc* | s390*],
397 [AC_MSG_NOTICE([data alignment is not required on this target])],
399 [AC_MSG_NOTICE([data alignment is required on this target])
400 AC_DEFINE([CPU_ALIGNED_ACCESS_REQUIRED], [1], [data alignment is required])]
403 dnl Checks for functions and headers
405 AS_IF([test "x$EMSCRIPTEN" = "x"],[
406 AC_CHECK_FUNCS([arc4random arc4random_buf])
408 AC_CHECK_FUNCS([mlock mprotect explicit_bzero posix_memalign])
410 AC_SUBST([LIBTOOL_EXTRA_FLAGS])
420 AH_VERBATIM([NDEBUG], [/* Always evaluate assert() calls */
422 #/**/undef/**/ NDEBUG
425 AS_IF([test "x$PKG_CONFIG" != "x"], [
426 AC_CONFIG_FILES([libsodium.pc])
428 AC_CONFIG_FILES([Makefile
430 msvc-scripts/Makefile
432 src/libsodium/Makefile
433 src/libsodium/include/Makefile
434 src/libsodium/include/sodium/version.h
435 test/default/Makefile