libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / configure.ac
blobaa698e0d1328ea97580a3bbe75e4330358b0146b
1 AC_PREREQ([2.61])
2 AC_INIT([libsodium],[0.4.1],
3   [https://github.com/jedisct1/libsodium/issues],
4   [libsodium],
5   [https://github.com/jedisct1/libsodium])
6 AC_CONFIG_MACRO_DIR([m4])
7 AC_CONFIG_SRCDIR([src/libsodium/sodium/version.c])
8 AC_CANONICAL_HOST
9 AM_INIT_AUTOMAKE([1.11 dist-bzip2 tar-ustar])
10 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
11 AM_MAINTAINER_MODE
12 AM_DEP_TRACK
14 AC_SUBST(VERSION)
15 ISODATE=`date +%Y-%m-%d`
16 AC_SUBST(ISODATE)
18 SODIUM_LIBRARY_VERSION_MAJOR=4
19 SODIUM_LIBRARY_VERSION_MINOR=1
20 DLL_VERSION=4
21 SODIUM_LIBRARY_VERSION=5:0:1
22 #                      | | |
23 #               +------+ | +---+
24 #               |        |     |
25 #            current:revision:age
26 #               |        |     |
27 #               |        |     +- increment if interfaces have been added
28 #               |        |        set to zero if interfaces have been removed
29 #               |        |        or changed
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)
36 AC_SUBST(DLL_VERSION)
38 LX_CFLAGS=${CFLAGS-NONE}
39 AC_PROG_CC_C99
40 AM_PROG_AS
41 AC_USE_SYSTEM_EXTENSIONS
42 CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
44 AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
45   [CFLAGS="$CFLAGS -fvisibility=hidden"])
47 AX_CHECK_COMPILE_FLAG([-fPIC], [
48   AX_CHECK_LINK_FLAG([-fPIC],
49     [CFLAGS="$CFLAGS -fPIC"]
50   )
53 AS_IF([test "$enable_pie" != "no"],[
54   AX_CHECK_COMPILE_FLAG([-fPIE], [
55     AX_CHECK_LINK_FLAG([-fPIE],
56       [AX_CHECK_LINK_FLAG([-pie],
57         [CFLAGS="$CFLAGS -fPIE"
58          LDFLAGS="$LDFLAGS -pie"])
59     ])
60   ])
63 AX_CHECK_COMPILE_FLAG([-fwrapv], [CFLAGS="$CFLAGS -fwrapv"])
64 AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
65 AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CFLAGS="$CFLAGS -fno-strict-overflow"])
67 LIBTOOL_EXTRA_FLAGS="-version-info $SODIUM_LIBRARY_VERSION"
68 case $host_os in
69   cygwin* | mingw* | pw32* | cegcc*)
70     AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
71     AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
72   ;;
73   dragonfly*)
74     AX_CHECK_COMPILE_FLAG([-fstack-protector], [
75       AX_CHECK_LINK_FLAG([-fstack-protector],
76         [CFLAGS="$CFLAGS -fstack-protector"]
77       )
78     ])
79   ;;
80   *)
81     AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [
82       AX_CHECK_LINK_FLAG([-fstack-protector-all],
83         [CFLAGS="$CFLAGS -fstack-protector-all"]
84       )
85     ])
86   ;;
87 esac
89 AX_CHECK_COMPILE_FLAG([-Winit-self], [CFLAGS="$CFLAGS -Winit-self"])
90 AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"])
91 AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])
92 AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"])
94 AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
96 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wall], [CWFLAGS="$CWFLAGS -Wall"])
97 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wextra], [CWFLAGS="$CWFLAGS -Wextra"])
99 AC_MSG_CHECKING(for clang)
100 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
101 #ifndef __clang__
102 be sad
103 #endif
104 ]])],
105   [AC_MSG_RESULT(yes)
106    AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-warning-option],
107      [CWFLAGS="$CWFLAGS -Wno-unknown-warning-option"])
108   ],
109   [AC_MSG_RESULT(no)
112 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wbad-function-cast], [CWFLAGS="$CWFLAGS -Wbad-function-cast"])
113 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-align], [CWFLAGS="$CWFLAGS -Wcast-align"])
114 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-qual], [CWFLAGS="$CWFLAGS -Wcast-qual"])
115 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wchar-subscripts], [CWFLAGS="$CWFLAGS -Wchar-subscripts"])
116 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcomment], [CWFLAGS="$CWFLAGS -Wcomment"])
117 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wfloat-equal], [CWFLAGS="$CWFLAGS -Wfloat-equal"])
118 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wformat=2], [CWFLAGS="$CWFLAGS -Wformat=2"])
119 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wimplicit], [CWFLAGS="$CWFLAGS -Wimplicit"])
120 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-declarations], [CWFLAGS="$CWFLAGS -Wmissing-declarations"])
121 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-prototypes], [CWFLAGS="$CWFLAGS -Wmissing-prototypes"])
122 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnormalized=id], [CWFLAGS="$CWFLAGS -Wnormalized=id"])
123 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Woverride-init], [CWFLAGS="$CWFLAGS -Woverride-init"])
124 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wparentheses], [CWFLAGS="$CWFLAGS -Wparentheses"])
125 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wpointer-arith], [CWFLAGS="$CWFLAGS -Wpointer-arith"])
126 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wredundant-decls], [CWFLAGS="$CWFLAGS -Wredundant-decls"])
127 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wstrict-prototypes], [CWFLAGS="$CWFLAGS -Wstrict-prototypes"])
128 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum"])
129 AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])
131 AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
132 AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
133 AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
135 LT_INIT
136 AC_SUBST(LIBTOOL_DEPS)
138 AC_ARG_VAR([AR], [path to the ar utility])
139 AC_CHECK_TOOL([AR], [ar], [ar])
141 AS_IF([test -d /usr/local/include], [
142   CPPFLAGS="$CPPFLAGS -I/usr/local/include"
145 AS_IF([test -d /usr/local/lib], [
146   LDFLAGS="$LDFLAGS -L/usr/local/lib"
149 dnl Checks for headers
150 AC_CHECK_HEADERS([emmintrin.h], [], [], [
151 #pragma GCC target("sse2")
154 AC_CHECK_HEADERS([tmmintrin.h], [], [], [
155 #pragma GCC target("ssse3")
158 AC_CHECK_HEADERS([smmintrin.h], [], [], [
159 #pragma GCC target("sse4.1")
162 AC_CHECK_HEADERS([immintrin.h], [], [], [
163 #pragma GCC target("avx")
166 AC_CHECK_HEADERS([avxintrin.h], [], [], [
167 #pragma GCC target("avx")
170 AC_CHECK_HEADERS([x86intrin.h], [], [], [
171 #pragma GCC target("xop")
174 AC_CHECK_HEADERS([wmmintrin.h], [], [], [
175 #pragma GCC target("aes")
178 AC_MSG_CHECKING(for access to floating-point rounding mode)
179 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
180   #include <fenv.h>
181   #pragma STDC FENV_ACCESS ON
182 ]], [[
183   const int previous_rounding_mode = fegetround();
184   fesetround(FE_TONEAREST);
185   fesetround(previous_rounding_mode);
186 ]])],
187 [AC_MSG_RESULT(yes)
188  AC_DEFINE([HAVE_FENV_H], [1], [floating-point rounding mode is accessible])
190 [AC_MSG_RESULT(no)])
192 dnl Checks for typedefs, structures, and compiler characteristics.
194 AC_C_BIGENDIAN(
195   AC_DEFINE(NATIVE_BIG_ENDIAN, 1, [machine is bigendian]),
196   AC_DEFINE(NATIVE_LITTLE_ENDIAN, 1, [machine is littleendian]),
197   AC_MSG_ERROR([unknown endianess]),
198   AC_MSG_WARN([universal endianess])
201 AC_MSG_CHECKING(whether __STDC_LIMIT_MACROS is required)
202 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
203 #include <limits.h>
204 #include <stdint.h>
205 ]], [[
206 (void) SIZE_MAX;
207 (void) UINT64_MAX;
208 ]])],
209   [AC_MSG_RESULT(no)],
210   [AC_MSG_RESULT(yes)
211    CPPFLAGS="$CPPFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
214 HAVE_AMD64_ASM_V=0
215 AS_IF([test "$enable_asm" != "no"],[
216   AC_MSG_CHECKING(whether we can assemble basic amd64 code)
217   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
218   ]], [[
219 #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
220 /* neat */
221 #else
222 # error !amd64
223 #endif
224 __asm__("pxor %xmm12,%xmm6");
225 ]])],
226   [AC_MSG_RESULT(yes)
227    AC_DEFINE([HAVE_AMD64_ASM], [1], [basic amd64 code can be assembled])
228    HAVE_AMD64_ASM_V=1],
229   [AC_MSG_RESULT(no)])
231 AM_CONDITIONAL([HAVE_AMD64_ASM], [test $HAVE_AMD64_ASM_V = 1])
232 AC_SUBST(HAVE_AMD64_ASM_V)
234 AC_MSG_CHECKING(for 128-bit arithmetic)
235 HAVE_TI_MODE_V=0
236 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
237 ]], [[
238 #ifndef __GNUC__
239 # error mode(TI) is a gcc extension
240 #endif
241 #if defined(__clang__) && !defined(__x86_64__)
242 # error clang doesn't properly compile smult_curve25519_donna_c64.c
243 #endif
244 typedef unsigned uint128_t __attribute__((mode(TI)));
245 uint128_t x;
246 (void) x;
247 ]])],
248 [AC_MSG_RESULT(yes)
249  AC_DEFINE([HAVE_TI_MODE], [1], [gcc TI mode is available])
250  HAVE_TI_MODE_V=1],
251 [AC_MSG_RESULT(no)])
252 AM_CONDITIONAL([HAVE_TI_MODE], [test $HAVE_TI_MODE_V = 1])
253 AC_SUBST(HAVE_TI_MODE_V)
255 AC_MSG_CHECKING(for cpuid instruction)
256 HAVE_CPUID_V=0
257 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
258 __asm__("movl %ebx,%esi\n"
259         "cpuid\n"
260         "movl %esi,%ebx");
261 ]])],
262 [AC_MSG_RESULT(yes)
263  AC_DEFINE([HAVE_CPUID], [1], [cpuid instruction is available])
264  HAVE_CPUID_V=1],
265 [AC_MSG_RESULT(no)])
266 AM_CONDITIONAL([HAVE_CPUID], [test $HAVE_CPUID_V = 1])
267 AC_SUBST(HAVE_CPUID_V)
269 dnl Checks for functions and headers
271 AC_CHECK_FUNC(clock_gettime, , [AC_CHECK_LIB(rt, clock_gettime)])
272 AC_CHECK_FUNC(fegetenv, , [AC_CHECK_LIB(m, fegetenv)])
274 AC_CHECK_FUNCS([SecureZeroMemory])
276 dnl Switches.
278 AC_ARG_ENABLE(pie,
279 [AS_HELP_STRING(--enable-pie,Produce position independent executables @<:@default=yes@:>@)],
280  enable_pie=$enableval, enable_pie="maybe")
282 AC_ARG_ENABLE(asm,
283 [AS_HELP_STRING(--disable-asm,Disable assembly implementations)],
285   AS_IF([test "x$enableval" = "xno"], [
286     enable_asm="no"
287   ], [
288     enable_asm="yes"
289   ])
292   enable_asm="yes"
295 AC_ARG_ENABLE(ssp,
296 [AS_HELP_STRING(--disable-ssp,Don't compile with -fstack-protector)],
297 [AS_IF([test "x$enableval" = "xno"], [
298     nxflags=""
299     for flag in `echo $CFLAGS`; do
300       case "$flag" in
301        -fstack-protector*) ;;
302         *) AS_VAR_APPEND([nxflags], [" $flag"]) ;;
303       esac
304     done
305     CFLAGS="$nxflags"
306   ])
309 AC_ARG_ENABLE(blocking-random,
310 [AS_HELP_STRING(--enable-blocking-random,Use /dev/random instead of /dev/urandom)],
311 [AC_DEFINE([USE_BLOCKING_RANDOM], [1], [Use blocking random])])
313 AC_ARG_ENABLE(debug,
314 [AS_HELP_STRING(--enable-debug,For maintainers only - please do not use)],
316   AS_IF([test "x$LX_CFLAGS" = "xNONE"], [
317     nxflags=""
318     for flag in `echo $CFLAGS`; do
319       case "$flag" in
320         -O*) ;;
321         -g*) ;;
322         *) AS_VAR_APPEND([nxflags], [" $flag"]) ;;
323       esac
324     done
325     CFLAGS="$nxflags -O0 -g3"
326   ])
327   CPPFLAGS="$CPPFLAGS -DDEBUG=1"
330 AC_ARG_WITH(safecode,
331 [AS_HELP_STRING(--with-safecode,For maintainers only - please do not use)],
332 [AS_IF([test "x$withval" = "xyes"], [
333     AC_ARG_VAR([SAFECODE_HOME], [set to the safecode base directory])
334     : ${SAFECODE_HOME:=/opt/safecode}
335     LDFLAGS="$LDFLAGS -L${SAFECODE_HOME}/lib"
336     LIBS="$LIBS -lsc_dbg_rt -lpoolalloc_bitmap -lstdc++"
337     CFLAGS="$CFLAGS -fmemsafety"
338   ])
341 AC_SUBST([MAINT])
342 AC_SUBST([LIBTOOL_EXTRA_FLAGS])
344 dnl Libtool.
346 LT_INIT([dlopen])
347 AC_LIBTOOL_WIN32_DLL
348 gl_LD_OUTPUT_DEF
350 dnl Output.
352 AH_VERBATIM([NDEBUG], [/* Never ever ignore assertions */
353 #ifdef NDEBUG
354 #/**/undef/**/ NDEBUG
355 #endif])
357 AC_CONFIG_FILES([Makefile
358                  src/Makefile
359                  src/libsodium/Makefile
360                  src/libsodium/include/Makefile
361                  src/libsodium/include/sodium/version.h
362                  src/libsodium/include/sodium/crypto_scalarmult_curve25519.h
363                  src/libsodium/include/sodium/crypto_stream_salsa20.h
364                  test/default/Makefile
365                  test/Makefile
366                  ])
367 AC_OUTPUT