]> Git Repo - secp256k1.git/blame - configure.ac
Add constant-time multiply `secp256k1_ecmult_const` for ECDH
[secp256k1.git] / configure.ac
CommitLineData
78cd96b1
CF
1AC_PREREQ([2.60])
2AC_INIT([libsecp256k1],[0.1])
6fac238f 3AC_CONFIG_AUX_DIR([build-aux])
4AC_CONFIG_MACRO_DIR([build-aux/m4])
78cd96b1
CF
5AC_CANONICAL_HOST
6AH_TOP([#ifndef LIBSECP256K1_CONFIG_H])
7AH_TOP([#define LIBSECP256K1_CONFIG_H])
f735446c 8AH_BOTTOM([#endif /*LIBSECP256K1_CONFIG_H*/])
5190079e 9AM_INIT_AUTOMAKE([foreign subdir-objects])
78cd96b1
CF
10LT_INIT
11
53628757
CF
12dnl make the compilation flags quiet unless V=1 is used
13m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
14
78cd96b1
CF
15PKG_PROG_PKG_CONFIG
16
3ab1178d
CF
17AC_PATH_TOOL(AR, ar)
18AC_PATH_TOOL(RANLIB, ranlib)
19AC_PATH_TOOL(STRIP, strip)
fbecc38a 20AX_PROG_CC_FOR_BUILD
3ab1178d 21
056ad310 22if test "x$CFLAGS" = "x"; then
c88e2b8c
PW
23 CFLAGS="-O3 -g"
24fi
25
f735446c
GM
26AC_PROG_CC_C89
27if test x"$ac_cv_prog_cc_c89" = x"no"; then
28 AC_MSG_ERROR([c89 compiler support required])
78cd96b1
CF
29fi
30
31case $host in
32 *mingw*)
33 use_pkgconfig=no
34 ;;
35 *)
36 use_pkgconfig=yes
37 ;;
38esac
39
a86f241d 40case $host_os in
e2274c58
CF
41 *darwin*)
42 if test x$cross_compiling != xyes; then
43 AC_PATH_PROG([BREW],brew,)
44 if test x$BREW != x; then
45 dnl These Homebrew packages may be keg-only, meaning that they won't be found
46 dnl in expected paths because they may conflict with system files. Ask
47 dnl Homebrew where each one is located, then adjust paths accordingly.
48
49 openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
50 gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
51 if test x$openssl_prefix != x; then
52 PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
53 export PKG_CONFIG_PATH
54 fi
55 if test x$gmp_prefix != x; then
56 GMP_CPPFLAGS="-I$gmp_prefix/include"
57 GMP_LIBS="-L$gmp_prefix/lib"
58 fi
59 else
60 AC_PATH_PROG([PORT],port,)
61 dnl if homebrew isn't installed and macports is, add the macports default paths
62 dnl as a last resort.
63 if test x$PORT != x; then
64 CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
65 LDFLAGS="$LDFLAGS -L/opt/local/lib"
66 fi
67 fi
68 fi
69 ;;
a86f241d
PD
70esac
71
a099073a
GM
72CFLAGS="$CFLAGS -W"
73
7c3771dd 74warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings"
a099073a
GM
75saved_CFLAGS="$CFLAGS"
76CFLAGS="$CFLAGS $warn_CFLAGS"
77AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
78AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
79 [ AC_MSG_RESULT([yes]) ],
80 [ AC_MSG_RESULT([no])
81 CFLAGS="$saved_CFLAGS"
82 ])
83
84
78cd96b1 85AC_ARG_ENABLE(benchmark,
8336040f 86 AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is no)]),
78cd96b1 87 [use_benchmark=$enableval],
8336040f 88 [use_benchmark=no])
78cd96b1
CF
89
90AC_ARG_ENABLE(tests,
91 AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
92 [use_tests=$enableval],
93 [use_tests=yes])
94
95AC_ARG_ENABLE(endomorphism,
0e9baf6f 96 AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
78cd96b1 97 [use_endomorphism=$enableval],
0e9baf6f 98 [use_endomorphism=no])
fbecc38a
TD
99
100AC_ARG_ENABLE(ecmult_static_precomputation,
a83bb480 101 AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing (default is yes)]),
fbecc38a 102 [use_ecmult_static_precomputation=$enableval],
a83bb480 103 [use_ecmult_static_precomputation=yes])
78cd96b1 104
7277fd76 105AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
0e9baf6f 106[Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
78cd96b1 107
1ba4a60a 108AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
78cd96b1
CF
109[Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
110
1d52a8b1
PW
111AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
112[Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
113
1ba4a60a
PW
114AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|no|auto]
115[Specify assembly optimizations to use. Default is auto])],[req_asm=$withval], [req_asm=auto])
116
78cd96b1
CF
117AC_CHECK_TYPES([__int128])
118
1f46b006
CF
119AC_MSG_CHECKING([for __builtin_expect])
120AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])],
121 [ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_EXPECT,1,[Define this symbol if __builtin_expect is available]) ],
122 [ AC_MSG_RESULT([no])
123 ])
1c7fa133 124
1ba4a60a 125if test x"$req_asm" = x"auto"; then
0e9baf6f
CF
126 SECP_64BIT_ASM_CHECK
127 if test x"$has_64bit_asm" = x"yes"; then
1ba4a60a
PW
128 set_asm=x86_64
129 fi
130 if test x"$set_asm" = x; then
131 set_asm=no
78cd96b1 132 fi
1ba4a60a
PW
133else
134 set_asm=$req_asm
135 case $set_asm in
136 x86_64)
137 SECP_64BIT_ASM_CHECK
138 if test x"$has_64bit_asm" != x"yes"; then
139 AC_MSG_ERROR([x86_64 assembly optimization requested but not available])
140 fi
141 ;;
142 no)
143 ;;
144 *)
145 AC_MSG_ERROR([invalid assembly optimization selection])
146 ;;
147 esac
148fi
78cd96b1 149
1ba4a60a
PW
150if test x"$req_field" = x"auto"; then
151 if test x"set_asm" = x"x86_64"; then
152 set_field=64bit
153 fi
78cd96b1
CF
154 if test x"$set_field" = x; then
155 SECP_INT128_CHECK
156 if test x"$has_int128" = x"yes"; then
0e9baf6f 157 set_field=64bit
78cd96b1
CF
158 fi
159 fi
78cd96b1 160 if test x"$set_field" = x; then
0e9baf6f 161 set_field=32bit
78cd96b1
CF
162 fi
163else
164 set_field=$req_field
165 case $set_field in
0e9baf6f 166 64bit)
1ba4a60a
PW
167 if test x"$set_asm" != x"x86_64"; then
168 SECP_INT128_CHECK
169 if test x"$has_int128" != x"yes"; then
170 AC_MSG_ERROR([64bit field explicitly requested but neither __int128 support or x86_64 assembly available])
171 fi
172 fi
78cd96b1 173 ;;
0e9baf6f 174 32bit)
78cd96b1
CF
175 ;;
176 *)
177 AC_MSG_ERROR([invalid field implementation selection])
178 ;;
179 esac
180fi
181
1d52a8b1 182if test x"$req_scalar" = x"auto"; then
1ba4a60a
PW
183 SECP_INT128_CHECK
184 if test x"$has_int128" = x"yes"; then
185 set_scalar=64bit
1d52a8b1
PW
186 fi
187 if test x"$set_scalar" = x; then
188 set_scalar=32bit
189 fi
190else
191 set_scalar=$req_scalar
192 case $set_scalar in
193 64bit)
194 SECP_INT128_CHECK
1ba4a60a
PW
195 if test x"$has_int128" != x"yes"; then
196 AC_MSG_ERROR([64bit scalar explicitly requested but __int128 support not available])
197 fi
1d52a8b1
PW
198 ;;
199 32bit)
200 ;;
201 *)
202 AC_MSG_ERROR([invalid scalar implementation selected])
203 ;;
204 esac
205fi
206
78cd96b1
CF
207if test x"$req_bignum" = x"auto"; then
208 SECP_GMP_CHECK
209 if test x"$has_gmp" = x"yes"; then
210 set_bignum=gmp
211 fi
212
78cd96b1 213 if test x"$set_bignum" = x; then
1ba4a60a 214 set_bignum=no
78cd96b1
CF
215 fi
216else
217 set_bignum=$req_bignum
218 case $set_bignum in
219 gmp)
220 SECP_GMP_CHECK
1ba4a60a
PW
221 if test x"$has_gmp" != x"yes"; then
222 AC_MSG_ERROR([gmp bignum explicitly requested but libgmp not available])
223 fi
78cd96b1 224 ;;
1ba4a60a 225 no)
78cd96b1
CF
226 ;;
227 *)
228 AC_MSG_ERROR([invalid bignum implementation selection])
229 ;;
230 esac
231fi
232
1ba4a60a
PW
233# select assembly optimization
234case $set_asm in
235x86_64)
236 AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations])
237 ;;
238no)
239 ;;
240*)
241 AC_MSG_ERROR([invalid assembly optimizations])
242 ;;
243esac
244
78cd96b1
CF
245# select field implementation
246case $set_field in
0e9baf6f 24764bit)
78cd96b1
CF
248 AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
249 ;;
0e9baf6f 25032bit)
78cd96b1
CF
251 AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
252 ;;
253*)
254 AC_MSG_ERROR([invalid field implementation])
255 ;;
256esac
257
258# select bignum implementation
259case $set_bignum in
260gmp)
597128d3
PW
261 AC_DEFINE(HAVE_LIBGMP, 1, [Define this symbol if libgmp is installed])
262 AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation for num])
d1502eb4
PW
263 AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation])
264 AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation])
78cd96b1 265 ;;
1ba4a60a 266no)
597128d3
PW
267 AC_DEFINE(USE_NUM_NONE, 1, [Define this symbol to use no num implementation])
268 AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the native field inverse implementation])
269 AC_DEFINE(USE_SCALAR_INV_BUILTIN, 1, [Define this symbol to use the native scalar inverse implementation])
270 ;;
78cd96b1
CF
271*)
272 AC_MSG_ERROR([invalid bignum implementation])
273 ;;
274esac
275
1d52a8b1
PW
276#select scalar implementation
277case $set_scalar in
27864bit)
279 AC_DEFINE(USE_SCALAR_4X64, 1, [Define this symbol to use the 4x64 scalar implementation])
280 ;;
28132bit)
282 AC_DEFINE(USE_SCALAR_8X32, 1, [Define this symbol to use the 8x32 scalar implementation])
283 ;;
284*)
285 AC_MSG_ERROR([invalid scalar implementation])
286 ;;
287esac
288
78cd96b1
CF
289if test x"$use_tests" = x"yes"; then
290 SECP_OPENSSL_CHECK
28ade27d 291 if test x"$has_openssl_ec" = x"yes"; then
78cd96b1
CF
292 AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
293 SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
294 SECP_TEST_LIBS="$CRYPTO_LIBS"
295
296 case $host in
297 *mingw*)
298 SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
299 ;;
300 esac
301
302 fi
303fi
304
7277fd76 305if test x"$set_bignum" = x"gmp"; then
78cd96b1 306 SECP_LIBS="$SECP_LIBS $GMP_LIBS"
e2274c58 307 SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
78cd96b1
CF
308fi
309
310if test x"$use_endomorphism" = x"yes"; then
c35ff1ea 311 AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism optimization])
78cd96b1
CF
312fi
313
fbecc38a
TD
314if test x"$use_ecmult_static_precomputation" = x"yes"; then
315 AC_DEFINE(USE_ECMULT_STATIC_PRECOMPUTATION, 1, [Define this symbol to use a statically generated ecmult table])
316fi
317
ae55e850
PW
318AC_C_BIGENDIAN()
319
1ba4a60a 320AC_MSG_NOTICE([Using assembly optimizations: $set_asm])
78cd96b1
CF
321AC_MSG_NOTICE([Using field implementation: $set_field])
322AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
1d52a8b1 323AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
1ba4a60a 324AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
78cd96b1
CF
325
326AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
c7ee71f7 327AC_CONFIG_FILES([Makefile libsecp256k1.pc])
78cd96b1
CF
328AC_SUBST(SECP_INCLUDES)
329AC_SUBST(SECP_LIBS)
330AC_SUBST(SECP_TEST_LIBS)
331AC_SUBST(SECP_TEST_INCLUDES)
78cd96b1 332AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
8336040f 333AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
fbecc38a 334AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$use_ecmult_static_precomputation" = x"yes"])
e2274c58
CF
335
336dnl make sure nothing new is exported so that we don't break the cache
337PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
338unset PKG_CONFIG_PATH
339PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
340
78cd96b1 341AC_OUTPUT
This page took 0.061808 seconds and 4 git commands to generate.