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.

configure.ac 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. AC_PREREQ([2.60])
  2. AC_INIT([libsecp256k1],[0.1])
  3. AC_CONFIG_AUX_DIR([build-aux])
  4. AC_CONFIG_MACRO_DIR([build-aux/m4])
  5. AC_CANONICAL_HOST
  6. AH_TOP([#ifndef LIBSECP256K1_CONFIG_H])
  7. AH_TOP([#define LIBSECP256K1_CONFIG_H])
  8. AH_BOTTOM([#endif /*LIBSECP256K1_CONFIG_H*/])
  9. AM_INIT_AUTOMAKE([foreign subdir-objects])
  10. LT_INIT
  11. dnl make the compilation flags quiet unless V=1 is used
  12. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  13. PKG_PROG_PKG_CONFIG
  14. AC_PATH_TOOL(AR, ar)
  15. AC_PATH_TOOL(RANLIB, ranlib)
  16. AC_PATH_TOOL(STRIP, strip)
  17. AX_PROG_CC_FOR_BUILD
  18. if test "x$CFLAGS" = "x"; then
  19. CFLAGS="-O3 -g"
  20. fi
  21. AM_PROG_CC_C_O
  22. AC_PROG_CC_C89
  23. if test x"$ac_cv_prog_cc_c89" = x"no"; then
  24. AC_MSG_ERROR([c89 compiler support required])
  25. fi
  26. AM_PROG_AS
  27. case $host_os in
  28. *darwin*)
  29. if test x$cross_compiling != xyes; then
  30. AC_PATH_PROG([BREW],brew,)
  31. if test x$BREW != x; then
  32. dnl These Homebrew packages may be keg-only, meaning that they won't be found
  33. dnl in expected paths because they may conflict with system files. Ask
  34. dnl Homebrew where each one is located, then adjust paths accordingly.
  35. openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
  36. gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
  37. if test x$openssl_prefix != x; then
  38. PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
  39. export PKG_CONFIG_PATH
  40. fi
  41. if test x$gmp_prefix != x; then
  42. GMP_CPPFLAGS="-I$gmp_prefix/include"
  43. GMP_LIBS="-L$gmp_prefix/lib"
  44. fi
  45. else
  46. AC_PATH_PROG([PORT],port,)
  47. dnl if homebrew isn't installed and macports is, add the macports default paths
  48. dnl as a last resort.
  49. if test x$PORT != x; then
  50. CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
  51. LDFLAGS="$LDFLAGS -L/opt/local/lib"
  52. fi
  53. fi
  54. fi
  55. ;;
  56. esac
  57. CFLAGS="$CFLAGS -W"
  58. warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings"
  59. saved_CFLAGS="$CFLAGS"
  60. CFLAGS="$CFLAGS $warn_CFLAGS"
  61. AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
  62. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
  63. [ AC_MSG_RESULT([yes]) ],
  64. [ AC_MSG_RESULT([no])
  65. CFLAGS="$saved_CFLAGS"
  66. ])
  67. saved_CFLAGS="$CFLAGS"
  68. CFLAGS="$CFLAGS -fvisibility=hidden"
  69. AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])
  70. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
  71. [ AC_MSG_RESULT([yes]) ],
  72. [ AC_MSG_RESULT([no])
  73. CFLAGS="$saved_CFLAGS"
  74. ])
  75. AC_ARG_ENABLE(benchmark,
  76. AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is no)]),
  77. [use_benchmark=$enableval],
  78. [use_benchmark=no])
  79. AC_ARG_ENABLE(tests,
  80. AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
  81. [use_tests=$enableval],
  82. [use_tests=yes])
  83. AC_ARG_ENABLE(openssl_tests,
  84. AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests, if OpenSSL is available (default is auto)]),
  85. [enable_openssl_tests=$enableval],
  86. [enable_openssl_tests=auto])
  87. AC_ARG_ENABLE(experimental,
  88. AS_HELP_STRING([--enable-experimental],[allow experimental configure options (default is no)]),
  89. [use_experimental=$enableval],
  90. [use_experimental=no])
  91. AC_ARG_ENABLE(endomorphism,
  92. AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
  93. [use_endomorphism=$enableval],
  94. [use_endomorphism=no])
  95. AC_ARG_ENABLE(ecmult_static_precomputation,
  96. AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing (default is yes)]),
  97. [use_ecmult_static_precomputation=$enableval],
  98. [use_ecmult_static_precomputation=auto])
  99. AC_ARG_ENABLE(module_ecdh,
  100. AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation (experimental)]),
  101. [enable_module_ecdh=$enableval],
  102. [enable_module_ecdh=no])
  103. AC_ARG_ENABLE(module_recovery,
  104. AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module (default is no)]),
  105. [enable_module_recovery=$enableval],
  106. [enable_module_recovery=no])
  107. AC_ARG_ENABLE(jni,
  108. AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni (default is auto)]),
  109. [use_jni=$enableval],
  110. [use_jni=auto])
  111. AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
  112. [Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
  113. AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
  114. [Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
  115. AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
  116. [Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
  117. AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto]
  118. [Specify assembly optimizations to use. Default is auto (experimental: arm)])],[req_asm=$withval], [req_asm=auto])
  119. AC_CHECK_TYPES([__int128])
  120. AC_MSG_CHECKING([for __builtin_expect])
  121. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])],
  122. [ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_EXPECT,1,[Define this symbol if __builtin_expect is available]) ],
  123. [ AC_MSG_RESULT([no])
  124. ])
  125. if test x"$use_ecmult_static_precomputation" != x"no"; then
  126. save_cross_compiling=$cross_compiling
  127. cross_compiling=no
  128. TEMP_CC="$CC"
  129. CC="$CC_FOR_BUILD"
  130. AC_MSG_CHECKING([native compiler: ${CC_FOR_BUILD}])
  131. AC_RUN_IFELSE(
  132. [AC_LANG_PROGRAM([], [return 0])],
  133. [working_native_cc=yes],
  134. [working_native_cc=no],[dnl])
  135. CC="$TEMP_CC"
  136. cross_compiling=$save_cross_compiling
  137. if test x"$working_native_cc" = x"no"; then
  138. set_precomp=no
  139. if test x"$use_ecmult_static_precomputation" = x"yes"; then
  140. AC_MSG_ERROR([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
  141. else
  142. AC_MSG_RESULT([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
  143. fi
  144. else
  145. AC_MSG_RESULT([ok])
  146. set_precomp=yes
  147. fi
  148. else
  149. set_precomp=no
  150. fi
  151. if test x"$req_asm" = x"auto"; then
  152. SECP_64BIT_ASM_CHECK
  153. if test x"$has_64bit_asm" = x"yes"; then
  154. set_asm=x86_64
  155. fi
  156. if test x"$set_asm" = x; then
  157. set_asm=no
  158. fi
  159. else
  160. set_asm=$req_asm
  161. case $set_asm in
  162. x86_64)
  163. SECP_64BIT_ASM_CHECK
  164. if test x"$has_64bit_asm" != x"yes"; then
  165. AC_MSG_ERROR([x86_64 assembly optimization requested but not available])
  166. fi
  167. ;;
  168. arm)
  169. ;;
  170. no)
  171. ;;
  172. *)
  173. AC_MSG_ERROR([invalid assembly optimization selection])
  174. ;;
  175. esac
  176. fi
  177. if test x"$req_field" = x"auto"; then
  178. if test x"set_asm" = x"x86_64"; then
  179. set_field=64bit
  180. fi
  181. if test x"$set_field" = x; then
  182. SECP_INT128_CHECK
  183. if test x"$has_int128" = x"yes"; then
  184. set_field=64bit
  185. fi
  186. fi
  187. if test x"$set_field" = x; then
  188. set_field=32bit
  189. fi
  190. else
  191. set_field=$req_field
  192. case $set_field in
  193. 64bit)
  194. if test x"$set_asm" != x"x86_64"; then
  195. SECP_INT128_CHECK
  196. if test x"$has_int128" != x"yes"; then
  197. AC_MSG_ERROR([64bit field explicitly requested but neither __int128 support or x86_64 assembly available])
  198. fi
  199. fi
  200. ;;
  201. 32bit)
  202. ;;
  203. *)
  204. AC_MSG_ERROR([invalid field implementation selection])
  205. ;;
  206. esac
  207. fi
  208. if test x"$req_scalar" = x"auto"; then
  209. SECP_INT128_CHECK
  210. if test x"$has_int128" = x"yes"; then
  211. set_scalar=64bit
  212. fi
  213. if test x"$set_scalar" = x; then
  214. set_scalar=32bit
  215. fi
  216. else
  217. set_scalar=$req_scalar
  218. case $set_scalar in
  219. 64bit)
  220. SECP_INT128_CHECK
  221. if test x"$has_int128" != x"yes"; then
  222. AC_MSG_ERROR([64bit scalar explicitly requested but __int128 support not available])
  223. fi
  224. ;;
  225. 32bit)
  226. ;;
  227. *)
  228. AC_MSG_ERROR([invalid scalar implementation selected])
  229. ;;
  230. esac
  231. fi
  232. if test x"$req_bignum" = x"auto"; then
  233. SECP_GMP_CHECK
  234. if test x"$has_gmp" = x"yes"; then
  235. set_bignum=gmp
  236. fi
  237. if test x"$set_bignum" = x; then
  238. set_bignum=no
  239. fi
  240. else
  241. set_bignum=$req_bignum
  242. case $set_bignum in
  243. gmp)
  244. SECP_GMP_CHECK
  245. if test x"$has_gmp" != x"yes"; then
  246. AC_MSG_ERROR([gmp bignum explicitly requested but libgmp not available])
  247. fi
  248. ;;
  249. no)
  250. ;;
  251. *)
  252. AC_MSG_ERROR([invalid bignum implementation selection])
  253. ;;
  254. esac
  255. fi
  256. # select assembly optimization
  257. use_external_asm=no
  258. case $set_asm in
  259. x86_64)
  260. AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations])
  261. ;;
  262. arm)
  263. use_external_asm=yes
  264. ;;
  265. no)
  266. ;;
  267. *)
  268. AC_MSG_ERROR([invalid assembly optimizations])
  269. ;;
  270. esac
  271. # select field implementation
  272. case $set_field in
  273. 64bit)
  274. AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
  275. ;;
  276. 32bit)
  277. AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
  278. ;;
  279. *)
  280. AC_MSG_ERROR([invalid field implementation])
  281. ;;
  282. esac
  283. # select bignum implementation
  284. case $set_bignum in
  285. gmp)
  286. AC_DEFINE(HAVE_LIBGMP, 1, [Define this symbol if libgmp is installed])
  287. AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation for num])
  288. AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation])
  289. AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation])
  290. ;;
  291. no)
  292. AC_DEFINE(USE_NUM_NONE, 1, [Define this symbol to use no num implementation])
  293. AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the native field inverse implementation])
  294. AC_DEFINE(USE_SCALAR_INV_BUILTIN, 1, [Define this symbol to use the native scalar inverse implementation])
  295. ;;
  296. *)
  297. AC_MSG_ERROR([invalid bignum implementation])
  298. ;;
  299. esac
  300. #select scalar implementation
  301. case $set_scalar in
  302. 64bit)
  303. AC_DEFINE(USE_SCALAR_4X64, 1, [Define this symbol to use the 4x64 scalar implementation])
  304. ;;
  305. 32bit)
  306. AC_DEFINE(USE_SCALAR_8X32, 1, [Define this symbol to use the 8x32 scalar implementation])
  307. ;;
  308. *)
  309. AC_MSG_ERROR([invalid scalar implementation])
  310. ;;
  311. esac
  312. if test x"$use_tests" = x"yes"; then
  313. SECP_OPENSSL_CHECK
  314. if test x"$has_openssl_ec" = x"yes"; then
  315. if test x"$enable_openssl_tests" != x"no"; then
  316. AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
  317. SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
  318. SECP_TEST_LIBS="$CRYPTO_LIBS"
  319. case $host in
  320. *mingw*)
  321. SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
  322. ;;
  323. esac
  324. fi
  325. else
  326. if test x"$enable_openssl_tests" = x"yes"; then
  327. AC_MSG_ERROR([OpenSSL tests requested but OpenSSL with EC support is not available])
  328. fi
  329. fi
  330. else
  331. if test x"$enable_openssl_tests" = x"yes"; then
  332. AC_MSG_ERROR([OpenSSL tests requested but tests are not enabled])
  333. fi
  334. fi
  335. if test x"$use_jni" != x"no"; then
  336. AX_JNI_INCLUDE_DIR
  337. have_jni_dependencies=yes
  338. if test x"$enable_module_ecdh" = x"no"; then
  339. have_jni_dependencies=no
  340. fi
  341. if test "x$JNI_INCLUDE_DIRS" = "x"; then
  342. have_jni_dependencies=no
  343. fi
  344. if test "x$have_jni_dependencies" = "xno"; then
  345. if test x"$use_jni" = x"yes"; then
  346. AC_MSG_ERROR([jni support explicitly requested but headers/dependencies were not found. Enable ECDH and try again.])
  347. fi
  348. AC_MSG_WARN([jni headers/dependencies not found. jni support disabled])
  349. use_jni=no
  350. else
  351. use_jni=yes
  352. for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS; do
  353. JNI_INCLUDES="$JNI_INCLUDES -I$JNI_INCLUDE_DIR"
  354. done
  355. fi
  356. fi
  357. if test x"$set_bignum" = x"gmp"; then
  358. SECP_LIBS="$SECP_LIBS $GMP_LIBS"
  359. SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
  360. fi
  361. if test x"$use_endomorphism" = x"yes"; then
  362. AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism optimization])
  363. fi
  364. if test x"$set_precomp" = x"yes"; then
  365. AC_DEFINE(USE_ECMULT_STATIC_PRECOMPUTATION, 1, [Define this symbol to use a statically generated ecmult table])
  366. fi
  367. if test x"$enable_module_ecdh" = x"yes"; then
  368. AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
  369. fi
  370. if test x"$enable_module_recovery" = x"yes"; then
  371. AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
  372. fi
  373. AC_C_BIGENDIAN()
  374. if test x"$use_external_asm" = x"yes"; then
  375. AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
  376. fi
  377. AC_MSG_NOTICE([Using static precomputation: $set_precomp])
  378. AC_MSG_NOTICE([Using assembly optimizations: $set_asm])
  379. AC_MSG_NOTICE([Using field implementation: $set_field])
  380. AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
  381. AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
  382. AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
  383. AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
  384. AC_MSG_NOTICE([Building ECDSA pubkey recovery module: $enable_module_recovery])
  385. AC_MSG_NOTICE([Using jni: $use_jni])
  386. if test x"$enable_experimental" = x"yes"; then
  387. AC_MSG_NOTICE([******])
  388. AC_MSG_NOTICE([WARNING: experimental build])
  389. AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
  390. AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
  391. AC_MSG_NOTICE([******])
  392. else
  393. if test x"$enable_module_ecdh" = x"yes"; then
  394. AC_MSG_ERROR([ECDH module is experimental. Use --enable-experimental to allow.])
  395. fi
  396. if test x"$set_asm" = x"arm"; then
  397. AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
  398. fi
  399. fi
  400. AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
  401. AC_CONFIG_FILES([Makefile libsecp256k1.pc])
  402. AC_SUBST(JNI_INCLUDES)
  403. AC_SUBST(SECP_INCLUDES)
  404. AC_SUBST(SECP_LIBS)
  405. AC_SUBST(SECP_TEST_LIBS)
  406. AC_SUBST(SECP_TEST_INCLUDES)
  407. AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
  408. AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
  409. AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"])
  410. AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
  411. AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
  412. AM_CONDITIONAL([USE_JNI], [test x"$use_jni" == x"yes"])
  413. AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
  414. AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
  415. dnl make sure nothing new is exported so that we don't break the cache
  416. PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
  417. unset PKG_CONFIG_PATH
  418. PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
  419. AC_OUTPUT