From 245c132218f792a1e8a1bdd80ea08b73bf87e356 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 30 Apr 2026 11:48:47 +0930 Subject: [PATCH] Build: Only use -Werror on debug builds. Otherwise, we can break people's builds if they upgrade compiler, for example. Yet we still want -Werror for developers, and CI. Changelog-Changed: Build: We no longer use `-Werror` by default, unless --enable-debugbuild is set. Signed-off-by: Rusty Russell --- configure | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/configure b/configure index bee8ab193574ead6251cece2a5962594a2c89816..0aa1669ab9bc25999071d4551724924bc572e136 100755 --- a/configure +++ b/configure @@ -6,7 +6,7 @@ set -e CONFIGURATOR=ccan/tools/configurator/configurator CONFIG_VAR_FILE=config.vars CONFIG_HEADER=ccan/config.h -BASE_WARNFLAGS="-Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror" +BASE_WARNFLAGS="-Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition" OS=$(uname -s) ARCH=$(uname -m) @@ -51,7 +51,7 @@ default_coptflags() fi } -# Given COPTFLAGS, HAVE_GCC and HAVE_MODERN_GCC, what CWARNFLAGS to default to? +# Given COPTFLAGS, HAVE_GCC, HAVE_MODERN_GCC and DEBUGBUILD, what CWARNFLAGS to default to? default_cwarnflags() { F=$BASE_WARNFLAGS @@ -66,6 +66,10 @@ default_cwarnflags() # this gcc-only. F="$F -Wshadow=local" fi + # Debug builds get -Werror (great for CI!) + if [ "$4" = 1 ]; then + F="$F -Werror" + fi echo "$F" } @@ -220,7 +224,8 @@ have_function_sections() TMPOBJFILE=$CONFIG_VAR_FILE.$$.o echo "int foo(void); int foo(void) { return 0; }" > $TMPCFILE - $1 $2 -ffunction-sections -Wl,--gc-sections -c $TMPCFILE -o $TMPOBJFILE + # We *want* this to fail if we get a warning, hence use -Werror. + $1 $2 -Werror -ffunction-sections -Wl,--gc-sections -c $TMPCFILE -o $TMPOBJFILE } usage() @@ -231,7 +236,7 @@ usage() set_defaults DEFAULT_COPTFLAGS="$(default_coptflags $DEBUGBUILD)" # We assume we have a modern gcc. - DEFAULT_CWARNFLAGS="$(default_cwarnflags ""$DEFAULT_COPTFLAGS"" 1 1)" + DEFAULT_CWARNFLAGS="$(default_cwarnflags ""$DEFAULT_COPTFLAGS"" 1 1 ""$DEBUGBUILD"")" usage_with_default "CC" "$CC" usage_with_default "CWARNFLAGS" "$DEFAULT_CWARNFLAGS" usage_with_default "COPTFLAGS" "$DEFAULT_COPTFLAGS" @@ -601,7 +606,8 @@ fi if [ -z ${CWARNFLAGS+x} ]; then CWARNFLAGS=$(default_cwarnflags "$COPTFLAGS" \ $(sed -n 's/^HAVE_GCC=//p' < $CONFIG_VAR_FILE.$$) \ - $(sed -n 's/^HAVE_MODERN_GCC=//p' < $CONFIG_VAR_FILE.$$) ) + $(sed -n 's/^HAVE_MODERN_GCC=//p' < $CONFIG_VAR_FILE.$$) \ + "$DEBUGBUILD") fi add_var PREFIX "$PREFIX"