Skip to content

Commit 08cd5ac

Browse files
committed
build: always set -g -O2 in CORE_CXXFLAGS
This avoids cases of missing -O2, when *FLAGS has been overriden. Removes the need for duplicate code to clear autoconf defaults. Also, move CORE_CXXFLAGS before DEBUG_CXXFLAGS, so that -O2 is always overriden if debugging etc.
1 parent 2ac2821 commit 08cd5ac

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

configure.ac

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,15 @@ AC_ARG_ENABLE([external-signer],
323323

324324
AC_LANG_PUSH([C++])
325325

326+
dnl Always set -g -O2 in our CXXFLAGS. Autoconf will try and set CXXFLAGS to "-g -O2" by default,
327+
dnl so we suppress that (if CXXFLAGS hasn't been overridden by the user), given we are adding it
328+
dnl ourselves.
329+
CORE_CXXFLAGS="$CORE_CXXFLAGS -g -O2"
330+
331+
if test "$CXXFLAGS_overridden" = "no"; then
332+
CXXFLAGS=""
333+
fi
334+
326335
dnl Check for a flag to turn compiler warnings into errors. This is helpful for checks which may
327336
dnl appear to succeed because by default they merely emit warnings when they fail.
328337
dnl
@@ -347,12 +356,6 @@ case $host in
347356
esac
348357

349358
if test "$enable_debug" = "yes"; then
350-
dnl If debugging is enabled, and the user hasn't overridden CXXFLAGS, clear
351-
dnl them, to prevent autoconfs "-g -O2" being added. Otherwise we'd end up
352-
dnl with "-O0 -g3 -g -O2".
353-
if test "$CXXFLAGS_overridden" = "no"; then
354-
CXXFLAGS=""
355-
fi
356359

357360
dnl Disable all optimizations
358361
AX_CHECK_COMPILE_FLAG([-O0], [DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"], [], [$CXXFLAG_WERROR])
@@ -859,12 +862,6 @@ if test "$use_lcov" = "yes"; then
859862
[AC_MSG_ERROR([lcov testing requested but --coverage linker flag does not work])])
860863
AX_CHECK_COMPILE_FLAG([--coverage],[CORE_CXXFLAGS="$CORE_CXXFLAGS --coverage"],
861864
[AC_MSG_ERROR([lcov testing requested but --coverage flag does not work])])
862-
dnl If coverage is enabled, and the user hasn't overridden CXXFLAGS, clear
863-
dnl them, to prevent autoconfs "-g -O2" being added. Otherwise we'd end up
864-
dnl with "--coverage -Og -O0 -g -O2".
865-
if test "$CXXFLAGS_overridden" = "no"; then
866-
CXXFLAGS=""
867-
fi
868865
CORE_CXXFLAGS="$CORE_CXXFLAGS -Og -O0"
869866
fi
870867

@@ -1996,7 +1993,7 @@ echo " CC = $CC"
19961993
echo " CFLAGS = $PTHREAD_CFLAGS $CFLAGS"
19971994
echo " CPPFLAGS = $DEBUG_CPPFLAGS $HARDENED_CPPFLAGS $CORE_CPPFLAGS $CPPFLAGS"
19981995
echo " CXX = $CXX"
1999-
echo " CXXFLAGS = $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CORE_CXXFLAGS $CXXFLAGS"
1996+
echo " CXXFLAGS = $CORE_CXXFLAGS $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CXXFLAGS"
20001997
echo " LDFLAGS = $PTHREAD_LIBS $HARDENED_LDFLAGS $GPROF_LDFLAGS $CORE_LDFLAGS $LDFLAGS"
20011998
echo " AR = $AR"
20021999
echo " ARFLAGS = $ARFLAGS"

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ print-%: FORCE
99
DIST_SUBDIRS = secp256k1
1010

1111
AM_LDFLAGS = $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS) $(CORE_LDFLAGS)
12-
AM_CXXFLAGS = $(DEBUG_CXXFLAGS) $(HARDENED_CXXFLAGS) $(WARN_CXXFLAGS) $(NOWARN_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS) $(CORE_CXXFLAGS)
12+
AM_CXXFLAGS = $(CORE_CXXFLAGS) $(DEBUG_CXXFLAGS) $(HARDENED_CXXFLAGS) $(WARN_CXXFLAGS) $(NOWARN_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS)
1313
AM_CPPFLAGS = $(DEBUG_CPPFLAGS) $(HARDENED_CPPFLAGS) $(CORE_CPPFLAGS)
1414
AM_LIBTOOLFLAGS = --preserve-dup-deps
1515
PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)

0 commit comments

Comments
 (0)