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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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="-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 yes)]),
  77. [use_benchmark=$enableval],
  78. [use_benchmark=yes])
  79. AC_ARG_ENABLE(coverage,
  80. AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis]),
  81. [enable_coverage=$enableval],
  82. [enable_coverage=no])
  83. AC_ARG_ENABLE(tests,
  84. AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
  85. [use_tests=$enableval],
  86. [use_tests=yes])
  87. AC_ARG_ENABLE(openssl_tests,
  88. AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests, if OpenSSL is available (default is auto)]),
  89. [enable_openssl_tests=$enableval],
  90. [enable_openssl_tests=auto])
  91. AC_ARG_ENABLE(experimental,
  92. AS_HELP_STRING([--enable-experimental],[allow experimental configure options (default is no)]),
  93. [use_experimental=$enableval],
  94. [use_experimental=no])
  95. AC_ARG_ENABLE(exhaustive_tests,
  96. AS_HELP_STRING([--enable-exhaustive-tests],[compile exhaustive tests (default is yes)]),
  97. [use_exhaustive_tests=$enableval],
  98. [use_exhaustive_tests=yes])
  99. AC_ARG_ENABLE(endomorphism,
  100. AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
  101. [use_endomorphism=$enableval],
  102. [use_endomorphism=no])
  103. AC_ARG_ENABLE(ecmult_static_precomputation,
  104. AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing (default is yes)]),
  105. [use_ecmult_static_precomputation=$enableval],
  106. [use_ecmult_static_precomputation=auto])
  107. AC_ARG_ENABLE(module_ecdh,
  108. AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation (experimental)]),
  109. [enable_module_ecdh=$enableval],
  110. [enable_module_ecdh=no])
  111. AC_ARG_ENABLE(module_recovery,
  112. AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module (default is no)]),
  113. [enable_module_recovery=$enableval],
  114. [enable_module_recovery=no])
  115. AC_ARG_ENABLE(jni,
  116. AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni (default is no)]),
  117. [use_jni=$enableval],
  118. [use_jni=no])
  119. AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
  120. [Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
  121. AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
  122. [Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
  123. AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
  124. [Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
  125. AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto]
  126. [Specify assembly optimizations to use. Default is auto (experimental: arm)])],[req_asm=$withval], [req_asm=auto])
  127. AC_CHECK_TYPES([__int128])
  128. AC_MSG_CHECKING([for __builtin_expect])
  129. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])],
  130. [ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_EXPECT,1,[Define this symbol if __builtin_expect is available]) ],
  131. [ AC_MSG_RESULT([no])
  132. ])
  133. if test x"$enable_coverage" = x"yes"; then
  134. AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
  135. CFLAGS="$CFLAGS -O0 --coverage"
  136. LDFLAGS="--coverage"
  137. else
  138. CFLAGS="$CFLAGS -O3"
  139. fi
  140. if test x"$use_ecmult_static_precomputation" != x"no"; then
  141. save_cross_compiling=$cross_compiling
  142. cross_compiling=no
  143. TEMP_CC="$CC"
  144. CC="$CC_FOR_BUILD"
  145. AC_MSG_CHECKING([native compiler: ${CC_FOR_BUILD}])
  146. AC_RUN_IFELSE(
  147. [AC_LANG_PROGRAM([], [return 0])],
  148. [working_native_cc=yes],
  149. [working_native_cc=no],[dnl])
  150. CC="$TEMP_CC"
  151. cross_compiling=$save_cross_compiling
  152. if test x"$working_native_cc" = x"no"; then
  153. set_precomp=no
  154. if test x"$use_ecmult_static_precomputation" = x"yes"; then
  155. AC_MSG_ERROR([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
  156. else
  157. AC_MSG_RESULT([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
  158. fi
  159. else
  160. AC_MSG_RESULT([ok])
  161. set_precomp=yes
  162. fi
  163. else
  164. set_precomp=no
  165. fi
  166. if test x"$req_asm" = x"auto"; then
  167. SECP_64BIT_ASM_CHECK
  168. if test x"$has_64bit_asm" = x"yes"; then
  169. set_asm=x86_64
  170. fi
  171. if test x"$set_asm" = x; then
  172. set_asm=no
  173. fi
  174. else
  175. set_asm=$req_asm
  176. case $set_asm in
  177. x86_64)
  178. SECP_64BIT_ASM_CHECK
  179. if test x"$has_64bit_asm" != x"yes"; then
  180. AC_MSG_ERROR([x86_64 assembly optimization requested but not available])
  181. fi
  182. ;;
  183. arm)
  184. ;;
  185. no)
  186. ;;
  187. *)
  188. AC_MSG_ERROR([invalid assembly optimization selection])
  189. ;;
  190. esac
  191. fi
  192. if test x"$req_field" = x"auto"; then
  193. if test x"set_asm" = x"x86_64"; then
  194. set_field=64bit
  195. fi
  196. if test x"$set_field" = x; then
  197. SECP_INT128_CHECK
  198. if test x"$has_int128" = x"yes"; then
  199. set_field=64bit
  200. fi
  201. fi
  202. if test x"$set_field" = x; then
  203. set_field=32bit
  204. fi
  205. else
  206. set_field=$req_field
  207. case $set_field in
  208. 64bit)
  209. if test x"$set_asm" != x"x86_64"; then
  210. SECP_INT128_CHECK
  211. if test x"$has_int128" != x"yes"; then
  212. AC_MSG_ERROR([64bit field explicitly requested but neither __int128 support or x86_64 assembly available])
  213. fi
  214. fi
  215. ;;
  216. 32bit)
  217. ;;
  218. *)
  219. AC_MSG_ERROR([invalid field implementation selection])
  220. ;;
  221. esac
  222. fi
  223. if test x"$req_scalar" = x"auto"; then
  224. SECP_INT128_CHECK
  225. if test x"$has_int128" = x"yes"; then
  226. set_scalar=64bit
  227. fi
  228. if test x"$set_scalar" = x; then
  229. set_scalar=32bit
  230. fi
  231. else
  232. set_scalar=$req_scalar
  233. case $set_scalar in
  234. 64bit)
  235. SECP_INT128_CHECK
  236. if test x"$has_int128" != x"yes"; then
  237. AC_MSG_ERROR([64bit scalar explicitly requested but __int128 support not available])
  238. fi
  239. ;;
  240. 32bit)
  241. ;;
  242. *)
  243. AC_MSG_ERROR([invalid scalar implementation selected])
  244. ;;
  245. esac
  246. fi
  247. if test x"$req_bignum" = x"auto"; then
  248. SECP_GMP_CHECK
  249. if test x"$has_gmp" = x"yes"; then
  250. set_bignum=gmp
  251. fi
  252. if test x"$set_bignum" = x; then
  253. set_bignum=no
  254. fi
  255. else
  256. set_bignum=$req_bignum
  257. case $set_bignum in
  258. gmp)
  259. SECP_GMP_CHECK
  260. if test x"$has_gmp" != x"yes"; then
  261. AC_MSG_ERROR([gmp bignum explicitly requested but libgmp not available])
  262. fi
  263. ;;
  264. no)
  265. ;;
  266. *)
  267. AC_MSG_ERROR([invalid bignum implementation selection])
  268. ;;
  269. esac
  270. fi
  271. # select assembly optimization
  272. use_external_asm=no
  273. case $set_asm in
  274. x86_64)
  275. AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations])
  276. ;;
  277. arm)
  278. use_external_asm=yes
  279. ;;
  280. no)
  281. ;;
  282. *)
  283. AC_MSG_ERROR([invalid assembly optimizations])
  284. ;;
  285. esac
  286. # select field implementation
  287. case $set_field in
  288. 64bit)
  289. AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
  290. ;;
  291. 32bit)
  292. AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
  293. ;;
  294. *)
  295. AC_MSG_ERROR([invalid field implementation])
  296. ;;
  297. esac
  298. # select bignum implementation
  299. case $set_bignum in
  300. gmp)
  301. AC_DEFINE(HAVE_LIBGMP, 1, [Define this symbol if libgmp is installed])
  302. AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation for num])
  303. AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation])
  304. AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation])
  305. ;;
  306. no)
  307. AC_DEFINE(USE_NUM_NONE, 1, [Define this symbol to use no num implementation])
  308. AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the native field inverse implementation])
  309. AC_DEFINE(USE_SCALAR_INV_BUILTIN, 1, [Define this symbol to use the native scalar inverse implementation])
  310. ;;
  311. *)
  312. AC_MSG_ERROR([invalid bignum implementation])
  313. ;;
  314. esac
  315. #select scalar implementation
  316. case $set_scalar in
  317. 64bit)
  318. AC_DEFINE(USE_SCALAR_4X64, 1, [Define this symbol to use the 4x64 scalar implementation])
  319. ;;
  320. 32bit)
  321. AC_DEFINE(USE_SCALAR_8X32, 1, [Define this symbol to use the 8x32 scalar implementation])
  322. ;;
  323. *)
  324. AC_MSG_ERROR([invalid scalar implementation])
  325. ;;
  326. esac
  327. if test x"$use_tests" = x"yes"; then
  328. SECP_OPENSSL_CHECK
  329. if test x"$has_openssl_ec" = x"yes"; then
  330. if test x"$enable_openssl_tests" != x"no"; then
  331. AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
  332. SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
  333. SECP_TEST_LIBS="$CRYPTO_LIBS"
  334. case $host in
  335. *mingw*)
  336. SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
  337. ;;
  338. esac
  339. fi
  340. else
  341. if test x"$enable_openssl_tests" = x"yes"; then
  342. AC_MSG_ERROR([OpenSSL tests requested but OpenSSL with EC support is not available])
  343. fi
  344. fi
  345. else
  346. if test x"$enable_openssl_tests" = x"yes"; then
  347. AC_MSG_ERROR([OpenSSL tests requested but tests are not enabled])
  348. fi
  349. fi
  350. if test x"$use_jni" != x"no"; then
  351. AX_JNI_INCLUDE_DIR
  352. have_jni_dependencies=yes
  353. if test x"$enable_module_ecdh" = x"no"; then
  354. have_jni_dependencies=no
  355. fi
  356. if test "x$JNI_INCLUDE_DIRS" = "x"; then
  357. have_jni_dependencies=no
  358. fi
  359. if test "x$have_jni_dependencies" = "xno"; then
  360. if test x"$use_jni" = x"yes"; then
  361. AC_MSG_ERROR([jni support explicitly requested but headers/dependencies were not found. Enable ECDH and try again.])
  362. fi
  363. AC_MSG_WARN([jni headers/dependencies not found. jni support disabled])
  364. use_jni=no
  365. else
  366. use_jni=yes
  367. for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS; do
  368. JNI_INCLUDES="$JNI_INCLUDES -I$JNI_INCLUDE_DIR"
  369. done
  370. fi
  371. fi
  372. if test x"$set_bignum" = x"gmp"; then
  373. SECP_LIBS="$SECP_LIBS $GMP_LIBS"
  374. SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
  375. fi
  376. if test x"$use_endomorphism" = x"yes"; then
  377. AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism optimization])
  378. fi
  379. if test x"$set_precomp" = x"yes"; then
  380. AC_DEFINE(USE_ECMULT_STATIC_PRECOMPUTATION, 1, [Define this symbol to use a statically generated ecmult table])
  381. fi
  382. if test x"$enable_module_ecdh" = x"yes"; then
  383. AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
  384. fi
  385. if test x"$enable_module_recovery" = x"yes"; then
  386. AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
  387. fi
  388. AC_C_BIGENDIAN()
  389. if test x"$use_external_asm" = x"yes"; then
  390. AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
  391. fi
  392. AC_MSG_NOTICE([Using static precomputation: $set_precomp])
  393. AC_MSG_NOTICE([Using assembly optimizations: $set_asm])
  394. AC_MSG_NOTICE([Using field implementation: $set_field])
  395. AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
  396. AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
  397. AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
  398. AC_MSG_NOTICE([Building benchmarks: $use_benchmark])
  399. AC_MSG_NOTICE([Building for coverage analysis: $enable_coverage])
  400. AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
  401. AC_MSG_NOTICE([Building ECDSA pubkey recovery module: $enable_module_recovery])
  402. AC_MSG_NOTICE([Using jni: $use_jni])
  403. if test x"$enable_experimental" = x"yes"; then
  404. AC_MSG_NOTICE([******])
  405. AC_MSG_NOTICE([WARNING: experimental build])
  406. AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
  407. AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
  408. AC_MSG_NOTICE([******])
  409. else
  410. if test x"$enable_module_ecdh" = x"yes"; then
  411. AC_MSG_ERROR([ECDH module is experimental. Use --enable-experimental to allow.])
  412. fi
  413. if test x"$set_asm" = x"arm"; then
  414. AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
  415. fi
  416. fi
  417. AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
  418. AC_CONFIG_FILES([Makefile libsecp256k1.pc])
  419. AC_SUBST(JNI_INCLUDES)
  420. AC_SUBST(SECP_INCLUDES)
  421. AC_SUBST(SECP_LIBS)
  422. AC_SUBST(SECP_TEST_LIBS)
  423. AC_SUBST(SECP_TEST_INCLUDES)
  424. AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"])
  425. AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
  426. AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$use_exhaustive_tests" != x"no"])
  427. AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
  428. AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"])
  429. AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
  430. AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
  431. AM_CONDITIONAL([USE_JNI], [test x"$use_jni" == x"yes"])
  432. AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
  433. AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
  434. dnl make sure nothing new is exported so that we don't break the cache
  435. PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
  436. unset PKG_CONFIG_PATH
  437. PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
  438. AC_OUTPUT