Skip to content

Commit 47802a4

Browse files
Restructure and tidy configure.ac
No behavioral changes.
1 parent 252c19d commit 47802a4

File tree

1 file changed

+96
-74
lines changed

1 file changed

+96
-74
lines changed

configure.ac

+96-74
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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
@@ -37,9 +37,9 @@ case $host_os in
3737
if test x$cross_compiling != xyes; then
3838
AC_PATH_PROG([BREW],brew,)
3939
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.
40+
# These Homebrew packages may be keg-only, meaning that they won't be found
41+
# in expected paths because they may conflict with system files. Ask
42+
# Homebrew where each one is located, then adjust paths accordingly.
4343
openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
4444
gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
4545
valgrind_prefix=`$BREW --prefix valgrind 2>/dev/null`
@@ -57,8 +57,8 @@ case $host_os in
5757
fi
5858
else
5959
AC_PATH_PROG([PORT],port,)
60-
dnl if homebrew isn't installed and macports is, add the macports default paths
61-
dnl as a last resort.
60+
# If homebrew isn't installed and macports is, add the macports default paths
61+
# as a last resort.
6262
if test x$PORT != x; then
6363
CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
6464
LDFLAGS="$LDFLAGS -L/opt/local/lib"
@@ -89,6 +89,10 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
8989
CFLAGS="$saved_CFLAGS"
9090
])
9191

92+
###
93+
### Define config arguments
94+
###
95+
9296
AC_ARG_ENABLE(benchmark,
9397
AS_HELP_STRING([--enable-benchmark],[compile benchmark [default=yes]]),
9498
[use_benchmark=$enableval],
@@ -149,8 +153,8 @@ AC_ARG_ENABLE(external_default_callbacks,
149153
[use_external_default_callbacks=$enableval],
150154
[use_external_default_callbacks=no])
151155

152-
dnl Test-only override of the (autodetected by the C code) "widemul" setting.
153-
dnl Legal values are int64 (for [u]int64_t), int128 (for [unsigned] __int128), and auto (the default).
156+
# Test-only override of the (autodetected by the C code) "widemul" setting.
157+
# Legal values are int64 (for [u]int64_t), int128 (for [unsigned] __int128), and auto (the default).
154158
AC_ARG_WITH([test-override-wide-multiply], [] ,[set_widemul=$withval], [set_widemul=auto])
155159

156160
AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
@@ -180,6 +184,10 @@ AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto],
180184
)],
181185
[req_valgrind=$withval], [req_valgrind=auto])
182186

187+
###
188+
### Handle config options (except for modules)
189+
###
190+
183191
if test x"$req_valgrind" = x"no"; then
184192
enable_valgrind=no
185193
else
@@ -203,61 +211,6 @@ else
203211
CFLAGS="-O2 $CFLAGS"
204212
fi
205213

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

314-
# select assembly optimization
267+
# Select assembly optimization
315268
use_external_asm=no
316269

317270
case $set_asm in
@@ -328,7 +281,12 @@ no)
328281
;;
329282
esac
330283

331-
# select wide multiplication implementation
284+
if test x"$use_external_asm" = x"yes"; then
285+
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
286+
fi
287+
288+
289+
# Select wide multiplication implementation
332290
case $set_widemul in
333291
int128)
334292
AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation])
@@ -343,7 +301,7 @@ auto)
343301
;;
344302
esac
345303

346-
# select bignum implementation
304+
# Select bignum implementation
347305
case $set_bignum in
348306
gmp)
349307
AC_DEFINE(HAVE_LIBGMP, 1, [Define this symbol if libgmp is installed])
@@ -361,7 +319,7 @@ no)
361319
;;
362320
esac
363321

364-
#set ecmult window size
322+
# Set ecmult window size
365323
if test x"$req_ecmult_window" = x"auto"; then
366324
set_ecmult_window=15
367325
else
@@ -383,7 +341,7 @@ case $set_ecmult_window in
383341
;;
384342
esac
385343

386-
#set ecmult gen precision
344+
# Set ecmult gen precision
387345
if test x"$req_ecmult_gen_precision" = x"auto"; then
388346
set_ecmult_gen_precision=4
389347
else
@@ -434,10 +392,70 @@ if test x"$enable_valgrind" = x"yes"; then
434392
SECP_INCLUDES="$SECP_INCLUDES $VALGRIND_CPPFLAGS"
435393
fi
436394

