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.

440 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. AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=2],
  124. [CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"])
  125. AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
  126. [CFLAGS="$CFLAGS -fvisibility=hidden"])
  127. AS_CASE([$host_os], [cygwin*|mingw*|msys|pw32*|cegcc*], [ ], [
  128. AX_CHECK_COMPILE_FLAG([-fPIC], [
  129. AX_CHECK_LINK_FLAG([-fPIC],
  130. [CFLAGS="$CFLAGS -fPIC"]
  131. )
  132. ])
  133. ])
  134. AS_IF([test "$enable_pie" != "no"],[
  135. AX_CHECK_COMPILE_FLAG([-fPIE], [
  136. AX_CHECK_LINK_FLAG([-fPIE],
  137. [AX_CHECK_LINK_FLAG([-pie],
  138. [CFLAGS="$CFLAGS -fPIE"
  139. LDFLAGS="$LDFLAGS -pie"])
  140. ])
  141. ])
  142. ])
  143. AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
  144. AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CFLAGS="$CFLAGS -fno-strict-overflow"], [
  145. AX_CHECK_COMPILE_FLAG([-fwrapv], [CFLAGS="$CFLAGS -fwrapv"])
  146. ])
  147. LIBTOOL_OLD_FLAGS="$LIBTOOL_EXTRA_FLAGS"
  148. LIBTOOL_EXTRA_FLAGS="$LIBTOOL_EXTRA_FLAGS -version-info $SODIUM_LIBRARY_VERSION"
  149. AC_ARG_ENABLE(soname-versions,
  150. [AC_HELP_STRING([--enable-soname-versions], [enable soname versions (must be disabled for Android) (default: enabled)])],
  151. [
  152. AS_IF([test "x$enableval" = "xno"], [
  153. LIBTOOL_EXTRA_FLAGS="$LIBTOOL_OLD_FLAGS -avoid-version"
  154. ])
  155. ]
  156. )
  157. AS_CASE([$host_os],
  158. [cygwin*|mingw*|msys|pw32*|cegcc*], [
  159. AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
  160. AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
  161. ])
  162. AS_IF([test "x$enable_ssp" != "xno"],[
  163. AS_CASE([$host_os],
  164. [cygwin*|mingw*|msys|pw32*|cegcc*], [ ],
  165. [*], [
  166. AX_CHECK_COMPILE_FLAG([-fstack-protector], [
  167. AX_CHECK_LINK_FLAG([-fstack-protector],
  168. [CFLAGS="$CFLAGS -fstack-protector"]
  169. )
  170. ])
  171. ])
  172. ])
  173. AX_CHECK_COMPILE_FLAG([-Winit-self], [CFLAGS="$CFLAGS -Winit-self"])
  174. AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"])
  175. AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])
  176. AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"])
  177. AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
  178. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wall], [CWFLAGS="$CWFLAGS -Wall"])
  179. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wextra], [CWFLAGS="$CWFLAGS -Wextra"])
  180. AC_MSG_CHECKING(for clang)
  181. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  182. #ifndef __clang__
  183. be sad
  184. #endif
  185. ]])],
  186. [AC_MSG_RESULT(yes)
  187. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wno-unknown-warning-option],
  188. [CWFLAGS="$CWFLAGS -Wno-unknown-warning-option"])
  189. ],
  190. [AC_MSG_RESULT(no)
  191. ])
  192. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wbad-function-cast], [CWFLAGS="$CWFLAGS -Wbad-function-cast"])
  193. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-align], [CWFLAGS="$CWFLAGS -Wcast-align"])
  194. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-qual], [CWFLAGS="$CWFLAGS -Wcast-qual"])
  195. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wchar-subscripts], [CWFLAGS="$CWFLAGS -Wchar-subscripts"])
  196. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcomment], [CWFLAGS="$CWFLAGS -Wcomment"])
  197. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wfloat-equal], [CWFLAGS="$CWFLAGS -Wfloat-equal"])
  198. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wformat=2], [CWFLAGS="$CWFLAGS -Wformat=2"])
  199. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wimplicit], [CWFLAGS="$CWFLAGS -Wimplicit"])
  200. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-declarations], [CWFLAGS="$CWFLAGS -Wmissing-declarations"])
  201. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-prototypes], [CWFLAGS="$CWFLAGS -Wmissing-prototypes"])
  202. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnormalized=id], [CWFLAGS="$CWFLAGS -Wnormalized=id"])
  203. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Woverride-init], [CWFLAGS="$CWFLAGS -Woverride-init"])
  204. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wparentheses], [CWFLAGS="$CWFLAGS -Wparentheses"])
  205. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wpointer-arith], [CWFLAGS="$CWFLAGS -Wpointer-arith"])
  206. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wredundant-decls], [CWFLAGS="$CWFLAGS -Wredundant-decls"])
  207. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wstrict-prototypes], [CWFLAGS="$CWFLAGS -Wstrict-prototypes"])
  208. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum"])
  209. AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])
  210. AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
  211. AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
  212. AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])
  213. LT_INIT
  214. AC_SUBST(LIBTOOL_DEPS)
  215. AC_ARG_VAR([AR], [path to the ar utility])
  216. AC_CHECK_TOOL([AR], [ar], [ar])
  217. dnl Checks for headers
  218. AS_IF([test "x$EMSCRIPTEN" = "x"],[
  219. AC_MSG_CHECKING(for MMX instructions set)
  220. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  221. #pragma GCC target("mmx")
  222. #include <mmintrin.h>
  223. ]], [[ __m64 x = _mm_setzero_si64(); ]])],
  224. [AC_MSG_RESULT(yes)
  225. AC_DEFINE([HAVE_MMINTRIN_H], [1], [mmx is available])],
  226. [AC_MSG_RESULT(no)])
  227. AC_MSG_CHECKING(for SSE2 instructions set)
  228. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  229. #pragma GCC target("sse2")
  230. #include <emmintrin.h>
  231. ]], [[ __m128d x = _mm_setzero_pd(); ]])],
  232. [AC_MSG_RESULT(yes)
  233. AC_DEFINE([HAVE_EMMINTRIN_H], [1], [sse2 is available])],
  234. [AC_MSG_RESULT(no)])
  235. AC_MSG_CHECKING(for SSE3 instructions set)
  236. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  237. #pragma GCC target("sse3")
  238. #include <pmmintrin.h>
  239. ]], [[ __m128 x = _mm_addsub_ps(_mm_cvtpd_ps(_mm_setzero_pd()),
  240. _mm_cvtpd_ps(_mm_setzero_pd())); ]])],
  241. [AC_MSG_RESULT(yes)
  242. AC_DEFINE([HAVE_PMMINTRIN_H], [1], [sse3 is available])],
  243. [AC_MSG_RESULT(no)])
  244. AC_MSG_CHECKING(for SSSE3 instructions set)
  245. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  246. #pragma GCC target("ssse3")
  247. #include <tmmintrin.h>
  248. ]], [[ __m64 x = _mm_abs_pi32(_m_from_int(0)); ]])],
  249. [AC_MSG_RESULT(yes)
  250. AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])],
  251. [AC_MSG_RESULT(no)])
  252. ])
  253. AC_CHECK_HEADERS([sys/mman.h])
  254. dnl Checks for typedefs, structures, and compiler characteristics.
  255. AC_C_INLINE
  256. AC_C_BIGENDIAN(
  257. AC_DEFINE(NATIVE_BIG_ENDIAN, 1, [machine is bigendian]),
  258. AC_DEFINE(NATIVE_LITTLE_ENDIAN, 1, [machine is littleendian]),
  259. AC_MSG_ERROR([unknown endianess]),
  260. AC_MSG_ERROR([universal endianess is not supported - compile separately and use lipo(1)])
  261. )
  262. AC_MSG_CHECKING(whether __STDC_LIMIT_MACROS is required)
  263. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  264. #include <limits.h>
  265. #include <stdint.h>
  266. ]], [[
  267. (void) SIZE_MAX;
  268. (void) UINT64_MAX;
  269. ]])],
  270. [AC_MSG_RESULT(no)],
  271. [AC_MSG_RESULT(yes)
  272. CPPFLAGS="$CPPFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
  273. ])
  274. HAVE_AMD64_ASM_V=0
  275. AS_IF([test "$enable_asm" != "no"],[
  276. AC_MSG_CHECKING(whether we should use x86_64 asm code)
  277. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  278. ]], [[
  279. #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
  280. # if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
  281. # error Windows x86_64 calling conventions are not supported yet
  282. # endif
  283. /* neat */
  284. #else
  285. # error !x86_64
  286. #endif
  287. __asm__("pxor %xmm12,%xmm6");
  288. ]])],
  289. [AC_MSG_RESULT(yes)
  290. AC_DEFINE([HAVE_AMD64_ASM], [1], [x86_64 asm code should be used])
  291. HAVE_AMD64_ASM_V=1],
  292. [AC_MSG_RESULT(no)])
  293. ])
  294. AM_CONDITIONAL([HAVE_AMD64_ASM], [test $HAVE_AMD64_ASM_V = 1])
  295. AC_SUBST(HAVE_AMD64_ASM_V)
  296. AC_MSG_CHECKING(for 128-bit arithmetic)
  297. HAVE_TI_MODE_V=0
  298. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  299. #ifndef __GNUC__
  300. # error mode(TI) is a gcc extension
  301. #endif
  302. #if defined(__clang__) && !defined(__x86_64__)
  303. # error clang doesn't properly compile smult_curve25519_donna_c64.c
  304. #endif
  305. #ifndef NATIVE_LITTLE_ENDIAN
  306. # error donna_c64 currently requires a little endian CPU
  307. #endif
  308. #ifdef EMSCRIPTEN
  309. # error emscripten currently supports only shift operations on integers \
  310. # larger than 64 bits
  311. #endif
  312. #include <stdint.h>
  313. typedef unsigned uint128_t __attribute__((mode(TI)));
  314. void fcontract(uint128_t *t) {
  315. *t += 0x8000000000000 - 1;
  316. }
  317. ]], [[
  318. (void) fcontract;
  319. ]])],
  320. [AC_MSG_RESULT(yes)
  321. AC_DEFINE([HAVE_TI_MODE], [1], [gcc TI mode is available])
  322. HAVE_TI_MODE_V=1],
  323. [AC_MSG_RESULT(no)])
  324. AM_CONDITIONAL([HAVE_TI_MODE], [test $HAVE_TI_MODE_V = 1])
  325. AC_SUBST(HAVE_TI_MODE_V)
  326. HAVE_CPUID_V=0
  327. AS_IF([test "$enable_asm" != "no"],[
  328. AC_MSG_CHECKING(for cpuid instruction)
  329. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  330. unsigned int cpu_info[4];
  331. __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" :
  332. "=a" (cpu_info[0]), "=&r" (cpu_info[1]),
  333. "=c" (cpu_info[2]), "=d" (cpu_info[3]) :
  334. "0" (0U), "2" (0U));
  335. ]])],
  336. [AC_MSG_RESULT(yes)
  337. AC_DEFINE([HAVE_CPUID], [1], [cpuid instruction is available])
  338. HAVE_CPUID_V=1],
  339. [AC_MSG_RESULT(no)])
  340. ])
  341. AC_SUBST(HAVE_CPUID_V)
  342. AC_MSG_CHECKING(if weak symbols are supported)
  343. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  344. __attribute__((weak)) void __dummy(void *x) { }
  345. void f(void *x) { __dummy(x); }
  346. ]], [[ ]]
  347. )],
  348. [AC_MSG_RESULT(yes)
  349. AC_DEFINE([HAVE_WEAK_SYMBOLS], [1], [weak symbols are supported])],
  350. [AC_MSG_RESULT(no)])
  351. AS_CASE([$host_cpu],
  352. [i*86 | x86_64 | powerpc* | s390*],
  353. [AC_MSG_NOTICE([data alignment is not required on this target])],
  354. [*],
  355. [AC_MSG_NOTICE([data alignment is required on this target])
  356. AC_DEFINE([CPU_ALIGNED_ACCESS_REQUIRED], [1], [data alignment is required])]
  357. )
  358. dnl Checks for functions and headers
  359. AS_IF([test "x$EMSCRIPTEN" = "x"],[
  360. AC_CHECK_FUNCS([arc4random arc4random_buf])
  361. ])
  362. AC_CHECK_FUNCS([mlock mprotect explicit_bzero posix_memalign])
  363. AC_SUBST([LIBTOOL_EXTRA_FLAGS])
  364. dnl Libtool.
  365. LT_INIT([dlopen])
  366. AC_LIBTOOL_WIN32_DLL
  367. gl_LD_OUTPUT_DEF
  368. dnl Output.
  369. AH_VERBATIM([NDEBUG], [/* Always evaluate assert() calls */
  370. #ifdef NDEBUG
  371. #/**/undef/**/ NDEBUG
  372. #endif])
  373. AS_IF([test "x$PKG_CONFIG" != "x"], [
  374. AC_CONFIG_FILES([libsodium.pc])
  375. ])
  376. AC_CONFIG_FILES([Makefile
  377. dist-build/Makefile
  378. msvc-scripts/Makefile
  379. src/Makefile
  380. src/libsodium/Makefile
  381. src/libsodium/include/Makefile
  382. src/libsodium/include/sodium/version.h
  383. ])
  384. AC_OUTPUT