@@ -8,10 +8,6 @@ AH_TOP([#define LIBSECP256K1_CONFIG_H])
8
8
AH_BOTTOM ( [ #endif /*LIBSECP256K1_CONFIG_H*/] )
9
9
AM_INIT_AUTOMAKE ( [ foreign subdir-objects] )
10
10
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).
14
- : ${CFLAGS="-g"}
15
11
LT_INIT
16
12
17
13
# Make the compilation flags quiet unless V=1 is used.
@@ -42,8 +38,8 @@ AM_PROG_AS
42
38
case $host_os in
43
39
*darwin*)
44
40
if test x$cross_compiling != xyes; then
45
- AC_PATH_PROG ( [ BREW] ,brew ,)
46
- if test x$BREW != x ; then
41
+ AC_CHECK_PROG ( [ BREW] , brew , brew )
42
+ if test x$BREW = xbrew ; then
47
43
# These Homebrew packages may be keg-only, meaning that they won't be found
48
44
# in expected paths because they may conflict with system files. Ask
49
45
# Homebrew where each one is located, then adjust paths accordingly.
@@ -58,10 +54,10 @@ case $host_os in
58
54
VALGRIND_CPPFLAGS="-I$valgrind_prefix/include"
59
55
fi
60
56
else
61
- AC_PATH_PROG ( [ PORT] ,port ,)
57
+ AC_CHECK_PROG ( [ PORT] , port , port )
62
58
# If homebrew isn't installed and macports is, add the macports default paths
63
59
# as a last resort.
64
- if test x$PORT != x ; then
60
+ if test x$PORT = xport ; then
65
61
CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
66
62
LDFLAGS="$LDFLAGS -L/opt/local/lib"
67
63
fi
@@ -70,35 +66,41 @@ case $host_os in
70
66
;;
71
67
esac
72
68
73
- CFLAGS="-W $CFLAGS"
74
-
75
- warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef -Wno-unused-function -Wno-long-long -Wno-overlength-strings"
76
- saved_CFLAGS="$CFLAGS"
77
- CFLAGS="$warn_CFLAGS $CFLAGS"
78
- AC_MSG_CHECKING ( [ if ${CC} supports ${warn_CFLAGS}] )
79
- AC_COMPILE_IFELSE ( [ AC_LANG_SOURCE ( [ [ char foo;] ] ) ] ,
80
- [ AC_MSG_RESULT ( [ yes] ) ] ,
81
- [ AC_MSG_RESULT ( [ no] )
82
- CFLAGS="$saved_CFLAGS"
83
- ] )
84
-
85
- saved_CFLAGS="$CFLAGS"
86
- CFLAGS="-Wconditional-uninitialized $CFLAGS"
87
- AC_MSG_CHECKING ( [ if ${CC} supports -Wconditional-uninitialized] )
88
- AC_COMPILE_IFELSE ( [ AC_LANG_SOURCE ( [ [ char foo;] ] ) ] ,
89
- [ AC_MSG_RESULT ( [ yes] ) ] ,
90
- [ AC_MSG_RESULT ( [ no] )
91
- CFLAGS="$saved_CFLAGS"
92
- ] )
93
-
94
- saved_CFLAGS="$CFLAGS"
95
- CFLAGS="-fvisibility=hidden $CFLAGS"
96
- AC_MSG_CHECKING ( [ if ${CC} supports -fvisibility=hidden] )
97
- AC_COMPILE_IFELSE ( [ AC_LANG_SOURCE ( [ [ char foo;] ] ) ] ,
98
- [ AC_MSG_RESULT ( [ yes] ) ] ,
99
- [ AC_MSG_RESULT ( [ no] )
100
- CFLAGS="$saved_CFLAGS"
101
- ] )
69
+ # Try if some desirable compiler flags are supported and append them to SECP_CFLAGS.
70
+ #
71
+ # These are our own flags, so we append them to our own SECP_CFLAGS variable (instead of CFLAGS) as
72
+ # recommended in the automake manual (Section "Flag Variables Ordering"). CFLAGS belongs to the user
73
+ # and we are not supposed to touch it. In the Makefile, we will need to ensure that SECP_CFLAGS
74
+ # is prepended to CFLAGS when invoking the compiler so that the user always has the last word (flag).
75
+ #
76
+ # Another advantage of not touching CFLAGS is that the contents of CFLAGS will be picked up by
77
+ # libtool for compiling helper executables. For example, when compiling for Windows, libtool will
78
+ # generate entire wrapper executables (instead of simple wrapper scripts as on Unix) to ensure
79
+ # proper operation of uninstalled programs linked by libtool against the uninstalled shared library.
80
+ # These executables are compiled from C source file for which our flags may not be appropriate,
81
+ # e.g., -std=c89 flag has lead to undesirable warnings in the past.
82
+ #
83
+ # TODO We should analogously not touch CPPFLAGS and LDFLAGS but currently there are no issues.
84
+ AC_DEFUN ( [ SECP_TRY_APPEND_DEFAULT_CFLAGS] , [
85
+ # Try to append -Werror=unknown-warning-option to CFLAGS temporarily. Otherwise clang will
86
+ # not error out if it gets unknown warning flags and the checks here will always succeed
87
+ # no matter if clang knows the flag or not.
88
+ SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS="$CFLAGS"
89
+ SECP_TRY_APPEND_CFLAGS([ -Werror=unknown-warning-option] , CFLAGS)
90
+
91
+ SECP_TRY_APPEND_CFLAGS([ -std=c89 -pedantic -Wno-long-long -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef] , $1 ) # GCC >= 3.0, -Wlong-long is implied by -pedantic.
92
+ SECP_TRY_APPEND_CFLAGS([ -Wno-overlength-strings] , $1 ) # GCC >= 4.2, -Woverlength-strings is implied by -pedantic.
93
+ SECP_TRY_APPEND_CFLAGS([ -Wall] , $1 ) # GCC >= 2.95 and probably many other compilers
94
+ SECP_TRY_APPEND_CFLAGS([ -Wno-unused-function] , $1 ) # GCC >= 3.0, -Wunused-function is implied by -Wall.
95
+ SECP_TRY_APPEND_CFLAGS([ -Wextra] , $1 ) # GCC >= 3.4, this is the newer name of -W, which we don't use because older GCCs will warn about unused functions.
96
+ SECP_TRY_APPEND_CFLAGS([ -Wcast-align] , $1 ) # GCC >= 2.95
97
+ SECP_TRY_APPEND_CFLAGS([ -Wcast-align=strict] , $1 ) # GCC >= 8.0
98
+ SECP_TRY_APPEND_CFLAGS([ -Wconditional-uninitialized] , $1 ) # Clang >= 3.0 only
99
+ SECP_TRY_APPEND_CFLAGS([ -fvisibility=hidden] , $1 ) # GCC >= 4.0
100
+
101
+ CFLAGS="$SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS"
102
+ ] )
103
+ SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS)
102
104
103
105
# ##
104
106
# ## Define config arguments
@@ -253,10 +255,14 @@ AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
253
255
254
256
if test x"$enable_coverage" = x"yes"; then
255
257
AC_DEFINE ( COVERAGE , 1 , [ Define this symbol to compile out all VERIFY code] )
256
- CFLAGS ="-O0 --coverage $CFLAGS "
258
+ SECP_CFLAGS ="-O0 --coverage $SECP_CFLAGS "
257
259
LDFLAGS="--coverage $LDFLAGS"
258
260
else
259
- CFLAGS="-O2 $CFLAGS"
261
+ # Most likely the CFLAGS already contain -O2 because that is autoconf's default.
262
+ # We still add it here because passing it twice is not an issue, and handling
263
+ # this case would just add unnecessary complexity (see #896).
264
+ SECP_CFLAGS="-O2 $SECP_CFLAGS"
265
+ SECP_CFLAGS_FOR_BUILD="-O2 $SECP_CFLAGS_FOR_BUILD"
260
266
fi
261
267
262
268
AC_MSG_CHECKING ( [ for __builtin_popcount] )
@@ -403,6 +409,9 @@ if test x"$enable_valgrind" = x"yes"; then
403
409
SECP_INCLUDES="$SECP_INCLUDES $VALGRIND_CPPFLAGS"
404
410
fi
405
411
412
+ # Add -Werror and similar flags passed from the outside (for testing, e.g., in CI)
413
+ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
414
+
406
415
# Handle static precomputation (after everything which modifies CFLAGS and friends)
407
416
if test x"$use_ecmult_static_precomputation" != x"no"; then
408
417
if test x"$cross_compiling" = x"no"; then
@@ -412,8 +421,9 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
412
421
fi
413
422
# If we're not cross-compiling, simply use the same compiler for building the static precompation code.
414
423
CC_FOR_BUILD="$CC"
415
- CFLAGS_FOR_BUILD="$CFLAGS"
416
424
CPPFLAGS_FOR_BUILD="$CPPFLAGS"
425
+ SECP_CFLAGS_FOR_BUILD="$SECP_CFLAGS"
426
+ CFLAGS_FOR_BUILD="$CFLAGS"
417
427
LDFLAGS_FOR_BUILD="$LDFLAGS"
418
428
else
419
429
AX_PROG_CC_FOR_BUILD
@@ -423,42 +433,32 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
423
433
cross_compiling=no
424
434
SAVE_CC="$CC"
425
435
CC="$CC_FOR_BUILD"
426
- SAVE_CFLAGS="$CFLAGS"
427
- CFLAGS="$CFLAGS_FOR_BUILD"
428
436
SAVE_CPPFLAGS="$CPPFLAGS"
429
437
CPPFLAGS="$CPPFLAGS_FOR_BUILD"
438
+ SAVE_CFLAGS="$CFLAGS"
439
+ CFLAGS="$CFLAGS_FOR_BUILD"
430
440
SAVE_LDFLAGS="$LDFLAGS"
431
441
LDFLAGS="$LDFLAGS_FOR_BUILD"
432
442
433
- warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
434
- saved_CFLAGS="$CFLAGS"
435
- CFLAGS="$warn_CFLAGS_FOR_BUILD $CFLAGS"
436
- AC_MSG_CHECKING ( [ if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}] )
437
- AC_COMPILE_IFELSE ( [ AC_LANG_SOURCE ( [ [ char foo;] ] ) ] ,
438
- [ AC_MSG_RESULT ( [ yes] ) ] ,
439
- [ AC_MSG_RESULT ( [ no] )
440
- CFLAGS="$saved_CFLAGS"
441
- ] )
443
+ SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS_FOR_BUILD)
442
444
443
445
AC_MSG_CHECKING ( [ for working native compiler: ${CC_FOR_BUILD}] )
444
446
AC_RUN_IFELSE (
445
447
[ AC_LANG_PROGRAM ( [ ] , [ ] ) ] ,
446
448
[ working_native_cc=yes] ,
447
449
[ working_native_cc=no] ,[ :] )
448
450
449
- CFLAGS_FOR_BUILD="$CFLAGS"
450
-
451
451
# Restore the environment
452
452
cross_compiling=$save_cross_compiling
453
453
CC="$SAVE_CC"
454
- CFLAGS="$SAVE_CFLAGS"
455
454
CPPFLAGS="$SAVE_CPPFLAGS"
455
+ CFLAGS="$SAVE_CFLAGS"
456
456
LDFLAGS="$SAVE_LDFLAGS"
457
457
458
458
if test x"$working_native_cc" = x"no"; then
459
459
AC_MSG_RESULT ( [ no] )
460
460
set_precomp=no
461
- m4_define ( [ please_set_for_build] , [ Please set CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD , and/or LDFLAGS_FOR_BUILD.] )
461
+ m4_define ( [ please_set_for_build] , [ Please set CC_FOR_BUILD, CPPFLAGS_FOR_BUILD, CFLAGS_FOR_BUILD , and/or LDFLAGS_FOR_BUILD.] )
462
462
if test x"$use_ecmult_static_precomputation" = x"yes"; then
463
463
AC_MSG_ERROR ( [ native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build] )
464
464
else
@@ -471,8 +471,9 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
471
471
fi
472
472
473
473
AC_SUBST ( CC_FOR_BUILD )
474
- AC_SUBST ( CFLAGS_FOR_BUILD )
475
474
AC_SUBST ( CPPFLAGS_FOR_BUILD )
475
+ AC_SUBST ( SECP_CFLAGS_FOR_BUILD )
476
+ AC_SUBST ( CFLAGS_FOR_BUILD )
476
477
AC_SUBST ( LDFLAGS_FOR_BUILD )
477
478
else
478
479
set_precomp=no
@@ -626,6 +627,7 @@ AC_SUBST(SECP_INCLUDES)
626
627
AC_SUBST ( SECP_LIBS )
627
628
AC_SUBST ( SECP_TEST_LIBS )
628
629
AC_SUBST ( SECP_TEST_INCLUDES )
630
+ AC_SUBST ( SECP_CFLAGS )
629
631
AM_CONDITIONAL([ ENABLE_COVERAGE] , [ test x"$enable_coverage" = x"yes"] )
630
632
AM_CONDITIONAL([ USE_TESTS] , [ test x"$use_tests" != x"no"] )
631
633
AM_CONDITIONAL([ USE_EXHAUSTIVE_TESTS] , [ test x"$use_exhaustive_tests" != x"no"] )
679
681
echo
680
682
echo " valgrind = $enable_valgrind"
681
683
echo " CC = $CC"
682
- echo " CFLAGS = $CFLAGS"
683
684
echo " CPPFLAGS = $CPPFLAGS"
685
+ echo " SECP_CFLAGS = $SECP_CFLAGS"
686
+ echo " CFLAGS = $CFLAGS"
684
687
echo " LDFLAGS = $LDFLAGS"
685
688
echo
686
689
if test x"$set_precomp" = x"yes"; then
687
690
echo " CC_FOR_BUILD = $CC_FOR_BUILD"
688
- echo " CFLAGS_FOR_BUILD = $CFLAGS_FOR_BUILD"
689
691
echo " CPPFLAGS_FOR_BUILD = $CPPFLAGS_FOR_BUILD"
692
+ echo " SECP_CFLAGS_FOR_BUILD = $SECP_CFLAGS_FOR_BUILD"
693
+ echo " CFLAGS_FOR_BUILD = $CFLAGS_FOR_BUILD"
690
694
echo " LDFLAGS_FOR_BUILD = $LDFLAGS_FOR_BUILD"
691
695
fi
0 commit comments