395+
# Handle static precomputation (after everything which modifies CFLAGS and friends)
396+
if test x"$use_ecmult_static_precomputation" != x"no"; then
397+
# Temporarily switch to an environment for the native compiler
398+
save_cross_compiling=$cross_compiling
399+
cross_compiling=no
400+
SAVE_CC="$CC"
401+
CC="$CC_FOR_BUILD"
402+
SAVE_CFLAGS="$CFLAGS"
403+
CFLAGS="$CFLAGS_FOR_BUILD"
404+
SAVE_CPPFLAGS="$CPPFLAGS"
405+
CPPFLAGS="$CPPFLAGS_FOR_BUILD"
406+
SAVE_LDFLAGS="$LDFLAGS"
407+
LDFLAGS="$LDFLAGS_FOR_BUILD"
408+
409+
warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
410+
saved_CFLAGS="$CFLAGS"
411+
CFLAGS="$warn_CFLAGS_FOR_BUILD $CFLAGS"
412+
AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}])
413+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
414+
[ AC_MSG_RESULT([yes]) ],
415+
[ AC_MSG_RESULT([no])
416+
CFLAGS="$saved_CFLAGS"
417+
])
418+
419+
AC_MSG_CHECKING([for working native compiler: ${CC_FOR_BUILD}])
420+
AC_RUN_IFELSE(
421+
[AC_LANG_PROGRAM([], [])],
422+
[working_native_cc=yes],
423+
[working_native_cc=no],[:])
424+
425+
CFLAGS_FOR_BUILD="$CFLAGS"
426+
427+
# Restore the environment
428+
cross_compiling=$save_cross_compiling
429+
CC="$SAVE_CC"
430+
CFLAGS="$SAVE_CFLAGS"
431+
CPPFLAGS="$SAVE_CPPFLAGS"
432+
LDFLAGS="$SAVE_LDFLAGS"
433+
434+
if test x"$working_native_cc" = x"no"; then
435+
AC_MSG_RESULT([no])
436+
set_precomp=no
437+
m4_define([please_set_for_build], [Please set CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD, and/or LDFLAGS_FOR_BUILD.])
438+
if test x"$use_ecmult_static_precomputation" = x"yes"; then
439+
AC_MSG_ERROR([native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
440+
else
441+
AC_MSG_WARN([Disabling statically generated ecmult table because the native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
442+
fi
443+
else
444+
AC_MSG_RESULT([yes])
445+
set_precomp=yes
446+
fi
447+
else
448+
set_precomp=no
449+
fi
450+
437451
if test x"$set_precomp" = x"yes"; then
438452
AC_DEFINE(USE_ECMULT_STATIC_PRECOMPUTATION, 1, [Define this symbol to use a statically generated ecmult table])
439453
fi
440454

455+
###
456+
### Handle module options
457+
###
458+
441459
if test x"$enable_module_ecdh" = x"yes"; then
442460
AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
443461
fi
@@ -457,14 +475,14 @@ if test x"$enable_module_extrakeys" = x"yes"; then
457475
AC_DEFINE(ENABLE_MODULE_EXTRAKEYS, 1, [Define this symbol to enable the extrakeys module])
458476
fi
459477

460-
if test x"$use_external_asm" = x"yes"; then
461-
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
462-
fi
463-
464478
if test x"$use_external_default_callbacks" = x"yes"; then
465479
AC_DEFINE(USE_EXTERNAL_DEFAULT_CALLBACKS, 1, [Define this symbol if an external implementation of the default callbacks is used])
466480
fi
467481

482+
###
483+
### Check for --enable-experimental if necessary
484+
###
485+
468486
if test x"$enable_experimental" = x"yes"; then
469487
AC_MSG_NOTICE([******])
470488
AC_MSG_NOTICE([WARNING: experimental build])
@@ -484,6 +502,10 @@ else
484502
fi
485503
fi
486504

505+
###
506+
### Generate output
507+
###
508+
487509
AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
488510
AC_CONFIG_FILES([Makefile libsecp256k1.pc])
489511
AC_SUBST(SECP_INCLUDES)
@@ -502,7 +524,7 @@ AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" =
502524
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
503525
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
504526

505-
dnl make sure nothing new is exported so that we don't break the cache
527+
# Make sure nothing new is exported so that we don't break the cache.
506528
PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
507529
unset PKG_CONFIG_PATH
508530
PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
@@ -526,7 +548,7 @@ echo " asm = $set_asm"
526548
echo " bignum = $set_bignum"
527549
echo " ecmult window size = $set_ecmult_window"
528550
echo " ecmult gen prec. bits = $set_ecmult_gen_precision"
529-
dnl Hide test-only options unless they're used.
551+
# Hide test-only options unless they're used.
530552
if test x"$set_widemul" != xauto; then
531553
echo " wide multiplication = $set_widemul"
532554
fi

0 commit comments

Comments
 (0)