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