Skip to content

Commit f2d9aea

Browse files
Merge #862: Autoconf improvements
3c15130 Improve CC_FOR_BUILD detection (Tim Ruffing) 47802a4 Restructure and tidy configure.ac (Tim Ruffing) 252c19d Ask brew for valgrind include path (Tim Ruffing) Pull request description: See individual commit messages. These are improvements in preparation of the switch to Cirrus CI. (Maybe I'll just open a PR on top of this one.) The first commit made the difference between successful build https://cirrus-ci.com/task/6740575057608704 and unsuccessful build https://cirrus-ci.com/task/4909571074424832. I've tested the second commit without cross-compilation and with cross-compilation for android (#621 (comment)) When working on the autoconf stuff, I noticed two things that I just want to write down here: - At some point we should update [build-aux/m4/ax_prog_cc_for_build.m4](https://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html). This is outdated, and [there have been a lot of fixes](autoconf-archive/autoconf-archive#207) But the latest version is [broken](https://lists.gnu.org/archive/html/autoconf-archive-maintainers/2020-06/msg00002.html), so now is probably not the time. - The latest autoconf 2.70 deprecates `AC_PROG_CC_C89`. It's not needed anymore because `AC_PROG_CC` cares about testing for version support. This makes autoconf 2.70 output a warning that we should probably just ignore. We don't want to force users onto 2.70... ACKs for top commit: sipa: utACK 3c15130 jonasnick: utACK 3c15130 makes sense (with my very basic understanding of autoconf) Tree-SHA512: 595b9de316374c2213f1340cddaa22eb3190b01fa99aa6ae26e77804df41e7ecf96a09e03c28e8f8b9fd04e211e4ee2f78f1e5a7995143c84f99d2e16d4f0260
2 parents 328aaef + 3c15130 commit f2d9aea

File tree

3 files changed

+144
-80
lines changed

3 files changed

+144
-80
lines changed

build-aux/m4/bitcoin_secp.m4

+8
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ if test x"$has_gmp" != x"yes"; then
8787
LIBS="$LIBS_TEMP"
8888
fi
8989
])
90+
91+
AC_DEFUN([SECP_VALGRIND_CHECK],[
92+
if test x"$has_valgrind" != x"yes"; then
93+
CPPFLAGS_TEMP="$CPPFLAGS"
94+
CPPFLAGS="$VALGRIND_CPPFLAGS $CPPFLAGS"
95+
AC_CHECK_HEADER([valgrind/memcheck.h], [has_valgrind=yes; AC_DEFINE(HAVE_VALGRIND,1,[Define this symbol if valgrind is installed])])
96+
fi
97+
])

configure.ac

+134-78
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ AM_INIT_AUTOMAKE([foreign subdir-objects])
1414
: ${CFLAGS="-g"}
1515
LT_INIT
1616

17-
dnl make the compilation flags quiet unless V=1 is used
17+
# Make the compilation flags quiet unless V=1 is used.
1818
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
1919

2020
PKG_PROG_PKG_CONFIG
2121

2222
AC_PATH_TOOL(AR, ar)
2323
AC_PATH_TOOL(RANLIB, ranlib)
2424
AC_PATH_TOOL(STRIP, strip)
25-
AX_PROG_CC_FOR_BUILD
2625

2726
AM_PROG_CC_C_O
2827

@@ -37,12 +36,12 @@ case $host_os in
3736
if test x$cross_compiling != xyes; then
3837
AC_PATH_PROG([BREW],brew,)
3938
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.
43-
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.
4442
openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
4543
gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
44+
valgrind_prefix=`$BREW --prefix valgrind 2>/dev/null`
4645
if test x$openssl_prefix != x; then
4746
PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
4847
export PKG_CONFIG_PATH
@@ -52,10 +51,13 @@ case $host_os in
5251
GMP_CPPFLAGS="-I$gmp_prefix/include"
5352
GMP_LIBS="-L$gmp_prefix/lib"
5453
fi
54+
if test x$valgrind_prefix != x; then
55+
VALGRIND_CPPFLAGS="-I$valgrind_prefix/include"
56+
fi
5557
else
5658
AC_PATH_PROG([PORT],port,)
57-
dnl if homebrew isn't installed and macports is, add the macports default paths
58-
dnl as a last resort.
59+
# If homebrew isn't installed and macports is, add the macports default paths
60+
# as a last resort.
5961
if test x$PORT != x; then
6062
CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
6163
LDFLAGS="$LDFLAGS -L/opt/local/lib"
@@ -86,6 +88,10 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
8688
CFLAGS="$saved_CFLAGS"
8789
])
8890

