@@ -70,35 +70,40 @@ case $host_os in
70
70
;;
71
71
esac
72
72
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
- ] )
73
+ # Try if some desirable compiler flags are supported and append them to SECP_CFLAGS.
74
+ #
75
+ # These are our own flags, so we append them to our own SECP_CFLAGS variable (instead of CFLAGS) as
76
+ # recommended in the automake manual (Section "Flag Variables Ordering"). CFLAGS belongs to the user
77
+ # and we are not supposed to touch it. In the Makefile, we will need to ensure that SECP_CFLAGS
78
+ # is prepended to CFLAGS when invoking the compiler so that the user always has the last word (flag).
79
+ #
80
+ # Another advantage of not touching CFLAGS is that the contents of CFLAGS will be picked up by
81
+ # libtool for compiling helper executables. For example, when compiling for Windows, libtool will
82
+ # generate entire wrapper executables (instead of simple wrapper scripts as on Unix) to ensure
83
+ # proper operation of uninstalled programs linked by libtool against the uninstalled shared library.
84
+ # These executables are compiled from C source file for which our flags may not be appropriate,
85
+ # e.g., -std=c89 flag has lead to undesirable warnings in the past.
86
+ #
87
+ # TODO We still touch the CFLAGS for --coverage and -O0/-O2.
88
+ # TODO We should analogously not touch CPPFLAGS and LDFLAGS but currently there are no issues.
89
+ AC_DEFUN ( [ SECP_TRY_APPEND_DEFAULT_CFLAGS] , [
90
+ # Try to append -Werror=unknown-warning-option to CFLAGS temporarily. Otherwise clang will
91
+ # not error out if it gets unknown warning flags and the checks here will always succeed
92
+ # no matter if clang knows the flag or not.
93
+ SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS="$CFLAGS"
94
+ SECP_TRY_APPEND_CFLAGS([ -Werror=unknown-warning-option] , CFLAGS)
95
+
96
+ 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.
97
+ SECP_TRY_APPEND_CFLAGS([ -Wno-overlength-strings] , $1 ) # GCC >= 4.2, -Woverlength-strings is implied by -pedantic.
98
+ SECP_TRY_APPEND_CFLAGS([ -Wall] , $1 ) # GCC >= 2.95 and probably many other compilers
99
+ SECP_TRY_APPEND_CFLAGS([ -Wno-unused-function] , $1 ) # GCC >= 3.0, -Wunused-function is implied by -Wall.
100
+ 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.
101
+ SECP_TRY_APPEND_CFLAGS([ -Wconditional-uninitialized] , $1 ) # Clang >= 3.0 only
102
+ SECP_TRY_APPEND_CFLAGS([ -fvisibility=hidden] , $1 ) # GCC >= 4.0
103
+
104
+ CFLAGS="$SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS"
105
+ ] )
106
+ SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS)
102
107
103
108
# ##
104
109
# ## Define config arguments
@@ -360,8 +365,9 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
360
365
fi
361
366
# If we're not cross-compiling, simply use the same compiler for building the static precompation code.
362
367
CC_FOR_BUILD="$CC"
363
- CFLAGS_FOR_BUILD ="$CFLAGS "
368
+ SECP_CFLAGS_FOR_BUILD ="$SECP_CFLAGS "
364
369
CPPFLAGS_FOR_BUILD="$CPPFLAGS"
370
+ CFLAGS_FOR_BUILD="$CFLAGS"
365
371
LDFLAGS_FOR_BUILD="$LDFLAGS"
366
372
else
367
373
AX_PROG_CC_FOR_BUILD
@@ -378,15 +384,7 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
378
384
SAVE_LDFLAGS="$LDFLAGS"
379
385
LDFLAGS="$LDFLAGS_FOR_BUILD"
380
386
381
- warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
382
- saved_CFLAGS="$CFLAGS"
383
- CFLAGS="$warn_CFLAGS_FOR_BUILD $CFLAGS"
384
- AC_MSG_CHECKING ( [ if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}] )
385
- AC_COMPILE_IFELSE ( [ AC_LANG_SOURCE ( [ [ char foo;] ] ) ] ,
386
- [ AC_MSG_RESULT ( [ yes] ) ] ,
387
- [ AC_MSG_RESULT ( [ no] )
388
- CFLAGS="$saved_CFLAGS"
389
- ] )
387
+ SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS_FOR_BUILD)
390
388
391
389
AC_MSG_CHECKING ( [ for working native compiler: ${CC_FOR_BUILD}] )
392
390
AC_RUN_IFELSE (
@@ -419,6 +417,7 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
419
417
fi
420
418
421
419
AC_SUBST ( CC_FOR_BUILD )
420
+ AC_SUBST ( SECP_CFLAGS_FOR_BUILD )
422
421
AC_SUBST ( CFLAGS_FOR_BUILD )
423
422
AC_SUBST ( CPPFLAGS_FOR_BUILD )
424
423
AC_SUBST ( LDFLAGS_FOR_BUILD )
@@ -490,6 +489,7 @@ AC_SUBST(SECP_INCLUDES)
490
489
AC_SUBST ( SECP_LIBS )
491
490
AC_SUBST ( SECP_TEST_LIBS )
492
491
AC_SUBST ( SECP_TEST_INCLUDES )
492
+ AC_SUBST ( SECP_CFLAGS )
493
493
AM_CONDITIONAL([ ENABLE_COVERAGE] , [ test x"$enable_coverage" = x"yes"] )
494
494
AM_CONDITIONAL([ USE_TESTS] , [ test x"$use_tests" != x"no"] )
495
495
AM_CONDITIONAL([ USE_EXHAUSTIVE_TESTS] , [ test x"$use_exhaustive_tests" != x"no"] )
532
532
echo
533
533
echo " valgrind = $enable_valgrind"
534
534
echo " CC = $CC"
535
+ echo " SECP_CFLAGS = $SECP_CFLAGS"
535
536
echo " CFLAGS = $CFLAGS"
536
537
echo " CPPFLAGS = $CPPFLAGS"
537
538
echo " LDFLAGS = $LDFLAGS"
538
539
echo
539
540
if test x"$set_precomp" = x"yes"; then
540
541
echo " CC_FOR_BUILD = $CC_FOR_BUILD"
542
+ echo " SECP_CFLAGS_FOR_BUILD = $SECP_CFLAGS_FOR_BUILD"
541
543
echo " CFLAGS_FOR_BUILD = $CFLAGS_FOR_BUILD"
542
544
echo " CPPFLAGS_FOR_BUILD = $CPPFLAGS_FOR_BUILD"
543
545
echo " LDFLAGS_FOR_BUILD = $LDFLAGS_FOR_BUILD"
0 commit comments