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.

442 lines
13 KiB

  1. AC_PREREQ([2.65])
  2. AC_INIT([libsodium],[1.0.1],
  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=7
  18. SODIUM_LIBRARY_VERSION_MINOR=3
  19. DLL_VERSION=6
  20. SODIUM_LIBRARY_VERSION=13:3: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 Switches
  38. AC_ARG_ENABLE(ssp,
  39. [AS_HELP_STRING(--disable-ssp,Do not compile with -fstack-protector)],
  40. [
  41. AS_IF([test "x$enableval" = "xno"], [
  42. enable_ssp="no"
  43. ], [
  44. enable_ssp="yes"
  45. ])
  46. ],
  47. [
  48. enable_ssp="yes"
  49. ])
  50. AC_ARG_ENABLE(asm,
  51. [AS_HELP_STRING(--disable-asm,Disable assembly implementations)],
  52. [
  53. AS_IF([test "x$enableval" = "xno"], [
  54. enable_asm="no"
  55. ], [
  56. enable_asm="yes"
  57. ])
  58. ],
  59. [
  60. enable_asm="yes"
  61. ])
  62. AS_IF([test "x$EMSCRIPTEN" != "x"],[
  63. enable_asm="no"
  64. AC_MSG_WARN([compiling to javascript - asm implementations disabled])
  65. ])
  66. AC_ARG_ENABLE(pie,
  67. [AS_HELP_STRING(--disable-pie,Do not produce position independent executables)],
  68. enable_pie=$enableval, enable_pie="maybe")
  69. AS_CASE([$host_os], [mingw*|cygwin*|msys], [enable_pie="no"])
  70. AC_ARG_ENABLE(blocking-random,
  71. [AS_HELP_STRING(--enable-blocking-random,Use /dev/random instead of /dev/urandom)],
  72. [
  73. AS_IF([test "x$enableval" = "xyes"], [
  74. AC_DEFINE([USE_BLOCKING_RANDOM], [1], [Use blocking random])
  75. ])
  76. ])
  77. AC_ARG_ENABLE(minimal,
  78. [AS_HELP_STRING(--enable-minimal,
  79. [Only compile the minimum set of functions required for the high-level API])],
  80. [
  81. AS_IF([test "x$enableval" = "xyes"], [
  82. enable_minimal="yes"
  83. ], [
  84. enable_minimal="no"
  85. ])
  86. ],
  87. [
  88. enable_minimal="yes"
  89. ])
  90. AM_CONDITIONAL([MINIMAL], [test x$enable_minimal = xyes])
  91. AC_ARG_WITH(safecode,
  92. [AS_HELP_STRING(--with-safecode,For maintainers only - please do not use)],
  93. [AS_IF([test "x$withval" = "xyes"], [
  94. AC_ARG_VAR([SAFECODE_HOME], [set to the safecode base directory])
  95. : ${SAFECODE_HOME:=/opt/safecode}
  96. LDFLAGS="$LDFLAGS -L${SAFECODE_HOME}/lib"
  97. LIBS="$LIBS -lsc_dbg_rt -lpoolalloc_bitmap -lstdc++"
  98. CFLAGS="$CFLAGS -fmemsafety"
  99. ])
  100. ])
  101. AC_ARG_ENABLE(debug,
  102. [AS_HELP_STRING(--enable-debug,For maintainers only - please do not use)],
  103. [
  104. AS_IF([test "x$enableval" = "xyes"], [
  105. AS_IF([test "x$LX_CFLAGS" = "xNONE"], [
  106. nxflags=""
  107. for flag in `echo $CFLAGS`; do
  108. AS_CASE([$flag],
  109. [-O*], [ ],
  110. [-g*], [ ],
  111. [*], [AS_VAR_APPEND([nxflags], [" $flag"])])
  112. done
  113. CFLAGS="$nxflags -O0 -g3"
  114. ])
  115. CPPFLAGS="$CPPFLAGS -DDEBUG=1"
  116. ])
  117. ])
  118. AC_SUBST([MAINT])
  119. dnl Checks
  120. AC_PROG_CC_C99
  121. AM_PROG_AS
  122. AC_USE_SYSTEM_EXTENSIONS
  123. AC_CHECK_DEFINE([_FORTIFY_SOURCE], [], [
  124. AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=2],
  125. [CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"])
  126. ])
  127. AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
  128. [CFLAGS="$CFLAGS -fvisibility=hidden"])
  129. AS_CASE([$host_os], [cygwin*|mingw*|msys|pw32*|cegcc*], [ ], [
  130. AX_CHECK_COMPILE_FLAG([-fPIC], [
  131. AX_CHECK_LINK_FLAG([-fPIC],
  132. [CFLAGS="$CFLAGS -fPIC"]
  133. )
  134. ])
  135. ])
  136. AS_IF([test "$enable_pie" != "no"],[
  137. AX_CHECK_COMPILE_FLAG([-fPIE], [
  138. AX_CHECK_LINK_FLAG([-fPIE],
  139. [AX_CHECK_LINK_FLAG([-pie],
  140. [CFLAGS="$CFLAGS -fPIE"
  141. LDFLAGS="$LDFLAGS -pie"])
  142. ])
  143. ])
  144. ])
  145. AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
  146. AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CFLAGS="$CFLAGS -fno-strict-overflow"], [
  147. AX_CHECK_COMPILE_FLAG([-fwrapv], [CFLAGS="$CFLAGS -fwrapv"])
  148. ])
  149. LIBTOOL_OLD_FLAGS="$LIBTOOL_EXTRA_FLAGS"
  150. LIBTOOL_EXTRA_FLAGS="$LIBTOOL_EXTRA_FLAGS -version-info $SODIUM_LIBRARY_VERSION"
  151. AC_ARG_ENABLE(soname-versions,
  152. [AC_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for Android) (default: enabled)])],
  153. [
  154. AS_IF([test "x$enableval" = "xno"], [
  155. LIBTOOL_EXTRA_FLAGS="$LIBTOOL_OLD_FLAGS -avoid-version"
  156. ])
  157. ]
  158. )
  159. AS_CASE([$host_os],
  160. [cygwin*|mingw*|msys|pw32*|cegcc*], [
  161. AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
  162. AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
  163. ])
  164. AS_IF([test "x$enable_ssp" != "xno"],[
  165. AS_CASE([$host_os],
  166. [cygwin*|mingw*|msys|pw32*|cegcc*], [ ],
  167. [*], [
  168. AX_CHECK_COMPILE_FLAG([-fstack-protector], [
  169. AX_CHECK_LINK_FLAG([-fstack-protector],
  170. [CFLAGS="$CFLAGS -fstack-protector"]
  171. )
  172. ])
  173. ])
  174. ])
  175. AX_CHECK_COMPILE_FLAG([-Winit-self], [CFLAGS="$CFLAGS -Winit-self"])
  176. AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"])
  177. AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])
  178. AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"])
  179. AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
  180. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wall], [CWFLAGS="$CWFLAGS -Wall"])
  181. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wextra], [CWFLAGS="$CWFLAGS -Wextra"])
  182. AC_MSG_CHECKING(for clang)
  183. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  184. #ifndef __clang__
  185. be sad
  186. #endif
  187. ]])],
  188. [AC_MSG_RESULT(yes)
  189. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-warning-option],
  190. [CWFLAGS="$CWFLAGS -Wno-unknown-warning-option"])
  191. ],
  192. [AC_MSG_RESULT(no)
  193. ])
  194. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wbad-function-cast], [CWFLAGS="$CWFLAGS -Wbad-function-cast"])
  195. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-align], [CWFLAGS="$CWFLAGS -Wcast-align"])
  196. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-qual], [CWFLAGS="$CWFLAGS -Wcast-qual"])
  197. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wchar-subscripts], [CWFLAGS="$CWFLAGS -Wchar-subscripts"])
  198. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcomment], [CWFLAGS="$CWFLAGS -Wcomment"])
  199. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wfloat-equal], [CWFLAGS="$CWFLAGS -Wfloat-equal"])
  200. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wformat=2], [CWFLAGS="$CWFLAGS -Wformat=2"])
  201. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wimplicit], [CWFLAGS="$CWFLAGS -Wimplicit"])
  202. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-declarations], [CWFLAGS="$CWFLAGS -Wmissing-declarations"])
  203. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-prototypes], [CWFLAGS="$CWFLAGS -Wmissing-prototypes"])
  204. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnormalized=id], [CWFLAGS="$CWFLAGS -Wnormalized=id"])
  205. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Woverride-init], [CWFLAGS="$CWFLAGS -Woverride-init"])
  206. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wparentheses], [CWFLAGS="$CWFLAGS -Wparentheses"])
  207. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wpointer-arith], [CWFLAGS="$CWFLAGS -Wpointer-arith"])
  208. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wredundant-decls], [CWFLAGS="$CWFLAGS -Wredundant-decls"])
  209. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wstrict-prototypes], [CWFLAGS="$CWFLAGS -Wstrict-prototypes"])
  210. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum"])
  211. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])
  212. AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
  213. AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
  214. AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
  215. LT_INIT
  216. AC_SUBST(LIBTOOL_DEPS)
  217. AC_ARG_VAR([AR], [path to the ar utility])
  218. AC_CHECK_TOOL([AR], [ar], [ar])
  219. dnl Checks for headers
  220. AS_IF([test "x$EMSCRIPTEN" = "x"],[
  221. AC_MSG_CHECKING(for MMX instructions set)
  222. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  223. #pragma GCC target("mmx")
  224. #include <mmintrin.h>
  225. ]], [[ __m64 x = _mm_setzero_si64(); ]])],
  226. [AC_MSG_RESULT(yes)
  227. AC_DEFINE([HAVE_MMINTRIN_H], [1], [mmx is available])],
  228. [AC_MSG_RESULT(no)])
  229. AC_MSG_CHECKING(for SSE2 instructions set)
  230. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  231. #pragma GCC target("sse2")
  232. #include <emmintrin.h>
  233. ]], [[ __m128d x = _mm_setzero_pd(); ]])],
  234. [AC_MSG_RESULT(yes)
  235. AC_DEFINE([HAVE_EMMINTRIN_H], [1], [sse2 is available])],
  236. [AC_MSG_RESULT(no)])
  237. AC_MSG_CHECKING(for SSE3 instructions set)
  238. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  239. #pragma GCC target("sse3")
  240. #include <pmmintrin.h>
  241. ]], [[ __m128 x = _mm_addsub_ps(_mm_cvtpd_ps(_mm_setzero_pd()),
  242. _mm_cvtpd_ps(_mm_setzero_pd())); ]])],
  243. [AC_MSG_RESULT(yes)
  244. AC_DEFINE([HAVE_PMMINTRIN_H], [1], [sse3 is available])],
  245. [AC_MSG_RESULT(no)])
  246. AC_MSG_CHECKING(for SSSE3 instructions set)
  247. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  248. #pragma GCC target("ssse3")
  249. #include <tmmintrin.h>
  250. ]], [[ __m64 x = _mm_abs_pi32(_m_from_int(0)); ]])],
  251. [AC_MSG_RESULT(yes)
  252. AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])],
  253. [AC_MSG_RESULT(no)])
  254. ])
  255. AC_CHECK_HEADERS([sys/mman.h])
  256. dnl Checks for typedefs, structures, and compiler characteristics.
  257. AC_C_INLINE
  258. AC_C_BIGENDIAN(
  259. AC_DEFINE(NATIVE_BIG_ENDIAN, 1, [machine is bigendian]),
  260. AC_DEFINE(NATIVE_LITTLE_ENDIAN, 1, [machine is littleendian]),
  261. AC_MSG_ERROR([unknown endianess]),
  262. AC_MSG_ERROR([universal endianess is not supported - compile separately and use lipo(1)])
  263. )
  264. AC_MSG_CHECKING(whether __STDC_LIMIT_MACROS is required)
  265. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  266. #include <limits.h>
  267. #include <stdint.h>
  268. ]], [[
  269. (void) SIZE_MAX;
  270. (void) UINT64_MAX;
  271. ]])],
  272. [AC_MSG_RESULT(no)],
  273. [AC_MSG_RESULT(yes)
  274. CPPFLAGS="$CPPFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
  275. ])
  276. HAVE_AMD64_ASM_V=0
  277. AS_IF([test "$enable_asm" != "no"],[
  278. AC_MSG_CHECKING(whether we should use x86_64 asm code)
  279. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  280. ]], [[
  281. #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
  282. # if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
  283. # error Windows x86_64 calling conventions are not supported yet
  284. # endif
  285. /* neat */
  286. #else
  287. # error !x86_64
  288. #endif
  289. __asm__("pxor %xmm12,%xmm6");
  290. ]])],
  291. [AC_MSG_RESULT(yes)
  292. AC_DEFINE([HAVE_AMD64_ASM], [1], [x86_64 asm code should be used])
  293. HAVE_AMD64_ASM_V=1],
  294. [AC_MSG_RESULT(no)])
  295. ])
  296. AM_CONDITIONAL([HAVE_AMD64_ASM], [test $HAVE_AMD64_ASM_V = 1])
  297. AC_SUBST(HAVE_AMD64_ASM_V)
  298. AC_MSG_CHECKING(for 128-bit arithmetic)
  299. HAVE_TI_MODE_V=0
  300. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  301. #ifndef __GNUC__
  302. # error mode(TI) is a gcc extension
  303. #endif
  304. #if defined(__clang__) && !defined(__x86_64__)
  305. # error clang doesn't properly compile smult_curve25519_donna_c64.c
  306. #endif
  307. #ifndef NATIVE_LITTLE_ENDIAN
  308. # error donna_c64 currently requires a little endian CPU
  309. #endif
  310. #ifdef EMSCRIPTEN
  311. # error emscripten currently supports only shift operations on integers \
  312. # larger than 64 bits
  313. #endif
  314. #include <stdint.h>
  315. typedef unsigned uint128_t __attribute__((mode(TI)));
  316. void fcontract(uint128_t *t) {
  317. *t += 0x8000000000000 - 1;
  318. }
  319. ]], [[
  320. (void) fcontract;
  321. ]])],
  322. [AC_MSG_RESULT(yes)
  323. AC_DEFINE([HAVE_TI_MODE], [1], [gcc TI mode is available])
  324. HAVE_TI_MODE_V=1],
  325. [AC_MSG_RESULT(no)])
  326. AM_CONDITIONAL([HAVE_TI_MODE], [test $HAVE_TI_MODE_V = 1])
  327. AC_SUBST(HAVE_TI_MODE_V)
  328. HAVE_CPUID_V=0
  329. AS_IF([test "$enable_asm" != "no"],[
  330. AC_MSG_CHECKING(for cpuid instruction)
  331. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  332. unsigned int cpu_info[4];
  333. __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" :
  334. "=a" (cpu_info[0]), "=&r" (cpu_info[1]),
  335. "=c" (cpu_info[2]), "=d" (cpu_info[3]) :
  336. "0" (0U), "2" (0U));
  337. ]])],
  338. [AC_MSG_RESULT(yes)
  339. AC_DEFINE([HAVE_CPUID], [1], [cpuid instruction is available])
  340. HAVE_CPUID_V=1],
  341. [AC_MSG_RESULT(no)])
  342. ])
  343. AC_SUBST(HAVE_CPUID_V)
  344. AC_MSG_CHECKING(if weak symbols are supported)
  345. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  346. __attribute__((weak)) void __dummy(void *x) { }
  347. void f(void *x) { __dummy(x); }
  348. ]], [[ ]]
  349. )],
  350. [AC_MSG_RESULT(yes)
  351. AC_DEFINE([HAVE_WEAK_SYMBOLS], [1], [weak symbols are supported])],
  352. [AC_MSG_RESULT(no)])
  353. AS_CASE([$host_cpu],
  354. [i*86 | x86_64 | powerpc* | s390*],
  355. [AC_MSG_NOTICE([data alignment is not required on this target])],
  356. [*],
  357. [AC_MSG_NOTICE([data alignment is required on this target])
  358. AC_DEFINE([CPU_ALIGNED_ACCESS_REQUIRED], [1], [data alignment is required])]
  359. )
  360. dnl Checks for functions and headers
  361. AS_IF([test "x$EMSCRIPTEN" = "x"],[
  362. AC_CHECK_FUNCS([arc4random arc4random_buf])
  363. ])
  364. AC_CHECK_FUNCS([mlock mprotect explicit_bzero posix_memalign])
  365. AC_SUBST([LIBTOOL_EXTRA_FLAGS])
  366. dnl Libtool.
  367. LT_INIT([dlopen])
  368. AC_LIBTOOL_WIN32_DLL
  369. gl_LD_OUTPUT_DEF
  370. dnl Output.
  371. AH_VERBATIM([NDEBUG], [/* Always evaluate assert() calls */
  372. #ifdef NDEBUG
  373. #/**/undef/**/ NDEBUG
  374. #endif])
  375. AS_IF([test "x$PKG_CONFIG" != "x"], [
  376. AC_CONFIG_FILES([libsodium.pc])
  377. ])
  378. AC_CONFIG_FILES([Makefile
  379. dist-build/Makefile
  380. msvc-scripts/Makefile
  381. src/Makefile
  382. src/libsodium/Makefile
  383. src/libsodium/include/Makefile
  384. src/libsodium/include/sodium/version.h
  385. ])
  386. AC_OUTPUT