]>
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]) |
83fb1bce | 10 | |
ca739cba JN |
11 | # Set -g if CFLAGS are not already set, which matches the default autoconf |
12 | # behavior (see PROG_CC in the Autoconf manual) with the exception that we don't | |
13 | # set -O2 here because we set it in any case (see further down). | |
83fb1bce | 14 | : ${CFLAGS="-g"} |
78cd96b1 CF |
15 | LT_INIT |
16 | ||
47802a47 | 17 | # Make the compilation flags quiet unless V=1 is used. |
53628757 CF |
18 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) |
19 | ||
78cd96b1 CF |
20 | PKG_PROG_PKG_CONFIG |
21 | ||
3ab1178d CF |
22 | AC_PATH_TOOL(AR, ar) |
23 | AC_PATH_TOOL(RANLIB, ranlib) | |
24 | AC_PATH_TOOL(STRIP, strip) | |
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 | 31 | fi |
001f1763 | 32 | AM_PROG_AS |
78cd96b1 | 33 | |
a86f241d | 34 | case $host_os in |
e2274c58 CF |
35 | *darwin*) |
36 | if test x$cross_compiling != xyes; then | |
37 | AC_PATH_PROG([BREW],brew,) | |
38 | if test x$BREW != x; then | |
47802a47 TR |
39 | # These Homebrew packages may be keg-only, meaning that they won't be found |
40 | # in expected paths because they may conflict with system files. Ask | |
41 | # Homebrew where each one is located, then adjust paths accordingly. | |
e2274c58 CF |
42 | openssl_prefix=`$BREW --prefix openssl 2>/dev/null` |
43 | gmp_prefix=`$BREW --prefix gmp 2>/dev/null` | |
252c19df | 44 | valgrind_prefix=`$BREW --prefix valgrind 2>/dev/null` |
e2274c58 CF |
45 | if test x$openssl_prefix != x; then |
46 | PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH" | |
47 | export PKG_CONFIG_PATH | |
84b5fc5b | 48 | CRYPTO_CPPFLAGS="-I$openssl_prefix/include" |
e2274c58 CF |
49 | fi |
50 | if test x$gmp_prefix != x; then | |
51 | GMP_CPPFLAGS="-I$gmp_prefix/include" | |
52 | GMP_LIBS="-L$gmp_prefix/lib" | |
53 | fi | |
252c19df TR |
54 | if test x$valgrind_prefix != x; then |
55 | VALGRIND_CPPFLAGS="-I$valgrind_prefix/include" | |
56 | fi | |
e2274c58 CF |
57 | else |
58 | AC_PATH_PROG([PORT],port,) | |
47802a47 TR |
59 | # If homebrew isn't installed and macports is, add the macports default paths |
60 | # as a last resort. | |
e2274c58 CF |
61 | if test x$PORT != x; then |
62 | CPPFLAGS="$CPPFLAGS -isystem /opt/local/include" | |
63 | LDFLAGS="$LDFLAGS -L/opt/local/lib" | |
64 | fi | |
65 | fi | |
66 | fi | |
67 | ;; | |
a86f241d PD |
68 | esac |
69 | ||
ecba8138 | 70 | CFLAGS="-W $CFLAGS" |
a099073a | 71 | |
e73ff309 | 72 | warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef -Wno-unused-function -Wno-long-long -Wno-overlength-strings" |
a099073a | 73 | saved_CFLAGS="$CFLAGS" |
ecba8138 | 74 | CFLAGS="$warn_CFLAGS $CFLAGS" |
a099073a GM |
75 | AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}]) |
76 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], | |
77 | [ AC_MSG_RESULT([yes]) ], | |
78 | [ AC_MSG_RESULT([no]) | |
79 | CFLAGS="$saved_CFLAGS" | |
80 | ]) | |
81 | ||
118cd821 | 82 | saved_CFLAGS="$CFLAGS" |
ecba8138 | 83 | CFLAGS="-fvisibility=hidden $CFLAGS" |
118cd821 GM |
84 | AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden]) |
85 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], | |
86 | [ AC_MSG_RESULT([yes]) ], | |
87 | [ AC_MSG_RESULT([no]) | |
88 | CFLAGS="$saved_CFLAGS" | |
89 | ]) | |
a099073a | 90 | |
47802a47 TR |
91 | ### |
92 | ### Define config arguments | |
93 | ### | |
94 | ||
78cd96b1 | 95 | AC_ARG_ENABLE(benchmark, |
a61a93ff | 96 | AS_HELP_STRING([--enable-benchmark],[compile benchmark [default=yes]]), |
78cd96b1 | 97 | [use_benchmark=$enableval], |
4afec9f1 | 98 | [use_benchmark=yes]) |
78cd96b1 | 99 | |
a724d729 | 100 | AC_ARG_ENABLE(coverage, |
a61a93ff | 101 | AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis [default=no]]), |
a724d729 AP |
102 | [enable_coverage=$enableval], |
103 | [enable_coverage=no]) | |
104 | ||
78cd96b1 | 105 | AC_ARG_ENABLE(tests, |
a61a93ff | 106 | AS_HELP_STRING([--enable-tests],[compile tests [default=yes]]), |
78cd96b1 CF |
107 | [use_tests=$enableval], |
108 | [use_tests=yes]) | |
109 | ||
a9b2a5d8 | 110 | AC_ARG_ENABLE(openssl_tests, |
a61a93ff | 111 | AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests [default=auto]]), |
a9b2a5d8 AP |
112 | [enable_openssl_tests=$enableval], |
113 | [enable_openssl_tests=auto]) | |
114 | ||
83221ecb | 115 | AC_ARG_ENABLE(experimental, |
a61a93ff | 116 | AS_HELP_STRING([--enable-experimental],[allow experimental configure options [default=no]]), |
83221ecb PW |
117 | [use_experimental=$enableval], |
118 | [use_experimental=no]) | |
119 | ||
20b8877b | 120 | AC_ARG_ENABLE(exhaustive_tests, |
a61a93ff | 121 | AS_HELP_STRING([--enable-exhaustive-tests],[compile exhaustive tests [default=yes]]), |
20b8877b AP |
122 | [use_exhaustive_tests=$enableval], |
123 | [use_exhaustive_tests=yes]) | |
124 | ||
fbecc38a | 125 | AC_ARG_ENABLE(ecmult_static_precomputation, |
a61a93ff | 126 | AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing [default=auto]]), |
fbecc38a | 127 | [use_ecmult_static_precomputation=$enableval], |
aa0b1fd1 | 128 | [use_ecmult_static_precomputation=auto]) |
78cd96b1 | 129 | |
0739bbb6 | 130 | AC_ARG_ENABLE(module_ecdh, |
353dff15 | 131 | AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation]), |
0739bbb6 AP |
132 | [enable_module_ecdh=$enableval], |
133 | [enable_module_ecdh=no]) | |
134 | ||
9f443be0 | 135 | AC_ARG_ENABLE(module_recovery, |
a61a93ff | 136 | AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module [default=no]]), |
9f443be0 PW |
137 | [enable_module_recovery=$enableval], |
138 | [enable_module_recovery=no]) | |
139 | ||
47e6618e JN |
140 | AC_ARG_ENABLE(module_extrakeys, |
141 | AS_HELP_STRING([--enable-module-extrakeys],[enable extrakeys module (experimental)]), | |
142 | [enable_module_extrakeys=$enableval], | |
143 | [enable_module_extrakeys=no]) | |
144 | ||
7a703fd9 JN |
145 | AC_ARG_ENABLE(module_schnorrsig, |
146 | AS_HELP_STRING([--enable-module-schnorrsig],[enable schnorrsig module (experimental)]), | |
147 | [enable_module_schnorrsig=$enableval], | |
148 | [enable_module_schnorrsig=no]) | |
149 | ||
5db782e6 | 150 | AC_ARG_ENABLE(external_default_callbacks, |
a467047e | 151 | AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]), |
5db782e6 TR |
152 | [use_external_default_callbacks=$enableval], |
153 | [use_external_default_callbacks=no]) | |
154 | ||
47802a47 TR |
155 | # Test-only override of the (autodetected by the C code) "widemul" setting. |
156 | # Legal values are int64 (for [u]int64_t), int128 (for [unsigned] __int128), and auto (the default). | |
79f1f7a4 | 157 | AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_widemul=auto]) |
78cd96b1 | 158 | |
1ba4a60a | 159 | AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto], |
a61a93ff | 160 | [bignum implementation to use [default=auto]])],[req_bignum=$withval], [req_bignum=auto]) |
78cd96b1 | 161 | |
a61a93ff TR |
162 | AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto], |
163 | [assembly optimizations to useĀ (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto]) | |
1ba4a60a | 164 | |
2842dc52 TR |
165 | AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto], |
166 | [window size for ecmult precomputation for verification, specified as integer in range [2..24].] | |
167 | [Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.] | |
4232e5b7 | 168 | [The table will store 2^(SIZE-1) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.] |
2842dc52 TR |
169 | ["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]] |
170 | )], | |
171 | [req_ecmult_window=$withval], [req_ecmult_window=auto]) | |
172 | ||
dcb2e3b3 | 173 | AC_ARG_WITH([ecmult-gen-precision], [AS_HELP_STRING([--with-ecmult-gen-precision=2|4|8|auto], |
174 | [Precision bits to tune the precomputed table size for signing.] | |
175 | [The size of the table is 32kB for 2 bits, 64kB for 4 bits, 512kB for 8 bits of precision.] | |
176 | [A larger table size usually results in possible faster signing.] | |
177 | ["auto" is a reasonable setting for desktop machines (currently 4). [default=auto]] | |
178 | )], | |
179 | [req_ecmult_gen_precision=$withval], [req_ecmult_gen_precision=auto]) | |
180 | ||
412bf874 LD |
181 | AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto], |
182 | [Build with extra checks for running inside Valgrind [default=auto]] | |
183 | )], | |
184 | [req_valgrind=$withval], [req_valgrind=auto]) | |
185 | ||
47802a47 TR |
186 | ### |
187 | ### Handle config options (except for modules) | |
188 | ### | |
189 | ||
412bf874 LD |
190 | if test x"$req_valgrind" = x"no"; then |
191 | enable_valgrind=no | |
192 | else | |
252c19df TR |
193 | SECP_VALGRIND_CHECK |
194 | if test x"$has_valgrind" != x"yes"; then | |
412bf874 LD |
195 | if test x"$req_valgrind" = x"yes"; then |
196 | AC_MSG_ERROR([Valgrind support explicitly requested but valgrind/memcheck.h header not available]) | |
197 | fi | |
198 | enable_valgrind=no | |
252c19df TR |
199 | else |
200 | enable_valgrind=yes | |
201 | fi | |
412bf874 | 202 | fi |
7b50483a GM |
203 | AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"]) |
204 | ||
a724d729 AP |
205 | if test x"$enable_coverage" = x"yes"; then |
206 | AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code]) | |
ecba8138 JN |
207 | CFLAGS="-O0 --coverage $CFLAGS" |
208 | LDFLAGS="--coverage $LDFLAGS" | |
a724d729 | 209 | else |
ca739cba | 210 | CFLAGS="-O2 $CFLAGS" |
a724d729 AP |
211 | fi |
212 | ||
1ba4a60a | 213 | if test x"$req_asm" = x"auto"; then |
0e9baf6f CF |
214 | SECP_64BIT_ASM_CHECK |
215 | if test x"$has_64bit_asm" = x"yes"; then | |
1ba4a60a PW |
216 | set_asm=x86_64 |
217 | fi | |
218 | if test x"$set_asm" = x; then | |
219 | set_asm=no | |
78cd96b1 | 220 | fi |
1ba4a60a PW |
221 | else |
222 | set_asm=$req_asm | |
223 | case $set_asm in | |
224 | x86_64) | |
225 | SECP_64BIT_ASM_CHECK | |
226 | if test x"$has_64bit_asm" != x"yes"; then | |
227 | AC_MSG_ERROR([x86_64 assembly optimization requested but not available]) | |
228 | fi | |
229 | ;; | |
001f1763 WL |
230 | arm) |
231 | ;; | |
1ba4a60a PW |
232 | no) |
233 | ;; | |
234 | *) | |
235 | AC_MSG_ERROR([invalid assembly optimization selection]) | |
236 | ;; | |
237 | esac | |
238 | fi | |
78cd96b1 | 239 | |
78cd96b1 CF |
240 | if test x"$req_bignum" = x"auto"; then |
241 | SECP_GMP_CHECK | |
242 | if test x"$has_gmp" = x"yes"; then | |
243 | set_bignum=gmp | |
244 | fi | |
245 | ||
78cd96b1 | 246 | if test x"$set_bignum" = x; then |
1ba4a60a | 247 | set_bignum=no |
78cd96b1 CF |
248 | fi |
249 | else | |
250 | set_bignum=$req_bignum | |
251 | case $set_bignum in | |
252 | gmp) | |
253 | SECP_GMP_CHECK | |
1ba4a60a PW |
254 | if test x"$has_gmp" != x"yes"; then |
255 | AC_MSG_ERROR([gmp bignum explicitly requested but libgmp not available]) | |
256 | fi | |
78cd96b1 | 257 | ;; |
1ba4a60a | 258 | no) |
78cd96b1 CF |
259 | ;; |
260 | *) | |
261 | AC_MSG_ERROR([invalid bignum implementation selection]) | |
262 | ;; | |
263 | esac | |
264 | fi | |
265 | ||
47802a47 | 266 | # Select assembly optimization |
001f1763 WL |
267 | use_external_asm=no |
268 | ||
1ba4a60a PW |
269 | case $set_asm in |
270 | x86_64) | |
271 | AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations]) | |
272 | ;; | |
001f1763 WL |
273 | arm) |
274 | use_external_asm=yes | |
275 | ;; | |
1ba4a60a PW |
276 | no) |
277 | ;; | |
278 | *) | |
279 | AC_MSG_ERROR([invalid assembly optimizations]) | |
280 | ;; | |
281 | esac | |
282 | ||
47802a47 TR |
283 | if test x"$use_external_asm" = x"yes"; then |
284 | AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used]) | |
285 | fi | |
286 | ||
287 | ||
288 | # Select wide multiplication implementation | |
79f1f7a4 PW |
289 | case $set_widemul in |
290 | int128) | |
291 | AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation]) | |
78cd96b1 | 292 | ;; |
79f1f7a4 PW |
293 | int64) |
294 | AC_DEFINE(USE_FORCE_WIDEMUL_INT64, 1, [Define this symbol to force the use of the (u)int64_t based wide multiplication implementation]) | |
295 | ;; | |
296 | auto) | |
78cd96b1 CF |
297 | ;; |
298 | *) | |
79f1f7a4 | 299 | AC_MSG_ERROR([invalid wide multiplication implementation]) |
78cd96b1 CF |
300 | ;; |
301 | esac | |
302 | ||
47802a47 | 303 | # Select bignum implementation |
78cd96b1 CF |
304 | case $set_bignum in |
305 | gmp) | |
597128d3 PW |
306 | AC_DEFINE(HAVE_LIBGMP, 1, [Define this symbol if libgmp is installed]) |
307 | AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation for num]) | |
d1502eb4 PW |
308 | AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation]) |
309 | AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation]) | |
78cd96b1 | 310 | ;; |
1ba4a60a | 311 | no) |
597128d3 PW |
312 | AC_DEFINE(USE_NUM_NONE, 1, [Define this symbol to use no num implementation]) |
313 | AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the native field inverse implementation]) | |
314 | AC_DEFINE(USE_SCALAR_INV_BUILTIN, 1, [Define this symbol to use the native scalar inverse implementation]) | |
315 | ;; | |
78cd96b1 CF |
316 | *) |
317 | AC_MSG_ERROR([invalid bignum implementation]) | |
318 | ;; | |
319 | esac | |
320 | ||
47802a47 | 321 | # Set ecmult window size |
2842dc52 TR |
322 | if test x"$req_ecmult_window" = x"auto"; then |
323 | set_ecmult_window=15 | |
324 | else | |
325 | set_ecmult_window=$req_ecmult_window | |
326 | fi | |
327 | ||
328 | error_window_size=['window size for ecmult precomputation not an integer in range [2..24] or "auto"'] | |
329 | case $set_ecmult_window in | |
330 | ''|*[[!0-9]]*) | |
331 | # no valid integer | |
332 | AC_MSG_ERROR($error_window_size) | |
333 | ;; | |
334 | *) | |
335 | if test "$set_ecmult_window" -lt 2 -o "$set_ecmult_window" -gt 24 ; then | |
336 | # not in range | |
337 | AC_MSG_ERROR($error_window_size) | |
338 | fi | |
339 | AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation]) | |
340 | ;; | |
341 | esac | |
342 | ||
47802a47 | 343 | # Set ecmult gen precision |
dcb2e3b3 | 344 | if test x"$req_ecmult_gen_precision" = x"auto"; then |
345 | set_ecmult_gen_precision=4 | |
346 | else | |
347 | set_ecmult_gen_precision=$req_ecmult_gen_precision | |
348 | fi | |
349 | ||
350 | case $set_ecmult_gen_precision in | |
351 | 2|4|8) | |
352 | AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits]) | |
353 | ;; | |
354 | *) | |
355 | AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"']) | |
356 | ;; | |
357 | esac | |
358 | ||
78cd96b1 CF |
359 | if test x"$use_tests" = x"yes"; then |
360 | SECP_OPENSSL_CHECK | |
3734b682 ET |
361 | if test x"$enable_openssl_tests" != x"no" && test x"$has_openssl_ec" = x"yes"; then |
362 | enable_openssl_tests=yes | |
a9b2a5d8 | 363 | AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available]) |
84b5fc5b | 364 | SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS $CRYPTO_CPPFLAGS" |
a9b2a5d8 AP |
365 | SECP_TEST_LIBS="$CRYPTO_LIBS" |
366 | ||
367 | case $host in | |
368 | *mingw*) | |
369 | SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32" | |
370 | ;; | |
371 | esac | |
a9b2a5d8 AP |
372 | else |
373 | if test x"$enable_openssl_tests" = x"yes"; then | |
374 | AC_MSG_ERROR([OpenSSL tests requested but OpenSSL with EC support is not available]) | |
375 | fi | |
3734b682 | 376 | enable_openssl_tests=no |
a9b2a5d8 AP |
377 | fi |
378 | else | |
379 | if test x"$enable_openssl_tests" = x"yes"; then | |
380 | AC_MSG_ERROR([OpenSSL tests requested but tests are not enabled]) | |
78cd96b1 | 381 | fi |
3734b682 | 382 | enable_openssl_tests=no |
78cd96b1 CF |
383 | fi |
384 | ||
7277fd76 | 385 | if test x"$set_bignum" = x"gmp"; then |
78cd96b1 | 386 | SECP_LIBS="$SECP_LIBS $GMP_LIBS" |
e2274c58 | 387 | SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS" |
78cd96b1 CF |
388 | fi |
389 | ||
252c19df TR |
390 | if test x"$enable_valgrind" = x"yes"; then |
391 | SECP_INCLUDES="$SECP_INCLUDES $VALGRIND_CPPFLAGS" | |
392 | fi | |
393 | ||
47802a47 TR |
394 | # Handle static precomputation (after everything which modifies CFLAGS and friends) |
395 | if test x"$use_ecmult_static_precomputation" != x"no"; then | |
3c151307 TR |
396 | if test x"$cross_compiling" = x"no"; then |
397 | set_precomp=yes | |
398 | if test x"${CC_FOR_BUILD+x}${CFLAGS_FOR_BUILD+x}${CPPFLAGS_FOR_BUILD+x}${LDFLAGS_FOR_BUILD+x}" != x; then | |
399 | AC_MSG_WARN([CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD, and/or LDFLAGS_FOR_BUILD is set but ignored because we are not cross-compiling.]) | |
47802a47 | 400 | fi |
3c151307 TR |
401 | # If we're not cross-compiling, simply use the same compiler for building the static precompation code. |
402 | CC_FOR_BUILD="$CC" | |
403 | CFLAGS_FOR_BUILD="$CFLAGS" | |
404 | CPPFLAGS_FOR_BUILD="$CPPFLAGS" | |
405 | LDFLAGS_FOR_BUILD="$LDFLAGS" | |
47802a47 | 406 | else |
3c151307 TR |
407 | AX_PROG_CC_FOR_BUILD |
408 | ||
409 | # Temporarily switch to an environment for the native compiler | |
410 | save_cross_compiling=$cross_compiling | |
411 | cross_compiling=no | |
412 | SAVE_CC="$CC" | |
413 | CC="$CC_FOR_BUILD" | |
414 | SAVE_CFLAGS="$CFLAGS" | |
415 | CFLAGS="$CFLAGS_FOR_BUILD" | |
416 | SAVE_CPPFLAGS="$CPPFLAGS" | |
417 | CPPFLAGS="$CPPFLAGS_FOR_BUILD" | |
418 | SAVE_LDFLAGS="$LDFLAGS" | |
419 | LDFLAGS="$LDFLAGS_FOR_BUILD" | |
420 | ||
421 | warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function" | |
422 | saved_CFLAGS="$CFLAGS" | |
423 | CFLAGS="$warn_CFLAGS_FOR_BUILD $CFLAGS" | |
424 | AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}]) | |
425 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], | |
426 | [ AC_MSG_RESULT([yes]) ], | |
427 | [ AC_MSG_RESULT([no]) | |
428 | CFLAGS="$saved_CFLAGS" | |
429 | ]) | |
430 | ||
431 | AC_MSG_CHECKING([for working native compiler: ${CC_FOR_BUILD}]) | |
432 | AC_RUN_IFELSE( | |
433 | [AC_LANG_PROGRAM([], [])], | |
434 | [working_native_cc=yes], | |
435 | [working_native_cc=no],[:]) | |
436 | ||
437 | CFLAGS_FOR_BUILD="$CFLAGS" | |
438 | ||
439 | # Restore the environment | |
440 | cross_compiling=$save_cross_compiling | |
441 | CC="$SAVE_CC" | |
442 | CFLAGS="$SAVE_CFLAGS" | |
443 | CPPFLAGS="$SAVE_CPPFLAGS" | |
444 | LDFLAGS="$SAVE_LDFLAGS" | |
445 | ||
446 | if test x"$working_native_cc" = x"no"; then | |
447 | AC_MSG_RESULT([no]) | |
448 | set_precomp=no | |
449 | m4_define([please_set_for_build], [Please set CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD, and/or LDFLAGS_FOR_BUILD.]) | |
450 | if test x"$use_ecmult_static_precomputation" = x"yes"; then | |
451 | AC_MSG_ERROR([native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build]) | |
452 | else | |
453 | AC_MSG_WARN([Disabling statically generated ecmult table because the native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build]) | |
454 | fi | |
455 | else | |
456 | AC_MSG_RESULT([yes]) | |
457 | set_precomp=yes | |
458 | fi | |
47802a47 | 459 | fi |
3c151307 TR |
460 | |
461 | AC_SUBST(CC_FOR_BUILD) | |
462 | AC_SUBST(CFLAGS_FOR_BUILD) | |
463 | AC_SUBST(CPPFLAGS_FOR_BUILD) | |
464 | AC_SUBST(LDFLAGS_FOR_BUILD) | |
47802a47 TR |
465 | else |
466 | set_precomp=no | |
467 | fi | |
468 | ||
00c5d2e1 | 469 | if test x"$set_precomp" = x"yes"; then |
fbecc38a TD |
470 | AC_DEFINE(USE_ECMULT_STATIC_PRECOMPUTATION, 1, [Define this symbol to use a statically generated ecmult table]) |
471 | fi | |
472 | ||
47802a47 TR |
473 | ### |
474 | ### Handle module options | |
475 | ### | |
476 | ||
0739bbb6 AP |
477 | if test x"$enable_module_ecdh" = x"yes"; then |
478 | AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module]) | |
479 | fi | |
480 | ||
9f443be0 PW |
481 | if test x"$enable_module_recovery" = x"yes"; then |
482 | AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module]) | |
483 | fi | |
484 | ||
7a703fd9 JN |
485 | if test x"$enable_module_schnorrsig" = x"yes"; then |
486 | AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module]) | |
487 | enable_module_extrakeys=yes | |
488 | fi | |
489 | ||
490 | # Test if extrakeys is set after the schnorrsig module to allow the schnorrsig | |
491 | # module to set enable_module_extrakeys=yes | |
47e6618e JN |
492 | if test x"$enable_module_extrakeys" = x"yes"; then |
493 | AC_DEFINE(ENABLE_MODULE_EXTRAKEYS, 1, [Define this symbol to enable the extrakeys module]) | |
494 | fi | |
495 | ||
5db782e6 TR |
496 | if test x"$use_external_default_callbacks" = x"yes"; then |
497 | AC_DEFINE(USE_EXTERNAL_DEFAULT_CALLBACKS, 1, [Define this symbol if an external implementation of the default callbacks is used]) | |
498 | fi | |
499 | ||
47802a47 TR |
500 | ### |
501 | ### Check for --enable-experimental if necessary | |
502 | ### | |
503 | ||
83221ecb PW |
504 | if test x"$enable_experimental" = x"yes"; then |
505 | AC_MSG_NOTICE([******]) | |
506 | AC_MSG_NOTICE([WARNING: experimental build]) | |
507 | AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.]) | |
47e6618e | 508 | AC_MSG_NOTICE([Building extrakeys module: $enable_module_extrakeys]) |
7a703fd9 | 509 | AC_MSG_NOTICE([Building schnorrsig module: $enable_module_schnorrsig]) |
83221ecb PW |
510 | AC_MSG_NOTICE([******]) |
511 | else | |
47e6618e JN |
512 | if test x"$enable_module_extrakeys" = x"yes"; then |
513 | AC_MSG_ERROR([extrakeys module is experimental. Use --enable-experimental to allow.]) | |
514 | fi | |
7a703fd9 JN |
515 | if test x"$enable_module_schnorrsig" = x"yes"; then |
516 | AC_MSG_ERROR([schnorrsig module is experimental. Use --enable-experimental to allow.]) | |
517 | fi | |
001f1763 WL |
518 | if test x"$set_asm" = x"arm"; then |
519 | AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.]) | |
520 | fi | |
83221ecb PW |
521 | fi |
522 | ||
47802a47 TR |
523 | ### |
524 | ### Generate output | |
525 | ### | |
526 | ||
78cd96b1 | 527 | AC_CONFIG_HEADERS([src/libsecp256k1-config.h]) |
c7ee71f7 | 528 | AC_CONFIG_FILES([Makefile libsecp256k1.pc]) |
78cd96b1 CF |
529 | AC_SUBST(SECP_INCLUDES) |
530 | AC_SUBST(SECP_LIBS) | |
531 | AC_SUBST(SECP_TEST_LIBS) | |
532 | AC_SUBST(SECP_TEST_INCLUDES) | |
a724d729 | 533 | AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"]) |
78cd96b1 | 534 | AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"]) |
20b8877b | 535 | AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$use_exhaustive_tests" != x"no"]) |
8336040f | 536 | AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"]) |
00c5d2e1 | 537 | AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"]) |
0739bbb6 | 538 | AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"]) |
9f443be0 | 539 | AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"]) |
7a703fd9 JN |
540 | AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"yes"]) |
541 | AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"]) | |
001f1763 WL |
542 | AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"]) |
543 | AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"]) | |
e2274c58 | 544 | |
47802a47 | 545 | # Make sure nothing new is exported so that we don't break the cache. |
e2274c58 CF |
546 | PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH" |
547 | unset PKG_CONFIG_PATH | |
548 | PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP" | |
549 | ||
78cd96b1 | 550 | AC_OUTPUT |
3965027c EK |
551 | |
552 | echo | |
553 | echo "Build Options:" | |
5db782e6 TR |
554 | echo " with ecmult precomp = $set_precomp" |
555 | echo " with external callbacks = $use_external_default_callbacks" | |
5db782e6 | 556 | echo " with benchmarks = $use_benchmark" |
3734b682 ET |
557 | echo " with tests = $use_tests" |
558 | echo " with openssl tests = $enable_openssl_tests" | |
5db782e6 TR |
559 | echo " with coverage = $enable_coverage" |
560 | echo " module ecdh = $enable_module_ecdh" | |
561 | echo " module recovery = $enable_module_recovery" | |
47e6618e | 562 | echo " module extrakeys = $enable_module_extrakeys" |
7a703fd9 | 563 | echo " module schnorrsig = $enable_module_schnorrsig" |
3965027c | 564 | echo |
5db782e6 TR |
565 | echo " asm = $set_asm" |
566 | echo " bignum = $set_bignum" | |
5db782e6 | 567 | echo " ecmult window size = $set_ecmult_window" |
dcb2e3b3 | 568 | echo " ecmult gen prec. bits = $set_ecmult_gen_precision" |
47802a47 | 569 | # Hide test-only options unless they're used. |
79f1f7a4 PW |
570 | if test x"$set_widemul" != xauto; then |
571 | echo " wide multiplication = $set_widemul" | |
572 | fi | |
3965027c | 573 | echo |
3d230225 | 574 | echo " valgrind = $enable_valgrind" |
5db782e6 TR |
575 | echo " CC = $CC" |
576 | echo " CFLAGS = $CFLAGS" | |
577 | echo " CPPFLAGS = $CPPFLAGS" | |
578 | echo " LDFLAGS = $LDFLAGS" | |
3965027c | 579 | echo |
3c151307 TR |
580 | if test x"$set_precomp" = x"yes"; then |
581 | echo " CC_FOR_BUILD = $CC_FOR_BUILD" | |
582 | echo " CFLAGS_FOR_BUILD = $CFLAGS_FOR_BUILD" | |
583 | echo " CPPFLAGS_FOR_BUILD = $CPPFLAGS_FOR_BUILD" | |
584 | echo " LDFLAGS_FOR_BUILD = $LDFLAGS_FOR_BUILD" | |
585 | fi |