91+
###
92+
### Define config arguments
93+
###
94+
8995
AC_ARG_ENABLE(benchmark,
9096
AS_HELP_STRING([--enable-benchmark],[compile benchmark [default=yes]]),
9197
[use_benchmark=$enableval],
@@ -146,8 +152,8 @@ AC_ARG_ENABLE(external_default_callbacks,
146152
[use_external_default_callbacks=$enableval],
147153
[use_external_default_callbacks=no])
148154

149-
dnl Test-only override of the (autodetected by the C code) "widemul" setting.
150-
dnl Legal values are int64 (for [u]int64_t), int128 (for [unsigned] __int128), and auto (the default).
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).
151157
AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_widemul=auto])
152158

153159
AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
@@ -177,15 +183,22 @@ AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto],
177183
)],
178184
[req_valgrind=$withval], [req_valgrind=auto])
179185

186+
###
187+
### Handle config options (except for modules)
188+
###
189+
180190
if test x"$req_valgrind" = x"no"; then
181191
enable_valgrind=no
182192
else
183-
AC_CHECK_HEADER([valgrind/memcheck.h], [enable_valgrind=yes], [
193+
SECP_VALGRIND_CHECK
194+
if test x"$has_valgrind" != x"yes"; then
184195
if test x"$req_valgrind" = x"yes"; then
185196
AC_MSG_ERROR([Valgrind support explicitly requested but valgrind/memcheck.h header not available])
186197
fi
187198
enable_valgrind=no
188-
], [])
199+
else
200+
enable_valgrind=yes
201+
fi
189202
fi
190203
AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
191204

@@ -197,61 +210,6 @@ else
197210
CFLAGS="-O2 $CFLAGS"
198211
fi
199212

200-
if test x"$use_ecmult_static_precomputation" != x"no"; then
201-
# Temporarily switch to an environment for the native compiler
202-
save_cross_compiling=$cross_compiling
203-
cross_compiling=no
204-
SAVE_CC="$CC"
205-
CC="$CC_FOR_BUILD"
206-
SAVE_CFLAGS="$CFLAGS"
207-
CFLAGS="$CFLAGS_FOR_BUILD"
208-
SAVE_CPPFLAGS="$CPPFLAGS"
209-
CPPFLAGS="$CPPFLAGS_FOR_BUILD"
210-
SAVE_LDFLAGS="$LDFLAGS"
211-
LDFLAGS="$LDFLAGS_FOR_BUILD"
212-
213-
warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
214-
saved_CFLAGS="$CFLAGS"
215-
CFLAGS="$warn_CFLAGS_FOR_BUILD $CFLAGS"
216-
AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}])
217-
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
218-
[ AC_MSG_RESULT([yes]) ],
219-
[ AC_MSG_RESULT([no])
220-
CFLAGS="$saved_CFLAGS"
221-
])
222-
223-
AC_MSG_CHECKING([for working native compiler: ${CC_FOR_BUILD}])
224-
AC_RUN_IFELSE(
225-
[AC_LANG_PROGRAM([], [])],
226-
[working_native_cc=yes],
227-
[working_native_cc=no],[:])
228-
229-
CFLAGS_FOR_BUILD="$CFLAGS"
230-
231-
# Restore the environment
232-
cross_compiling=$save_cross_compiling
233-
CC="$SAVE_CC"
234-
CFLAGS="$SAVE_CFLAGS"
235-
CPPFLAGS="$SAVE_CPPFLAGS"
236-
LDFLAGS="$SAVE_LDFLAGS"
237-
238-
if test x"$working_native_cc" = x"no"; then
239-
AC_MSG_RESULT([no])
240-
set_precomp=no
241-
m4_define([please_set_for_build], [Please set CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD, and/or LDFLAGS_FOR_BUILD.])
242-
if test x"$use_ecmult_static_precomputation" = x"yes"; then
243-
AC_MSG_ERROR([native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
244-
else
245-
AC_MSG_WARN([Disabling statically generated ecmult table because the native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
246-
fi
247-
else
248-
AC_MSG_RESULT([yes])
249-
set_precomp=yes
250-
fi
251-
else
252-
set_precomp=no
253-
fi
254-
255213
if test x"$req_asm" = x"auto"; then
256214
SECP_64BIT_ASM_CHECK
257215
if test x"$has_64bit_asm" = x"yes"; then
@@ -305,7 +263,7 @@ else
305263
esac
306264
fi
307265

308-
# select assembly optimization
266+
# Select assembly optimization
309267
use_external_asm=no
310268

311269
case $set_asm in
@@ -322,7 +280,12 @@ no)
322280
;;
323281
esac
324282

325-
# select wide multiplication implementation
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
326289
case $set_widemul in
327290
int128)
328291
AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation])
@@ -337,7 +300,7 @@ auto)
337300
;;
338301
esac
339302

