You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

579 lines
18 KiB

  1. AC_PREREQ([2.65])
  2. AC_INIT([libsodium],[1.0.7],
  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. AC_SUBST(VERSION)
  15. ISODATE=`date +%Y-%m-%d`
  16. AC_SUBST(ISODATE)
  17. SODIUM_LIBRARY_VERSION_MAJOR=9
  18. SODIUM_LIBRARY_VERSION_MINOR=0
  19. DLL_VERSION=8
  20. SODIUM_LIBRARY_VERSION=18:0:0
  21. # | | |
  22. # +------+ | +---+
  23. # | | |
  24. # current:revision:age
  25. # | | |
  26. # | | +- increment if interfaces have been added
  27. # | | set to zero if interfaces have been removed
  28. # | | or changed
  29. # | +- increment if source code has changed
  30. # | set to zero if current is incremented
  31. # +- increment if interfaces have been added, removed or changed
  32. AC_SUBST(SODIUM_LIBRARY_VERSION_MAJOR)
  33. AC_SUBST(SODIUM_LIBRARY_VERSION_MINOR)
  34. AC_SUBST(SODIUM_LIBRARY_VERSION)
  35. AC_SUBST(DLL_VERSION)
  36. LX_CFLAGS=${CFLAGS-NONE}
  37. dnl Path check
  38. AS_IF([test pwd | fgrep ' ' > /dev/null 2>&1],
  39. [AC_MSG_WARN([The build directory contains whitespaces - This can cause tests/installation to fail due to limitations of some libtool versions])]
  40. )
  41. dnl Switches
  42. AC_ARG_ENABLE(ssp,
  43. [AS_HELP_STRING(--disable-ssp,Do not compile with -fstack-protector)],
  44. [
  45. AS_IF([test "x$enableval" = "xno"], [
  46. enable_ssp="no"
  47. ], [
  48. enable_ssp="yes"
  49. ])
  50. ],
  51. [
  52. enable_ssp="yes"
  53. ])
  54. AC_ARG_ENABLE(asm,
  55. [AS_HELP_STRING(--disable-asm,Disable assembly implementations)],
  56. [
  57. AS_IF([test "x$enableval" = "xno"], [
  58. enable_asm="no"
  59. ], [
  60. enable_asm="yes"
  61. ])
  62. ],
  63. [
  64. enable_asm="yes"
  65. ])
  66. AS_IF([test "x$EMSCRIPTEN" != "x"],[
  67. enable_asm="no"
  68. AC_MSG_WARN([compiling to javascript - asm implementations disabled])
  69. ])
  70. AC_ARG_ENABLE(pie,
  71. [AS_HELP_STRING(--disable-pie,Do not produce position independent executables)],
  72. enable_pie=$enableval, enable_pie="maybe")
  73. AS_CASE([$host_os], [mingw*|cygwin*|msys], [enable_pie="no"])
  74. AC_ARG_ENABLE(blocking-random,
  75. [AS_HELP_STRING(--enable-blocking-random,Enable this switch only if /dev/urandom is totally broken on the target platform)],
  76. [
  77. AS_IF([test "x$enableval" = "xyes"], [
  78. AC_DEFINE([USE_BLOCKING_RANDOM], [1], [/dev/urandom is insecure on the target platform])
  79. ])
  80. ])
  81. AC_ARG_ENABLE(minimal,
  82. [AS_HELP_STRING(--enable-minimal,
  83. [Only compile the minimum set of functions required for the high-level API])],
  84. [
  85. AS_IF([test "x$enableval" = "xyes"], [
  86. enable_minimal="yes"
  87. ], [
  88. enable_minimal="no"
  89. ])
  90. ],
  91. [
  92. enable_minimal="no"
  93. ])
  94. AM_CONDITIONAL([MINIMAL], [test x$enable_minimal = xyes])
  95. AC_ARG_WITH(safecode,
  96. [AS_HELP_STRING(--with-safecode,For maintainers only - please do not use)],
  97. [AS_IF([test "x$withval" = "xyes"], [
  98. AC_ARG_VAR([SAFECODE_HOME], [set to the safecode base directory])
  99. : ${SAFECODE_HOME:=/opt/safecode}
  100. LDFLAGS="$LDFLAGS -L${SAFECODE_HOME}/lib"
  101. LIBS="$LIBS -lsc_dbg_rt -lpoolalloc_bitmap -lstdc++"
  102. CFLAGS="$CFLAGS -fmemsafety"
  103. ])
  104. ])
  105. AC_ARG_ENABLE(debug,
  106. [AS_HELP_STRING(--enable-debug,For maintainers only - please do not use)],
  107. [
  108. AS_IF([test "x$enableval" = "xyes"], [
  109. AS_IF([test "x$LX_CFLAGS" = "xNONE"], [
  110. nxflags=""
  111. for flag in `echo $CFLAGS`; do
  112. AS_CASE([$flag],
  113. [-O*], [ ],
  114. [-g*], [ ],
  115. [*], [AS_VAR_APPEND([nxflags], [" $flag"])])
  116. done
  117. CFLAGS="$nxflags -O0 -g3"
  118. ])
  119. CPPFLAGS="$CPPFLAGS -DDEBUG=1"
  120. ])
  121. ])
  122. AC_ARG_ENABLE(opt,
  123. [AS_HELP_STRING(--enable-opt,Optimize for the native CPU - The resulting library will be faster but not portable)],
  124. [
  125. AS_IF([test "x$enableval" = "xyes"], [
  126. CFLAGS="$CFLAGS -flto -march=native"
  127. LDFLAGS="$LDFLAGS -flto -march=native"])
  128. ])
  129. AC_SUBST([MAINT])
  130. dnl Checks
  131. AC_PROG_CC_C99
  132. AM_PROG_AS
  133. AC_USE_SYSTEM_EXTENSIONS
  134. AC_CHECK_DEFINE([__native_client__], [NATIVECLIENT="yes"], [])
  135. AC_CHECK_DEFINE([_FORTIFY_SOURCE], [], [
  136. AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=2],
  137. [CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"])
  138. ])
  139. AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
  140. [CFLAGS="$CFLAGS -fvisibility=hidden"])
  141. AS_CASE([$host_os], [cygwin*|mingw*|msys|pw32*|cegcc*], [ ], [
  142. AX_CHECK_COMPILE_FLAG([-fPIC], [
  143. AX_CHECK_LINK_FLAG([-fPIC],
  144. [CFLAGS="$CFLAGS -fPIC"]
  145. )
  146. ])
  147. ])
  148. AS_IF([test "$enable_pie" != "no"],[
  149. AX_CHECK_COMPILE_FLAG([-fPIE], [
  150. AX_CHECK_LINK_FLAG([-fPIE],
  151. [AX_CHECK_LINK_FLAG([-pie],
  152. [CFLAGS="$CFLAGS -fPIE"
  153. LDFLAGS="$LDFLAGS -pie"])
  154. ])
  155. ])
  156. ])
  157. AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
  158. AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CFLAGS="$CFLAGS -fno-strict-overflow"], [
  159. AX_CHECK_COMPILE_FLAG([-fwrapv], [CFLAGS="$CFLAGS -fwrapv"])
  160. ])
  161. LIBTOOL_OLD_FLAGS="$LIBTOOL_EXTRA_FLAGS"
  162. LIBTOOL_EXTRA_FLAGS="$LIBTOOL_EXTRA_FLAGS -version-info $SODIUM_LIBRARY_VERSION"
  163. AC_ARG_ENABLE(soname-versions,
  164. [AC_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for Android) (default: enabled)])],
  165. [
  166. AS_IF([test "x$enableval" = "xno"], [
  167. LIBTOOL_EXTRA_FLAGS="$LIBTOOL_OLD_FLAGS -avoid-version"
  168. ])
  169. ]
  170. )
  171. AS_CASE([$host_os],
  172. [cygwin*|mingw*|msys|pw32*|cegcc*], [
  173. AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
  174. AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
  175. ])
  176. AS_IF([test "x$enable_ssp" != "xno"],[
  177. AS_CASE([$host_os],
  178. [cygwin*|mingw*|msys|pw32*|cegcc*|*aix*|*sunos*|*solaris*], [ ],
  179. [*], [
  180. AX_CHECK_COMPILE_FLAG([-fstack-protector], [
  181. AX_CHECK_LINK_FLAG([-fstack-protector],
  182. [CFLAGS="$CFLAGS -fstack-protector"]
  183. )
  184. ])
  185. ])
  186. ])
  187. AX_CHECK_COMPILE_FLAG([-Winit-self], [CFLAGS="$CFLAGS -Winit-self"])
  188. AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"])
  189. AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])
  190. AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"])
  191. AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
  192. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wall], [CWFLAGS="$CWFLAGS -Wall"])
  193. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wextra], [CWFLAGS="$CWFLAGS -Wextra"])
  194. AC_MSG_CHECKING(for clang)
  195. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  196. #ifndef __clang__
  197. be sad
  198. #endif
  199. ]])],
  200. [AC_MSG_RESULT(yes)
  201. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-warning-option],
  202. [CWFLAGS="$CWFLAGS -Wno-unknown-warning-option"])
  203. ],
  204. [AC_MSG_RESULT(no)
  205. ])
  206. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wbad-function-cast], [CWFLAGS="$CWFLAGS -Wbad-function-cast"])
  207. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-align], [CWFLAGS="$CWFLAGS -Wcast-align"])
  208. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-qual], [CWFLAGS="$CWFLAGS -Wcast-qual"])
  209. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wchar-subscripts], [CWFLAGS="$CWFLAGS -Wchar-subscripts"])
  210. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcomment], [CWFLAGS="$CWFLAGS -Wcomment"])
  211. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wfloat-equal], [CWFLAGS="$CWFLAGS -Wfloat-equal"])
  212. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wformat=2], [CWFLAGS="$CWFLAGS -Wformat=2"])
  213. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wimplicit], [CWFLAGS="$CWFLAGS -Wimplicit"])
  214. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-declarations], [CWFLAGS="$CWFLAGS -Wmissing-declarations"])
  215. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-prototypes], [CWFLAGS="$CWFLAGS -Wmissing-prototypes"])
  216. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnormalized=id], [CWFLAGS="$CWFLAGS -Wnormalized=id"])
  217. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Woverride-init], [CWFLAGS="$CWFLAGS -Woverride-init"])
  218. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wparentheses], [CWFLAGS="$CWFLAGS -Wparentheses"])
  219. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wpointer-arith], [CWFLAGS="$CWFLAGS -Wpointer-arith"])
  220. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wredundant-decls], [CWFLAGS="$CWFLAGS -Wredundant-decls"])
  221. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wstrict-prototypes], [CWFLAGS="$CWFLAGS -Wstrict-prototypes"])
  222. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum"])
  223. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])
  224. AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
  225. AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
  226. AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
  227. LT_INIT
  228. AC_SUBST(LIBTOOL_DEPS)
  229. AC_ARG_VAR([AR], [path to the ar utility])
  230. AC_CHECK_TOOL([AR], [ar], [ar])
  231. dnl Checks for headers
  232. AS_IF([test "x$EMSCRIPTEN" = "x"],[
  233. AC_MSG_CHECKING(for MMX instructions set)
  234. oldcflags="$CFLAGS"
  235. AX_CHECK_COMPILE_FLAG([-mmmx], [CFLAGS="$CFLAGS -mmmx"])
  236. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  237. #pragma GCC target("mmx")
  238. #include <mmintrin.h>
  239. ]], [[ __m64 x = _mm_setzero_si64(); ]])],
  240. [AC_MSG_RESULT(yes)
  241. AC_DEFINE([HAVE_MMINTRIN_H], [1], [mmx is available])
  242. AX_CHECK_COMPILE_FLAG([-mmmx], [CFLAGS_MMX="-mmmx"])],
  243. [AC_MSG_RESULT(no)])
  244. CFLAGS="$oldcflags"
  245. AC_MSG_CHECKING(for SSE2 instructions set)
  246. oldcflags="$CFLAGS"
  247. AX_CHECK_COMPILE_FLAG([-msse2], [CFLAGS="$CFLAGS -msse2"])
  248. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  249. #pragma GCC target("sse2")
  250. #ifndef __SSE2__
  251. # define __SSE2__
  252. #endif
  253. #include <emmintrin.h>
  254. ]], [[ __m128d x = _mm_setzero_pd(); ]])],
  255. [AC_MSG_RESULT(yes)
  256. AC_DEFINE([HAVE_EMMINTRIN_H], [1], [sse2 is available])
  257. AX_CHECK_COMPILE_FLAG([-msse2], [CFLAGS_SSE2="-msse2"])],
  258. [AC_MSG_RESULT(no)])
  259. CFLAGS="$oldcflags"
  260. oldcflags="$CFLAGS"
  261. AX_CHECK_COMPILE_FLAG([-msse3], [CFLAGS="$CFLAGS -msse3"])
  262. AC_MSG_CHECKING(for SSE3 instructions set)
  263. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  264. #pragma GCC target("sse3")
  265. #include <pmmintrin.h>
  266. ]], [[ __m128 x = _mm_addsub_ps(_mm_cvtpd_ps(_mm_setzero_pd()),
  267. _mm_cvtpd_ps(_mm_setzero_pd())); ]])],
  268. [AC_MSG_RESULT(yes)
  269. AC_DEFINE([HAVE_PMMINTRIN_H], [1], [sse3 is available])
  270. AX_CHECK_COMPILE_FLAG([-msse3], [CFLAGS_SSE3="-msse3"])],
  271. [AC_MSG_RESULT(no)])
  272. CFLAGS="$oldcflags"
  273. oldcflags="$CFLAGS"
  274. AX_CHECK_COMPILE_FLAG([-mssse3], [CFLAGS="$CFLAGS -mssse3"])
  275. AC_MSG_CHECKING(for SSSE3 instructions set)
  276. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  277. #pragma GCC target("ssse3")
  278. #include <tmmintrin.h>
  279. ]], [[ __m64 x = _mm_abs_pi32(_m_from_int(0)); ]])],
  280. [AC_MSG_RESULT(yes)
  281. AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])
  282. AX_CHECK_COMPILE_FLAG([-mssse3], [CFLAGS_SSSE3="-mssse3"])],
  283. [AC_MSG_RESULT(no)])
  284. CFLAGS="$oldcflags"
  285. oldcflags="$CFLAGS"
  286. AX_CHECK_COMPILE_FLAG([-msse4.1], [CFLAGS="$CFLAGS -msse4.1"])
  287. AC_MSG_CHECKING(for SSE4.1 instructions set)
  288. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  289. #pragma GCC target("sse4.1")
  290. #include <smmintrin.h>
  291. ]], [[ __m128i x = _mm_minpos_epu16(_mm_setzero_si128()); ]])],
  292. [AC_MSG_RESULT(yes)
  293. AC_DEFINE([HAVE_SMMINTRIN_H], [1], [sse4.1 is available])
  294. AX_CHECK_COMPILE_FLAG([-msse4.1], [CFLAGS_SSE41="-msse4.1"])],
  295. [AC_MSG_RESULT(no)])
  296. CFLAGS="$oldcflags"
  297. oldcflags="$CFLAGS"
  298. AX_CHECK_COMPILE_FLAG([-mavx], [CFLAGS="$CFLAGS -mavx"])
  299. AC_MSG_CHECKING(for AVX instructions set)
  300. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  301. #pragma GCC target("avx")
  302. #include <immintrin.h>
  303. ]], [[ _mm256_zeroall(); ]])],
  304. [AC_MSG_RESULT(yes)
  305. AC_DEFINE([HAVE_AVXINTRIN_H], [1], [AVX is available])
  306. AX_CHECK_COMPILE_FLAG([-mavx], [CFLAGS_AVX="-mavx"])],
  307. [AC_MSG_RESULT(no)])
  308. CFLAGS="$oldcflags"
  309. oldcflags="$CFLAGS"
  310. AX_CHECK_COMPILE_FLAG([-maes], [CFLAGS="$CFLAGS -maes"])
  311. AX_CHECK_COMPILE_FLAG([-mpclmul], [CFLAGS="$CFLAGS -mpclmul"])
  312. AC_MSG_CHECKING(for AESNI instructions set and PCLMULQDQ)
  313. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  314. #pragma GCC target("aes")
  315. #pragma GCC target("pclmul")
  316. #include <wmmintrin.h>
  317. ]], [[ __m128i x = _mm_aesimc_si128(_mm_setzero_si128());
  318. __m128i y = _mm_clmulepi64_si128(_mm_setzero_si128(), _mm_setzero_si128(), 0);]])],
  319. [AC_MSG_RESULT(yes)
  320. AC_DEFINE([HAVE_WMMINTRIN_H], [1], [aesni is available])
  321. AX_CHECK_COMPILE_FLAG([-maes], [CFLAGS_AESNI="-maes"])
  322. AX_CHECK_COMPILE_FLAG([-mpclmul], [CFLAGS_PCLMUL="-mpclmul"])
  323. ],
  324. [AC_MSG_RESULT(no)])
  325. CFLAGS="$oldcflags"
  326. ])
  327. AC_SUBST(CFLAGS_MMX)
  328. AC_SUBST(CFLAGS_SSE2)
  329. AC_SUBST(CFLAGS_SSE3)
  330. AC_SUBST(CFLAGS_SSSE3)
  331. AC_SUBST(CFLAGS_SSE41)
  332. AC_SUBST(CFLAGS_AESNI)
  333. AC_SUBST(CFLAGS_PCLMUL)
  334. AC_CHECK_HEADERS([sys/mman.h])
  335. dnl Checks for typedefs, structures, and compiler characteristics.
  336. AC_C_INLINE
  337. AC_C_BIGENDIAN(
  338. AC_DEFINE(NATIVE_BIG_ENDIAN, 1, [machine is bigendian]),
  339. AC_DEFINE(NATIVE_LITTLE_ENDIAN, 1, [machine is littleendian]),
  340. AC_MSG_ERROR([unknown endianess]),
  341. AC_MSG_ERROR([universal endianess is not supported - compile separately and use lipo(1)])
  342. )
  343. AC_MSG_CHECKING(whether __STDC_LIMIT_MACROS is required)
  344. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  345. #include <limits.h>
  346. #include <stdint.h>
  347. ]], [[
  348. (void) SIZE_MAX;
  349. (void) UINT64_MAX;
  350. ]])],
  351. [AC_MSG_RESULT(no)],
  352. [AC_MSG_RESULT(yes)
  353. CPPFLAGS="$CPPFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
  354. ])
  355. HAVE_AMD64_ASM_V=0
  356. AS_IF([test "$enable_asm" != "no"],[
  357. AC_MSG_CHECKING(whether we can use x86_64 asm code)
  358. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  359. ]], [[
  360. #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
  361. # if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
  362. # error Windows x86_64 calling conventions are not supported yet
  363. # endif
  364. /* neat */
  365. #else
  366. # error !x86_64
  367. #endif
  368. unsigned char i = 0, o = 0, t;
  369. __asm__ __volatile__ ("pxor %%xmm12, %%xmm6 \n"
  370. "movb (%[i]), %[t] \n"
  371. "addb %[t], (%[o]) \n"
  372. : [t] "=&r"(t)
  373. : [o] "D"(&o), [i] "S"(&i)
  374. : "memory", "flags", "cc");
  375. ]])],
  376. [AC_MSG_RESULT(yes)
  377. AC_DEFINE([HAVE_AMD64_ASM], [1], [x86_64 asm code can be used])
  378. HAVE_AMD64_ASM_V=1],
  379. [AC_MSG_RESULT(no)])
  380. ])
  381. AM_CONDITIONAL([HAVE_AMD64_ASM], [test $HAVE_AMD64_ASM_V = 1])
  382. AC_SUBST(HAVE_AMD64_ASM_V)
  383. HAVE_AVX_ASM_V=0
  384. AS_IF([test "$enable_asm" != "no"],[
  385. AC_MSG_CHECKING(whether we can assemble AVX opcodes)
  386. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  387. ]], [[
  388. #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
  389. # if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
  390. # error Windows x86_64 calling conventions are not supported yet
  391. # endif
  392. /* neat */
  393. #else
  394. # error !x86_64
  395. #endif
  396. __asm__ __volatile__ ("vpunpcklqdq %xmm0,%xmm13,%xmm0");
  397. ]])],
  398. [AC_MSG_RESULT(yes)
  399. AC_DEFINE([HAVE_AVX_ASM], [1], [AVX opcodes are supported])
  400. HAVE_AVX_ASM_V=1],
  401. [AC_MSG_RESULT(no)])
  402. ])
  403. AM_CONDITIONAL([HAVE_AVX_ASM], [test $HAVE_AVX_ASM_V = 1])
  404. AC_SUBST(HAVE_AVX_ASM_V)
  405. AC_MSG_CHECKING(for 128-bit arithmetic)
  406. HAVE_TI_MODE_V=0
  407. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  408. #if !defined(__GNUC__) && !defined(__SIZEOF_INT128__)
  409. # error mode(TI) is a gcc extension, and __int128 is not available
  410. #endif
  411. #if defined(__clang__) && !defined(__x86_64__)
  412. # error clang does not properly handle the 128-bit type on 32-bit systems
  413. #endif
  414. #ifndef NATIVE_LITTLE_ENDIAN
  415. # error libsodium currently expects a little endian CPU for the 128-bit type
  416. #endif
  417. #ifdef __EMSCRIPTEN__
  418. # error emscripten currently supports only shift operations on integers \
  419. # larger than 64 bits
  420. #endif
  421. #include <stddef.h>
  422. #include <stdint.h>
  423. #if defined(__SIZEOF_INT128__)
  424. typedef unsigned __int128 uint128_t;
  425. #else
  426. typedef unsigned uint128_t __attribute__((mode(TI)));
  427. #endif
  428. void fcontract(uint128_t *t) {
  429. *t += 0x8000000000000 - 1;
  430. }
  431. ]], [[
  432. (void) fcontract;
  433. ]])],
  434. [AC_MSG_RESULT(yes)
  435. AC_DEFINE([HAVE_TI_MODE], [1], [gcc TI mode is available])
  436. HAVE_TI_MODE_V=1],
  437. [AC_MSG_RESULT(no)])
  438. AM_CONDITIONAL([HAVE_TI_MODE], [test $HAVE_TI_MODE_V = 1])
  439. AC_SUBST(HAVE_TI_MODE_V)
  440. HAVE_CPUID_V=0
  441. AS_IF([test "$enable_asm" != "no"],[
  442. AC_MSG_CHECKING(for cpuid instruction)
  443. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  444. unsigned int cpu_info[4];
  445. __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" :
  446. "=a" (cpu_info[0]), "=&r" (cpu_info[1]),
  447. "=c" (cpu_info[2]), "=d" (cpu_info[3]) :
  448. "0" (0U), "2" (0U));
  449. ]])],
  450. [AC_MSG_RESULT(yes)
  451. AC_DEFINE([HAVE_CPUID], [1], [cpuid instruction is available])
  452. HAVE_CPUID_V=1],
  453. [AC_MSG_RESULT(no)])
  454. ])
  455. AC_SUBST(HAVE_CPUID_V)
  456. AC_MSG_CHECKING(if weak symbols are supported)
  457. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  458. __attribute__((weak)) void __dummy(void *x) { }
  459. void f(void *x) { __dummy(x); }
  460. ]], [[ ]]
  461. )],
  462. [AC_MSG_RESULT(yes)
  463. AC_DEFINE([HAVE_WEAK_SYMBOLS], [1], [weak symbols are supported])],
  464. [AC_MSG_RESULT(no)])
  465. AC_MSG_CHECKING(if data alignment is required)
  466. aligned_access_required=yes
  467. AS_CASE([$host_cpu],
  468. [i*86 | x86_64 | powerpc* | s390*],
  469. [aligned_access_required=no],
  470. [arm*],
  471. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  472. #ifndef __ARM_FEATURE_UNALIGNED
  473. # error data alignment is required
  474. #endif
  475. ]], [[]])], [aligned_access_required=no], [])]
  476. )
  477. AS_IF([test "x$aligned_access_required" = "xyes"],
  478. [AC_MSG_RESULT(yes)],
  479. [AC_MSG_RESULT(no)
  480. AC_DEFINE([CPU_UNALIGNED_ACCESS], [1], [unaligned memory access is supported])])
  481. dnl Checks for functions and headers
  482. AS_IF([test "x$EMSCRIPTEN" = "x"],[
  483. AC_CHECK_FUNCS([arc4random arc4random_buf])
  484. AC_CHECK_FUNCS([mmap mlock madvise mprotect explicit_bzero])
  485. ])
  486. AC_CHECK_FUNCS([posix_memalign getpid])
  487. AC_SUBST([LIBTOOL_EXTRA_FLAGS])
  488. TEST_LDFLAGS=''
  489. AS_IF([test "x$EMSCRIPTEN" != "x"],[
  490. EXEEXT=.js
  491. TEST_LDFLAGS='--memory-init-file 0 --pre-js pre.js.inc -s NO_BROWSER=1 -s RESERVED_FUNCTION_POINTERS=8'
  492. ])
  493. AC_SUBST(TEST_LDFLAGS)
  494. AM_CONDITIONAL([EMSCRIPTEN], [test "x$EMSCRIPTEN" != "x"])
  495. AM_CONDITIONAL([NATIVECLIENT], [test "x$NATIVECLIENT" != "x"])
  496. dnl Libtool.
  497. LT_INIT([dlopen])
  498. AC_LIBTOOL_WIN32_DLL
  499. gl_LD_OUTPUT_DEF
  500. dnl Output.
  501. AH_VERBATIM([NDEBUG], [/* Always evaluate assert() calls */
  502. #ifdef NDEBUG
  503. #/**/undef/**/ NDEBUG
  504. #endif])
  505. AC_CONFIG_FILES([Makefile
  506. src/Makefile
  507. src/libsodium/Makefile
  508. src/libsodium/include/Makefile
  509. src/libsodium/include/sodium/version.h
  510. ])
  511. AC_OUTPUT