configure.ac 27 KB

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