340-
# select bignum implementation
303+
# Select bignum implementation
341304
case $set_bignum in
342305
gmp)
343306
AC_DEFINE(HAVE_LIBGMP, 1, [Define this symbol if libgmp is installed])
@@ -355,7 +318,7 @@ no)
355318
;;
356319
esac
357320

358-
#set ecmult window size
321+
# Set ecmult window size
359322
if test x"$req_ecmult_window" = x"auto"; then
360323
set_ecmult_window=15
361324
else
@@ -377,7 +340,7 @@ case $set_ecmult_window in
377340
;;
378341
esac
379342

380-
#set ecmult gen precision
343+
# Set ecmult gen precision
381344
if test x"$req_ecmult_gen_precision" = x"auto"; then
382345
set_ecmult_gen_precision=4
383346
else
@@ -424,10 +387,93 @@ if test x"$set_bignum" = x"gmp"; then
424387
SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
425388
fi
426389

390+
if test x"$enable_valgrind" = x"yes"; then
391+
SECP_INCLUDES="$SECP_INCLUDES $VALGRIND_CPPFLAGS"
392+
fi
393+
394+
# Handle static precomputation (after everything which modifies CFLAGS and friends)
395+
if test x"$use_ecmult_static_precomputation" != x"no"; then
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.])
400+
fi
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"
406+
else
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
459+
fi
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)
465+
else
466+
set_precomp=no
467+
fi
468+
427469
if test x"$set_precomp" = x"yes"; then
428470
AC_DEFINE(USE_ECMULT_STATIC_PRECOMPUTATION, 1, [Define this symbol to use a statically generated ecmult table])
429471
fi
430472

473+
###
474+
### Handle module options
475+
###
476+
431477
if test x"$enable_module_ecdh" = x"yes"; then
432478
AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
433479
fi
@@ -447,14 +493,14 @@ if test x"$enable_module_extrakeys" = x"yes"; then
447493
AC_DEFINE(ENABLE_MODULE_EXTRAKEYS, 1, [Define this symbol to enable the extrakeys module])
448494
fi
449495

450-
if test x"$use_external_asm" = x"yes"; then
451-
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
452-
fi
453-
454496
if test x"$use_external_default_callbacks" = x"yes"; then
455497
AC_DEFINE(USE_EXTERNAL_DEFAULT_CALLBACKS, 1, [Define this symbol if an external implementation of the default callbacks is used])
456498
fi
457499

500+
###
501+
### Check for --enable-experimental if necessary
502+
###
503+
458504
if test x"$enable_experimental" = x"yes"; then
459505
AC_MSG_NOTICE([******])
460506
AC_MSG_NOTICE([WARNING: experimental build])
@@ -474,6 +520,10 @@ else
474520
fi
475521
fi
476522

523+
###
524+
### Generate output
525+
###
526+
477527
AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
478528
AC_CONFIG_FILES([Makefile libsecp256k1.pc])
479529
AC_SUBST(SECP_INCLUDES)
@@ -492,7 +542,7 @@ AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" =
492542
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
493543
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
494544

495-
dnl make sure nothing new is exported so that we don't break the cache
545+
# Make sure nothing new is exported so that we don't break the cache.
496546
PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
497547
unset PKG_CONFIG_PATH
498548
PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
@@ -516,7 +566,7 @@ echo " asm = $set_asm"
516566
echo " bignum = $set_bignum"
517567
echo " ecmult window size = $set_ecmult_window"
518568
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
519-
dnl Hide test-only options unless they're used.
569+
# Hide test-only options unless they're used.
520570
if test x"$set_widemul" != xauto; then
521571
echo " wide multiplication = $set_widemul"
522572
fi
@@ -527,3 +577,9 @@ echo " CFLAGS = $CFLAGS"
527577
echo " CPPFLAGS = $CPPFLAGS"
528578
echo " LDFLAGS = $LDFLAGS"
529579
echo
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

src/gen_context.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
66

7-
// Autotools creates libsecp256k1-config.h, of which ECMULT_GEN_PREC_BITS is needed.
8-
// ifndef guard so downstream users can define their own if they do not use autotools.
7+
/* Autotools creates libsecp256k1-config.h, of which ECMULT_GEN_PREC_BITS is needed.
8+
ifndef guard so downstream users can define their own if they do not use autotools. */
99
#if !defined(ECMULT_GEN_PREC_BITS)
1010
#include "libsecp256k1-config.h"
1111
#endif

0 commit comments

Comments
 (0)