@@ -70,35 +70,41 @@ 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([ -Wcast-align] , $1 ) # GCC >= 2.95
102
+ SECP_TRY_APPEND_CFLAGS([ -Wconditional-uninitialized] , $1 ) # Clang >= 3.0 only
103
+ SECP_TRY_APPEND_CFLAGS([ -fvisibility=hidden] , $1 ) # GCC >= 4.0
104
+
105
+ CFLAGS="$SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS"
106
+ ] )
107
+ SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS)
102
108
103
109
# ##
104
110
# ## Define config arguments
@@ -360,8 +366,9 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
360
366
fi
361
367
# If we're not cross-compiling, simply use the same compiler for building the static precompation code.
362
368
CC_FOR_BUILD="$CC"
363
- CFLAGS_FOR_BUILD ="$CFLAGS "
369
+ SECP_CFLAGS_FOR_BUILD ="$SECP_CFLAGS "
364
370
CPPFLAGS_FOR_BUILD="$CPPFLAGS"
371
+ CFLAGS_FOR_BUILD="$CFLAGS"
365
372
LDFLAGS_FOR_BUILD="$LDFLAGS"
366
373
else
367
374
AX_PROG_CC_FOR_BUILD
@@ -378,24 +385,14 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
378
385
SAVE_LDFLAGS="$LDFLAGS"
379
386
LDFLAGS="$LDFLAGS_FOR_BUILD"
380
387
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
- ] )
388
+ SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS_FOR_BUILD)
390
389
391
390
AC_MSG_CHECKING ( [ for working native compiler: ${CC_FOR_BUILD}] )
392
391
AC_RUN_IFELSE (
393
392
[ AC_LANG_PROGRAM ( [ ] , [ ] ) ] ,
394
393
[ working_native_cc=yes] ,
395
394
[ working_native_cc=no] ,[ :] )
396
395
397
- CFLAGS_FOR_BUILD="$CFLAGS"
398
-
399
396
# Restore the environment
400
397
cross_compiling=$save_cross_compiling
401
398
CC="$SAVE_CC"
@@ -419,6 +416,7 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
419
416
fi
420
417
421
418
AC_SUBST ( CC_FOR_BUILD )
419
+ AC_SUBST ( SECP_CFLAGS_FOR_BUILD )
422
420
AC_SUBST ( CFLAGS_FOR_BUILD )
423
421
AC_SUBST ( CPPFLAGS_FOR_BUILD )
424
422
AC_SUBST ( LDFLAGS_FOR_BUILD )
@@ -490,6 +488,7 @@ AC_SUBST(SECP_INCLUDES)
490
488
AC_SUBST ( SECP_LIBS )
491
489
AC_SUBST ( SECP_TEST_LIBS )
492
490
AC_SUBST ( SECP_TEST_INCLUDES )
491
+ AC_SUBST ( SECP_CFLAGS )
493
492
AM_CONDITIONAL([ ENABLE_COVERAGE] , [ test x"$enable_coverage" = x"yes"] )
494
493
AM_CONDITIONAL([ USE_TESTS] , [ test x"$use_tests" != x"no"] )
495
494
AM_CONDITIONAL([ USE_EXHAUSTIVE_TESTS] , [ test x"$use_exhaustive_tests" != x"no"] )
532
531
echo
533
532
echo " valgrind = $enable_valgrind"
534
533
echo " CC = $CC"
534
+ echo " SECP_CFLAGS = $SECP_CFLAGS"
535
535
echo " CFLAGS = $CFLAGS"
536
536
echo " CPPFLAGS = $CPPFLAGS"
537
537
echo " LDFLAGS = $LDFLAGS"
538
538
echo
539
539
if test x"$set_precomp" = x"yes"; then
540
540
echo " CC_FOR_BUILD = $CC_FOR_BUILD"
541
+ echo " SECP_CFLAGS_FOR_BUILD = $SECP_CFLAGS_FOR_BUILD"
541
542
echo " CFLAGS_FOR_BUILD = $CFLAGS_FOR_BUILD"
542
543
echo " CPPFLAGS_FOR_BUILD = $CPPFLAGS_FOR_BUILD"
543
544
echo " LDFLAGS_FOR_BUILD = $LDFLAGS_FOR_BUILD"
0 commit comments