2 AC_INIT([libsecp256k1],[0.1])
3 AC_CONFIG_AUX_DIR([src/build-aux])
4 AC_CONFIG_MACRO_DIR([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])
18 AC_ARG_WITH([pkgconfigdir], AS_HELP_STRING([--with-pkgconfigdir=PATH],
19 [Path to the pkgconfig directory [[LIBDIR/pkgconfig]]]),
20 [pkgconfigdir="$withval"], [pkgconfigdir='${libdir}/pkgconfig'])
21 AC_SUBST([pkgconfigdir])
24 if test x"$ac_cv_prog_cc_c99" == x"no"; then
25 AC_MSG_ERROR([c99 compiler support required])
37 AC_ARG_ENABLE(benchmark,
38 AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is yes)]),
39 [use_benchmark=$enableval],
43 AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
44 [use_tests=$enableval],
47 AC_ARG_ENABLE(endomorphism,
48 AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
49 [use_endomorphism=$enableval],
50 [use_endomorphism=no])
52 AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=gmp|64bit|64bit_asm|32bit|auto],
53 [Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
55 AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|openssl|auto],
56 [Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
58 AC_CHECK_TYPES([__int128])
60 AC_DEFUN([SECP_INT128_CHECK],[
61 has_int128=$ac_cv_type___int128
62 if test x"$has_int128" != x"yes" && test x"$set_field" = x"64bit"; then
63 AC_MSG_ERROR([$set_field field support explicitly requested but is not compatible with this host])
67 AC_DEFUN([SECP_64BIT_ASM_CHECK],[
68 if test x"$host_cpu" == x"x86_64"; then
69 AC_CHECK_PROG(YASM, yasm, yasm)
71 if test x"$set_field" = x"64bit_asm"; then
72 AC_MSG_ERROR([$set_field field support explicitly requested but is not compatible with this host])
75 if test x$YASM = x; then
76 if test x"$set_field" = x"64bit_asm"; then
77 AC_MSG_ERROR([$set_field field support explicitly requested but yasm was not found])
89 if $YASM -f help | grep -q $YASM_BINFMT; then
92 if test x"$set_field" = x"64bit_asm"; then
93 AC_MSG_ERROR([$set_field field support explicitly requested but yasm doesn't support $YASM_BINFMT format])
95 AC_MSG_WARN([yasm too old for $YASM_BINFMT format])
101 AC_DEFUN([SECP_OPENSSL_CHECK],[
102 if test x"$use_pkgconfig" = x"yes"; then
104 m4_ifdef([PKG_CHECK_MODULES],[
105 PKG_CHECK_MODULES([SSL], [libssl], [has_libssl=yes; AC_DEFINE(HAVE_LIBSSL,1,[Define this symbol if libssl is installed])],[has_libssl=no])
106 PKG_CHECK_MODULES([CRYPTO], [libcrypto], [has_libcrypto=yes; AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])],[has_libcrypto=no])
110 AC_CHECK_HEADER(openssl/ssl.h,[has_libssl=yes; AC_DEFINE(HAVE_LIBSSL,1,[Define this symbol if libssl is installed])])
111 AC_CHECK_HEADER(openssl/crypto.h,[AC_CHECK_LIB(crypto, main,[has_libcrypto=yes; CRYPTO_LIBS=-lcrypto; AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])]
115 if test x"$has_libssl" == x"yes" && test x"$has_openssl_ec" = x; then
116 AC_MSG_CHECKING(for EC functions in libssl)
118 #include <openssl/ec.h>
119 #include <openssl/ecdsa.h>
120 #include <openssl/obj_mac.h>],[
121 EC_KEY *eckey = EC_KEY_new_by_curve_name(NID_secp256k1);
122 ECDSA_sign(0, NULL, 0, NULL, NULL, eckey);
123 ECDSA_verify(0, NULL, 0, NULL, 0, eckey);
125 ],[has_openssl_ec=yes], [has_openssl_ec=no])
126 AC_MSG_RESULT([$has_openssl_ec])
128 if test x"$set_bignum" = x"openssl"; then
129 if test x"$has_libssl" != x"yes"; then
130 AC_MSG_ERROR([$set_bignum field support explicitly requested but libssl was not found])
132 if test x"$has_libcrypto" != x"yes"; then
133 AC_MSG_ERROR([$set_bignum field support explicitly requested but libcrypto was not found])
138 AC_DEFUN([SECP_GMP_CHECK],[
139 if test x"$has_gmp" != x"yes"; then
140 AC_CHECK_HEADER(gmp.h,[AC_CHECK_LIB(gmp, __gmpz_init,[has_gmp=yes; GMP_LIBS=-lgmp; AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])])])
142 if test x"$set_field" = x"gmp" && test x"$has_gmp" != x"yes"; then
143 AC_MSG_ERROR([$set_field field support explicitly requested but libgmp was not found])
145 if test x"$set_bignum" = x"gmp" && test x"$has_gmp" != x"yes"; then
146 AC_MSG_ERROR([$set_bignum field support explicitly requested but libgmp was not found])
150 if test x"$req_field" = x"auto"; then
152 if test x"$has_64bit_asm" = x"yes"; then
156 if test x"$set_field" = x; then
158 if test x"$has_int128" = x"yes"; then
163 if test x"$set_field" = x; then
165 if test x"$has_gmp" = x"yes"; then
170 if test x"$set_field" = x; then
188 AC_MSG_ERROR([invalid field implementation selection])
193 if test x"$req_bignum" = x"auto"; then
195 if test x"$has_gmp" = x"yes"; then
199 if test x"$set_bignum" = x; then
201 if test x"$has_libssl" = x"yes"; then
206 if test x"$set_bignum" = x; then
207 AC_MSG_ERROR([no working bignum implementation found])
210 set_bignum=$req_bignum
219 AC_MSG_ERROR([invalid bignum implementation selection])
224 # select field implementation
227 AC_DEFINE(USE_FIELD_5X52_ASM, 1, [Define this symbol to use the assembly version for the 5x52 field implementation])
228 AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
231 AC_DEFINE(USE_FIELD_5X52_INT128, 1, [Define this symbol to use the __int128 version for the 5x52 field implementation])
232 AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
235 AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])
236 AC_DEFINE(USE_FIELD_GMP, 1, [Define this symbol to use the FIELD_GMP implementation])
239 AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
242 AC_MSG_ERROR([invalid field implementation])
246 # select bignum implementation
249 AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])
250 AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation])
251 AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the USE_FIELD_INV_NUM implementation])
254 AC_DEFINE(USE_NUM_OPENSSL, 1,[Define this symbol to use the openssl implementation])
255 AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the FIELD_INV_BUILTIN implementation])
256 SECP_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
257 SECP_LIBS="$CRYPTO_LIBS"
260 AC_MSG_ERROR([invalid bignum implementation])
264 if test x"$use_tests" = x"yes"; then
266 if test x"$has_openssl_ec" == x"yes"; then
267 AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
268 SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
269 SECP_TEST_LIBS="$CRYPTO_LIBS"
273 SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
280 if test x"$set_field" = x"gmp" || test x"$set_bignum" = x"gmp"; then
281 SECP_LIBS="$SECP_LIBS $GMP_LIBS"
284 if test x"$use_endomorphism" = x"yes"; then
285 AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism])
288 AC_MSG_NOTICE([Using field implementation: $set_field])
289 AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
291 AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
292 AC_CONFIG_FILES([Makefile libsecp256k1.pc])
293 AC_SUBST(SECP_INCLUDES)
295 AC_SUBST(SECP_TEST_LIBS)
296 AC_SUBST(SECP_TEST_INCLUDES)
297 AC_SUBST(YASM_BINFMT)
298 AM_CONDITIONAL([USE_ASM], [test x"$set_field" == x"64bit_asm"])
299 AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
300 AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" != x"no"])