2 AC_INIT([libsecp256k1],[0.1])
3 AC_CONFIG_AUX_DIR([build-aux])
4 AC_CONFIG_MACRO_DIR([build-aux/m4])
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])
12 dnl make the compilation flags quiet unless V=1 is used
13 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
18 AC_PATH_TOOL(RANLIB, ranlib)
19 AC_PATH_TOOL(STRIP, strip)
22 if test x"$ac_cv_prog_cc_c99" == x"no"; then
23 AC_MSG_ERROR([c99 compiler support required])
37 if test x$cross_compiling != xyes; then
38 AC_PATH_PROG([BREW],brew,)
39 if test x$BREW != x; then
40 dnl These Homebrew packages may be keg-only, meaning that they won't be found
41 dnl in expected paths because they may conflict with system files. Ask
42 dnl Homebrew where each one is located, then adjust paths accordingly.
44 openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
45 gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
46 if test x$openssl_prefix != x; then
47 PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
48 export PKG_CONFIG_PATH
50 if test x$gmp_prefix != x; then
51 GMP_CPPFLAGS="-I$gmp_prefix/include"
52 GMP_LIBS="-L$gmp_prefix/lib"
55 AC_PATH_PROG([PORT],port,)
56 dnl if homebrew isn't installed and macports is, add the macports default paths
58 if test x$PORT != x; then
59 CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
60 LDFLAGS="$LDFLAGS -L/opt/local/lib"
69 warn_CFLAGS="-Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function"
70 saved_CFLAGS="$CFLAGS"
71 CFLAGS="$CFLAGS $warn_CFLAGS"
72 AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
73 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
74 [ AC_MSG_RESULT([yes]) ],
76 CFLAGS="$saved_CFLAGS"
80 AC_ARG_ENABLE(benchmark,
81 AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is yes)]),
82 [use_benchmark=$enableval],
86 AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
87 [use_tests=$enableval],
90 AC_ARG_ENABLE(endomorphism,
91 AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
92 [use_endomorphism=$enableval],
93 [use_endomorphism=no])
95 AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=gmp|64bit|64bit_asm|32bit|auto],
96 [Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
98 AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|auto],
99 [Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
101 AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
102 [Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
104 AC_CHECK_TYPES([__int128])
106 AC_CHECK_DECL(__builtin_expect,AC_DEFINE(HAVE_BUILTIN_EXPECT,1,[Define this symbol if __builtin_expect is available]),,)
108 if test x"$req_field" = x"auto"; then
110 if test x"$has_64bit_asm" = x"yes"; then
114 if test x"$set_field" = x; then
116 if test x"$has_int128" = x"yes"; then
121 if test x"$set_field" = x; then
123 if test x"$has_gmp" = x"yes"; then
128 if test x"$set_field" = x; then
146 AC_MSG_ERROR([invalid field implementation selection])
151 if test x"$req_scalar" = x"auto"; then
152 if test x"$set_scalar" = x; then
154 if test x"$has_int128" = x"yes"; then
158 if test x"$set_scalar" = x; then
162 set_scalar=$req_scalar
170 AC_MSG_ERROR([invalid scalar implementation selected])
175 if test x"$req_bignum" = x"auto"; then
177 if test x"$has_gmp" = x"yes"; then
181 if test x"$set_bignum" = x; then
182 AC_MSG_ERROR([no working bignum implementation found])
185 set_bignum=$req_bignum
194 AC_MSG_ERROR([invalid bignum implementation selection])
199 # select field implementation
202 AC_DEFINE(USE_FIELD_5X52_ASM, 1, [Define this symbol to use the assembly version for the 5x52 field implementation])
203 AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
206 AC_DEFINE(USE_FIELD_5X52_INT128, 1, [Define this symbol to use the __int128 version for the 5x52 field implementation])
207 AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
210 AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])
211 AC_DEFINE(USE_FIELD_GMP, 1, [Define this symbol to use the FIELD_GMP implementation])
214 AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
217 AC_MSG_ERROR([invalid field implementation])
221 # select bignum implementation
224 AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])
225 AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation])
226 AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation])
227 AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation])
230 AC_MSG_ERROR([invalid bignum implementation])
234 #select scalar implementation
237 AC_DEFINE(USE_SCALAR_4X64, 1, [Define this symbol to use the 4x64 scalar implementation])
240 AC_DEFINE(USE_SCALAR_8X32, 1, [Define this symbol to use the 8x32 scalar implementation])
243 AC_MSG_ERROR([invalid scalar implementation])
247 if test x"$use_tests" = x"yes"; then
249 if test x"$has_openssl_ec" == x"yes"; then
250 AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
251 SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
252 SECP_TEST_LIBS="$CRYPTO_LIBS"
256 SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
263 if test x"$set_field" = x"gmp" || test x"$set_bignum" = x"gmp"; then
264 SECP_LIBS="$SECP_LIBS $GMP_LIBS"
265 SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
268 if test x"$use_endomorphism" = x"yes"; then
269 AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism])
272 AC_MSG_NOTICE([Using field implementation: $set_field])
273 AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
274 AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
276 AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
277 AC_CONFIG_FILES([Makefile libsecp256k1.pc])
278 AC_SUBST(SECP_INCLUDES)
280 AC_SUBST(SECP_TEST_LIBS)
281 AC_SUBST(SECP_TEST_INCLUDES)
282 AC_SUBST(YASM_BINFMT)
283 AM_CONDITIONAL([USE_ASM], [test x"$set_field" == x"64bit_asm"])
284 AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
285 AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" != x"no"])
287 dnl make sure nothing new is exported so that we don't break the cache
288 PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
289 unset PKG_CONFIG_PATH
290 PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"