Skip to content

Commit ed1b911

Browse files
Merge dashpay#700: Allow overriding default flags
ca739cb Compile with optimization flag -O2 by default instead of -O3 (Jonas Nick) 83fb1bc Remove -O2 from default CFLAGS because this would override the -O3 flag (see AC_PROG_CC in the Autoconf manual) (Jonas Nick) ecba813 Append instead of Prepend user-CFLAGS to default CFLAGS allowing the user to override default variables (Jonas Nick) 613c34c Remove test in configure.ac because it doesn't have an effect (Jonas Nick) Pull request description: Right now, it's not easy to reduce the optimization level with `CFLAGS` because `configure` overwrites any optimization flag with `-O3`. The [automake documentation](https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html) states that: > The reason ‘$(CPPFLAGS)’ appears after ‘$(AM_CPPFLAGS)’ or ‘$(mumble_CPPFLAGS)’ in the compile command is that users should always have the last say. and also that it's incorrect to redefine CFLAGS in the first place > You should never redefine a user variable such as CPPFLAGS in Makefile.am. [...] You should not add options to these user variables within configure either, for the same reason With this PR `CFLAGS` is still redefined, but user-provided flags appear after the default `CFLAGS` which means that they override the default flags (at least in clang and gcc). Otherwise, the default configuration is not changed. This also means that if CFLAGS are defined by the user, then -g is not added (which does not seem to make much sense). In order to keep the `-O3` despite the reordering we need to explicitly tell autoconf to not append `-O2` by setting the default to `-g` with `: ${CFLAGS="-g"}` as per [the manual](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/autoconf.html#C-Compiler) (EDIT: link fix). ACKs for top commit: real-or-random: ACK ca739cb theuni: ACK ca739cb. elichai: ACK ca739cb Tree-SHA512: be92589faa461d245203385d44b489c7d6917b0c68472b8d7576806c0250cf5ff61d5c99ce04eebb8ff5279b9987185d4e5d2da979683fb1c489fdf3e5b59630
2 parents e9fccd4 + ca739cb commit ed1b911

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

configure.ac

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ AH_TOP([#ifndef LIBSECP256K1_CONFIG_H])
77
AH_TOP([#define LIBSECP256K1_CONFIG_H])
88
AH_BOTTOM([#endif /*LIBSECP256K1_CONFIG_H*/])
99
AM_INIT_AUTOMAKE([foreign subdir-objects])
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"}
1015
LT_INIT
1116

1217
dnl make the compilation flags quiet unless V=1 is used
@@ -19,10 +24,6 @@ AC_PATH_TOOL(RANLIB, ranlib)
1924
AC_PATH_TOOL(STRIP, strip)
2025
AX_PROG_CC_FOR_BUILD
2126

22-
if test "x$CFLAGS" = "x"; then
23-
CFLAGS="-g"
24-
fi
25-
2627
AM_PROG_CC_C_O
2728

2829
AC_PROG_CC_C89
@@ -63,11 +64,11 @@ case $host_os in
6364
;;
6465
esac
6566

66-
CFLAGS="$CFLAGS -W"
67+
CFLAGS="-W $CFLAGS"
6768

6869
warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings"
6970
saved_CFLAGS="$CFLAGS"
70-
CFLAGS="$CFLAGS $warn_CFLAGS"
71+
CFLAGS="$warn_CFLAGS $CFLAGS"
7172
AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
7273
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
7374
[ AC_MSG_RESULT([yes]) ],
@@ -76,7 +77,7 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
7677
])
7778

7879
saved_CFLAGS="$CFLAGS"
79-
CFLAGS="$CFLAGS -fvisibility=hidden"
80+
CFLAGS="-fvisibility=hidden $CFLAGS"
8081
AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])
8182
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
8283
[ AC_MSG_RESULT([yes]) ],
@@ -175,10 +176,10 @@ AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
175176

176177
if test x"$enable_coverage" = x"yes"; then
177178
AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
178-
CFLAGS="$CFLAGS -O0 --coverage"
179-
LDFLAGS="$LDFLAGS --coverage"
179+
CFLAGS="-O0 --coverage $CFLAGS"
180+
LDFLAGS="--coverage $LDFLAGS"
180181
else
181-
CFLAGS="$CFLAGS -O3"
182+
CFLAGS="-O2 $CFLAGS"
182183
fi
183184

184185
if test x"$use_ecmult_static_precomputation" != x"no"; then
@@ -196,7 +197,7 @@ if test x"$use_ecmult_static_precomputation" != x"no"; then
196197

197198
warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
198199
saved_CFLAGS="$CFLAGS"
199-
CFLAGS="$CFLAGS $warn_CFLAGS_FOR_BUILD"
200+
CFLAGS="$warn_CFLAGS_FOR_BUILD $CFLAGS"
200201
AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}])
201202
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
202203
[ AC_MSG_RESULT([yes]) ],

0 commit comments

Comments
 (0)